jobs-lossdel.tcl
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:8k
源码类别:

通讯编程

开发平台:

Visual C++

  1. # jobs-lossdel.tcl
  2. #
  3. # Tests that the delay/loss differentiation is working properly
  4. # Outputs a nam animation and tracefiles.
  5. #
  6. # Topology is as follows:
  7. #
  8. # source(1)  --                                  /- sink(1)
  9. # source(2)  ---  core_node(1) -- core_node(2)  /-- sink(2)
  10. # source(3)  ---/                                -- sink(3)
  11. # source(4)  __/                                  _ sink(4)
  12. #
  13. # Links:
  14. # - : 10 Mbps, 1 ms
  15. #
  16. # Classes: 
  17. # 1: ADC=5 ms, ALC=1 %, no ARC, no RDC, no RLC
  18. # 2: no ADC, no ALC, RDC = 4, RLC = 2
  19. # 3: no ADC, no ALC, RDC = 4, RLC = 2
  20. # 4: no ADC, no ALC, RDC = 4, RLC = 2
  21. #
  22. # Traffic is randomized CBR
  23. #
  24. # Auxiliary functions
  25. Simulator instproc get-link { node1 node2 } {
  26.      $self instvar link_
  27.      set id1 [$node1 id]
  28.      set id2 [$node2 id]
  29.      return $link_($id1:$id2)
  30. }
  31. Simulator instproc get-queue { node1 node2 } {
  32.      global ns
  33.      set l [$ns get-link $node1 $node2]
  34.      set q [$l queue]
  35.      return $q
  36. }
  37. # JoBS duplex link: rate in kbps, delay in ms, buff_sz in packets
  38. proc build-jobs-link {src dst rate delay buff_sz} {
  39.      global ns
  40.      $ns duplex-link $src $dst [expr $rate*1000.0] [expr $delay/1000.0] JoBS
  41.      $ns queue-limit $src $dst $buff_sz
  42.      $ns queue-limit $dst $src $buff_sz
  43. }
  44. # FCFS-marker duplex link: rate in kbps, delay in ms, buff_sz in packets
  45. proc build-marker-link {src dst rate delay buff_sz} {
  46.      global ns
  47.      $ns simplex-link $src $dst [expr $rate*1000.0] [expr $delay/1000.0] Marker
  48.      $ns simplex-link $dst $src [expr $rate*1000.0] [expr $delay/1000.0] Demarker
  49.      $ns queue-limit $src $dst $buff_sz
  50.      $ns queue-limit $dst $src $buff_sz
  51. }
  52. # FCFS-demarker duplex link: rate in kbps, delay in ms, buff_sz in packets
  53. proc build-demarker-link {src dst rate delay buff_sz} {
  54. global ns
  55. $ns simplex-link $src $dst [expr $rate*1000.0] [expr $delay/1000.0] Demarker
  56. $ns simplex-link $dst $src [expr $rate*1000.0] [expr $delay/1000.0] Marker
  57. $ns queue-limit $src $dst $buff_sz
  58. $ns queue-limit $dst $src $buff_sz
  59. }
  60. # Basic procedure for connecting agents, etc.
  61. proc flow_setup {id src src_agent dst dst_agent app_flow pksize} {
  62. global ns
  63. $ns attach-agent $src $src_agent
  64. $ns attach-agent $dst $dst_agent
  65. $ns connect $src_agent $dst_agent
  66. $src_agent set packetSize_  $pksize
  67. $src_agent set fid_ $id
  68. $app_flow set flowid_ $id
  69. $app_flow attach-agent $src_agent
  70. return $src_agent    
  71. }
  72. # CBR flow: Packet size:bytes, Rate: kbps, Start time:seconds
  73. proc build-cbr {id src src_agent dst dst_agent app_flow rate pksize start_tm} {
  74.      global ns
  75.      flow_setup $id $src $src_agent $dst $dst_agent $app_flow $pksize
  76.      $app_flow set rate_        [expr $rate * 1000.0]
  77.      $app_flow set random_ 1
  78.      $ns at $start_tm "$app_flow start"
  79.      puts [format "tCBR-$id starts at %.4fsec" $start_tm]
  80. }
  81. # main 
  82. puts " "
  83. set ns [new Simulator]
  84. set rnd [new RNG]
  85. set seed 16
  86. puts "Random seed: $seed"
  87. $rnd seed $seed 
  88. set nf [open jobs-lossdel/out.nam w]
  89. $ns namtrace-all $nf
  90. Queue/JoBS set drop_front_ false
  91. Queue/JoBS set trace_hop_ true
  92. Queue/JoBS set adc_resolution_type_ 0
  93. Queue/JoBS set shared_buffer_ 1
  94. Queue/JoBS set mean_pkt_size_ 4000
  95. Queue/Demarker set demarker_arrvs1_ 0
  96. Queue/Demarker set demarker_arrvs2_ 0
  97. Queue/Demarker set demarker_arrvs3_ 0
  98. Queue/Demarker set demarker_arrvs4_ 0
  99. Queue/Marker set marker_arrvs1_ 0
  100. Queue/Marker set marker_arrvs2_ 0
  101. Queue/Marker set marker_arrvs3_ 0
  102. Queue/Marker set marker_arrvs4_ 0
  103. #
  104. puts "nTOPOLOGY SETUP"
  105. # Number of hops (=k)
  106. set hops 2
  107. puts "Number of hops: $hops"
  108. # Link  latency (ms)
  109. set DELAY   1.0
  110. puts "Links latency: $DELAY (ms)"
  111. # links: bandwidth (kbps) 
  112. set BW 10000.0
  113. puts "Links capacity: $BW (kbps)"
  114. # Buffer size in gateways (in packets)
  115. set GW_BUFF 50
  116. puts "Gateway Buffer Size: $GW_BUFF (packs)"
  117. # Packet Size (in bytes); assume common for all sources
  118. set PKTSZ      500
  119. set MAXWIN     50
  120. puts "Packet Size: $PKTSZ (bytes)"
  121. # Number of monitored flows (equal to # of classes)
  122. set N_CL 4
  123. puts "Number of classes: $N_CL"
  124. set N_USERS 4
  125. puts "Number of flows: $N_USERS"
  126. set START_TM  0.0
  127. puts "Monitored flows start at: $START_TM"
  128. set max_time  10.0
  129. puts "Max time: $max_time (sec)"
  130. # Statistics-related parameters
  131. set STATS_INTR  2; # interval between reporting statistics 
  132. set START_STATS 0; # start-time for reporting statistics 
  133. # Marker Types
  134. # Deterministic 
  135. set DETERM 1
  136. # Demarker Types
  137. # Create a trace file for each class (for user traffic)
  138. set VERBOSE 1
  139. # Do not create trace files 
  140. set QUIET 2
  141. proc print_time {interval} {
  142. global ns 
  143.      puts ""
  144.      puts -nonewline stdout [format "%.2ft" [$ns now]]
  145.      $ns at [expr [$ns now]+$interval] "print_time $interval"
  146. }
  147. # 1. Core nodes ($hops nodes)
  148. for {set i 1} {$i <= $hops} {incr i} {
  149. set core_node($i) [$ns node]
  150. $core_node($i) color "black"
  151. $core_node($i) shape "square"
  152. $core_node($i) label QoSbox
  153. }
  154. puts "Core nodes: OK"
  155. # 2. User traffic nodes and sinks (N_USERS sources and sinks)
  156. for {set i 1} {$i <= $N_USERS} {incr i} {
  157. set source($i) [$ns node]
  158. $source($i) color blue
  159. set sink($i) [$ns node]
  160. $sink($i) color blue
  161. set source_agent($i) [new Agent/UDP]
  162. set sink_agent($i) [new Agent/LossMonitor]
  163. }
  164. puts "Traffic nodes and sinks: OK"
  165. # 3. Core link (JoBS)
  166. build-jobs-link $core_node(1) $core_node(2) $BW $DELAY $GW_BUFF
  167. set q [$ns get-queue $core_node(1) $core_node(2)]
  168. set l [$ns get-link $core_node(1) $core_node(2)]
  169. $q copyright-info
  170. $q init-rdcs -1 4 4 4 
  171. $q init-rlcs -1 2 2 2 
  172. $q init-alcs 0.01 -1 -1 -1
  173. $q init-adcs 0.001 -1 -1 -1
  174. $q init-arcs -1 -1 -1 -1
  175. $q trace-file jobs-lossdel/hoptrace
  176. $q link [$l link]
  177. $q sampling-period 1
  178. $q id $i
  179. $q initialize
  180. # It's a duplex link
  181. # Even though data won't travel on the reverse path (UDP sources), 
  182. # it is always a good idea to configure the JoBS queue on the reverse
  183. # path as well, in order to avoid unexpected results for TCP traffic. 
  184. set q [$ns get-queue $core_node(2) $core_node(1)]
  185. set l [$ns get-link $core_node(2) $core_node(1)]
  186. $q init-rdcs -1 4 4 4 
  187. $q init-rlcs -1 2 2 2
  188. $q init-alcs 0.01 -1 -1 -1
  189. $q init-adcs 0.001 -1 -1 -1
  190. $q init-arcs -1 -1 -1 -1
  191. $q trace-file null
  192. $q link [$l link]
  193. $q sampling-period 1
  194. $q id $i
  195. $q initialize
  196. puts "Core link: OK"
  197. # 6. Edge links (marker)
  198. for {set i 1} {$i <= $N_USERS} {incr i} {
  199. build-marker-link    $source($i) $core_node(1) $BW $DELAY [expr $GW_BUFF*10]
  200.      set q [$ns get-queue $source($i) $core_node(1)]
  201.     $q marker_type $DETERM
  202. $q marker_class $i
  203.      set q [$ns get-queue $core_node(1) $source($i)]
  204. # assign a bogus id
  205.      $q id 99
  206. set l [$ns get-link $source($i) $core_node(1)]
  207.     
  208. build-demarker-link  $core_node($hops) $sink($i) $BW $DELAY [expr $GW_BUFF*10]
  209.      set q [$ns get-queue $core_node($hops) $sink($i)]
  210.      $q id 99
  211.      set q [$ns get-queue $sink($i) $core_node($hops)]
  212.      $q marker_type $DETERM
  213. $q marker_class $i
  214. }
  215. puts "Edge marker/demarker links: OK" 
  216. #
  217. # Create traffic
  218. #
  219. # User traffic (UDP)
  220. for {set i 1} {$i <= $N_USERS} {incr i} {
  221. set flow($i) [new Application/Traffic/CBR]
  222. $flow($i) set random_ 1
  223. build-cbr $i $source($i) $source_agent($i) $sink($i) $sink_agent($i) $flow($i) 2600.0 $PKTSZ $START_TM 
  224. }
  225. puts "Flows: OK"
  226. #
  227. # Queue Monitors
  228. #
  229. $ns at $STATS_INTR "print_time $STATS_INTR"
  230. $ns at [expr $max_time+.000000001] "puts "Finishing Simulation...""
  231. $ns at [expr $max_time+1] "finish"
  232. proc finish {} {
  233. global ns nf
  234.         puts "nSimulation End"
  235. $ns flush-trace
  236. close $nf
  237. exec nam jobs-lossdel/out.nam & 
  238. exit 0
  239. }
  240. # nam stuff
  241. $ns duplex-link-op $source(1) $core_node(1) orient 300deg
  242. $ns duplex-link-op $source(1) $core_node(1) color "blue"
  243. $ns duplex-link-op $source(2) $core_node(1) orient 330deg
  244. $ns duplex-link-op $source(2) $core_node(1) color "blue"
  245. $ns duplex-link-op $source(3) $core_node(1) orient 30deg
  246. $ns duplex-link-op $source(3) $core_node(1) color "blue"
  247. $ns duplex-link-op $source(4) $core_node(1) orient 60deg
  248. $ns duplex-link-op $source(4) $core_node(1) color "blue"
  249. $ns duplex-link-op $core_node(1) $core_node(2) orient right
  250. $ns duplex-link-op $core_node(1) $core_node(2) color black
  251. $ns duplex-link-op $core_node(1) $core_node(2) queuePos 0.5
  252. $ns duplex-link-op $core_node(2) $sink(1) orient 60deg
  253. $ns duplex-link-op $core_node(2) $sink(1) color "blue"
  254. $ns duplex-link-op $core_node(2) $sink(2) orient 30deg
  255. $ns duplex-link-op $core_node(2) $sink(2) color "blue"
  256. $ns duplex-link-op $core_node(2) $sink(3) orient 330deg
  257. $ns duplex-link-op $core_node(2) $sink(3) color "blue"
  258. $ns duplex-link-op $core_node(2) $sink(4) orient 300deg
  259. $ns duplex-link-op $core_node(2) $sink(4) color "blue"
  260. $ns color 1 red
  261. $ns color 2 green
  262. $ns color 3 blue
  263. $ns color 4 purple
  264. puts "ngo!n"
  265. $ns run