22 from ns.core
import Simulator, Seconds, Config, int64x64_t
28 import ns.applications
30 UINT32_MAX = 0xFFFFFFFF
45 """! Test schedule now
46 @param self this object
50 """! Callback function
59 Simulator.ScheduleNow(callback,
"args")
62 self.assertEqual(self.
_cb_time_cb_time.GetSeconds(), 0.0)
66 @param self this object
70 """! Callback function
75 self.
_cb_time_cb_time = Simulator.Now()
79 Simulator.Schedule(
Seconds(123), callback,
"args")
82 self.assertEqual(self.
_cb_time_cb_time.GetSeconds(), 123.0)
85 """! Test schedule destroy
86 @param self this object
90 """! Callback function
95 self.
_cb_time_cb_time = Simulator.Now()
100 Simulator.Schedule(
Seconds(123), null)
101 Simulator.ScheduleDestroy(callback,
"args")
105 self.assertEqual(self.
_cb_time_cb_time.GetSeconds(), 123.0)
108 """! Test schedule with context
109 @param self this object
112 def callback(context, args):
114 @param context the cntet
115 @param args the arguments
120 self.
_cb_time_cb_time = Simulator.Now()
125 Simulator.ScheduleWithContext(54321,
Seconds(123), callback,
"args")
129 self.assertEqual(self.
_cb_time_cb_time.GetSeconds(), 123.0)
132 """! Test time comparison
133 @param self this object
143 """! Test numeric operations
144 @param self this object
150 v1 = int64x64_t(5.0)*int64x64_t(10)
151 self.assertEqual(v1, int64x64_t(50))
154 """! Test configuration
155 @param self this object
158 Config.SetDefault(
"ns3::OnOffApplication::PacketSize", ns.core.UintegerValue(123))
166 node = ns.network.Node()
167 internet = ns.internet.InternetStackHelper()
168 internet.Install(node)
171 def rx_callback(socket):
172 """! Receive Callback
173 @param socket the socket to receive
177 self.
_received_packet_received_packet = socket.Recv(maxSize=UINT32_MAX, flags=0)
179 sink = ns.network.Socket.CreateSocket(node, ns.core.TypeId.LookupByName(
"ns3::UdpSocketFactory"))
180 sink.Bind(ns.network.InetSocketAddress(ns.network.Ipv4Address.GetAny(), 80))
181 sink.SetRecvCallback(rx_callback)
183 source = ns.network.Socket.CreateSocket(node, ns.core.TypeId.LookupByName(
"ns3::UdpSocketFactory"))
184 source.SendTo(ns.network.Packet(19), 0, ns.network.InetSocketAddress(ns.network.Ipv4Address(
"127.0.0.1"), 80))
192 """! Test attributes function
193 @param self this object
197 queue = ns.network.DropTailQueue__Ns3Packet()
198 queueSizeValue = ns.network.QueueSizeValue (ns.network.QueueSize (
"500p"))
199 queue.SetAttribute(
"MaxSize", queueSizeValue)
201 limit = ns.network.QueueSizeValue()
202 queue.GetAttribute(
"MaxSize", limit)
203 self.assertEqual(limit.Get(), ns.network.QueueSize (
"500p"))
206 mobility = ns.mobility.RandomWaypointMobilityModel()
207 ptr = ns.core.PointerValue()
208 mobility.GetAttribute(
"PositionAllocator", ptr)
209 self.assertEqual(ptr.GetObject(),
None)
211 pos = ns.mobility.ListPositionAllocator()
212 mobility.SetAttribute(
"PositionAllocator", ns.core.PointerValue(pos))
214 ptr = ns.core.PointerValue()
215 mobility.GetAttribute(
"PositionAllocator", ptr)
216 self.assertTrue(ptr.GetObject()
is not None)
220 @param self this object
223 csma = ns.csma.CsmaNetDevice()
224 channel = ns.csma.CsmaChannel()
227 c1 = csma.GetChannel()
228 c2 = csma.GetChannel()
230 self.assertTrue(c1
is c2)
234 @param self this object
237 typeId1 = ns.core.TypeId.LookupByNameFailSafe(
"ns3::UdpSocketFactory")
238 self.assertEqual(typeId1.GetName (),
"ns3::UdpSocketFactory")
240 self.assertRaises(KeyError, ns.core.TypeId.LookupByNameFailSafe,
"__InvalidTypeName__")
243 """! Test command line
244 @param self this object
247 cmd = ns.core.CommandLine()
248 cmd.AddValue(
"Test1",
"this is a test option")
249 cmd.AddValue(
"Test2",
"this is a test option")
250 cmd.AddValue(
"Test3",
"this is a test option", variable=
"test_xxx")
258 cmd.AddValue(
"Test4",
"this is a test option", variable=
"test_foo", namespace=foo)
260 cmd.Parse([
"python",
"--Test1=value1",
"--Test2=value2",
"--Test3=123",
"--Test4=xpto"])
262 self.assertEqual(cmd.Test1,
"value1")
263 self.assertEqual(cmd.Test2,
"value2")
264 self.assertEqual(cmd.test_xxx,
"123")
265 self.assertEqual(foo.test_foo,
"xpto")
269 @param self this object
273 class MyNode(ns.network.Node):
276 @param self this object
279 super(MyNode, self).__init__()
284 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.