【正文】
NS 的 網絡功能實體結構及類結構 任三陽 把 N門時髦的技術掛在嘴邊不如將一門過時的技術記在心里。 ——BBS A poor framework is much better than nothing. ——kkzhou outline ? 1預修知識 ? 2一個最簡單的 ns仿真的啟動過程 ? 3Ns的網絡實體結構和類結構 1預修知識 ? C++、 Tcl、 OTcl的語法 – – – 《 ns與網絡模擬 》 ? 面向對象的思想:虛擬函數,動態(tài)創(chuàng)建機制 ? Ns的安裝和簡單仿真操作 (論壇上有 ) ? Ns的開發(fā)工具: gdb和 tcldebug(非常簡單 ) ? Ns的分裂對象模型和 tclcl(非常重要而且很難,主要原理是動態(tài)創(chuàng)建機制 ) 要學透, 注意區(qū)分類和對象 ,發(fā)現好多問題都是因為 OTcl理解不透造成的。 一個仿真例子的操作過程 1. 寫場景 tcl腳本 , 2. 運行 ns 3. 察看仿真過程,是否有錯或者是否與預想中的大致相似 nam 4. 分析仿真數據 ,可以用各種工具 set ns [new Simulator] set tracefd [ open w] set namfd [open w] $ns traceall $tracefd $ns namtraceall $namfd set n0 [$ns node] set n1 [$ns node] $ns duplexlink $n0 $n1 1Mb 10ms DropTail set tcp [new Agent/TCP] set snk [new Agent/TCPSink] $ns attachagent $n0 $tcp $ns attachagent $n1 $snk set ftp [new Application/FTP] $ftp attachagent $tcp $ns connect $tcp $snk $ns at $ftp start $ns at ―exit 0 $ns run 例子的仿真結果 + 0 1 tcp 1040 0 7 14 0 1 tcp 1040 0 7 14 + 0 1 tcp 1040 0 8 15 r 1 0 ack 40 0 4 11 + 0 1 tcp 1040 0 9 16 V t * v a 0 A t * n 1 p 0 o 0xffffffff c 31 a 1 A t * h 1 m 2147483647 s 0 n t * a 0 s 0 S UP v circle c black i black n t * a 1 s 1 S UP v circle c black i black l t * s 0 d 1 S UP r 1000000 D c black + t s 0 d 1 p tcp e 40 c 0 i 0 a 0 x { 0 null} t s 0 d 1 p tcp e 40 c 0 i 0 a 0 x { 0 null} h t s 0 d 1 p tcp e 40 c 0 i 0 a 0 x { 1 null} r t s 0 d 1 p tcp e 40 c 0 i 0 a 0 x { 0 null} + t s 1 d 0 p ack e 40 c 0 i 1 a 0 x { 0 null} 2一個最簡單的 ns腳本的啟動過程 set ns [new Simulator] set n0 [$ns node] set n1 [$ns node] $ns duplexlink $n0 $n1 1Mb 10ms DropTail set tcp [new Agent/TCP] set snk [new Agent/TCPSink] $ns attachagent $n0 $tcp $ns attachagent $n1 $snk set ftp [new Application/FTP] $ftp attachagent $tcp $ns connect $tcp $snk proc finish {} { exit 0 } $ns at $ftp start $ns at finish $ns run 啟動過程 0 ? 當命令行運行 ns,會創(chuàng)建 3個對象 _o1, _o2, _o3 ? _o1和 _o2是 RNG, _o3是 Import (tclcl/tcl) simulator:~/ins/$ ns % set a [new Application/FTP] _o4 % _o1 info class RNG % _o2 info class RNG % _o3 info class Import % _o4 info class Application/FTP 啟動過程 1 ? set ns [new Simulator] tclcl/ proc new { className args } { set o [SplitObject getid] if [catch $className create $o $args msg] { if [string match __FAILED_SHADOW_OBJECT_ $msg] { The shadow object failed to be allocated. delete $o return } global errorInfo error class $className: constructor failed: $msg $errorInfo } return $o } ―Simulator create 4‖ 該操作創(chuàng)建一個Simulator對象,并調用它的 init函數進行初始化 啟動過程 1 ? Simulator instproc init args {…} tcl/lib/ Simulator instproc init ar