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...
  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-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: 
 32: #Create two nodes
 33: set NODE_ShenZhen [$ns node]
 34: $NODE_ShenZhen color red
 35: $NODE_ShenZhen shape circle
 36: $NODE_ShenZhen label "ShenZhen"
 37: $NODE_ShenZhen label-color red
 38: $NODE_ShenZhen label-at up
 39: 
 40: set NODE_ShangHai [$ns node]
 41: $NODE_ShangHai color blue
 42: $NODE_ShangHai shape circle
 43: $NODE_ShangHai label "ShangHai"
 44: $NODE_ShangHai label-color blue
 45: $NODE_ShangHai label-at down
 46: 
 47: 
 48: #Create a duplex link between the nodes
 49: $ns duplex-link $NODE_ShenZhen $NODE_ShangHai 1Mb 100ms DropTail
 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: ##TCP Traffic from NODE_ShangHai to NODE_ShenZhen
 56: #Create a TCP agent and attach it to node NODE_ShangHai
 57: set Agent_Sender_TCP [new Agent/TCP]
 58: $Agent_Sender_TCP set class_    2
 59: $Agent_Sender_TCP set fid_      1
 60: $Agent_Sender_TCP set window_   20
 61: $ns attach-agent $NODE_ShangHai $Agent_Sender_TCP
 62: # Create a FTP source and attach it to Agent_Sender_TCP
 63: set APP_FTP [new Application/FTP]
 64: $APP_FTP attach-agent $Agent_Sender_TCP
 65: $APP_FTP set type_  FTP
 66: #Create a TCPSink agent and attach it to node NODE_ShenZhen
 67: set Agent_Receiver_TCPSink [new Agent/TCPSink]
 68: $ns attach-agent $NODE_ShenZhen $Agent_Receiver_TCPSink
 69: $ns connect $Agent_Sender_TCP $Agent_Receiver_TCPSink
 70: 
 71: ##UDP Traffic from NODE_ShenZhen to NODE_ShangHai
 72: #Create a UDP agent and attach it to node NODE_ShenZhen
 73: set Agent_Sender_UDP [new Agent/UDP]
 74: $Agent_Sender_UDP set agent_addr_   1000
 75: $Agent_Sender_UDP set agent_port_   100
 76: $Agent_Sender_UDP set fid_          2
 77: $ns attach-agent $NODE_ShenZhen $Agent_Sender_UDP
 78: ## Create a Exponential traffic source and attach it to Agent_Sender_UDP
 79: #set APP_EXP [new Application/Traffic/Exponential]
 80: #$APP_EXP set packetSize_    400
 81: #$APP_EXP set burst_time_    400ms
 82: #$APP_EXP set idle_time_     100ms
 83: #$APP_EXP set rate_          150kb
 84: #$APP_EXP attach-agent $Agent_Sender_UDP
 85: #set APP_PARETO [new Application/Traffic/Pareto]
 86: #$APP_PARETO set packetSize_     400
 87: #$APP_PARETO set burst_time_     400ms
 88: #$APP_PARETO set idle_time_      100ms
 89: #$APP_PARETO set rate_           200kb
 90: #$APP_PARETO set shape_          1.2
 91: #$APP_PARETO attach-agent $Agent_Sender_UDP
 92: set APP_CBR [new Application/Traffic/CBR]
 93: $APP_CBR set packetSize_    1000
 94: $APP_CBR set burst_time_    500ms
 95: $APP_CBR set idle_time_     100ms
 96: $APP_CBR set rate_          1050kb
 97: $APP_CBR set random_        On
 98: $APP_CBR attach-agent $Agent_Sender_UDP
 99: #Create a Null agent (a traffic sink) and attach it to node NODE_ShangHai
100: set Agent_Receiver_NULL [new Agent/Null]
101: $Agent_Receiver_NULL set dst_addr_   2000
102: $Agent_Receiver_NULL set dst_port_   200
103: $ns attach-agent $NODE_ShangHai $Agent_Receiver_NULL
104: 
105: #Connect the traffic source with the traffic sink
106: $ns connect $Agent_Sender_UDP $Agent_Receiver_NULL
107: 
108: #Schedule events for the CBR agent
109: $ns at 0.2 "$APP_FTP start"
110: $ns at 0.5 "$APP_CBR start"
111: $ns at 7.5 "$APP_CBR stop"
112: $ns at 9.7 "$APP_FTP stop"
113: 
114: 
115: #Call the finish procedure after 5 seconds of simulation time
116: $ns at 10.0 "finish"
117: 
118: #Run the simulation
119: $ns run
120: 
目录
相关文章
NS2网络性能参数分析
NS2下trace文件分析网络性能参数-zhenhuaqin-ChinaUnix博客 http://blog.chinaunix.net/uid-21411227-id-1826744.html
874 0
|
SDN
NS2网络模拟(1)-延迟
1: #NS2_有线部分\EndDelay.awk 2: 3: BEGIN { 4: #Initialize the variable 5: MaxID = 0; 6: i = 0; 7: } ...
765 0
|
网络协议
NS2网络模拟(2)-丢包率
1: #NS2_有线部分\LossRate.awk 2: 3: BEGIN { 4: #Initialize the variable 5: Lost = 0; #the Sum of Lost packet 6: ...
1037 0
NS2网络模拟(3)-吞吐率
1: #NS2_有线部分\Throughput.awk 2: 3: BEGIN { 4: #Initialize the variable 5: init = 0; 6: i = 0; 7: } 8:...
789 0
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...
749 0
|
网络协议
NS2网络模拟(5)-homework01.tcl
1: #NS2_有线部分\homework01.tcl 2: 3: #创建两个结点,深圳到北京的TCP连接,图形将数据显示出来,计算吞吐率,画图分析 4: #tcp上层用ftp 5: #udp上层用cbr 6: #Create a simula...
1077 0
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...
1363 0
|
3天前
|
存储 SQL 安全
网络安全与信息安全:关于网络安全漏洞、加密技术、安全意识等方面的知识分享
【10月更文挑战第39天】在数字化时代,网络安全和信息安全成为了我们生活中不可或缺的一部分。本文将介绍网络安全漏洞、加密技术和安全意识等方面的内容,帮助读者更好地了解网络安全的重要性,并提供一些实用的技巧和方法来保护自己的信息安全。
14 2
|
4天前
|
安全 网络安全 数据安全/隐私保护
网络安全与信息安全:关于网络安全漏洞、加密技术、安全意识等方面的知识分享
【10月更文挑战第38天】本文将探讨网络安全与信息安全的重要性,包括网络安全漏洞、加密技术和安全意识等方面。我们将通过代码示例和实际操作来展示如何保护网络和信息安全。无论你是个人用户还是企业,都需要了解这些知识以保护自己的网络安全和信息安全。
|
3天前
|
存储 安全 网络安全
云计算与网络安全:探索云服务中的信息安全策略
【10月更文挑战第39天】随着云计算的飞速发展,越来越多的企业和个人将数据和服务迁移到云端。然而,随之而来的网络安全问题也日益突出。本文将从云计算的基本概念出发,深入探讨在云服务中如何实施有效的网络安全和信息安全措施。我们将分析云服务模型(IaaS, PaaS, SaaS)的安全特性,并讨论如何在这些平台上部署安全策略。文章还将涉及最新的网络安全技术和实践,旨在为读者提供一套全面的云计算安全解决方案。

热门文章

最新文章