Lab 2
Lab 2
# Nodes definition
create-god 3 # General Operations Director
# Create 3 nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
$n0 label "tcp0"
$n1 label "sink1/tcp1"
$n2 label "sink2"
$n0 set X_ 50
$n0 set Y_ 50
$n0 set Z_ 0
$n1 set X_ 100
$n1 set Y_ 100
$n1 set Z_ 0
$n2 set X_ 600
$n2 set Y_ 600
$n2 set Z_ 0
$ns at 0.1 "$n0 setdest 50 50 15"
$ns at 0.1 "$n1 setdest 100 100 25"
$ns at 0.1 "$n2 setdest 600 600 25"
# Agent definition
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
set sink1 [new Agent/TCPSink]
$ns attach-agent $n1 $sink1
$ns connect $tcp0 $sink1
set tcp1 [new Agent/TCP]
$ns attach-agent $n1 $tcp1
set ftp1 [new Application/FTP]
$ftp1 attach-agent $tcp1
set sink2 [new Agent/TCPSink]
$ns attach-agent $n2 $sink2
$ns connect $tcp1 $sink2
$ns at 5 "$ftp0 start"
$ns at 5 "$ftp1 start"
$ns at 100 "$n1 setdest 550 550 15"
$ns at 190 "$n1 setdest 70 70 15"
# Start simulation
$ns run
.awk file:
BEGIN {
count1 = 0;
count 2 = 0;
pack1 = 0;
pack2 = 0;
time1 = 0;
time2 = 0;
}
{
if ($1 == "r" && $3 == "_1_" && $4 == "AGT") {
count1++;
pack1 += $8;
time1 = $2;
}
if ($1 == "r" && $3 == "_2_" && $4 == "AGT") {
count2++;
pack2 += $8;
time2 = $2;
}
}
END {
printf("The throughput from n0 to n1 is %f Mbps\n", (count1 * pack1 * 8) / (t1 *
1000000));
printf("The throughput from n1 to n2 is %f Mbps\n", (count2 * pack2 * 8) / (t2 *
1000000));
}
Steps for execution
o Open gedit editor and type program. Program name should have the extension “ .tcl ”
[root@localhost ~]# gedit lab2.tcl
o Save the program and close the file.
o Open gedit editor and type awk program. Program name should have the extension
“.awk ”
[root@localhost ~]# gedit lab2.awk
o Save the program and close the file.
o Run the simulation program
[root@localhost~]# sudo ns lab4.tcl.
Here “ns” indicates network simulator.
o Now press the play button in the simulation window and the simulation will begins.
o After simulation is completed run awk file to see the output ,
[root@localhost~]# awk –f lab4.awk lab4.tr
o To see the trace file contents open the file as ,
[root@localhost~]# gedit lab4.tr