bindings: Remove injected namespaces
This commit is contained in:
@@ -202,7 +202,7 @@ class TestSimulator(unittest.TestCase):
|
||||
@param self this object
|
||||
@return None
|
||||
"""
|
||||
ns.Config.SetDefault("ns3::OnOffApplication::PacketSize", ns.core.UintegerValue(123))
|
||||
ns.Config.SetDefault("ns3::OnOffApplication::PacketSize", ns.UintegerValue(123))
|
||||
# hm.. no Config.Get?
|
||||
|
||||
def testSocket(self):
|
||||
@@ -228,19 +228,15 @@ class TestSimulator(unittest.TestCase):
|
||||
"""
|
||||
)
|
||||
|
||||
sink = ns.network.Socket.CreateSocket(
|
||||
node, ns.core.TypeId.LookupByName("ns3::UdpSocketFactory")
|
||||
)
|
||||
sink.Bind(ns.network.InetSocketAddress(ns.network.Ipv4Address.GetAny(), 80).ConvertTo())
|
||||
sink = ns.Socket.CreateSocket(node, ns.TypeId.LookupByName("ns3::UdpSocketFactory"))
|
||||
sink.Bind(ns.InetSocketAddress(ns.Ipv4Address.GetAny(), 80).ConvertTo())
|
||||
sink.SetRecvCallback(ns.cppyy.gbl.make_rx_callback_test_socket(python_rx_callback))
|
||||
|
||||
source = ns.network.Socket.CreateSocket(
|
||||
node, ns.core.TypeId.LookupByName("ns3::UdpSocketFactory")
|
||||
)
|
||||
source = ns.Socket.CreateSocket(node, ns.TypeId.LookupByName("ns3::UdpSocketFactory"))
|
||||
source.SendTo(
|
||||
ns.network.Packet(19),
|
||||
ns.Packet(19),
|
||||
0,
|
||||
ns.network.InetSocketAddress(ns.network.Ipv4Address("127.0.0.1"), 80).ConvertTo(),
|
||||
ns.InetSocketAddress(ns.Ipv4Address("127.0.0.1"), 80).ConvertTo(),
|
||||
)
|
||||
|
||||
ns.Simulator.Run()
|
||||
@@ -257,26 +253,26 @@ class TestSimulator(unittest.TestCase):
|
||||
"""
|
||||
# Templated class DropTailQueue<Packet> in C++
|
||||
queue = ns.CreateObject("DropTailQueue<Packet>")
|
||||
queueSizeValue = ns.network.QueueSizeValue(ns.network.QueueSize("500p"))
|
||||
queueSizeValue = ns.QueueSizeValue(ns.QueueSize("500p"))
|
||||
queue.SetAttribute("MaxSize", queueSizeValue)
|
||||
|
||||
limit = ns.network.QueueSizeValue()
|
||||
limit = ns.QueueSizeValue()
|
||||
queue.GetAttribute("MaxSize", limit)
|
||||
self.assertEqual(limit.Get(), ns.network.QueueSize("500p"))
|
||||
self.assertEqual(limit.Get(), ns.QueueSize("500p"))
|
||||
|
||||
## -- object pointer values
|
||||
mobility = ns.CreateObject("RandomWaypointMobilityModel")
|
||||
ptr = ns.CreateObject("PointerValue")
|
||||
mobility.GetAttribute("PositionAllocator", ptr)
|
||||
self.assertEqual(ptr.GetObject(), ns.core.Ptr["Object"](ns.cppyy.nullptr))
|
||||
self.assertEqual(ptr.GetObject(), ns.Ptr["Object"](ns.cppyy.nullptr))
|
||||
|
||||
pos = ns.mobility.ListPositionAllocator()
|
||||
pos = ns.ListPositionAllocator()
|
||||
ptr.SetObject(pos)
|
||||
mobility.SetAttribute("PositionAllocator", ptr)
|
||||
|
||||
ptr2 = ns.CreateObject("PointerValue")
|
||||
mobility.GetAttribute("PositionAllocator", ptr2)
|
||||
self.assertNotEqual(ptr.GetObject(), ns.core.Ptr["Object"](ns.cppyy.nullptr))
|
||||
self.assertNotEqual(ptr.GetObject(), ns.Ptr["Object"](ns.cppyy.nullptr))
|
||||
|
||||
# Delete Ptr<>'s on the python side to let C++ clean them
|
||||
del queue, mobility, ptr, ptr2
|
||||
@@ -324,7 +320,7 @@ class TestSimulator(unittest.TestCase):
|
||||
test4Buffer = create_string_buffer(b"this is a test option", BUFFLEN)
|
||||
test4 = c_char_p(test4Buffer.raw)
|
||||
|
||||
cmd = ns.core.CommandLine(__file__)
|
||||
cmd = ns.CommandLine(__file__)
|
||||
cmd.AddValue("Test1", "this is a test option", test1)
|
||||
cmd.AddValue("Test2", "this is a test option", test2)
|
||||
cmd.AddValue["double"]("Test3", "this is a test option", test3)
|
||||
@@ -351,7 +347,7 @@ class TestSimulator(unittest.TestCase):
|
||||
"""
|
||||
|
||||
## MyNode class
|
||||
class MyNode(ns.network.Node):
|
||||
class MyNode(ns.Node):
|
||||
def GetLocalTime(self) -> ns.Time:
|
||||
return ns.Seconds(10)
|
||||
|
||||
@@ -367,20 +363,20 @@ class TestSimulator(unittest.TestCase):
|
||||
"""
|
||||
ns.Simulator.Destroy()
|
||||
|
||||
nodes = ns.network.NodeContainer()
|
||||
nodes = ns.NodeContainer()
|
||||
nodes.Create(2)
|
||||
|
||||
pointToPoint = ns.point_to_point.PointToPointHelper()
|
||||
pointToPoint.SetDeviceAttribute("DataRate", ns.core.StringValue("5Mbps"))
|
||||
pointToPoint.SetChannelAttribute("Delay", ns.core.StringValue("2ms"))
|
||||
pointToPoint = ns.PointToPointHelper()
|
||||
pointToPoint.SetDeviceAttribute("DataRate", ns.StringValue("5Mbps"))
|
||||
pointToPoint.SetChannelAttribute("Delay", ns.StringValue("2ms"))
|
||||
|
||||
devices = pointToPoint.Install(nodes)
|
||||
|
||||
stack = ns.internet.InternetStackHelper()
|
||||
stack = ns.InternetStackHelper()
|
||||
stack.Install(nodes)
|
||||
|
||||
address = ns.internet.Ipv4AddressHelper()
|
||||
address.SetBase(ns.network.Ipv4Address("10.1.1.0"), ns.network.Ipv4Mask("255.255.255.0"))
|
||||
address = ns.Ipv4AddressHelper()
|
||||
address.SetBase(ns.Ipv4Address("10.1.1.0"), ns.Ipv4Mask("255.255.255.0"))
|
||||
|
||||
interfaces = address.Assign(devices)
|
||||
|
||||
@@ -401,7 +397,7 @@ class TestSimulator(unittest.TestCase):
|
||||
)
|
||||
|
||||
## EchoServer application class
|
||||
class EchoServer(ns.applications.Application):
|
||||
class EchoServer(ns.Application):
|
||||
LOGGING = False
|
||||
ECHO_PORT = 1234
|
||||
socketToInstanceDict = {}
|
||||
@@ -419,13 +415,11 @@ class TestSimulator(unittest.TestCase):
|
||||
## Listen port for the server
|
||||
self.port = port
|
||||
## Socket used by the server to listen to port
|
||||
self.m_socket = ns.network.Socket.CreateSocket(
|
||||
node, ns.core.TypeId.LookupByName("ns3::UdpSocketFactory")
|
||||
self.m_socket = ns.Socket.CreateSocket(
|
||||
node, ns.TypeId.LookupByName("ns3::UdpSocketFactory")
|
||||
)
|
||||
self.m_socket.Bind(
|
||||
ns.network.InetSocketAddress(
|
||||
ns.network.Ipv4Address.GetAny(), self.port
|
||||
).ConvertTo()
|
||||
ns.InetSocketAddress(ns.Ipv4Address.GetAny(), self.port).ConvertTo()
|
||||
)
|
||||
self.m_socket.SetRecvCallback(ns.make_rx_callback(EchoServer._Receive))
|
||||
EchoServer.socketToInstanceDict[self.m_socket] = self
|
||||
@@ -507,18 +501,18 @@ class TestSimulator(unittest.TestCase):
|
||||
|
||||
serverApps = ns.ApplicationContainer()
|
||||
serverApps.Add(echoServer)
|
||||
serverApps.Start(ns.core.Seconds(1.0))
|
||||
serverApps.Stop(ns.core.Seconds(10.0))
|
||||
serverApps.Start(ns.Seconds(1.0))
|
||||
serverApps.Stop(ns.Seconds(10.0))
|
||||
|
||||
address = interfaces.GetAddress(1).ConvertTo()
|
||||
echoClient = ns.applications.UdpEchoClientHelper(address, EchoServer.ECHO_PORT)
|
||||
echoClient.SetAttribute("MaxPackets", ns.core.UintegerValue(10))
|
||||
echoClient.SetAttribute("Interval", ns.core.TimeValue(ns.core.Seconds(1.0)))
|
||||
echoClient.SetAttribute("PacketSize", ns.core.UintegerValue(101))
|
||||
echoClient = ns.UdpEchoClientHelper(address, EchoServer.ECHO_PORT)
|
||||
echoClient.SetAttribute("MaxPackets", ns.UintegerValue(10))
|
||||
echoClient.SetAttribute("Interval", ns.TimeValue(ns.Seconds(1.0)))
|
||||
echoClient.SetAttribute("PacketSize", ns.UintegerValue(101))
|
||||
|
||||
clientApps = echoClient.Install(nodes.Get(0))
|
||||
clientApps.Start(ns.core.Seconds(2.0))
|
||||
clientApps.Stop(ns.core.Seconds(10.0))
|
||||
clientApps.Start(ns.Seconds(2.0))
|
||||
clientApps.Stop(ns.Seconds(10.0))
|
||||
|
||||
ns.Simulator.Run()
|
||||
ns.Simulator.Destroy()
|
||||
|
||||
Reference in New Issue
Block a user