0% found this document useful (0 votes)
20 views131 pages

Hands On Training in NS2

SRI Indu College of Engineering and Technology is offering a 6-week hands-on training course on NS2, focusing on network simulation and programming using TCL and C++. The course covers various modules including network components, wireless network programs, and routing protocols, with practical assignments and assessments. The NS2 simulator is a discrete event-driven tool used for simulating various IP networks and evaluating network protocols.

Uploaded by

hiren
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views131 pages

Hands On Training in NS2

SRI Indu College of Engineering and Technology is offering a 6-week hands-on training course on NS2, focusing on network simulation and programming using TCL and C++. The course covers various modules including network components, wireless network programs, and routing protocols, with practical assignments and assessments. The NS2 simulator is a discrete event-driven tool used for simulating various IP networks and evaluating network protocols.

Uploaded by

hiren
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 131

SRI INDU COLLEGE OF ENGINEERING AND TECHNOLOGY

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

HANDS ON TRAINING COURSE

ON

HANDS ON TRAINING IN NS2


Date: From 25-11-2021 to 31-12-21 (6 Week Course, Only on Saturdays)

COURSE CONTENTS

MODULE -1
Durations Topics Resource Person

Introduction to NS2
Overview
Why TCL, Installation of NS-2
Week 1 Dr. C.Kotteeswaran
Network Component
Node and Routing
Packet Flow
Assignment-1
Overview of ns-2 simulation test bed
ns architecture
NS programming
Dr. C.Kotteeswaran
Week 2 TCL interpreter, characteristics, X Graph
Assignment-2
Basic Linux and Ns2
Node Commands
Dr. C.Kotteeswaran
WIRELESS NETWORK PROGRAMS
Week 3
Assignment-3
MODULE -2
Durations Topics Resource Person
WSN program
Creation of TCP
AODV routing protocol
Multicast

1
Week 4 Link Dr. C.Kotteeswaran
Assignment-4
MODULE -3
Durations Topics Resource Person
Channel – Wireless Channel

Week 5 Propagation Two Ray Ground Propagation Dr. C.Kotteeswaran


Queue Type – Drop Tail
Assessment -1
Conclusion

1 NS 2 INTRODUCTION

Network Simulation (version 2) is one of the object-oriented language based discrete


event-driven introduced at UC Berkely developed in two languages, namely C++ and OTcl

2
(Object Tool Command Language). Network Simulation is first and foremost used in the
simulation of LAN and WAN network.

1.1 Overview

Network Simulation 2 is an event-driven simulator that simulates various kinds of IP


networks. It implements network protocols such as Transmission Control Protocol (TCP) and
User Datagram Protocol (UDP), behavior of traffic source such as File Transfer Protocol (FTP),
Telnet, Web, Constant Bit Rate (CBR) and Variable Bit Rate (VBR), queue management
methods such as Drop Tail, RED and CBQ, and some of the routing algorithm are used. NS also
works with multicasting network oriented programs and some of the Medium Access Control
(MAC) layer protocols for local area network simulations. Network Simulation project is
currently working for the VINT project that introduce tools for simulation results display,
analysis and converters that convert network topologies generated by well-known generators to
NS formats. At present, Network Simulation (version 2) developed in C++ and OTcl is on hand.
This manual discusses briefly about the basic construction of NS, and explains detaily how to
make use of NS frequently by giving examples.

As shown in Figure (Simplified user view of NS2), in a simplified user's view, Network
simulation is an Object-oriented tool script interpretered with simulation event scheduler and the
libraries of network component object, and the libraries of network setup (plumbing) module (in
fact it is the plumbing modules which are implemented as member functions of the base
simulator object). Otherwise to use NS, we have to program in OTcl script language.

To create and run a simulation, OTcl script should be written by the user that creates an
event, initiate the network topology set up using the objects of the network and comment the
traffic sources and fix the transmission time and stop time of transmitting packets through the
event scheduler.

OTcl: Tcl Interpreter with


OO extension

NS Simulator Library

Event Scheduler objects


OTcl Script Analysis

Simulation Program Simulation


NAM
Results

Network Animator

Figure Simplified User's View of NS

One more imporant component of NS beside network objects is the event scheduler. An
event in NS is a packet ID that is unique for a packet with scheduled time and the pointer to an
object that handles the event. In NS, an event scheduler continuously tracking of simulation time
period and fires all the simulation events in the event queue programmed for the present time by
invoking suitable network components, which more often than not are the ones who issued the
events in the simulation, and let them perform the suitable action connected with packet pointed
by the event.

Network components communicates with one another transitory packet, however this does
not devour real simulation time. Each and every network components that require spending a
little simulation time for handling a packet (i.e. essential delay) use the event scheduler by
providing an event for the packet and to come for the event to be fired to itself previous to doing
additional action handling the packet. For example, a network switch component that handles the
simulation which switch with 20 microseconds of switching delay issues an event for a data
packet to be switched to the scheduler as an event 20 microsecond afterward. The scheduler
following 20 microseconds handle the process of dequeue the event and fires it to the switch
component, which subsequently send the packet to a suitable output link component.

