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

📄 nsscript5.html

📁 NS的教程
💻 HTML
📖 第 1 页 / 共 2 页
字号:
$ftp attach-agent $tcp
$ns_ at 10.0 "$ftp start" 
</PRE></CODE></TD></TABLE>
This sets up a TCP connection betwen the two nodes with a TCP source on
node0. 
</P>
<P>
Then we need to define stop time when the simulation ends and tell mobilenodes
to reset which actually resets thier internal network components,
<TABLE BGCOLOR="#eeeeee" CELLPADDING=5><TD><CODE><PRE>
#
# Tell nodes when the simulation ends
#
for {set i 0} {$i < $val(nn) } {incr i} {
    $ns_ at 150.0 "$node_($i) reset";
}
$ns_ at 150.0001 "stop"
$ns_ at 150.0002 "puts \"NS EXITING...\" ; $ns_ halt"
proc stop {} {
    global ns_ tracefd
    close $tracefd
}
</PRE></CODE></TD></TABLE>
At time 150.0s, the simulation shall stop. The nodes are reset at that
time and the "$ns_ halt" is called at 150.0002s, a little later after
resetting the nodes. The
procedure stop{} is called to flush out traces and close the trace file.
</P>
<P>
And finally the command to start the simulation,

<TABLE BGCOLOR="#eeeeee" CELLPADDING=5><TD><CODE><PRE>
puts "Starting Simulation..."
$ns_ run
</PRE></CODE></TD></TABLE>
</P>
<P>
Save the file simple-wireless.tcl. In order to download a copy of the
file click <A HREF="examples/simple-wireless.tcl">here</A>.
Next run the simulation in the usual way (type at prompt: 
"ns simple-wireless.tcl" )
</P>
<P>
At the end of the simulation run, trace-output file simple.tr is created.
As we have turned on the AgentTrace and RouterTrace we see DSDV routing
messages and TCP pkts being received and sent by Router and Agent objects
in node _0_ and _1_. Note that all wireless traces starts with WL in their
first field. See Chapter 15 of <A HREF="http://www.isi.edu/nsnam/ns/ns-documentation.html">
ns documentation</A>
for details on wireless trace.
We see TCP flow starting at 10.0s from node0. Initially both the nodes are
far apart and thus TCP pkts are dropped by node0 as it cannot hear from node1.
Around 81.0s the routing info begins to be exchanged between both the nodes
and around 100.0s we see the first TCP pkt being received by the Agent at
node1 which then sends an ACK back to node0 and the TCP connection is setup.
However as node1 starts to move away from node0, the connection 
breaks down again around time 116.0s. Pkts start getting dropped as the
nodes move away from one another.
</P>

