networksimulationandanalysis---usingns2内容摘要:
ad_flatgrid $opt(x) $opt(y) creategod [expr $opt(nn) + 2] 2 for HA and FA set temp { }。 hierarchical addresses for {set i 0} {$i $num_wired_nodes} {incr i} { set W($i) [$ns_ node [lindex $temp $i]] } $ns_ nodeconfig mobileIP ON \ adhocRouting DSDV \ llType LL \ macType Mac/802_11 \ ifqType Queue/DropTail/PriQueue \ ifqLen 50 \ antType Antenna/OmniAntenna \ propType Propagation/TwoRayGround \ phyType Phy/WirelessPhy \ channelType Channel/WirelessChannel \ topoInstance $topo \ wiredRouting ON \ agentTrace ON \ routerTrace OFF \ macTrace OFF Create Home Agent and Foreign Agent set HA [$ns_ node ] set FA [$ns_ node ] $HA set X_ $HA set Y_ $HA set Z_ $FA set X_ $FA set Y_ $FA set Z_ create links between wired and BaseStation nodes $ns_ duplexlink $W(0) $W(1) 5Mb 2ms DropTail $ns_ duplexlink $W(1) $HA 5Mb 2ms DropTail $ns_ duplexlink $W(1) $FA 5Mb 2ms DropTail $ns_ duplexlinkop $W(0) $W(1) orient down $ns_ duplexlinkop $W(1) $HA orient leftdown $ns_ duplexlinkop $W(1) $FA orient rightdown create a mobilenode (in the domain of the HA) that is moving between HA and FA. $ns_ nodeconfig wiredRouting OFF set MH [$ns_ node ] set HAaddress [AddrParams addr2id [$HA nodeaddr]] [$MH set regagent_] set home_agent_ $HAaddress $MH set Z_ $MH set Y_ $MH set X_ MH starts to move towards FA $ns_ at $MH setdest goes back to HA $ns_ at $MH setdest Define initial node position in nam $ns_ initial_node_pos $MH 20 set tcp1 [new Agent/TCP] $tcp1 set class_ 2 set sink1 [new Agent/TCPSink] $ns_ attachagent $W(0) $tcp1 $ns_ attachagent $MH $sink1 $ns_ connect $tcp1 $sink1 set ftp1 [new Application/FTP] $ftp1 attachagent $tcp1 $ns_ at $opt(ftp1start) $ftp1 start $ns_ at $opt(stop).0 $MH reset。 $ns_ at $opt(stop).0 $HA reset。 $ns_ at $opt(stop).0 $FA reset。 $ns_ at $opt(stop).0002 puts \NS EXITING...\。 $ns_ halt $ns_ at $opt(stop).0001 finish proc finish {} { global ns_ tracefd namtrace close $tracefd close $namtrace exec rm f exec awk f exec xgraph amp。 exec nam amp。 } puts Starting Simulation... $ns_ run How to measure the loss rate, delay, jitter, throughput? 1. nsBench 2. Write the tcl script yourself set ns [new Simulator] 針對不同的資料流定義不同的顏色,這是要給 NAM用的 $ns color 1 Blue $ns color 2 Red 開啟一個 NAM 記錄檔 set nf [open w] $ns namtraceall $nf 開啟一個模擬過程記錄檔,用來記錄封包傳送的過程 set nd [open w] $ns traceall $nd 定義一個結束的程序 proc finish {} { global ns nf nd $ns flushtrace close $nf close $nd 以背景執行的方式去執行 NAM exec nam amp。 exit 0 } 產生傳輸節點 set s1 [$ns node] set s2 [$ns node] 產生路由器節點 set r [$ns node] 產生資料接收節點 set d [$ns node] $ns duplexlink $s1 $r 2Mb 10ms DropTail $ns duplexlink $s2 $r 2Mb 10ms DropTail $ns duplexlink $r $d 20ms DropTail 設定 r到 d之間的 Queue Limit為 10個封包大小 $ns queuelimit $r $d 10 設定節點的位置,這是要給 NAM用的 $ns duplexlinkop $s1 $r orient rightdown $ns duplexlinkop $s2 $r orient rightup $ns duplexlinkop $r $d orient right 觀測 r到 d之間 queue的變化,這是要給 NAM用的 $ns duplexlinkop $r $d queuePos 建立一條 TCP的連線 set tcp [new Agent/TCP] $ns attachagent $s1 $tcp set sink [new Agent/TCPSink] $ns attachagent $d $sink $ns connect $tcp $sink 在 NAM中, TCP的連線會以藍色表示 $tcp set fid_ 1 在 TCP連線之上建立 FTP應用程式 set ftp [new Application/FTP] $ftp attachagent $tcp $ftp set type_ FTP 建立一條 UDP的連線 set udp [new Agent/UDP] $ns attachagent $s2 $udp set null [new Agent/Null] $ns attachagent $d $null $ns connect $udp $null 在 NAM中, UDP的連線會以紅色表示 $udp set fid_ 2 在 UDP連線之上建立 CBR應用程式 set cbr [new Application/Traffic/CBR] $cbr attachagent $udp $cbr set type_ CBR 設定傳送封包的大小為 1000 byte $cbr set packet_size_ 1000 設定傳送的速率為 1Mbps $cbr set rate_ 1mb $cbr set random_ false 設定 FTP和 CBR資料傳送開始和結束時間 $ns at $cbr start $ns at $ftp start $ns at $ftp stop $ns at $cbr stop 結束 TCP的連線 (不一定需要寫下面的程式碼來實際結束連線 ) $ns at $ns detachagent $s1 $tcp。 $ns detachagent $d $sink 在模擬環境中, 5秒後去呼叫 finish來結束模擬 (這樣要注意模擬環境中 的 5秒並不一定等於實際模擬的時間 $ns at finish 執行模擬 $ns run + 1 2 cbr 1000 2 0 0 1 2 cbr 1000 2 0 0 + 1 2 cbr 1000 2 1 1 1 2 cbr 1000 2 1 1 r 1 2 cbr 1000 2 0 0 + 2 3 cbr 1000 2 0 0 2 3 cbr 1000 2 0 0 + 1 2 cbr 1000 2 2 2 1 2 cbr 1000 2 2 2 r 1 2 cbr 1000 2 1 1 + 2 3 cbr 1000 2 1 1 2 3 cbr 1000 2 1 1 + 1 2 cbr 1000 2 3 3 1 2 cbr 1000 2 3 3 r 1 2 cbr 1000 2 2 2 + 2 3 cbr 1000 2 2 2 2 3 cbr 1000 2 2 2 + 1 2 cbr 1000 2 4 4 1 2 cbr 1000 2 4 4 r 1 2 cbr 1000 2 3 3 + 2 3 cbr 1000 2 3 3 2 3 cbr 1000 2 3 3 r 2 3 cbr 1000 2 0 0 ……………………………………………… sequence_number: 對於同一條 flow而言 , 這個 flow所產生的第一個 packet,它的 sequence number 就是 0,第二個 flow所產生的 packet,就是 1,以此類推 packet_id: 這是對於整個系統而言 , 整個系統中所產生的第一個 packet, 它的 packet id 就是 0,第二個 packet,就是 1, 以此類推 這是測量 CBR封包端點到端點間延遲時間的 awk程式 BEGIN { 程式初始化,設定一變數以記錄目前最高處理封包的 ID。 highest_packet_id = 0。 } { action = $1。 time = $2。 from = $3。 to = $4。 type = $5。 pktsize = $6。 flow_id = $8。 src = $9。 dst。networksimulationandanalysis---usingns2
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。
用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。