0% found this document useful (0 votes)
31 views19 pages

CN Parta

The document describes implementing a point to point network with four nodes and duplex links between them. Various performance parameters like queue size and bandwidth are analyzed by running simulations in NS2. Packet drops are measured using awk.

Uploaded by

kushkruthik555
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views19 pages

CN Parta

The document describes implementing a point to point network with four nodes and duplex links between them. Various performance parameters like queue size and bandwidth are analyzed by running simulations in NS2. Packet drops are measured using awk.

Uploaded by

kushkruthik555
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

PART---A

1. Implement a point to pint network with four nodes and duplex links between them. Analyze the

network performance by setting the queue size and varying the bandwidth.

set ns [ new Simulator]

set tf [ open lab1.tr w ]

$ns trace-all $tf

set nf [ open lab1.nam w ]

$ns namtrace-all $nf

set n0 [$ns node]

set n1 [$ns node]

set n2 [$ns node]

set n3 [$ns node]

$ns color 1 "red"

$ns color 2 "blue"

$n0 label "Source/udp0"

$n1 label "Source/udp1"

$n2 label "Router"

$n3 label "Destination/Null"

$ns duplex-link $n0 $n2 10Mb 300ms DropTail

$ns duplex-link $n1 $n2 10Mb 300ms DropTail

$ns duplex-link $n2 $n3 1Mb 300ms DropTail

$ns set queue-limit $n0 $n2 10 $ns set queue-limit $n1 $n2 10 $ns set queue-limit $n2 $n3 5

set udp0 [new Agent/UDP]

$ns attach-agent $n0 $udp0

set cbr0 [new Application/Traffic/CBR]

$cbr0 attach-agent $udp0

set null3 [new Agent/Null]


$ns attach-agent $n3 $null3

set udp1 [new Agent/UDP]

$ns attach-agent $n1 $udp1

set cbr1 [new Application/Traffic/CBR]

$cbr1 attach-agent $udp1

$udp0 set class_ 1

$udp1 set class_ 2

$ns connect $udp0 $null3

$ns connect $udp1 $null3

$cbr1 set packetSize_ 500Mb

rate is high #then packets drops are high.

$cbr1 set interval_ 0.005

