Vous êtes sur la page 1sur 5

Network Simulator 2 (NS2)

Basics and Mobility Management

1. Experiment 1
Let the following example be considered. All links in this network have a bandwidth of 1
Mbit/s. Please go through the tasks (1-1) to (1-4). The results of each task should be saved in
a separate file, e.g., task1_1.tcl, task1_2.tcl, etc.

Figure 1: First example network

Task 1-1
1. Save the given script under “task1_1.tcl”
2. Run the simulation. This is executed through using the command "ns task1_1.tcl".
3. Observe the progress of the simulation using the program "nam". What do you
notice? Please pay attention of the following:
a. Labels
b. Establishment / Termination of FTP and CBR connections
c. Bandwidth of FTPand CBR connections
d. Queue on the link between node (2) and node (5)
e. FTP connection reaction on lost packets

Task 1-2:
In order to recognize both FTP and CBR traffic, please color the TCP traffic with red and
UDP with blue.

1
Task 1-3:
Intermediate nodes (2) and (5) are not connected by means of synchronous connection as
before, but by means of asynchronous connection (e.g. ADSL) that has the following
parameters: downstream from node (2) to (5) with 1Mbit/s and upstream from node (5) to (2)
with 128Kbit/s.
1. Save the current script under “task1_3.tcl”
2. What is the basic idea for such a connection?
3. Create the asynchronous connection using the parameters given above
4. Run the simulation

Task 1-4:
The parameter „packetSize“ or „interval“ can be used to reduce the bit rate of the CBR traffic
source so that no dropping in FTP is produced. Try to tune these parameters until no dropping
in TCP traffic is produced. See the results using the program "nam".

2. Experiment 2
Let the following example be considered. All links in this network have a bandwidth of 1
Mbit/s. Please go through the tasks (2-1) to (2-5). The results of each task should be saved in
a separate file, e.g., task2_1.tcl, task2_2.tcl, etc.

Figure 2: Third example network

Task 2-1:
1. Save the script under the name “task2_1.tcl”
2. Run the simulation of “task2_1.tcl”. This is executed through using the command
"ns task2_1.tcl <file name1>.nam < file name 2>.tr".
<file name1>.nam is the file responsible for the visualization of simulation results
using the program "nam". However, < file name 2>.tr is used for „xgraph”. Notice
please that the task will not write currently anything in < file name 2>.tr

2
3. Observe the progress of the simulation using the program "nam". Use the
command „nam < file name1>.nam“.
4. What do you notice? Please pay attention of the following:
a. Labels
b. Establishment / Termination of FTP and CBR connections
c. Routing path between CN and MN
d. The movement path and speed of the MN
e. Handoff actions and their influences
f. Packet loss within Handoffs

Task 2-2:
1. Save the file “task2_1.tcl” under the name „task2_2.tcl“
2. Open “task2_2.tcl” and go to this paragraph
# Configure for ForeignAgent and HomeAgent nodes
$ns_ node-config -mobileIP ON \
-adhocRouting $opt(adhocRouting) \
-llType $opt(ll) \
-macType $opt(mac) \
-ifqType $opt(ifq) \
-ifqLen $opt(ifqlen) \
-antType $opt(ant) \
-propType $opt(prop) \
-phyType $opt(netif) \
-channelType $opt(chan) \
-topoInstance $topo \
-wiredRouting ON \
-agentTrace ON \
-routerTrace ON \
-macTrace ON
Switch off each of “agentTrace”, “routerTrace” and “macTrace” (OFF instead of
ON)
3. Run the simulation of this example and visualize it via „nam“.
4. What are the differences in comparison to task2_1.tcl?

Task 2-3:
In this example the CN, node (1) in the figure above, sends UDP packets towards the MN,
node (9) in the figure. UDP packets are redirected during the simulation to the current
location of the MN. There will be few lost packets during the redirecting of UDP packets
towards the new location of MN. For performance analysis, it is very important to measure
the number of these lost packets. To do such a measurement, please work as follows:
1. Save the file “task2_2.tcl” under the name „task2_3.tcl“
2. Add the following paragraph to the file “task2_3.tcl”
set UDPSource [new Agent/UDP]
$ UDPSource set class_ 2
set UDPSink [new Agent/LossMonitor]
$ns_ attach-agent $W1 $UDPSource
$ns_ attach-agent $MH(0) $UDPSink
$ns_ connect $UDPSource $UDPSink

3
set CBRApplication [new Application/Traffic/CBR]
$CBRApplication attach-agent $UDPSource
$CBRApplication set type_ CBR
$CBRApplication set packetSize_ 1500
$CBRApplication set interval_ 20ms
$ns_ at 1.0 "$CBRApplication start"
Then write the following code:
$ns_ at 1.0 "Record"
"Record" is a procedure that writes the number of lost packets in the file <file name2>. tr.
This procedure is carried out periodically (every 10 msec). The following section should be
added to the file "task2_3.tcl"
proc Record {} {
global UDPSink xgrfile
#Get an instance of the simulator
set ns_ [Simulator instance]
#Set the time in seconds, after which the procedure should be
#called again
set time 0.01
#Reading, how many packets are dropped in the traffic sink?
set DP [$UDPSink set nlost_]
#Get the current time
set now [$ns_ now]
#Writing the number of the dropped packets in $xgrfile
puts $xgrfile "$now $DP"
#Reset the number od the dropping packets in the traffic sink
$UDPSink set nlost_ 0
#Re-schedule the procedure
$ns_ at [expr $now+$time] "Record"
}
3. Try to interpret the added code of procedure “Record”
4. Run the simulation and show the number of lost packets via the program„xgraph“.
This is executed through using the command „xgraph <file name2>.tr -geometry
800*400 &“.
5. Interpret your results

Task 2-4:
In this task, the delay on the link between nodes (0) and (4) should be varied. The aim is to
analyze the influence of this variation on the number of lost packets.
1. Save the file “task2_3.tcl” under the name „task2_4.tcl“
2. Run the simulation of the file “task2_4.tcl”
3. Set the delay of the link between nodes (0) and (4) to 40 msec. You can change the
link delay by modifying this line in the script
$ns_ duplex-link $W0 $HA 100Mb 20ms DropTail
to
$ns_ duplex-link $W0 $HA 100Mb 40ms DropTail

4. Start the simulation of the file “task2_4.tcl”. This will be executed by typing the
command „ns task2_4.tcl <file name1>.nam <file name2x>.tr“

4
5. Repeat steps 2 and 3. Set the delay to 60, 80 and 100 msec. pay attention that "x" in
"<file name 2x > should always be changed, so that at the end you have 5 files, i.e.
one for each link delay (20, 40, 60, 80 and 100 msec)
6. Show the number of lost packets for the 5 values of the link delay by means of
"xgraph". This will be executed by typing the command „xgraph <first file
name>.tr <seconed file name>.tr <third file name>.tr <fourth file name>.tr <fifth
file name>.tr -geometry 800*400 &“
7. Interpret your results

Task 2-5:
Repeat the task 2-4 using the following parameters: set the link delay to 20 msec. Change the
speed of the MN instead of changing the link delay between 20 km/h and 100 km/h in step of
20 km/h, i.e., 20, 40, 60, 80, and 100 km/h. The speed of the MN can be changed by
modifying the value „11.1111“in the following line.
$ns_ at 2.0 "$MH(0) setdest 210.0 550.0 11.1111"
Pay attention that the value 11.1111 is in msec and stand for 40 km/h.

Vous aimerez peut-être aussi