RFG
RFG
RFG
IT 312
Submitted by Submitted to
AJAY YADAV Janardan Verma
ROLL_NO: 11510516
SECTION-IT-1
1
Table of Contents
1.EXPERIMENT 1.............................................................................................. 3
1.1 EXPERIMENT 1.1 .............................................................................................................................................. 3
1.2 EXPERIMENT 1.2 .............................................................................................................................................. 5
2. EXPERIMENT 2........................................................................................... 15
2.1 EXPERIEMNT 2.1 ................................................................................................................................................. 15
2.2 EXPERIMENT 2.2 ................................................................................................................................................. 18
2.3 EXPERIEMNT 2.3 ................................................................................................................................................. 21
3. EXPERIMENT 3........................................................................................... 32
4. EXPERIMENT 4 ........................................................................................... 37
4.1 EXPERIEMNT 4.1 ................................................................................................................................................. 37
4.2 EXPERIMENT 4.2 ................................................................................................................................................. 42
4.3 EXPERIEMNT 4.3 ................................................................................................................................................. 47
2
Experiment -1.1
1. Create the following scenario with two nodes n0 and n1 and link in between.
– Sender agent: Agent/UDP
– Receiver agent: Agent/Null
– Connect agents
– Data source: Application/Traffic/CBR
– Run from 0.5 to 4.5 sec, finish at 5.0 sec
Source Code :
3
OUTPUT :
4
Experiment -1.2
2. Create the following scenario and connect the appropriate agents
Start the FTP application at t = 0.5s
Start the CBR data source at t = 1s
Terminate both at t = 4.5 s
Visualize the bottle neck queue
Source Code :
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exec nam out.nam &
exit 0
}
#tcp connection
set tcp [new Agent/TCP]
$tcp set class_ 2
$ns attach-agent $n0 $tcp
5
set sink [new Agent/TCPSink]
$ns attach-agent $n3 $sink
$ns connect $tcp $sink
$tcp set fid_ 1
6
OUTPUT :
7
Experiment-1.3
Write a TCL script to simulate a file transfer with using ns 2:
Consider a client and a server. The server is running a FTP application (over TCP).
The client sends a request to download a file of size 10 MB from the server. Write a
script to simulate this scenario. Let node #0 be the server and node #1 be the client.
TCP packet size is 1500 B. Assume typical values for other parameters.
Source Code :
global ns
proc finish {} {
global ns nf
$ns flush-trace
close $nf
8
exec nam out.nam &
exit 0
$ns run
9
OUTPUT :
10
Experiment -1.4
Consider a small network with five nodes n0, n1, n2, n3, n4, forming a star topology.
The node n4 is at the center. Node n0 is a TCP source, which transmits packets to
node n3 (a TCP sink) through the node n4. Node n1 is another traffic source, and
sends UDP packets to node n2 through n4. The duration of the simulation time is 10
seconds.
Source Code :
11
$ns connect $tcp $sink
12
$ns at 9.0 "$ftp stop"
proc finish {} {
$ns flush-trace
close $namfile
close $tracefile
exit 0
$ns run
13
OUTPUT :
14
Experiment-2.1
Consider the LAN with seven nodes to be an isolated one i.e. not connected to the
Internet. Node # 0 in the LAN act as a UDP traffic source, and node # 6 is the
destination node. Assume CBR traffic to be flowing between the nodes. The
simulation lasts for 25 seconds. In Ethernet a packet is broadcasted in the shared
medium, and only the destination node accepts the packet. Other nodes simply drop it.
How many hops a packet should take to travel from node # 0 to node # 6? Verify this
from the "Hop Count" plot.
Source Code :
set lan [$ns newLan "$n0 $n1 $n2 $n3 $n4 $n5 $n6" 100Mb 0.5ms LL Queue/DropTail Mac/802_3 Channel
Phy/WiredPhy]
15
$ns duplex-link-op $n0 $n1 orient right-down
proc finish {} {
$ns flush-trace
close $tracefile
close $namfile
exit 0
$ns run
16
OUTPUT :
17
Experiment 2.2
Create the following scenario with two nodes and link in between.
– Sender agent: Agent/UDP
– Receiver agent: Agent/Null
– Connect agents
– Data source: Application/Traffic/CBR
– Run from 0.5 to 4.5 sec, finish at 5.0 sec
Source Code :
#open tracefiles
proc finish {} {
$ns flush-trace
close $tracefile1
close $namfile
exit 0
18
set n1 [$ns node]
$ns run
19
OUTPUT :
20
Experiment 2.3
Source Code :
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exec nam out.nam &
exit 0
}
#tcp connection
21
set tcp [new Agent/TCP]
$tcp set class_ 2
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $n3 $sink
$ns connect $tcp $sink
$tcp set fid_ 1
22
OUTPUT :
23
Experiment 2.4
In the following simulation scenario set the following parameters:
Duplex link between n1 and n2
Simplex link between node n0 and n2
Queue Size of link n2-n3 to 40
CBR traffic packet size: 1000B, inter-arrival time: 8ms, start at time 1.0; TCP
window size 8000, packet size 512B
Generate nam trace and show animation
Source Code :
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exit 0
24
set n0 [$ns node]
25
set udp [new Agent/UDP]
$ns at 4.5 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n3 $sink"
$ns run
26
OUTPUT :
27
Experiment 2.5
Generate the following simulation scenario
Source Code :
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exit 0
28
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
29
set cbr [new Application/Traffic/CBR]
$ns run
30
OUTPUT :
31
Experiment 3 : Simulating link errors using ns2
Consider the following topology:
Here node # 2 act as a router. Any traffic to or from the LAN passes through it.
Consider node # 1 running a FTP server, and node # 5 is downloading a file of size 4
MB. However, the link between node # 2 and # 3 is fault. It drops packets with a fixed
probability of 0.2. Implement a link error model to reflect this.
It may be noted here that the file download time will be more than the we had in
exercise # 2 of experiment # 1. Try different values of the simulation time to ensure
that the file has been entirely transferred. Is the plot of bytes received a linear curve or
non-linear? Why?
Presence of link errors cause one or more packets to be retransmitted. Verify this from
the "Packet Retransmissions" plot.
Source Code :
32
set n5 [$ns node]
set lan [$ns newLan "$n3 $n4 $n5 $n6" 10Mb 10ms LL Queue/DropTail Mac/802_3 Channel]
33
set ftp [new Application/FTP]
proc finish {} {
$ns flush-trace
close $namfile
close $tracefile
set awkCode {
BEGIN{}
else
END{}
exec xgraph -bb -tk -x Time -x Bytes lab4.data -bg white &
34
exec xgraph -bb -tk -x Time -y packets lab4_packets.data -bg white &
exit 0
$ns run
35
OUTPUT :
36
Experiment 4: Measuring Network Performance
1. Simulating Bottleneck in the network using ns2:
Consider a dumbbell topology with eight nodes as shown as in the following figure.
Consider nodes # 2 and 3 to be two routers connecting two different networks. When
the bandwidth of the link 2-3 is much lower than the sum of bandwidths of the other
links in the network, it act as a bottleneck.
Assume node # 0 running a FTP application (over TCP) and sending data to node # 6.
Node # 1 is sending CBR data node # 7. Assume all the links except 2-3 has a
bandwidth of 1 Mb, propagation delay of 10ms and queue type as DropTail. (All are
duplex links).
Tasks:
o The link 2-3 has a propagation delay of 10 ms. Vary it's bandwidth from 0.5
Mb to 2.5 Mb in steps of 0.25Mb.
o Compute the throughput for node # 3 in each case
o Plot the throughput vs. bandwidth data in the "Custom Plot" section below
Based on the above plots, suggest what should be the recommended bandwidth of the
link 2-3.
Now, plot the end-to-end delay between nodes 0 and 6 for the above chosen values of
link 2-3 bandwidth. Revisit your previous answer (i.e. optimum bandwidth of link 2-
3) based on these graphs.
Source Code :
37
set tracefile [open ex_05a.tr w]
38
set tcp [new Agent/TCP]
39
$ns at 9.0 "$cbr stop"
proc finish {} {
$ns flush-trace
close $namfile
close $tracefile
exec xgraph -bb -tk -x Time -x Bytes ex05a.data -bg white &
exec xgraph -bb -tk -x Time -y packets ex05a_packets.data -bg white &
exit 0
$ns run
40
OUTPUT :
41
Experiment 4.2
Set up the network topology and run the simulation scenario as shown below
Source code :
proc finish {} {
global ns nf
$ns flush-trace
close $nf
42
exit 0
43
$ns attach-agent $n4 $sink1
44
#Call the finish procedure after 5 seconds of
simulation time $ns at 5.0 "finish"
$ns run
45
OUTPUT :
46
Experiment 4.3
2. Create a 10 node wireless topology. The nodes use AODV (an ad-hoc routing
protocol) to route packets among themselves. They also use
a. 802.11 mac
b. two-ray ground radio propagation model
c. priority queue with queue length of 50
d. omni-directional antenna
e. topology of 670 X 670.
f. the simulation stops at 200s
Source Code :
set a 1
while {$a == 1 } {
47
if {$top == 1}
{
Channel/WirelessChann
set opt(chan) el ;# channel type
Propagation/TwoRayGround ;# radio-propagation
set opt(prop) model
Phy/WirelessP
set opt(netif) hy ;# network interface type
Queue/DropTail/PriQueu
set opt(ifq) e ;# interface queue type
;# X dimension of
set opt(x) 1800 topography
;# Y dimension of
set opt(y) 840 topography
create-god $opt(nn)
48
set chan_1_ [new $opt(chan)]
-llType $opt(ll) \
-macType $opt(mac) \
-ifqType $opt(ifq) \
-ifqLen $opt(ifqlen) \
-antType $opt(ant) \
49
-propType $opt(prop) \
-phyType $opt(netif) \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace ON \
-channel $chan_1_
50
set n18 [$ns_ node]
set i 0
incr i
51
$n4 set X_ 201.0
52
$n11 set Y_ 194.0
53
$n18 set Y_ 626.0
54
$n19 set X_ 666.0
55
$ns_ at 0.25 "$n13 setdest 551.0 624.0 25.0"
56
$ns_ initial_node_pos $n14 70
57
$ns_ initial_node_pos $n17 70
58
$ns_ at 0.0 "$n18 label node18"
59
$ns_ at 0.0 "$n10 color yellow"
60
$n21 color orange
# COLORING THE
NODES $n9 color blue
61
$ns_ at 7.43 "$n9 label TTLover"
62
$ns_ at 2.4 "$cbr2 start"
63
set cbr6 [$udp6 attach-app Traffic/CBR]
64
set udp10 [$ns_ create-connection UDP $n4 LossMonitor
$n2 0] $udp10 set fid_ 1
#ANNOTATIONS DETAILS
$ns_ at 4.1 "$ns_ trace-annotate \"NODE27 CACHE THE DATA FRO SERVER\""
65
### PROCEDURE TO
$ns_ flush-trace
close $tracefd
exit 0
$ns_ run
} elseif {$top == 2} {
# Define options
Channel/WirelessChan
set val(chan) nel ;# channel type
Propagation/TwoRayGround ;# radio-propagation
set val(prop) model
Phy/WirelessPh
set val(netif) y ;# network interface type
Queue/DropTail/PriQue
set val(ifq) ue ;# interface queue type
set val(ll) LL ;# link layer type
set
val(ifqlen) 50 ;# max packet in ifq
66
set val(rp) DSDV ;# routing protocol
;# time of simulation
set val(stop) 100 end
$ns use-newtrace
Antenna/OmniAntenna set X_ 0
Antenna/OmniAntenna set Y_ 0
create-god $val(nn)
67
# configure the nodes
-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 ON
68
$node_(2) set Y_ 240.0
# Generation of movements
69
set tcp [new Agent/TCP]
70
agent $node_(0) $tcp $ns
attach-agent $node_(4) $sink
$ns connect $tcp $sink
71
# Define node initial position in nam for
{set i 0} {$i < $val(nn)} { incr i } {
# 30 defines the node size for nam
proc stop {} {
$ns flush-trace
close $tracefd
close $namtrace
exit 0
$ns run
} elseif {$top == 3} {
set Channel/WirelessChan
opt(chan) nel ;# channel type
Propagation/TwoRayGround ;# radio-propagation
set opt(prop) model
Phy/WirelessPh
set opt(netif) y ;# network interface type
72
set opt(mac) Mac/802_11 ;# MAC type
Queue/DropTail/PriQue
set opt(ifq) ue ;# interface queue type
set
opt(ifqlen) 50 ;# max packet in ifq
;# number of
set opt(nn) 3 mobilenodes
set opt(rp) DSR ;# routing protocol
;# X dimension of
set opt(x) 500 topography
;# Y dimension of
set opt(y) 400 topography
[open dsr.nam
set namtrace w]
create-god $opt(nn)
73
-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 \
-agentTrace ON \
-routerTrace ON \
-macTrace OFF \
-movementTrace ON
74
# Generation of movements
75
# ending nam and the simulation
proc stop {} {
$ns flush-trace
close $tracefd
close $namtrace
exit 0
$ns run
76
OUTPUT :
77
78