Manual For Network Simulator
Manual For Network Simulator
No: 1: Date :
Study of Network Simulator Tools
Aim:
To study of different Network Simulation Tools for constructing and performance
testing in different network.
Introduction:
Simulation is a very important modern technology. It can be applied to different
science, engineering, or other application fields for different purposes. Computer assisted
simulation can model hypothetical and real-life objects or activities on a computer so that it
can be studied to see how the system function. Different variables can be used to predict
the behavior of the system. Computer simulation can be used to assist the modeling and
analysis in many natural systems. Typical application areas include physics, chemistry,
biology, and human-involved systems in economics, finance or even social science. Other
important applications are in the engineering such as civil engineering, structural
engineering, mechanical engineering, and computer engineering. Application of simulation
technology into networking area such as network traffic simulation.
Page 1 of 80
• OPNET (Optimized Network Evaluation Tool):
OPNET 's software environment is called Modeler, which is specialized for network
research and development. It can be flexibly used to study communication networks,
devices, protocols, and applications. Because of the fact of being a commercial software
provider, OPNET offers relatively much powerful visual or graphical support for the users.
The graphical editor interface can be used to build network topology and entities from the
application layer to the physical layer. Object-oriented programming technique is used to
create the mapping from the graphical design to the implementation of the real systems. An
example of the graphical GUI of OPNET can be seen in Figure 1. We can see all the topology
configuration and simulation results can be presented very intuitively and visually. The
parameters can also be adjusted and the experiments can be repeated easily through easy
operation through the GUI.
Main features:
OPNET inherently has three main functions: modeling, simulating and analysis. For
modeling, it provides intuitive graphical environment to create all kinds of models of
protocols. For simulating, it uses three different advanced simulations technologies and
can be used to address a wide range of studies. For analysis, the simulation results and
data can be analyzed and displayed very easily. User friendly graphs, charts, statistics, and
even animation can be generated by OPNET for users ' convenience.
Page 2 of 80
• Network Simulator 2 (NS2)
NS2 is one of the most popular open source network simulators. The original NS is a
discrete event simulator targeted at networking research. NS2 is the second version of NS
(Network Simulator). NS is originally based on REAL network simulator. The first version
of NS was developed in 1989 and evolved a lot over the past few years. The current NS
project is supported through DARPA. The current second version NS2 is widely used in
academic research and it has a lot of packages contributed by different non-benefit
groups. An example of the graphical GUI of NS2 can be seen in Figure 2.
Main features:
First and foremost, NS2 is an object-oriented, discrete event driven network
simulator which was originally developed at University of California-Berkely. The
programming it uses is C++ and OTcl (Tcl script language with Object-oriented extensions
developed at MIT). The usage of these two programming language has its reason. The
biggest reason is due to the internal characteristics of these two languages. C++ is efficient
to implement a design but it is not very easy to be visual and graphically shown. It's not
easy to modify and assembly different components and to change different parameters
without a very visual and easy-to-use descriptive language. Moreover, for efficiency reason,
NS2 separates control path implementations from the data path implementation. The event
scheduler and the basic network component objects in the data path are written and
compiled using C++ to reduce packet and event processing time. OTcl happens to have the
feature that C++ lacks. So the combination of these two languages proves to be very
effective. C++ is used to implement the detailed protocol and OTcl is used for users to
control the simulation scenario and schedule the events. A simplified user's view of NS2 is
shown in Figure 3. The OTcl script is used to initiate the event scheduler, set up the
Page 3 of 80
network topology, and tell traffic source when to start and stop sending packets through
event scheduler. The scenes can be changed easily by programming in the OTcl script.
When a user wants to make a new network object, he can either write the new object or
assemble a compound object from the existing object library, and plumb the data path
through the object. This plumbing makes NS2 very powerful.
• OMNeT++
OMNeT++ has generic and flexible architecture which makes it successful also in
other areas like the IT systems, queuing networks, hardware architectures, or even
business processes as well. It is similar with NS2 and NS3, OMNeT++ is also a public-
source, component-based network simulator with GUI support. Its primary application
area is communication networks. Like NS2 and NS3, OMNeT++ is also a discrete event
simulator. It is a component-based architecture. Components are also called modules and
are programmed in C++. The components are then assembled into larger components and
models by using a high-level language. Its function is similar to that of OTcl in NS2 and
Python in NS3. OMNeT++ also provides GUI support, and due to its modular architecture,
the simulation kernel can be embedded into all kinds of different user s' applications.
Figure 5 is an OMNeT++ GUI screenshot.
Page 4 of 80
Figure 5. OMNeT++ GUI
Main features:
Since OMNeT++ is designed to provide a component-based architecture, the models
or modules of OMNeT++ are assembled from reusable components. Modules are reusable
and can be combined in various ways which is one of the main features of OMNeT++.
Page 5 of 80
• GloMoSim facilitates the ability to use in a parallel environment which distinguishes
it from most other wireless network simulators.
• It allows the simulation Scalability to simulate net-works with a hundred and
thousand of nodes.
• It supports various layers like Mobility, Radio Propagation, Radio Model, Packet
reception models, Data Link, Network (Routing), Transport and Ap-plication. i.e. (It
supports almost all the OSI layers with limited benefits).
• GloMoSim supports direct satellite communication, multi-hop wireless
communication and most of the traditional internet protocols.
• It facilitates to build a library of parallelized mod-els that can be used for the
evaluation of a varie-ty of wireless network protocols.
• NetSim
NetSim is a stochastic discrete event network simula-tiontool used for network lab
experimentation and research. Its leading network simulation software for protocol
modeling and simulation, allowing us to ana-lyze computer networks with unmatched
depth, power and flexibility. NetSim comes with an in-built develop-ment environment,
which serves as the interface be-tween User’s code and NetSim’s protocol libraries and
simulation kernel. It provides network performance metrics at various abstraction levels
such as Network, sub-network, Node and a detailed packet trace. It has unique features and
functionality. NetSimis available as Standard or Academic versions and is built on a com-
mon design framework of high level architecture and code. In a word, NetSim is truly a
fantastic product that is not only versatile, but also robust and provides those features that
are hard to come with any simulators.
Features:
• NetSim modeling and simulation are supported for Aloha, Slotted Aloha, Token
Ring/Bus, Ethernet CSMA/CD, Fast and Gigabit Ethernet, WLAN - IEEE 802.11
a/b/g/n and e, X.25, Frame Relay, TCP, UDP, IPv4 and IPv6, Routing - RIP, OSPF,
BGP,MPLS, Wi-Max, MANET, GSM, CDMA, Wire-less Sensor Network, Zigbee,
Cognitive radio.
• It simulates a wide variety of Cisco routers, including 2500 series, 2600 series, 2800
series, and 3600 series routers, as well as the Cisco Catalyst 1900 series, 2900
series, and 3500 series switches.
• Protocol libraries are available as open C code for user modification. This can help
avoid the time consuming process of programming, customization and configuration
commercial simulators to meet customer specific needs.
• Along with the Boson Virtual Packet Technology engine NetSim utilizes Boson’s
proprietary Network Simulator, Router Simulator, and EROUTER soft-ware
technologies, to create individual packets. These packets are routed and switched
through the simulated network, allowing NetSim to build an appropriate virtual
routing table and simulate true networking. Other simulation products on the mar-
ket do not support this level of functionality.
• It can be used to create a simulation of the topology of corporate network and help
practice trouble-shooting without using devices on the production network.
Page 6 of 80
Comparison of simulators based on General Information
SI.
Name LicenseType Language SupportedOperating GUI port
1 Ns2 Open source C++ and OTCL GNU/Linux,FreeBS Limited
D, Mac OS X, Win-
dows XP, Windows
Vista and Win. 7.
2 Ns3 Open source C++and GNU/Linux,FreeBS Yes
Optional D, Mac OS X, Win-
Python dows XP, Windows
Bindings Vista and Win. 7.
3 QualNet Commercial C++ UNIX, Window, MAC, Yes
(Separatelicenseforacademi Linux
ciansand others)
4 GloMoSim Open source C Windows, Linux, Limited
SunSPARCSolaris
5 NetSim Proprietary C and Windows (7, Vista) Yes
Java and windowsXP
6 OMNET++ Open source(for studyand C++ WindowsXPorLater,Linu Yes
research x,MacOSX,
Number of
Simulation Event
SI. Name Available Module Scalability node Parallelism
Type
support
Wired,Wireless, Up
Discrete-
1 NS2 AdHoc and Wireless Limited to No
event
Sensor Networks 3000
Wired,Wireless, Up
Discrete-
2 NS3 Adhoc and Wireless Limited to No
event
Sensor Networks 3000
Wired
&Wireless(like WiFi,
Yes(S MP/Be
3 QualNet Discrete- event Sensor net- Large 500-20000
owulf
work,MANET,WI
MAX)network
Wired, Wireless &
Yes(S
Discrete- Ad-Hoc Networks. Up to
4 GloMoSim Large MP/Be
event But currently pure 10,000
owulf
wireless support
5 NetSim Stochastic Wired &Wireless, Large ------- -------
Page 7 of 80
Discrete- sensor network Enough
Event
Discrete- Wired, Wireless, Ad-
6 OMNET++ (wireless LAN, hoc and WSN. Enough -------- MPI/P
WiMAX)
Result:
Page 8 of 80
Ex. No: 2 Date:
Aim:
To install the NS2 software and test it with simple example on Ubuntu Operating
System.
Download the all in one package for ns2 from internet. The package downloaded
will be named "ns-allinone-2.35.tar.gz". Copy it to the home folder. Then in a terminal use
the following two commands to extract the contents of the package:
• Ns2 requires a few packages to be pre installed. It also requires the GCC- version
4.3 to work correctly. So install all of them by using the following command:
• Once the installation is over, we have to make a change in the "ls.h" file. Use the
following steps to make the changes: Navigate to the folder "linkstate", use the
following command. Here it is assumed that the ns folder extracted is in the
home folder of your system.
cd ~/ns-allinone-2.35/ns-2.35/linkstate
• Now open the file named "ls.h" and scroll to the 137th line. In that change the
word "error" to "this->error". The image below shows the line 137
(highlighted in the image below) after making the changes to the ls.h file. To
open the file use the following command:
Page 9 of 80
gedit ls.h
• In the file, change Change CC= @CC@ to CC=gcc-4.4, as shown in the image
below:
Page 10 of 80
• Save that file and close it.
Step 3: Installation
• Now we are ready to install ns2. To do so we first require root privileges and
then we can run the install script. Use the following two commands:
cd ns-allinone-2.35
./install
• After successful installation following message will be shown on the screen.
Ns-allinone package has been installed successfully.
Ns-allinone package has been installed successfully.
Here are the installation places:
tcl8.5.10: /home/sitams/ns-allinone-2.35/{bin,include,lib}
tk8.5.10: /home/sitams/ns-allinone-2.35/{bin,include,lib}
otcl: /home/sitams/ns-allinone-2.35/otcl-1.14
tclcl: /home/sitams/ns-allinone-2.35/tclcl-1.20
ns: /home/sitams/ns-allinone-2.35/ns-2.35/ns
nam: /home/sitams/ns-allinone-2.35/nam-1.15/nam
xgraph: /home/sitams/ns-allinone-2.35/xgraph-12.2
gt-itm: /home/sitams/ns-allinone-2.35/itm, edriver, sgb2alt, sgb2ns,
sgb2comns, sgb2hierns
----------------------------------------------------------------------------------
Please put /home/sitams/ns-allinone-2.35/bin:/home/sitams/ns-
allinone-2.35/tcl8.5.10/unix:/home/sitams/ns-allinone-
2.35/tk8.5.10/unix
Page 11 of 80
into your PATH environment; so that you'll be able to run
itm/tclsh/wish/xgraph.
IMPORTANT NOTICES:
After these steps, you can now run the ns validation suite with
cd ns-2.35; ./validate
• Lines to be added:
# LD_LIBRARY_PATH
OTCL_LIB=/home/sitams/ns-allinone-2.35/otcl-1.14
NS2_LIB=/home/sitams/ns-allinone-2.35/lib
X11_LIB=/usr/X11R6/lib
USR_LOCAL_LIB=/usr/local/lib
export
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$OTCL_LIB:$NS2_LIB:$X11_LIB:$USR_
LOCAL_LIB
# TCL_LIBRARY
TCL_LIB=/home/sitams/ns-allinone-2.35/tcl8.5.10/library
USR_LIB=/usr/lib
export TCL_LIBRARY=$TCL_LIB:$USR_LIB
Page 12 of 80
# PATH
XGRAPH=/home/sitams/ns-allinone-2.35/bin:/home/sitams/ns-allinone-
2.35/tcl8.5.10/unix:/home/sitams/ns-allinone-2.35/tk8.5.10/unix
#the above two lines beginning from xgraph and ending with unix should
come on the same line
NS=/home/sitams/ns-allinone-2.35/ns-2.35/
NAM=/home/sitams/ns-allinone-2.35/nam-1.15/
PATH=$PATH:$XGRAPH:$NS:$NAM
• Once the changes have been made, save the file and restart the system.
ns
• System returns
%
Step 6: Testing ns2
Test the addition of two integer numbers.
% set a 10
10
% set b 20
20
% expr $a+$b
30
%
Result :
NS2 software has been successfully installed and it’s tested with simple example on
Ubuntu Operating System.
Page 13 of 80
Ex. No: 3 Date:
Study of TCL Commands
Aim:
To study the various TCL Commands.
Introduction:
TCL is an interpreted language. Each instruction is a command in tcl program. TCL
programming is used to write simulation script in ns2. Following are the topics which you
need to learn in order to write simulation script.
Topics:
• Variables in TCL
• Basic Operations
• If-else
• Loop
• Array
• Procedure
• File Handling
• Variables in TCL
• set command
set command is used to make a variable and assign value to them. This
command is also used to fetch value of variable.
Syntax :
set <variable_name><variable_value>
set x 100
//creating a integer variable with name ‘x’ and value ‘10’
set name "sitams"
//creating a string variable with name ‘name’ and value ‘sitams’
set price 120.5
//creating a float variable with name ‘price’ and value ‘120.5’
• unset command
unset command is used to delete a variable.
Page 14 of 80
Syntax :
unset <variable_name>
Example:
unset x
Before unset x:
set x
100
After unset x:
set x
can't read "x": no such variable
Example:
gets stdin x
Enter the value of x: 20
Example:
set x 20 // creating a integer variable with name ‘x’ and value ‘20’
set y $x // assign value of x variable to another variable y.
set y // The system returns value of y, i.e 20
Page 15 of 80
Example:
Simple Program:
set x 10
set y 20
puts "value of x is $x"
puts "value of y is $y"
Output:
value of x is 10
value of y is 20
• Basic Operations
In tcl expr command used to perform operations. expr command takes entire
expression as arguments.
Syntax :
expr $<variable_name> + $<variable_name>
Output: 30
Page 16 of 80
gets stdin r
set pie [expr 22/7]
set area [expr $r*$r*$pie]
puts "Area of circle: $area"
Ouput:
csm@ubuntu:~$ ns ss.tcl
Enter the radius :
2
Area of circle: 12
• If statements:
TCL also has construct for if statements.
• Simple if statement
Syntax:
if {condition} {
statement_block
}
statement_x
Another syntax:
if [ expr condition] {
statement_block
}
statement_x
Output:
Page 17 of 80
csm@ubuntu:~$ ns ss1.tcl
x is less than 50
x is greater than 50
Output:
csm@ubuntu:~$ ns ss1.tcl
x is greater than 50
• if –else statement
Syntax:
if {condition} {
statement_true_block
} else {
statement_false_block
}
Program:
gets stdin x
if { $x < 50 } {
puts "x is less than 50"
} else {
puts "x is greater than 50"
}
Output:
csm@ubuntu:~$ ns ss1.tcl
10
x is less than 50
Page 18 of 80
csm@ubuntu:~$ ns ss1.tcl
100
x is greater than 50
• if-elseif statement
Syntax:
if {condition1} {
statement_true_block 1
} elseif {condition2} {
statement_false_block2
} else {
statement_false_block
}
In this syntax if condition is true, the first True block statements will
be executed; otherwise check the another condition, if condition2 is true, the
second true block statements will be executed, otherwise False block
statement will be executed.
Program:
gets stdin a
gets stdin b
gets stdin c
if { $a>=$b && $a>=$c} {
puts "A is Biggest"
} elseif {$b>=$a && $b>=$c} {
puts "B is Biggest"
} else {
puts "C is Biggest"
}
Output:
csm@ubuntu:~$ ns ss1.tcl
4
3
2
A is Biggest
• switch statement
Page 19 of 80
A switch statement allows a variable to be tested for equality against a list of
values. Each value is called a case, and the variable being switched on is checked for
each switch case.
Syntax:
switch switchingString {
matchString1 { body1 }
matchString2 { body2 }
...
matchStringn { bodyn }
}
Program:
gets stdin grade
switch $grade {
A { puts "Well done!" }
B { puts "Excellent!" }
C {puts "You passed!" }
F {puts "Better try again"}
default {puts "Invalid grade" }
}
puts "Your grade is $grade"
Output:
csm@ubuntu:~$ ns ss1.tcl
A
Well done!
Your grade is A
csm@ubuntu:~$ ns ss1.tcl
B
Excellent!
Your grade is B
csm@ubuntu:~$ ns ss1.tcl
R
Invalid grade
Your grade is R
• Loop Statements
• while loop
A while loop statement in Tcl language repeatedly executes a target
statement as long as a given condition is true.
Syntax:
while {condition} {
statement(s)
Page 20 of 80
}
Program:
set a 0
while { $a < 10 } {
puts "value of a: $a"
incr a
}
Output:
csm@ubuntu:~$ ns ss1.tcl
value of a: 0
value of a: 1
value of a: 2
value of a: 3
value of a: 4
value of a: 5
value of a: 6
value of a: 7
value of a: 8
value of a: 9
• for loop
A for loop is a repetition control structure that allows you to efficiently write
a code that needs to be executed for a specific number of times.
Syntax:
for {initialization} {condition} {increment} {
statement(s);
}
Program:
for { set a 0} {$a < 10} {incr a} {
puts "value of a: $a"
}
Output:
csm@ubuntu:~$ ns ss1.tcl
value of a: 0
value of a: 1
value of a: 2
Page 21 of 80
value of a: 3
value of a: 4
value of a: 5
value of a: 6
value of a: 7
value of a: 8
value of a: 9
• Array
Array is a collection of homogeneous data. TCL also support named array in which
string is given as named variable.
Syntax:
set ArrayName(Index) value
Program:
set a(0) 10
set a(1) 30
puts $a(0)
// Another Way
array set b {10,30}
puts $b(0)
Output: 10
• Procedure
Multiple commands can be combined to make a new command. This can be done by
making a procedure.
Syntax:
proc <procedure name> { } {
procedure-body
}
Program:
proc fact { a } {
set fact 1
for {set i 1} {$i <= $a} {incr i} {
set fact [expr $fact * $i]
}
puts "factorial Value is :$fact"
}
fact 5
Page 22 of 80
• File Handling
Before performing any operation on file, that file needs to be opened. In tcl open
command is used to open a channel with file to perform read/write operation. File can
be opened in various modes which allow which operation is allowed. These modes are
• Read only Mode (r)
• Write Only Mode (w)
• Append Mode (a)
• Read and Write (r+)
• Write and Read (w+)
• Opening File
Syntax:
open <file_name><acc_type>
Example:
open one.txt r
Example:
set f [open one.txt w]
puts $f "welcome to tcl"
close $f
• Reading File - gets command is used for reading data from file.
Syntax:
gets <file_handle><variable_value>
Example:
set f [open one.txt r]
gets $f data
puts $data
close $f
Result:
Page 23 of 80
Ex No:4 Date:
ALGORITHM:
1.start
2.create a simulator object with name ns
3.create a trace objects with name nt
4. create a nam object nf
5.create 4 nodes with names n0,n1,n2,n3
6.connect the link between nodes n0 n2, n1 n2, and n2 n3
7.give the nodes a standard position
8.create a udp agent udp0 and udp1 and attach it to n0 and n1
9.a CBR traffic source cbr0 and cbr1 are created and attach it to udp0 and udp1
10.a null agent is created n0 and attach it nodes n2 and n3
11.connect the traffic source with traffic sink
12.schedule events for cbr agent
13.write finish procedure
14.call the finish procedure
15.now run the simulation
16. stop
PROGRAM:
Page 25 of 80
OUTPUT:
RESULT:
Thus the program for creating simple scenario of creating four nodes had been
executed successfully.
Page 26 of 80
Ex No: 5 Date:
AIM:
To create a simple TCP scenario with droptail queue mechanism on the gateway
ALGORITHM:
1.start
2.create a simulator object ns
3.create a trace object nt
4.create a nam object nf
5.create a 4 nodes
6.create link between nodes and create node orientation
7.create a queue between n2 and n3
8.set a TCP coonection for n0 over ftp
9.set up a UDP connection for n2 over CBR
10.set up a null agent for n3
11.write finish procedure
12.run the program
PROGRAM:
OUTPUT:
Page 29 of 80
RESULT:
Thus the program for simple TCP scenario with dropTail queue mechanism had
been executed successfully.
Page 30 of 80
Ex No:6 Date:
AIM:
To write a program to create a new agent called MyAgent.
Algorithm:
1.create a class MyAgent and take n1,n2 as private and methods such as
command,multiply,show as protected and a constructor MyAgent as public.
2.create a class MyAgentclass.
3.create a tcl object and return.
4.set up connections and take inputn1,n2.
5.if argc==4 then argv[1] is "sum" then add n1,n2.
6.if argc==2 then argv[1] is "sub" then n1-n2.
7.if argv[1] is "mul" then call multiply function.
8.in multiply() scan n1,n1 values from keyboard and perform n1*n2.
9.display output.
10.stop.
PROGRAM:
C ++ Program for attaching new agent:
#include "agent.h" //Available in the path of NS2
#include<stdio.h>
class MyAgent:public Agent
{
private:
int n1,n2;
protected:
int command(int argc,const char* const* argv);
void multiply();
void show();
public:
MyAgent();
};
static class MyAgentClass : public TclClass
{
public:
MyAgentClass():TclClass("Agent/MyAgent")
{}
TclObject * create(int,const char* const*) // To use the above MyAgent as constant name
use this line
{
return (new MyAgent());
}}
//Shadow object
Page 31 of 80
//When a TCL object is been called, the C++ class will retuen an agent. If agent is
//Not present, it shows a failed shadow object error.
class_MyAgent;
➢ create a new folder in ‘ns-allinone-2.35/ns-2.35’ with name ‘test’ and save the above
file
with name ‘MyAgent.cc’ in test folder
➢ Again go to ns-allinone-2.35/ns-2.35 and then open makefile in this file after the line
164 insert “test/MyAgent.o \” . ensure that there should not be any extra blank spaces
after “\” open the terminal and type the following commands:
$ cd ns-allinone-2.35/ns-2.35
$ make clean
for i in indep-utils/cmu-scen-gen/setdest in…...…...ns.core core core.ns core.nsx core.nse
common/ptypes2tcl common/ptypes2tcl.o
$ make
gcc -c -Wall -Wno-write-strings -DTCP_DELAY_BIND_ALL -DNO_TK -
DTCLCL_CLASSINSTVAR
-DNDEBUG -DLINUX_TCP_HEADER -DUSE_SHM -DHAVE_………..
-Wall -Wno-write-strings -DCPP_NAMESPACE=std -o ucb-tr-stat tr-stat.o logparse.o utils.o
-L/home/mallesh/ns-allinone-2.35/lib -ltcl8.5 -lnsl -ldl -lm
make[1]: Leaving directory '/home/mallesh/ns-allinone-2.35/ns-2.35/indep-
utils/webtrace-conv/ucb'
$ su
Password:****
root@ubuntu:ns-allinone-2.35/ns-2.35# make install
TCL Script:
Page 33 of 80
OUTPUT:
10+20=30
The value of n1=10
The value of n2=20
5-2=3
The value of n1=5
The value of n2=2
Enter n1,n2 values:
10
20
10*20=200
The value of n1=10
The value of n2=20
RESULT:
Thus the program for creating new agent called MyAgent using c++ has been
executed successfully.
Page 34 of 80
Ex No: 7 Date:
AIM:
To create a new protocol for ping using c++ program.
ALGORITHM:
1.start
2.create a structure named MyPingHeader.
3.write header access methods.
4.create class MyPingHeader and MyPingclass.
5.in MyPingAgent create a new packet ie
Packet *pkt=allocPkt()
6.access the ping header for new packet.
7.store the time in send_time filed and send packet.
8.access ip header for received packet.
9.if flag field is 0 then send an echo and discard the packet and create a new packet and
access ping header for new packet.
10.else display the nodes received ping answer from another and free all packets.
11.stop.
PROGRAM:
C ++ Program for implementation of PING Protocol:
#include "agent.h"
#include "tclcl.h"
#include "packet.h"
#include "address.h"
#include "ip.h"
#include<stdio.h>
struct MyPingHeader
{ char flag;
double send_time;
static int offset_;
inline static MyPingHeader* access(const Packet* p)
{
return (MyPingHeader*) p->access(offset_);
}}
;
class MyPingAgent : public Agent
{
public:
MyPingAgent();
protected:
int command(int argc,const char*const* argv);
Page 35 of 80
void recv(Packet*,Handler*);
};
int MyPingHeader::offset_;
static class MyPingHeaderClass : public PacketHeaderClass
{
public:
MyPingHeaderClass():PacketHeaderClass("PacketHeader/MyPing",sizeof(MyPingHeader))
{
bind_offset(&MyPingHeader::offset_);
}}
class_pinghdr;
static class MyPingClass:public TclClass
{
public:
MyPingClass():TclClass("Agent/MyPing")
{}
TclObject * create(int,const char*const*)
{
return (new MyPingAgent());
}
}class_ping;
MyPingAgent::MyPingAgent() : Agent(PT_PING)
{}
int MyPingAgent::command(int argc,const char*const* argv)
{ if(argc==2)
{ if(strcmp(argv[1],"send")==0)
{
Packet *pkt=allocpkt();
MyPingHeader *hdr=MyPingHeader::access(pkt);
hdr->flag=0;
hdr->send_time=Scheduler::instance().clock();
send(pkt,0);
return(TCL_OK);
}}
return (Agent::command(argc,argv));
}
void MyPingAgent::recv(Packet *pkt,Handler*)
{
hdr_ip* iphdr=hdr_ip::access(pkt);
MyPingHeader* pinghdr=MyPingHeader::access(pkt);
if(pinghdr->flag==0)
{
double stime=pinghdr->send_time;
Packet::free(pkt);
Packet* pktret=allocpkt();
MyPingHeader* hdrret=MyPingHeader::access(pktret);
Page 36 of 80
hdrret->flag=1;
hdrret->send_time=stime;
send(pktret,0);
} else
{
double rtt=Scheduler::instance().clock()-pinghdr->send_time;
printf("node %d received ping answer from node %d with round-trip-time=%1f rtt
seconds\n",iphdr-
>src_.addr_,iphdr->dst_.addr_,rtt);
Packet::free(pkt);
}}
➢ create a new folder in ‘ns-allinone-2.35/ns-2.35’ with name ‘Ping’ and save the above
file with name ‘MyPing.cc’ in test folder
➢ Again go to ns-allinone-2.35/ns-2.35 and then open makefile in this file after the line
164
insert “Ping/MyPing.o \” . ensure that there should not be any extra blank spaces after “\”
open the terminal and type the following commands:
$ cd ns-allinone-2.35/ns-2.35
$ make clean
for i in indep-utils/cmu-scen-gen/setdest in…...…...ns.core core core.ns core.nsx core.nse
common/ptypes2tcl common/ptypes2tcl.o
$ make
gcc -c -Wall -Wno-write-strings -DTCP_DELAY_BIND_ALL -DNO_TK -
DTCLCL_CLASSINSTVAR
-DNDEBUG -DLINUX_TCP_HEADER -DUSE_SHM -DHAVE_………..
-Wall -Wno-write-strings -DCPP_NAMESPACE=std -o ucb-tr-stat tr-stat.o logparse.o utils.o
-L/home/mallesh/ns-allinone-2.35/lib -ltcl8.5 -lnsl -ldl -lm
make[1]: Leaving directory '/home/mallesh/ns-allinone-2.35/ns-2.35/indep-
utils/webtrace-conv/ucb'
$ su
Password:****
root@ubuntu:ns-allinone-2.35/ns-2.35# make install
TCL Script:
Page 37 of 80
$ns attach-agent $n1 $p1
$ns connect $p0 $p1
$ns at 1 "$p0 send"
$ns at 3 "$p0 send"
$ns at 5 "$p0 send"
$ns at 7 "$p0 send"
$ns at 10.0 "$ns halt"
$ns run
OUTPUT:
node 1 received ping answer from node 0 with round-trip-time=2.000000 rtt seconds
node 1 received ping answer from node 0 with round-trip-time=2.000000 rtt seconds
node 1 received ping answer from node 0 with round-trip-time=2.000000 rtt seconds
node 1 received ping answer from node 0 with round-trip-time=2.000000 rtt seconds
RESULT:
Thus the program for creating a new protocol called ping has been executed
successfully.
Page 38 of 80
Ex No: 8 Date:
DIJKSTRA'S ALGORITHM
AIM:
To write a C program for implementation of dijkstras algorithm.
ALGORITHM:
1.start
2.Enter number of nodes and read the cost matrix from the keyboard.
3.for(j=0;j<n;j++) then do
3.1:for(i=0;i<n;i++) then do
3.1.1: d[i]=c[j][i] end for
3.2.d[n]=30000
3.3.dijkstra(c,d,j,n)
3.4.Display the shortest path from node j
3.5.end for
4.free(c)
5.free(d)
6.stop
Program:
Page 39 of 80
{
min=n;
for(i=0;i<n;i++)
if(d[i]<=d[min]&&v[i]!=1)
min=i;
v[min]=1;
for(i=0;i<n;i++)
if(v[i]==0)
d[i]=minimum(d[i],d[min]+c[min][i]);
}
free(v);
} int main()
{ int **c,*d,sn,n,i,j,t;
printf("enter the number of nodes:\n");
scanf("%d",&n);
c=(int**)calloc(n,sizeof(int*));
for(i=0;i<n;i++)
c[i]=(int*)calloc(n,sizeof(int));
d=(int*)calloc(n+1,sizeof(int));
printf("enter the cost matrix:\n");
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{s
canf("%d",&t);
(t==-1)?(c[i][j]=30000):(c[i][j]=t);
}
printf("the shortest path from all %d nodes:\n",n);
for(j=0;j<n;j++)
{
for(i=0;i<n;i++)
d[i]=c[j][i];
d[n]=30000;
digikstra(c,d,j,n);
for(i=0;i<n;i++)
printf("%d ",((d[i]>=10000)?-1:d[i]));
printf("\n");
}
free(c);
free(d);
}
Page 40 of 80
Output:
Result:
Thus the program for finding shortest path using dijkstra’s has been executed
successfully.
Page 41 of 80
Ex No: 9 Date:
Page 42 of 80
{
flag[v]=0;
last[v]=src_router;
dist[v]=cost_matrix[src_router][v];
}
flag[src_router]=1;
for(i=0;i<count;i++)
{
min=1000;
for(w=0;w<count;w++)
{
if(!flag[w])
if(dist[w]<min)
{
v=w;
min=dist[w];
}
}
}
flag[v]=1;
for(w=0;w<count;w++)
if(!flag[w] && min+cost_matrix[v][w]<dist[w])
{
dist[w]=min+cost_matrix[v][w];
last[w]=v;
}
printf(“the shortest path from %d to remaining nodes is:\n”,src_router);
for(i=0;i<count;i++)
{
w=i;
while(w!=src_router)
w=last[w];
printf("\n %d----→%d:%d",src_router,i,dist[i]);
}
}
Page 43 of 80
OUTPUT :
Enter the no of routers
4
Enter the cost matrix values:
0 -1 2 6
-1 0 5 8
2502
6820
Enter the source router: 0
the shortest path from 0 to remaining nodes is:
0----->0 : 0
0----->1:7
0----->2:2
0----->3 :4
RESULT:
Thus the program for finding shortest distance using link state packets has been
executed successfully.
Page 44 of 80
Ex No:10 Date:
Aim:
To write a C program to print the number of packets dropped,sent,received.
Algorithm:
1.start
2.open main()
3.open the file using file pointer in read mode.
4.Declare float variables drop=0,received=0,sent=0,throughput=0 and character variable
char ch;
5.while((ch=getc(f)!=EOF) then
5.1:if(ch==’d’)
++drop;
5.2:if(ch==’r’)
++received;
6.while(getc(f)!=’\n’) the empty loop
7.Calculate sent packet,throughput and print them on the screen.
8.stop
program:
BEGIN {
r=d=0
}
{
if ( $1 == "r" )
++r
else if ( $1 == "d" )a
++d
}
END {
printf("received=%d,dropped=%d,sent=%d,throughput=%f\n",r,d,r+d,r/(r+d));
}
Page 45 of 80
OUTPUT :
throughput
1.2
0.8
0.6
0.4
0.2
0
1 2 3 4 5 6 7 8 9 10
RESULT:
Thus the program for analyzing the trace file using awk program has been executed
successfully.
Page 46 of 80
Ex No:11 Date:
LAN SIMULATION
AIM:
To write a TCL script for lan simulation.
ALGORITHM:
1.Start
12.Create a TCP sink and attach to n2,n3,n4 and connect sink1 to tcp0.
15.Create a null agent null0 and attach to n2,n3,n4 and connect to udp0.
21.Create a null agent null and attach to n3,n4 and connect to udp1.
Page 47 of 80
22.Schedule events for the CBR and FTP agents.
26.Stop.
program:
Page 48 of 80
$ns attach-agent $n(6) $tcp6
$tcp6 set fid_ 103
set cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $udp0
$cbr0 set packetSize_ 1000
$cbr0 set interval_ 0.005
set cbr7 [new Application/Traffic/CBR]
$cbr7 attach-agent $udp7
$cbr7 set packetSize_ 1000
$cbr7 set interval_ 0.005
set null4 [new Agent/Null]
$ns attach-agent $n(4) $null4
set ftp1 [new Application/FTP]
$ftp1 attach-agent $tcp1
$ftp1 set packetSize_ 2000
$ftp1 set interval_ 0.001
set ftp6 [new Application/FTP]
$ftp6 attach-agent $tcp6
$ftp6 set packetSize_ 1600
$ftp6 set interval_ 0.001
set sink4 [new Agent/TCPSink]
$ns attach-agent $n(4) $sink4
set sink41 [new Agent/TCPSink]
$ns attach-agent $n(4) $sink41
$ns connect $udp0 $null4
$ns connect $udp7 $null4
$ns connect $tcp6 $sink41
$ns connect $tcp1 $sink4
$ns at 0.1 "$cbr0 start"
$ns at 0.8 "$cbr7 start"
$ns at 0.1 "$ftp1 start"
$ns at 0.1 "$ftp6 start"
$ns at 4.5 "$ftp1 stop"
$ns at 4.5 "$ftp6 stop"
$ns at 4.5 "$cbr0 stop"
$ns at 4.5 "$cbr7 stop"
$ns color 100 green
$ns color 101 green
$ns color 102 red
$ns color 103 red
$ns queue-limit $n(2) $n(3) 5
$ns duplex-link-op $n(2) $n(3) queuePos 0.5
$ns queue-limit $n(5) $n(4) 5
$ns duplex-link-op $n(5) $n(4) queuePos 0.5
proc finish {} {
global ns nf tf
Page 49 of 80
$ns flush-trace
close $nf
close $tf
exec nam LAN.nam &
exit 0
}
$ns at 5.0 "finish"
$ns run
OUTPUT:
Page 50 of 80
RESULT:
Thus the TCL script for LAN simulation has been executed successfully.
Page 51 of 80
Ex No:12 Date:
To write a tcl script to simulate a simple wireless network with DSDV,DSR and AODV
routing protocol
ALGORITHM:
1.start
2.set wireless channel,two ray ground,wireless phy,queue,queuelength and anteena
3.also set DSR,nodes number is 10 with speed 5
4.set dimenessions of x and y to 1000
5. set cp "seen1/scen10" and set cc to "scen1/cbr-op1
6.stop at 25 and size is 512 with rate of 100kb
7.set channel b and width 2.0e6
8.set new simulator and set nt open wireless-tr in write mode
9.set new tropography
10.create a channel chan_1 and create god
11.now config the adhoc routing
12.now create the nodes
13. set the initial node position
14. write the finish procedure
15. stop
PROGRAM:
OUTPUT:
num_nodes is set 50
creating nodes....
INITIALIZE THE LIST xListHead
loading random connection pattern....
starting simulation....
channel.cc:sendUp - Calc highestAntennaZ_ and distCST_
highestAntennaZ_ = 1.5, distCST_ = 550.0
SORTING LISTS ...DONE!
Page 54 of 80
RESULT:
Thus the TCL script to simulate a simple wireless network with DSDV routing
protocol has been executed successfully.
Page 55 of 80
Ex No:13 Date:
BLACKHOLE ATTACK
AIM:
To write the tcl program to create attackers from the existing protocol .
ALGORITHM:
1.start
2.to create a wireless netwsork with 5 nodes and AODV protocol
3. create a ns simulator
4.set gup topography object and open ns trace file and open nam trace file
5. now set up the mobile node parameter
6. now create 5 nodes
7.now assign color red to node2 and attacker
8.now assign color green to node0 and source
9. now assign color blue to node3 and destination
10.set up node n2 as an attacker
11.set up UDP connection
12.set CBR application over UDP connection
13.define a finish procedure
14.run the program
15.stop
PROGRAM:
#===================================
#===================================
Page 56 of 80
set val(ifqlen) 50 ;# max packet in ifq
#===================================
# Initialization
#===================================
#Create a ns simulator
create-god $val(nn)
#===================================
Page 57 of 80
#===================================
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channel $chan \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace OFF \
-movementTrace ON
#===================================
# Nodes Definition
#===================================
#Create 7 nodes
$n0 set X_ 99
Page 58 of 80
$n1 set X_ 299
Page 59 of 80
$ns at 0.0 "$n0 color green"
#===================================
#===================================
#===================================
# Agents Definition
#===================================
#===================================
# Applications Definition
#===================================
Page 60 of 80
$cbr0 attach-agent $udp0
#===================================
# Termination
#===================================
proc finish {} {
$ns flush-trace
close $tracefile
close $namfile
exit 0
$ns run
Page 61 of 80
OUTPUT:
RESULT:
Thus the TCL script for adding attacker to simulate Black Hole attack has been
executed successfully.
Page 62 of 80
Ex No:14 Date:
AIM:
ALGORITHM:
1.start
6.throughput=rec/sent.
8.stop
PROGRAM:
AWK program:
BEGIN {
r=s=d=0
}
{
if ($4=="AGT" )
( $1=="r" ) ? ++r : ( $1=="D" ) ? ++d : ( $1=="s" ) ? ++s : true
}
END {
printf("Throughput=%f\n",r/s)
}
X-Graph Program:
Page 63 of 80
"DSDV"
10 0.150000
20 0.135417 Values Obtained
30 0.146341
40 0.291391
50 0.194595
"AODV"
10 0.439024
20 0.589474
30 0.632000
40 0.679348
50 0.600000
"DSR"
10 0.416667
20 0.800000
30 0.857143
40 0.800000
50 0.600000
OUTPUT:
Result:
Page 64 of 80
ADVANCED LAB PROGRAMS
Page 65 of 80
Ex No: 15 Date:
AIM:
To study the throughput performance of DSDV in an wireless Ad hoc network
environment.
THEORY:
DSDV is a proactive table driven protocol. In which the all the nodes maintain a
routing table through which the packets are transmitted. The tables are forwarded if a
node observes a significant change in local topology. The table updates are of two types,
incremental updates and full dump An incremental update takes a single network data
packet unit (NDPU), while a full dump may take multiple NDPUs.
If a link breaks the weight is initiated as infinity and the update is made throughout
the network.
The availability of routes to all destinations at all times implies that much less delay
is involved in the route setup process. Another disadvantage of DSDV is that in order to
obtain information about a particular destination node, a node has to wait for a table
update message initiated by the same destination node.
PROCEDURE:
1. Set up a new simulator nam file and create new trace file.
2. Create 10 nodes which communicate in wireless mode for 78 sec.
3. Choose DSDV as a routing protocol.
4. Run the simulation.
5. Calculate the throughput using awk file.
PROGRAM:
set val(chan) Channel/WirelessChannel
set val(prop) Propagation/TwoRayGround
set val(netif) Phy/WirelessPhy
set val(mac) Mac/802_11
set val(ifq) Queue/DropTail/PriQueue
set val(ll) LL
set val(ant) Antenna/OmniAntenna
set val(ifqlen) 50
set val(nn) 10
set val(rp) DSDV
set val(x) 500
set val(y) 500
# Create God
create-god $val(nn)
#
# Provide initial (X,Y, for now Z=0) co-ordinates for mobilenodes
#
#
# nodes: 10, max conn: 8, send rate: 0.25, seed: 1.0
#
#
# 1 connecting to 2 at time 2.5568388786897245
#
set udp_(0) [new Agent/UDP]
$ns_ attach-agent $node_(1) $udp_(0)
set null_(0) [new Agent/Null]
$ns_ attach-agent $node_(2) $null_(0)
set cbr_(0) [new Application/Traffic/CBR]
Page 68 of 80
$cbr_(0) set packetSize_ 512
$cbr_(0) set interval_ 0.25
$cbr_(0) set random_ 1
$cbr_(0) set maxpkts_ 10000
$cbr_(0) attach-agent $udp_(0)
$ns_ connect $udp_(0) $null_(0)
$ns_ at 2.5568388786897245 "$cbr_(0) start"
#
# 4 connecting to 5 at time 56.333118917575632
#
set udp_(1) [new Agent/UDP]
$ns_ attach-agent $node_(4) $udp_(1)
set null_(1) [new Agent/Null]
$ns_ attach-agent $node_(5) $null_(1)
set cbr_(1) [new Application/Traffic/CBR]
$cbr_(1) set packetSize_ 512
$cbr_(1) set interval_ 0.25
$cbr_(1) set random_ 1
$cbr_(1) set maxpkts_ 10000
$cbr_(1) attach-agent $udp_(1)
$ns_ connect $udp_(1) $null_(1)
$ns_ at 56.333118917575632 "$cbr_(1) start"
#
# 4 connecting to 6 at time 146.96568928983328
#
set udp_(2) [new Agent/UDP]
$ns_ attach-agent $node_(4) $udp_(2)
set null_(2) [new Agent/Null]
$ns_ attach-agent $node_(6) $null_(2)
set cbr_(2) [new Application/Traffic/CBR]
$cbr_(2) set packetSize_ 512
$cbr_(2) set interval_ 0.25
$cbr_(2) set random_ 1
$cbr_(2) set maxpkts_ 10000
$cbr_(2) attach-agent $udp_(2)
$ns_ connect $udp_(2) $null_(2)
$ns_ at 146.96568928983328 "$cbr_(2) start"
#
# 6 connecting to 7 at time 55.634230382570173
#
set udp_(3) [new Agent/UDP]
$ns_ attach-agent $node_(6) $udp_(3)
set null_(3) [new Agent/Null]
$ns_ attach-agent $node_(7) $null_(3)
set cbr_(3) [new Application/Traffic/CBR]
$cbr_(3) set packetSize_ 512
Page 69 of 80
$cbr_(3) set interval_ 0.25
$cbr_(3) set random_ 1
$cbr_(3) set maxpkts_ 10000
$cbr_(3) attach-agent $udp_(3)
$ns_ connect $udp_(3) $null_(3)
$ns_ at 55.634230382570173 "$cbr_(3) start"
#
# 7 connecting to 8 at time 29.546173154165118
#
set udp_(4) [new Agent/UDP]
$ns_ attach-agent $node_(7) $udp_(4)
set null_(4) [new Agent/Null]
$ns_ attach-agent $node_(8) $null_(4)
set cbr_(4) [new Application/Traffic/CBR]
$cbr_(4) set packetSize_ 512
$cbr_(4) set interval_ 0.25
$cbr_(4) set random_ 1
$cbr_(4) set maxpkts_ 10000
$cbr_(4) attach-agent $udp_(4)
$ns_ connect $udp_(4) $null_(4)
$ns_ at 29.546173154165118 "$cbr_(4) start"
#
# 7 connecting to 9 at time 7.7030203154790309
#
set udp_(5) [new Agent/UDP]
$ns_ attach-agent $node_(7) $udp_(5)
set null_(5) [new Agent/Null]
$ns_ attach-agent $node_(9) $null_(5)
set cbr_(5) [new Application/Traffic/CBR]
$cbr_(5) set packetSize_ 512
$cbr_(5) set interval_ 0.25
$cbr_(5) set random_ 1
$cbr_(5) set maxpkts_ 10000
$cbr_(5) attach-agent $udp_(5)
$ns_ connect $udp_(5) $null_(5)
$ns_ at 7.7030203154790309 "$cbr_(5) start"
#
# 8 connecting to 9 at time 20.48548468411224
#
set udp_(6) [new Agent/UDP]
$ns_ attach-agent $node_(8) $udp_(6)
set null_(6) [new Agent/Null]
$ns_ attach-agent $node_(9) $null_(6)
set cbr_(6) [new Application/Traffic/CBR]
$cbr_(6) set packetSize_ 512
$cbr_(6) set interval_ 0.25
Page 70 of 80
$cbr_(6) set random_ 1
$cbr_(6) set maxpkts_ 10000
$cbr_(6) attach-agent $udp_(6)
$ns_ connect $udp_(6) $null_(6)
$ns_ at 20.48548468411224 "$cbr_(6) start"
#
# 9 connecting to 10 at time 76.258212521792487
#
set udp_(7) [new Agent/UDP]
$ns_ attach-agent $node_(9) $udp_(7)
set null_(7) [new Agent/Null]
$ns_ attach-agent $node_(8) $null_(7)
set cbr_(7) [new Application/Traffic/CBR]
$cbr_(7) set packetSize_ 512
$cbr_(7) set interval_ 0.25
$cbr_(7) set random_ 1
$cbr_(7) set maxpkts_ 10000
$cbr_(7) attach-agent $udp_(7)
$ns_ connect $udp_(7) $null_(7)
$ns_ at 76.258212521792487 "$cbr_(7) start"
#
#Total sources/connections: 6/8
#
Page 71 of 80
SCREEN SHOT:
RESULT:
Page 72 of 80
Ex No: 16 Date:
INTRODUCTION:
MAC-ALOHA:
Aloha refers to a simple communication scheme in which each source (transmitter)
in a network sends data whenever there is a frame to send. If the frame successfully
reaches the destination (receiver), the next frame is sent. If the frame fails to be received at
the destination, it is sent again.
TYPES OF ALOHA
PURE ALOHA
With Pure Aloha, stations are allowed access to the channel whenever they have
data to transmit. Because the threat of data collision exists, each station must either
monitor its transmission on the rebroadcast or await an acknowledgment from the
destination station. By comparing the transmitted packet with the received packet
or by the lack of an acknowledgement, the transmitting station can determine the
success of the transmitted packet. If the transmission was unsuccessful it is resent
after a random amount of time to reduce the probability of re-collision.
SLOTTED ALOHA
Assuming constant length packets, transmission time is broken into slots equivalent
to the transmission time of a single packet. Stations are only allowed to transmit at
slot boundaries. When packets collide they will overlap completely instead of
partially. This has the effect of doubling the efficiency of the Aloha protocol and has
come to be known as Slotted Aloha.
R-ALOHA(RESERVATION ALOHA)
This technique is sometimes combined with TDMA system to form the so called
reservation ALOHA protocol. In this protocol the time slot is divided into contention
periods and contention free periods. During the contention interval , an MS use very
short packets to contended for the upcoming contention free interval that will be
used for transmission of long information packets.
Page 73 of 80
PROCEDURE:
1. Create new simulation scenario with 6 nodes of simulation time 125 sec.
2. Choose aloha as MAC protocol.
3. Connect the link between node 3 and node 4 using Mac aloha protocol.
4. Connect the link between node 0 and node 4 where FTP is applied over TCP
connection.
5. Connect the link between node 1 and node 5 with UDP connection.
6. Run the scenario.
PROGRAM:
set lan [$ns newLan "$n3 $n4" 0.5Mb 40ms LL Queue/DropTail MAC/Sat/Unslotted Aloha
Channel]
SCREENSHOT:
RESULT:
Thus the MAC- Aloha scenario was implemented successfully in a 6 node system
and trace file is generated.
Page 76 of 80
Ex No: 17 Date:
INTRODUCTION:
MAC-CSMA:
Carrier Sense Multiple Access (CSMA) is a media access control (MAC) protocol in
which a node verifies the absence of other traffic before transmitting on a shared
transmission medium.
TYPES OF CSMA:
1-PERSISTENT CSMA
When the sender is ready to transmit data, it checks if the physical medium is busy. If
so, it senses the medium continually until it become idle, and then it transmits a pieces of
data, In case of a collision, the sender ewais for a random period of time and attempts to
transmit again.
P- PERSISTENT CSMA
This protocol is a generalization of 1-persisten CSMA. When the sender is ready to
send data, it checks continually if the medium is busy. If the medium becomes idle, the
sender transmits a frame with a probability p. In case the transmission did not happen the
sender waits until the next available time slot and transmits again with the same
probability p. This process repeats until the frame is sent or some other sender starts
transmitting.
NON PERSISTENT CSMA
This protocol Sense the channel if it is busy then it waits for a random amount of time
and sense the channel again if the channel is idle then it will transmit a packet immediately.
If collision occurs then it will wait for a random amount of time and then the frames are
transmitted.
Page 77 of 80
PROCEDURE:
1. Create new simulation scenario with routing with 6 nodes of simulation time 125 sec.
2. Choose CSMA as MAC protocol.
3. Choose node 3 and node 5 and start the routing between these two nodes.
4. Run the scenario.
PROGRAM:
set lan [$ns newLan "$n3 $n5" 0.5Mb 40ms LL Queue/DropTail MAC/Csma/Cd Channel]
SCREEN SHOT:
RESULT:
Thus the MAC-CSMA is implemented in a 6 node based system and its trace file is
generated.
Page 80 of 80