proc finish { } {

global ns nf tf

$ns flush-trace

exec nam lab1.nam &

close $tf

close $nf

exit 0

$ns at 0.1 "$cbr0 start"

$ns at 0.1 "$cbr1 start"

$ns at 10.0 "finish"

$ns run

#AWK

BEGIN

#include<stdio.h>
count=0;

if($1=="d") #d stands for the packets drops.

count++

END

printf("The Total no of Packets Dropped due to Congestion :

%d\n\n", count)

Output:

ns lab1.tcl

awk –f lab1.awk lab1.tr

The Total no of packets Dropped due to congestion:4560

_____________________________________________________________________________________
_____________

2. Implement a four node point to point network with links n0-n2, n1-n2 and n2-n3. Apply TCP agent

between n0-n3 and UDP between n1-n3. Apply relevant applications over TCP and UDP agents

changing the parameter and determine the number of packets sent by TCP/UDP.

set ns [new Simulator]

set tf [open lab2.tr w]

$ns trace-all $tf

set nf [open lab2.nam w]

$ns namtrace-all $nf

set n0 [$ns node]


set n1 [$ns node]

set n2 [$ns node]

set n3 [$ns node]

$ns color 1 "red"

$ns color 2 "blue"

$n0 label "source/TCP"

$n1 label "source/UDP"

$n2 label "Router"

$n3 label "destination"

$ns duplex-link $n0 $n2 100Mb 1ms DropTail $ns duplex-link $n1 $n2

100Mb 1ms DropTail $ns duplex-link $n2 $n3 100Mb 1ms DropTail

$ns duplex-link-op $n0 $n2 color "green"

$ns duplex-link-op $n0 $n2 label "from 0-2"

$ns duplex-link-op $n1 $n2 color "green"

$ns duplex-link-op $n1 $n2 label "from 1-2"

$ns duplex-link-op $n2 $n3 color "green"

$ns duplex-link-op $n2 $n3 label "from 2-3"

set tcp0 [new Agent/TCP]

$ns attach-agent $n0 $tcp0

set ftp0 [new Application/FTP]

$ftp0 attach-agent $tcp0

set sink3 [new Agent/TCPSink]

$ns attach-agent $n3 $sink3

set udp1 [new Agent/UDP]

$ns attach-agent $n1 $udp1

set cbr1 [new Application/Traffic/CBR] $cbr1 attach-agent

$udp1 set null3 [new Agent/Null]

$ns attach-agent $n3 $null3

$ftp0 set packetSize_ 500


$ftp0 set interval_ 0.001

$cbr1 set packetSize_ 500

$cbr1 set interval_ 0.001

$tcp0 set class_ 1

$udp1 set class_ 2

$ns connect $udp1 $null3

proc finish { } {

global ns nf tf

$ns flush-trace

exec nam lab2.nam &

close $nf

close $tf

exit 0

$ns at 0.1 "$cbr1 start"

$ns at 0.2 "$ftp0 start"

$ns at 5.0 "finish"

$ns run

#AWK

BEGIN{

#include<stdio.h>

tcp=0;

udp=0;

if($1=="r"&&$3=="2"&&$4=="3"&& $5=="tcp")

tcp++;

if($1=="r"&&$3=="2"&&$4=="3"&&$5=="cbr")
udp++;

END{

printf("\n Total number of packets sent by TCP : %d\n",tcp);

printf("\n Total number of packets sent by UDP : %d\n",udp);

Output:

ns lab2.tcl

awk –f lab2.awk lab2.tr

Total number of packets sent by TCP: 1200

Total number of packets sent by UDP: 4500

_____________________________________________________________________________________
_____________

3. Implement an Ethernet LAN using n nodes (6-10), change the error rate and data rate and compare

the throughput.

set ns [new Simulator]

set tf [open lab5.tr w]

$ns trace-all $tf

set nf [open lab5.nam w]

$ns namtrace-all $nf

$ns color 1 "red"

set n0 [$ns node]

set n1 [$ns node]

set n2 [$ns node]

set n3 [$ns node]

set n4 [$ns node]


set n5 [$ns node]

set n6 [$ns node]

$n1 label "Source/UDP"

$n3 label "Error Node"

$n5 label "Destination"

$ns make-lan "$n0 $n1 $n2 $n3" 10Mb 10ms LL Queue/DropTail Mac/802_3

$ns make-lan "$n4 $n5 $n6" 10Mb 10ms LL Queue/DropTail Mac/802_3

$ns duplex-link $n3 $n6 100Mb 10ms DropTail

set udp1 [new Agent/UDP]

$ns attach-agent $n1 $udp1

set cbr1 [ new Application/Traffic/CBR]

$cbr1 attach-agent $udp1

set null5 [new Agent/Null]

$ns attach-agent $n5 $null5

$ns connect $udp1 $null5

$cbr1 set packetSize_ 1000

$cbr1 set interval_ 0.0001

$udp1 set class_ 1

set err [new ErrorModel]

$ns lossmodel $err $n3 $n6

$err set rate_ 0.2;

proc finish { } {

global nf ns tf

exec nam lab5.nam &

close $nf

close $tf

exit 0

$ns at 5.0 "finish"


$ns at 0.1 "$cbr1 start"

$ns run

#AWK

BEGIN

#include <stdio.h>

pkt=0;

time=0

if($1="r" && $3=="8" && $4=="5")

pkt=pkt+$6

time=$2

END

printf(" Throughput: %fMbps\n\n",(pkt/time)*(8/1000000));

Output:

ns lab5.tcl

awk –f lab5.awk lab5.tr

Throughput:148Mbps

_____________________________________________________________________________________
______
4. Implement Ethernet LAN using n nodes and assign multiple traffic to the nodes and obtain

congestion window for different sources/ destinations.

set val(stop) 10;

set ns [new Simulator]

set tf [open exp4.tr w]

$ns trace-all $tf

set nf [open exp4.nam w]

$ns namtrace-all $nf

set n0 [$ns node]

set n1 [$ns node]

set n2 [$ns node]

set n3 [$ns node]

$ns make-lan "$n0 $n1 $n2 $n3" 10mb 10ms LL Queue/DropTail Mac/802_3

set tcp0 [new Agent/TCP]

$ns attach-agent $n0 $tcp0

set ftp0 [new Application/FTP]

$ftp0 attach-agent $tcp0

set sink3 [new Agent/TCPSink]

$ns attach-agent $n3 $sink3

$ns connect $tcp0 $sink3

set tcp2 [new Agent/TCP]

$ns attach-agent $n2 $tcp2

set ftp2 [new Application/FTP]

$ftp2 attach-agent $tcp2

set sink1 [new Agent/TCPSink]

$ns attach-agent $n1 $sink1

$ns connect $tcp2 $sink1

set file1 [open file1.tr w]


$tcp0 attach $file1

$tcp0 trace cwnd_

$tcp0 set maxcwnd_ 10

set file2 [open file2.tr w]

$tcp2 attach $file2

$tcp2 trace cwnd_

proc finish { } {

global nf tf ns

$ns flush-trace

exec nam exp4.nam &

exec xg/xg/bin/xgraph tcp2 tcp1

close $nf

close $tf

exit 0

$ns at 0.1 "$ftp0 start"

$ns at 1.5 "$ftp0 stop"

$ns at 2 "$ftp0 start"

$ns at 3 "$ftp0 stop"

$ns at 0.2 "$ftp2 start"

$ns at 2 "$ftp2 stop"

$ns at 2.5 "$ftp2 start"

$ns at 4 "$ftp2 stop"

$ns at 5.0 "finish"

$ns run

#AWK

BEGIN{
#include<stdio.h>

if($6=="cwnd_")

printf("%f \t %f \n", $1,$7);

END

puts "DONE"

Output:

ns lab7.tcl

awk –f lab7.awk file1.tr>tcp1

awk –f lab7.awk file2.tr>tcp2

xgraph –x “time” –y “convalue ” tcp1 tcp2

Note: To set the foreground and background color of the graph choose the appropriate options by

giving xgraph –

_____________________________________________________________________________________
__________

5. Implement ESS with transmission nodes in Wireless LAN and obtain the performance parameters.

set val(stop) 10;

set val(chan) Channel/WirelessChannel;

set val(prop) Propagation/TwoRayGround;

set val(netif) Phy/WirelessPhy;

set val(mac) Mac/802_11;

set val(ifq) Queue/DropTail/PriQueue;


set val(ll) LL;

set val(ant) Antenna/OmniAntenna;

set val(ifqlen) 50;

set val(nn) 3;

set val(rp) DSDV;

set val(x) 580;

set val(y) 545;

set val(stop) 10.0;

#Create a ns simulator

set ns [new Simulator]

#Setup topography object

set topo [new Topography]

$topo load_flatgrid $val(x) $val(y)

create-god $val(nn)

#Open the NS trace file

set tracefile [open exp5.tr w]

$ns trace-all $tracefile

#Open the NAM trace file

set namfile [open exp5.nam w]

$ns namtrace-all $namfile

$ns namtrace-all-wireless $namfile $val(x) $val(y)

set chan [new $val(chan)];#Create wireless channel

$ns node-config -adhocRouting $val(rp) \

-llType $val(ll) \
-macType $val(mac) \

-ifqType $val(ifq) \

-ifqLen $val(ifqlen) \

-antType $val(ant) \

-propType $val(prop) \

-phyType $val(netif) \

-channel $chan \

-topoInstance $topo \

-agentTrace ON \

-routerTrace ON \

-macTrace ON \

-movementTrace ON

#Create 3 nodes

set n0 [$ns node]

$n0 set X_ 203

$n0 set Y_ 303

$n0 set Z_ 0.0

$ns initial_node_pos $n0 20

set n1 [$ns node]

$n1 set X_ 343

$n1 set Y_ 359

$n1 set Z_ 0.0

$ns initial_node_pos $n1 20

set n2 [$ns node]

$n2 set X_ 480

$n2 set Y_ 445

$n2 set Z_ 0.0

$ns initial_node_pos $n2 20


#Setup a TCP connection

set tcp0 [new Agent/TCP]

$ns attach-agent $n0 $tcp0

set sink2 [new Agent/TCPSink]

$ns attach-agent $n1 $sink2

$ns connect $tcp0 $sink2

$tcp0 set packetSize_ 1500

#Setup a TCP connection

set tcp1 [new Agent/TCP]

$ns attach-agent $n1 $tcp1

set sink3 [new Agent/TCPSink]

$ns attach-agent $n2 $sink3

$ns connect $tcp1 $sink3

$tcp1 set packetSize_ 1500

#Setup a FTP Application over TCP connection

set ftp0 [new Application/FTP]

$ftp0 attach-agent $tcp0

$ns at 1.0 "$ftp0 start"

$ns at 2.0 "$ftp0 stop"

#Setup a FTP Application over TCP connection

set ftp1 [new Application/FTP]

$ftp1 attach-agent $tcp1

$ns at 1.0 "$ftp1 start"

$ns at 2.0 "$ftp1 stop"


#Define a 'finish' procedure

proc finish {} {

global ns tracefile namfile

$ns flush-trace

close $tracefile

close $namfile

exec nam exp5.nam &

exit 0

for {set i 0} {$i < $val(nn) } { incr i } {

$ns at $val(stop) "\$n$i reset"

$ns at $val(stop) "$ns nam-end-wireless $val(stop)"

$ns at $val(stop) "finish"

$ns at $val(stop) "puts \"done\" ; $ns halt"

$ns run

#AWK

BEGIN

#include<stdio.h>

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: %fMbps\n",

((count1*pack1*8)/(time1*1000000)))

Printf("The Throughput from n1 to n2: %f Mbps", ((count2* pack2 * 8)

/(time2*1000000)))

Output:

ns lab8.tcl

awk –f lab8.awk lab8.tr

The Throughput from n0 to n1: 5444Mbps

The Throughput from n1 to n2: 345Mbps

_____________________________________________________________________________________
__
6. Implementation of Link state routing algorithm.

set val(stop) 10.0 ;# time of simulation end

#Create a ns simulator

set ns [new Simulator]

#Open the NS trace file

set tracefile [open expt6.tr w]

$ns trace-all $tracefile

#Open the NAM trace file

set namfile [open expt6.nam w]

$ns namtrace-all $namfile

#Create 5 nodes

set n0 [$ns node]

set n1 [$ns node]

set n2 [$ns node]

set n3 [$ns node]

set n4 [$ns node]

#Createlinks between nodes

$ns duplex-link $n0 $n1 100.0Mb 10ms DropTail

$ns queue-limit $n0 $n1 50

$ns duplex-link $n1 $n2 100.0Mb 10ms DropTail

$ns queue-limit $n1 $n2 50

$ns duplex-link $n0 $n2 100.0Mb 10ms DropTail

$ns queue-limit $n0 $n2 50


$ns duplex-link $n2 $n3 100.0Mb 10ms DropTail

$ns queue-limit $n2 $n3 50

$ns duplex-link $n1 $n3 100.0Mb 10ms DropTail

$ns queue-limit $n1 $n3 50

$ns duplex-link $n3 $n4 100.0Mb 10ms DropTail

$ns queue-limit $n3 $n4 50

$ns duplex-link $n0 $n3 100.0Mb 10ms DropTail

$ns queue-limit $n0 $n3 50

$ns cost $n0 $n2 1

$ns cost $n0 $n1 2

$ns cost $n0 $n3 3

$ns cost $n1 $n2 2

$ns cost $n1 $n3 3

$ns cost $n2 $n3 1

$ns cost $n3 $n4 2

#Give node position (for NAM)

$ns duplex-link-op $n0 $n1 orient right

$ns duplex-link-op $n1 $n2 orient left-down

$ns duplex-link-op $n0 $n2 orient left-down

$ns duplex-link-op $n2 $n3 orient right-down

$ns duplex-link-op $n1 $n3 orient right-down

$ns duplex-link-op $n3 $n4 orient right

$ns duplex-link-op $n0 $n3 orient right-down

set udp0 [new Agent/UDP]

$ns attach-agent $n0 $udp0


set null1 [new Agent/Null]

$ns attach-agent $n4 $null1

$ns connect $udp0 $null1

$udp0 set packetSize_ 1500

#Setup a CBR Application over UDP connection

set cbr0 [new Application/Traffic/CBR]

$cbr0 attach-agent $udp0

$cbr0 set packetSize_ 1000

$cbr0 set rate_ 1.0Mb

$cbr0 set random_ null

$ns at 1.0 "$cbr0 start"

$ns at 2.0 "$cbr0 stop"

#Define a 'finish' procedure

proc finish {} {

global ns tracefile namfile

$ns flush-trace

close $tracefile

close $namfile

exec nam expt6.nam &

exit 0

$ns at $val(stop) "$ns nam-end-wireless $val(stop)"

$ns at $val(stop) "finish"

$ns at $val(stop) "puts \"done\" ; $ns halt"

$ns run

NO AWK..!

You might also like