NS2网络模拟(6)-homework02.tcl
转载
1: #NS2_有线部分\homework02.tcl
3: #Create a simulator object
4: set ns [new Simulator]
6: #Define different colors for data flows
10: #Open the nam trace file
11: set nf [open szsh.nam w]
14: #Open the trace record file
15: set nd [open szsh.tr w]
18: #Define a 'finish' procedure
22: #Close the trace file
24: #Close the record file
26: #Execute nam on the trace file
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
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
47: #Create a duplex link between the nodes
48: $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
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
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
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
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
83: #Connect the traffic source with the traffic sink
84: $ns connect $Agent_Sender $Agent_Receiver
86: #Schedule events for the CBR agent
87: $ns at 0.2 "$APP_PARETO start"
88: $ns at 0.8 "$APP_PARETO stop"
90: #Call the finish procedure after 5 seconds of simulation time
本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。