?? 3ss_withoutbg.tcl
字號:
# Copyright (c) 2006 Korea Advanced Institute of Science and Technology,# All rights reserved.# # Permission to use, copy, modify, and distribute this software and# its documentation for any purpose, without fee, and without# written agreement is hereby granted, provided that the above# copyright notice and the following two paragraphs appear in all# copies of this software.# # IN NO EVENT SHALL KOREA ADVANCED INSTITUTE OF SCIENCE AND TECHNOLOGY BE# LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR# CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND# ITS DOCUMENTATION, EVEN IF KOREA ADVANCED INSTITUTE OF SCIENCE AND# TECHNOLOGY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.# # KOREA ADVANCED INSTITUTE OF SCIENCE AND TECHNOLOGY SPECIFICALLY DISCLAIMS# ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE# SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND# KOREA ADVANCED INSTITUTE OF SCIENCE AND TECHNOLOGY HAS NO OBLIGATION TO# PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.# # Code contributed by Seungwoon Kim, swkim@cnlab.kaist.ac.kr, http://cnlab.kaist.ac.kr/~swkim## Copyright (c) 1997 Regents of the University of California.# All rights reserved.## Redistribution and use in source and binary forms, with or without# modification, are permitted provided that the following conditions# are met:# 1. Redistributions of source code must retain the above copyright# notice, this list of conditions and the following disclaimer.# 2. Redistributions in binary form must reproduce the above copyright# notice, this list of conditions and the following disclaimer in the# documentation and/or other materials provided with the distribution.# 3. All advertising materials mentioning features or use of this software# must display the following acknowledgement:# This product includes software developed by the Computer Systems# Engineering Group at Lawrence Berkeley Laboratory.# 4. Neither the name of the University nor of the Laboratory may be used# to endorse or promote products derived from this software without# specific prior written permission.## THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF# SUCH DAMAGE.## wireless2.tcl# simulation of a wired-cum-wireless scenario consisting of 2 wired nodes# connected to a wireless domain through a base-station node.# ======================================================================# Define options# ======================================================================set opt(chan) Channel/WirelessChannel ;# channel typeset opt(prop) Propagation/TwoRayGround ;# radio-propagation modelset opt(netif) Phy/WirelessPhy ;# network interface typeset opt(mac) Mac/802_16 ;# MAC typeset opt(ifq) Queue/DropTail/PriQueue ;# interface queue typeset opt(ll) LL ;# link layer typeset opt(ant) Antenna/OmniAntenna ;# antenna modelset opt(ifqlen) 50 ;# max packet in ifqset opt(adhocRouting) RAgent_802_16 ;# routing protocolset opt(cp) "" ;# connection pattern fileset opt(sc) "" ;# node movement file. set opt(x) 670 ;# x coordinate of topologyset opt(y) 670 ;# y coordinate of topologyset opt(seed) 0.0 ;# seed for random number gen.set num_wired_nodes 2set num_bs_nodes 1set opt(nn) 3 ;# number of mobilenodesset num_tcp_flows 3 ;# number of mobilenodesset dumpinterval 1.0 set opt(stop) 80 ;# time to stop simulation#puts $opt(stop)# ============================================================================# check for boundary parameters and random seedif { $opt(x) == 0 || $opt(y) == 0 } { puts "No X-Y boundary values given for wireless topology\n"}if {$opt(seed) > 0} { puts "Seeding Random number generator with $opt(seed)\n" ns-random $opt(seed)}source $env(NS_HOME)/ns-2.28/ieee802_16/tcl/lib/ns-mac802_16-lib.tclsource $env(NS_HOME)/ns-2.28/ieee802_16/tcl/lib/ns-mac802_16-defaults.tclMac/802_16 set DL_bandwidth_ 20.0e6 ;# Downlink tx_rate 20MbpsMac/802_16 set UL_bandwidth_ 20.0e6 ;# Uplink tx_rate 20MbpsMac/802_16 set UplinkRatio_ 0.5 ;# Ratio of uplink slots in a frameMac/802_16 set MiniSlotLength_ 2 ;# Slot Length in Bytes# create simulator instanceset ns_ [new Simulator]# set up for hierarchical routing$ns_ node-config -addressType hierarchicalAddrParams set domain_num_ 2 ;# number of domains#lappend cluster_num 2 1 ;# number of clusters in each domainlappend cluster_num $num_wired_nodes 1 ;# number of clusters in each domainAddrParams set cluster_num_ $cluster_num#lappend eilastlevel 1 1 4 ;# number of nodes in each cluster for {set i 0} {$i < $num_wired_nodes} {incr i} { lappend eilastlevel 1}lappend eilastlevel [expr $opt(nn) + 1] ;# number of nodes in each cluster AddrParams set nodes_num_ $eilastlevel ;# of each domain# open files to record dataset tracefd [open ex1.tr w]#set namtrace [open ex1.nam w]$ns_ trace-all $tracefd#$ns_ namtrace-all-wireless $namtrace $opt(x) $opt(y)#set tcp_status_record_file(1) [open TCP1_STATUS_RECORD_EVERYSECOND w]#set tcp_status_record_file(2) [open TCP2_STATUS_RECORD_EVERYSECOND w]#set tcp_status_record_file(3) [open TCP3_STATUS_RECORD_EVERYSECOND w]for {set i 1} {$i <= $num_tcp_flows} {incr i} { set tcp_status_record_file($i) [open ITCP${i}STATUS.dat w]}# Create topography objectset topo [new Topography]# define topology$topo load_flatgrid $opt(x) $opt(y)# create Godcreate-god [expr $opt(nn) + $num_bs_nodes]set ms_ [new Scheduler_802_16]#create wired nodes#set temp {0.0.0 0.1.0} ;# hierarchical addresses for wired domainfor {set i 0} {$i < $num_wired_nodes} {incr i} { set W($i) [$ns_ node 0.${i}.0] }#debug 1# 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) \ -channelType $opt(chan) \ -topoInstance $topo \ -wiredRouting ON \ -agentTrace ON \ -routerTrace OFF \ -macTrace OFF#create base-station node#Queue/PerConnectionQ set num_queue_ 32#set temp {1.0.0 1.0.1 1.0.2 1.0.3} ;# hier address to be used for wireless ;# domain#set BS(0) [$ns_ node [lindex $temp1 0]]set BS(0) [$ns_ node 1.0.0]$BS(0) random-motion 0 ;# disable random motion#provide some co-ord (fixed) to base station node$BS(0) set X_ 1.0$BS(0) set Y_ 2.0$BS(0) set Z_ 0.0# create mobilenodes in the same domain as BS(0) # note the position and movement of mobilenodes is as defined# in $opt(sc)#configure for mobilenodes$ns_ node-config -wiredRouting OFFfor {set j 0} {$j < $opt(nn)} {incr j} {# set node_($j) [ $ns_ node [lindex $temp1 [expr $j+1]] ] set node_address 1.0.[expr $j+1] set node_($j) [ $ns_ node $node_address ] $node_($j) base-station [AddrParams addr2id \ [$BS(0) node-addr]]}Queue set limit_ 30#create links between wired and BS nodes$ns_ duplex-link $BS(0) $W(0) 10Mb 10ms DropTail$ns_ duplex-link $W(0) $W(1) 3Mb 10ms DropTailproc construct-arptable {} { global BS node_ opt [$BS(0) set arptable_] construct-static-arptable for {set j 0} {$j < $opt(nn)} {incr j} { [$node_($j) set arptable_] construct-static-arptable }}# setup TCP connectionsproc create-tcp-connections {} { global ns_ tcp ftp sink node_ W opt ftcp num_tcp_flows for {set j 1} {$j <= $num_tcp_flows} {incr j} { set tcp($j) [new Agent/TCP] $tcp($j) set fid_ [expr $j] set sink($j) [new Agent/TCPSink] $ns_ attach-agent $node_([expr $j-1]) $tcp($j) $ns_ attach-agent $W(1) $sink($j) $ns_ connect $tcp($j) $sink($j) set ftp($j) [new Application/FTP] $ftp($j) attach-agent $tcp($j) set ftpjstart [expr $j*0.1] $ns_ at $ftpjstart "$ftp($j) start" $tcp($j) set starts $ftpjstart $ns_ at $opt(stop) "$ftp($j) stop" } for {set j 1} {$j <= $num_tcp_flows} {incr j} { set ftcp($j) [open tcp_cwnd_trace_${j}.tr w] $tcp($j) attach-trace $ftcp($j) $tcp($j) trace cwnd_ $tcp($j) trace t_seqno_ $tcp($j) trace ack_ $tcp($j) trace rtt_ $tcp($j) trace srtt_ $tcp($j) trace rttvar_ }}Simulator instproc dump_tcps_title {} { global tcp_status_record_file tcp num_tcp_flows for {set j 1} {$j <= $num_tcp_flows} {incr j} {# puts $tcp_status_record_file($j) "fid \t\# src_start_time \t current_time \t duration \t\# ndata_pack \t ndata_bytes \t nack_pack \t\# nrexmit_pack \t nrexmit_bytes \t nrexmit \t 8*ndata_bytes/duration \t datasent_for_the_period throughput_for_the_period" $tcp($j) set ndatabytes_prev_ 0 $tcp($j) set nackpack_prev_ 0 }}Simulator instproc dump_tcps {} { global tcp ns_ tcp_status_record_file num_tcp_flows dumpinterval for {set j 1} {$j <= $num_tcp_flows} {incr j} { set duration($j) [expr [$ns_ now] - [$tcp($j) set starts]] if { $duration($j) > 0 } { puts $tcp_status_record_file($j) "[$tcp($j) set fid_] \t\ [$tcp($j) set starts] \t [$ns_ now] \t $duration($j) \t\ [$tcp($j) set ndatapack_]\t\ [$tcp($j) set ndatabytes_]\t [$tcp($j) set nackpack_]\t\ [$tcp($j) set nrexmitpack_]\t [$tcp($j) set nrexmitbytes_]\t\ [$tcp($j) set nrexmit_]\t [expr 8.0*[$tcp($j) set ndatabytes_]/$duration($j)]\t\ [expr 8.0*[expr [$tcp($j) set ndatabytes_] - [$tcp($j) set ndatabytes_prev_]]]\t\ [expr 8000*[expr [$tcp($j) set nackpack_] - [$tcp($j) set nackpack_prev_]]/$dumpinterval]" $tcp($j) set ndatabytes_prev_ [$tcp($j) set ndatabytes_] $tcp($j) set nackpack_prev_ [$tcp($j) set nackpack_] } else { puts $tcp_status_record_file($j) "[$tcp($j) set fid_] \t 0 \t [$ns_ now] \t 0 \t\ 0 \t 0 \t 0 \t 0 \t 0 \t 0 \t 0 \t 0 \t 0" } }} proc stop {} { global ns_ tracefd namtrace tcp_status_record_file ftcp num_tcp_flows $ns_ flush-trace close $tracefd# close $namtrace for {set j 1} {$j < $num_tcp_flows} {incr j} { close $tcp_status_record_file($j) close $ftcp($j) } set f0 [open TCPpackets.p0 w] puts $f0 "TitleText: TCP packet status of the flow 1" puts $f0 "Device: Posscript" exec awk {$6=="t_seqno_" && $7!="0" { print $1, $7} } tcp_cwnd_trace_1.tr > TCP1sent exec awk {$6=="ack_" && $7!="-1" && $7!="0" { print $1, $7} } tcp_cwnd_trace_1.tr > TCP1ack_rcvd exec awk {$1=="d" && $8=="1" { print $2, $11} } ex1.tr > TCP1dropped puts $f0 [format "\n\"TCP Packet Sent"] flush $f0 exec cat TCP1sent >@ $f0 flush $f0 puts $f0 [format "\n\"ACK Packet Rcvd"] flush $f0 exec cat TCP1ack_rcvd >@ $f0 flush $f0 puts $f0 [format "\n\"TCP Packet Dropped"] flush $f0 exec cat TCP1dropped >@ $f0 flush $f0 close $f0 #exec xgraph -display $env(DISPLAY) -bb -tk -nl -m -x time(sec) -y seqno TCPpackets.p0 & exec xgraph -display 127.0.0.1:0.0 -bb -tk -nl -m -x time(sec) -y seqno TCPpackets.p0 & exit 0}construct-arptablecreate-tcp-connections# source connection-pattern and node-movement scriptsif { $opt(cp) == "" } { puts "*** NOTE: no connection pattern specified." set opt(cp) "none"} else { puts "Loading connection pattern..." source $opt(cp)}if { $opt(sc) == "" } { puts "*** NOTE: no scenario file specified." set opt(sc) "none"} else { puts "Loading scenario file..." source $opt(sc) puts "Load complete..."}for {set i 0} {$i < $opt(nn) } {incr i} { $node_($i) set X_ [expr 100 + $i] $node_($i) set Y_ [expr 10 * $i] $node_($i) set Z_ 0} # Define initial node position in namfor {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} $ns_ at 0 "$ms_ start-scheduler_802_16"# Tell all nodes when the simulation endsfor {set i 0 } {$i < $opt(nn) } {incr i} { $ns_ at $opt(stop).0 "$node_($i) reset";}$ns_ at $opt(stop).0 "$BS(0) reset";$ns_ at [expr $opt(stop)] "stop"$ns_ at [expr $opt(stop)] "puts \"NS EXITING...\" ; $ns_ halt"# informative headers for CMUTracefileputs $tracefd "M 0.0 nn $opt(nn) x $opt(x) y $opt(y) rp \ $opt(adhocRouting)"puts $tracefd "M 0.0 sc $opt(sc) cp $opt(cp) seed $opt(seed)"puts $tracefd "M 0.0 prop $opt(prop) ant $opt(ant)"$ns_ dump_tcps_titlefor {set stat_record_time [expr 0 + $dumpinterval]} {$stat_record_time < [expr $opt(stop) + 1] } {set stat_record_time [expr $stat_record_time + $dumpinterval]} { $ns_ at $stat_record_time "$ns_ dump_tcps"}puts "Starting Simulation..."$ns_ run
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -