---------- Forwarded message ---------- From: xiue ns2 <xiue...@gmail.com> Date: 2010/10/31 Subject: Please help: ns2 p2p WLAN application code compile error To: ns-users@isi.edu
Dear all, I want to do a TCP simulation to evaluate TCP performance, below is the source code which I download from network, but I just can't compile it correct, when I run the command with "ns wireless2.tcl 11 20" program shown the error: " warning: Route to base_stn not known: dropping pkt ns: finish: wrong # args: should be "set varName ?newValue?" while compiling "set goodput [expr [$tcp0 set ack_]*[$tcp0 set packetSize_]*8/$now/1000000.0] #" (compiling body of proc "finish", line 4) invoked from within ----------source code------------------ # ------------------------ # Define options # ------------------------ set opt(chan) [new Channel/WirelessChannel] ;# Channel type set opt(prop) Propagation/TwoRayGround ;# Radio-propagation model set opt(netif) Phy/WirelessPhy ;# Network interface type set opt(mac) Mac/802_11 ;# MAC type set opt(ifq) Queue/DropTail/PriQueue ;# Interface queue type set opt(ll) LL ;# Link layer type set opt(ant) Antenna/OmniAntenna ;# Antenna model set opt(ifqlen) 50 ;# Max packet in ifq set opt(nn) 1 ;# Number of mobilenodes set opt(adhocRouting) DSDV ;# Routing protocol set opt(x) 500 ;# x coordinate of topology set opt(y) 500 ;# y coordinate of topology set opt(seed) 0 ;# Seed for random number gen. set opt(stop) 60 ;# 設定結束時間 set opt(ftp0-start) 0.0 ;# 設定 FTP 的開始時間 set num_wired_nodes 2 ;# 設定 Wireless node 的個數 set num_ap_nodes 1 ;# 設定 AP (Access Point)的個數 #Suggestion by http://web.syr.edu/~dchen02/FAQ.txt Phy/WirelessPhy set freq_ 2.4e+9 ;# frequency is 2.4 GHz Phy/WirelessPhy set Pt_ 3.3962527e-2 ;# transmit power Phy/WirelessPhy set RXThresh_ 2.1003e-09 ;# Receive sensitivity, 40 meters. Phy/WirelessPhy set CSThresh_ 4.14873e-10 ;# 90 meters Mac/802_11 set RTSThreshold_ 3000 ;# < 256 bytes, no RTS/CTS set datarate 11 if {$datarate == "2"} { puts "FHSS (IEEE802.11)" Mac/802_11 set SlotTime_ 0.000050 ;# 50 us Mac/802_11 set SIFS_ 0.000028 ;# 28 us Mac/802_11 set PreambleLength_ 0 ;# no preamble Mac/802_11 set PLCPHeaderLength_ 128 ;# 128 bits Mac/802_11 set PLCPDataRate_ 1.0e6 ;# 1 Mbps Mac/802_11 set dataRate_ 2.0e6 ;# 2 Mbps Mac/802_11 set basicRate_ 1.0e6 ;# 1 Mbps } elseif {$datarate == "11"} { puts "DSSS (IEEE802.11b)" Mac/802_11 set SlotTime_ 0.000020 ;# 20 us Mac/802_11 set SIFS_ 0.000010 ;# 10 us Mac/802_11 set PreambleLength_ 144 ;# 144 bit Mac/802_11 set PLCPHeaderLength_ 48 ;# 48 bits Mac/802_11 set PLCPDataRate_ 1.0e6 ;# 1 Mbps Mac/802_11 set dataRate_ 11.0e6 ;# 11 Mbps Mac/802_11 set basicRate_ 1.0e6 ;# 1 Mbps } elseif {$datarate == "54"} { puts "DSSS (IEEE802.11g)" Mac/802_11 set SlotTime_ 0.000009 ;# 9 us Mac/802_11 set SIFS_ 0.000016 ;# 16 us Mac/802_11 set PreambleLength_ 96 ;# 96 bit Mac/802_11 set PLCPHeaderLength_ 40 ;# 40 bits Mac/802_11 set PLCPDataRate_ 6.0e6 ;# 6 Mbps Mac/802_11 set dataRate_ 54.0e6 ;# 54 Mbps Mac/802_11 set basicRate_ 1.0e6 ;# 1 Mbps } else { puts "Error datarate configuration." } # ============================================================================ # 副程式 proc finish {} { global ns_ tracefd namtrace tcp0 datarate set now [$ns_ now] set goodput [expr [$tcp0 set ack_]*[$tcp0 set packetSize_]*8/$now/1000000.0] #; 計算 TCP 的 Goodput puts [format "goodput = %.2f Mbps (%.2f %s)" $goodput [expr $goodput/$datarate*100] %] puts "" close $tracefd close $namtrace } # 讀入外部參數 proc getopt {argc argv} { global opt lappend optlist nn for {set i 0} {$i < $argc} {incr i} { set opt($i) [lindex $argv $i] } } getopt $argc $argv #Example: ns tcp80211-wlan.tcl 54 set datarate $opt(0) # ============================================================================ # 產生模擬物件 set ns_ [new Simulator] puts "Seeding Random number generator with $opt(seed), Random [ns-random 0]" # 使用 Hierarchial addressing 的方式定址 (2 個 domain,第 1 個 domain 有 2 個 cluster,第 2 個 domain 有 1 個 # cluster。每個 cluster 中的 node 個數分別為 1、1、$num_ap_nodes +$opt(nn)) $ns_ node-config -addressType hierarchical AddrParams set domain_num_ 2 ;# number of domains lappend cluster_num 2 1 ;# number of clusters in each domain AddrParams set cluster_num_ $cluster_num lappend eilastlevel 1 1 [expr $num_ap_nodes +$opt(nn)] ;# number of nodes in each cluster AddrParams set nodes_num_ $eilastlevel ;# of each domain set tracefd [open wireless-out.tr w] set namtrace [open wireless-out.nam w] $ns_ trace-all $tracefd $ns_ namtrace-all-wireless $namtrace $opt(x) $opt(y) # Create topography object set topo [new Topography] # Define topology $topo load_flatgrid $opt(x) $opt(y) # Create God create-god [expr $opt(nn) + $num_ap_nodes] # 建立 Wired node (先設定 Wired node,接著再設定 Wireless node,一定要依此步驟進行) set temp {0.0.0 0.1.0} ;# hierarchical addresses for wired domain for {set i 0} {$i < $num_wired_nodes} {incr i} { set W($i) [$ns_ node [lindex $temp $i]] } # Configure for base-station node $ns_ node-config -adhocRouting $opt(adhocRouting) \ -llType $opt(ll) \ -macType $opt(mac) \ -ifqType $opt(ifq) \ -ifqLen $opt(ifqlen) \ -antType $opt(ant) \ -propType $opt(prop) \ -phyType $opt(netif) \ -channel $opt(chan) \ -topoInstance $topo \ -wiredRouting ON \ -agentTrace ON \ -mobileIP ON \ -routerTrace OFF \ -macTrace OFF # 設定 AP set temp {1.0.0 1.0.1} ;# hier address to be used for wireless domain set AP(0) [$ns_ node [lindex $temp 0]] $AP(0) random-motion 0 ;# disable random motion # 設定 AP 的位置 $AP(0) set X_ 0.0 $AP(0) set Y_ 0.0 $AP(0) set Z_ 0.0 # 設定 mobile node $ns_ node-config -wiredRouting OFF for {set j 0} {$j < $opt(nn)} {incr j} { set node_($j) [ $ns_ node [lindex $temp [expr $j+1]] ] $node_($j) base-station [AddrParams addr2id [$AP(0) node-addr]] # 設定 Mobile node 的位置 $node_($j) set X_ [expr 30.0 + $j * 30.0] $node_($j) set Y_ 0.0 $node_($j) set Z_ 0.0 } # 設定 Wired node 和 AP 之間的連線 $ns_ duplex-link $W(0) $W(1) 100Mb 2ms DropTail $ns_ duplex-link $W(1) $AP(0) 45Mb 10ms DropTail $ns_ queue-limit $W(0) $W(1) 64 $ns_ queue-limit $W(1) $AP(0) 64 # 設定 TCP 連線 set tcp0 [new Agent/TCP/Reno] ;# 指定 TCP 版本為 TCP Reno set sink0 [new Agent/TCPSink] $ns_ attach-agent $W(0) $tcp0 $ns_ attach-agent $node_(0) $sink0 $ns_ connect $tcp0 $sink0 ;# 建立 End-to-End 的連線 $tcp0 set window_ 128 ;# Initial window size 為 128 packets $tcp0 set packetSize_ 1400 ;# Packet size 為 1400 bytes $tcp0 set maxburst_ 2 ;# 指定收到 1 個 ACK 最多能連續送出的封包個數是 2 個 packet set ftp0 [new Application/FTP] ;# 指定 application layer traffic generator $ftp0 attach-agent $tcp0 $ns_ at $opt(ftp0-start) "$ftp0 start" ;# 排定產生 FTP traffic 的開始時間 # Define initial node position in nam for {set i 0} {$i < $opt(nn)} {incr i} { # 20 defines the node size in nam, must adjust it according to your scenario # The function must be called after mobility model is defined $ns_ initial_node_pos $node_($i) 20 } # 排定執行的時間 # Tell all nodes when the simulation ends for {set i } {$i < $opt(nn) } {incr i} { $ns_ at $opt(stop).0 "$node_($i) reset"; } $ns_ at $opt(stop).0 "$AP(0) reset"; $ns_ at $opt(stop).0 "finish" $ns_ at $opt(stop).0002 "puts \"NS EXITING...\" ; $ns_ halt" puts "Starting Simulation..." $ns_ run ---------------------source code end--------------------- so what's the problem with this code? please help to give me some suggestion, thanks in advance. best regards xiue