Thursday 25 February 2016

What are the differences between NS2 & NS3?

1.Ns 2 is used for wired and wireless simulation wheras ns3 is used for internet simulation.

2.NS3 is not backward compatible with NS2; it's built from the scratch to replace NS2.

 3.NS3 is written in C++, Python Programming Language can be optionally used as an interface.

 4.NS3 is trying to solve problems present in NS2.

 5. There is very limited number of contributed codes made with NS3 compared to NS2

6. In NS2, bi-language system make debugging complex (C++/Tcl), but for NS3 only knowledge of C++ is
enough (single-language architecture is more robust in the long term).

 7.NS3 has an emulation mode, which allows for the integration with real networks.

Tcl script to create fixed color wireless nodes

Description: 

     Eight wireless nodes are created and they are configured with specific parameters of a mobile wireless node. After creating the nam file and trace file, we set up topography object. set node_ ($i) [$ns node] is used to create the nodes. Location of the nodes is fixed by specifying X, Y coordinates. Z coordinate is always zero.  Here we set the initial size for the every node by using initial_node_pos. AODV routing protocol is used here. $val(stop) specifies the end time of the simulation. In this program nodes are given with cyan color


code:-

 # 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)             2                      ;# number of mobilenodes
set val(rp)             AODV                       ;# routing protocol
set val(x)              500                  ;# X dimension of topography
set val(y)              400                  ;# Y dimension of topography 
set val(stop)        10.0               ;# time of simulation end




#-------Event scheduler object creation--------#
set ns              [new Simulator]
#Creating trace file and nam file.
set tracefd       [open wireless2.tr w]
set namtrace      [open wireless2.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)
set god_ [create-god $val(nn)]
# 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
                 
# Creating node objects..           
for {set i 0} {$i < $val(nn) } { incr i } {
            set node_($i) [$ns node]      
      }
      for {set i 0} {$i < $val(nn)  } {incr i } {
            $node_($i) color cyan
            $ns at 0.0 "$node_($i) color cyan"
      }
# Provide initial location of mobilenodes
$node_(0) set X_ 5.0
$node_(0) set Y_ 30.0
$node_(0) set Z_ 0.0
$node_(1) set X_ 50.0
$node_(1) set Y_ 25.0
$node_(1) set Z_ 0.0
$node_(2) set X_ 200.0
$node_(2) set Y_ 90.0
$node_(2) set Z_ 0.0
$node_(3) set X_ 350.0
$node_(3) set Y_ 160.0
$node_(3) set Z_ 0.0
$node_(4) set X_ 100.0
$node_(4) set Y_ 250.0
$node_(4) set Z_ 0.0
$node_(5) set X_ 300.0
$node_(5) set Y_ 100.0
$node_(5) set Z_ 0.0
$node_(6) set X_ 400.0
$node_(6) set Y_ 350.0
$node_(6) set Z_ 0.0
$node_(7) set X_ 3s50.0
$node_(7) set Y_ 470.0
$node_(7) set Z_ 0.0
# 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 10.01 "puts \"end simulation\" ; $ns halt"
proc stop {} {
    global ns tracefd namtrace
    $ns flush-trace
    close $tracefd
    close $namtrace
exec nam wireless2.nam &
}
$ns run
# How to run the program
$ns wireless2.tcl

Wednesday 24 February 2016

How to create Wireless Network in ns2

The wireless networking model can be created using Tool Command Language (TCL) script with fixed number of nodes. The sample code discussed below models the wireless network with 2 nodes. Nodes are configured with the components of channel, networking interface, radio propagation model, Medium Access Control (MAC) protocol, adhoc routing protocol, interface queue, link layer, topography object, and antenna type. The wireless network with 2 nodes can be viewed in the Network Animator (NAM) window after executing the file sample1.tc

code:-

#Filename: sample1.tcl

#TCL - Tool Command Language

# Simulator Instance Creation
set ns [new Simulator]

#Fixing the co-ordinate of simutaion area
set val(x) 500
set val(y) 500