One more work of an event scheduler is timer. For example, Transmission Control
Protocol (TCP) needs to make use of a timer to keep tracking transmission time of a packet out
for further transmission (transmission of a packet with similar TCP packet number but dissimilar
network packet identication). Timers will make use of the event schedulers in a same manner
that delay does. The one and only difference in that timer is, it measures a time linked with a

4
packet and does a suitable action connected to that packet after a firm time goes by, and does not
simulate a time delay.

1.2 Why TCL

A user inscribe an OTcl script that’s creates an event scheduler, sets up the topology of the
network by make use of an objects of the network and the libraries plumbing functions, and
control the traffic sources when to initiate and finalize the transmission of the packets through
the event scheduler. Here plumbing is defined as a network setup, for the reason that setting up a
network is plumbing possible paths for data transfer between network objects by locating the
"neighbor" pointer of an object to the address of a suitable object. When a user needs to create a
new network object, he or she with no trouble can make an object either by creating a fresh
object or by constructing a compound object from the object library, and plumb the path of the
data through the object. This may resonance like difficult job, but the plumbing OTcl modules in
reality make the job trouble-free. The influence of NS comes from this plumbing.

NS is created not only in tool command language but in C++ also. For efficiency reason,
NS data path implementations are separated from control path implementations. Most
importantly the packet and event processing time has to be reduced, for that purpose the C++
language is used to write and compile the event scheduler and the component objects. These
compiled objects are ready accessible to the OTcl interpreter through an OTcl linkage that
creates a corresponding OTcl object for each and every C++ objects and makes the control
functions and the configurable variables specified by the C++ object take action as member
functions and member variables of the corresponding OTcl object. By the way, the controls of
the C++ objects are prearranged to OTcl. It is also probable to insert member functions and
variables to a C++ linked OTcl object.

1.2.1 Network Component

TclObject

Other Objects NS Object


5
Connector Classifier

Snoop Queue Queue Delay Agent Trace Addr MCast


Classifier Classifier

IN OUT DRP Edrp Drop RED TCP UDP Enq Deq Drop Recv
Tail

Reno SACK

Figure Class Hierarchies (Partial)

1.2.2 Node and Routing


Application
Application
Agent
Agent
Port Classifier
Addr Classifier Port

Link Link Classifier


Node
Addr
Entry Classifier
Node Entry

Link
Unicast Node Multicast Node
Link
Figure Nodes (Unicast and Multicast)

A node of a network is one of a compound object composed by both the node entry object
and classifiers as shown in Figure (Unicast and Multicast). There are two important types of
nodes in network simulation. First is unicast node, it has an address classifier with it that does the
operation of unicast routing and a port classifier. Next is multicast node, in addition to routing

6
and port classification, it has a classifier which classify multicast packets from unicast packets
and a multicast classifier that performs multicast routing.

In network simulation, Unicast nodes are in default condition. In order to create Multicast
nodes once the user must clearly notify in the input of the OTcl script, after the exact creation of
scheduler object, the nodes which are created that will be in the form of multicast nodes. Next
process is specification, once it get done then specify the node type, the user can also select a
exact routing protocol other than using a predifined one.

Unicast
- $ns rtproto type
- type: Static, Session, DV, cost, multi-path

Multicast
- $ns multicast (right after set $ns [new Scheduler])

1.2.3 Link

n0 Simplex Link n1

Link Entry
Queue Delay TTL

Agent/Null
Figure Link
Drop
First notify that a node’s output queue is actually implemented in the form of simplex
link object. Once after completing the process of dequeued packets from a queue are passed to
the Delay object that again simulates the link delay, and the dropped packets at a queue are
transferred to a Null Agent and are made freed there. Finally, the TTL object calculates Time To
Live (TTL) parameters for each received packets and updates.

7
1.2.4 Tracing

In NS2, activities of the network are traced around simplex links. If the simulator is
intended for to the trace network activities (specifically make use of $ns trace-all file or $ns
namtrace-all file), the links created after this commands will be followed by the upcoming trace
objects inserted as shown in Figure (Inserting Trace Objects). Users creates a trace object of type
type between the given source and destination nodes using the create-trace {type file src dst}
command.

Link with Trace Objects

RecvT

Link Entry EnqT Queue DeqT DDdyy


Delay TTL

DrpT Agent/Null
Figure Inserting Trace Objects
Drop

1.2.5 Queue Monitor

On the whole, tracing objects are intended to trace packet arrival time at which the
localization is done. Even though a user gets sufficient information from the trace files, he or she
might be concerned with what is going inside the output queue. For example, a user paying
attention in RED queue behavior may want to calculate the dynamics of average and current
queue size of a exact RED queue (i.e. need for queue monitoring). Queue monitoring can be
successfully achieved using queue monitor objects and snoop queue objects as shown in Figure
(Monitoring Queues).

8
Link with Snoop Queue Objects

SnoopQ/In Queue SnoopQ/Out Delay TTL

Link Entry

SnoopQ/Drop Agent/Null

Drop
Queue Monitor

Figure Monitoring Queues

When a data packet arrives, the queue monitor object is notified by the snoop queue
object of this event. Using this information the queue is monitored by the queue monitor. RED
Queue Monitor Example section shows some examples for RED queue monitoring. Note that
snoop queue objects can be second-hand in parallel with tracing objects although it is not shown
in the above figure (Figure Monitoring Queues).

