📄 mhop.tcl
字号:
#type of the source traversing oll the hops: reno, westwood or vegasset conn_type [lindex $argv 0]#capacity of the links between consecutive hopsset bw [lindex $argv 1]#number of hopsset hop [lindex $argv 2]#loss rate of the last linkset perdite [lindex $argv 3]#select the filter used by westwood (set $filt=4 to simulate westwood+, $filt=3 to simulate westwood)set filter [lindex $argv 4]#kind of cross traffic sources: reno, westwood or vegasset cross [lindex $argv 5]#capacity of the last linkset bw_last [lindex $argv 6]set stringa "$conn_type $bw $hop $perdite $filter $cross $bw_last"#Create a simulator objectset ns [new Simulator]#Open the output filesset q0 [open q.tr w]#congestion window values of the forward connectionsset cwndf [open cwnd.tr w]#sequence numbers of the forward connectionsset snf [open sn.tr w]#bandwidth estimates of the forward connectionsset bwef [open bwe.tr w]#rtts measuered by the forward connectionsset rttf [open rtt.tr w]#slow start thtreshold of the forward connectionsset sstf [open sst.tr w]#buffers have been dimensionated assuming a maximum RTT=250msset buffer [expr ((($bw*250000)/(1500*8)))]set bw [expr ($bw*1000000)]set bufferlast [expr ((($bw_last*250000)/(1500*8)))]set bwlast [expr ($bw_last*1000000)]#if you want to set up a minimum bound on the bottleneck queue length uncomment the following 6 lines#if ($buffer<20) {# set buffer 20# }# if ($bufferlast<20) {# set bufferlast 20# }set nf [open out.nam w]#$ns namtrace-all $nfset f [open out.tr w]#$ns trace-all $fset Rfirst [$ns node]set Rlast [$ns node]set Sender [$ns node]set Receiver [$ns node]#all links have a 10ms delay#set delay [expr (0.025/(3+2*$hop))]set delay 0.01#set delayhop [expr ((0.025-$delay)/2)]set delayhop 0.01#set delay1 [expr ($delay+0.05)]set delay1 0.01$ns duplex-link $Sender $Rfirst 1000Mb $delay1 DropTail$ns queue-limit $Sender $Rfirst 1000000$ns queue-limit $Rfirst $Sender 1000000$ns duplex-link $Receiver $Rlast $bwlast $delay1 DropTail$ns queue-limit $Receiver $Rlast $bufferlast$ns queue-limit $Rlast $Receiver $bufferlast switch $conn_type { "reno" { set tcpl [new Agent/TCP/Newreno] } "westwood" { set tcpl [new Agent/TCP/WestwoodNR] } "vegas" { set tcpl [new Agent/TCP/Vegas] } } $tcpl set window_ 1000 $tcpl set maxcwnd_ 1000 $tcpl set windowInit_ 1 $tcpl set packetSize_ 1500 $tcpl set filter_type_ $filter $tcpl set tau_ 1.0 $tcpl set west_type_ 3 $tcpl set useHeaders_ 0 $tcpl set interp_type_ 0 $tcpl set windowInitOption_ 2 #$tcpl set timestamps_ 1 $ns attach-agent $Sender $tcpl set ftpl [new Application/FTP] set sinkl [new Agent/TCPSink/DelAck] $ns attach-agent $Receiver $sinkl $ns connect $tcpl $sinkl $ftpl attach-agent $tcpl $ns at 0.0 "$ftpl start"#Create nodesfor {set i 0} {$i < $hop} {incr i} { set nsender($i) [$ns node] set nrecv($i) [$ns node] set nsenderrew($i) [$ns node] set nrecvrew($i) [$ns node] set nfirst($i) [$ns node] set nlast($i) [$ns node] $ns duplex-link $nfirst($i) $nlast($i) $bw $delay DropTail $ns queue-limit $nfirst($i) $nlast($i) $buffer $ns queue-limit $nlast($i) $nfirst($i) $buffer $ns duplex-link $nsender($i) $nfirst($i) 1000Mb $delayhop DropTail $ns queue-limit $nfirst($i) $nsender($i) $buffer $ns queue-limit $nsender($i) $nfirst($i) 100000 $ns duplex-link $nrecv($i) $nlast($i) 1000Mb $delayhop DropTail $ns queue-limit $nlast($i) $nrecv($i) $buffer $ns queue-limit $nrecv($i) $nlast($i) 100000 $ns duplex-link $nrecvrew($i) $nfirst($i) 1000Mb $delayhop DropTail $ns queue-limit $nfirst($i) $nrecvrew($i) $buffer $ns queue-limit $nrecvrew($i) $nfirst($i) 100000 $ns duplex-link $nsenderrew($i) $nlast($i) 1000Mb $delayhop DropTail $ns queue-limit $nlast($i) $nsenderrew($i) $buffer $ns queue-limit $nsenderrew($i) $nlast($i) 100000 if {$i>0} { $ns duplex-link $nfirst($i) $nlast([expr ($i-1)]) $bw $delay DropTail $ns queue-limit $nfirst($i) $nlast([expr ($i-1)]) $buffer $ns queue-limit $nlast([expr ($i-1)]) $nfirst($i) $buffer } }$ns duplex-link $Rfirst $nfirst(0) $bw $delay DropTail$ns queue-limit $Rfirst $nfirst(0) $buffer$ns queue-limit $nfirst(0) $Rfirst 1000000$ns duplex-link $Rlast $nlast([expr ($hop-1)]) $bw $delay DropTail$ns queue-limit $Rlast $nlast([expr ($hop-1)]) 1000000$ns queue-limit $nlast([expr ($hop-1)]) $Rlast $bufferset u [new RandomVariable/Uniform]$u set min_ 1$u set max_ 500set u1 [new RandomVariable/Uniform]$u1 set min_ 500$u1 set max_ 1000for {set i 0} {$i < $hop} {incr i} { switch $cross { "reno" { set tcp($i) [new Agent/TCP/Newreno] set tcprew($i) [new Agent/TCP/Newreno] } "westwood" { set tcp($i) [new Agent/TCP/WestwoodNR] set tcprew($i) [new Agent/TCP/WestwoodNR] $tcp($i) set filter_type_ 4 $tcprew($i) set filter_type_ 4 $tcp($i) set tau_ 1 $tcprew($i) set tau_ 1 $tcp($i) set west_type_ 3 $tcprew($i) set west_type_ 3 $tcp($i) set interp_type_ 0 $tcprew($i) set interp_type_ 0 } "vegas" { set tcp($i) [new Agent/TCP/Vegas] set tcprew($i) [new Agent/TCP/Vegas] } } $tcp($i) set window_ 10000 $tcp($i) set maxcwnd_ 10000 $tcp($i) set windowInit_ 1 $tcp($i) set packetSize_ 1500 $tcp($i) set windowInitOption_ 2 #$tcp($i) set timestamps_ 1 $ns attach-agent $nsender($i) $tcp($i) set ftp($i) [new Application/FTP] set sink($i) [new Agent/TCPSink/DelAck] $ns attach-agent $nrecv($i) $sink($i) $ns connect $tcp($i) $sink($i) $ftp($i) attach-agent $tcp($i) #the start time of the cross connection is uniformly distributed in the range [0,500] set k [$u value] $ns at $k "$ftp($i) start" #puts "$k" #the stop time of the cross connection is uniformly distributed in the range [500,1000] set k [$u1 value] $ns at $k "$ftp($i) stop" #puts "$k" #$ns at 0.0 "$ftp($i) start" $tcprew($i) set window_ 1000 $tcprew($i) set maxcwnd_ 1000 $tcprew($i) set windowInit_ 1 $tcprew($i) set packetSize_ 1500 $tcprew($i) set windowInitOption_ 2 # $tcprew($i) set timestamps_ 1 $ns attach-agent $nsenderrew($i) $tcprew($i) set ftprew($i) [new Application/FTP] set sinkrew($i) [new Agent/TCPSink/DelAck] $ns attach-agent $nrecvrew($i) $sinkrew($i) $ns connect $tcprew($i) $sinkrew($i) $ftprew($i) attach-agent $tcprew($i) set k [$u value] $ns at $k "$ftprew($i) start" #puts "$k" set k [$u1 value] $ns at $k "$ftprew($i) stop" #puts "$k" #$ns at 0.0 "$ftprew($i) start" }# definizione del modello d'erroreset good [new ErrorModel]$good unit pkt$good set rate_ $perdite#set rv0 [new RandomVariable/Uniform]#$rv0 set avg_ 0.01#$good ranvar $rv0set bad [new ErrorModel]$bad unit pkt$bad set rate_ $perdite#set rv1 [new RandomVariable/Uniform]#$rv1 set avg_ 0.07#$bad ranvar $rv1#rapporto tra i tempi good e bad 10:1set states [list $good $bad]#set periods [list 0.1 0.1]set periods [list 0.01 0.01]#set trans {{0.9875 0.0125} {0.025 0.975}}set trans {{0.5 0.5} {0.5 0.5}}set transunit pktset sttype timeset nstates 2set start $goodset em1 [new ErrorModel/MultiState $states $periods $trans $transunit $sttype $nstates $start]set em2 [new ErrorModel/MultiState $states $periods $trans $transunit $sttype $nstates $start]$ns lossmodel $good $Receiver $Rlast$ns lossmodel $bad $Rlast $Receiver#Define a 'finish' procedureproc finish {} { global node q0 cwndf snf nf ns bwef rttf sstf conn_type #Close the output files close $q0 close $cwndf close $snf close $bwef close $rttf close $sstf $ns flush-trace close $nf exit 0}set coda 0#Define a procedure which periodically records the bandwidth received by the#three traffic sinks sink0/1/2 and writes it to the three files f0/1/2.proc record {} { global ns coda sink0 sink1 sink2 q0 cwndf snf tcp mymonitor_ bwef rttf sstf conn_type hop tcpl stringa #Get an instance of the simulator #Set the time after which the procedure should be called again set time 0.1 set now [$ns now] set cwnd "$now" set seq "$now" #number of packets retransmitted by the cross traffic sources times 0.001 set somma 0 #sum of the sequence numbers of the cross traffic sources times 0.001 set sommag 0 set bwe "$now" set rttF "$now" set sst "$now" for {set i 0} {$i < $hop} {incr i} { set num [expr ([$tcp($i) set nrexmitpack_]*0.001)] set numg [expr ([$tcp($i) set t_seqno_])*0.001] set somma [expr ($somma + $num)] set sommag [expr ($sommag + $numg)] } set cwnd "$cwnd [$tcpl set cwnd_]" set seq "$seq [$tcpl set t_seqno_]" #packets retransmitted by the connection traversion all the hops set retlong [$tcpl set nrexmitpack_] #seq. no. of the connection traversing all the hops set goodputlong [$tcpl set t_seqno_] set rttF "$rttF [$tcpl set rtt_]" set sst "$sst [$tcpl set ssthresh_]" switch $conn_type { "westwood" { set bwe "$bwe [$tcpl set current_bwe_]" } } puts $cwndf "$cwnd" puts $snf "$seq" puts $bwef "$bwe" puts $rttf "$rttF" puts $sstf "$sst" if {$now>=999.9} { puts "$stringa $goodputlong $retlong $sommag $somma" } #Reset the bytes_ values on the traffic sinks #Re-schedule the procedure $ns at [expr $now+$time] "record"}#Create three traffic sinks and attach them to the node n4#Create three traffic sources#Start logging the received bandwidth$ns at 0.0 "record"$ns at 1000.0 "finish"#Run the simulation$ns run
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -