Saturday 21 September 2013

NS 2

STARTING Network Simulator in Ubuntu
We can start ns with the command ‘ns YouFile.tcl’. where YouFile.tcl’ is the name of a Tcl script file which defines the simulation scenario (i.e. the topology and the events).Open you Terminal and type:
1
ns YouFile.tcl
nsscreenshot
████████████████████████████████████████████████████████████████████
STARTING NAM
You can either start nam with the command ‘nam YouFile.tcl’ where ‘YouFile.tcl’ is the name of a nam trace file that was generated by ns, or you can execute it directly out of the Tcl simulation script for the simulation which you want to visualize.Open you Terminal and Type:
1
nam YouFile.tcl
namescreenshot
Here is brief features of Network Animator
nam1
Here in this small post, i have only talk about Basics of ns,nam and Network animator :)
Hi :) as i have already mentinoned a small intoduction of Network simulator-2 here. Now finally i decided my self to write more about it. So today i am going to write about “From whear to Download and How to Install network Simulator-2 on any Linux Distribution(Ubuntu/Fedora).
We can build “Network-Simulator-2 either from the the various packages like Tcl/Tk, otcl,ns,nam,xgraph etc or we can go through downloading an ‘all-in-one’ package. well i suggest you to start with the all-in-one package, Beacuse it is easy to install for any newbi like me. I comes to know about disadvantage of the all-in-one distribution from it’s offical tutorial is the size, since it contains some components that we don’t need anymore after you compiled ns and nam. And remember one thing ns-allinone package work’s only in *NIX/LINUX system :) .
We can Download Network Simulator-2 from the Following Source (ns-allinone Package ie. Download ns-allinone-2.35.tar.gz (59.5 MB) )
████████████████████████████████████████████████████████████████████
After Downloading ns-allinone-2.35.tar.gz file start installing it in you Linux(Ubuntu/Fedora). I am going to First install in Fedora F17.
Installation Process For Installing Network Simulator-2(NS-2) in Fedora F17.
STEP-1
Get inside into root account,Then in home directory,and start installing Dependency for NetworkSimulator-2 in Fedora F17.
1
2
3
4
5
6
7
8
9
su
cd
yum install autoconf
yum install automake
yum install gcc-c++
yum install libX11-devel
yum install xorg-x11-proto-devel
yum install libXt-devel
yum install libXmu-devel
STEP-2
Open you Terminal (Hit Ctrl+Alt+T). get inside root, and it’s home directory.Download ns-allineone-2.35.tar.gz and then untar it.
1.su
2.cd
3.wget http://nchc.dl.sourceforge.net/project/nsnam/allinone/ns-allinone-2.35/ns-allinone-2.35.tar.gz
4.tar -xzvf ns-allinone-2.35.tar.gz

STEP-3

After untaring the above ns-allinone-2.35.tar.gz Package, a newly directory(Folder) is created.Now delete that ns-allinone-2.35.tar.gz as there is now no need of it. Get inside ns-allinone-2.35 (Directory/folder). It containes around 18 sub-directory and 3 files.

1.bin, 2.include, 3.nam-1.15, 4.README, 5.tclcl, 6.zlib-1.2.3, 7.cweb, 8.install, 8.ns-2.35, 9.sgb, 10.tclcl-1.20, 11.dei80211mr-1.1.4, 12.INSTALL.WIN32, 13.otcl, 14.share, 15.tk8.5.10, 16.gt-itm 17.lib, 18.otcl-1.14, 19.tcl8.5.10, 20. xgraph-12.2. Now install it.
1
2
3
cd ns-allinone-2.35/
ls
./install

STEP-4

While installation of ns-allinone in Fedora F17, We will encounter the following error. This error tells that at line number 137 in the following file(ns-2.35/linkstate/ls.h) has mistake.And to fix this mistake i have to place ‘This->erase’