1.2.6 Packet Flow Example

Until now, the examination of two most important network components (node and link) is
done. Figure (Packet Flow Examples) shows internals of an example simulation network setup
and packet flow. The number of nodes network is two which is node 0 (n0) and node 1 (n1) of
which the network addresses are 0 and 1 respectively. A TCP agent (sender agent) attached to n0
using port 0 communicates with a TCP sink object (destination agent) attached to n1 port 0.
Finally, an FTP application layer (or traffic source) is attached to the TCP agent (sender
application), asking to send some amount of data to the destination which is node 1.

9
Figure Packet Flow Examples

1.3 Overview of ns-2 simulation test bed

NS-2 has many and expanding uses included.

 The performance of existing network protocols is evaluated.


 Before the usage the new network protocols are evaluated.
 To run large scale experiments and it is not possible in the real time environment.
 Various kinds of internet protocols IP are possible to simulate in network simulation 2.
NS-2 is an object oriented discrete event simulator which works to calculate the performance and
behavior of the network. Simulator maintains list of events in the queue and executes one event
after another event.

Features:

 Protocols mostly used


 Fast to run, with high network control
 Front end is OTCL – Object tool command language
 BACK end is C++ - Creating scenarios, extensions to C++ protocols
 fast to create and modify
1.3.1 Characteristics of NS-2

 NS-2 implementation consist of the following features


 Multicasting is employed here.

10
 Simulation of various kinds of wireless networks
 Terrestrial (cellular, Adhoc, GPRS, WLAN, BLUETOOTH), satellite network are used
 IEEE 802.11 standard can be simulated, Mobile Internet Protocols and Ad hoc protocols
such as DSR, TORA, DSDV and AODV Routing are simulated

1.3.2 Software Tools used with NS-2

In the simulation, there are the two tools are used.

 NAM(Network Animator)
 xGraph

1.3.3 NS ARCHITECTURE

 Object-oriented (C++, OTCL).


 Modular approach
 Fine –grained object composition
 Reusability
 Maintenance
 Perfomanace(speed and memory)
 Careful planning of modularity

1.3.4 NS PROGRAMMING

 Create the event scheduler


 Turn on tracing
 Create network
 Setup routing
 Insert errors
 Create transport connection
 Create traffic
 Transmit application-level data

11
1.3.5 TCL INTERPRETER

TclCL is the language used to provide a linkage between C++ and OTcl. Toolkit
Command Language(Tcl/OTcl) scripts are written to set up/configure network topologies. TclCL
provides linkage for class hierarchy,object instantiation, variable binding and command
dispatching. OTcl is used for periodic or triggered events

The following is written and compiled with C++

1. Events Scheduler
2. NAM- The Network Animator
3. Xgraph- For plotting
4. Pre Processing- Traffic & Topology generator
5. Post Processing- Simple Trace Analysis often used TCL and Pearl

1.3.6 CHARACTERISTICS

NS-2 implements the following features

1. Router queue Management Techniques Drop Tail, RED, CBQ,

2. Multicasting

3. Simulation of wireless networks

4. Developed by Sun Microsystem + UC Berkeley (Daedalus project)

5. Terrestrial (Cellular, Ad-hoc, GPRS, WLAN, BLUETOOTH), Satellite

1.3.7 NAM (Network Animator)

NAM provides a visual interpretation of the network topology created. The application was
developed as part of the VINT project. Its feature is as follows.

 Provides a visual interpretation of the network created


 Can be executed directly from a Tcl script

12
 Controls include play; stop fast forward, rewind, pause, a display speed controller button
and a packet monitor facility.
 Presented information such as throughput, number packets on each link

1.3.8 X Graph

X- Graph is an X-Window application that includes:

Interactive plotting and graphing Animated and derivatives, to use Graph in NS-2 the
executable can be called within a TCL script. This will then load a graph displaying the
information visually displaying the information of the file produced from the simulation. The
output is a graph of size 800 x 400 displaying information on the traffic flow and time.
1.3.9 Simulation tool

NS2 are often growing to include new protocols. LANs need to be updated for new
wired/wireless support. ns are an object oriented simulator, written in C++, with an OTcl
interpreter as a front-end. The simulator supports a class hierarchy in C++ and a similar class
hierarchy within the OTcl interpreter (also called the interpreted hierarchy). The two hierarchies

13
are closely related to each other; from the user’s perspective, there is a one-to-one
correspondence between classes in the interpreted.

2 Basic Linux and Ns2

2.1 Linux Commands

cd : change directory

 Syntax: cd directoryname

ls : list the files in current directory

 Syntax: ls

rm : Remove a file from directory

 Syntax: rm filename

cp : Copying file from one directory to another

 Syntax: cp filename directoryname

pwd: For checking current directory

 Syntax: pwd

ps: For viewing currently running processes on system

 Syntax: ps

kill: For killing a process

 Syntax: kill processid

cat: For viewing file contents on terminal

 Syntax: cat filename

clear: clear the contents on terminal

 Syntax: clear

gcc: For compliling c and c++ programs.

 Syntax: gcc programname.c

14
gedit: Create and open the file in text editor.

 Syntax: gedit filename

./ : For running object file.

 Syntax: ./ objectfilename

