Make more Python examples use new modular bindings
This commit is contained in:
@@ -23,49 +23,52 @@
|
||||
# - DropTail queues
|
||||
# - Tracing of queues and packet receptions to file "udp-echo.tr"
|
||||
|
||||
import ns3
|
||||
|
||||
import ns.applications
|
||||
import ns.core
|
||||
import ns.csma
|
||||
import ns.internet
|
||||
import ns.network
|
||||
|
||||
def main(argv):
|
||||
#
|
||||
# Allow the user to override any of the defaults and the above Bind() at
|
||||
# run-time, via command-line arguments
|
||||
#
|
||||
cmd = ns3.CommandLine()
|
||||
cmd = ns.core.CommandLine()
|
||||
cmd.Parse(argv)
|
||||
|
||||
#
|
||||
# But since this is a realtime script, don't allow the user to mess with
|
||||
# that.
|
||||
#
|
||||
ns3.GlobalValue.Bind("SimulatorImplementationType", ns3.StringValue("ns3::RealtimeSimulatorImpl"))
|
||||
ns.core.GlobalValue.Bind("SimulatorImplementationType", ns.core.StringValue("ns3::RealtimeSimulatorImpl"))
|
||||
|
||||
#
|
||||
# Explicitly create the nodes required by the topology (shown above).
|
||||
#
|
||||
print "Create nodes."
|
||||
n = ns3.NodeContainer()
|
||||
n = ns.network.NodeContainer()
|
||||
n.Create(4)
|
||||
|
||||
internet = ns3.InternetStackHelper()
|
||||
internet = ns.internet.InternetStackHelper()
|
||||
internet.Install(n)
|
||||
|
||||
#
|
||||
# Explicitly create the channels required by the topology (shown above).
|
||||
#
|
||||
print ("Create channels.")
|
||||
csma = ns3.CsmaHelper()
|
||||
csma.SetChannelAttribute("DataRate", ns3.DataRateValue(ns3.DataRate(5000000)))
|
||||
csma.SetChannelAttribute("Delay", ns3.TimeValue(ns3.MilliSeconds(2)));
|
||||
csma.SetDeviceAttribute("Mtu", ns3.UintegerValue(1400))
|
||||
csma = ns.csma.CsmaHelper()
|
||||
csma.SetChannelAttribute("DataRate", ns.network.DataRateValue(ns.network.DataRate(5000000)))
|
||||
csma.SetChannelAttribute("Delay", ns.core.TimeValue(ns.core.MilliSeconds(2)));
|
||||
csma.SetDeviceAttribute("Mtu", ns.core.UintegerValue(1400))
|
||||
d = csma.Install(n)
|
||||
|
||||
#
|
||||
# We've got the "hardware" in place. Now we need to add IP addresses.
|
||||
#
|
||||
print ("Assign IP Addresses.")
|
||||
ipv4 = ns3.Ipv4AddressHelper()
|
||||
ipv4.SetBase(ns3.Ipv4Address("10.1.1.0"), ns3.Ipv4Mask("255.255.255.0"))
|
||||
ipv4 = ns.internet.Ipv4AddressHelper()
|
||||
ipv4.SetBase(ns.network.Ipv4Address("10.1.1.0"), ns.network.Ipv4Mask("255.255.255.0"))
|
||||
i = ipv4.Assign(d)
|
||||
|
||||
print ("Create Applications.")
|
||||
@@ -74,10 +77,10 @@ def main(argv):
|
||||
# Create a UdpEchoServer application on node one.
|
||||
#
|
||||
port = 9 # well-known echo port number
|
||||
server = ns3.UdpEchoServerHelper(port)
|
||||
server = ns.applications.UdpEchoServerHelper(port)
|
||||
apps = server.Install(n.Get(1))
|
||||
apps.Start(ns3.Seconds(1.0))
|
||||
apps.Stop(ns3.Seconds(10.0))
|
||||
apps.Start(ns.core.Seconds(1.0))
|
||||
apps.Stop(ns.core.Seconds(10.0))
|
||||
|
||||
#
|
||||
# Create a UdpEchoClient application to send UDP datagrams from node zero to
|
||||
@@ -85,16 +88,16 @@ def main(argv):
|
||||
#
|
||||
packetSize = 1024
|
||||
maxPacketCount = 500
|
||||
interPacketInterval = ns3.Seconds(0.01)
|
||||
client = ns3.UdpEchoClientHelper(i.GetAddress (1), port)
|
||||
client.SetAttribute("MaxPackets", ns3.UintegerValue(maxPacketCount))
|
||||
client.SetAttribute("Interval", ns3.TimeValue(interPacketInterval))
|
||||
client.SetAttribute("PacketSize", ns3.UintegerValue(packetSize))
|
||||
interPacketInterval = ns.core.Seconds(0.01)
|
||||
client = ns.applications.UdpEchoClientHelper(i.GetAddress (1), port)
|
||||
client.SetAttribute("MaxPackets", ns.core.UintegerValue(maxPacketCount))
|
||||
client.SetAttribute("Interval", ns.core.TimeValue(interPacketInterval))
|
||||
client.SetAttribute("PacketSize", ns.core.UintegerValue(packetSize))
|
||||
apps = client.Install(n.Get(0))
|
||||
apps.Start(ns3.Seconds(2.0))
|
||||
apps.Stop(ns3.Seconds(10.0))
|
||||
apps.Start(ns.core.Seconds(2.0))
|
||||
apps.Stop(ns.core.Seconds(10.0))
|
||||
|
||||
ascii = ns3.AsciiTraceHelper()
|
||||
ascii = ns.network.AsciiTraceHelper()
|
||||
csma.EnableAsciiAll(ascii.CreateFileStream("realtime-udp-echo.tr"))
|
||||
csma.EnablePcapAll("realtime-udp-echo", False)
|
||||
|
||||
@@ -102,8 +105,8 @@ def main(argv):
|
||||
# Now, do the actual simulation.
|
||||
#
|
||||
print ("Run Simulation.")
|
||||
ns3.Simulator.Run()
|
||||
ns3.Simulator.Destroy()
|
||||
ns.core.Simulator.Run()
|
||||
ns.core.Simulator.Destroy()
|
||||
print ("Done.")
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -3,3 +3,5 @@
|
||||
def build(bld):
|
||||
obj = bld.create_ns3_program('realtime-udp-echo', ['csma', 'internet'])
|
||||
obj.source = 'realtime-udp-echo.cc'
|
||||
|
||||
bld.register_ns3_script('realtime-udp-echo.py', ['csma', 'internet', 'applications'])
|
||||
|
||||
Reference in New Issue
Block a user