installationerror
So open that file with you favorite editor like vi,nano,gedit. i have used vi
1
vi ns-allinone-2.35/ns-2.35/linkstate/ls.h
Go to Line number 137 Hit “i”
change the following line to “void eraseAll() { erase(baseMap::begin(), baseMap::end()); }”
to this line
“void eraseAll() { this->erase(baseMap::begin(), baseMap::end()); }” After that again install
1
./install

STEP-5

After giving ./install a PATH will appear on your terminals with some IMPORTANT NOTICE regading editing inside .bash_profile something like this

PathINformation
So move into you home directory /home/you-name/ as a root user , and see the hiden file(.bash_profile) by using “ls -a” command. once you find it,just edit the PATH,according to the given instruction. Type ns in terminal if you can ” %” symbole means NetworkSimulator-2 is successfully installed in Fedora F17
Installation of NetworkSimulator-2 on Ubuntu12.04
Before starting installation Note You MUST INSTALL THIS dependency before installing Ns-2 in ubuntu 12.04
1
sudo apt-get install build-essential autoconf automake libxmu-dev
STEP-1
Open you Terminal (Ctrl+Alt+t) update you package lists from the repositories by typing the following command:
1
sudo apt-get update
STEP-2
Download ns-allinone-2.35.tar.gz package from sourceforge by typing the following command in terminal:
1. wget http://nchc.dl.sourceforge.net/project/nsnam/allinone/ns-allinone-2.35/ns-allinone-2.35.tar.gz
STEP-3
Untar the ns-allinone-2.35.tar.gz Package, then a newly directory(Folder) is created. Now delete that ns-allinone-2.35.tar.gz, as there is now no need of it. Get inside ns-allinone-2.35 (Directory/folder). It containes around 18 sub-directory and 3 files.
1.bin, 2.include, 3.nam-1.15, 4.README, 5.tclcl, 6.zlib-1.2.3, 7.cweb, 8.install, 8.ns-2.35, 9.sgb, 10.tclcl-1.20, 11.dei80211mr-1.1.4, 12.INSTALL.WIN32, 13.otcl, 14.share, 15.tk8.5.10, 16.gt-itm 17.lib, 18.otcl-1.14, 19.tcl8.5.10, 20. xgraph-12.2. Now install it.
1
2
3
4
5
tar -xzvf ns-allinone-2.35.tar.gz
ls
cd ns-allinone-2.35/
ls
./install
STEP-4
After giving ./install a PATH will appear on your terminals with some IMPORTANT NOTICE regading editing. So edite inside .bashrc something like this
pattth
1
2
3
4
cd ~
 ls -a
 sudo gedit .bashrc
 source .bashrc