2.2 Simulation System Architecture

2.3 Installation of NS-2

2.3.1 Installation on Linux

Copy ns-allinone-2.34.tar_1.gz into /usr/local folder

Extract ns-allinone-2.34.tar_1.gz, you will get ns-allinone-2.34.tar_1.

Extract ns-allinone-2.34.tar_1, you will get ns-allinone-2.34 folder.

Go to ns-allinone-2.34 folder and say – ( ./install).

Go to ns-2.34 folder,

Do (./configure)

Do make all.

Do make install.

2.3.2 Bash file setting (option 2)

15
Open Terminal

Type on terminal following command

gedit ~/.bashrc

Add the TCL library, LD library and ns library path in .bashrc file.

Save the changes

Type on terminal following comand

source ~/.bashrc

2.4 NS-2 Directory Structure

16
3 Scenarios

3.1 First Simulation Scenario

Simulation Script

17
18
Save the simulation script in specific folder.

Open the terminal and go up to specific folder.

Run the simulation script,

ns: command to run simulation script.

Syntax: ns filename.tcl

e.g. ns First_script_wired.tcl

Run the nam file,

nam: command to run animation file

Syntax: nam filename.nam

e.g. nam s1.nam

3.1.1 Flow of Simulation (NS-Node)

19
3.1.2 Flow of Simulation (Network Topology – Link)

3.1.3 Flow of Simulation (Routing)

20
3.1.4 Flow of Simulation (Transport)

3.1.5 Flow of Simulation (Application)

21
3.1.6 Flow of Simulation (Packet Flow)

3.2 Second Simulation Scenario

22
3.2.1 Simulation Script 2

23
24
3.3 Node Orientation

25
3.4 Node Commands

$ns node [ <hier_addr_>]

$ns node-config -<config-parameters> <optional-val>

$node id

$node node-addr

$node reset

$node agent <port_num>

$node entry

$node attach <agent>

$node detach <agent>

$node neighbors

$node add-neighbor <neighbor_node>

$node add-route <destination_id> <target>

$node alloc-port <null_agent>

$node incr-rgtable-size

More Node Commands

Check ~ns-2.34/tcl/lib/ns-node.tcl and ~tcl/lib/ns-mobilenode.tcl

3.5 Link Commands

$ns simplex-link <node1> <node2> <bw> <delay> <qtype> <args>

$ns duplex-link <node1> <node2> <bw> <delay> <qtype> args>

$ns simplex-link-op <n1> <n2> <op> <args>

$ns duplex-link-op <n1> <n2> <p> <args>

$ns lossmodel <lossobj> <from> <to>

$link head

$link link

26
$link add-to-head <connector>

$link queue

$link cost <c>

$link cost?

$link if-lable?

$link up

$link down

$link up?

$link all-connectors <op>

More Node Commands

Check ~ns-2.34/tcl/lib (ns-lib.tcl,ns-link.tcl, ns-intserv.tcl, ns-namsupp.tcl, ns-queue.tcl)


and ~tcl/mcast (McastMonitor.tcl, ns-mcast.tcl), ~ns-2.34/tcl/session/session.tcl

3.6 Simulator Commands

set ns [new Simulator]

set now [$ns now]

$ns halt

$ns run

$ns at <time> <event>

$ns cancel <event>

$ns flush-trace

$ns use - scheduler <type>

$ns after <delay> <event>

$ns clearMemTrace

$ns is-started

$ns dumpq

27
More functions

Check ~ns-2.34/tcl/lib/ns-lib.tcl, ~ns-2.34/commnon/scheduler.{cc,h} and ~ns-


2.34/heap.h

3.7 Trace Related Commands

$ns trace-all <trace-file>

$ns namtrace-all <namtracefile>

$ns namtrace-all-wireless <namtracefile> <X> <Y>

$ns nam-end-wireless <stoptime>

$ns flush-trace

$ns create-trace <type> <file> <src> <dst> <optional:op>

$ns trace-queue <n1> <n2> <optional : file>

$ns namtrace-queue <n1> <n2> <optional : file>

$ns drop-trace <n1> <n2> <trace>

$ns monitor-queue <n1> <n2> <qtrace> <optional : sampleinterval>

$link trace-dynamics <ns> <fileID>

More Functions,

Check ~ns-2.34/trace.{cc,h}, ~ns-2.34/tcl/lib/ns-trace.tcl, ~ns/queue-monitor.


{cc,h}, ~ns-2.34/tcl/ns-link.tcl, ~ns-2.34/packet.h, ~ns-2.34/flowmon.cc and ~ns-
2.34/classifier-hash.cc

3.8 NAM Commands

$ns color <color-id>

$ns trace-annotate <annotation>

$ns set-animation-rate <timestep>

28
3.9 Third Simulation Scenario

3.9.1 Simulation Script 3

29
30
31
3.10 Wired file format

32
Event Time From- To- Pkt- Pkt- Fid Src- Dest- Seq- Pkt-
Node Node Type Size Flags addr addr num id

- 1.06 0 2 tcp 1040 ------ 1 0.0 3.0 2 124


-

r 1.07 1 2 cbr 1000 ------ 2 1.0 3.1 120 122


-

+ 1.07 2 3 cbr 1000 ------ 2 1.0 3.1 120 122


