Tuesday, October 22, 2013

NS-2.33 installation in Ubuntu 12.04


Follow the below given steps:

Download ns-allinnone-2.33 from nasam website
             http://sourceforge.net/projects/nsnam/files/ns-2
Create a folder in home with name ns2
 Extract the tar file in ns2
Open terminal and type cd ns2/ns-allinone-2.33
 Install required libraries for ns2 using terminal
            sudo apt-get install build-essential autoconf automake libxmu-dev
 Then, sudo ./install

For 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 ...
Solution:
In otcl-1.13/configure, line number 6304

-SHLIB_LD="ld -shared"
+SHLIB_LD="gcc -shared"

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

Solution:
In ns-2.33/tools/ranvar.cc, line 219

-return GammaRandomVariable::GammaRandomVariable(1.0 + alpha_, beta_).value() * pow (u, 1.0 / alpha_);
+return GammaRandomVariable(1.0 + alpha_, beta_).value() * pow (u, 1.0 / alpha_);

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!

Solution:
In mac/mac-802_Ext.h, line 65

+#include<cstddef>

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

Solution:
In ns-2.33/mobile/nakagami.cc, Line no.

-if (int_m == m) {
-             resultPower = ErlangRandomVariable::ErlangRandomVariable(Pr/m, int_m).value();
-         } else {
-             resultPower = GammaRandomVariable::GammaRandomVariable(m, Pr/m).value();
-         }
-         return resultPower;
-    }

 +if (int_m == m) {
 +           resultPower = ErlangRandomVariable(Pr/m, int_m).value();
 +        } else {
 +            resultPower = GammaRandomVariable(m, Pr/m).value();
 +        }
 +       return resultPower;
 +   }

Path Setup:
In terminal sudo gedit ~/.bash_aliases
Then update the environmrnt variable

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

# PATH
XGRAPH=/home/ramakrishna/ns2/ns-allinone-2.33/bin:/home/ramakrishna/ns2/ns-allinone-2.33/tcl8.4.18/unix:/home/ramakrishna/ns2/ns-allinone-2.33/tk8.4.18/unix
NS=/home/ramakrishna/ns2/ns-allinone-2.33/ns-2.33/
NAM=/home/ramakrishna/ns2/ns-allinone-2.33/nam-1.13/
PATH=$PATH:$XGRAPH:$NS:$NAM

NS-2 Error


Application initialization failed: Can't find a usable init.tcl in the following 

directories:
 
../../../linux/lib/tcltk/lib/tcl8.3 ../../../linux/lib/tcltk/lib/tcl8.3



Solution:


1. Go to location root-usr-local-bin by giving following command in terminal

cd /usr/local/bin


2. There you would find the ns file. We just need to remove it by giving following command


rm ns


3. Thats it, you are done. Now your ns starts running successfully.

Saturday, October 5, 2013

Error while including wireless-phy.h

The below error is solved:

