30 from ctypes
import c_int, c_bool
32 verbose = c_bool(
True)
33 cmd = ns.CommandLine(__file__)
34 cmd.AddValue(
"nCsma",
"Number of extra CSMA nodes/devices", nCsma)
35 cmd.AddValue(
"verbose",
"Tell echo applications to log if true", verbose)
39 ns.core.LogComponentEnable(
"UdpEchoClientApplication", ns.core.LOG_LEVEL_INFO)
40 ns.core.LogComponentEnable(
"UdpEchoServerApplication", ns.core.LOG_LEVEL_INFO)
41 nCsma.value = 1
if nCsma.value == 0
else nCsma.value
43 p2pNodes = ns.network.NodeContainer()
46 csmaNodes = ns.network.NodeContainer()
47 csmaNodes.Add(p2pNodes.Get(1))
48 csmaNodes.Create(nCsma.value)
50 pointToPoint = ns.point_to_point.PointToPointHelper()
51 pointToPoint.SetDeviceAttribute(
"DataRate", ns.core.StringValue(
"5Mbps"))
52 pointToPoint.SetChannelAttribute(
"Delay", ns.core.StringValue(
"2ms"))
54 p2pDevices = pointToPoint.Install(p2pNodes)
56 csma = ns.csma.CsmaHelper()
57 csma.SetChannelAttribute(
"DataRate", ns.core.StringValue(
"100Mbps"))
58 csma.SetChannelAttribute(
"Delay", ns.core.TimeValue(ns.core.NanoSeconds(6560)))
60 csmaDevices = csma.Install(csmaNodes)
62 stack = ns.internet.InternetStackHelper()
63 stack.Install(p2pNodes.Get(0))
64 stack.Install(csmaNodes)
66 address = ns.internet.Ipv4AddressHelper()
67 address.SetBase(ns.network.Ipv4Address(
"10.1.1.0"), ns.network.Ipv4Mask(
"255.255.255.0"))
68 p2pInterfaces = address.Assign(p2pDevices)
70 address.SetBase(ns.network.Ipv4Address(
"10.1.2.0"), ns.network.Ipv4Mask(
"255.255.255.0"))
71 csmaInterfaces = address.Assign(csmaDevices)
73 echoServer = ns.applications.UdpEchoServerHelper(9)
75 serverApps = echoServer.Install(csmaNodes.Get(nCsma.value))
76 serverApps.Start(ns.core.Seconds(1.0))
77 serverApps.Stop(ns.core.Seconds(10.0))
79 echoClient = ns.applications.UdpEchoClientHelper(csmaInterfaces.GetAddress(nCsma.value).ConvertTo(), 9)
80 echoClient.SetAttribute(
"MaxPackets", ns.core.UintegerValue(1))
81 echoClient.SetAttribute(
"Interval", ns.core.TimeValue(ns.core.Seconds (1.0)))
82 echoClient.SetAttribute(
"PacketSize", ns.core.UintegerValue(1024))
84 clientApps = echoClient.Install(p2pNodes.Get(0))
85 clientApps.Start(ns.core.Seconds(2.0))
86 clientApps.Stop(ns.core.Seconds(10.0))
88 ns.internet.Ipv4GlobalRoutingHelper.PopulateRoutingTables()
90 pointToPoint.EnablePcapAll(
"second")
91 csma.EnablePcap (
"second", csmaDevices.Get (1),
True)
93 ns.core.Simulator.Run()
94 ns.core.Simulator.Destroy()