def create_througput_gnuplot(monitor_info, title, filename, flow_ids=None, image_format="png"): """Create Gnuplot PLT file for a saved FlowStats.""" gnuplot = ns3.Gnuplot("%s.%s" % (filename, image_format), title) gnuplot.SetLegend("Time (seconds)", "Throughput (Mbps)") flow_stats_steps = monitor_info["flow_stats_steps"] flow_ids = flow_ids or flow_stats_steps.keys() for flow_id in flow_ids: dataset = ns3.Gnuplot2dDataset("Flow %d" % flow_id) dataset.SetStyle(ns3.Gnuplot2dDataset.LINES) pairs = flow_stats_steps[flow_id] dataset.Add(pairs[0][0], 0) for (time_x, y) in get_flow_stats_deltas(pairs, "rxBytes"): dataset.Add(time_x, 8 * y / 1e6) gnuplot.AddDataset(dataset) pltfilename = "%s.plt" % filename logging.info("created gnuplot (%s) for %d flows (%s): %s" % (title, len(flow_ids), ", ".join(map(str, flow_ids)), pltfilename)) gnuplot.GenerateOutput(ns3.ofstream(pltfilename))
def create_througput_gnuplot(monitor_info, title, filename, flow_ids=None, image_format="png"): """Create Gnuplot PLT file for a saved FlowStats.""" gnuplot = ns3.Gnuplot("%s.%s" % (filename, image_format), title) gnuplot.SetLegend("Time (seconds)", "Throughput (Mbps)") flow_stats_steps = monitor_info["flow_stats_steps"] flow_ids = flow_ids or flow_stats_steps.keys() for flow_id in flow_ids: dataset = ns3.Gnuplot2dDataset("Flow %d" % flow_id) dataset.SetStyle(ns3.Gnuplot2dDataset.LINES) pairs = flow_stats_steps[flow_id] dataset.Add(pairs[0][0], 0) for (time_x, y) in get_flow_stats_deltas(pairs, "rxBytes"): dataset.Add(time_x, 8 * y / 1e6) gnuplot.AddDataset(dataset) pltfilename = "%s.plt" % filename logging.info( "created gnuplot (%s) for %d flows (%s): %s" % (title, len(flow_ids), ", ".join(map(str, flow_ids)), pltfilename)) gnuplot.GenerateOutput(ns3.ofstream(pltfilename))
def main(argv): cmd = ns3.CommandLine() cmd.Parse(argv) # Create nodes print "Create nodes" n0 = ns3.Node() r = ns3.Node() n1 = ns3.Node() net1 = ns3.NodeContainer() net1.Add(n0) net1.Add(r) net2 = ns3.NodeContainer() net2.Add(r) net2.Add(n1) all = ns3.NodeContainer() all.Add(n0) all.Add(r) all.Add(n1) # Create IPv6 Internet Stack internetv6 = ns3.InternetStackHelper() internetv6.Install(all) # Create channels csma = ns3.CsmaHelper() csma.SetChannelAttribute("DataRate", ns3.DataRateValue(ns3.DataRate(5000000))) csma.SetChannelAttribute("Delay", ns3.TimeValue(ns3.MilliSeconds(2))) d1 = csma.Install(net1) d2 = csma.Install(net2) # Create networks and assign IPv6 Addresses print "Addressing" ipv6 = ns3.Ipv6AddressHelper() ipv6.NewNetwork(ns3.Ipv6Address("2001:1::"), ns3.Ipv6Prefix(64)) i1 = ipv6.Assign(d1) i1.SetRouter(1, True) ipv6.NewNetwork(ns3.Ipv6Address("2001:2::"), ns3.Ipv6Prefix(64)) i2 = ipv6.Assign(d2) i2.SetRouter(0, True) # Create a Ping6 application to send ICMPv6 echo request from n0 to n1 via r print "Application" packetSize = 1024 maxPacketCount = 5 interPacketInterval = ns3.Seconds(1.) ping6 = ns3.Ping6Helper() ping6.SetLocal(i1.GetAddress(0, 1)) ping6.SetRemote(i2.GetAddress(1, 1)) ping6.SetAttribute("MaxPackets", ns3.UintegerValue(maxPacketCount)) ping6.SetAttribute("Interval", ns3.TimeValue(interPacketInterval)) ping6.SetAttribute("PacketSize", ns3.UintegerValue(packetSize)) apps = ping6.Install(ns3.NodeContainer(net1.Get(0))) apps.Start(ns3.Seconds(2.0)) apps.Stop(ns3.Seconds(20.0)) print "Tracing" ascii = ns3.ofstream("simple-routing-ping6.tr") ns3.CsmaHelper.EnableAsciiAll(ascii) ns3.CsmaHelper.EnablePcapAll("simple-routing-ping6", True) # Run Simulation ns3.Simulator.Run() ns3.Simulator.Destroy()
appsocket.SetSingleDevice(devices.Get(nNodes-1).GetIfIndex()) appsocket.SetPhysicalAddress(devices.Get (nNodes-1).GetAddress()) appsocket.SetProtocol(0) app=ns.applications.OnOffHelper("ns3::PacketSocketFactory",appsocket.GetPhysicalAddress()) app.SetAttribute("OnTime",ns.core.StringValue("ns3::ConstantRandomVariable[Constant=1]")) app.SetAttribute("OffTime",ns.core.StringValue("ns3::ConstantRandomVariable[Constant=0]")) app.SetAttribute("DataRate",ns.network.DataRateValue(ns.network.DataRate(1300))) app.SetAttribute("PacketSize",ns.core.UintegerValue(1000)) apps=ns.network.ApplicationContainer(app.Install(nodes.Get(0))) sinkNode=nodes.Get(nNodes-1) #Ptr<Node> sinkNode = nodes.Get (nNodes-1); psfid = ns3.TypeId.LookupByName("ns3::PacketSocketFactory") sinkSocket = ns3.Socket.CreateSocket(sinkNode, psfid) sinkSocket.Bind (appsocket) #sinkSocket.SetRecvCallback(ns.core.MakeCallback(ReceivePacket)); apps.Start(ns.core.Seconds(0.5)) apps.Stop(ns.core.Seconds(100.5)) ''' #NS_LOG_INFO ("Run Simulation."); #ns3.Simulator.Stop(ns.core.Seconds(100.)) ns3.Simulator.Run() ns3.Simulator.Destroy() if __name__ == "__main__": ascii = ns3.ofstream("uan-thorp.tr") runMain(len(sys.argv), sys.argv)
def main(argv): ns3.Packet.EnablePrinting (); # enable rts cts all the time. ns3.Config.SetDefault("ns3::WifiRemoteStationManager::RtsCtsThreshold", ns3.StringValue("0")) # disable fragmentation ns3.Config.SetDefault("ns3::WifiRemoteStationManager::FragmentationThreshold", ns3.StringValue ("2200")) wifi = ns3.WifiHelper.Default() mobility = ns3.MobilityHelper() stas = ns3.NodeContainer() ap = ns3.NodeContainer() #NetDeviceContainer staDevs; packetSocket = ns3.PacketSocketHelper() stas.Create(2) ap.Create(1) # give packet socket powers to nodes. packetSocket.Install(stas) packetSocket.Install(ap) wifiPhy = ns3.YansWifiPhyHelper.Default() wifiChannel = ns3.YansWifiChannelHelper.Default() wifiPhy.SetChannel(wifiChannel.Create()) ssid = ns3.Ssid("wifi-default") wifi.SetRemoteStationManager("ns3::ArfWifiManager") # setup stas. wifi.SetMac("ns3::NqstaWifiMac", "Ssid", ns3.SsidValue(ssid), "ActiveProbing", ns3.BooleanValue(False)) staDevs = wifi.Install(wifiPhy, stas) # setup ap. wifi.SetMac("ns3::NqapWifiMac", "Ssid", ns3.SsidValue(ssid), "BeaconGeneration", ns3.BooleanValue(True), "BeaconInterval", ns3.TimeValue(ns3.Seconds(2.5))) wifi.Install(wifiPhy, ap) # mobility. mobility.Install(stas) mobility.Install(ap) ns3.Simulator.Schedule(ns3.Seconds(1.0), AdvancePosition, ap.Get(0)) socket = ns3.PacketSocketAddress() socket.SetSingleDevice(staDevs.Get(0).GetIfIndex()) socket.SetPhysicalAddress(staDevs.Get(1).GetAddress()) socket.SetProtocol(1) onoff = ns3.OnOffHelper("ns3::PacketSocketFactory", ns3.Address(socket)) onoff.SetAttribute("OnTime", ns3.RandomVariableValue(ns3.ConstantVariable(42))) onoff.SetAttribute("OffTime", ns3.RandomVariableValue(ns3.ConstantVariable(0))) apps = onoff.Install(ns3.NodeContainer(stas.Get(0))) apps.Start(ns3.Seconds(0.5)) apps.Stop(ns3.Seconds(43.0)) ns3.Simulator.Stop(ns3.Seconds(44.0)) # Config::Connect ("/NodeList/*/DeviceList/*/Tx", MakeCallback (&DevTxTrace)); # Config::Connect ("/NodeList/*/DeviceList/*/Rx", MakeCallback (&DevRxTrace)); # Config::Connect ("/NodeList/*/DeviceList/*/Phy/RxOk", MakeCallback (&PhyRxOkTrace)); # Config::Connect ("/NodeList/*/DeviceList/*/Phy/RxError", MakeCallback (&PhyRxErrorTrace)); # Config::Connect ("/NodeList/*/DeviceList/*/Phy/Tx", MakeCallback (&PhyTxTrace)); # Config::Connect ("/NodeList/*/DeviceList/*/Phy/State", MakeCallback (&PhyStateTrace)); ascii = ns3.ofstream("wifi-ap.tr") ns3.YansWifiPhyHelper.EnableAsciiAll(ascii) ns3.Simulator.Run() ns3.Simulator.Destroy() ascii.close() return 0
def main(argv): ns3.Packet.EnablePrinting() # enable rts cts all the time. ns3.Config.SetDefault("ns3::WifiRemoteStationManager::RtsCtsThreshold", ns3.StringValue("0")) # disable fragmentation ns3.Config.SetDefault( "ns3::WifiRemoteStationManager::FragmentationThreshold", ns3.StringValue("2200")) wifi = ns3.WifiHelper.Default() mobility = ns3.MobilityHelper() stas = ns3.NodeContainer() ap = ns3.NodeContainer() #NetDeviceContainer staDevs; packetSocket = ns3.PacketSocketHelper() stas.Create(2) ap.Create(1) # give packet socket powers to nodes. packetSocket.Install(stas) packetSocket.Install(ap) wifiPhy = ns3.YansWifiPhyHelper.Default() wifiChannel = ns3.YansWifiChannelHelper.Default() wifiPhy.SetChannel(wifiChannel.Create()) ssid = ns3.Ssid("wifi-default") wifi.SetRemoteStationManager("ns3::ArfWifiManager") wifiMac = ns3.NqosWifiMacHelper.Default() # setup stas. wifiMac.SetType("ns3::NqstaWifiMac", "Ssid", ns3.SsidValue(ssid), "ActiveProbing", ns3.BooleanValue(False)) staDevs = wifi.Install(wifiPhy, wifiMac, stas) # setup ap. wifiMac.SetType("ns3::NqapWifiMac", "Ssid", ns3.SsidValue(ssid), "BeaconGeneration", ns3.BooleanValue(True), "BeaconInterval", ns3.TimeValue(ns3.Seconds(2.5))) wifi.Install(wifiPhy, wifiMac, ap) # mobility. mobility.Install(stas) mobility.Install(ap) ns3.Simulator.Schedule(ns3.Seconds(1.0), AdvancePosition, ap.Get(0)) socket = ns3.PacketSocketAddress() socket.SetSingleDevice(staDevs.Get(0).GetIfIndex()) socket.SetPhysicalAddress(staDevs.Get(1).GetAddress()) socket.SetProtocol(1) onoff = ns3.OnOffHelper("ns3::PacketSocketFactory", ns3.Address(socket)) onoff.SetAttribute("OnTime", ns3.RandomVariableValue(ns3.ConstantVariable(42))) onoff.SetAttribute("OffTime", ns3.RandomVariableValue(ns3.ConstantVariable(0))) apps = onoff.Install(ns3.NodeContainer(stas.Get(0))) apps.Start(ns3.Seconds(0.5)) apps.Stop(ns3.Seconds(43.0)) ns3.Simulator.Stop(ns3.Seconds(44.0)) # Config::Connect("/NodeList/*/DeviceList/*/Tx", MakeCallback(&DevTxTrace)); # Config::Connect("/NodeList/*/DeviceList/*/Rx", MakeCallback(&DevRxTrace)); # Config::Connect("/NodeList/*/DeviceList/*/Phy/RxOk", MakeCallback(&PhyRxOkTrace)); # Config::Connect("/NodeList/*/DeviceList/*/Phy/RxError", MakeCallback(&PhyRxErrorTrace)); # Config::Connect("/NodeList/*/DeviceList/*/Phy/Tx", MakeCallback(&PhyTxTrace)); # Config::Connect("/NodeList/*/DeviceList/*/Phy/State", MakeCallback(&PhyStateTrace)); ascii = ns3.ofstream("wifi-ap.tr") ns3.YansWifiPhyHelper.EnableAsciiAll(ascii) ns3.Simulator.Run() ns3.Simulator.Destroy() ascii.close() return 0
def main(argv): cmd = ns3.CommandLine(); cmd.Parse(argv); # Create nodes print "Create nodes" n0 = ns3.Node(); r = ns3.Node(); n1 = ns3.Node(); net1 = ns3.NodeContainer(); net1.Add(n0); net1.Add(r); net2 = ns3.NodeContainer(); net2.Add(r); net2.Add(n1); all = ns3.NodeContainer(); all.Add(n0); all.Add(r); all.Add(n1); # Create IPv6 Internet Stack internetv6 = ns3.InternetStackHelper(); internetv6.Install(all); # Create channels csma = ns3.CsmaHelper(); csma.SetChannelAttribute("DataRate", ns3.DataRateValue(ns3.DataRate(5000000))); csma.SetChannelAttribute("Delay", ns3.TimeValue(ns3.MilliSeconds(2))); d1 = csma.Install(net1); d2 = csma.Install(net2); # Create networks and assign IPv6 Addresses print "Addressing" ipv6 = ns3.Ipv6AddressHelper(); ipv6.NewNetwork(ns3.Ipv6Address("2001:1::"), ns3.Ipv6Prefix(64)); i1 = ipv6.Assign(d1); i1.SetRouter(1, True); ipv6.NewNetwork(ns3.Ipv6Address("2001:2::"), ns3.Ipv6Prefix(64)); i2 = ipv6.Assign(d2); i2.SetRouter(0, True); # Create a Ping6 application to send ICMPv6 echo request from n0 to n1 via r print "Application" packetSize = 1024; maxPacketCount = 5; interPacketInterval = ns3.Seconds(1.); ping6 = ns3.Ping6Helper(); ping6.SetLocal(i1.GetAddress(0, 1)); ping6.SetRemote(i2.GetAddress(1, 1)); ping6.SetAttribute("MaxPackets", ns3.UintegerValue(maxPacketCount)); ping6.SetAttribute("Interval", ns3.TimeValue(interPacketInterval)); ping6.SetAttribute("PacketSize", ns3.UintegerValue(packetSize)); apps = ping6.Install(ns3.NodeContainer(net1.Get(0))); apps.Start(ns3.Seconds(2.0)); apps.Stop(ns3.Seconds(20.0)); print "Tracing" ascii = ns3.ofstream("simple-routing-ping6.tr"); ns3.CsmaHelper.EnableAsciiAll(ascii); ns3.CsmaHelper.EnablePcapAll("simple-routing-ping6", True); # Run Simulation ns3.Simulator.Run(); ns3.Simulator.Destroy();