rename src/nepi/ into just nepi/
[nepi.git] / nepi / resources / ns3 / classes / on_off_application.py
1 #
2 #    NEPI, a framework to manage network experiments
3 #    Copyright (C) 2014 INRIA
4 #
5 #    This program is free software: you can redistribute it and/or modify
6 #    it under the terms of the GNU General Public License version 2 as
7 #    published by the Free Software Foundation;
8 #
9 #    This program is distributed in the hope that it will be useful,
10 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 #    GNU General Public License for more details.
13 #
14 #    You should have received a copy of the GNU General Public License
15 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 #
17
18 from nepi.execution.attribute import Attribute, Flags, Types
19 from nepi.execution.trace import Trace, TraceAttr
20 from nepi.execution.resource import ResourceManager, clsinit_copy, \
21         ResourceState
22 from nepi.resources.ns3.ns3application import NS3BaseApplication 
23
24 @clsinit_copy
25 class NS3OnOffApplication(NS3BaseApplication):
26     _rtype = "ns3::OnOffApplication"
27
28     @classmethod
29     def _register_attributes(cls):
30         
31         attr_datarate = Attribute("DataRate",
32             "The data rate in on state.",
33             type = Types.String,
34             default = "500000bps",  
35             allowed = None,
36             range = None,    
37             flags = Flags.Reserved | Flags.Construct)
38
39         cls._register_attribute(attr_datarate)
40
41         attr_packetsize = Attribute("PacketSize",
42             "The size of packets sent in on state",
43             type = Types.Integer,
44             default = "512",  
45             allowed = None,
46             range = None,    
47             flags = Flags.Reserved | Flags.Construct)
48
49         cls._register_attribute(attr_packetsize)
50
51         attr_remote = Attribute("Remote",
52             "The address of the destination",
53             type = Types.String,
54             default = "00-00-00",  
55             allowed = None,
56             range = None,    
57             flags = Flags.Reserved | Flags.Construct)
58
59         cls._register_attribute(attr_remote)
60
61         attr_ontime = Attribute("OnTime",
62             "A RandomVariableStream used to pick the duration of the \'On\' state.",
63             type = Types.String,
64             default = "ns3::ConstantRandomVariable[Constant=1.0]",  
65             allowed = None,
66             range = None,    
67             flags = Flags.Reserved | Flags.Construct)
68
69         cls._register_attribute(attr_ontime)
70
71         attr_offtime = Attribute("OffTime",
72             "A RandomVariableStream used to pick the duration of the \'Off\' state.",
73             type = Types.String,
74             default = "ns3::ConstantRandomVariable[Constant=1.0]",  
75             allowed = None,
76             range = None,    
77             flags = Flags.Reserved | Flags.Construct)
78
79         cls._register_attribute(attr_offtime)
80
81         attr_maxbytes = Attribute("MaxBytes",
82             "The total number of bytes to send. Once these bytes are sent, no packet is sent again, even in on state. The value zero means that there is no limit.",
83             type = Types.Integer,
84             default = "0",  
85             allowed = None,
86             range = None,    
87             flags = Flags.Reserved | Flags.Construct)
88
89         cls._register_attribute(attr_maxbytes)
90
91         attr_protocol = Attribute("Protocol",
92             "The type of protocol to use.",
93             type = Types.String,
94             default = "ns3::UdpSocketFactory",  
95             allowed = None,
96             range = None,    
97             flags = Flags.Reserved | Flags.Construct)
98
99         cls._register_attribute(attr_protocol)
100
101         attr_starttime = Attribute("StartTime",
102             "Time at which the application will start",
103             type = Types.String,
104             default = "+0.0ns",  
105             allowed = None,
106             range = None,    
107             flags = Flags.Reserved | Flags.Construct)
108
109         cls._register_attribute(attr_starttime)
110
111         attr_stoptime = Attribute("StopTime",
112             "Time at which the application will stop",
113             type = Types.String,
114             default = "+0.0ns",  
115             allowed = None,
116             range = None,    
117             flags = Flags.Reserved | Flags.Construct)
118
119         cls._register_attribute(attr_stoptime)
120
121
122
123     @classmethod
124     def _register_traces(cls):
125         
126         tx = Trace("Tx", "A new packet is created and is sent")
127
128         cls._register_trace(tx)
129
130
131
132     def __init__(self, ec, guid):
133         super(NS3OnOffApplication, self).__init__(ec, guid)
134         self._home = "ns3-on-off-application-%s" % self.guid