# 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)             2                      ;# number of mobilenodes
set val(rp)             AODV                       ;# routing protocol
set val(x)              500                  ;# X dimension of topography
set val(y)              400                  ;# Y dimension of topography 
set val(stop)        10.0               ;# time of simulation end

# set up topography object
set topo       [new Topography]
$topo load_flatgrid $val(x) $val(y)

#Nam File Creation  nam - network animator
set namfile [open sample1.nam w]

#Tracing all the events and cofiguration
$ns namtrace-all-wireless $namfile $val(x) $val(y)

#Trace File creation
set tracefile [open sample1.tr w]

#Tracing all the events and cofiguration
$ns trace-all $tracefile

# general operational descriptor- storing the hop details in the network
create-god $val(nn)

# 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

# Node Creation
set node1 [$ns node]


# Initial color of the node
$node1 color black

#Location fixing for a single node
$node1 set X_ 200
$node1 set Y_ 100
$node1 set Z_ 0

set node2 [$ns node]
$node2 color black

$node2 set X_ 200
$node2 set Y_ 300
$node2 set Z_ 0




# Label and coloring
$ns at 0.1 "$node1 color blue"
$ns at 0.1 "$node1 label Node1"
$ns at 0.1 "$node2 label Node2"


#Size of the node
$ns initial_node_pos $node1 30
$ns initial_node_pos $node2 30




# ending nam and the simulation
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "stop"

#Stopping the scheduler
$ns at 10.01 "puts \"end simulation\" ; $ns halt"


#$ns at 10.01 "$ns halt"


proc stop {} {
    global namfile tracefile ns
    $ns flush-trace
    close $namfile
    close $tracefile
    #executing nam file
    exec nam sample1.nam &
}



#Starting scheduler
$ns run

#############################################################
Execution:
ns sample1.tcl


Tuesday 23 February 2016

Installation of NS2 (ns-allinone-2.35) on Ubuntu 14.04

Following steps are the guide to install ns2 in windows after the ubuntu (linux) installation.
» Step-1. Install the follwing software before installing NS2
sudo apt-get install tcl8.5-dev tk8.5-dev
sudo apt-get install build-essential autoconf automake
sudo apt-get install perl xgraph libxt-dev libx11-dev libxmu-dev
» Step-2. Download ns2 from the following link
» Step-3. Extract ns-allinone-2.35.tar.gz into the home dirctory (/home/admin admin is username given in system) using the follwing command .
tar -zxvf ns-allinone-2.35.tar.gz -C /home/admin
» Step-4. Install NS2 using the follwing command
cd /home/anupamj/ns-allinone-2.35
sudo ./install>
» Step-5. Set PATH environment as follows
1. You MUST put /home/admin /ns-allinone-2.35/otcl-1.14, /home/admin/ns-allinone-2.35/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 /home/admin/ns-allinone-2.35/tcl8.5.10/library into your TCL_LIBRARY environmental variable. Otherwise ns/nam will complain during startup.
» Step-6. Modify .bahrc
vi /home/admin/.bashrc
Go to the last line and add the scripts below:
export PATH=$PATH:/home/stan/ns-allinone-2.35/bin:/home/admin/ns-allinone-2.35/tcl8.5.10/unix:/home/admin/ns-allinone-2.35/tk8.5.10/unix
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/admin/ns-allinone-2.35/otcl-1.14:/home/admin/ns-allinone-2.35/lib
export TCL_LIBRARY=$TCL_LIBRARY:/home/admin/ns-allinone-2.35/tcl8.5.10/library
Enable the path setting:
» Step-7. Successful Installation of ns2 can be verified using the following command
cd ns-2.35; ./validate
» For trouble shooting, please first read ns problems page

What is ns-2?

• ns-2 stands for Network Simulator version 2.
• ns-2:
• Is a discrete event simulator for networking research
• Work at packet level.
• Provide substantial support to simulate bunch of
protocols like TCP, UDP, FTP, HTTP and DSR.
• Simulate wired and wireless network.
• Is primarily Unix based.
• Use TCL as its scripting language.
• ns-2 is a standard experiment environment in
research community.