-

d 1.07 2 3 cbr 1000 ------ 2 1.0 3.1 120 122


-

33
4 WIRELESS NETWORK PROGRAMS

4.1 SIMULATION PROGRAM FOR LAN NETWORK

34
35
36
OUTPUT

NETWORK FORMATION

DATA TRANSMISSION

37
4.2 UNICAST PROGRAM

38
OUTPUT

39
DATA TRANSFER

PATH CHANGE DUE TO LINK FAILURE

40
4.3 MULTICAST PROGRAM 1

41
42
OUTPUT

DATA TRANSMISSION

43
4.4 MULTICAST PROGRAM 2

44
45
OUTPUT

DATA TRANSMISSION

46
4.5 Mobile/Wireless Node Structure

47
4.6 WIRELESS PROGRAM 1

48
49
50
OUTPUT

DATA TRANSFER

51
4.7 WSN PROGRAM – 802.11

52
53
54
OUTPUT

DATA TRANSFER

55
4.8 WSN PROGRAM – 802.15.4

56
57
OUTPUT

58
5 Protocol Works

5.1 Procedure to construct Malicious Node in TCL Script and C++

 Modification in AODV PROTOCOL


 LOCATION – ns-allinone-2.33/ns2.33/aodv/aodv.cc
 LOCATION – ns-allinone-2.33/ns2.33/aodv/aodv.h

aodv.h file changes


Declare a boolean variable malicious as shown below in the protected scope in the class AODV

bool malicious;

aodv.cc file changes


1. Initialize the malicious variable with a value "false". Declare it inside the constructor as
shown below
AODV::AODV(nsaddr_t id):Agent(PT_AODV)...
{
.......
malicious = false;
}

2. Add the following statement to the aodv.cc file in the "if(argc==2)" statement.

if(strcmp(argv[1], "malicious") == 0) {
desyn = true;
return TCL_OK;
}

3. Implement the behavior of the malicious node by setting the following code in the
rt_resolve(Packet *p) function. The malicious s node will simply drop the packet as indicated
below.

59
if(malicious ==true)
{
drop(p,DROP_RTR_ROUTE_LOOP);
}

Once done, recompile ns2 as given below


Open Terminal -> Go to ~ns-2.33/ directory and type the command make to compile
$] cd /ns-allinone-2.33/ns-2.33/
$] make

Once the compilation is done, Check the malicious behavior using the Tcl Script by setting any
four node as malicious node. The command to set the malicious node is
$ns at 2.0 "[$n0 set ragent_] malicious "

$ns at 2.0 "[$n8 set ragent_] malicious "

$ns at 2.0 "[$n23 set ragent_] malicious "

$ns at 2.0 "[$n19 set ragent_] malicious "

5.2 How to generate random mobility in ns2?


Procedure
Open the new terminal
cd ns-allinone-2.34
cd ns-2.34
cd indep-utils
pwd
ls
cd cmu-scen-gen
ls
cd setdest
ls
./setdest

60
./setdest –v 2 –n 10 –s 1 –m 10 –M 50 –t 30 –P 1 –p 1 –x 500 –y 500
./setdest –v 2 –n 10 –s 1 –m 10 –M 50 –t 30 –P 1 –p 1 –x 500 –y 500 >usersetdest.tcl
gedit usersetdest.tcl

5.3 How to generate random agent and application creation in ns2?


Procedure
cd ns-allinone-2.34
cd ns-2.34
cdindep-utils
cdcmu-scen-gen
ls
nscbrgen.tcl
nscbrgen.tcl –type cbr –nn 10 –seed 1 –mc 5 –rate 5.0
nscbrgen.tcl –type cbr –nn 10 –seed 1 –mc 5 –rate 5.0 > cbr-10.tcl
gedit cbr-10.tcl

6. PROGRAMS

6.1 PROGRAMS 1 – Wireless Network Construction using TCL script

Program Description

Basic wirless construction with number of nodes contained is three. The procedure to
create nam file and trace file is given in this program. Topology is created by giving the position
to the nodes and is specified by X, Y and Z coordinates. Here initial size of each and every nodes
are built using initial_node_pos.The routing protocol which is used in this program is AODV
(Adhoc On-demand Vector Routing Protocol). And simulation end time is 10ms.

File Name – program1.tcl

 Channel Type – Wireless Channel


 Propogation – Two Ray Ground Model
 X dimension – 500
 Y dimension – 400

61
62
Procedure to run the program in the terminal window - $ns program1.tcl

OUTPUT

63
6.2 PROGRAM 2 – Code for the construction of wireless nodes with fixed colors

Program Description:

Number of nodes in the network is eight which are created and configured as mobile
wireless nodes. Procedure for the creation of nam file and trace file is given and is followed by
the topology creation. Localization of the network is specified by using the X, Y and Z
coordinates and the Z coordinates are always remains zero. Routing protocol is AODV and the
stop time of the simulation is 10ms. Here all the nodes are created in cyan color.

 Channel Type – Wireless Channel


 Propogation – Two Ray Ground Model
 Queue Type – DropTail
 Antenna Type – Omni Directional Antenna
 Number of nodes – 8
 Routing protocol - AODV
 X dimension – 500
 Y dimension – 400
 Stop time – 10ms
 Color – cyan color