./mac/wireless-phy.h:129: error: expected identifier before 'r'
./mac/wireless-phy.h:129: error: expected `}' before 'r'
./mac/wireless-phy.h:129: error: expected unqualified-id before 'r'
./mac/wireless-phy.h: In member function ‘bool& WirelessPhy::Is_node_on()’:
./mac/wireless-phy.h:97: error: ‘node_on_’ was not declared in this scope
./mac/wireless-phy.h: In member function ‘bool WirelessPhy::Is_sleeping()’:
./mac/wireless-phy.h:98: error: ‘status_’ was not declared in this scope
./mac/wireless-phy.h: At global scope:
./mac/wireless-phy.h:131: error: no matching function for call to ‘Sleep_Timer::Sleep_Timer()’
./mac/wireless-phy.h:58: note: candidates are: Sleep_Timer::Sleep_Timer(WirelessPhy*)
./mac/wireless-phy.h:56: note:                 Sleep_Timer::Sleep_Timer(const Sleep_Timer&)
./mac/wireless-phy.h:134: error: expected unqualified-id before ‘private’
./mac/wireless-phy.h: In function ‘EnergyModel* em()’:
./mac/wireless-phy.h:142: error: ‘node’ was not declared in this scope
./mac/wireless-phy.h: At global scope:
./mac/wireless-phy.h:144: error: ‘friend’ can only be specified inside a class
./mac/wireless-phy.h:146: error: expected declaration before ‘}’ token 



The error is due to duplicate link to SEND and RECV, so we need to change one of the file as shown below:

In cmu-trace.cc

- #define    RECV    'r'
- #define    SEND    's'


Rename as follows:

+ #define    RECVs    'r'
+ #define    SENDs    's' 


 

Friday, October 4, 2013

Installing LEACH in NS-2.34

The home directory of NS-2.34 is “/home/ns2/ns-allinone-2.34″

        1. Download the package “ns-234-leach.tar.gz” into the directory “/home/ns2/ns-allinone-2.34/ns-2.34″.
        2. Download the bash file “leach-setup.sh” into the directory “/home/ns2/ns-allinone-2.34/ns-2.34″.
    If the home directory of your “NS-2.34″ is other than “/home/ns2/ns-allinone-2.34″, then you need to find “ns-allinone-2.34″ and replace with “yourpath/ns-allinone-2.34″ for the file “leach-setup.sh”.
        3. Move to the directory “/home/ns2/ns-allinone-2.34/ns-2.34″ and patch the file “leach-setup.sh” by run this command :
        ns2@ubuntu-10.04:~$ cd /home/ns2/ns-allinone-2.34/ns-2.34/
        ns2@ubuntu-10.04:/home/ns2/ns-allinone-2.34/ns-2.34$ bash leach-setup.sh
    If the home directory of your “ns-2.34″ is other than “/home/ns2/ns-allinone-2.34″, then you need to find “…/ns-allinone-2.34″ and replace with “yourpath/ns-allinone-2.34″ for the following two files:
         ”Makefile” : found in the directory “/home/ns2/ns-allinone-2.34/ns-2.34″.
        “Makefile.in” : found in the directory “/home/ns2/ns-allinone-2.34/ns-2.34″.
        4. Edit both “Makefile” & “Makefile.in” as following:
        CC = gcc-4.3
        CPP = g++-4.3

        5. Run the following commands
        ns2@ubuntu-10.04:/home/ns2/ns-allinone-2.34/ns-2.34$ ./configure
        ns2@ubuntu-10.04:/home/ns2/ns-allinone-2.34/ns-2.34$ make clean
        ns2@ubuntu-10.04:/home/ns2/ns-allinone-2.34/ns-2.34$ make

    If you have a problem while ‘make’ and shown error message like this : “trace/cmu-trace.cc: In member function ‘void CMUTrace::format(Packet*, const char*)’: trace/cmu-trace.cc:1327: error: ‘format_rca’ was not declared in this scope trace/cmu-trace.cc: At global scope: trace/cmu-trace.cc:1523: error: no ‘void CMUTrace::format_rca(Packet*, int)’ member function declared in class ‘CMUTrace’ make: *** [trace/cmu-trace.o] Error 1″

Then you need to add this lines into your cmu-trace.h:
    // start from line 165
    #ifdef MIT_uAMPS
    void format_rca(Packet *p, int offset);
    #define ADV_CHAR ‘A’
    #define REQ_CHAR ‘R’
    #define DATA_CHAR ‘D’

    #endif

and also add this line into ns-default.tcl (line 765):

    # ——————————————————
    Phy/WirelessPhy set alive_ 1
    Phy/WirelessPhy set Efriss_amp_ 100e-12
    Phy/WirelessPhy set Etwo_ray_amp_ 0.013e-12

    Phy/WirelessPhy set EXcvr_ 50e-9
    Phy/WirelessPhy set sleep_ 0
    Phy/WirelessPhy set ss_ 1
    Phy/WirelessPhy set dist_ 0
    # ——————————————————

After that you need to re-make.

If the previous commands passed successfully then you are ready to test your “Leach” by running ./test:

ns2@ubuntu-10.04:/home/ns2/ns-allinone-2.34/ns-2.34$ ./test


Check the file “leach.err”, if no error reported then go to “leach.out” for results.

Sunday, August 11, 2013

TCL Error

TCL compilation error:

/home/ramakrishna/ns2/ns-allinone-2.34/tcl8.4.18/library:/usr/lib /home/ramakrishna/ns2/ns-allinone-2.32/lib/tcl8.4 /home/ramakrishna/ns2/ns-allinone-2.34/tcl8.4.18/library:/usr/lib /home/ramakrishna/ns2/ns-allinone-2.34/tcl8.4.18/library:/usr/tcl8.4 /usr/local/lib/tcl8.4 /usr/lib/tcl8.4 /usr/local/library /usr/library /usr/tcl8.4.15/library /tcl8.4.15/library /home/ramakrishna/ns2/ns-allinone-2.32/lib/tcl8.4



This probably means that Tcl wasn't installed properly.


1) cd ns-allinone-2.34/tcl8.4.18/ && ln -s lib/ library
2) Reinstall ns-allinone-2.34

OR

1. Go to location root-usr-local-bin by giving following command in terminal
cd /usr/local/bin
2. There you would find the ns file. We just need to remove it by giving following command
rm ns
3. Thats it, you are done. Now your ns starts running successfully.

Friday, May 31, 2013

'make depend' Error


/bin/sh: Syntax error: Bad fd number
make: *** [depend] Error 2

This is because the default ubuntu 10.04 setting uses dash instead of bash for sh command. Thus, rename the old link of /bin/sh to dash and create new link of /bin/sh to bash.

cd /bin
sudo mv sh sh_orig
sudo ln -s /bin/bash sh

Monday, April 29, 2013

NS-2 NAM Error

If following is the error when you run

$nam sample.nam
node 0 is not defined… node 0 is not defined… node 1 is not defined… node 1 is not defined… node 1 is not defined… node 0 is not defined… node 0 is not defined… node 0 is not defined… node 1 is not defined… node 1 is not defined… node 1 is not defined… node 0 is not defined… node 0 is not defined… node 0 is not defined… node 1 is not defined… node 1 is not defined… node 1 is not defined… node 0 is not defined… node 0 is not defined… node 0 is not defined… node 1 is not defined
 
Solution:
 $node_(0) set X_ 1236.434683198672
$node_(0) set Y_ 179.979610823970
$node_(0) set Z_ 0.000000000000
$node_(1) set X_ 1790.717030099859
$node_(1) set Y_ 83.776877593619
$node_(1) set Z_ 0.000000000000
 $ns_ at 0.000000000000 "$node_(0) setdest 8.478589906252 340.108921691462 0.138306462152"
$ns_ at 0.000000000000 "$node_(1) setdest 758.184447675563 73.841187162084 0.696734621404"
Add following two line at the after the mobility declaration.
$ns_ initial_node_pos $node_(1) 20
$ns_ initial_node_pos $node_(0) 20

Tuesday, April 16, 2013

Error while adding new protocol in NS2 - 3

One more common error is as follows:

invalid command name "Agent/MyAgentOtcl"
    while executing
"Agent/MyAgentOtcl set seqNo_ $opt(seqNo)"



This is due to one of the below listed reason:

1. The spelling mistake in "Agent/MyAgentOtcl" of TCL script and .cc file. In .cc file code will be as follows:

MyAgentClass() : TclClass("Agent/MyAgentOtcl") {}
TclObject* create(int, const char*const*) {
return(new MyAgent());
}


2. Once protocol is added, then updating makefile is also important. In makefile give the path for creating object file. If path is not give, then TCL scripts cannot access the C++ codes.

3. After modifying the makefile and ./configure, sometimes makefile will not be having the path information. You may get ./configure as successfully completed but TCL scripts fails to access. So updating is also important.

Error while adding new protocol in NS2 - 2

Error:

    make: *** No rule to make target `tcp/linux/tcp_naivereno.cc', needed by `depend'.  Stop.

