Weisheng Si
Director of Academic Program - Postgrad ICT
Senior Lecturer in Networking
School of Computer, Data and Mathematical Sciences, WSU
Post: Bldg ER, Parramatta South Campus, Parramatta, NSW 2150
E: w.si a-t WesternSydney.edu.au
As a split-language, object-oriented network simulator, ns-2 is very flexible for plumbing network components. However, since the source codes of ns-2 are contributed by different parties, it appears a little messy.
For doing research in wireless networks, I learned to use ns-2.
Some of my experiences with it are recorded here to prevent me from
forgetting and to ease others' life. The version of ns-2 discussed here is
ns-allinone-2.31. If any comments, very welcome to let me know.
1. Enable the debugging of ns-2 with gdb/ddd completely,
including the otcl, tcl parts
The following three steps are needed before executing
./install:
1) Edit file: <allinone>/install
a) Locate the part for "Build Tcl<Version>", and
add option '--enable-symbols' to the ./configure command, so
that it becomes
./configure --enable-gcc
--enable-symbols ...
b) Locate the part for "Build Tk<Version>", and
add option '--enable-symbols' to the ./configure command, so
that it becomes
./configure --enable-gcc
--enable-symbols ...
c) Locate the part for "Build Otcl<Version>", and
add option '--enable-debug' to the ./configure command, so
that it becomes
./configure --enable-debug ...
d) Locate the part for "Build tclcl<Version>", and
add option '--enable-debug' to the ./configure command, so
that it becomes
./configure --enable-debug ...
e) Locate the part for "Build ns<Version>", and
add option '--enable-debug' to the ./configure command, so
that it becomes
./configure --enable-debug ...
2) Edit file: <allinone>/<tcl8>/unix/configure (do the same for <tk8>)
Search for DBGX and replace DBGX=g with DBGX="".
Otherwise, the debuggable library produced has a name with a
trailing "g".
By default, ns-2 will not link this library.
3) Edit file: <allinone>/<ns>/configure
Comment the line: #V_CCOPT="$V_CCOPT -Wall -Werror"
Otherwise, warnings will be treated as errors when <ns> is
compiled.
If you don't perform these three steps when you first install ns-2, don't
worry. You just perform these steps and execute ./install again. The later
installation will overwrite the previous installation.
If you know better techniques to enable the debugging, please let me know.
2. Where to find the documentation about
Otcl?
In the "otcl" directory of the <allinone> distribution, there is a directory
named "doc",
which contains the authoritative documentation on otcl. It's faster to look at
them than
to browse the web.
3. The steps that ns-2 execute to create a
wireless node.
1) $ns node-config
set up variables to specify the type of nodes to be created
2) $ns node
call create-wireless-node
3) $ns create-wireless-node
a) call create-node-instance, which invokes the constructor
of Node/MobileNode
this constructor "init" does
the following:
calls
the constructor "init" of Node
$node mk-default-classifier
$node set reg_module_([$mod module-name]) $mod
$node install-entry $self $classifier_
initializes X_, Y_, Z_, arptable_, nifs_ to 0 or ""
b) create the routing agent
c) attach the routing agent to the node
d) add the wireless interface to the node
4. A small bug in ns-lib.tcl
In the procedure "Simulator instproc node-config", the command
warn "Please use -channel as shown in tcl/ex/wireless-mitf.tcl"
should appear in the next elseif body: "elseif {[info exists channel_]}"
Currently, this bug doesn't affect the correctness of simulation.
5. A small bug in common/mobilenode.cc
int MobileNode::command(int argc, const char*const* argv)
There is a conflict between objects WiredPhy and
WirelessPhy in the implementation of "addif". Currently, this bug doesn't affect the correctness of
simulation.
6. The steps of setting up dynamic links
1). Set up bidirectional dynamic links, with each command
creating a new rtmodel
$ns rtmodel model-name params elements
;# in rtglib/dynamics.tcl
e.g. $ns rtmodel Deterministic { 0.1 1 1 } $n0 $n1
set ret [eval new rtModel/$dist $self]
# add link_(0:1) and link_(1:0), if exist, to "links_($i)"
eval $ret set-elements $args
eval $ret set-parms $parms
set trace [$self get-ns-traceall]
if {$trace != ""} {
$ret trace $self $trace
;# calling trace-dynamics for all links_($i)
}
lappend rtModel_ $ret
2). Simulator instproc run {}
$self rtmodel-configure
;# in rtglib/dynamics.tcl
for every rtModel/$dist, call
rtModel/$dist configure
3). rtModel/$dist configure
;# in rtglib/dynamics.tcl
for every $links_($i), call
$links_($i) dynamic
;# creating the DynamicLink object for this link
$self set-first-event
7. How to configure the data rate of MAC
layer?
1) tcl/lan/ns-mac.tcl
Mac/802_11 set basicRate_ 1Mb ;# set
this to 0 if want to use bandwidth_
Mac/802_11 set dataRate_ 1Mb ;#
for both control and data pkts
2) tcl/lib/ns-default.tcl
Mac/802_11 set PLCPDataRate_ 1.0e6
;# 1Mbps
Both files are sourced by ns-lib.tcl
8. How to get the current system time?
#include "scheduler.h"
Call Scheduler::instance().clock()
The unit of time is second