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