Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Network Simulation with NS-2: TCP and UDP Traffic Analysis, Study notes of Network security

A comprehensive guide to network simulation using ns-2, focusing on tcp and udp traffic analysis. It includes detailed code examples demonstrating the creation of network topologies, configuring tcp and udp agents, and analyzing packet drops and throughput. Valuable for students and researchers interested in network performance evaluation and simulation.

Typology: Study notes

2022/2023

Uploaded on 09/14/2024

raksha-bharadwaj
raksha-bharadwaj 🇮🇳

1 document

1 / 17

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
01/03/2023, 11:20
5.tcl
about:blank
1/1
5.tcl
set ns [new Simulator]
set na [open 5.nam w]
$ns namtrace-all $na
set nt [open 5.tr w]
$ns trace-all $nt
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
$ns duplex-link $n0 $n1 10Mb 10ms DropTail
$ns queue-limit $n0 $n1 10
$ns duplex-link $n1 $n2 1Mb 10ms DropTail
$ns queue-limit $n1 $n2 1
set TCP [new Agent/TCP]
$ns attach-agent $n0 $TCP
set CBR [new Application/Traffic/CBR]
$CBR attach-agent $TCP
set SINK [new Agent/TCPSink]
$ns attach-agent $n2 $SINK
$ns connect $TCP $SINK
proc End {} {
global ns na nt
$ns flush-trace
close $na
close $nt
exec nam 5.nam &
exit 0
}
$ns at 0.0 "$CBR start"
$ns at 50.0 "End"
$ns run
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Network Simulation with NS-2: TCP and UDP Traffic Analysis and more Study notes Network security in PDF only on Docsity!

01/03/2023, 11:20 5.tcl

5.tcl

set ns [new Simulator] set na [open 5.nam w] $ns namtrace-all $na set nt [open 5.tr w] $ns trace-all $nt set n0 [$ns node] set n1 [$ns node] set n2 [$ns node] $ns duplex-link $n0 $n1 10Mb 10ms DropTail $ns queue-limit $n0 $n1 10 $ns duplex-link $n1 $n2 1Mb 10ms DropTail $ns queue-limit $n1 $n2 1 set TCP [new Agent/TCP] $ns attach-agent $n0 $TCP set CBR [new Application/Traffic/CBR] $CBR attach-agent $TCP set SINK [new Agent/TCPSink] $ns attach-agent $n2 $SINK $ns connect $TCP $SINK proc End {} { global ns na nt $ns flush-trace close $na close $nt exec nam 5.nam & exit 0 } $ns at 0.0 "$CBR start" $ns at 50.0 "End" $ns run

01/03/2023, 11:20 5.awk

5.awk

BEGIN{Count=0;} { if($1=="d") Count++; } END{ printf("\nNumber of packets dropped is: %d\n",Count); }

01/03/2023, 11:05 prgm6.tcl set null0 [new Agent/Null] $ns attach-agent $n3 $null $ns connect $udp0 $null #Create CBR Application for UDP Agent set cbr0 [new Application/Traffic/CBR] $cbr0 set packetSize_ 500 $cbr0 set interval_ 0. $cbr0 attach-agent $udp #Start and Stop FTP Traffic $ns at 0.75 "$ftp0 start" $ns at 4.75 "$ftp0 stop" #Start and Stop CBR traffic $ns at 0.5 "$cbr0 start" $ns at 4.5 "$cbr0 stop" #Stop the simulation $ns at 5.0 "finish" #Run the simulation $ns run

01/03/2023, 11:08 prgm6.awk

prgm6.awk

BEGIN{

#include tcp=0; udp=0; } { if($1=="r" && $3=="0" && $4=="1" && $5=="tcp") tcp++; if($1=="r" && $3=="1" && $4=="1" && $5=="cbr") udp++; } END{ printf("The packet sent by TCP : %d\n",tcp); printf("The packet sent by UDP : %d\n",udp); }

01/03/2023, 11:01 program7.tcl close $nt close $na exec nam program7.nam & exit 0 } for {set t 0} {$t<5} {set t [expr $t+0.001]} { $ns at $t "$Ping1 send" $ns at $t "$Ping2 send" } $ns at 5.0 "End" $ns run

01/03/2023, 11:01 program7.awk

program7.awk

BEGIN{Count=0;} { if($1=="d") Count++; } END{ printf("\nNumber of packets dropped is: %d\n",Count); }

01/03/2023, 11:02 8.tcl $ns at 0.1 "$CBR start" $ns at 3.0 "finish" $ns run

01/03/2023, 11:02 8.awk

8.awk

BEGIN{

pkt=0; time=0; } { if($1=="r" && $4=="7"){ pkt+=$6; time=$2; } } END{ printf("Throughput = %fMbps\n",((pkt/time)*(8/1000000))); }

01/03/2023, 11:03 9a.tcl $ns at 0.1 "$ftp0 start" $ns at 5 "$ftp0 stop" $ns at 7 "$ftp0 start" $ns at 0.2 "$ftp2 start" $ns at 8 "$ftp2 stop" $ns at 14 "$ftp0 stop" $ns at 10 "$ftp2 start" $ns at 15 "$ftp2 stop" $ns at 16 "finish" $ns run

01/03/2023, 11:03 9a.awk

9a.awk

BEGIN{

{ if($6=="cwnd_") printf("%f\t%f\t\n",$1,$7); } END{ }

01/03/2023, 10:25 pr10.tcl $ns at 5 "$ftp1 start" $ns at 100 "$n1 setdest 550 550 15" $ns at 190 "$n1 setdest 70 70 15" proc finish {} { global ns nf tf $ns flush-trace exec nam pr10.nam & close $tf close $nf exit awk } $ns at 250 "finish" $ns run

01/03/2023, 10:25 pr10.awk

pr10.awk

BEGIN{

count1=0; count2=0; pack1=0; pack2=0; time1=0; time2=0; } { if($1=="r"&& $3=="1"&& $4=="AGT") { count1++; pack1=pack1+$8; time1=$2; } if($1=="r"&& $3=="2"&& $4=="AGT") { count2++; pack2=pack2+$8; time2=$2; } } END{ printf("The Throughput from n0 to n1: %f Mbps\n", ((count1pack18)/(time11000000))); printf("The Throughput from n1 to n2: %f Mbps\n", ((count2pack28)/(time21000000))); }