Академический Документы
Профессиональный Документы
Культура Документы
1. INTRODUCTION 1.8e+06
"out2.xgr"
This document is a quick tutorial on ns-2 [4]. It introduces basic 1.6e+06 "out4.xgr"
simulation aspects of wireless networking. Other detailed tutorials "out6.xgr"
1.4e+06
Throughput (bits/s)
and documentation can be found in [4, 2, 3]. We assume the reader
1.2e+06
is using a Linux machine (on which ns is already installed) and is
familiar with common Linux basics. 1e+06
800000
Here are some conventions used throughout this document: 600000
400000
200000
• ˜ns/ is the ns directory (.../ns-allinone-2.33/)
0
0 50 100 150 200
• Templates for the examples in this tutorial can be found in Time (s)
˜ns/quick-tutorial/.
Figure 1: Throughputs of nodes WT(1), WT(3) and WT(5)
• This document can be found in
˜ns/quick-tutorial/quick-tutorial.pdf
ns ex6sta.tcl.
60 6
You will see a graph popping up with 3 curves (Figure 1): the 5
1
Like all array variables opt() used throughout the script, opt(nn) -agentTrace ON \
is defined (=6) at the beginning of ex6sta.tcl. coord_proc -routerTrace OFF \
is a procedure we define to compute the values to be assigned to -macTrace OFF \
X , Y (coordinates) of each node WT(i). ns-2 does not take the -movementTrace OFF
Z elevation into consideration (flat 2-D topologies only).
We use CBR (constant bit rate) sources, over UDP layers, that we agent traces are the ones written by traffic sources/destinations.
attach to nodes WT(1),WT(3) and WT(5): Router traces are written by packet forwarders. MAC traces are
written by each node’s MAC. Nodes’ movements can be traced by
switching movementTrace ON (we don’t need it for the mo-
for {set i 1} {$i < $opt(nn)} {incr i 2} { ment).
set udp($i) [new Agent/UDP]
$ns_ attach-agent $WT($i) $udp($i) We use the basic mode (no RTS/CTS,
i.e. Mac/802_11 set RTSThreshold_ 3000), and the chan-
set sink($i) [new Agent/Null] nel capacity is set to 2Mbps
$ns_ attach-agent $WT([expr $i +1]) $sink($i) (Mac/802_11 set dataRate_ 2.0e6)
$ns_ connect $udp($i) $sink($i)
A god (General Operations Director) needs to be created:
set cbr($i) [new Application/Traffic/CBR]
$cbr($i) set packetSize_ 1000
create-god $opt(nn)
$cbr($i) set interval_ 0.005
$cbr($i) attach-agent $udp($i)
god is an object that is used to store global information about the
$ns_ at [expr 20.0 * $i] "$cbr($i) start" state of the environment, network and nodes that an omniscient ob-
$ns_ at $opt(stop) "$cbr($i) stop" server would have (without being available to any participant in the
} simulation). It accelerates the computation of the network rout-
ing/connectivity prior to the simulation run. We still need to create
it even though we use no routing in our simulations.
For a UDP source in WT(i), we place a “sink” at WT(i+1) to receive
the packets. Each CBR source sends 1000-Bytes packets each 5ms,
Finally, at the end of the simulation (at t=opt(stop)), we reset
therefore it can occupy alone the total channel capacity (2 Mbits/s
all wireless nodes and we call a procedure finish. In this pro-
in this example). We schedule the sources to start at t1 = 20s,
cedure, we call some external tools to filter, compute and display
t2 = 60s and t3 = 100s respectively, and to stop at t4 = 150s.
throughput graphs. Everything is based on the trace file out.tr.
Open and display it while you follow the explanation. out.tr
Lower layers of Mobile nodes are configured as follows:
looks like this:
2
following lines (between {}) which are applied to each line of the 3. ADDING AN INFRASTRUCTURE
trace file. As in previous section, we start by showing the result of the ns
script. Go to ˜ns/quick-tutorial/ and run ns infra.tcl.
Simulations will start, then xgraph pops up showing a throughput
if ($1=="r" && $7=="cbr" && $3=="_1_") {
graph. You can open Nam (Network AniMator) to see the network
sec[int($2)]+=$8;
topology by typing: nam infra-out.tcl (you must zoom-in to see it
};
properly). Figure 4 shows it more clearly.
It indicates that if the value in column 1 ($1) is r (packet received) W(0): 0.0.0
and the value in column 7 ($7) is cbr (packet type) and the value
in column 3 ($3) is _1_ (WT(2)), then add the packet size ($8) to
the throughput in sec[int($2)].
At the end of the trace file, awk displays (output directed to out1.xgr) W(1): 0.1.0
the array values as:
5 Mbps / 2 ms
X Y
sec[i] throughput[i]
in bits/s.
HA: 1.0.0
FA: 2.0.0
Exercises:
With this basic information, you are asked to do the following:
MH: 1.0.1
3
How do we tell the HA to forward the MH’s packets to its new One of these files is used by NAM. We will let you discover NAM’s
location (FA)? MobileIP takes care of this: GUI intuitively, and watch the packet runs on the wired links. Mo-
bile nodes can be seen moving in NAM. However, packets are not
shown on the wireless channel.
$ns_ node-config -mobileIP ON
As for the ns trace file, the structure differs slightly from the one
We have to register the MH at the corresponding Home Agent seen before since it combines wireless (similar to the previous one)
(HA): and wired traces. Since we are only interested in the throughput of
the MH (wireless), we only had to adapt the awk filter fil-tcp.awk
to count tcp packets instead of cbr ones:
set MH [$ns_ node 1.0.1]
set HAaddress [AddrParams addr2id [$HA node-addr]]
[$MH set regagent_] set home_agent_ $HAaddress if ($1=="r" && $7=="tcp" && $3=="_4_") {...
Exercises:
Therefore, when the MH moves towards the FA (starting at second
Now that you are familiar with wireless and wired networking sim-
100)
ulations, you are asked to simulate all scenarios presented in Figure
5 and Table 1.
$ns_ at 100.00 "$MH setdest 640.00 610.00 20.00" Sink
at a speed of 20m/s (640 and 610 are the coordinates of the FA),
the home agent (HA) will take care of tunneling MH’s packets to
the FA.
IEEE 802.11
AddrParams set domain_num_ 3
11 Mbps / basic mode
4
4. FAQ 5. REFERENCES
Q: Compilation problem... what’s wrong? [1] http://www.cs.hmc.edu/qref/awk.html.
A: Make sure there are no spaces after
$ns_ node-config -adhocRouting DumbAgent \ [2] Kevin Fall and Kannan Varadhan. The ns manual.
and all \s of the following lines. http://www.isi.edu/nsnam/ns/ns-documentation.html.
[3] M. Greis. Marc Greis’ Tutorial for the UCB/LBNL/VINT
Q: Even though the hidden nodes are far enough from each other, Network Simulator “ns”.
it seems they still can sense each other (no decrease in throughput). http://www.isi.edu/nsnam/ns/tutorial/index.html.
Why?
A: A common problem is to miss one of the “h”s in: [4] The VINT Project. Network Simulator.
Phy/WirelessPhy set CSThresh\_ http://www.isi.edu/nsnam/ns/.