NS2网络模拟(6)-homework02.tcl

  1: #NS2_有线部分\homework02.tcl
  2:
  3: #Create a simulator object
  4: set ns [new Simulator]
  5:
  6: #Define different colors for data flows
  7: $ns color 1 Blue
  8: $ns color 2 Red
  9:
 10: #Open the nam trace file
 11: set nf [open szsh.nam w]
 12: $ns namtrace-all $nf
 13:
 14: #Open the trace record file
 15: set nd [open szsh.tr w]
 16: $ns trace-all $nd
 17:
 18: #Define a 'finish' procedure
 19: proc finish {} {
 20:     global ns nf nd
 21:     $ns flush-trace
 22:     #Close the trace file
 23:     close $nf
 24:     #Close the record file
 25:     close $nd
 26:     #Execute nam on the trace file
 27:     exec nam szsh.nam &
 28:     exit 0
 29: }
 30:
 31: #Create two nodes
 32: set NODE_ShenZhen [$ns node]
 33: $NODE_ShenZhen color red
 34: $NODE_ShenZhen shape circle
 35: $NODE_ShenZhen label "ShenZhen"
 36: $NODE_ShenZhen label-color red
 37: $NODE_ShenZhen label-at up
 38:
 39: set NODE_ShangHai [$ns node]
 40: $NODE_ShangHai color blue
 41: $NODE_ShangHai shape circle
 42: $NODE_ShangHai label "ShangHai"
 43: $NODE_ShangHai label-color blue
 44: $NODE_ShangHai label-at down
 45:
 46:
 47: #Create a duplex link between the nodes
 48: $ns duplex-link $NODE_ShenZhen $NODE_ShangHai 1Mb 100ms DropTail
 49:
 50: #Monitor the queue for the link between node 2 and node 3
 51: $ns duplex-link-op $NODE_ShenZhen $NODE_ShangHai queuePos 0.5
 52: $ns duplex-link-op $NODE_ShenZhen $NODE_ShangHai color green
 53: $ns duplex-link-op $NODE_ShenZhen $NODE_ShangHai orient right
 54:
 55: #Create a UDP agent and attach it to node NODE_ShenZhen
 56: set Agent_Sender [new Agent/UDP]
 57: $Agent_Sender set agent_addr_   1000
 58: $Agent_Sender set agent_port_   100
 59: $ns attach-agent $NODE_ShenZhen $Agent_Sender
 60:
 61: ## Create a Exponential traffic source and attach it to Agent_Sender
 62: #set APP_EXP [new Application/Traffic/Exponential]
 63: #$APP_EXP set packetSize_    400
 64: #$APP_EXP set burst_time_    400ms
 65: #$APP_EXP set idle_time_     100ms
 66: #$APP_EXP set rate_          150kb
 67: #$APP_EXP attach-agent $Agent_Sender
 68:
 69: set APP_PARETO [new Application/Traffic/Pareto]
 70: $APP_PARETO set packetSize_     400
 71: $APP_PARETO set burst_time_     400ms
 72: $APP_PARETO set idle_time_      100ms
 73: $APP_PARETO set rate_           100kb
 74: $APP_PARETO set shape_          1.2
 75: $APP_PARETO attach-agent $Agent_Sender
 76:
 77: #Create a Null agent (a traffic sink) and attach it to node NODE_ShangHai
 78: set Agent_Receiver [new Agent/Null]
 79: $Agent_Receiver set dst_addr_   2000
 80: $Agent_Receiver set dst_port_   200
 81: $ns attach-agent $NODE_ShangHai $Agent_Receiver
 82:
 83: #Connect the traffic source with the traffic sink
 84: $ns connect $Agent_Sender $Agent_Receiver
 85:
 86: #Schedule events for the CBR agent
 87: $ns at 0.2 "$APP_PARETO start"
 88: $ns at 0.8 "$APP_PARETO stop"
 89:
 90: #Call the finish procedure after 5 seconds of simulation time
 91: $ns at 1.0 "finish"
 92:
 93: #Run the simulation
 94: $ns run
 95: 
时间: 2024-09-12 12:13:21

NS2网络模拟(6)-homework02.tcl的相关文章

NS2网络模拟(7)-homework03.tcl

