Happy Shrimp
http://blog.csdn.net/lights_joy/
Welcome reprint, but please keep the author information
in the previous section, we emulated a total Linetype network, which attempts toN0to become a wirelessAP, and then connect a few nodes. This isNS3The example inthird.ccdo the things that we just usePythonimplementation.
Default Network topology//// Wifi 10.1.3.0// ap// * * * *// | | | | 10.1.1.0//N5 n6 N7 n0--------------N1 n2 N3 n4// point-to-point | | | | ================// LAN 10.1.2.0
as in the previous section, first construct the Peer Network, and then build the total line cable:
# Build a point-to-point connection P2pnodes = Ns.network.NodeContainer () p2pnodes.create (2) Pointtopoint = Ns.point_to_point. Pointtopointhelper () Pointtopoint.setdeviceattribute ("Datarate", Ns.core.StringValue ("5Mbps")) Pointtopoint.setchannelattribute ("Delay", Ns.core.StringValue ("2ms")) P2pdevices = Pointtopoint.install (p2pnodes) # Build bus Connection Ncsma = 3csmaNodes = Ns.network.NodeContainer () csmanodes.add (P2pnodes.get (1)) csmanodes.create (ncsma) Csma = Ns.csma.CsmaHelper () Csma. Setchannelattribute ("Datarate", Ns.core.StringValue ("100Mbps")) Csma. Setchannelattribute ("Delay", Ns.core.TimeValue (Ns.core.NanoSeconds (6560))) Csmadevices = Csma. Install (Csmanodes)
Then build the wireless network:
# build WiFi Connection Nwifi = 3wifiStaNodes = Ns.network.NodeContainer () wifistanodes.create (nwifi) Wifiapnode = p2pnodes.get (0) Channel = Ns.wifi.YansWifiChannelHelper.Default () PHY = Ns.wifi.YansWifiPhyHelper.Default () PHY. Setchannel (channel. Create ())
then configure AP :
# Configure Apwifi = Ns.wifi.WifiHelper.Default () WiFi. Setremotestationmanager ("Ns3::aarfwifimanager") Mac = Ns.wifi.NqosWifiMacHelper.Default () SSID = Ns.wifi.Ssid (" Ns-3-ssid ") Mac. SetType ("Ns3::stawifimac", "SSID", Ns.wifi.SsidValue (SSID), "Activeprobing", Ns.core.BooleanValue (False) ) stadevices = WiFi. Install (PHY, Mac, Wifistanodes) Mac. SetType ("Ns3::apwifimac", "SSID", Ns.wifi.SsidValue (SSID)) apdevices = WiFi. Install (PHY, Mac, Wifiapnode);
Then configure the location parameters of the wireless node:
# Configure the location of the wireless node mobility = Ns.mobility.MobilityHelper () mobility. Setpositionallocator ("Ns3::gridpositionallocator", "MinX", Ns.core.DoubleValue (0.0), "Miny", Ns.core.DoubleValue (0.0), "DeltaX", Ns.core.DoubleValue (5.0), "DeltaY", Ns.core.DoubleValue (10.0), " Gridwidth ", Ns.core.UintegerValue (3), " Layouttype ", Ns.core.StringValue (" Rowfirst ")) mobility. Setmobilitymodel ("Ns3::randomwalk2dmobilitymodel", "Bounds", Ns.mobility.RectangleValue ( Ns.mobility.Rectangle ( -50, -50, ())) mobility. Install (wifistanodes) mobility. Setmobilitymodel ("Ns3::constantpositionmobilitymodel") mobility. Install (Wifiapnode)
Then install the protocol stack:
# install stack of stacks = Ns.internet.InternetStackHelper () stack. Install (csmanodes) stack. Install (wifiapnode) stack. Install (Wifistanodes)
Configuration IP , this is the same as in the previous section, just add 10.1.3.0 Network segment only:
# config IPAddress = ns.internet.Ipv4AddressHelper () address. SetBase ( ns.network.Ipv4Address ("10.1.1.0"), ns.network.Ipv4Mask ("255.255.255.0")) P2pinterfaces = Address. Assign (p2pdevices) address. SetBase ( ns.network.Ipv4Address ("10.1.2.0"), ns.network.Ipv4Mask ("255.255.255.0")) Csmainterfaces = Address. Assign (csmadevices) address. SetBase ( ns.network.Ipv4Address ("10.1.3.0"), ns.network.Ipv4Mask ("255.255.255.0")) address. Assign (stadevices) address. Assign (apdevices)
Next, simulate a Echo service, which is the same as the previous section, just Client installed in the Wifi node.
# config Application echoserver = ns.applications.UdpEchoServerHelper (9) Serverapps = Echoserver.install (Csmanodes.get (Ncsma)) Serverapps.start (Ns.core.Seconds (1.0)) Serverapps.stop (Ns.core.Seconds (20.0)) Echoclient = Ns.applications.UdpEchoClientHelper (Csmainterfaces.getaddress (Ncsma), 9) Echoclient.setattribute ("Maxpackets", Ns.core.UintegerValue (5)) Echoclient.setattribute ("Interval", Ns.core.TimeValue (Ns.core.Seconds (1.0))) Echoclient.setattribute ("PacketSize", Ns.core.UintegerValue (1024x768)) ClientApps = Echoclient.install ( Wifistanodes.get (nWifi-1)) Clientapps.start (Ns.core.Seconds (2.0)) Clientapps.stop (Ns.core.Seconds (20.0))
the next section is almost exactly the same as the previous one, with the addition of Simulator.stop , because if this function is not called, it will cause Simulator.run Will never stop:
# The Global Routing manager establishes a routing table for each node based on the link advertisement generated by the node Ns.internet.Ipv4GlobalRoutingHelper.PopulateRoutingTables () ns.core.Simulator.Stop (Ns.core.Seconds (10.0));p Ointtopoint.enablepcapall ("third"); Csma. Enablepcap ("Third", Csmadevices.get (1), True) PHY. Enablepcap ("Third", Apdevices.get (0)) Anim = Ns.netanim.AnimationInterface (' third.xml ') anim. Setconstantposition (p2pnodes.get (0), ten) Anim. Setconstantposition (csmanodes.get (0), Anim, ten). Setconstantposition (Csmanodes.get (1), anim). Setconstantposition (Csmanodes.get (2), Anim, ten). Setconstantposition (Csmanodes.get (3), ten) Anim. Enablepacketmetadata (True) # start Emulation Ns.core.Simulator.Run () Ns.core.Simulator.Destroy ()
See Netanim simulation Results shown:
V:f eqn= "prod @3 21600 pixelheight" >
look again . Third-0-1.pcap the content of:
as we wish, 802.11 Agreement, hehe ~~~~~
??
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
NS3 network emulation (7): WiFi node