Saturday, 20 July 2013

some useful link for ns2

1. NS2 Official Website, http://www.isi.edu/nsnam/ns/
2. The ns Manual (Online),http://www.isi.edu/nsnam/ns/ns-
4. NS Simulator for beginners by Eitan Altman, Tania Jimenez,
         http://citeseer.ist.psu.edu/altman03ns.html (recommend)
6. NS by Example by Jae Chung and Mark Claypool, http://nile.wpi.edu/NS/
7. NS-2 and Tcl by Richard Griswold, http://www.k-lug.org/~griswold/NS2/index.html
8. NS Simulator Course for Beginners by Eitan Altman and Tania Jimenez,
9. Introducing ns by Lloyd Wood, http://www.ee.surrey.ac.uk/Personal/L.Wood/ns/
10. ns-2 for the impatient by Imad AAD and Jean-Pierre HUBAUX,
11. ns-2 Simulation Code and Examples,http://www.cs.bu.edu/groups/itm/SATS/simulation.html
12. A Tutorial of 802.11 Implementation in ns-2 by Yue Wang,
13. Pedro Vale Estrela – NS2 Page, http://mega.ist.utl.pt/~pmsrve/ns2/
14. Implementing a New Manet Unicast Routing Protocol in NS2 by Francisco
          J. Roshttp://masimum.dif.um.es/nsrt-howto/html/nsrt-howto.html and Pedro
          M. Ruiz,

Friday, 19 July 2013

Installation steps for Ns2 under fedora8

Step 1:
Download ns-allinone-2.34.tar.gz from the following link
http://sourceforge.net/project/showfiles.php?group_id=149743&package_id=169689&release_id=684492

Step 2:
Execute the following commands to install ns2.34 from the terminal. You must login as root.

$cp ns-allinone-2.34.tar /opt/
$cd /opt/
$tar -xzf ns-allinone-2.34.tar.gz
$cd ns-allinone-2.34
$./install

Step 3:
After a long wait and a whole lot of text, you should see the installation finish up with text like the following:

Please put /opt/ns-allinone-2.34/bin:/opt/ns-allinone-2.34/tcl8.4.18/unix:/opt/ns-allinone-2.34/tk8.4.18/unix
into your PATH environment; so that you'll be able to run itm/tclsh/wish/xgraph.

IMPORTANT NOTICES:

(1) You MUST put /opt/ns-allinone-2.34/otcl-1.13, /opt/ns-allinone-2.34/lib,
    into your LD_LIBRARY_PATH environment variable.
    If it complains about X libraries, add path to your X libraries
    into LD_LIBRARY_PATH.
    If you are using csh, you can set it like:
                setenv LD_LIBRARY_PATH <paths>
    If you are using sh, you can set it like:
                export LD_LIBRARY_PATH=<paths>

(2) You MUST put /opt/ns-allinone-2.34/tcl8.4.18/library into your TCL_LIBRARY environmental
    variable. Otherwise ns/nam will complain during startup.



Step 4:
To change PATH environment & others execute following commands in terminal.

$cd /etc
$gedit ~/.bashrc &

Step 5:
Add following lines at the end of bashrc file.

# LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/ns-allinone-2.34/otcl-1.13:/opt/ns-allinone-2.34/lib

# TCL_LIBRARY
export TCL_LIBRARY=$TCL_LIBRARY:/opt/ns-allinone-2.34/tcl8.4.18/library

# PATH
export PATH=$PATH:/opt/ns-allinone-2.34/bin:/opt/ns-allinone-2.34/tcl8.4.18/unix:/opt/ns-allinone-2.34/tk8.4.18/unix

Step 6:
To make the change in the path & others permanent, type the following command in terminal.
$ source ~/.bashrc

You can check what is written in your path by writing
$echo $PATH
$echo $LD_LIBRARY_PATH
$echo $TCL_LIBRARY

Step 7:
Now, the installation has been completed. If you try:
$ns

Then a "%" will appear on the screen. Type "exit" to quit the mode.

Step 8:
You can test/validate the installation by doing the following: [It is not necessary]
$cd /opt/ns-allinone-2.34/ns-2.34/
$./validate
Note that this validation takes a really long time. If it starts out ok, you probably have a good installation.

Step 9:
Simple ns2 Simulation program

$cd /opt/ns-allinone-2.34/ns-2.34/tcl/ex
$ns wireless-demo-csci694.tcl
$nam 694demo.nam

If output comes, then everything is ok :)

Testing:
Way 1:

$ns
%set ns [new Simulator]
%$ns at 1 "puts \"Hello World!\""
%$ns at 1.5 "exit"
%$ns run


Way 2:

Step 1: Create a file named sample.tcl & add the following lines in the file.
set ns [new Simulator]
$ns at 1 "puts \"Hello World!\""
$ns at 1.5 "exit"
$ns run

Step 2: Run the file by executing following command
$ns sample.tcl

Step 3: Output will be: Hello World!

Throughput Analysis for MANET using awk file

BEGIN {
send = 0;
recv = 0;
packetsize = 0;
st = 0;
ft = 0;
linecount=0;
throughput=0;
TotalDelay = 0.0 ;
packetid=0;
}

{

rTime=$2
packetid=$6
if ( $1 == "s" &&  $7 !="ack" )
 {
     
        rSentTime[ packetid ] = rTime ;
send++;
}

if ( lineCount==0 )
{
st = $2;
lineCount++;
}
else
{
ft = $2;
}


if ( $1 == "r" && $7 != "ack" )
{
recv++;
     
packetsize=$8
        rReceivedTime[ idPacket ] = rTime ;

TotalDelay += ReceivedTime[ packetid] - SentTime[ packetid ];
}

}


