NS3 Example Analysis (4)--third.cc

Source: Internet
Author: User

This section is mainly about analyzing the third example of third.cc. This example includes a peer-to channel, an Ethernet channel, and a WiFi channel.

The network topology is as follows:

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


Next, we will analyze the implementation of the third.cc source code:

--------------------------------------------------------------------------------------------

#include "ns3/core-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/network-module.h"
#include "ns3/applications-module.h"
#include "ns3/wifi-module.h"
#include "ns3/mobility-module.h"
#include "ns3/csma-module.h"
#include "ns3/internet-module.h"

using namespace Ns3;

Declares a log widget called Secondscriptexample, which enables the output of the console log to be turned on or off.
Ns_log_component_define ("Thirdscriptexample");

int main (int argc, char *argv[])
{
Defines a variable that determines whether to open two udpapplication logging components;
BOOL verbose = true;
uint32_t Ncsma = 3;
uint32_t Nwifi = 3;

CommandLine cmd;
Cmd. AddValue ("Ncsma", "Number of \" Extra\ "CSMA nodes/devices", Ncsma);
Cmd. AddValue ("Nwifi", "number of WiFi STA devices", Nwifi);
Cmd. AddValue ("Verbose", "tell-echo applications to log if True", verbose);

Cmd. Parse (ARGC,ARGV);

if (Nwifi > 18)
{
Std::cout << "Number of WiFi nodes" << Nwifi <<
"Specified exceeds the mobility bounding box" << Std::endl;
Exit (1);
}

if (verbose)
{
Logcomponentenable ("Udpechoclientapplication", log_level_info);
Logcomponentenable ("Udpechoserverapplication", log_level_info);
}

/******************** Network topology Section ************************/
Create 2 nodes using a peer-to link
Nodecontainer P2pnodes;
P2pnodes.create (2);

Set transfer rate and channel delay
Pointtopointhelper Pointtopoint;
Pointtopoint.setdeviceattribute ("Datarate", StringValue ("5Mbps"));
Pointtopoint.setchannelattribute ("Delay", StringValue ("2ms"));

To install peer-to network interface devices to peer-to node
Netdevicecontainer p2pdevices;
P2pdevices = Pointtopoint.install (p2pnodes);

Create a Nodecontainer class object for the bus (CSMA) network
Nodecontainer Csmanodes;
Add a second peer to Csma's Nodecontainer
Csmanodes.add (P2pnodes.get (1));
Create another 3 node on the bus network
Csmanodes.create (NCSMA);

Create and connect CSMA devices and channels
Csmahelper Csma;
Csma. Setchannelattribute ("Datarate", StringValue ("100Mbps"));
Csma. Setchannelattribute ("Delay", TimeValue (nanoseconds (6560)));

Installing the network card device to the CSMA channel node
Netdevicecontainer csmadevices;
Csmadevices = Csma. Install (Csmanodes);

Create a Nodecontainer class object for WiFi network
Nodecontainer Wifistanodes;
Wifistanodes.create (Nwifi);
Set the first node of the WiFi network to be the AP
Nodecontainer Wifiapnode = p2pnodes.get (0);

Initializing the physical channel
Yanswifichannelhelper channel = Yanswifichannelhelper::D efault ();
Yanswifiphyhelper phy = yanswifiphyhelper::D efault ();
Phy. Setchannel (channel. Create ());

Wifihelper WiFi = wifihelper::D efault ();
Wifi. Setremotestationmanager ("Ns3::aarfwifimanager");

MAC layer Settings
Nqoswifimachelper mac = Nqoswifimachelper::D efault ();

SSID SSID = SSID ("Ns-3-ssid");
Mac. SetType ("Ns3::stawifimac",
"SSID", Ssidvalue (SSID),
"Activeprobing", Booleanvalue (false));

Install the NIC device to the network node of the WiFi channel, and configure the parameters
Netdevicecontainer stadevices;
Stadevices = WiFi. Install (PHY, Mac, Wifistanodes);

Mac. SetType ("Ns3::apwifimac",
"SSID", Ssidvalue (SSID));

Install the network card device to the AP node of the WiFi channel and configure the parameters
Netdevicecontainer apdevices;
Apdevices = WiFi. Install (PHY, Mac, Wifiapnode);

Add a mobile model
Mobilityhelper Mobility;

Mobility. Setpositionallocator ("Ns3::gridpositionallocator",
"MinX", Doublevalue (0.0),
"Miny", Doublevalue (0.0),
"DeltaX", Doublevalue (5.0),
"DeltaY", Doublevalue (10.0),
"Gridwidth", Uintegervalue (3),
"Layouttype", StringValue ("Rowfirst"));

Mobility. Setmobilitymodel ("Ns3::randomwalk2dmobilitymodel",
"Bounds", Rectanglevalue (Rectangle (-50, 50,-50, 50)));
Installing the mobile model on the STA node
Mobility. Install (Wifistanodes);

Set AP: Fixed in one place
Mobility. Setmobilitymodel ("Ns3::constantpositionmobilitymodel");
Mobility. Install (Wifiapnode);

Installing network Protocols
Internetstackhelper Stack;
Stack. Install (Csmanodes);
Stack. Install (Wifiapnode);
Stack. Install (Wifistanodes);

Ipv4addresshelper address;

Arrange the address of the peer segment
Address. SetBase ("10.1.1.0", "255.255.255.0");
Ipv4interfacecontainer p2pinterfaces;
P2pinterfaces = Address. Assign (p2pdevices);

Arrange the address of the CSMA network segment
Address. SetBase ("10.1.2.0", "255.255.255.0");
Ipv4interfacecontainer csmainterfaces;
Csmainterfaces = Address. Assign (csmadevices);

Arrange the address of the WiFi network segment
Address. SetBase ("10.1.3.0", "255.255.255.0");
Address. Assign (stadevices);
Address. Assign (apdevices);
/******************** network topology partial end *********************/

/********************** Application Section *********************/
Udpechoserverhelper Echoserver (9);

Install the Server service on the last node of the CSMA network segment
Applicationcontainer Serverapps = Echoserver.install (Csmanodes.get (Ncsma));
Serverapps.start (Seconds (1.0));
Serverapps.stop (Seconds (10.0));

Udpechoclienthelper echoclient (csmainterfaces.getaddress (Ncsma), 9);
Echoclient.setattribute ("Maxpackets", Uintegervalue (1));
Echoclient.setattribute ("Interval", TimeValue (Seconds (1.0)));
Echoclient.setattribute ("PacketSize", Uintegervalue (1024));

Install the client app on the second-to-last node of the WiFi network segment
Applicationcontainer ClientApps =
Echoclient.install (Wifistanodes.get (nWifi-1));
Clientapps.start (Seconds (2.0));
Clientapps.stop (Seconds (10.0));

/**************** calls Global routing helper to help establish network routing *******************/
Ipv4globalroutinghelper::P opulateroutingtables ();

Simulator::stop (Seconds (10.0));

/**************** turn on pcap tracking *******************/
Pointtopoint.enablepcapall ("third");
Phy. Enablepcap ("Third", Apdevices.get (0));
Csma. Enablepcap ("Third", Csmadevices.get (0), true);

Simulator::run ();
Simulator::D Estroy ();
return 0;
}


-----------------------------------------------------------------------------------------------


The results of the operation are as follows:



Attention:

1, Yanswifichannelhelper:
Yanswifiphyhelper share the same underlying channel, meaning that they share the same wireless media and can communicate with each other.

2, Nqoswifimachelper
Use the Nqoswifimachelper object to set the Mac parameter, which means using a MAC layer mechanism without QoS assurance.

3, Randomwalk2dmobilitymodel
Indicates that in a bounding box, the node moves in a random direction at a random speed.

NS3 Example Analysis (4)--third.cc

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.