23ns.LogComponentEnable(
"OpenFlowInterface", ns.LOG_LEVEL_ALL)
24ns.LogComponentEnable(
"OpenFlowSwitchNetDevice", ns.LOG_LEVEL_ALL)
26terminals = ns.NodeContainer()
29csmaSwitch = ns.NodeContainer()
33csma.SetChannelAttribute(
"DataRate", ns.DataRateValue(5000000))
34csma.SetChannelAttribute(
"Delay", ns.TimeValue(ns.MilliSeconds(2)))
36terminalDevices = ns.NetDeviceContainer()
37switchDevices = ns.NetDeviceContainer()
39 container = ns.NodeContainer()
40 container.Add(terminals.Get(i))
41 container.Add(csmaSwitch)
42 link = csma.Install(container)
43 terminalDevices.Add(link.Get(0))
44 switchDevices.Add(link.Get(1))
46switchNode = csmaSwitch.Get(0)
47swtch = ns.OpenFlowSwitchHelper()
48controller = ns.ofi.DropController()
50swtch.Install(switchNode, switchDevices, controller)
54internet = ns.InternetStackHelper()
55internet.Install(terminals)
57ipv4 = ns.Ipv4AddressHelper()
58ipv4.SetBase(
"10.1.1.0",
"255.255.255.0")
59ipv4.Assign(terminalDevices)
63onoff = ns.OnOffHelper(
"ns3::UdpSocketFactory", ns.InetSocketAddress(ns.Ipv4Address(
"10.1.1.2"), port).ConvertTo())
64onoff.SetConstantRate(ns.DataRate(
"500kb/s"))
66app = onoff.Install(terminals.Get(0))
68app.Start(ns.Seconds(1.0))
69app.Stop(ns.Seconds(10.0))
71sink = ns.PacketSinkHelper(
"ns3::UdpSocketFactory",
72 ns.InetSocketAddress(ns.Ipv4Address.GetAny(), port).ConvertTo())
73app = sink.Install(terminals.Get(1))
74app.Start(ns.Seconds(0.0))
76onoff.SetAttribute(
"Remote", ns.AddressValue(ns.InetSocketAddress(ns.Ipv4Address(
"10.1.1.1"), port).ConvertTo()))
77app = onoff.Install(terminals.Get(3))
78app.Start(ns.Seconds(1.1))
79app.Stop(ns.Seconds(10.0))
81app = sink.Install(terminals.Get(0))
82app.Start(ns.Seconds(0.0))