Computer Network NS2
Computer Network NS2
Figure shows the general architecture of NS. In this figure a general user (not an NS
developer) can be thought of standing at the left bottom corner, designing and running
simulations in Tcl using the simulator objects in the OTcl library. The event schedulers and
most of the network components are implemented in C++ and available to OTcl through an
OTcl linkage that is implemented using tclcl. The whole thing together makes NS, which is a
OO extended Tcl interpreter with network simulator libraries.
WRITING A TCL SCRIPT
As shown in Figure 1, we desire to simulate a simple network in which the source node is
generating data with a Mobile Wifi subscriber node as the destination.
Writing the tcl script for this scenario include the following steps
i) Define simulator.
Creating a simulator is essential for any NS-2 simulation. It is done using the
following simple codes.
In this step, define the area (in terms of size) under which the simulation occurs. WE
must define it keeping in view the possible locations of our nodes.
Quoted from CMU document, "GOD (General Operations Director) is the object that
is used to store global information about the state of the environment, network or nodes that
an omniscient observer would have, but that should not be made known to any participant in
the simulation." In simple words, we need to define the GOD to manage the details of
operations we supply such as the movement patterns in our simulations.
Create-god number_of_nodes
To create and configure a base station or an access point in NS-2, it is preferable to define the
options we want to configure the AP/BS with. The configuration is handled as follows.
-option_2 value_2\
........................................
To create an AP/BS with the set configuration, we can now define it as follows.
Then we need to disable random motion for the AP and give it a location.
$ap_name random-motion 0
$ap_name set Z _ 0
After you are done with creating the AP, switch off the configuration mode.
Creating and configuring a wireless node is very similar to what we needed to do with the
AP. To set the configurable options, we use the following code.
-option _ 2 value_ 2 \
....................................
–option_n value _ n\
vii) Define the wired source, configure it and connect it to the AP/BS.
The creation and configuration of the wired source is similar to that of the wireless node,
except we do not “attach” it but rather “connect” it with a wired link.
To define the traffic flow, we need to designate the nodes as source or destination and decide
the type of application/traffic.
It should be noted that each traffic type comes with default values of traffic parameters like rate
and packet size which can be easily overridden with the set command.
It must be noted that source and destination agents form a pair, and though many options are
available for a type of agent, not all of them all compatible with each other.
It is necessary to tell the simulator when to start and stop the traffic flow. To do so we
schedule events that controls the agent‟s activities.
$simulator_name at start_time “$traffic_name start”
To order the simulator to execute, we simply need to provide the following statement in the
script.
$simulator_name run
It is necessary to clear variables and close files after the simulation ends. It is customary to
create a procedure for that.
Proc proc_name {} {
$simulator_name flush-trace
Close $file_name
exit 0
}
STEPS TO RUN NS2 PROGRAM IN UBUNTU
1. In Home folder select the program folder in NS2 allinone2.35 and copy the path location,
to copy the location ctrl+l and ctrl+c.
2. Go to Terminal Window and paste the program folder path location Command for that
mkt@mkt-Aspire-4530:~/ns-allinone-2.35/madocar$ ns caa.tcl
If there is no error in the program after executing the program we will get Nam window and
Graph windows.
5. For Program trace file also be created in that it contains information like which protocol
we used, traffic generated, packet sent, packet receive, request and reply between the nodes.
Fig Trace File
6. To know the performances metrics we have to write AWK script program that should be
save in same program folder. The performance matrices like throughput, end-to-end delay,
packet delivery ratio, total packet dropped, and total packet sent.
Where packet.awk is the AWK script is to know the performance matrices and caa.tr is the
trace file generated for our program.
mkt@mkt-Aspire-4530:~/ns-allinone-2.35/madocar$ ns graph.tcl
OUTPUT
Packet drop=20