1: #NS2_有线部分\homework03.tcl 2: 3: #Create a simulator object 4: set ns [new Simulator] 5: 6: #Define different colors for data flows 7: $ns color 1 Blue 8: $ns color 2 Red 9: 10: #Open the nam trace file 11: set nf [open szsh.nam w] 12: $ns namtrace-

NS2网络模拟(5)-homework01.tcl

1: #NS2_有线部分\homework01.tcl 2: 3: #创建两个结点,深圳到北京的TCP连接,图形将数据显示出来,计算吞吐率,画图分析 4: #tcp上层用ftp 5: #udp上层用cbr 6: #Create a simulator object 7: set ns [new Simulator] 8: 9: set nf [open SZ2BJ.nam w] 10: $ns namtrace-all $nf 11: 12: set nd [open SZ2BJ.tr w] 1

NS2网络模拟(4)-吞吐率图

1: #NS2_有线部分\ForGnuplot.plot 2: 3: #gnuplot> 4: #set xtics 0, 1, 10 5: set grid 6: set xrange [0:10] 7: set yrange [0:1000] 8: set key top left set key bottom right 9: set key box 10: set title "TCP Throughput" 11: set xlabel "Time(s)&qu

NS2网络模拟(3)-吞吐率

1: #NS2_有线部分\Throughput.awk 2: 3: BEGIN { 4: #Initialize the variable 5: init = 0; 6: i = 0; 7: } 8: 9: { 10: #Event Abbreviation Type Value 11: #%g %d %d %s %d %s %d %d.%d %d.%d %d %d 12: #Normal Event 13: #r: Receive 14: #d: Drop 15: #e: Error 16:

NS2网络模拟(2)-丢包率

1: #NS2_有线部分\LossRate.awk 2: 3: BEGIN { 4: #Initialize the variable 5: Lost = 0; #the Sum of Lost packet 6: Send = 0; #the Sum of Send packet 7: } 8: 9: { 10: #Event Abbreviation Type Value 11: #%g %d %d %s %d %s %d %d.%d %d.%d %d %d 12: #Normal Even

NS2网络模拟(1)-延迟

  1: #NS2_有线部分\EndDelay.awk 2: 3: BEGIN { 4: #Initialize the variable 5: MaxID = 0; 6: i = 0; 7: } 8: 9: { 10: #Event Abbreviation Type Value 11: #%g %d %d %s %d %s %d %d.%d %d.%d %d %d 12: #Normal Event 13: #r: Receive 14: #d: Drop 15: #e: Error 16:

NS2

NS是一种针对网络技术的源代码公开的.免费的软件模拟平台,研究人员使用它可以很容易的进行网络技术的开发,而且发展到今天,它所包含的模块已经非常丰富,几乎涉及到了网络技术的所有方面.所以,NS成了目前学术界广泛使用的一种网络模拟软件.在每年国内外发表的有关网络技术的学术论文中,利用NS给出模拟结果的文章最多,通过这种方法得出的研究结果也是被学术界所普遍认可的,此外,NS也可作为一种辅助教学的工具,已被广泛应用在了网络技术的教学方面.因此,目前在学术界和教育界,有大量的人正在使用或试图使用NS. 然

ns2 gunplot绘图-Unbuntu 里gnuplot绘图

问题描述 Unbuntu 里gnuplot绘图 NS2 运行tcl文件 出来tr和nam文件之后用awk命令追踪tr文件,找出两列数据然后用gnuplot命令想把这两列数据在坐标轴上画出来 但是之后的各种gunplot命令都提示有没有大神说一下什么情况 解决方案 http://www.linuxidc.com/Linux/2011-12/50358.htm 解决方案二: Gnuplot绘图 解决方案三: 原来我都没进入gnuplot... I am a fish

NS2安装

NS-2是OpenSource的,最早的版本是在linux/unix下运行的,后来有了windows下用vc编译运行的版本,但从2.26以后就放弃了对vc的支持,所以现在装NS2只有两条路,要么装个linux,要么就在windows下装个cygwin,然后再在cygwin上装ns2. 为了一个ns2(完成安装后不过100M)而安装linux(RH9完全安装大概在5G左右)实在不值,所以我决定用cygwin 先去http://www.cygwin.com/setup.exe 下载setup.exe