Or there is another great and easy way to install Network Simulator-2 in ubuntu is Download direct from Repositories.
sudo apt-get install ns2
sudo apt-get install nam
sudo apt-get install xgraph
Hy I am back once again from Long time !. I was hel busy in my college stuff. Today i am gona talk about My Minor Project called Network Simulator-2, i always thank’s to Prof. Naryan shau sir, for giving me a such a great project.:). and i am always thinking how shud i merge this project with any IBM tools, so that i can take part in The great mind challenge 2012 , but anyway let us Concentrate here.
Before proceeding we need to know what is Network simulator-2 is ?
A network simulator version-2 is widely known as NS2 is simply Open source an event driven simulation tool that has proved useful in studying the dynamic nature of a communication network.It is used in a simulation of wired as well as wireless network function and protocols, Example (Routing algorithms,TCP/UDP) cab be done using ns2. NS2 provides user with a way of specifying such network protocols and simulating their corresponding behaviours.Let me give you an Live example,
I am going to demostrate a video in which i have stimulated a UDP packet from node 0 to node 1.
1
Lol packets are moving like Bullet is't  hahah..
So here is Question? How i did this :p. it’s really simple i made a small script in TCL language, which is basically design to stimulate UDP packet’s from node 0 to node 1 via one Link. Let me explain you..but Before check Below
Fundamental’s for writing tcl script for Network simulator-2
I have devided this codes into 6 parts with each explanation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
set ns [new Simulator]
set nf [open out.nam w]
$ns namtrace-all $nf
proc finish {} {
        global ns nf
        $ns flush-trace
        close $nf
        exec nam out.nam &
        exit 0
}
$ns at 3.0 "finish"
set n0 [$ns node]
set n1 [$ns node]
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
$ns run
1. we need to create a simulator object something like this.
1
set ns [new Simulator]
2.Now we need to open a file for writing that is going to be used for the nam trace data.First line open a file ‘out.nam’ for writing and give it to file handle ‘nf’
1
set nf [open out.nam w]
In this code we are telling simulator object that we created above to write all simulation data that is going to be relevant for nam into this file
1
$ns namtrace-all $nf
3.This is to add a ‘finish’ procedure that closes the trace file and start nam
1
2
3
4
5
6
7
proc finish {} {
        global ns nf
        $ns flush-trace
        close $nf
        exec nam out.nam &
        exit 0
}
4.This one tell simulator object to execute the ‘finish’ procedure after 3.0 seconds of simulation time
1
$ns at 3.0 "finish"
5. This code tells the simulator object to connects the nodes n0 and n1 with duplex link with a bandwidth 1 Megabit,a delay of 10ms Drop tail (A simple queue management algorithm used by internet routers to decides when to drop packets :) )
1
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
6.This is a last line finally starts the simulation
1
$ns run
Now save the above script with .tcl extansion, and Open a terminal type
1
ns filename.tcl
You will se something like this
NOW to send a data on two nodes via one link, we need to do certaine things
1.Create a UDP agent.
2.Create a CBR traffic source.
3.Create NULL agent which act as a traffic sink
4.Connect the two agent with each other.
5.Fixe the time when to send and stop a data.
1.Create a UDP agent and attach it to node n0
1
2
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
2.Create a CBR traffic source and attach it to udp0
1
2
3
4
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetsize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0
3.The next lines creates a null agent which acts as traffic sink and attach it to node n1
1
2
set null0 [new Agent/null]
$ns attach-agent $n1 $null0
4. Now we are going to connect two agents with each other
1
$ns connect $udp0 $null0
5 NOw to fix a time by telling CBR agent when to send data and when to stop sending a data by following code
1
2
$ns at 0.5 "$cbr0 start"
$ns at 4.5 "$cbr0 stop"
So here is a complete code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#Create a simulator object
set ns [new Simulator]
#Open the nam trace file
set nf [open out.nam w]
$ns namtrace-all $nf
#Define a 'finish' procedure
proc finish {} {
        global ns nf
        $ns flush-trace
    #Close the trace file
        close $nf
    #Execute nam on the trace file
        exec nam out.nam &
        exit 0
}
#Create two nodes
set n0 [$ns node]
set n1 [$ns node]
#Create a duplex link between the nodes
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
#Create a UDP agent and attach it to node n0
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
# Create a CBR traffic source and attach it to udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.05
$cbr0 attach-agent $udp0
#Create a Null agent (a traffic sink) and attach it to node n1
set null0 [new Agent/Null]
$ns attach-agent $n1 $null0
#Connect the traffic source with the traffic sink
$ns connect $udp0 $null0 
#Schedule events for the CBR agent
$ns at 0.5 "$cbr0 start"
$ns at 4.5 "$cbr0 stop"
#Call the finish procedure after 5 seconds of simulation time
$ns at 5.0 "finish"
#Run the simulation
$ns run
Now save it with some name with .tcl extension,and again Open a terminal Type
1
ns filename.tcl
Now chuck it ;) YOu are able to create and run UDP packets between two nodes via one link ;) wow congrates heheh…bbye

No comments:

Post a Comment