dctcp example-ns2
1 set N 8 2 set B 250 3 set K 65 4 set RTT 0.0001 5 6 set simulationTime 1.0 7 8 set startMeasurementTime 1 9 set stopMeasurementTime 2 10 set flowClassifyTime 0.001 11 12 set sourceAlg DC-TCP-Sack 13 set switchAlg RED 14 set lineRate 10Gb 15 set inputLineRate 11Gb 16 17 set DCTCP_g_ 0.0625 18 set ackRatio 1 19 set packetSize 1460 20 21 set traceSamplingInterval 0.0001 22 set throughputSamplingInterval 0.01 23 set enableNAM 0 24 25 set ns [new Simulator] 26 27 Agent/TCP set ecn_ 1 28 Agent/TCP set old_ecn_ 1 29 Agent/TCP set packetSize_ $packetSize 30 Agent/TCP/FullTcp set segsize_ $packetSize 31 Agent/TCP set window_ 1256 32 Agent/TCP set slow_start_restart_ false 33 Agent/TCP set tcpTick_ 0.01 34 Agent/TCP set minrto_ 0.2 ; # minRTO = 200ms 35 Agent/TCP set windowOption_ 0 36 37 38 if {[string compare $sourceAlg "DC-TCP-Sack"] == 0} { 39 Agent/TCP set dctcp_ true 40 Agent/TCP set dctcp_g_ $DCTCP_g_; 41 } 42 Agent/TCP/FullTcp set segsperack_ $ackRatio; 43 Agent/TCP/FullTcp set spa_thresh_ 3000; 44 Agent/TCP/FullTcp set interval_ 0.04 ; #delayed ACK interval = 40ms 45 46 Queue set limit_ 1000 47 48 Queue/RED set bytes_ false 49 Queue/RED set queue_in_bytes_ true 50 Queue/RED set mean_pktsize_ $packetSize 51 Queue/RED set setbit_ true 52 Queue/RED set gentle_ false 53 Queue/RED set q_weight_ 1.0 54 Queue/RED set mark_p_ 1.0 55 Queue/RED set thresh_ [expr $K] 56 Queue/RED set maxthresh_ [expr $K] 57 58 DelayLink set avoidReordering_ true 59 60 if {$enableNAM != 0} { 61 set namfile [open out.nam w] 62 $ns namtrace-all $namfile 63 } 64 65 set mytracefile [open mytracefile.tr w] 66 set throughputfile [open thrfile.tr w] 67 68 proc finish {} { 69 global ns enableNAM namfile mytracefile throughputfile 70 $ns flush-trace 71 close $mytracefile 72 close $throughputfile 73 if {$enableNAM != 0} { 74 close $namfile 75 exec nam out.nam & 76 } 77 exit 0 78 } 79 80 proc myTrace {file} { 81 global ns N traceSamplingInterval tcp qfile MainLink nbow nclient packetSize enableBumpOnWire 82 83 set now [$ns now] 84 85 for {set i 0} {$i < $N} {incr i} { 86 set cwnd($i) [$tcp($i) set cwnd_] 87 set dctcp_alpha($i) [$tcp($i) set dctcp_alpha_] 88 } 89 90 $qfile instvar parrivals_ pdepartures_ pdrops_ bdepartures_ 91 92 puts -nonewline $file "$now $cwnd(0)" 93 for {set i 1} {$i < $N} {incr i} { 94 puts -nonewline $file " $cwnd($i)" 95 } 96 for {set i 0} {$i < $N} {incr i} { 97 puts -nonewline $file " $dctcp_alpha($i)" 98 } 99 100 puts -nonewline $file " [expr $parrivals_-$pdepartures_-$pdrops_]" 101 puts $file " $pdrops_" 102 103 $ns at [expr $now+$traceSamplingInterval] "myTrace $file" 104 } 105 106 proc throughputTrace {file} { 107 global ns throughputSamplingInterval qfile flowstats N flowClassifyTime 108 109 set now [$ns now] 110 111 $qfile instvar bdepartures_ 112 113 puts -nonewline $file "$now [expr $bdepartures_*8/$throughputSamplingInterval/1000000]" 114 set bdepartures_ 0 115 if {$now <= $flowClassifyTime} { 116 for {set i 0} {$i < [expr $N-1]} {incr i} { 117 puts -nonewline $file " 0" 118 } 119 puts $file " 0" 120 } 121 122 if {$now > $flowClassifyTime} { 123 for {set i 0} {$i < [expr $N-1]} {incr i} { 124 $flowstats($i) instvar barrivals_ 125 puts -nonewline $file " [expr $barrivals_*8/$throughputSamplingInterval/1000000]" 126 set barrivals_ 0 127 } 128 $flowstats([expr $N-1]) instvar barrivals_ 129 puts $file " [expr $barrivals_*8/$throughputSamplingInterval/1000000]" 130 set barrivals_ 0 131 } 132 $ns at [expr $now+$throughputSamplingInterval] "throughputTrace $file" 133 } 134 135 136 $ns color 0 Red 137 $ns color 1 Orange 138 $ns color 2 Yellow 139 $ns color 3 Green 140 $ns color 4 Blue 141 $ns color 5 Violet 142 $ns color 6 Brown 143 $ns color 7 Black 144 145 for {set i 0} {$i < $N} {incr i} { 146 set n($i) [$ns node] 147 } 148 149 set nqueue [$ns node] 150 set nclient [$ns node] 151 152 153 $nqueue color red 154 $nqueue shape box 155 $nclient color blue 156 157 for {set i 0} {$i < $N} {incr i} { 158 $ns duplex-link $n($i) $nqueue $inputLineRate [expr $RTT/4] DropTail 159 $ns duplex-link-op $n($i) $nqueue queuePos 0.25 160 } 161 162 163 $ns simplex-link $nqueue $nclient $lineRate [expr $RTT/4] $switchAlg 164 $ns simplex-link $nclient $nqueue $lineRate [expr $RTT/4] DropTail 165 $ns queue-limit $nqueue $nclient $B 166 167 $ns duplex-link-op $nqueue $nclient color "green" 168 $ns duplex-link-op $nqueue $nclient queuePos 0.25 169 set qfile [$ns monitor-queue $nqueue $nclient [open queue.tr w] $traceSamplingInterval] 170 171 172 for {set i 0} {$i < $N} {incr i} { 173 if {[string compare $sourceAlg "Newreno"] == 0 || [string compare $sourceAlg "DC-TCP-Newreno"] == 0} { 174 set tcp($i) [new Agent/TCP/Newreno] 175 set sink($i) [new Agent/TCPSink] 176 } 177 if {[string compare $sourceAlg "Sack"] == 0 || [string compare $sourceAlg "DC-TCP-Sack"] == 0} { 178 set tcp($i) [new Agent/TCP/FullTcp/Sack] 179 set sink($i) [new Agent/TCP/FullTcp/Sack] 180 $sink($i) listen 181 } 182 183 $ns attach-agent $n($i) $tcp($i) 184 $ns attach-agent $nclient $sink($i) 185 186 $tcp($i) set fid_ [expr $i] 187 $sink($i) set fid_ [expr $i] 188 189 $ns connect $tcp($i) $sink($i) 190 } 191 192 for {set i 0} {$i < $N} {incr i} { 193 set ftp($i) [new Application/FTP] 194 $ftp($i) attach-agent $tcp($i) 195 } 196 197 $ns at $traceSamplingInterval "myTrace $mytracefile" 198 $ns at $throughputSamplingInterval "throughputTrace $throughputfile" 199 200 set ru [new RandomVariable/Uniform] 201 $ru set min_ 0 202 $ru set max_ 1.0 203 204 for {set i 0} {$i < $N} {incr i} { 205 $ns at 0.0 "$ftp($i) send 10000" 206 $ns at [expr 0.1 + $simulationTime * $i / ($N + 0.0001)] "$ftp($i) start" 207 $ns at [expr $simulationTime] "$ftp($i) stop" 208 } 209 210 set flowmon [$ns makeflowmon Fid] 211 set MainLink [$ns link $nqueue $nclient] 212 213 $ns attach-fmon $MainLink $flowmon 214 215 set fcl [$flowmon classifier] 216 217 $ns at $flowClassifyTime "classifyFlows" 218 219 proc classifyFlows {} { 220 global N fcl flowstats 221 puts "NOW CLASSIFYING FLOWS" 222 for {set i 0} {$i < $N} {incr i} { 223 set flowstats($i) [$fcl lookup autp 0 0 $i] 224 } 225 } 226 227 228 set startPacketCount 0 229 set stopPacketCount 0 230 231 proc startMeasurement {} { 232 global qfile startPacketCount 233 $qfile instvar pdepartures_ 234 set startPacketCount $pdepartures_ 235 } 236 237 proc stopMeasurement {} { 238 global qfile startPacketCount stopPacketCount packetSize startMeasurementTime stopMeasurementTime simulationTime 239 $qfile instvar pdepartures_ 240 set stopPacketCount $pdepartures_ 241 puts "Throughput = [expr ($stopPacketCount-$startPacketCount)/(1024.0*1024*($stopMeasurementTime-$startMeasurementTime))*$packetSize*8] Mbps" 242 } 243 244 $ns at $startMeasurementTime "startMeasurement" 245 $ns at $stopMeasurementTime "stopMeasurement" 246 247 $ns at $simulationTime "finish" 248 249 $ns run