20 from ns.core
import Simulator, Seconds, Config, int64x64_t
26 import ns.applications
41 """! Test schedule now
42 @param self this object
46 """! Callback function
55 Simulator.ScheduleNow(callback,
"args")
58 self.assertEqual(self.
_cb_time_cb_time.GetSeconds(), 0.0)
62 @param self this object
66 """! Callback function
71 self.
_cb_time_cb_time = Simulator.Now()
75 Simulator.Schedule(
Seconds(123), callback,
"args")
78 self.assertEqual(self.
_cb_time_cb_time.GetSeconds(), 123.0)
81 """! Test schedule destroy
82 @param self this object
86 """! Callback function
91 self.
_cb_time_cb_time = Simulator.Now()
96 Simulator.Schedule(
Seconds(123), null)
97 Simulator.ScheduleDestroy(callback,
"args")
101 self.assertEqual(self.
_cb_time_cb_time.GetSeconds(), 123.0)
104 """! Test schedule with context
105 @param self this object
108 def callback(context, args):
110 @param context the cntet
111 @param args the arguments
116 self.
_cb_time_cb_time = Simulator.Now()
121 Simulator.ScheduleWithContext(54321,
Seconds(123), callback,
"args")
125 self.assertEqual(self.
_cb_time_cb_time.GetSeconds(), 123.0)
128 """! Test time comparison
129 @param self this object
139 """! Test numeric operations
140 @param self this object
146 v1 = int64x64_t(5.0)*int64x64_t(10)
147 self.assertEqual(v1, int64x64_t(50))
150 """! Test configuration
151 @param self this object
154 Config.SetDefault(
"ns3::OnOffApplication::PacketSize", ns.core.UintegerValue(123))
162 node = ns.network.Node()
163 internet = ns.internet.InternetStackHelper()
164 internet.Install(node)
167 def rx_callback(socket):
168 """! Receive Callback
169 @param socket the socket to receive
175 sink = ns.network.Socket.CreateSocket(node, ns.core.TypeId.LookupByName(
"ns3::UdpSocketFactory"))
176 sink.Bind(ns.network.InetSocketAddress(ns.network.Ipv4Address.GetAny(), 80))
177 sink.SetRecvCallback(rx_callback)
179 source = ns.network.Socket.CreateSocket(node, ns.core.TypeId.LookupByName(
"ns3::UdpSocketFactory"))
180 source.SendTo(ns.network.Packet(19), 0, ns.network.InetSocketAddress(ns.network.Ipv4Address(
"127.0.0.1"), 80))
188 """! Test attributes function
189 @param self this object
193 queue = ns.network.DropTailQueue__Ns3Packet()
194 queueSizeValue = ns.network.QueueSizeValue (ns.network.QueueSize (
"500p"))
195 queue.SetAttribute(
"MaxSize", queueSizeValue)
197 limit = ns.network.QueueSizeValue()
198 queue.GetAttribute(
"MaxSize", limit)
199 self.assertEqual(limit.Get(), ns.network.QueueSize (
"500p"))
202 mobility = ns.mobility.RandomWaypointMobilityModel()
203 ptr = ns.core.PointerValue()
204 mobility.GetAttribute(
"PositionAllocator", ptr)
205 self.assertEqual(ptr.GetObject(),
None)
207 pos = ns.mobility.ListPositionAllocator()
208 mobility.SetAttribute(
"PositionAllocator", ns.core.PointerValue(pos))
210 ptr = ns.core.PointerValue()
211 mobility.GetAttribute(
"PositionAllocator", ptr)
212 self.assertTrue(ptr.GetObject()
is not None)
216 @param self this object
219 csma = ns.csma.CsmaNetDevice()
220 channel = ns.csma.CsmaChannel()
223 c1 = csma.GetChannel()
224 c2 = csma.GetChannel()
226 self.assertTrue(c1
is c2)
230 @param self this object
233 typeId1 = ns.core.TypeId.LookupByNameFailSafe(
"ns3::UdpSocketFactory")
234 self.assertEqual(typeId1.GetName (),
"ns3::UdpSocketFactory")
236 self.assertRaises(KeyError, ns.core.TypeId.LookupByNameFailSafe,
"__InvalidTypeName__")
239 """! Test command line
240 @param self this object
243 cmd = ns.core.CommandLine()
244 cmd.AddValue(
"Test1",
"this is a test option")
245 cmd.AddValue(
"Test2",
"this is a test option")
246 cmd.AddValue(
"Test3",
"this is a test option", variable=
"test_xxx")
254 cmd.AddValue(
"Test4",
"this is a test option", variable=
"test_foo", namespace=foo)
256 cmd.Parse([
"python",
"--Test1=value1",
"--Test2=value2",
"--Test3=123",
"--Test4=xpto"])
258 self.assertEqual(cmd.Test1,
"value1")
259 self.assertEqual(cmd.Test2,
"value2")
260 self.assertEqual(cmd.test_xxx,
"123")
261 self.assertEqual(foo.test_foo,
"xpto")
265 @param self this object
269 class MyNode(ns.network.Node):
272 @param self this object
275 super(MyNode, self).__init__()
280 if __name__ ==
'__main__':
def testScheduleDestroy(self)
Test schedule destroy.
def testCommandLine(self)
Test command line.
def testTimeNumericOperations(self)
Test numeric operations.
def testScheduleNow(self)
Test schedule now.
def testTypeId(self)
Test type ID.
def testSubclass(self)
Test subclass.
def testSchedule(self)
Test schedule.
def testScheduleWithContext(self)
Test schedule with context.
def testAttributes(self)
Test attributes function.
def testSocket(self)
Test socket.
def testTimeComparison(self)
Test time comparison.
def testConfig(self)
Test configuration.
_received_packet
received packet
def testIdentity(self)
Test identify.
Time Seconds(double value)
Construct a Time in the indicated unit.
uint32_t GetSize(Ptr< const Packet > packet, const WifiMacHeader *hdr, bool isAmpdu)
Return the total size of the packet after WifiMacHeader and FCS trailer have been added.