Write a TCL script to simulate a file transfer with ns2 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. Note: This simulation require transfer of a fixed size file. Therefore, time required for the transfer would be constant for a given bandwidth of a link. To verify this, determine the time that would roughly be required for the transfer. Then look at the bottom of the trace file and verify whether there is any transmission beyond the time calculated. To verify that the client has downloaded the entire file, plot the "Bytes Received" curve for node#1. The yaxis is in Kbits. Convert it to MB and verify whether it approximates the specified file size. TCP headers would effectively increase the count of received bytes at node # 1.
TCL Script:
set ns [new Simulator]
set namfile [open ex_02.nam w]
$ns namtrace-all $namfile
set tracefile [open ex_02.tr w]
$ns trace-all $tracefile
Agent/TCP set packetSize_ 1500
set n0 [$ns node]
set n1 [$ns node]
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
set tcp [new Agent/TCP]
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $n1 $sink
$ns connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
set filesize [expr 10*1024*1024]
$ns at 0.0 "$ftp send $filesize"
proc finish {}
{
global ns namfile tracefile
$ns flush-trace
close $namfile
close $tracefile
set awkCode
{
BEGIN{}
{
if ($1 == "r" && $4 == 1 && $6 > 1500)
{
count = count + $6 - ($6 % 1500);
print $2, count >> "ex_02.data";
}
}
END{}
}
exec awk $awkCode ex_02.tr
exec nam ex_02.nam &
exec xgraph -bb -tk -x Time -y Bytes ex_02.data -bg white &
exit 0
}
$ns at 100.0 "finish"
$ns run
TCL Script:
set ns [new Simulator]
set namfile [open ex_02.nam w]
$ns namtrace-all $namfile
set tracefile [open ex_02.tr w]
$ns trace-all $tracefile
Agent/TCP set packetSize_ 1500
set n0 [$ns node]
set n1 [$ns node]
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
set tcp [new Agent/TCP]
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $n1 $sink
$ns connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
set filesize [expr 10*1024*1024]
$ns at 0.0 "$ftp send $filesize"
proc finish {}
{
global ns namfile tracefile
$ns flush-trace
close $namfile
close $tracefile
set awkCode
{
BEGIN{}
{
if ($1 == "r" && $4 == 1 && $6 > 1500)
{
count = count + $6 - ($6 % 1500);
print $2, count >> "ex_02.data";
}
}
END{}
}
exec awk $awkCode ex_02.tr
exec nam ex_02.nam &
exec xgraph -bb -tk -x Time -y Bytes ex_02.data -bg white &
exit 0
}
$ns at 100.0 "finish"
$ns run
please explain
ReplyDeleteI am Mr.Pranshu
ReplyDeletePlease explain the code.
This comment has been removed by the author.
ReplyDeleteSara zamana haseeno ka dewana
ReplyDelete