0% found this document useful (0 votes)
15 views

Computer Networks

This document defines a network simulation with four nodes connected by links and simulates both TCP and UDP traffic between the nodes over 5 seconds of simulation time. It creates agents for TCP, UDP, FTP and CBR and attaches them to nodes to generate and receive traffic. It also defines colors for tracing and outputs the results to a NAM file for visualization.

Uploaded by

Montana Jones
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Computer Networks

This document defines a network simulation with four nodes connected by links and simulates both TCP and UDP traffic between the nodes over 5 seconds of simulation time. It creates agents for TCP, UDP, FTP and CBR and attaches them to nodes to generate and receive traffic. It also defines colors for tracing and outputs the results to a NAM file for visualization.

Uploaded by

Montana Jones
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

#create a new simulator object

set ns [new Simulator]

#define different colors for data flows (for NAM)


$ns color 1 Blue
$ns color 2 Red

#open NAM trace file


set nf [open out.nam w]
$ns namtrace-all $nf

#define a 'finish' procedure


proc finish {} {
global ns nf
$ns flush-trace
#close the NAM trace file
close $nf
#Execute NAM on the trace file
exec nam out.nam &
exit 0
}

#create four nodes


set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]

#create link between the nodes


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

#setup a TCP connection


set tcp [new Agent/TCP]
$ns attach-agent $n0 $tcp
set tcpsink [new Agent/TCPSink]
$ns attach-agent $n3 $tcpsink
$ns connect $tcp $tcpsink

#setup FTP over TCP connection


set ftp [new Application/FTP]
$ftp attach-agent $tcp

#setup a UDP connection


set udp [new Agent/UDP]
$ns attach-agent $n1 $udp
set null [new Agent/Null]
$ns attach-agent $n3 $null
$ns connect $udp $null

#setup CBR over UDP connection


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

#schedule events for the CBR and FTP agents


$ns at 0.1 "$cbr start"
$ns at 1.0 "$ftp start"
$ns at 4.0 "$cbr stop"
$ns at 4.5 "$ftp stop"

#call finish procedure after 5seconds of simulation time


$ns at 5.0 "finish"

#run the simulation


$ns run

You might also like