Steps to install
ns2.34 on ubuntu10.04
1.at first stay
into your home directory(/home/ashrafi/-- here ashrafi is my home folder)
Step1: Download
ns-allinone-2.34 package from this <site>. I will be using ns version
2.34.
Step2: Place the
ns-allinone-2.34.tar.gz file in your home folder(/home/ashrafi in my case).
Right click on the package and extract the contents in the same home folder.
[N.B (step 4-8
you need to connect internet to update and install these)]
Step3: Next, open
the Terminal(Applications–>Accessories–>Terminal in ubuntu)
Step4: sudo gedit
/etc/apt/sources.list
Step5: sudo
apt-get update
after completing
update
Step6: sudo
apt-get install build-essential autoconf automake libxmu-dev gcc-4.3
after completing
install
Step7: sudo
apt-get install g++ make autoconf automake libtool libxmu-dev
Step8: sudo
apt-get install g++-4.3
Edit Makefile.in
found at this location ns-allinone-2.34/otcl-1.13/Makefile.in as follows:
in terminal write
command
Step9: clear
Step10: cd
ns-allinone-2.34/otcl-1.13
if step10 doesn't
work only then write(10.1)
Step10.1: cd
otcl-1.13/
Step11: ls
Step12: gedit
Makefile.in
Now
Edit Makefile.in
found at this location ns-allinone-2.34/otcl-1.13/Makefile.in as follows:
Find the line
that says:
CC= @CC@
and change it to:
CC= gcc-4.3
and press save button
after change it
back to terminal
Step13: sudo su
Step14: cd ..
Step15: ./install
after
successfully install ns-allinone-2.34 pakage without any error back to terminal
Step16: clear
Step17: su
ashrafi
Step18:
gedit ~/.bashrc
Step19:
Append the following lines to the file
~/.bashrc
just go to end of
the file and press enter and copy following instuction and paste it in there,then
press save button
# LD_LIBRARY_PATH
OTCL_LIB=/home/ashrafi/ns-allinone-2.34/otcl-1.13
NS2_LIB=/home/ashrafi/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=/home/ashrafi/ns-allinone-2.34/tcl8.4.18/library
USR_LIB=/usr/lib
export
TCL_LIBRARY=$TCL_LIB:$USR_LIB
# PATH
XGRAPH=/home/ashrafi/ns-allinone-2.34/bin:/home/ashrafi/ns-allinone-2.34/tcl8.4.18/unix:/home/ashrafi/ns-allinone-2.34/tk8.4.18/unix
# Note: the above
two lines starting from XGRAPH should come in the same line
NS=/home/ashrafi/ns-allinone-2.34/ns-2.34/
NAM=/home/ashrafi/ns-allinone-2.34/nam-1.14/
PATH=$PATH:$XGRAPH:$NS:$NAM
Step20: now back
to terminal and write down
source ~/.bashrc
Step21: ns
Step22: %exit
Step23: nam
[note that:
download
wireless-tcp and save as wireless-tcp.tcl
i've given below
the code u've to copy it and paste in a notepad then save as wireless-tcp.tcl
source code:
#illidan.modeler@gmail.com
#
======================================================================
# 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
#
======================================================================
# Main Program
#
======================================================================
#
# Initialize
Global Variables
#
set ns_ [new Simulator]
set tracefd [open wireless.tr w]
set namfd [open wireless.nam w]
set f0 [open
wireless-tcp.data w]
$ns_ trace-all
$tracefd
$ns_
namtrace-all-wireless $namfd 20 20
# set up
topography object
set topo [new Topography]
$topo
load_flatgrid 20 20
#
# Create God
#
create-god
$val(nn)
#
# Create the specified number of mobilenodes
[$val(nn)] and "attach" them
# to the channel.
# Here two nodes are created : node(0) and
node(1)
# 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) \
-channelType
$val(chan) \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace OFF \
-movementTrace
OFF
for {set i 0} {$i < $val(nn) } {incr
i} {
set node_($i) [$ns_ node]
$node_($i) random-motion 0 ;# disable random motion
}
#
# Provide initial
(X,Y, for now Z=0) co-ordinates for mobilenodes
#
$node_(0) set X_
5.0
$node_(0) set Y_
5.0
$node_(0) set Z_
0.0
$node_(1) set X_
15.0
$node_(1) set Y_
15.0
$node_(1) set Z_
0.0
$ns_
initial_node_pos $node_(0) 5
$ns_
initial_node_pos $node_(1) 5
# Setup traffic
flow between nodes
# TCP connections
between node_(0) and node_(1)
set tcp [new
Agent/TCP]
$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"
proc record {} {
global sink f0
#Get an instance of the simulator
set ns [Simulator instance]
#Set the time after which the procedure
should be called again
set time 0.5
#How many bytes have been received by
the traffic sinks?
set bytes [$sink set bytes_]
#Get the current time
set now [$ns now]
#Calculate the bandwidth (in MBit/s)
and write it to the files
puts $f0 "$now [expr
$bytes/$time*8]"
#Reset the bytes_ values on the traffic
sinks
$sink set bytes_ 0
#Re-schedule the procedure
$ns at [expr $now+$time]
"record"
#
puts "getting out of record()"
#
puts "$now"
}
#
# Tell nodes when
the simulation ends
#
for {set i 0} {$i
< $val(nn) } {incr i} {
$ns_ at 150.0 "$node_($i) reset";
}
$ns_ at 0.0
"record"
$ns_ at 150.01
"puts \"NS EXITING...\""
$ns_ at 150.02
"stop"
proc stop {} {
global ns_ tracefd namfd f0
$ns_ flush-trace
close $namfd
close $tracefd
exec nam wireless.nam &
$ns_ halt
}
puts
"Starting Simulation..."
$ns_ run
Step24: now go to
home folder/ashrafi/ns-allinone-2.34 then paste wireless-tcp.tcl file
in home folder/ashrafi/ns-allinone-2.34 just
press Ctrl+L u'll see the directory like
home/ashrafi/ns-allinone-2.34 then copy it and back to the terminal and paste
it as step25
Step25:
cd/home/ashrafi/ns-allinone-2.34
Step26: ls
Step27: ns wireless-tcp.tcl
Step28: ls
Step29: nam wireless-tcp.nam
Step30: exit
Step31: sudo
apt-get install xgraph