END {
print "packetsize\t\t\t"  packetsize
totaltime=ft-st
throughput=(recv*packetsize)/totaltime
print "total simulation time\t\t"  totaltime
print "No of pkts send \t\t" send
print "No of pkts recv \t\t" recv
print "Pkt delivery ratio \t\t" recv/send
print "Throughput \t\t\t" int(throughput)
}



save the above code  as  awkfilename.awk 

run as 

open terminal window if u  are using linux os

ns aodv.tcl

nam will be created......
aodv.tr will be generated....

awk -f  awkfilename.awk aodv.tr


Simulation of Mobile adhoc Networks in Ns2

# wireless aodv.tcl
# A 3-node example for ad-hoc simulation with DSDV

# Define options
set val(chan)           Channel/WirelessChannel    ;# channel type
set val(prop)           Propagation/TwoRayGround   ;# radio-propagation model
set val(netif)          Phy/WirelessPhy            ;# network interface type
set val(mac)            Mac/802_11                 ;# MAC type
set val(ifq)            Queue/DropTail/PriQueue    ;# interface queue type
set val(ll)             LL                         ;# link layer type
set val(ant)            Antenna/OmniAntenna        ;# antenna model
set val(ifqlen)         50                         ;# max packet in ifq
set val(nn)             10                         ;# number of mobilenodes
set val(rp)             AODV                      ;# routing protocol
set val(x)              300   ;# X dimension of topography
set val(y)              350   ;# Y dimension of topography
set val(stop) 150   ;# time of simulation end

set ns  [new Simulator]
set tracefd       [open aodv.tr w]
set namtrace      [open aodv.nam w]  

$ns trace-all $tracefd
$ns namtrace-all-wireless $namtrace $val(x) $val(y)

# set up topography object
set topo       [new Topography]

$topo load_flatgrid $val(x) $val(y)

create-god $val(nn)

#
#  Create nn mobilenodes [$val(nn)] and attach them to the channel.
#

# configure the nodes
        $ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channelType $val(chan) \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace OFF \
-movementTrace ON

for {set i 0} {$i < $val(nn) } { incr i } {
set node_($i) [$ns node]
}

# Provide initial location of mobilenodes
$node_(0) set X_ 5.0
$node_(0) set Y_ 5.0
$node_(0) set Z_ 0.0

$node_(1) set X_ 240.0
$node_(1) set Y_ 265.0
$node_(1) set Z_ 0.0

$node_(2) set X_ 150.0
$node_(2) set Y_ 240.0
$node_(2) set Z_ 0.0

$node_(3) set X_ 20.0
$node_(3) set Y_ 20.0
$node_(3) set Z_ 0.0

$node_(4) set X_ 200.0
$node_(4) set Y_ 120.0
$node_(4) set Z_ 0.0

$node_(5) set X_ 150.0
$node_(5) set Y_ 20.0
$node_(5) set Z_ 0.0

$node_(6) set X_ 35.0
$node_(6) set Y_ 120.0
$node_(6) set Z_ 0.0

$node_(7) set X_ 100.0
$node_(7) set Y_ 20.0
$node_(7) set Z_ 0.0

$node_(8) set X_ 80.0
$node_(8) set Y_ 130.0
$node_(8) set Z_ 0.0

$node_(9) set X_ 170.0
$node_(9) set Y_ 200.0
$node_(9) set Z_ 0.0







# Generation of movements
$ns at 10.0 "$node_(0) setdest 250.0 250.0 3.0"
$ns at 15.0 "$node_(1) setdest 45.0 285.0 5.0"
$ns at 110.0 "$node_(0) setdest 230.0 290.0 5.0"

# Set a TCP connection between node_(0) and node_(1)
set tcp [new Agent/TCP/Newreno]
$tcp set class_ 2
set sink [new Agent/TCPSink]
$ns attach-agent $node_(0) $tcp
$ns attach-agent $node_(1) $sink
$ns connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns at 10.0 "$ftp start"
$ns at 25.0 "$ftp stop"

set tcp [new Agent/TCP/Newreno]
$tcp set class_ 2
set sink [new Agent/TCPSink]
$ns attach-agent $node_(2) $tcp
$ns attach-agent $node_(5) $sink
$ns connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns at 30.0 "$ftp start"
$ns at 45.0 "$ftp stop"

set tcp [new Agent/TCP/Newreno]
$tcp set class_ 2
set sink [new Agent/TCPSink]
$ns attach-agent $node_(3) $tcp
$ns attach-agent $node_(6) $sink
$ns connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns at 50.0 "$ftp start"
$ns at 80.0 "$ftp stop"

set tcp [new Agent/TCP/Newreno]
$tcp set class_ 2
set sink [new Agent/TCPSink]
$ns attach-agent $node_(4) $tcp
$ns attach-agent $node_(8) $sink
$ns connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns at 90.0 "$ftp start"
$ns at 120.0 "$ftp stop"

set tcp [new Agent/TCP/Newreno]
$tcp set class_ 2
set sink [new Agent/TCPSink]
$ns attach-agent $node_(0) $tcp
$ns attach-agent $node_(9) $sink
$ns connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns at 120.0 "$ftp start"


# Define node initial position in nam
for {set i 0} {$i < $val(nn)} { incr i } {
# 30 defines the node size for nam
$ns initial_node_pos $node_($i) 30
}

# Telling nodes when the simulation ends
for {set i 0} {$i < $val(nn) } { incr i } {
    $ns at $val(stop) "$node_($i) reset";
}

# ending nam and the simulation
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "stop"
$ns at 150.01 "puts \"end simulation\" ; $ns halt"
proc stop {} {
    global ns tracefd namtrace
    $ns flush-trace
    close $tracefd
    close $namtrace
}

$ns run