File Name – program2.tcl

64
65
66
Procedure to run the program in the terminal window - $ns program2.tcl

OUTPUT

6.3 PROGRAM 3 – Dynamic node creation program using AODV protocol TCL script

Program Discription

Number of nodes in the network is not static in this program. Number of nodes
construction is given during the run time of the program. The user should give the number of
nodes in the terminal window during the execution of the program. Procedure for the creation of
nam file and trace file is given and is followed by the topology creation. Localization of the
network is specified by using the X, Y and Z coordinates and the Z coordinates are always
remains zero. Routing protocol is AODV and the stop time of the simulation is 10ms. Here all
the nodes are created in yellow color.

File Name – program3.tcl

if {$argc != 1} {
error "\nCommand: ns wireless1.tcl <no.of.mobile-nodes>\n\n "
}

67
68
69
Procedure to run the program in the terminal window - $ns program3.tcl

OUTPUT

70
6.4 PROGRAM 4 – Dynamic node creation program and its initial location using AODV
protocol TCL script

Program Discription

Number of nodes in the network is not static in this program. Number of nodes
construction is given during the run time of the program. The user should give the number of
nodes in the terminal window during the execution of the program. Procedure for the creation of
nam file and trace file is given and is followed by the topology creation. Localization of the
network is specified by using the X, Y and Z coordinates and the Z coordinates are always
remains zero. Here initial size of each and every node is created by the use of the command
(initial_node_pos). Routing protocol is AODV and the stop time of the simulation is 10ms. Here
all the nodes are created in yellow color.

File Name – program4.tcl

 X dimension – 600
 Y dimension – 600
 Stop time – 10ms
 Color – Yellow color
 Initial Node Position - 30

if {$argc != 1} {
error "\nCommand: ns wireless3.tcl <no.of.mobile-nodes>\n\n "
}

71
72
Procedure to run the program in the terminal window - $ns program4.tcl

OUTPUT

73
6.5 PROGRAM 5 – Dynamic color creation program and its initial location of nodes using
AODV routing protocol TCL script

Program Discription

Number of nodes in the network is static in this program. Nodes are configured in the
mobile wireless node format. Procedure for the creation of nam file and trace file is given and is
followed by the topology creation. Localization of the network is not static. X and Y coordinates
are randomly selected and the Z coordinates are always remains zero. Here initial size of each
and every node is created by the use of the command (initial_node_pos). Routing protocol is
AODV and the stop time of the simulation is 10ms. Here all the nodes colors will get modified
dynamically according to the time period

File Name – program5.tcl

 Number of nodes - 4
 X dimension – 750
 Y dimension – 550
 Stop time – 3.0ms
 Color – Yellow color
 Initial Node Position - 30

74
75
76
Procedure to run the program in the terminal window - $ns program5.tcl

OUTPUT

77
6.6 PROGRAM 6 – Node mobility construction program using DSR routing protocol TCL
script

Program Discription

Number of nodes in the network is static. Nodes are configured in the mobile wireless
node format. Procedure for the creation of nam file and trace file is given and is followed by the
topology creation. Localization of the network is static. X and Y coordinates values are given in
the program and the Z coordinates are always remains zero. Movement for each and every node
is built with static speed and spectifed receiver address which is randomly generated and also the
mobility will get change accoding to the time period. Here initial size of each and every node is
created by the use of the command (initial_node_pos). Routing protocol is DSR and the stop
time of the simulation is 10ms.

File Name – program6.tcl

 X dimension – 750
 Y dimension – 550
 Stop time – 3.0ms
 Color – Yellow color
 Initial Node Position - 30

if {$argc != 1} {
error "\nCommand: ns program6.tcl <no.of.mobile-nodes>\n\n "
}

78
79
80
81
Procedure to run the program in the terminal window - $ns program6.tcl

OUTPUT

82
6.7 PROGRAM 7 – Creation of TCP (Transmission Control Protocol) communication
between the nodes using AODV routing protocol TCL script

Program Discription

Number of nodes in the network is static and is declared as three in the network. Nodes
are configured in the mobile wireless node format. Procedure for the creation of nam file and
trace file is given and is followed by the topology creation. Localization of the network is static.
X and Y coordinates values are given in the program and the Z coordinates are always remains
zero. Movement for each and every node is built with static speed and spectifed receiver address
which is randomly generated and also the mobility will get change accoding to the time period.
Here initial size of each and every node is created by the use of the command (initial_node_pos).
Routing protocol is AODV and the stop time of the simulation is 150ms. Three nodes are created
which are node0, node 1 and node 2. Send TCP agent is created and attached to node0,
destination TCPsink agent is created and attached to node1. Then the TCP agent and the
TCPsink agent are connected. In the next level, FTP application is created and attached to the
sender TCP agent. Now the communication is initiated.

File Name – program7.tcl

 X dimension – 500
 Y dimension – 400
 Stop time – 150 ms

83
84
85
Procedure to run the program in the terminal window - $ns program7.tcl

OUTPUT

86
6.8 PROGRAM 8 – Creation of TCP (Transmission Control Protocol) communication
between the nodes using DSR routing protocol TCL script

Program Discription

