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]
13: $ns namtrace-all $nd
14:
15: proc finish {} {
16: global ns nf nd
17: $ns flush-trace
18: close $nf
19: close $nd
20: exec nam SZ2BJ.nam &
21: exit 0
22: }
23:
24:
25: #$ns node-config -addressType hierarchical
26:
27: #Create two nodes
28: set Node_Shenzhen [$ns node]
29: $Node_Shenzhen color red
30: $Node_Shenzhen shape hexagon
31: #$Node_Shenzhen label "ShenZhen"
32:
33: set Node_Beijing [$ns node]
34: $Node_Beijing color red
35: #$Node_Beijing lable "BeiJing"
36: #Create a duplex link between the nodes
37: $ns duplex-link $Node_Shenzhen $Node_Beijing 1Mb 500ms DropTail
38:
39: #$ns queue-limit $2 $n3 10
40:
41: #TCP
42: set Agent_Sender [new Agent/TCP]
43: $Agent_Sender set class_ 2
44: $Agent_Sender set addr_ 192.168.1.100
45: $Agent_Sender set dst_addr- 192.168.1.200
46: $Agent_Sender set size_ 1492
47: $Agent_Sender set defttl_ 256
48: $ns attach-agent $Node_Shenzhen $Agent_Sender
49:
50: set Agent_Receiver [new Agent/NULL]
51: $ns attach-agent $Node_Beijing $Agent_Receiver
52:
53: $ns connect $Agent_Sender $Agent_Receiver
54:
55: #Simulated Application
56: set App_Ftp [new Application/FTP]
57: $App_Ftp attach-agent $Agent_Sender
58:
59:
60: #start and stop FTP
61: $ns at 1.0 "App_Ftp start"
62: $ns at 4.0 "App_Ftp stop"
63:
64: $ns at 5.0 "finish"
65:
66: $ns run
67:
本文来自博客园,作者:方倍工作室,转载请注明原文链接:https://www.cnblogs.com/txw1958/archive/2011/10/13/2210126.html