Friday, 7 November 2014

Error during NS-2.34 installation in Ubuntu

When installing NS-2.34 in ubuntu, you might get following compilation errors.


1. 
ld: libotcl.so: hidden symbol `__stack_chk_fail_local' isn't defined
ld: final link failed: Bad value
make: *** [libotcl.so] Error 1
otcl-1.13 make failed! Exiting ...


2. 
tools/ranvar.cc: In member function ‘virtual double GammaRandomVariable::value()’:
tools/ranvar.cc:219:70: error: cannot call constructor ‘GammaRandomVariable::GammaRandomVariable’ directly [-fpermissive]
tools/ranvar.cc:219:70: error:   for a function-style cast, remove the redundant ‘::GammaRandomVariable’ [-fpermissive]
make: *** [tools/ranvar.o] Error 1


3.
In file included from mac/mac-802_11Ext.cc:66:0:
mac/mac-802_11Ext.h: In member function ‘u_int32_t PHY_MIBExt::getHdrLen11()’:
mac/mac-802_11Ext.h:175:19: error: expected primary-expression before ‘struct’
mac/mac-802_11Ext.h:175:41: error: ‘dh_body’ was not declared in this scope
mac/mac-802_11Ext.h:175:51: error: ‘offsetof’ was not declared in this scope
mac/mac-802_11Ext.h:177:3: warning: control reaches end of non-void function [-Wreturn-type]
make: *** [mac/mac-802_11Ext.o] Error 1
Ns make failed!


4.
mobile/nakagami.cc: In member function ‘virtual double Nakagami::Pr(PacketStamp*, PacketStamp*, WirelessPhy*)’:
mobile/nakagami.cc:183:73: error: cannot call constructor ‘ErlangRandomVariable::ErlangRandomVariable’ directly [-fpermissive]
mobile/nakagami.cc:183:73: error:   for a function-style cast, remove the redundant ‘::ErlangRandomVariable’ [-fpermissive]
mobile/nakagami.cc:185:67: error: cannot call constructor ‘GammaRandomVariable::GammaRandomVariable’ directly [-fpermissive]
mobile/nakagami.cc:185:67: error:   for a function-style cast, remove the redundant ‘::GammaRandomVariable’ [-fpermissive]
make: *** [mobile/nakagami.o] Error 1


5.
other compilation error


What ever is the compilation error, the error is most probably due to the old version of gcc compiler.


Solution:



Step 1. 
first install the latest compiler
~$ sudo apt-get install gcc-4.4 g++-4.4


Step 2. 
The next step is to edit line 270 in tcl8.4.18/unix/Makefile.in.

~$ gedit /your/path/ns-allinone-2.34/tcl8.4.18/Makefile.in

SOLVED:
#CC = @CC@
CC = @CC@-4.4

save and exit

Step 3. 
To used gcc-4.4 and g++-4.4 as compiler to compile ns-allinone-2.34, change the line 36-37 in ns-2.34/Makefile.in.

~$ gedit /your/path/ns-allinone-2.34/ns-2.34/Makefile.in

SOLVED:
#CC = @CC@ 
#CPP = @CXX@
CC = @CC@-4.4
CPP = @CXX@-4.4

save and exit


Step 4. 
now go to /your/path/ns-allinone-2.34
./install


Thats all...now your ns2 should install well. Good luck.

Tuesday, 18 March 2014

Simulation of IEEE 802.15.4 (WPAN) in NS-2

To simulate 802.15.4, we just need two commands.

1. $node sscs startPANCoord <txBeacon = 1> <beaconOrder = 3>  <SuperframeOrder = 3>
This command can be used to start a PAN coordinator. Generally, there will be only one coordinator in a PAN.  If some parameters are omitted, the default values shown above will be assumed.
Examples:
$node_(0) sscs startPANCoord
$node_(0) sscs startPANCoord 1 3 3
2. $node sscs startDevice <isFFD = 1> <assoPermit = 1> <txBeacon = 0> <beaconOrder = 3> <SuperframeOrder = 3>
 This Command can be used to start a device or coordinator. If some parameters are omitted, the default values shown above will be assumed.
Examples:
$node_(0) sscs startDevice // non-beacon
$node_(0) sscs startDevice 1 1 1 // beacon enabled

Following is the simple tcl script to simulate IEEE 802.15.4. It consists of only two nodes; 1 coordinator and 1 end node.

==================================Start=================================
set stopTime 100
set BO 3
set SO 3
set speed 1
#speed is in m/s

# ======================================================================
# Define options
# ======================================================================
set val(chan)        Channel/WirelessChannel    ;# Channel Type
set val(prop)        Propagation/TwoRayGround   ;# radio-propagation model
set val(netif)         Phy/WirelessPhy/802_15_4
set val(mac)         Mac/802_15_4
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)           50
set val(y)           50
set opt(err)        UniformErrorProc

set val(nam)                2nodes.nam
set val(traffic) cbr                        ;# cbr/poisson/ftp

#read command line arguments
proc getCmdArgu {argc argv} {
        global val
        for {set i 0} {$i < $argc} {incr i} {
                set arg [lindex $argv $i]
                if {[string range $arg 0 0] != "-"} continue
                set name [string range $arg 1 end]
                set val($name) [lindex $argv [expr $i+1]]
        }
}
getCmdArgu $argc $argv

##This is optional error model. you can delete it if u dont need it
proc UniformErrorProc {} {
#          puts "useing error model-"
            set err [new ErrorModel]
#          $err unit pkt
            $err set rate_ 0.05
            return $err
}

# Initialize Global Variables
set ns_             [new Simulator]
set tracefd     [open ./2nodes.tr w]
$ns_ trace-all $tracefd
if { "$val(nam)" == "2nodes.nam" } {
       set namtrace     [open ./$val(nam) w]
        $ns_ namtrace-all-wireless $namtrace $val(x) $val(y)
}

$ns_ puts-nam-traceall {# nam4wpan #}                   ;# inform nam that this is a trace file for wpan (special handling needed)

#Mac/802_15_4 wpanNam macType $para1  # added by pranesh
Mac/802_15_4 wpanCmd verbose on
Mac/802_15_4 wpanNam namStatus on                   ;# default = off (should be turned on before other 'wpanNam' commands can work)
#Mac/802_15_4 wpanNam ColFlashClr gold             ;# default = gold

# For model 'TwoRayGround'
set dist(5m)  7.69113e-06
set dist(9m)  2.37381e-06
set dist(10m) 1.92278e-06
set dist(11m) 1.58908e-06
set dist(12m) 1.33527e-06
set dist(13m) 1.13774e-06
set dist(14m) 9.81011e-07
set dist(15m) 8.54570e-07
set dist(16m) 7.51087e-07
set dist(20m) 4.80696e-07
set dist(25m) 3.07645e-07
set dist(30m) 2.13643e-07
set dist(35m) 1.56962e-07
set dist(40m) 1.20174e-07
Phy/WirelessPhy set CSThresh_ $dist(15m)
Phy/WirelessPhy set RXThresh_ $dist(15m)

# set up topography object
set topo       [new Topography]
$topo load_flatgrid $val(x) $val(y)
#ns-random 1  gives same result in trace file everytime simulation is done
#ns-random 0 gives different result in trace file when simulated
ns-random 0
# Create God
set god_ [create-god $val(nn)]
set chan_1_ [new $val(chan)]

# configure node
$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) \
                        -topoInstance $topo \
                        -agentTrace ON \
                        -routerTrace OFF \
                        -macTrace ON \
                        -movementTrace OFF \
                        -energyModel "EnergyModel" \
                        -initialEnergy 10 \
                        -idlePower 0.00279 \
                        -rxPower 0.0565 \
                        -txPower 0.048 \
                        -sleepPower 0.000030 \
                        -transitionPower 0.002 \
                        -transitionTime 0.0002 \
                        -IncomingErrProc $opt(err) \
                        -channel $chan_1_ 

for {set i 0} {$i < $val(nn) } {incr i} {
            set node_($i) [$ns_ node]      
            $node_($i) random-motion 0             ;# disable random motion
}
##initial postion of node 0 and node 1
$node_(0) set X_ 25.0
$node_(0) set Y_ 25.0
$node_(0) set Z_ 0.0
$node_(1) set X_ 10.0
$node_(1) set Y_ 25.0
$node_(1) set Z_ 0.0


$ns_ at 0.0  "$node_(0) NodeLabel PAN Coor"
$ns_ at 0.0  "$node_(0) sscs startPANCoord 1 $BO $SO"  ;# startPANCoord <txBeacon=1> <BO=3> <SO=3>
$ns_ at 5  "$node_(1) sscs startDevice 0 0 0 $BO $SO"

Mac/802_15_4 wpanNam PlaybackRate 3ms
$ns_ at 50 "puts \"\nTransmitting data ...\n\""

##define traffic type and date rate 
set udp_(0) [new Agent/UDP]
$ns_ attach-agent $node_(1) $udp_(0)
set null_(0) [new Agent/Null]
$ns_ attach-agent $node_(0) $null_(0)
set cbr_ [new Application/Traffic/CBR]
$cbr_ set packetSize_ 100
$cbr_ set interval_ 0.2
$cbr_ set random_ 1
$cbr_ attach-agent $udp_(0)
$ns_ connect $udp_(0) $null_(0)
$ns_ at 50 "$cbr_ start"

# the following command is for moving the node 1. you can disable it if you dont need it.
#node 1 will start to meet at time 70 towards the cordinate(42,25) at the speed of $speed. $speed is defined at top.
$ns_ at 70 "$node_(1) setdest 42.00 25 $speed"

# defines the node size in nam
for {set i 0} {$i < $val(nn)} {incr i} {
            $ns_ initial_node_pos $node_($i) 2
}

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

##to stop simulation
$ns_ at $stopTime "stop"
$ns_ at $stopTime "puts \"\nNS EXITING...\n\""
$ns_ at $stopTime "$ns_ halt"

proc stop {} {
    global ns_ tracefd appTime val env
    $ns_ flush-trace
    close $tracefd
    set hasDISPLAY 0
    foreach index [array names env] {

        if { ("$index" == "DISPLAY") && ("$env($index)" != "") } {
                set hasDISPLAY 1
        }
    }
}
puts "\nStarting Simulation..."
$ns_ run

===========================End====================

Extra Features in the TCL


In the above two extra features have been added as bonus. 
  1. Error model
Error model has been added in the tcl file. UniformErrorProc defines the error mode and error rate. The error rate is set to 5%. If someone don’t need error model you can delete the UniformErrorProc. But make sure you delete “-IncomingErrProc $opt(err) \”  from node-config function also.
  1. Setdest
Setdest has been used in the tcl file. Setdest function is use for node mobility. Setdest is used to move node from current position to new position.
The syntax is:
 $node_(1) setdest  newXpos newYpos speed

for example: setdest 50 50 2 ;  will move node 1 from current location to 50,50 at the speed of 2 m/s.
You can disable the node movement by just delete the setdest line.


P.S. Queries are welcome. I will try to answer to my earliest convince. Thank you.


Wednesday, 4 December 2013

How to install NO Ad-Hoc Routing Agent (NOAH) in NS-2.34

NO Ad-Hoc Routing Agent (NOAH)

NOAH is a wireless routing agent that (in contrast to DSDV, DSR, ...) only supports direct communication between wireless nodes or between base stations and mobile nodes in case Mobile IP is used. This allows to simulate scenarios where multi-hop wireless routing is undesired. NOAH does not send any routing related packets.


  • It has been updated to work with ns-2.26 - ns-2.30 and with non-Mobile IP scenarios. (For older versions of ns-2, take a look at http://www.informatik.uni-mannheim.de/informatik/pi4/projects/MobileIP/ns-extension/ but this version does not contain the bugfixes for non-Mobile IP scenarios.)
  • Further update to allow static multi-hop routes. The routes can be set up using the routing command which takes as parameters the number of destinations and then as many tuples of destination and next hop address. The following example sets up static routing for a line of nodes:
    # setup static routing for line of nodes
    for {set i 0} {$i < $val(nn) } {incr i} {
        set cmd "[$node_($i) set ragent_] routing $val(nn)"
        for {set to 0} {$to < $val(nn) } {incr to} {
     if {$to < $i} {
         set hop [expr $i - 1]
     } elseif {$to > $i} {
         set hop [expr $i + 1]
     } else {
         set hop $i
     }
     set cmd "$cmd $to $hop"
        }
        eval $cmd
    }
Step-by-step installation instructions for ns-2.34

Makefile.in
add noah/noah.o \ to OBJ_CC and tcl/mobility/noah.tcl \ to NS_TCL_LIB
Note: make sure there is no space after "\"
noah/noah.{h,cc}
add noah.h and noah.cc to a new subdirectory noah/
Create directory in the folder ns-2.34
tcl/mobility/noah.tcl
add noah.tcl to tcl/mobility/
tcl/lib/ns-lib.tcl
in  line 197: add source ../mobility/noah.tcl
in 634: add
            NOAH {
                   set ragent [$self create-noah-agent $node]
            }
line 778: add
Simulator instproc create-noah-agent { node } {
    # Create a noah routing agent for this node
    set ragent [new Agent/NOAH]

    ## setup address (supports hier-addr) for noah agent
    ## and mobilenode
    set addr [$node node-addr]

    $ragent addr $addr
    $ragent node $node

    if [Simulator set mobile_ip_] {
        $ragent port-dmux [$node demux]
    }
    $node addr $addr
    $node set ragent_ $ragent
    return $ragent
}
Open terminal and go to the directory ns-2.34 and type follow commands
./configure
make clean
make

If everything went then you have successfully installed NOAH routing protocol. 
Congratulation. 

Possible errors
Makefile:13: *** commands commence before first target.  Stop.

The reason of this error is due to the possible space after “\” in these lines noah/noah.o \ or tcl/mobility/noah.tcl \
Make sure u leave no space after “\”
 


Thursday, 14 February 2013

bash unexpected end of file problem

bash unexpected end of file problem


Other day I was working for my research in Ubuntu and I needed to automate a process. I decide to write a bash script but my while loop was not working at all. Any condition and loop I wrote, it gave me a unexpected end of file error. I try to google for more than an hour but nothing was helpful. Even though my syntax seems to be correct but the terminal was giving me same error again and again. I was not able to figure out what was causing the error but, finally I was able to solve it.

There are several reasons for throwing this error when working with the bash script and mostly its due to syntax error. But, sometimes even  though every syntax is correct, you may still get this error and those times are really frustrating. It took me more than 2 hours to figure out the problem.

Cause:
I figure our the cause of this problem. It is due to the line ending used by various OS. I figure out that when we save our file in gedit (ubuntu), it has 3 line ending options as,
1. Unix/linux
2. Mac
3. Windows.



By default, windows is selected as line ending, and if its the case then how much you write the correct syntax, bash will not run and give you the unexpected end of file error.



Solution:
Just use the line ending as unix/linux and your bash script should work well this time. I hope this simple information is helpful.



Thank you and have a nice day...

Sunday, 11 November 2012

How to Install and Configure NS-2 with Eclipse in Linux

Running NS-2

Ns-2 can be run both in windows or Linux platform.

Best option

  • Use Linux 

How to run NS-2 under Windows?

  • Using Cygwin (not recommended)
  • Using Virtual machine
    • Vmware station (not free)
    • WM player (free and recommended)
    • Virtualbox (free)
  • others



Installation Procedures for NS-2 (ns-allinone-2.34)


Step 1: Download

download the latest ns2 copy . their are two methods to do that
1. go to terminal and type
wget http://nchc.dl.sourceforge.net/sourceforge/nsnam/ns-allinone-2.34.tar.gz
2. u can download it from here
Step 2: Extract
extract the tar file in home directory  i.e. /home/username
OR
try this in terminal
tar -xzvf ns-allinone-2.34.tar.gz
step 3 :install
just type following commands

cd ns-allinone-2.34
sudo apt-get install build-essential autoconf automake libxmu-dev
./install
Step 4: Set environment variables
$ gedit ~/.bashrc
Add the following lines to the end of the file. Remember replace “/your/path” by the folder where you have stored extracted the ns-2 file

# LD_LIBRARY_PATH
OTCL_LIB=/your/path/ns-allinone-2.34/otcl-1.13
NS2_LIB=/your/path/ns-allinone-2.34/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=/your/path/ns-allinone-2.34/tcl8.4.18/library
USR_LIB=/usr/lib
export TCL_LIBRARY=$TCL_LIB:$USR_LIB

# PATH
XGRAPH=/your/path/ns-allinone-2.34/bin:/your/path/ns-allinone-2.34/tcl8.4.18/unix:/your/path/ns-allinone-2.34/tk8.4.18/unix
NS=/your/path/ns-allinone-2.34/ns-2.34/
NAM=/your/path/ns-allinone-2.34/nam-1.14/
PATH=$PATH:$XGRAPH:$NS:$NAM

Ensure that it immediately takes effect:
$ source ~/.bashrc

Note: the previous step is important; else you cannot successfully run ns-2.
(Alternatively, you may have to restart your X-windows, that is logout, and then login, or restart your computer.)
Now, the installation has been completed. Try:
$ ns
The “%” symbol appears on the screen. Type “exit” to quit.

Validation (optional)

To run the ns validation suite:
$ cd ns-2.34
$ ./validate