(ii) NS3 How to compile, run scripts, and command line parameter settings

Source: Internet
Author: User

Ii. compiling, running scripts and command line parameter settings 7. Compiling and running scripts main steps

1) Copy the script written to the Ns-3.22/scratch directory (can be copied directly from the Ubuntu window interface)

Go to ns3 directory:/ns-3.22

$ cp examples/tutorial/first.cc scratch/myfirst.cc Copy the script to the scratch directory

2) build (Compile)

$ ./waf

3) Run

$ ./waf--run Scratch/myfirst

(There may be a running permissions issue that can be run under root)

7.1 ns3 in first.cc example notes
 Point-to-points communication between FIRST.CC:2 nodes//header file contains # include "Ns3/core-module.h" #include "ns3/network-module.h" #include "ns3/ Internet-module.h "#include" ns3/point-to-point-module.h "#include" ns3/applications-module.h "//ns3 namespace using namespace ns3;//Log definition ns_log_component_define ("firstscriptexample");//main function intmain (int argc, char *argv[]) {//Time Resolution  :: Setresolution (Time::ns);  Make the Log component effective: component--udpechoclientapplication--level INFO logcomponentenable ("Udpechoclientapplication", log_level_info);  Logcomponentenable ("Udpechoserverapplication", log_level_info);  Generate network node ********//Can be simply regarded as part of the partial emptying of the content of the computer, can be added to the protocol stack, applications and peripherals such as network cards.  Node Container class (contains many methods): Is a helper helper class that can manipulate multiple nodes at once.  For example, by using its object (variable) as the parameter of the device helper class object, you can install the device to more than one node at a time.  Nodecontainer nodes; Nodes.  Create (2);//Using the Create node method of the container class, creating two nodes//******** physical connection computer ********//Abstract: Physical entity = Network Device + channel, one by one corresponds. Pointtopointhelper pointtopoint;//-point Communication helper class, which can set the network device and channel properties Pointtopoint.setdeviceattribute ("Datarate") through the included methods, StringValue ("5Mbps"));//Call member function Pointtopoint.setchannelattribute ("Delay", StringValue ("2ms"));  A network equipment container, which is a node Netdevicecontainer devices with network devices and channels installed; devices = Pointtopoint.install (nodes);//******** install the protocol stack ********//internetstackhelper stack;//Network Stack helper class. belongs to the topology Help class stack.  Install (nodes),//For each node installation protocol stack, IP layer//ipv4 address helper class, belonging to the topology Help class Ipv4addresshelper address; Address.  SetBase ("10.1.1.0", "255.255.255.0"); IPv4 interface container class, for later reference convenience, to the network Device container class configuration address.  The result exists in an object of the IPv4 interface container class. Ipv4interfacecontainer interfaces = address.  Assign (Devices);  Install the application layer ********////UDP server Settings Udpechoserverhelper echoserver (9); Applicationcontainer Serverapps = Echoserver.install (nodes.  Get (1));  Serverapps.start (Seconds (1.0));  Serverapps.stop (Seconds (10.0)); UDP client Udpechoclienthelper echoclient (interfaces.  GetAddress (1), 9);//remote server address and Port Echoclient.setattribute ("Maxpackets", Uintegervalue (1));  Echoclient.setattribute ("Interval", TimeValue (Seconds (1.0)));  Echoclient.setattribute ("PacketSize", Uintegervalue (1024)); Applicationcontainer ClientApps = Echoclient.install (nodes.  Get (0));  Clientapps.start (Seconds (2.0));  Clientapps.stop (Seconds (10.0));  did not join Simulation::stop (Seconds (11.0)); Simulation end time//Because events in the event queue of the first.cc example are automatically completed;//For simulations that have been generated by events (similar operating systems), the simulation end time must be set  Simulator::run ();  Simulator::D Estroy (); return 0;}

7.2 commandline command line arguments

Simulations are typically designed to collect data from a variety of different conditions, often requiring changes in variables. NS-3 provides the command line parameter interface, which allows you to set the variables in the script at run time, eliminating the hassle of recompiling and building the script every time you change a variable.

1) Modifying an existing attribute variable

Add a statement to a script

int main (int argc, char *argv[])

{

...

CommandLine cmd;

cmd. Parse (argc, argv); // use the command line input parameter as the class CommandLine the parameters for analysis

...

}

This allows you to use some additional parameters such as printhelpin the shell:

$~/ns-3.2.1 >/waf--run "scratch/example--printhelp"

This command lists the currently available command parameters for example:

Entering directory '/home/craigdo/repos/ns-3-dev/build '

Compilation finished successfully

--printhelp:print this help message.

--printgroups:print the list of groups.

--printtypeids:print all typeids.

--printgroup=[group]: Print all typeids of group.

--printattributes=[typeid]: Print all attributes of typeid.

--printglobals:print the list of globals.

From the output (the penultimate line) we know that we can print properties of some classes:

$~/ns-3.2.1 >/waf--run "scratch/example-printattributes=ns3::P ointtopointnetdevice"

This command lists the properties of a device of type pointtopointnetdevice:

--NS3::P ointtopointnetdevice::D atarate=[32768bps]:

The default data rate for Point Topoint links

knowing the name of the property, we can also use the command to change this property : If you need to comment/delete the assignment statement in the script

$~/ns-3.2.1>./waf--run "Scratch/example --ns3::P ointtopointnetdevice::D atarate=5mbps"

2) Add your own variables

Use Commandline::addvalue to add your own variables, associate them with the command line by hooking up their own variables, making them a parameter that commandline can use.

In the script, the main function begins to add

Commandlinecmd;

Cmd. AddValue ("Npackets", "number of packets to echo", npackets); (Attribute name, property description, variable)

Cmd. Parse (ARGC,ARGV);

So in the shell we can change this property in the command:

$~/ns-3.2.1 >/waf--run "scratch/example--npackets=2"

Reference Documents:

[1] http://blog.sina.com.cn/s/articlelist_1923709774_8_1.html

[2] Ns-3project. Ns-3 software Tutorial. Ns-3 Project. February 26, 2015

[3] Ns-3project. Ns-3 Reference Manual. Ns-3 Project. February 26, 2015

[4] Basic and application of ns-3 Network Simulator, People's post and telecommunications publishing house, Ma Chunguang Yiu Jiansheng, January 2014

Some reference network materials, not listed, please forgive!




(ii) NS3 How to compile, run scripts, and command line parameter settings

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.