<A NAME="second"></A>
<P>
<STRONG>IX.2. Using node-movement/traffic-pattern files and other features
in wireless simulations </STRONG><BR>
</P>
<P>
As an extension to the previous <A HREF="nsscript5.html#first">sub-section</A>,
we are going to simulate a 
simple multihop wireless scenario consisting of 3 mobilenodes here.
As before, the mobilenodes move within the boundaries of a defined
topology. However the node movements for this example shall be read from a
node-movement file called scen-3-test. scen-3-test defines random node
movements for the 3 mobilenodes within a topology of 670mX670m. This file is
available as a part of the ns distribution and can be found, along with other
node-movement files, under directory ~ns/tcl/mobility/scene. Random node
movement files like scen-3-test can be generated using CMU's node-movement
generator "setdest". Details on generation of node movement 
files are covered in <A HREF="nsscript7.html#second">section XI.2</A> of this
tutorial.
</P>
<P>
In addition to node-movements, traffic flows that are setup between the
mobilenodes, are also read from a traffic-pattern file called
cbr-3-test. cbr-3-test is also available under ~ns/tcl/mobility/scene. Random CBR and TCP
flows are setup between the 3 mobilenodes and data packets are sent, forwarded
or received by nodes within hearing range of one another. See cbr-3-test to
find out more about the traffic flows that are setup. These traffic-pattern
files can also be generated using CMU's TCP/CBR traffic generator script.
More about this is discussed in <A HREF="nsscript7.html#first">section XI.1</A> of
this tutorial.
</P>
<P>We shall make changes to the script, <A HREF="examples/simple-wireless.tcl">simple-wireless.tcl</A>,
we had created
in <A HREF="nsscript5.html#first">section IX.1.</A>
and shall call the resulting file wireless1.tcl. For a copy of wireless1.tcl
download from <A HREF="examples/wireless1.tcl">here</A>.
In addition to the variables (LL, MAC, antenna etc) that were declared at the
beginning of the script, we now define
some more parameters like the connection-pattern and node-movement file,
x and y values for the topology boundary, a seed value for the random-number
generator, time for the simulation to stop, for convinience. They are listed
as follows:
<TABLE BGCOLOR="#eeeeee" CELLPADDING=5><TD><CODE><PRE>
set val(chan)       Channel/WirelessChannel
set val(prop)       Propagation/TwoRayGround
set val(netif)      Phy/WirelessPhy
set val(mac)        Mac/802_11
set val(ifq)        Queue/DropTail/PriQueue
set val(ll)         LL
set val(ant)        Antenna/OmniAntenna
set val(x)              670   ;# X dimension of the topography
set val(y)              670   ;# Y dimension of the topography
set val(ifqlen)         50            ;# max packet in ifq
set val(seed)           0.0
set val(adhocRouting)   DSR
set val(nn)             3             ;# how many nodes are simulated
set val(cp)             "../mobility/scene/cbr-3-test" 
set val(sc)             "../mobility/scene/scen-3-test" 
set val(stop)           2000.0           ;# simulation time

</PRE></CODE></TD></TABLE>
Number of mobilenodes is changed to 3;
Also we use DSR (dynamic source routing) as the adhoc routing protocol inplace
of DSDV (Destination sequence distance vector);
</P>
<P>

After creation of ns_, the simulator instance, open a file (wireless1-out.tr)
for wireless traces. Also we are going to set up nam traces. 

<TABLE BGCOLOR="#eeeeee" CELLPADDING=5><TD><CODE><PRE>
set tracefd  [open wireless1-out.tr w]      ;# for wireless traces
$ns_ trace-all $tracefd

set namtrace [open wireless1-out.nam w]           ;# for nam tracing
$ns_ namtrace-all-wireless $namtrace $val(x) $val(y)
</PRE></CODE></TD></TABLE>
</P>
<P>
<P>
Next (after creation of mobilenodes) source node-movement and connection
pattern files that were defined earlier as val(sc) and val(cp) respectively. 

<TABLE BGCOLOR="#eeeeee" CELLPADDING=5><TD><CODE><PRE>
# 
# Define node movement model
#
puts "Loading connection pattern..."
source $val(cp)

# 
# Define traffic model
#
puts "Loading scenario file..."
source $val(sc)

</PRE></CODE></TD></TABLE>
</P>

<P>
In node-movement file scen-3-test, we see node-movement commands like
<TABLE BGCOLOR="#eeeeee" CELLPADDING=5><TD><CODE><PRE>
$ns_ at 50.000000000000 "$node_(2) setdest 369.463244915743 \
170.519203111152 3.371785899154"
</PRE></CODE></TD></TABLE>

This, as described in earlier sub-section, means at time 50s, node2 starts to move
towards destination (368.4,170.5) at a speed of 3.37m/s.
We also  see other lines like
<TABLE BGCOLOR="#eeeeee" CELLPADDING=5><TD><CODE><PRE>
$god_ set-dist 1 2 2
</PRE></CODE></TD></TABLE>

These are command lines used to load the god object with the shortest hop
information. 
It means the shortest path between node 1 and 2 is 2 hops. By providing
this information, the calculation of shortest distance between nodes by the god
object during simulation runs, which can be quite time-consuming, is prevented.

