README.txt
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:10k
源码类别:

通讯编程

开发平台:

Visual C++

  1. This file gives a brief description of the commands existing in ns to
  2. simulate source routing. There is a sample file "src_rting.tcl" which
  3. contains a sample script to simulate two source routed
  4. connections. The steps involved in simulation:
  5. a) To enable source routing use node-config command in the following
  6.    manner:
  7. > $ns src_rting 1
  8. b) To establish a connection and to specify the source route to be
  9.    used use the following command:
  10. > set temp [$n1 set src_agent_]
  11. > $temp install_connection 3 1 3 1 2 3
  12.    The first argurment here is the flow id for the connection. This is
  13.    same as the flow id of the agent generating the traffic ( TCP or
  14.    UDP). The second arguement is the source node id of the
  15.    connection. The third arguement is the destination node id of the
  16.    connection. The arguements following this form the source route of
  17.    the connection.
  18.    
  19. c) To insert the routes in the packets generated from your agent ( TCP
  20.    or UDP) you need to set the target of the agent to the source routing
  21.    agent:
  22. > $tcp target [$n1 set src_agent_]
  23. This steps will get the source routing working for you. A sample code is shown below :
  24. st login: Thu May 10 2001 07:25:54 -0700 from 63.108.172.129
  25. No mail.
  26. bash: /etc/profile.d/alias.sh: No such file or directory
  27. [rishi@theory rishi]$ cd RA/ns-allinone-2.1b7.changedandwork/ns-2.1b7a
  28. [rishi@theory ns-2.1b7a]$ vi src_test.tcl 
  29. #Create a simulator object
  30. set ns [new Simulator]
  31. $ns src_rting 1
  32. # $ns node-config -perhopAgent Src_rt
  33. $ns color 1 Blue
  34. $ns color 2 Red
  35. #Open the nam trace file
  36. set nf [open out.tr w]
  37. $ns trace-all $nf
  38. set f [open out.nam w]
  39. $ns namtrace-all $f
  40. #Create four nodes
  41. set n0 [$ns node]
  42. set n1 [$ns node]
  43. set n2 [$ns node]
  44. set n3 [$ns node]
  45. set n4 [$ns node]
  46. #Create links between the nodes
  47. $ns duplex-link $n0 $n2 1Mb 10ms DropTail
  48. $ns duplex-link $n1 $n2 1Mb 10ms DropTail
  49. $ns duplex-link $n3 $n2 1Mb 10ms DropTail
  50. $ns duplex-link $n2 $n4 1Mb 10ms DropTail
  51. $ns duplex-link $n4 $n3 1Mb 10ms DropTail
  52. $ns duplex-link $n1 $n3 1Mb 10ms DropTail
  53. #Create a TCP agent and attach it to node n0
  54. set cbr0 [new Agent/TCP]
  55. $ns attach-agent $n0 $cbr0
  56. $cbr0 set fid_ 0
  57. #Create a TCP agent and attach it to node n1
  58. set cbr1 [new Agent/TCP]
  59. $ns attach-agent $n3 $cbr1
  60. $cbr1 set fid_ 1
  61. $cbr1 target [$n3 set src_agent_]
  62. $cbr0 target [$n0 set src_agent_]
  63. set temp [$n0 set src_agent_]
  64. $temp install_connection [$cbr0 set fid_] 0 1 0 2 4 3 1
  65. set temp [$n3 set src_agent_]
  66. set null0 [new Agent/TCPSink]
  67. set null1 [new Agent/TCPSink]
  68. $ns attach-agent $n1 $null0
  69. $ns attach-agent $n4 $null1
  70. $ns connect $cbr0 $null0
  71. $ns connect $cbr1 $null1
  72. $temp install_connection [$cbr1 set fid_] 3 4 3 2 4
  73. set ftp1 [$cbr0 attach-source FTP]
  74. set ftp2 [$cbr1 attach-source FTP]
  75. $ns at 0.5 "$ftp1 start"
  76. $cbr1 set fid_ 1
  77. $cbr1 target [$n3 set src_agent_]
  78. $cbr0 target [$n0 set src_agent_]
  79. set temp [$n0 set src_agent_]
  80. $temp install_connection [$cbr0 set fid_] 0 1 0 2 4 3 1
  81. set temp [$n3 set src_agent_]
  82. set null0 [new Agent/TCPSink]
  83. set null1 [new Agent/TCPSink]
  84. $ns attach-agent $n1 $null0
  85. $ns attach-agent $n4 $null1
  86. $ns connect $cbr0 $null0
  87. $ns connect $cbr1 $null1
  88. $temp install_connection [$cbr1 set fid_] 3 4 3 2 4
  89. set ftp1 [$cbr0 attach-source FTP]
  90. set ftp2 [$cbr1 attach-source FTP]
  91. $ns at 0.5 "$ftp1 start"
  92. #Create a TCP agent and attach it to node n0
  93. set cbr0 [new Agent/TCP]
  94. $ns attach-agent $n0 $cbr0
  95. $cbr0 set fid_ 0
  96. #Create a TCP agent and attach it to node n1
  97. set cbr1 [new Agent/TCP]
  98. $ns attach-agent $n3 $cbr1
  99. $cbr1 set fid_ 1
  100. $cbr1 target [$n3 set src_agent_]
  101. $cbr0 target [$n0 set src_agent_]
  102. set temp [$n0 set src_agent_]
  103. $temp install_connection [$cbr0 set fid_] 0 1 0 2 4 3 1
  104. set temp [$n3 set src_agent_]
  105. set null0 [new Agent/TCPSink]
  106. set null1 [new Agent/TCPSink]
  107. $ns attach-agent $n1 $null0
  108. $ns attach-agent $n4 $null1
  109. $ns connect $cbr0 $null0
  110. $ns connect $cbr1 $null1
  111. $temp install_connection [$cbr1 set fid_] 3 4 3 2 4
  112. set ftp1 [$cbr0 attach-source FTP]
  113. set ftp2 [$cbr1 attach-source FTP]
  114. $ns at 0.5 "$ftp1 start"
  115. $ns duplex-link $n0 $n2 1Mb 10ms DropTail
  116. $ns duplex-link $n1 $n2 1Mb 10ms DropTail
  117. $ns duplex-link $n3 $n2 1Mb 10ms DropTail
  118. $ns duplex-link $n2 $n4 1Mb 10ms DropTail
  119. $ns duplex-link $n4 $n3 1Mb 10ms DropTail
  120. $ns duplex-link $n1 $n3 1Mb 10ms DropTail
  121. #Create a TCP agent and attach it to node n0
  122. set cbr0 [new Agent/TCP]
  123. $ns attach-agent $n0 $cbr0
  124. $cbr0 set fid_ 0
  125. #Create a TCP agent and attach it to node n1
  126. set cbr1 [new Agent/TCP]
  127. $ns attach-agent $n3 $cbr1
  128. $cbr1 set fid_ 1
  129. $cbr1 target [$n3 set src_agent_]
  130. $cbr0 target [$n0 set src_agent_]
  131. set temp [$n0 set src_agent_]
  132. $temp install_connection [$cbr0 set fid_] 0 1 0 2 4 3 1
  133. set temp [$n3 set src_agent_]
  134. set null0 [new Agent/TCPSink]
  135. set null1 [new Agent/TCPSink]
  136. $ns attach-agent $n1 $null0
  137. $ns attach-agent $n4 $null1
  138. $ns connect $cbr0 $null0
  139. $ns connect $cbr1 $null1
  140. $temp install_connection [$cbr1 set fid_] 3 4 3 2 4
  141. set ftp1 [$cbr0 attach-source FTP]
  142. set ftp2 [$cbr1 attach-source FTP]
  143. $ns at 0.5 "$ftp1 start"
  144. #Open the nam trace file
  145. set nf [open out.tr w]
  146. $ns trace-all $nf
  147. set f [open out.nam w]
  148. $ns namtrace-all $f
  149. #Create four nodes
  150. set n0 [$ns node]
  151. set n1 [$ns node]
  152. set n2 [$ns node]
  153. set n3 [$ns node]
  154. set n4 [$ns node]
  155. #Create links between the nodes
  156. $ns duplex-link $n0 $n2 1Mb 10ms DropTail
  157. $ns duplex-link $n1 $n2 1Mb 10ms DropTail
  158. $ns duplex-link $n3 $n2 1Mb 10ms DropTail
  159. $ns duplex-link $n2 $n4 1Mb 10ms DropTail
  160. $ns duplex-link $n4 $n3 1Mb 10ms DropTail
  161. $ns duplex-link $n1 $n3 1Mb 10ms DropTail
  162. #Create a TCP agent and attach it to node n0
  163. set cbr0 [new Agent/TCP]
  164. $ns attach-agent $n0 $cbr0
  165. $cbr0 set fid_ 0
  166. #Create a TCP agent and attach it to node n1
  167. set cbr1 [new Agent/TCP]
  168. $ns attach-agent $n3 $cbr1
  169. $cbr1 set fid_ 1
  170. $cbr1 target [$n3 set src_agent_]
  171. $cbr0 target [$n0 set src_agent_]
  172. set temp [$n0 set src_agent_]
  173. $temp install_connection [$cbr0 set fid_] 0 1 0 2 4 3 1
  174. set temp [$n3 set src_agent_]
  175. set null0 [new Agent/TCPSink]
  176. set null1 [new Agent/TCPSink]
  177. $ns attach-agent $n1 $null0
  178. $ns attach-agent $n4 $null1
  179. $ns connect $cbr0 $null0
  180. $ns connect $cbr1 $null1
  181. $temp install_connection [$cbr1 set fid_] 3 4 3 2 4
  182. set ftp1 [$cbr0 attach-source FTP]
  183. set ftp2 [$cbr1 attach-source FTP]
  184. $ns at 0.5 "$ftp1 start"
  185. $ns at 0.5 "$ftp2 start"
  186. #Open the nam trace file
  187. set nf [open out.tr w]
  188. $ns trace-all $nf
  189. set f [open out.nam w]
  190. $ns namtrace-all $f
  191. #Create four nodes
  192. #Create a simulator object
  193. set ns [new Simulator]
  194. $ns src_rting 1
  195. # $ns node-config -perhopAgent Src_rt
  196. $ns color 1 Blue
  197. $ns color 2 Red
  198. #Open the nam trace file
  199. set nf [open out.tr w]
  200. $ns trace-all $nf
  201. set f [open out.nam w]
  202. $ns namtrace-all $f
  203. #Create four nodes
  204. #Create a simulator object
  205. set ns [new Simulator]
  206. # enable source routing
  207. $ns src_rting 1
  208. $ns color 1 Blue
  209. $ns color 2 Red
  210. #Open the nam trace file
  211. set nf [open out.tr w]
  212. $ns trace-all $nf
  213. set f [open out.nam w]
  214. $ns namtrace-all $f
  215. #Create four nodes
  216. set n0 [$ns node]
  217. #Create a simulator object
  218. set ns [new Simulator]
  219. # enable source routing
  220. $ns src_rting 1
  221. $ns color 1 Blue
  222. $ns color 2 Red
  223. #Open the nam trace file
  224. set nf [open out.tr w]
  225. $ns trace-all $nf
  226. set f [open out.nam w]
  227. $ns namtrace-all $f
  228. #Create four nodes
  229. set n0 [$ns node]
  230. set n1 [$ns node]
  231. set n2 [$ns node]
  232. set n3 [$ns node]
  233. set n4 [$ns node]
  234. #Create links between the nodes
  235. $ns duplex-link $n0 $n2 1Mb 10ms DropTail
  236. $ns duplex-link $n1 $n2 1Mb 10ms DropTail
  237. $ns duplex-link $n3 $n2 1Mb 10ms DropTail
  238. $ns duplex-link $n2 $n4 1Mb 10ms DropTail
  239. $ns duplex-link $n4 $n3 1Mb 10ms DropTail
  240. $ns duplex-link $n1 $n3 1Mb 10ms DropTail
  241. #Create a TCP agent and attach it to node n0
  242. set cbr0 [new Agent/TCP]
  243. $ns attach-agent $n0 $cbr0
  244. $cbr0 set fid_ 0
  245. #Create a TCP agent and attach it to node n1
  246. set cbr1 [new Agent/TCP]
  247. $ns attach-agent $n3 $cbr1
  248. $cbr1 set fid_ 1
  249. $cbr0 target [$n0 set src_agent_]
  250. $cbr1 target [$n3 set src_agent_]
  251. set temp [$n0 set src_agent_]
  252. $temp install_connection [$cbr0 set fid_] 0 1 0 2 4 3 1
  253. set temp [$n3 set src_agent_]
  254. $temp install_connection [$cbr1 set fid_] 3 4 3 2 4
  255. set null0 [new Agent/TCPSink]
  256. set null1 [new Agent/TCPSink]
  257. $ns attach-agent $n1 $null0
  258. $ns attach-agent $n4 $null1
  259. $ns connect $cbr0 $null0
  260. $ns connect $cbr1 $null1
  261. set ftp1 [$cbr0 attach-source FTP]
  262. set ftp2 [$cbr1 attach-source FTP]
  263. $ns at 0.5 "$ftp1 start"
  264. $ns at 0.5 "$ftp2 start"
  265. $ns at 5.0 "$ftp1 stop"
  266. $ns at 10.5 "$ftp2 stop"
  267. $ns at 11.0 "$ns halt"
  268. $ns run
  269. "src_test.tcl" 73L, 1480C written
  270. [rishi@theory ns-2.1b7a]$ vi src_test.tcl 
  271. #Create a simulator object
  272. set ns [new Simulator]
  273. # enable source routing
  274. $ns src_rting 1
  275. $ns color 1 Blue
  276. $ns color 2 Red
  277. #Open the nam trace file
  278. set nf [open out.tr w]
  279. $ns trace-all $nf
  280. set f [open out.nam w]
  281. $ns namtrace-all $f
  282. #Create four nodes
  283. set n0 [$ns node]
  284. set n1 [$ns node]
  285. set n2 [$ns node]
  286. set n3 [$ns node]
  287. set n4 [$ns node]
  288. #Create links between the nodes
  289. $ns duplex-link $n0 $n2 1Mb 10ms DropTail
  290. $ns duplex-link $n1 $n2 1Mb 10ms DropTail
  291. $ns duplex-link $n3 $n2 1Mb 10ms DropTail
  292. $ns duplex-link $n2 $n4 1Mb 10ms DropTail
  293. $ns duplex-link $n4 $n3 1Mb 10ms DropTail
  294. $ns duplex-link $n1 $n3 1Mb 10ms DropTail
  295. #Create a TCP agent and attach it to node n0
  296. set cbr0 [new Agent/TCP]
  297. $ns attach-agent $n0 $cbr0
  298. $cbr0 set fid_ 0
  299. #Create a TCP agent and attach it to node n1
  300. set cbr1 [new Agent/TCP]
  301. $ns attach-agent $n3 $cbr1
  302. $cbr1 set fid_ 1
  303. $cbr0 target [$n0 set src_agent_]
  304. $cbr1 target [$n3 set src_agent_]
  305. set temp [$n0 set src_agent_]
  306. $temp install_connection [$cbr0 set fid_] 0 1 0 2 4 3 1
  307. set temp [$n3 set src_agent_]
  308. $temp install_connection [$cbr1 set fid_] 3 4 3 2 4
  309. set null0 [new Agent/TCPSink]
  310. set null1 [new Agent/TCPSink]
  311. $ns attach-agent $n1 $null0
  312. $ns attach-agent $n4 $null1
  313. $ns connect $cbr0 $null0
  314. $ns connect $cbr1 $null1
  315. set ftp1 [$cbr0 attach-source FTP]
  316. set ftp2 [$cbr1 attach-source FTP]
  317. $ns at 0.5 "$ftp1 start"
  318. $ns at 0.5 "$ftp2 start"
  319. $ns at 5.0 "$ftp1 stop"
  320. $ns at 10.5 "$ftp2 stop"
  321. $ns at 11.0 "$ns halt"
  322. $ns run