Number of nodes in the network is static and is declared as three in the network. Nodes
are configured in the mobile wireless node format. Procedure for the creation of nam file and
trace file is given and is followed by the topology creation. Localization of the network is static.
X and Y coordinates values are given in the program and the Z coordinates are always remains
zero. Movement for each and every node is built with static speed and spectifed receiver address
which is randomly generated and also the mobility will get change accoding to the time period.
Here initial size of each and every node is created by the use of the command (initial_node_pos).
Routing protocol is DSR and the stop time of the simulation is 150ms. Three nodes are created
which are node0, node 1 and node 2. Send TCP agent is created and attached to node0,
destination TCPsink agent is created and attached to node1. Then the TCP agent and the
TCPsink agent are connected. In the next level, FTP application is created and attached to the
sender TCP agent. Now the communication is initiated.

File Name – program8.tcl

 X dimension – 500
 Y dimension – 400
 Stop time – 150 ms

87
88
89
Procedure to run the program in the terminal window - $ns program8.tcl

OUTPUT

90
6.9 PROGRAM 9 – Creation of UDP (User Datagram Protocol) communication between
nodes with CBR traffic using AODV routing protocol TCL script

Program Discription

Number of nodes in the network is static and is declared as 22 in the network. Nodes are
configured in the mobile wireless node format. Procedure for the creation of nam file and trace
file is given and is followed by the topology creation. Localization of the network is static. X and
Y coordinates values are given in the program and the Z coordinates are always remains zero.
Movement for each and every node is built with static speed and spectifed receiver address
which is randomly generated and also the mobility will get change accoding to the time period.
Here initial size of each and every node is created by the use of the command (initial_node_pos).
Routing protocol is AODV and the stop time of the simulation is 150ms. Send UDP agent is
created and attached to sender node, destination UDPNull agent is created and attached to
destination node. Then the UDP agent and the UDPNull agent are connected. In the next level,
CBR application is created and attached to the sender UDP agent. Now the communication is
initiated.

File Name – program9.tcl

 Number or nodes - 22
 X dimension – 1800
 Y dimension – 840
 Stop time – 150 ms

91
92
93
94
95
96
97
98
99
Procedure to run the program in the terminal window - $ns program9.tcl

OUTPUT

100
6.10 PROGRAM 10 – Creation of TCP (Transmission Control Protocol) communication
between the nodes using DSDV routing protocol TCL script

Program Discription

Number of nodes in the network is static and is declared as three in the network. Nodes
are configured in the mobile wireless node format. Procedure for the creation of nam file and
trace file is given and is followed by the topology creation. Localization of the network is static.
X and Y coordinates values are given in the program and the Z coordinates are always remains
zero. Movement for each and every node is built with static speed and spectifed receiver address
which is randomly generated and also the mobility will get change accoding to the time period.

Here initial size of each and every node is created by the use of the command
(initial_node_pos). Routing protocol is DSDV and the stop time of the simulation is 150ms.
Three nodes are created which are node0, node 1 and node 2. Send TCP agent is created and
attached to node0, destination TCPsink agent is created and attached to node1. Then the TCP
agent and the TCPsink agent are connected. In the next level, FTP application is created and
attached to the sender TCP agent. Now the communication is initiated.

File Name – program10.tcl

 Channel Type – Wireless Channel


 Propogation – Two Ray Ground Model
 Queue Type – DropTail
 Antenna Type – Omni Directional Antenna
 Number of nodes – 3
 Routing protocol - DSDV
 X dimension – 500
 Y dimension – 400
 Stop time – 150ms
 AGENT – TCP
 Application - FTP

101
102
103
Procedure to run the program in the terminal window - $ns program10.tcl

OUTPUT

104
6.11 PROGRAM 11 – Mobile node energy model construction TCL script

Program Discription

Number of nodes in the network is static and is declared as six in the network. Nodes are
configured in the mobile wireless node format. Procedure for the creation of nam file and trace
file is given and is followed by the topology creation. Localization of the network is static. X and
Y coordinates values are given in the program and the Z coordinates are always remains zero.

Movement for each and every node is built with static speed and spectifed receiver
address which is randomly generated and also the mobility will get change accoding to the time
period. Here initial size of each and every node is created by the use of the command
(initial_node_pos). Routing protocol is DSR and the stop time of the simulation is 18ms.

File Name – program11.tcl

 Channel – Wireless Channel


 Propagation – Two Ray Ground Propagation
 Queue Type – Drop Tail
 Antenna – Omni Directional Antenna
 Initial Energy – 20 J
 Transmission Power – 0.9 J
 Receiver Power – 0.8 J
 Idle Power – 0.0 J
 Sense Power – 0.0175 J
 Routing Protocol – DSR
 Simulation Time – 18ms
 Number of nodes – 6 nodes
 X dimension – 750
 Y dimension – 550
 Initial Node Position - 30

105
106
107
108
109
Procedure to run the program in the terminal window - $ns program11.tcl

OUTPUT

110
6.12 PROGRAM 12 – Creation of nodes at random destination at particular time interval
using AODV routing protocol TCL script

Program Discription

