日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ns2相关学习——tcl脚本编写(1)

發(fā)布時間:2024/8/23 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ns2相关学习——tcl脚本编写(1) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

新建一個仿真實例:

set ns [new Simulator]

為了讓nam文件和trace文件有地方可以依托,我們要打開.nam文件進行寫入,并且使用句柄nf

set nf [open out.nam w] $ns namtrace-all $nf


設置拓撲圖

1、設置節(jié)點的腳本語言:建了兩個節(jié)點,叫n0,n1

set n0 [$ns node] set n1 [$ns node]

2、建立一個鏈接

$ns duplex-link $n0 $n1 1Mb 10ms DropTail

該行告訴模擬器對象將節(jié)點n0和n1用帶寬1Megabit的雙工鏈路連接,延遲10ms、DropTail隊列


發(fā)送數(shù)據(jù)

1、為了能真正的發(fā)送數(shù)據(jù),要設置“代理”——n0發(fā)送數(shù)據(jù)的代理和n1接收數(shù)據(jù)的代理

首先,設置發(fā)送數(shù)據(jù)的代理

#Create a UDP agent and attach it to node n0 set udp0 [new Agent/UDP] $ns attach-agent $n0 $udp0# Create a CBR traffic source and attach it to udp0 set cbr0 [new Application/Traffic/CBR] $cbr0 set packetSize_ 500 $cbr0 set interval_ 0.005 $cbr0 attach-agent $udp0

腳本創(chuàng)建一個UDP代理并將其附加到節(jié)點n0,然后將一個CBR流量生成器附加到UDP代理。數(shù)據(jù)包大小被設置為500字節(jié),并且每0.005秒發(fā)送一個數(shù)據(jù)包(即每秒200個數(shù)據(jù)包)。


然后 設置接收數(shù)據(jù)的代理

set null0 [new Agent/Null] $ns attach-agent $n1 $null0

以上腳本創(chuàng)建一個Null代理,作為流量接收器并將其附加到節(jié)點n1。


為了能互相發(fā)送數(shù)據(jù),要將兩個代理連接起來,使用以下語句:

$ns connect $udp0 $null0

然后,我們要告訴CBR(發(fā)送數(shù)據(jù)的那個)什么時候開始發(fā)送,什么時候結束發(fā)送

$ns at 0.5 "$cbr0 start" $ns at 4.5 "$cbr0 stop"

上面語句就是說,在0.5s的時候開始發(fā)送,在4.5s的時候結束發(fā)送



下面是整個完整的簡單的TCL腳本語言:

#Create a simulator object set ns [new Simulator]#Open the nam trace file set nf [open out.nam w] $ns namtrace-all $nf#Define a 'finish' procedure proc finish {} {global ns nf$ns flush-trace #Close the trace fileclose $nf #Execute nam on the trace fileexec nam out.nam &exit 0 }#Create two nodes set n0 [$ns node] set n1 [$ns node]#Create a duplex link between the nodes $ns duplex-link $n0 $n1 1Mb 10ms DropTail#Create a UDP agent and attach it to node n0 set udp0 [new Agent/UDP] $ns attach-agent $n0 $udp0# Create a CBR traffic source and attach it to udp0 set cbr0 [new Application/Traffic/CBR] $cbr0 set packetSize_ 500 $cbr0 set interval_ 0.005 $cbr0 attach-agent $udp0#Create a Null agent (a traffic sink) and attach it to node n1 set null0 [new Agent/Null] $ns attach-agent $n1 $null0#Connect the traffic source with the traffic sink $ns connect $udp0 $null0 #Schedule events for the CBR agent $ns at 0.5 "$cbr0 start" $ns at 4.5 "$cbr0 stop" #Call the finish procedure after 5 seconds of simulation time $ns at 5.0 "finish"#Run the simulation $ns run


總結

以上是生活随笔為你收集整理的ns2相关学习——tcl脚本编写(1)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。