0% found this document useful (0 votes)
5 views6 pages

8 Program

The document outlines a simulation setup using a network simulator to create a network topology with multiple nodes and TCP connections. It includes procedures for plotting congestion windows, scheduling events, and managing trace files for analysis. Additionally, it provides steps for executing the simulation and processing the results using an AWK script.

Uploaded by

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

8 Program

The document outlines a simulation setup using a network simulator to create a network topology with multiple nodes and TCP connections. It includes procedures for plotting congestion windows, scheduling events, and managing trace files for analysis. Additionally, it provides steps for executing the simulation and processing the results using an AWK script.

Uploaded by

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

#Create Simulator

set ns [new Simulator]

#Use colors to differentiate the traffics


$ns color 1 Blue
$ns color 2 Red

#Open trace and NAM trace file set ntrace [open prog5.tr w]
$ns trace-all $ntrace
set namfile [open prog5.nam w]
$ns namtrace-all $namfile

#Use some flat file to create congestion graph windows set winFile0 [open WinFile0 w]
set winFile1 [open WinFile1 w]

#Finish Procedure proc Finish {} {


#Dump all trace data and Close the files global ns ntrace namfile
$ns flush-trace close $ntrace close $namfile

#Execute the NAM animation file exec nam prog5.nam &

#Plot the Congestion Window graph using xgraph exec xgraph WinFile0 WinFile1 &
exit 0
}

#Plot Window Procedure


proc PlotWindow {tcpSource file} { global ns
set time 0.1
set now [$ns now]

set cwnd [$tcpSource set cwnd_] puts $file "$now $cwnd"


$ns at [expr $now+$time] "PlotWindow $tcpSource $file"
}

#Create 6 nodes
for {set i 0} {$i<6} {incr i} { set n($i) [$ns node]
}

#Create duplex links between the nodes


$ns duplex-link $n(0) $n(2) 2Mb 10ms DropTail
$ns duplex-link $n(1) $n(2) 2Mb 10ms DropTail
$ns duplex-link $n(2) $n(3) 0.6Mb 100ms DropTail

#Nodes n(3) , n(4) and n(5) are considered in a LAN


set lan [$ns newLan "$n(3) $n(4) $n(5)" 0.5Mb 40ms LL Queue/DropTail MAC/802_3
Channel]

#Orientation to the nodes


$ns duplex-link-op $n(0) $n(2) orient right-down
$ns duplex-link-op $n(1) $n(2) orient right-up
$ns duplex-link-op $n(2) $n(3) orient right

#Setup queue between n(2) and n(3) and monitor the queue
$ns queue-limit $n(2) $n(3) 20
$ns duplex-link-op $n(2) $n(3) queuePos 0.5

#Set error model on link n(2) to n(3) set loss_module [new ErrorModel]
$loss_module ranvar [new RandomVariable/Uniform]
$loss_module drop-target [new Agent/Null]
$ns lossmodel $loss_module $n(2) $n(3)

#Set up the TCP connection between n(0) and n(4) set tcp0 [new Agent/TCP/Newreno]
$tcp0 set fid_ 1
$tcp0 set window_ 8000
$tcp0 set packetSize_ 552
$ns attach-agent $n(0) $tcp0
set sink0 [new Agent/TCPSink/DelAck]
$ns attach-agent $n(4) $sink0
$ns connect $tcp0 $sink0

#Apply FTP Application over TCP set ftp0 [new Application/FTP]


$ftp0 attach-agent $tcp0

$ftp0 set type_ FTP

#Set up another TCP connection between n(5) and n(1) set tcp1 [new Agent/TCP/Newreno]
$tcp1 set fid_ 2
$tcp1 set window_ 8000
$tcp1 set packetSize_ 552
$ns attach-agent $n(5) $tcp1
set sink1 [new Agent/TCPSink/DelAck]
$ns attach-agent $n(1) $sink1
$ns connect $tcp1 $sink1

#Apply FTP application over TCP set ftp1 [new Application/FTP]


$ftp1 attach-agent $tcp1
$ftp1 set type_ FTP
#Schedule Events
$ns at 0.1 "$ftp0 start"
$ns at 0.1 "PlotWindow $tcp0 $winFile0"
$ns at 0.5 "$ftp1 start"
$ns at 0.5 "PlotWindow $tcp1 $winFile1"
$ns at 25.0 "$ftp0 stop"
$ns at 25.1 "$ftp1 stop"
$ns at 25.2 "Finish"

#Run the simulation


$ns run

3. Implement an Ethernet LAN using n nodes and set multiple traffic nodes and plot
congestion window for different source / destination.

set ns [new Simulator]

set tf [open lab3.tr w]

$ns trace-all $tf

set nf [open lab3.nam w]

$ns namtrace-all $nf

set n0 [$ns node]

$n0 color "magenta"

$n0 label "src1"

set n1 [$ns node]

set n2 [$ns node]

$n2 color "magenta"

$n2 label "src2"

set n3 [$ns node]

$n3 color "blue"


$n3 label "dest2"

set n4 [$ns node]

set n5 [$ns node]

$n5 color "blue"

$n5 l

abel "dest1"

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

/* should come in single line */

$ns duplex-link $n4 $n5 1Mb 1ms DropTail

set tcp0 [new Agent/TCP]

$ns attach-agent $n0 $tcp0

set ftp0 [new Application/FTP]

$ftp0 attach-agent $tcp0

$ftp0 set packetSize_ 500

$ftp0 set interval_ 0.0001

set sink5 [new Agent/TCPSink]

$ns attach-agent $n5 $sink5

$ns connect $tcp0 $sink5

set tcp2 [new Agent/TCP]

$ns attach-agent $n2 $tcp2

set ftp2 [new Application/FTP]

$ftp2 attach-agent $tcp2

$ftp2 set packetSize_ 600

$ftp2 set interval_ 0.001


set sink3 [new Agent/TCPSink]
$ns attach-agent $n3 $sink3

$ns connect $tcp2 $sink3


set file1 [open file1.tr w]
$tcp0 attach $file1
set file2 [open file2.tr w]
$tcp2 attach $file2
$tcp0 trace cwnd_ /* must put underscore ( _ ) after cwnd and no space between them*/
$tcp2 trace cwnd_

proc finish { } {
global ns nf tf
$ns flush-trace
close $tf
close $nf
exec nam lab3.nam &
exit 0
}
$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

AWK file (Open a new editor using “vi command” and write awk file and save with
“.awk” extension)

cwnd:- means congestion window

BEGIN {
}
{

if($6= ="cwnd_") /* don‘t leave space after writing cwnd_ */ printf("%f\t%f\t\n",$1,$7); /*


you must put \n in printf */

END {

Steps for execution

1) Open vi editor and type program. Program name should have the extension ― .tcl ‖
[root@localhost ~]# gedit lab3.tcl

2) Open vi editor and type awk program. Program name should have the extension ―.awk ‖
[root@localhost ~]# gedit lab3.awk

3) Run the simulation program

[root@localhost~]# ns lab3.tcl

4) After simulation is completed run awk file to see the output ,-

i. [root@localhost~]# awk –f lab3.awk file1.tr > a1

ii. [root@localhost~]# awk –f lab3.awk file2.tr > a2

iii. [root@localhost~]# xgraph a1 a2

5) Here we are using the congestion window trace files i.e. file1.tr and file2.tr and we are
redirecting the contents of those files to new files say a1 and a2 using output redirection
operator (>).

5) To see the trace file contents open the file as ,

[root@localhost~]# gedit lab3.tr

You might also like