Number of nodes in the network is not static and is declared as six in the network. Nodes
are configured in the mobile wireless node format. Number of nodes construction is given during
the run time of the program. The user should give the number of nodes in the terminal window
during the execution of the program. Procedure for the creation of nam file and trace file is given
and is followed by the topology creation. Localization of the network is static. X and Y
coordinates values are given in the program and the Z coordinates are always remains zero.
Movement for each and every node is built with static speed and spectifed receiver address
which is randomly generated and also the detination location will get change accoding to the
time period.

File Name – program12.tcl

111
112
113
Procedure to run the program in the terminal window - $ns program12.tcl

OUTPUT

6.13 PROGRAM 13 – Creation of nodes destination and random coloring using AODV
routing protocol TCL script

Program Discription

Number of nodes in the network is not static and is declared as eight in the network.
Nodes are configured in the mobile wireless node format. Number of nodes construction is given
during the run time of the program. The user should give the number of nodes in the terminal
window during the execution of the program. Procedure for the creation of nam file and trace file
is given and is followed by the topology creation. Localization of the network is static. X and Y
coordinates values are given in the program and the Z coordinates are always remains zero.
Movement for each and every node is built with static speed and spectifed receiver address
which is randomly generated and also the detination location will get change accoding to the
time period. Here initial size of each and every node is created by the use of the command
(initial_node_pos). Routing protocol is AODV and the stop time of the simulation is 10ms. Here
each and every group of the nodes is constructed with different type of colors.

File Name – program13.tcl

114
115
116
Procedure to run the program in the terminal window - $ns program13.tcl

OUTPUT

117
6.14 PROGRAM 14 – Creation of nodes with the initial and destination position in random
manner using AODV routing protocol TCL script

Program Discription

Number of nodes in the network is not static and is declared as eight in the network.
Nodes are configured in the mobile wireless node format. Procedure for the creation of nam file
and trace file is given and is followed by the topology creation. Localization of the network is
static. X and Y coordinates values are given in the program and the Z coordinates are always
remains zero.

Movement for each and every node is built with static speed and spectifed receiver
address which is randomly generated and also the detination location will get change accoding to
the time period. Here initial size of each and every node is created by the use of the command
(initial_node_pos). Routing protocol is AODV and the stop time of the simulation is 10ms. Here
each and every group of the nodes is constructed with different type of colors.

File Name – program14.tcl

 Channel – Wireless Channel


 Propagation – Two Ray Ground Propagation
 Queue Type – Drop Tail
 Antenna – Omni Directional Antenna
 Routing Protocol –AODV
 Simulation Time – 18ms
 Number of nodes – 8 nodes
 X dimension – 500
 Y dimension – 400
 Initial Node Position - 30

118
119
120
Procedure to run the program in the terminal window - $ns program14.tcl

OUTPUT

121
6.15 PROGRAM 15 – Creation of graphs with X dimension and Y Dimension constructed
randomly using AODV routing protocol TCL script

Program Discription

Number of nodes in the network is static and is declared as three in the network.
Procedure for the creation of nam file and trace file is given and is followed by the topology
creation. Localization of the network is static. X and Y coordinates values are given in the
program and the Z coordinates are always remains zero. Graph is randomly generated using the
X and Y dimensions and is programmed to generate the trace file accordingly. Here the trace file
acts as a input file to plot the graph in the format of trace file. Routing protocol is AODV and the
stop time of the simulation is 10ms.

File Name – program15.tcl

 Channel – Wireless Channel


 Propagation – Two Ray Ground Propagation
 Queue Type – Drop Tail
 Antenna – Omni Directional Antenna
 Routing Protocol –AODV
 Simulation Time – 10ms
 Initial Node Position - 30

122
123
124
Procedure to run the program in the terminal window - $ns program15.tcl

OUTPUT

6.16 PROGRAM 16 – Creation of graphs with two parameters as inputs using AODV
routing protocol TCL script

Program Discription

Number of nodes in the network is static and is declared as three in the network.
Procedure for the creation of nam file and trace file is given and is followed by the topology
creation. Localization of the network is static. X and Y coordinates values are given in the
program and the Z coordinates are always remains zero. Graph is randomly generated using the
X and Y dimensions and is programmed to generate the trace file accordingly. The trace file acts
as input file to plot the graph in the format of trace file. Here single plotted graph consist of two
trace file values. Different colors are given to each trace file during plotting. Routing protocol is
AODV and the stop time of the simulation is 10ms.

File Name – program16.tcl

125
126
127
Procedure to run the program in the terminal window - $ns program16.tcl

OUTPUT

6.17 PROGRAM 17 – Creation of graphs with more than two parameter files as inputs
using AODV routing protocol TCL script

Program Discription

Number of nodes in the network is static and is declared as three in the network.
Procedure for the creation of nam file and trace file is given and is followed by the topology
creation. Localization of the network is static. X and Y coordinates values are given in the
program and the Z coordinates are always remains zero. Graph is randomly generated using the
X and Y dimensions and is programmed to generate the trace file accordingly. The trace file acts
as input file to plot the graph in the format of trace file. Here single plotted graph consist of more
than two trace file values. Different colors are given to each trace file during plotting. Routing
protocol is AODV and the stop time of the simulation is 10ms.

File Name – program17.tcl

128
129
130
Procedure to run the program in the terminal window - $ns program17.tcl

OUTPUT

131

You might also like