⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wireless2.tcl

📁 给新学习 ns模拟平台的人的一些参考的例子
💻 TCL
字号:
# 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_11                 ;# 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(nn)             3                          ;# number of mobilenodesset opt(adhocRouting)   DSDV                       ;# routing protocolset opt(cp)             ""                         ;# connection pattern fileset opt(sc)     "../mobility/scene/scen-3-test"    ;# 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 opt(stop)   250                            ;# time to stop simulationset opt(ftp1-start)      160.0set opt(ftp2-start)      170.0set num_wired_nodes      2set num_bs_nodes         1# ============================================================================# 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)}# create simulator instanceset ns_   [new Simulator]# set up for hierarchical routing$ns_ node-config -addressType hierarchicalAddrParams set domain_num_ 2           ;# number of domainslappend cluster_num 2 1                ;# number of clusters in each domainAddrParams set cluster_num_ $cluster_numlappend eilastlevel 1 1 4              ;# number of nodes in each cluster AddrParams set nodes_num_ $eilastlevel ;# of each domainset tracefd  [open wireless2-out.tr w]set namtrace [open wireless2-out.nam w]$ns_ trace-all $tracefd$ns_ namtrace-all-wireless $namtrace $opt(x) $opt(y)# Create topography objectset topo   [new Topography]# define topology$topo load_flatgrid $opt(x) $opt(y)# create Godcreate-god [expr $opt(nn) + $num_bs_nodes]#create wired nodesset 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 [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) \                 -channelType $opt(chan) \		 -topoInstance $topo \                 -wiredRouting ON \		 -agentTrace ON \                 -routerTrace OFF \                 -macTrace OFF #create base-station nodeset temp {1.0.0 1.0.1 1.0.2 1.0.3}   ;# hier address to be used for wireless                                     ;# domainset BS(0) [$ns_ node [lindex $temp 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 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 \	    [$BS(0) node-addr]]}#create links between wired and BS nodes$ns_ duplex-link $W(0) $W(1) 5Mb 2ms DropTail$ns_ duplex-link $W(1) $BS(0) 5Mb 2ms DropTail$ns_ duplex-link-op $W(0) $W(1) orient down$ns_ duplex-link-op $W(1) $BS(0) orient left-down# setup TCP connectionsset tcp1 [new Agent/TCP]$tcp1 set class_ 2set sink1 [new Agent/TCPSink]$ns_ attach-agent $node_(0) $tcp1$ns_ attach-agent $W(0) $sink1$ns_ connect $tcp1 $sink1set ftp1 [new Application/FTP]$ftp1 attach-agent $tcp1$ns_ at $opt(ftp1-start) "$ftp1 start"set tcp2 [new Agent/TCP]$tcp2 set class_ 2set sink2 [new Agent/TCPSink]$ns_ attach-agent $W(1) $tcp2$ns_ attach-agent $node_(2) $sink2$ns_ connect $tcp2 $sink2set ftp2 [new Application/FTP]$ftp2 attach-agent $tcp2$ns_ at $opt(ftp2-start) "$ftp2 start"# 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..."}# 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}     # Tell all nodes when the simulation endsfor {set i } {$i < $opt(nn) } {incr i} {    $ns_ at $opt(stop).0 "$node_($i) reset";}$ns_ at $opt(stop).0 "$BS(0) reset";$ns_ at $opt(stop).0002 "puts \"NS EXITING...\" ; $ns_ halt"$ns_ at $opt(stop).0001 "stop"proc stop {} {    global ns_ tracefd namtrace#    $ns_ flush-trace    close $tracefd    close $namtrace}# 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)"puts "Starting Simulation..."$ns_ run

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -