0% found this document useful (0 votes)
7 views3 pages

Ethernet LAN

notes

Uploaded by

winterteddy101
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)
7 views3 pages

Ethernet LAN

notes

Uploaded by

winterteddy101
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/ 3

#===============================================================================

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

#Create an instance of the Simulator class


set ns [new Simulator]

#Define different colors for data flows (for NAM)


$ns color 1 Blue
$ns color 2 Red

#Open the Trace file


set tracefile [open out.tr w]
$ns trace-all $tracefile

#Open the Congestion Window files


set winfile1 [open WinFile1 w]
set winfile2 [open WinFile2 w]
puts $winfile1 "Title = Congestion Window @ Node 0"
puts $winfile1 "title_x = Time in Sec"
puts $winfile1 "title_y = Window Size"
puts $winfile2 "Title = Congestion Window @ Node 1"
puts $winfile2 "title_x = Time in Sec"
puts $winfile2 "title_y = Window Size"

#Open the NAM trace file


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

#Define a 'finish' procedure


proc finish {} {
global ns tracefile namfile winfile1 winfile2

#Dump all the trace data and close the files


$ns flush-trace
close $tracefile
close $namfile
close $winfile1
close $winfile2

#Execute the NAM visualization


exec nam out.nam &

#Execute xgraph to plot the Congestion Window


exec xgraph WinFile1 &
exec xgraph WinFile2 &

exit 0
}
#Create nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]

#Create links between the nodes


$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns simplex-link $n2 $n3 0.3Mb 100ms DropTail
$ns simplex-link $n3 $n2 0.3Mb 100ms DropTail
set lan [$ns newLan "$n3 $n4 $n5" 0.5Mb 40ms LL Queue/DropTail MAC/802_3 Channel]

#Give node position(for NAM)


$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n1 $n2 orient right-up
$ns simplex-link-op $n2 $n3 orient right
$ns simplex-link-op $n3 $n2 orient left

#Set Queue Size of link (n2-n3) to 20


$ns queue-limit $n2 $n3 20

#Setup a TCP connection for first traffic


set tcp1 [new Agent/TCP]
$ns attach-agent $n0 $tcp1
set sink1 [new Agent/TCPSink]
$ns attach-agent $n4 $sink1
$ns connect $tcp1 $sink1
$tcp1 set fid_ 1
$tcp1 set packetSize_ 552

#Setup a TCP connection for second traffic


set tcp2 [new Agent/TCP]
$ns attach-agent $n1 $tcp2
set sink2 [new Agent/TCPSink]
$ns attach-agent $n5 $sink2
$ns connect $tcp2 $sink2
$tcp2 set fid_ 2
$tcp2 set packetSize_ 552

#Setup a FTP over TCP connection for both the traffics


set ftp1 [new Application/FTP]
$ftp1 attach-agent $tcp1
set ftp2 [new Application/FTP]
$ftp2 attach-agent $tcp2

#Label the nodes


$ns at 0.0 "$n0 label \"TCP Src1\""
$ns at 0.0 "$n4 label \"TCP Recv1\""
$ns at 0.0 "$n1 label \"TCP Src2\""
$ns at 0.0 "$n5 label \"TCP Recv2\""

#Plotting window size


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"
}

#Schedule events
$ns at 0.1 "$ftp1 start"
$ns at 0.5 "$ftp2 start"
$ns at 5.0 "$ftp2 stop"
$ns at 5.5 "$ftp1 stop"
$ns at 0.1 "plotWindow $tcp1 $winfile1"
$ns at 0.5 "plotWindow $tcp2 $winfile2"
$ns at 6.0 "finish"

#Run the simulation


$ns run

You might also like