<P>
The setdest program (see <A HREF="nsscript7.html#second">section XI.2</A>) generates movement pattern files
using the random waypoint algorithm.  The node-movement files generated
using setdest (like scen-3-test) already include lines like above to load
the god object with the appropriate information at the appropriate time.
</P>
<P>
A program called calcdest
(~ns/indep-utilities/cmu-scen-gen/setdest/calcdest)
can be used to annotate movement pattern files generated by other means with
the lines of god information. calcdest makes several assumptions about the
format of the lines in the input movement pattern file which will cause it
to fail if the file is not formatted properly.  If calcdest rejects a
movement pattern file you have created, the easiest way to format it properly
is often to load it into ad-hockey and then save it out again.  If ad-hockey
can read your input correctly, its output will be properly formatted for
calcdest.
</P>
<P>
Both setdest and calcdest calculate the shortest number
of hops between nodes based on the nominal radio range, ignoring any
effects that might be introduced by the propagation model in an actual
simulation.  The nominal range is either provided as an argument to
the programs, or extracted from the header in node-movement pattern
files.
</P>
<P>
The path length information provided to god was used by CMU's Monarch Project
to analyze the path length optimality of ad hoc network routing protocols,
and so was printed out as part of the CMUTrace output for each packet.  
</P>
<P>
Other uses that CMU has found for the information are:
<LI>Characterizing the rate of topology change in a movement pattern.
<LI>Identifying the frequency and size of partitions.
<LI>Experimenting with the behavior of the routing protocols if the
god information is used to provide them with ``perfect'' neighbor
information at zero cost.
</P>
</P>
<P>
Next add the following lines for providing initial position of
nodes in nam.
However note that only node movements can currently be
seen in nam . Dumping of traffic data and thus visualization of data pkt
movements in nam for wireless scenarios is still not supported (future work).

<TABLE BGCOLOR="#eeeeee" CELLPADDING=5><TD><CODE><PRE>
# Define node initial position in nam
for {set i 0} {$i < $val(nn)} {incr i} {

        # 20 defines the node size in nam, must adjust it according to your
        # scenario size.
        # The function must be called after mobility model is defined
        $ns_ initial_node_pos $node_($i) 20
}  
</PRE></CODE></TD></TABLE>
</P>
<P>
Next add informative headers for the CMUTrace file, just before the line
"ns_ run" :

<TABLE BGCOLOR="#eeeeee" CELLPADDING=5><TD><CODE><PRE>
puts $tracefd "M 0.0 nn $val(nn) x $val(x) y $val(y) rp $val(adhocRouting)"
puts $tracefd "M 0.0 sc $val(sc) cp $val(cp) seed $val(seed)"
puts $tracefd "M 0.0 prop $val(prop) ant $val(ant)"
</PRE></CODE></TD></TABLE>
The rest of the script remains unchanged.
</P>
<P>
Save the file wireless1.tcl. Make sure the connection-pattern and node-movement
files exist under the directories as declared above. 

<BR>Run the script by typing at the prompt:

<TABLE BGCOLOR="#eeeeee" CELLPADDING=5><TD><CODE><PRE>
ns  wireless1.tcl
</PRE></CODE></TD></TABLE>

On completion of the run, CMUTrace output file "wireless1-out.tr" and nam
output file "wireless1-out.nam" are created. Running wireless1-out.nam we see
the three mobilenodes moving in nam window. However as mentioned earlier no
traffic flow can be seen (not supported as yet). For a variety of coarse and
fine grained trace outputs turn on/off AgentTrace, RouteTrace, MacTrace and
movementTrace as shown earlier in the script. From the CMUTrace output we
find nodes 0 and 2 are out of range and so cannot hear one another. Node1 is
in range with nodes 0 and 2 and can communicate with both of them. Thus all
pkts destined for nodes 0 and 2 are routed through node 1. For details
on CMUTraces see chapter 15 of <A HREF="http://www.isi.edu/nsnam/ns/ns-documentation.html">
ns documentation</A>.
</P>
<HR>
<P>
[<A HREF="nsscript4.html">Previous section</A>]
[<A HREF="nsscript6.html">Next section</A>]
[<A HREF="nsindex.html">Back to the index</A>]
</P>

<P>
VINT <BR>
<ADDRESS><A HREF="mailto:ns-users@isi.edu">ns-users@isi.edu</A></ADDRESS>
</P>

</BODY>
</HTML>

⌨️ 快捷键说明

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