Solution:

edit file “ns-allinone-2.33/ns-2.33/Makefile.in”

...


OBJ_CC = \

...

    tcp/scoreboard.o tcp/scoreboard-rq.o tcp/tcp-sack1.o tcp/tcp-fack.o \
-    tcp/linux/tcp_naivereno.o\
-    tcp/linux/src/tcp_cong.o\
-    tcp/linux/src/tcp_highspeed.o tcp/linux/src/tcp_bic.o tcp/linux /src/tcp_htcp.o tcp/linux/src/tcp_scalable.o src/tcp_cubic.o\
-    tcp/linux/src/tcp_westwood.o tcp/linux/src/tcp_vegas.o tcp/linux/src/tcp_hybla.o\
-    tcp/linux/src/tcp_illinois.o tcp/linux/src/tcp_yeah.o \
-    tcp/linux/src/tcp_veno.o tcp/linux/src/tcp_compound.o tcp/linux/src/tcp_lp.o\
-    tcp/scoreboard1.o tcp/tcp-linux.o tcp/linux/ns-linux-util.o tcp/linux/ns-linux-c.o tcp/linux/ns-linux-param.o\
+    tcp/scoreboard1.o tcp/tcp-linux.o tcp/linux/ns-linux-util.o \
    tcp/tcp-asym.o tcp/tcp-asym-sink.o tcp/tcp-fs.o \

