exam pass
#selective repeat
#Create Simulator Oject
set ns [new Simulator]
#Open the trace file
set nr [open ls.tr w]
$ns trace-all $nr
#Open the output nam files
set nf [open ls.nam w]
$ns namtrace-all $nf
#Define a finish procedure
proc finish { } {
global ns nr nf
$ns flush-trace
close $nf
close $nr
exec nam ls.nam &
exit 0
}
# Create nodes
for { set i 0 } { $i < 12} { incr i 1 } {
set n($i) [$ns node]}
# Create duplex links between nodes
for {set i 0} {$i < 11} {incr i} {
$ns duplex-link $n($i) $n([expr $i+1]) 1Mb 10ms DropTail }
$ns duplex-link $n(1) $n(11) 1Mb 10ms DropTail
#Create a UDP agent and attach it to node n0
set udp0 [new Agent/UDP]
$ns attach-agent $n(0) $udp0
# Create a CBR traffic source and attach it to udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0
#Create a Null agent (a traffic sink) and attach it to node n5
set null0 [new Agent/Null]
$ns attach-agent $n(5) $null0
$ns connect $udp0 $null0
# specify Link State routing
$ns rtproto LS
# link between node n4 and n5 goes down(not working)
$ns rtmodel-at 5.0 down $n(4) $n(5)
# link between node n4 and n5 goes Up(working properly)
$ns rtmodel-at 10.0 up $n(4) $n(5)
# Set color for traffic
$udp0 set fid_ 1
# color specification
$ns color 1 Red
#Schedule events for the CBR agent
$ns at 1.0 "$cbr0 start"
#Call the finish procedure after 11 seconds of simulation time
$ns at 11 "finish"
$ns run
#************************************************************************************************
#************************************************************************************************
#distance vector routing
#Create Simulator Oject
set ns [new Simulator]
#Open the trace file
set nr [open dv.tr w]
$ns trace-all $nr
#Open the output nam files
set nf [open dv.nam w]
$ns namtrace-all $nf
#Define a finish procedure
proc finish { } {
global ns nr nf
$ns flush-trace
close $nf
close $nr
exec nam dv.nam &
exit 0
}
# Create nodes
for { set i 0 } { $i < 12} { incr i 1 } {
set n($i) [$ns node]}
# Create duplex links between nodes
for {set i 0} {$i < 11} {incr i} {
$ns duplex-link $n($i) $n([expr $i+1]) 1Mb 10ms DropTail }
$ns duplex-link $n(1) $n(11) 1Mb 10ms DropTail
#Create a UDP agent and attach it to node n0
set udp0 [new Agent/UDP]
$ns attach-agent $n(0) $udp0
# Create a CBR traffic source and attach it to udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0
#Create a Null agent (a traffic sink) and attach it to node n5
set null0 [new Agent/Null]
$ns attach-agent $n(5) $null0
$ns connect $udp0 $null0
$ns rtproto DV
# link between node n4 and n5 goes down(not working)
$ns rtmodel-at 5.0 down $n(4) $n(5)
# link between node n4 and n5 goes Up(working properly)
$ns rtmodel-at 10.0 up $n(4) $n(5)
# Set color for traffic
$udp0 set fid_ 1
# color specification
$ns color 1 Red
#Schedule events for the CBR agent
$ns at 1.0 "$cbr0 start"
#Call the finish procedure after 11 seconds of simulation time
$ns at 11 "finish"
$ns run
#******************************************************************************************
#******************************************************************************************
#distance vector routing
#Create Simulator Oject
set ns [new Simulator]
#Tell the simulator to use dynamic routing
$ns rtproto DV
$ns macType Mac/Sat/UnslottedAloha
#Open the nam trace file
set nf [open aloha.nam w]
$ns namtrace-all $nf
#Open the output files
set f0 [open aloha.tr w]
$ns trace-all $f0
#Define a finish procedure
proc finish {} {
global ns f0 nf
$ns flush-trace
#Close the trace file
close $f0
close $nf
exec nam aloha.nam &
exit 0
}
# Create six 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 duplex links between nodes with bandwidth and distance
$ns duplex-link $n0 $n4 1Mb 50ms DropTail
$ns duplex-link $n1 $n4 1Mb 50ms DropTail
$ns duplex-link $n2 $n5 1Mb 1ms DropTail
$ns duplex-link $n3 $n5 1Mb 1ms DropTail
$ns duplex-link $n4 $n5 1Mb 50ms DropTail
$ns duplex-link $n2 $n3 1Mb 50ms DropTail
# Create a duplex link between nodes 4 and 5 as queue position
#The queuePos is only needed for visualisation. It is not used during the simulations,used by NAM to show the queue i.e. 0.5 x 180 =90 degree
$ns duplex-link-op $n4 $n5 queuePos 0.5
#Create a UDP agent and attach it to node n(0)
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
# Create a CBR traffic source and attach it to udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0
#Create a Null agent (a traffic sink) and attach it to node n(2)
set null0 [new Agent/Null]
$ns attach-agent $n2 $null0
#Connect the traffic source with the traffic sink
$ns connect $udp0 $null0
#Schedule events for the CBR agent and the network dynamics
$ns at 0.5 "$cbr0 start"
# link between n5 and n2 not working properly from 1.0 and again get connection at time 2.0
# when link between n5 and n2 goes down then oter alternative path will be chosen by routing algorithm
$ns rtmodel-at 1.0 down $n5 $n2
$ns rtmodel-at 2.0 up $n5 $n2
$ns at 4.5 "$cbr0 stop"
#Call the finish procedure after 5 seconds of simulation time
$ns at 5.0 "finish"
#Run the simulation
$ns run
#**************************************************************************************************************
#*********************************************************************************************************
#goback n sliding window
#send packets one by one
#create simulator object
set ns [new Simulator]
#create node
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
# Labeling of nodes
$ns at 0.0 "$n1 label Sender"
$ns at 0.0 "$n4 label Receiver"
# processing nam file
set nf [open goback.nam w]
$ns namtrace-all $nf
# processing trace file file
set f [open goback.tr w]
$ns trace-all $f
# Link Setup
$ns duplex-link $n0 $n2 1Mb 20ms DropTail
$ns queue-limit $n0 $n2 5
$ns duplex-link $n1 $n2 1Mb 20ms DropTail
$ns duplex-link $n2 $n3 1Mb 20ms DropTail
$ns duplex-link $n3 $n4 1Mb 20ms DropTail
$ns duplex-link $n3 $n5 1Mb 20ms DropTail
# setting node position
$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n1 $n2 orient right-up
$ns duplex-link-op $n2 $n3 orient right
$ns duplex-link-op $n3 $n4 orient right-up
$ns duplex-link-op $n3 $n5 orient right-down
# traffic source setup
Agent/TCP set_nam_tracevar_true
set tcp [new Agent/TCP]
$tcp set fid 1
# n1 is the source
$ns attach-agent $n1 $tcp
# n4 is the receiver
set sink [new Agent/TCPSink]
$ns attach-agent $n4 $sink
$ns connect $tcp $sink
# traffic Agent setup
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns at 0.05 "$ftp start"
$ns at 0.06 "$tcp set windowlnit 6"
$ns at 0.06 "$tcp set maxcwnd 6"
$ns at 0.25 "$ns queue-limit $n3 $n4 0"
$ns at 0.26 "$ns queue-limit $n3 $n4 10"
$ns at 0.305 "$tcp set windowlnit 4"
$ns at 0.305 "$tcp set maxcwnd 4"
$ns at 0.368 "$ns detach-agent $n1 $tcp ; $ns detach-agent $n4 $sink"
$ns at 1.5 "finish"
$ns at 0.0 "$ns trace-annotate \"Goback N end\""
$ns at 0.05 "$ns trace-annotate \"FTP starts at 0.01\""
$ns at 0.06 "$ns trace-annotate \"Send 6Packets from SYS1 to SYS4\""
$ns at 0.26 "$ns trace-annotate \"Error Occurs for 4th packet so not sent ack for the Packet\""
$ns at 0.30 "$ns trace-annotate \"Retransmit Packet_4 to 6\""
$ns at 1.0 "$ns trace-annotate \"FTP stops\""
# function finish
proc finish {} {
global ns nf
$ns flush-trace
close $nf
puts "filtering..."
exec nam goback.nam &
exit 0
}
$ns run
#*********************************************************************************************************************
#*********************************************************************************************************************
#selective repeat...
#send packets one by one
# define simulator
set ns [new Simulator]
#define node
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 color of the node
$n1 color "red"
$n4 color "red"
#label sender and receiver
$ns at 0.0 "$n1 label Sender"
$ns at 0.0 "$n4 label Receiver"
#nam file
set nf [open Srepeat.nam w]
$ns namtrace-all $nf
#trace file
set f [open Srepeat.tr w]
$ns trace-all $f
#Link Setup
$ns duplex-link $n0 $n2 1Mb 10ms DropTail
# $ns queue-limit $n0 $n2 5
$ns duplex-link $n1 $n2 1Mb 10ms DropTail
$ns duplex-link $n2 $n3 1Mb 10ms DropTail
$ns duplex-link $n3 $n4 1Mb 10ms DropTail
$ns duplex-link $n3 $n5 1Mb 10ms DropTail
# node orientation
$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n1 $n2 orient right-up
$ns duplex-link-op $n2 $n3 orient right
$ns duplex-link-op $n3 $n4 orient right-up
$ns duplex-link-op $n3 $n5 orient right-down
# Traffic Agent setup
Agent/TCP set_nam_tracevar_true
set tcp [new Agent/TCP]
$tcp set fid 1
$ns attach-agent $n1 $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $n4 $sink
$ns connect $tcp $sink
# Traffic Source setup
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns at 0.05 "$ftp start"
$ns at 0.06 "$tcp set windowlnit 8"
$ns at 0.06 "$tcp set maxcwnd 8"
$ns at 0.25 "$ns queue-limit $n3 $n4 0"
$ns at 0.26 "$ns queue-limit $n3 $n4 10"
$ns at 0.30 "$tcp set windowlnit 1"
$ns at 0.30 "$tcp set maxcwnd 1"
$ns at 0.30 "$ns queue-limit $n3 $n4 10"
$ns at 0.47 "$ns detach-agent $n1 $tcp;$ns detach-agent $n4 $sink"
$ns at 1.55 "finish"
$ns at 0.0 "$ns trace-annotate \"Select and repeat\""
$ns at 0.05 "$ns trace-annotate \"FTP starts at 0.01\""
$ns at 0.06 "$ns trace-annotate \"Send 8 Packets from Sender to Receiver\""
$ns at 0.26 "$ns trace-annotate \"Error Occurs in 4th packet \""
$ns at 0.30 "$ns trace-annotate \"Retransmit Packet_4 from Sender to Receiver\""
$ns at 1.5 "$ns trace-annotate \"FTP stops\""
# define finish procedure
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exec nam Srepeat.nam &
exit 0
}
$ns run
#*****************************************************************************************************
#*****************************************************************************************************
# stop and wait protocol in normal situation
# features : labeling, annotation, nam-graph, and window size monitoring
# Create Simulator Oject
set ns [new Simulator]
$ns color 1 blue
#Define nodes
set n0 [$ns node]
set n1 [$ns node]
# labeling of nodes
$ns at 0.0 "$n0 label Sender"
$ns at 0.0 "$n1 label Receiver"
#create nam file and attach with simulator object
set nf [open swout.nam w]
$ns namtrace-all $nf
#create trace file and attach with simulator object
set f [open swout.tr w]
$ns trace-all $f
#Link Setup
$ns duplex-link $n0 $n1 0.2Mb 200ms DropTail
# Orientation of nodes in Network Animation
$ns duplex-link-op $n0 $n1 orient Right
# Queue Setup
$ns queue-limit $n0 $n1 10
Agent/TCP set nam_tracevar_ true
# Setting of Traffic Source
set tcp [new Agent/TCP]
$tcp set window_ 1
$tcp set maxcwnd_ 1
$tcp set class_ 1
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $n1 $sink
$ns connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns add-agent-trace $tcp tcp
#$ns monitor-agent-trace $tcp
#$tcp tracevar cwnd_
#Schedule ftp event
$ns at 0.1 "$ftp start"
$ns at 3.0 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n1 $sink"
$ns at 3.5 "finish"
# trace annotation
$ns at 0.0 "$ns trace-annotate \"Stop and Wait with normal operation\""
$ns at 0.05 "$ns trace-annotate \"FTP starts at 0.1\""
$ns at 0.11 "$ns trace-annotate \"Send Packet_0\""
$ns at 0.35 "$ns trace-annotate \"Receive Ack_0\""
$ns at 0.56 "$ns trace-annotate \"Send Packet_1\""
$ns at 0.79 "$ns trace-annotate \"Receive Ack_1\""
$ns at 0.99 "$ns trace-annotate \"Send Packet_2\""
$ns at 1.23 "$ns trace-annotate \"Receive Ack_2 \""
$ns at 1.43 "$ns trace-annotate \"Send Packet_3\""
$ns at 1.67 "$ns trace-annotate \"Receive Ack_3\""
$ns at 1.88 "$ns trace-annotate \"Send Packet_4\""
$ns at 2.11 "$ns trace-annotate \"Receive Ack_4\""
$ns at 2.32 "$ns trace-annotate \"Send Packet_5\""
$ns at 2.55 "$ns trace-annotate \"Receive Ack_5 \""
$ns at 2.75 "$ns trace-annotate \"Send Packet_6\""
$ns at 2.99 "$ns trace-annotate \"Receive Ack_6\""
$ns at 3.1 "$ns trace-annotate \"FTP stops\""
# define finish procedure
proc finish {} {
global ns nf
$ns flush-trace
close $nf
puts "running nam..."
exec nam swout.nam &
exit 0
}
$ns run
}
#Create Simulator Oject
set ns [new Simulator]
#Open the trace file
set nr [open ls.tr w]
$ns trace-all $nr
#Open the output nam files
set nf [open ls.nam w]
$ns namtrace-all $nf
#Define a finish procedure
proc finish { } {
global ns nr nf
$ns flush-trace
close $nf
close $nr
exec nam ls.nam &
exit 0
}
# Create nodes
for { set i 0 } { $i < 12} { incr i 1 } {
set n($i) [$ns node]}
# Create duplex links between nodes
for {set i 0} {$i < 11} {incr i} {
$ns duplex-link $n($i) $n([expr $i+1]) 1Mb 10ms DropTail }
$ns duplex-link $n(1) $n(11) 1Mb 10ms DropTail
#Create a UDP agent and attach it to node n0
set udp0 [new Agent/UDP]
$ns attach-agent $n(0) $udp0
# Create a CBR traffic source and attach it to udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0
#Create a Null agent (a traffic sink) and attach it to node n5
set null0 [new Agent/Null]
$ns attach-agent $n(5) $null0
$ns connect $udp0 $null0
# specify Link State routing
$ns rtproto LS
# link between node n4 and n5 goes down(not working)
$ns rtmodel-at 5.0 down $n(4) $n(5)
# link between node n4 and n5 goes Up(working properly)
$ns rtmodel-at 10.0 up $n(4) $n(5)
# Set color for traffic
$udp0 set fid_ 1
# color specification
$ns color 1 Red
#Schedule events for the CBR agent
$ns at 1.0 "$cbr0 start"
#Call the finish procedure after 11 seconds of simulation time
$ns at 11 "finish"
$ns run
#************************************************************************************************
#************************************************************************************************
#distance vector routing
#Create Simulator Oject
set ns [new Simulator]
#Open the trace file
set nr [open dv.tr w]
$ns trace-all $nr
#Open the output nam files
set nf [open dv.nam w]
$ns namtrace-all $nf
#Define a finish procedure
proc finish { } {
global ns nr nf
$ns flush-trace
close $nf
close $nr
exec nam dv.nam &
exit 0
}
# Create nodes
for { set i 0 } { $i < 12} { incr i 1 } {
set n($i) [$ns node]}
# Create duplex links between nodes
for {set i 0} {$i < 11} {incr i} {
$ns duplex-link $n($i) $n([expr $i+1]) 1Mb 10ms DropTail }
$ns duplex-link $n(1) $n(11) 1Mb 10ms DropTail
#Create a UDP agent and attach it to node n0
set udp0 [new Agent/UDP]
$ns attach-agent $n(0) $udp0
# Create a CBR traffic source and attach it to udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0
#Create a Null agent (a traffic sink) and attach it to node n5
set null0 [new Agent/Null]
$ns attach-agent $n(5) $null0
$ns connect $udp0 $null0
$ns rtproto DV
# link between node n4 and n5 goes down(not working)
$ns rtmodel-at 5.0 down $n(4) $n(5)
# link between node n4 and n5 goes Up(working properly)
$ns rtmodel-at 10.0 up $n(4) $n(5)
# Set color for traffic
$udp0 set fid_ 1
# color specification
$ns color 1 Red
#Schedule events for the CBR agent
$ns at 1.0 "$cbr0 start"
#Call the finish procedure after 11 seconds of simulation time
$ns at 11 "finish"
$ns run
#******************************************************************************************
#******************************************************************************************
#distance vector routing
#Create Simulator Oject
set ns [new Simulator]
#Tell the simulator to use dynamic routing
$ns rtproto DV
$ns macType Mac/Sat/UnslottedAloha
#Open the nam trace file
set nf [open aloha.nam w]
$ns namtrace-all $nf
#Open the output files
set f0 [open aloha.tr w]
$ns trace-all $f0
#Define a finish procedure
proc finish {} {
global ns f0 nf
$ns flush-trace
#Close the trace file
close $f0
close $nf
exec nam aloha.nam &
exit 0
}
# Create six 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 duplex links between nodes with bandwidth and distance
$ns duplex-link $n0 $n4 1Mb 50ms DropTail
$ns duplex-link $n1 $n4 1Mb 50ms DropTail
$ns duplex-link $n2 $n5 1Mb 1ms DropTail
$ns duplex-link $n3 $n5 1Mb 1ms DropTail
$ns duplex-link $n4 $n5 1Mb 50ms DropTail
$ns duplex-link $n2 $n3 1Mb 50ms DropTail
# Create a duplex link between nodes 4 and 5 as queue position
#The queuePos is only needed for visualisation. It is not used during the simulations,used by NAM to show the queue i.e. 0.5 x 180 =90 degree
$ns duplex-link-op $n4 $n5 queuePos 0.5
#Create a UDP agent and attach it to node n(0)
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
# Create a CBR traffic source and attach it to udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0
#Create a Null agent (a traffic sink) and attach it to node n(2)
set null0 [new Agent/Null]
$ns attach-agent $n2 $null0
#Connect the traffic source with the traffic sink
$ns connect $udp0 $null0
#Schedule events for the CBR agent and the network dynamics
$ns at 0.5 "$cbr0 start"
# link between n5 and n2 not working properly from 1.0 and again get connection at time 2.0
# when link between n5 and n2 goes down then oter alternative path will be chosen by routing algorithm
$ns rtmodel-at 1.0 down $n5 $n2
$ns rtmodel-at 2.0 up $n5 $n2
$ns at 4.5 "$cbr0 stop"
#Call the finish procedure after 5 seconds of simulation time
$ns at 5.0 "finish"
#Run the simulation
$ns run
#**************************************************************************************************************
#*********************************************************************************************************
#goback n sliding window
#send packets one by one
#create simulator object
set ns [new Simulator]
#create node
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
# Labeling of nodes
$ns at 0.0 "$n1 label Sender"
$ns at 0.0 "$n4 label Receiver"
# processing nam file
set nf [open goback.nam w]
$ns namtrace-all $nf
# processing trace file file
set f [open goback.tr w]
$ns trace-all $f
# Link Setup
$ns duplex-link $n0 $n2 1Mb 20ms DropTail
$ns queue-limit $n0 $n2 5
$ns duplex-link $n1 $n2 1Mb 20ms DropTail
$ns duplex-link $n2 $n3 1Mb 20ms DropTail
$ns duplex-link $n3 $n4 1Mb 20ms DropTail
$ns duplex-link $n3 $n5 1Mb 20ms DropTail
# setting node position
$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n1 $n2 orient right-up
$ns duplex-link-op $n2 $n3 orient right
$ns duplex-link-op $n3 $n4 orient right-up
$ns duplex-link-op $n3 $n5 orient right-down
# traffic source setup
Agent/TCP set_nam_tracevar_true
set tcp [new Agent/TCP]
$tcp set fid 1
# n1 is the source
$ns attach-agent $n1 $tcp
# n4 is the receiver
set sink [new Agent/TCPSink]
$ns attach-agent $n4 $sink
$ns connect $tcp $sink
# traffic Agent setup
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns at 0.05 "$ftp start"
$ns at 0.06 "$tcp set windowlnit 6"
$ns at 0.06 "$tcp set maxcwnd 6"
$ns at 0.25 "$ns queue-limit $n3 $n4 0"
$ns at 0.26 "$ns queue-limit $n3 $n4 10"
$ns at 0.305 "$tcp set windowlnit 4"
$ns at 0.305 "$tcp set maxcwnd 4"
$ns at 0.368 "$ns detach-agent $n1 $tcp ; $ns detach-agent $n4 $sink"
$ns at 1.5 "finish"
$ns at 0.0 "$ns trace-annotate \"Goback N end\""
$ns at 0.05 "$ns trace-annotate \"FTP starts at 0.01\""
$ns at 0.06 "$ns trace-annotate \"Send 6Packets from SYS1 to SYS4\""
$ns at 0.26 "$ns trace-annotate \"Error Occurs for 4th packet so not sent ack for the Packet\""
$ns at 0.30 "$ns trace-annotate \"Retransmit Packet_4 to 6\""
$ns at 1.0 "$ns trace-annotate \"FTP stops\""
# function finish
proc finish {} {
global ns nf
$ns flush-trace
close $nf
puts "filtering..."
exec nam goback.nam &
exit 0
}
$ns run
#*********************************************************************************************************************
#*********************************************************************************************************************
#selective repeat...
#send packets one by one
# define simulator
set ns [new Simulator]
#define node
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 color of the node
$n1 color "red"
$n4 color "red"
#label sender and receiver
$ns at 0.0 "$n1 label Sender"
$ns at 0.0 "$n4 label Receiver"
#nam file
set nf [open Srepeat.nam w]
$ns namtrace-all $nf
#trace file
set f [open Srepeat.tr w]
$ns trace-all $f
#Link Setup
$ns duplex-link $n0 $n2 1Mb 10ms DropTail
# $ns queue-limit $n0 $n2 5
$ns duplex-link $n1 $n2 1Mb 10ms DropTail
$ns duplex-link $n2 $n3 1Mb 10ms DropTail
$ns duplex-link $n3 $n4 1Mb 10ms DropTail
$ns duplex-link $n3 $n5 1Mb 10ms DropTail
# node orientation
$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n1 $n2 orient right-up
$ns duplex-link-op $n2 $n3 orient right
$ns duplex-link-op $n3 $n4 orient right-up
$ns duplex-link-op $n3 $n5 orient right-down
# Traffic Agent setup
Agent/TCP set_nam_tracevar_true
set tcp [new Agent/TCP]
$tcp set fid 1
$ns attach-agent $n1 $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $n4 $sink
$ns connect $tcp $sink
# Traffic Source setup
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns at 0.05 "$ftp start"
$ns at 0.06 "$tcp set windowlnit 8"
$ns at 0.06 "$tcp set maxcwnd 8"
$ns at 0.25 "$ns queue-limit $n3 $n4 0"
$ns at 0.26 "$ns queue-limit $n3 $n4 10"
$ns at 0.30 "$tcp set windowlnit 1"
$ns at 0.30 "$tcp set maxcwnd 1"
$ns at 0.30 "$ns queue-limit $n3 $n4 10"
$ns at 0.47 "$ns detach-agent $n1 $tcp;$ns detach-agent $n4 $sink"
$ns at 1.55 "finish"
$ns at 0.0 "$ns trace-annotate \"Select and repeat\""
$ns at 0.05 "$ns trace-annotate \"FTP starts at 0.01\""
$ns at 0.06 "$ns trace-annotate \"Send 8 Packets from Sender to Receiver\""
$ns at 0.26 "$ns trace-annotate \"Error Occurs in 4th packet \""
$ns at 0.30 "$ns trace-annotate \"Retransmit Packet_4 from Sender to Receiver\""
$ns at 1.5 "$ns trace-annotate \"FTP stops\""
# define finish procedure
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exec nam Srepeat.nam &
exit 0
}
$ns run
#*****************************************************************************************************
#*****************************************************************************************************
# stop and wait protocol in normal situation
# features : labeling, annotation, nam-graph, and window size monitoring
# Create Simulator Oject
set ns [new Simulator]
$ns color 1 blue
#Define nodes
set n0 [$ns node]
set n1 [$ns node]
# labeling of nodes
$ns at 0.0 "$n0 label Sender"
$ns at 0.0 "$n1 label Receiver"
#create nam file and attach with simulator object
set nf [open swout.nam w]
$ns namtrace-all $nf
#create trace file and attach with simulator object
set f [open swout.tr w]
$ns trace-all $f
#Link Setup
$ns duplex-link $n0 $n1 0.2Mb 200ms DropTail
# Orientation of nodes in Network Animation
$ns duplex-link-op $n0 $n1 orient Right
# Queue Setup
$ns queue-limit $n0 $n1 10
Agent/TCP set nam_tracevar_ true
# Setting of Traffic Source
set tcp [new Agent/TCP]
$tcp set window_ 1
$tcp set maxcwnd_ 1
$tcp set class_ 1
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $n1 $sink
$ns connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns add-agent-trace $tcp tcp
#$ns monitor-agent-trace $tcp
#$tcp tracevar cwnd_
#Schedule ftp event
$ns at 0.1 "$ftp start"
$ns at 3.0 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n1 $sink"
$ns at 3.5 "finish"
# trace annotation
$ns at 0.0 "$ns trace-annotate \"Stop and Wait with normal operation\""
$ns at 0.05 "$ns trace-annotate \"FTP starts at 0.1\""
$ns at 0.11 "$ns trace-annotate \"Send Packet_0\""
$ns at 0.35 "$ns trace-annotate \"Receive Ack_0\""
$ns at 0.56 "$ns trace-annotate \"Send Packet_1\""
$ns at 0.79 "$ns trace-annotate \"Receive Ack_1\""
$ns at 0.99 "$ns trace-annotate \"Send Packet_2\""
$ns at 1.23 "$ns trace-annotate \"Receive Ack_2 \""
$ns at 1.43 "$ns trace-annotate \"Send Packet_3\""
$ns at 1.67 "$ns trace-annotate \"Receive Ack_3\""
$ns at 1.88 "$ns trace-annotate \"Send Packet_4\""
$ns at 2.11 "$ns trace-annotate \"Receive Ack_4\""
$ns at 2.32 "$ns trace-annotate \"Send Packet_5\""
$ns at 2.55 "$ns trace-annotate \"Receive Ack_5 \""
$ns at 2.75 "$ns trace-annotate \"Send Packet_6\""
$ns at 2.99 "$ns trace-annotate \"Receive Ack_6\""
$ns at 3.1 "$ns trace-annotate \"FTP stops\""
# define finish procedure
proc finish {} {
global ns nf
$ns flush-trace
close $nf
puts "running nam..."
exec nam swout.nam &
exit 0
}
$ns run
}
No comments