12except ModuleNotFoundError:
14 "Error: ns3 Python module not found;"
15 " Python bindings may not be enabled"
16 " or your PYTHONPATH might not be properly configured"
19ns.LogComponentEnable(
"Ipv4ClickRouting", ns.LOG_LEVEL_ALL)
20ns.LogComponentEnable(
"Ipv4L3ClickProtocol", ns.LOG_LEVEL_ALL)
22clickConfigFolder = os.path.dirname(__file__)
24csmaNodes = ns.NodeContainer()
29csma.SetChannelAttribute(
"DataRate", ns.DataRateValue(ns.DataRate(5000000)))
30csma.SetChannelAttribute(
"Delay", ns.TimeValue(ns.MilliSeconds(2)))
31csmaDevices = csma.Install(csmaNodes)
34internet = ns.InternetStackHelper()
35internet.Install(csmaNodes.Get(1))
38clickinternet = ns.ClickInternetStackHelper()
39clickinternet.SetClickFile(
40 csmaNodes.Get(0), clickConfigFolder +
"/nsclick-lan-single-interface.click"
42clickinternet.SetRoutingTableElement(csmaNodes.Get(0),
"rt")
43clickinternet.Install(csmaNodes.Get(0))
46ipv4 = ns.Ipv4AddressHelper()
47ipv4.SetBase(
"172.16.1.0",
"255.255.255.0")
48ipv4.Assign(csmaDevices)
51LocalAddress = ns.InetSocketAddress(ns.Ipv4Address.GetAny(), 50000).ConvertTo()
52packetSinkHelper = ns.PacketSinkHelper(
"ns3::TcpSocketFactory", LocalAddress)
53recvapp = packetSinkHelper.Install(csmaNodes.Get(1))
54recvapp.Start(ns.Seconds(5.0))
55recvapp.Stop(ns.Seconds(10.0))
57onOffHelper = ns.OnOffHelper(
"ns3::TcpSocketFactory", ns.Address())
58onOffHelper.SetAttribute(
"OnTime", ns.StringValue(
"ns3::ConstantRandomVariable[Constant=1]"))
59onOffHelper.SetAttribute(
"OffTime", ns.StringValue(
"ns3::ConstantRandomVariable[Constant=0]"))
61appcont = ns.ApplicationContainer()
63remoteAddress = ns.InetSocketAddress(ns.Ipv4Address(
"172.16.1.2"), 50000).ConvertTo()
64onOffHelper.SetAttribute(
"Remote", ns.AddressValue(remoteAddress))
65appcont.Add(onOffHelper.Install(csmaNodes.Get(0)))
67appcont.Start(ns.Seconds(5.0))
68appcont.Stop(ns.Seconds(10.0))
71csma.EnablePcap(
"nsclick-simple-lan", csmaDevices,
False)
73ns.Simulator.Stop(ns.Seconds(20.0))