2 # NEPI, a framework to manage network experiments
3 # Copyright (C) 2014 INRIA
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;
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.
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/>.
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, \
22 from nepi.resources.ns3.ns3application import NS3BaseApplication
25 class NS3OnOffApplication(NS3BaseApplication):
26 _rtype = "ns3::OnOffApplication"
29 def _register_attributes(cls):
31 attr_datarate = Attribute("DataRate",
32 "The data rate in on state.",
34 default = "500000bps",
37 flags = Flags.Reserved | Flags.Construct)
39 cls._register_attribute(attr_datarate)
41 attr_packetsize = Attribute("PacketSize",
42 "The size of packets sent in on state",
47 flags = Flags.Reserved | Flags.Construct)
49 cls._register_attribute(attr_packetsize)
51 attr_remote = Attribute("Remote",
52 "The address of the destination",
57 flags = Flags.Reserved | Flags.Construct)
59 cls._register_attribute(attr_remote)
61 attr_ontime = Attribute("OnTime",
62 "A RandomVariableStream used to pick the duration of the \'On\' state.",
64 default = "ns3::ConstantRandomVariable[Constant=1.0]",
67 flags = Flags.Reserved | Flags.Construct)
69 cls._register_attribute(attr_ontime)
71 attr_offtime = Attribute("OffTime",
72 "A RandomVariableStream used to pick the duration of the \'Off\' state.",
74 default = "ns3::ConstantRandomVariable[Constant=1.0]",
77 flags = Flags.Reserved | Flags.Construct)
79 cls._register_attribute(attr_offtime)
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.",
87 flags = Flags.Reserved | Flags.Construct)
89 cls._register_attribute(attr_maxbytes)
91 attr_protocol = Attribute("Protocol",
92 "The type of protocol to use.",
94 default = "ns3::UdpSocketFactory",
97 flags = Flags.Reserved | Flags.Construct)
99 cls._register_attribute(attr_protocol)
101 attr_starttime = Attribute("StartTime",
102 "Time at which the application will start",
107 flags = Flags.Reserved | Flags.Construct)
109 cls._register_attribute(attr_starttime)
111 attr_stoptime = Attribute("StopTime",
112 "Time at which the application will stop",
117 flags = Flags.Reserved | Flags.Construct)
119 cls._register_attribute(attr_stoptime)
124 def _register_traces(cls):
126 tx = Trace("Tx", "A new packet is created and is sent")
128 cls._register_trace(tx)
132 def __init__(self, ec, guid):
133 super(NS3OnOffApplication, self).__init__(ec, guid)
134 self._home = "ns3-on-off-application-%s" % self.guid