【正文】
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一個(gè)最簡(jiǎn)單的 ns腳本的啟動(dòng)過(guò)程 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 啟動(dòng)過(guò)程 0 ? 當(dāng)命令行運(yùn)行 ns,會(huì)創(chuàng)建 3個(gè)對(duì)象 _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 啟動(dòng)過(guò)程 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)建一個(gè)Simulator對(duì)象,并調(diào)用它的 init函數(shù)進(jìn)行初始化 啟動(dòng)過(guò)程 1 ? Simulator instproc init args {…} tcl/lib/ Simulator instproc init args { …… $self create_packetformat $self usescheduler Calendar $self set nullAgent_ [new Agent/Null] $self setaddressformat def if {[lindex $args 0] == multicast} { $self multicast $args } eval $self next $args } 這個(gè)還未找到代碼位置 (找到了 ),可以猜想是創(chuàng)建數(shù)據(jù)包的頭標(biāo)對(duì)應(yīng)的數(shù)據(jù)結(jié)構(gòu),創(chuàng)建對(duì)象 _o5,類型為 PacketHeaderManager 創(chuàng)建對(duì)象 _o6,類型為Scheduler/Calender,一個(gè)非常重要的類,單線程的 ns能模擬多節(jié)點(diǎn)的網(wǎng)絡(luò),就是通過(guò)它來(lái)調(diào)度。s nodelist in C++ space $self addnode $node [$node id] set the nodeid in c++ Node ratul $node nodeid [$node id] $node set ns_ $self $self checknodenum return $node } 代碼沒(méi)有找到。 slot = getnxt(nullagent)。該函數(shù)不可見(jiàn),是二進(jìn)制的 對(duì)應(yīng)類的 init{} 基類的 init{},最終調(diào)用SplitObject的 init{} $self createshadow $args,進(jìn)入 c++代碼 .。這里通過(guò) attach把 agent加入到 每個(gè)路由模塊的 路由表。其實(shí)該模塊的功能是計(jì)算路由,而執(zhí)行路由是由 Classifier進(jìn)行的 路由的執(zhí)行 啟動(dòng)過(guò)程 3☆ ? $ns duplexlink $n0 $n1 1Mb 10ms DropTail tcl/lib/ Simulator instproc duplexlink { n1 n2 bw delay type args } { $self instvar link_ set i1 [$n1 id] set i2 [$n2 id] if [info exists link_($i1:$i2)] { $self removenamlinkconfig $i1 $i2 } eval $self simplexlink $n1 $n2 $bw $delay $type $args eval $self simplexlink $n2 $n1 $bw $delay $type $args Modified by GFR for nixvector routing if { [Simulator set nixrouting] } { I