23except ModuleNotFoundError:
25 "Error: ns3 Python module not found;"
26 " Python bindings may not be enabled"
27 " or your PYTHONPATH might not be properly configured"
30ns.LogComponentEnable(
"Ipv4ClickRouting", ns.LOG_LEVEL_ALL)
31ns.LogComponentEnable(
"Ipv4L3ClickProtocol", ns.LOG_LEVEL_ALL)
33clickConfigFolder = os.path.dirname(__file__)
35csmaNodes = ns.NodeContainer()
40csma.SetChannelAttribute(
"DataRate", ns.DataRateValue(ns.DataRate(5000000)))
41csma.SetChannelAttribute(
"Delay", ns.TimeValue(ns.MilliSeconds(2)))
42csmaDevices = csma.Install(csmaNodes)
45internet = ns.InternetStackHelper()
46internet.Install(csmaNodes.Get(1))
49clickinternet = ns.ClickInternetStackHelper()
50clickinternet.SetClickFile(
51 csmaNodes.Get(0), clickConfigFolder +
"/nsclick-lan-single-interface.click"
53clickinternet.SetRoutingTableElement(csmaNodes.Get(0),
"rt")
54clickinternet.Install(csmaNodes.Get(0))
57ipv4 = ns.Ipv4AddressHelper()
58ipv4.SetBase(
"172.16.1.0",
"255.255.255.0")
59ipv4.Assign(csmaDevices)
62LocalAddress = ns.InetSocketAddress(ns.Ipv4Address.GetAny(), 50000).ConvertTo()
63packetSinkHelper = ns.PacketSinkHelper(
"ns3::TcpSocketFactory", LocalAddress)
64recvapp = packetSinkHelper.Install(csmaNodes.Get(1))
65recvapp.Start(ns.Seconds(5.0))
66recvapp.Stop(ns.Seconds(10.0))
68onOffHelper = ns.OnOffHelper(
"ns3::TcpSocketFactory", ns.Address())
69onOffHelper.SetAttribute(
"OnTime", ns.StringValue(
"ns3::ConstantRandomVariable[Constant=1]"))
70onOffHelper.SetAttribute(
"OffTime", ns.StringValue(
"ns3::ConstantRandomVariable[Constant=0]"))
72appcont = ns.ApplicationContainer()
74remoteAddress = ns.InetSocketAddress(ns.Ipv4Address(
"172.16.1.2"), 50000).ConvertTo()
75onOffHelper.SetAttribute(
"Remote", ns.AddressValue(remoteAddress))
76appcont.Add(onOffHelper.Install(csmaNodes.Get(0)))
78appcont.Start(ns.Seconds(5.0))
79appcont.Stop(ns.Seconds(10.0))
82csma.EnablePcap(
"nsclick-simple-lan", csmaDevices,
False)
84ns.Simulator.Stop(ns.Seconds(20.0))