Write a TCL script to simulate the following scenario with ns2 simulator. Consider six nodes, (as shown in the figure below) moving within a flat topology of 700m x 700m. The initial positions of nodes are 0 (150,300) ,1 (300,500),2 (500,500),3 (300,100),4(500,100) and 5(650,300) respectively.A TCP connection is initiated between node 0 (source) and node 5 (destination) through node 3 and node 4 i.e the route is 0345. At time t = 3 seconds the FTP application runs over it. After time t=4.0 sec, node 3 (300,100) moves towards node 1 (300,500) with a speed of 5.0m/sec and after some time the path break, then the data transmit with a new path via node 1 and node 2 i.e the new route 0125. The simulation lasts for 60 secs. In the above said case both the route has equal cost. Use DSR as the routing protocol and the IEEE 802.11 MAC protocol. Now, Analyze the trace file and determine when the use of second route commence, and Plot the number of packets received by each node over the entire time duration of the simulation
TCL Script:
set ns [new Simulator]
set namfile [open namfile.nam w]
$ns namtrace-all-wireless $namfile 700 700
set wireless_tracefile [open dsr-6-nodes.tr w]
$ns trace-all $wireless_tracefile
$ns use-newtrace
set topography [new Topography]
$topography load_flatgrid 700 700
set god_ [create-god 6]
#globally node settings
$ns node-config -adhocRouting DSR \
-llType LL \
-macType Mac/802_11 \
-ifqType CMUPriQueue \
-ifqLen 50 \
-antType Antenna/OmniAntenna \
-propType Propagation/TwoRayGround \
-phyType Phy/WirelessPhy \
-channel [new Channel/WirelessChannel] \
-topoInstance $topography \
-agentTrace ON \
-routerTrace OFF \
-macTrace ON
# Create wireless nodes
set node(0) [$ns node]
$node(0) set X_ 150
$node(0) set Y_ 300
$node(0) set Z_ 0.0
$node(0) color "black"
$ns initial_node_pos
$node(0) 30.000000
set node(1) [$ns node]
$node(1) set X_ 300
$node(1) set Y_ 500
$node(1) set Z_ 0.0
$node(1) color "black"
$ns initial_node_pos
$node(1) 30.000000
set node(2) [$ns node]
$node(2) set X_ 500
$node(2) set Y_ 500
$node(2) set Z_ 0.0
$node(2) color "black"
$ns initial_node_pos
$node(2) 30.000000
set node(3) [$ns node]
$node(3) set X_ 300
$node(3) set Y_ 100
$node(3) set Z_ 0.0
$node(3) color "black"
$ns initial_node_pos
$node(3) 30.000000
set node(4) [$ns node]
$node(4) set X_ 500
$node(4) set Y_ 100
$node(4) set Z_ 0.0
$node(4) color "black"
$ns initial_node_pos
$node(4) 30.000000
set node(5) [$ns node]
$node(5) set X_ 650
$node(5) set Y_ 300
$node(5) set Z_ 0.0
$node(5) color "black"
$ns initial_node_pos
$node(5) 30.000000
$ns at 4.0 "$node(3) setdest 300.0 500.0 5.0"
$ns at 4.0 "$god_ set-dist 0 5 3"
set tcp [new Agent/TCP]
$ns attach-agent $node(0) $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $node(5) $sink
$ns connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns at 3.0 "$ftp start"
for {set i 0} {$i < 6 } {incr i} {
$ns at 60.000000 "$node($i) reset";
}
proc finish {}
{
global ns
$ns flush-trace
exit 0
}
$ns at 60.000000 "finish"
$ns run
TCL Script:
set ns [new Simulator]
set namfile [open namfile.nam w]
$ns namtrace-all-wireless $namfile 700 700
set wireless_tracefile [open dsr-6-nodes.tr w]
$ns trace-all $wireless_tracefile
$ns use-newtrace
set topography [new Topography]
$topography load_flatgrid 700 700
set god_ [create-god 6]
#globally node settings
$ns node-config -adhocRouting DSR \
-llType LL \
-macType Mac/802_11 \
-ifqType CMUPriQueue \
-ifqLen 50 \
-antType Antenna/OmniAntenna \
-propType Propagation/TwoRayGround \
-phyType Phy/WirelessPhy \
-channel [new Channel/WirelessChannel] \
-topoInstance $topography \
-agentTrace ON \
-routerTrace OFF \
-macTrace ON
# Create wireless nodes
set node(0) [$ns node]
$node(0) set X_ 150
$node(0) set Y_ 300
$node(0) set Z_ 0.0
$node(0) color "black"
$ns initial_node_pos
$node(0) 30.000000
set node(1) [$ns node]
$node(1) set X_ 300
$node(1) set Y_ 500
$node(1) set Z_ 0.0
$node(1) color "black"
$ns initial_node_pos
$node(1) 30.000000
set node(2) [$ns node]
$node(2) set X_ 500
$node(2) set Y_ 500
$node(2) set Z_ 0.0
$node(2) color "black"
$ns initial_node_pos
$node(2) 30.000000
set node(3) [$ns node]
$node(3) set X_ 300
$node(3) set Y_ 100
$node(3) set Z_ 0.0
$node(3) color "black"
$ns initial_node_pos
$node(3) 30.000000
set node(4) [$ns node]
$node(4) set X_ 500
$node(4) set Y_ 100
$node(4) set Z_ 0.0
$node(4) color "black"
$ns initial_node_pos
$node(4) 30.000000
set node(5) [$ns node]
$node(5) set X_ 650
$node(5) set Y_ 300
$node(5) set Z_ 0.0
$node(5) color "black"
$ns initial_node_pos
$node(5) 30.000000
$ns at 4.0 "$node(3) setdest 300.0 500.0 5.0"
$ns at 4.0 "$god_ set-dist 0 5 3"
set tcp [new Agent/TCP]
$ns attach-agent $node(0) $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $node(5) $sink
$ns connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns at 3.0 "$ftp start"
for {set i 0} {$i < 6 } {incr i} {
$ns at 60.000000 "$node($i) reset";
}
proc finish {}
{
global ns
$ns flush-trace
exit 0
}
$ns at 60.000000 "finish"
$ns run
No comments:
Post a Comment