STEP 1
From terminal login as super user and do the following.(internet must also be connected in order to install the package dependencies.
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
From terminal download ns-allinone-2.30 and type the following commands
$ wget http://www.isi.edu/nsnam/dist/ns-allinon
e-2.30.tar.gz
$ tar -xzf ns-allinone-2.30.tar.gz
$ cd ns-allinone-2.30.tar.gz
$. /install
STEP 3
Now go to /etc folder and type
gedit ~/.bashrc
Add the following lines to the end of it. Remember replace “/usr/local/” by your installation path like “/home/kazim”. And accordingly also change the version numbers. This is for ns 2.30.
# LD_LIBRARY_PATH
OTCL_LIB=/usr/local/ns-allinone-2.30/otcl-1.12
NS2_LIB=/usr/local/ns-allinone-2.30/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=/usr/local/ns-allinone-2.31/tcl8.4.14/library
USR_LIB=/usr/lib
export TCL_LIBRARY=$TCL_LIB:$USR_LIB# PATH
XGRAPH=/usr/local/ns-allinone-2.30/bin:/usr/local/ns-allinone-2.30/tcl8.4.13/unix: /usr/local/ns-allinone-2.30/tk8.4.13/uni x
NS=/usr/local/ns-allinone-2.30/ns-2.30/
NAM=/usr/local/ns-allinone-2.30/nam-1.12/
PATH=$PATH:$XGRAPH:$NS:$NAM
Let it take effect immediately
source ~/.bashrc
Note: the step described above is important; otherwise, you cannot run ns successfully.
or you can restart your X windows.i.e. logout and then login, or reboot your system, to make it work.)
Now, the installation has been completed. If you try:
$ ns
Then a “%” will appear on the screen.type “exit” to quit the mode and back to “$”
If you miss out step 1 you may get the following errors
Build XGraph-12.1
========================================
loading cache ./config.cache
checking for a BSD compatible install… /usr/bin/install -c
checking whether build environment is sane… yes
checking whether make sets ${MAKE}… yes
checking for working aclocal… missing
checking for working autoconf… missing
checking for working automake… missing
checking for working autoheader… missing
checking for working makeinfo… missing
checking if malloc debugging is wanted… no
checking for gcc… no
checking for cc… no
configure: error: no acceptable cc found in $PATH
make: *** No targets specified and no makefile found. Stop.
Can not create xgraph; But xgraph is an optional package, continuing…
If you miss step 3
At the prompt when you type ns you will get
Ns command not found
for {set i 0} {$i < $num_nodes} {incr i} {
set a($i) [new Agent/MessagePassing/Flooding]
$n($i) attach $a($i) $MESSAGE_PORT
$a($i) set messages_seen {}
set if_($i) [$n($i) set netif_(0)]
}
# then you can set the transmission power for each node individually :
for {set i 0} {$i < 10} {incr i} {
if { $i < 5} {
# transmission range: 40m
$if_($i) set Pt_ 8.5872e-4
} else {
# transmission range: 100m
$if_($i) set Pt_ 7.214e-3
}
}
$NS_HOME/indep-utils/propagation/thresho
예제
distance = 100
propagation model: TwoRayGround
transmit power: 0.007214
frequency: 9.14e+08
transmit antenna gain: 1
receive antenna gain: 1
system loss: 1
transmit antenna height: 1.5
receive antenna height: 1.5
// Pt_ = 8.5872e-4; // For 40m transmission range.
// Pt_ = 7.214e-3; // For 100m transmission range.
// Pt_ = 0.2818; // For 250m transmission range.
# it work like the 914MHz Lucent WaveLAN DSSS radio interface
Phy/WirelessPhy set CPThresh_ 10.0
Phy/WirelessPhy set CSThresh_ 1.559e-11
Phy/WirelessPhy set RXThresh_ 3.652e-10
Phy/WirelessPhy set bandwidth_ 2e6
Phy/WirelessPhy set Pt_ 0.28183815
Phy/WirelessPhy set freq_ 914e+6
Phy/WirelessPhy set L_ 1.0
Phy/WirelessPhy set debug_ false
$ tar -xzvf ns-allinone-2.33.tar.gz
$ cd ns-allinone-2.33
$ sudo apt-get install build-essential autoconf automake libxmu-dev
Now run this command :
$./install
$ gedit ~/.bashrc
Add the following lines to the end of it. Remember replace
“/home/networklab/ns/” by something like “/home/yourname/”
——————————————————————————————–
# LD_LIBRARY_PATH
OTCL_LIB=/home/networklab/ns/ns-allinone-2.3
NS2_LIB=/home/networklab/ns/ns-allinone-2.3
X11_LIB=/usr/X11R6/lib
USR_LOCAL_LIB=/usr/local/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$OTCL_L
LIB:$USR_LOCAL_LIB
# TCL_LIBRARY
TCL_LIB=/home/networklab/ns/ns-allinone-2.3
USR_LIB=/usr/lib
export TCL_LIBRARY=$TCL_LIB:$USR_LIB
# PATH
XGRAPH=/home/networklab/ns/ns-allinone-2.3
ns-allinone-2.33/tcl8.4.14/unix:/your/pa
NS=/home/networklab/ns/ns-allinone-2.33/n
NAM=/home/networklab/ns/ns-allinone-2.33/n
PATH=$PATH:$XGRAPH:$NS:$NAM
————————–
Let it take effect immediately:
$ source ~/.bashrc
Note: if ns unsuccessfully. you can restart your X windows, or reboot your system, to make it work Now,the installation has been completed. then try:
$ ns
Then a “%” will appear on the screen.type “exit” to quit the mode and back to “$”
Validation :
$ cd ns-2.33
$ ./validate
Introduction
Ns-2 is a widely used tool to simulate the behavior of wired and wireless networks. Useful general information can be found at
Official ns-2 website (http://www.isi.edu/nsnam/ns/ )
An ns-2 Documentation generated by Doxygen is in http://www-rp.lip6.fr/ns-doc/ns226-doc/h
Two good tutorials about ns-2.
Wireless tutorial by Marc Greis
ns by example
My presentation: ns2 tutorial for wireless simulation WINLAB, June 2003
My Lecture : Introduction to ns2 ECE 330:543 Class Lecture, Oct. 2007
Another good tutorial of ns-2
Installation & Debug
Install ns-2.27 in Red Hat Linux
Install ns 2.28 in Debian with gcc 4.0 or above
Debug ns-2 with gdb
Simulation Configuration
- Basic simulation scripts of wireless scenarios.
- Traffic, Topology and Mobility generation in ns-2
- Analyze CMU traces (for wireless simulation) and awk code.
- Header and Address Handling in ns-2
- Understanding OTcl syntax in ns-2
Physical Layer
- Demystify TwoRayGround Propagation Model
- Introduce Ricean Fading to produce probabilistic Link Error
- Why list-based improvements in channel.cc of ns-2.27 cause problems?
MAC layer
- Interfacing MAC
- Understand IEEE 802.11 MAC Standard
- Analysis of the 802.11 MAC code
- Simulation example: Measuring the effects of RTS/CTS on 802.11 link
- Practice: Implement Multi-Rate MAC
- Discussion of bugs and issues of IEEE802.11 MAC implementation
Routing
- Analysis of the DSR sourcecode in ns-2.
- Analysis of the DSDV in network simulator-2.
- How to produce a new Routing Agent with Fixed Routing Table.
- Calculate Routing Performance Metric from trace file
Summary of ns-2 bugs for wireless simulation
channel.cc List-based improvement causes "Segmentation Fault".
mac-802_11.cc: Bug in Defer timer causes "Event UID not valid!".
dsdv.cc: double IP header bug.
http://nuraini.net/2007/09/16/unicast-an
Those following code are some example code for sending packet unicast and broadcast on NS2.
void protocol::unicast(Packet *p, nsaddr_t destination)
{
hdr_cmn* hdrcmn = HDR_CMN(p);
hdr_ip* iphdr = HDR_IP(p);
// set all the necessary things for the common header
hdrcmn->next_hop_ = destination;
hdrcmn->prev_hop_ = this->addr();
hdrcmn->direction() = hdr_cmn::DOWN;
// take a look its name on packet.h
hdrcmn->ptype() = PT_PROTOCOLNAME;
hdrcmn->addr_type() = NS_AF_INET;
// setting the ip header
iphdr->saddr() = this->addr();
iphdr->sport() = 254; // 1-254
iphdr->daddr() = destination;
iphdr->dport() = 254; // 1-254
iphdr->ttl() = 32;
Scheduler::instance().schedule(ll, p, 0.0);
}
void protocol::broadcast(Packet *p)
{
hdr_cmn* hdrcmn = HDR_CMN(p);
hdr_ip* iphdr = HDR_IP(p);
// set all the necessary things for the common header
hdrcmn->next_hop_ = IP_BROADCAST;
hdrcmn->prev_hop_ = this->addr();
hdrcmn->direction() = hdr_cmn::DOWN;
// setting the ip header
iphdr->saddr() = this->addr();
iphdr->sport() = 254; // 1-254
iphdr->daddr() = IP_BROADCAST;
iphdr->dport() = 254; // 1-254
iphdr->ttl() = 32;
Scheduler::instance().schedule(ll, p, 0.0);
}
The above codes can be called anywhere on sourcecode.cc (anyname.cc). For example :int protocol::command(int argc, const char*const* argv)
{
if (argc == 4) {
if (strcmp(argv[1], "sendData“) == 0)
{
Packet* newpkt = allocpkt();
//some packet configuration
this->broadcast(newpkt);
return (TCL_OK);
}
}
When the node will receive it ?We should make recv procedure.
void protocol::recv(Packet* pkt, Handler*)
{
hdr_cmn* hdrcmn = HDR_CMN(pkt); //Access the common header for the received packet:
hdr_ip* hdrip = HDR_IP(pkt); // Access the IP header for the received packet:
cout << "node " << this->addr() << "received from node " << hdrcmn->prev_hop_;
}