博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
NS2网络模拟(6)-homework02.tcl
阅读量:7181 次
发布时间:2019-06-29

本文共 2967 字,大约阅读时间需要 9 分钟。

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:

转载于:https://www.cnblogs.com/lanzhi/p/6468737.html

你可能感兴趣的文章
中诚信携手神州控股助推智慧城市到信用城市发展
查看>>
想用好云?先看看这10条安全建议
查看>>
数据中心电源仍然困扰着CIO
查看>>
美南方电力解围东芝西屋困局 计提损失将减一半生 “蝴蝶效应”
查看>>
自然语言处理顶级会议 EMNLP 最佳论文出炉,聚焦神经网络 (下载)
查看>>
视频矩阵的十二种特性是什么
查看>>
智能电网易遭受网络攻击的症结在哪里?
查看>>
微软推视频分析服务 片中人什么心情都知道
查看>>
Windows 10年度更新将启用Hotspot 2.0功能
查看>>
雾计算是炒作吗?
查看>>
IT企业开始为NFV热身
查看>>
Win10或成全球最大操作系统
查看>>
智能城市包罗万象 “独干”成不了气候
查看>>
乌云和漏洞盒子停业整顿:白帽子被抓是导火索?
查看>>
奇虎360将于7月18日从纽约证交所摘牌
查看>>
传软银同意以234亿英镑收购英国芯片设计厂商ARM
查看>>
防爆摄像机应用特殊 从技术入手谋发展
查看>>
去年全球钓鱼攻击达历史最高水平
查看>>
GitHub增加了代码审查、项目管理等新功能
查看>>
深圳成为乌拉圭智慧城市解决方案输出地
查看>>