...
-OBJ_C =
+OBJ_C = \
+    tcp/linux/tcp_naivereno.o\
+    tcp/linux/src/tcp_cong.o\
+    tcp/linux/src/tcp_highspeed.o tcp/linux/src/tcp_bic.o tcp/linux/src/tcp_htcp.o tcp/linux/src/tcp_scalable.o tcp/linux/src/tcp_cubic.o\
+    tcp/linux/src/tcp_westwood.o tcp/linux/src/tcp_vegas.o tcp/linux/src/tcp_hybla.o\
+    tcp/linux/src/tcp_illinois.o tcp/linux/src/tcp_yeah.o \
+    tcp/linux/src/tcp_veno.o tcp/linux/src/tcp_compound.o tcp/linux/src/tcp_lp.o\
+    tcp/linux/ns-linux-c.o tcp/linux/ns-linux-param.o

Error while adding new protocol in NS2 - 1

The most commonly found errors while adding new protocol are as follows:

invoked from within
"_o433 cmd addr"
invoked from within
"catch "$self cmd $args" ret"
invoked from within
"if [catch "$self cmd $args" ret] {
set cls [$self info class]
global errorInfo
set savedInfo $errorInfo
error "error when calling class $cls: $args" $..."
(procedure "_o433" line 2)
(SplitObject unknown line 2)
invoked from within
"_o433 addr"
("eval" body line 1)
invoked from within
"eval $node addr $args"
("default" arm line 2)
invoked from within
"switch -exact $routingAgent_ {
DSDV {
set ragent [$self create-dsdv-agent $node]
}
DSR {
$self at 0.0 "$node start-dsr"
}
AODV {
set ragent [$self cre..."
(procedure "_o3" line 14)
(Simulator create-wireless-node line 14)
invoked from within
"_o3 create-wireless-node"
("eval" body line 1)
invoked from within
"eval $self create-wireless-node $args"
(procedure "_o3" line 23)
(Simulator node line 23)
invoked from within
"$ns_ node"
("for" body line 2)
invoked from within
"for {set i $val(nnaodv)} {$i < $val(nn)} {incr i} {
set node_($i) [$ns_ node]
$node_($i) random-motion 0 ;#disable random motion
#..."



The error is due to the TCL script you are trying to execute is not compilng to the library TCL scripts. This error can be solved using following commands:

  1. ./configure
  2. make clean
  3. make
  4. sudo make install

Friday, January 4, 2013

Using added new routing protocol in NS2

The steps to be followed in Fedora system are as follows:

  1. ./configure
  2. make clean
  3. make
  4. make install
After these only new protocol will be active and use.