2 from ns.core
import Simulator, Seconds, Config, int64x64_t
23 """! Test schedule now
24 @param self this object
28 """! Callback function
37 Simulator.ScheduleNow(callback,
"args")
40 self.assertEqual(self._cb_time.GetSeconds(), 0.0)
44 @param self this object
48 """! Callback function
57 Simulator.Schedule(
Seconds(123), callback,
"args")
60 self.assertEqual(self._cb_time.GetSeconds(), 123.0)
63 """! Test schedule destroy
64 @param self this object
68 """! Callback function
78 Simulator.Schedule(
Seconds(123), null)
79 Simulator.ScheduleDestroy(callback,
"args")
83 self.assertEqual(self._cb_time.GetSeconds(), 123.0)
86 """! Test schedule with context
87 @param self this object
90 def callback(context, args):
92 @param context the cntet
93 @param args the arguments
103 Simulator.ScheduleWithContext(54321,
Seconds(123), callback,
"args")
107 self.assertEqual(self._cb_time.GetSeconds(), 123.0)
110 """! Test time comparison
111 @param self this object
121 """! Test numeric operations
122 @param self ths object
128 v1 = int64x64_t(5.0)*int64x64_t(10)
129 self.assertEqual(v1, int64x64_t(50))
132 """! Test configuration
133 @param self this object
136 Config.SetDefault(
"ns3::OnOffApplication::PacketSize", ns.core.UintegerValue(123))
144 node = ns.network.Node()
145 internet = ns.internet.InternetStackHelper()
146 internet.Install(node)
149 def rx_callback(socket):
150 """! Receive Callback
151 @param socket the socket to receive
157 sink = ns.network.Socket.CreateSocket(node, ns.core.TypeId.LookupByName(
"ns3::UdpSocketFactory"))
158 sink.Bind(ns.network.InetSocketAddress(ns.network.Ipv4Address.GetAny(), 80))
159 sink.SetRecvCallback(rx_callback)
161 source = ns.network.Socket.CreateSocket(node, ns.core.TypeId.LookupByName(
"ns3::UdpSocketFactory"))
162 source.SendTo(ns.network.Packet(19), 0, ns.network.InetSocketAddress(ns.network.Ipv4Address(
"127.0.0.1"), 80))
166 self.assertEqual(self._received_packet.GetSize(), 19)
170 """! Test attributes function
171 @param self this object
178 queue = ns.network.DropTailQueue()
180 queue.SetAttribute(
"MaxPackets", ns.core.UintegerValue(123456))
182 limit = ns.core.UintegerValue()
183 queue.GetAttribute(
"MaxPackets", limit)
184 self.assertEqual(limit.Get(), 123456)
187 mobility = ns.mobility.RandomWaypointMobilityModel()
188 ptr = ns.core.PointerValue()
189 mobility.GetAttribute(
"PositionAllocator", ptr)
190 self.assertEqual(ptr.GetObject(),
None)
192 pos = ns.mobility.ListPositionAllocator()
193 mobility.SetAttribute(
"PositionAllocator", ns.core.PointerValue(pos))
195 ptr = ns.core.PointerValue()
196 mobility.GetAttribute(
"PositionAllocator", ptr)
197 self.assert_(ptr.GetObject()
is not None)
201 @param self thsi object
204 csma = ns.csma.CsmaNetDevice()
205 channel = ns.csma.CsmaChannel()
208 c1 = csma.GetChannel()
209 c2 = csma.GetChannel()
211 self.assert_(c1
is c2)
215 @param self this object
218 typeId1 = ns.core.TypeId.LookupByNameFailSafe(
"ns3::UdpSocketFactory")
219 self.assertEqual(typeId1.GetName (),
"ns3::UdpSocketFactory")
221 self.assertRaises(KeyError, ns.core.TypeId.LookupByNameFailSafe,
"__InvalidTypeName__")
224 """! Test command line
225 @param self this object
228 cmd = ns.core.CommandLine()
229 cmd.AddValue(
"Test1",
"this is a test option")
230 cmd.AddValue(
"Test2",
"this is a test option")
231 cmd.AddValue(
"Test3",
"this is a test option", variable=
"test_xxx")
239 cmd.AddValue(
"Test4",
"this is a test option", variable=
"test_foo", namespace=foo)
241 cmd.Parse([
"python",
"--Test1=value1",
"--Test2=value2",
"--Test3=123",
"--Test4=xpto"])
243 self.assertEqual(cmd.Test1,
"value1")
244 self.assertEqual(cmd.Test2,
"value2")
245 self.assertEqual(cmd.test_xxx,
"123")
246 self.assertEqual(foo.test_foo,
"xpto")
250 @param self this object
254 class MyNode(ns.network.Node):
257 @param self this object
260 super(MyNode, self).__init__()
265 if __name__ ==
'__main__':
_received_packet
received packet
def testSubclass(self)
Test subclass.
def testTypeId(self)
Test type ID.
def testTimeNumericOperations(self)
Test numeric operations.
def testConfig(self)
Test configuration.
def testAttributes(self)
Test attributes function.
def testCommandLine(self)
Test command line.
def testSchedule(self)
Test schedule.
def testTimeComparison(self)
Test time comparison.
def testIdentity(self)
Test identify.
def testScheduleWithContext(self)
Test schedule with context.
def testScheduleNow(self)
Test schedule now.
Time Seconds(double value)
Construct a Time in the indicated unit.
def testScheduleDestroy(self)
Test schedule destroy.
def testSocket(self)
Test socket.