#Crete simulator
set ns [new Simulator]
#set one communication line as blue and 2nd as red
$ns color 1 Blue
$ns color 2 Red
#create and open out.nam file in write mode
set nf [open out.nam w]
$ns namtrace-all $nf
#also create its trace file as testout.tr
set tf [open testout.tr w]
$ns trace-all $tf
#create nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
#define transactions (format node1 node2 Bandwidth delay queue)
$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns duplex-link $n2 $n3 [lindex $argv 0] 20ms DropTail
#set queue size for node2 and node3 to 10pkts
$ns queue-limit $n2 $n3 10
#draw the links to the node with specified orientations
$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n1 $n2 orient right-up
$ns duplex-link-op $n2 $n3 orient right
#setup a TCP(Transmission Control Protocol) connection, agent object between (node1-source and node2-sink)
set tcp [new Agent/TCP]
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $n3 $sink
$ns connect $tcp $sink
$tcp set fid_ 1
#setup a FTP(file transfer protocol)
set ftp [new Application/FTP]
$ftp attach-agent $tcp
#setup a UDP(User Datagram Protocol)
set udp [new Agent/UDP]
$ns attach-agent $n1 $udp
set null [new Agent/Null]
$ns attach-agent $n3 $null
$ns connect $udp $null
$udp set fid_ 2
#setup a CBR (Constant Bit Rate) over UDP connection, pkt bytes, rate
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set packet_size_ 1000
$cbr set rate_ 1Mb
#Schedule events for the CBR and FTP agents
$ns at 0.1 "$cbr start"
$ns at 1.0 "$ftp start"
$ns at 4.0 "$ftp stop"
$ns at 4.5 "$cbr stop"
#finish handler
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exec nam out.nam &
exit 0
}
#Call finish procedure after 5 seconds of simulation time
$ns at 5.0 "finish"
#Run the simulation
$ns run
AWK FILE
BEGIN {
tcp_send = 0; tcp_received = 0; tcp_drop = 0; tcp_throught = 0;
udp_send = 0; udp_received = 0; udp_drop = 0; udp_throught = 0;
} {
if ($5 == "tcp") {
if($1 == "-" && $3 == "0") tcp_send += $6;
if($1 == "r" && $4 == "3") tcp_received += $6;
if($1 == "d" && $4 == "3") tcp_drop += $6;
} else if($5 == "cbr") {
if($1 == "-" && $3 == "1") udp_send += $6;
if($1 == "r" && $4 == "3") udp_received += $6;
if($1 == "d" && $4 == "3") udp_drop += $6;
}
}
END {
printf("\n------------------------------------") >> "exp_2.txt";
printf("\nBandwidth: %s", bandwidth) >> "exp_2.txt";
printf("\n--------------TCP Data--------------") >> "exp_2.txt";
printf("\nSend: %d bytes", tcp_send) >> "exp_2.txt";
printf("\nReceived: %d bytes", tcp_received) >> "exp_2.txt";
printf("\nRatio of received/send : %.2f%%", tcp_received/tcp_send*100) >> "exp_2.txt";
printf("\nNumber of Packets dropped : %d", (tcp_drop)) >> "exp_2.txt";
tcp_throught = ((tcp_send + tcp_received) / $2);
printf("\nThroughtput = %f", tcp_throught) >> "exp_2.txt";
printf("\n--------------UDP Data--------------") >> "exp_2.txt";
printf("\nSend: %d bytes", udp_send) >> "exp_2.txt";
printf("\nReceived: %d bytes", udp_received) >> "exp_2.txt";
printf("\nRatio of received/send : %.2f%%", udp_received/udp_send*100) >> "exp_2.txt";
printf("\nNumber of Packets dropped : %d", (udp_drop)) >> "exp_2.txt";
udp_throught = ((udp_send + udp_received) / $2);
printf("\nThroughtput = %f\n", udp_throught) >> "exp_2.txt";
printf("%s %d %d\n", bandwidth, tcp_received, udp_received) >> "receive_vs_bandwidth.log";
printf("%s %d %d\n", bandwidth, tcp_drop, udp_drop) >> "pkt_drop_vs_bandwidth.log";
printf("%s %f %f\n", bandwidth, tcp_throught, udp_throught) >> "throughput_vs_bandwidth.log"
}
shell file
#!/bin/bash
#ns command generate out.nam, testout.tr
#awk command generate exp_2.txt, receive_vs_bandwidth.log, pkt_drop_vs_bandwidth.log, throughput_vs_bandwidth.txt
ns ppt.tcl 1Mb
awk -v bandwidth="1.0" -f ppt_1.awk testout.tr
ns ppt.tcl 1.5Mb
awk -v bandwidth="1.5" -f ppt_1.awk testout.tr
ns ppt.tcl 2Mb
awk -v bandwidth="2.0" -f ppt_1.awk testout.tr
ns ppt.tcl 2.5Mb
awk -v bandwidth="2.5" -f ppt_1.awk testout.tr
ns ppt.tcl 3Mb
awk -v bandwidth="3.0" -f ppt_2.awk testout.tr
#gnuploat generate the graphs using all log files respectively each
gnuplot receive_vs_bandwidth.gp
gnuplot pkt_drop_vs_bandwidth.gp
gnuplot throughput_vs_bandwidth.gp
gnu 1
set title "Packets Drop over Bandwidth" set term post enh mono set out 'pkt_drop_vs_bandwidth.pdf' set key top set key right set key box set ytics 2000 set xtics 0.5 set xrange [0:3.5] set yrange [0:20000] set xlabel "Bandwidth (Mb)" set ylabel "Packets Drop (Bytes)" plot "pkt_drop_vs_bandwidth.log" using 1:2 title "tcp" with linespoints lw 3, \ "pkt_drop_vs_bandwidth.log" using 1:3 title "udp" with linespoints lw 3
gnu 2
set title "Packets Drop over Bandwidth"
set term post enh mono
set out 'pkt_drop_vs_bandwidth.pdf'
set key top
set key right
set key box
set ytics 2000
set xtics 0.5
set xrange [0:3.5]
set yrange [0:20000]
set xlabel "Bandwidth (Mb)"
set ylabel "Packets Drop (Bytes)"
plot "pkt_drop_vs_bandwidth.log" using 1:2 title "tcp" with linespoints lw 3, \
"pkt_drop_vs_bandwidth.log" using 1:3 title "udp" with linespoints lw 3
gnu 3
set title "Throughput over Bandwidth"
set term post enh mono
set out 'throughput_vs_bandwidth.pdf'
set key top
set key right
set key box
set ytics 100000
set xtics 0.5
set xrange [0:3.5]
set yrange [0:350000]
set xlabel "Bandwidth (Mb)"
set ylabel "Throughput (Bytes)"
plot "throughput_vs_bandwidth.log" using 1:2 title "tcp" with linespoints lw 3, \
"throughput_vs_bandwidth.log" using 1:3 title "udp" with linespoints lw 3
next
#include rtx51tny.h
#include reg51.h
int tid = 0;
void job0 (void) _task_ 0 {
P2 = 0xFF;
P1 = 0x00;
os_create_task(1);
os_create_task(2);
os_create_task(3);
os_delete_task(0);
}
void job1 (void) _task_ 1 {
while(1){
P1 = 0x55;
tid = os_running_task_id();
os_wait (K_IVL, 1, 0);
}
}
void job2 (void) _task_ 2 {
while(1){
P1 = 0xAA;
tid = os_running_task_id();
os_wait (K_IVL, 1, 0);
}
}
void job3 (void) _task_ 3 {
while(1){
P2 = ~P2;
tid = os_running_task_id();
os_wait (K_IVL, 1, 0);
}
}