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

📄 nsscript6.html

📁 NS的教程
💻 HTML
📖 第 1 页 / 共 2 页
字号:
$ns_ at $opt(ftp1-start) "$ftp1 start"

set tcp2 [new Agent/TCP]
$tcp2 set class_ 2
set sink2 [new Agent/TCPSink]
$ns_ attach-agent $W(1) $tcp2        
$ns_ attach-agent $node_(2) $sink2
$ns_ connect $tcp2 $sink2
set ftp2 [new Application/FTP]
$ftp2 attach-agent $tcp2
$ns_ at $opt(ftp2-start) "$ftp2 start"

</PRE></CODE></TD></TABLE>
</P>
<P>
This would be followed by the remaining lines from wireless1.tcl (sourcing cp
and sc files, telling mobilenodes when to stop and
finally running ns). It is possible that some lines of code in wireless2.tcl have not been
discussed here. For a complete copy of script wireless2.tcl, download from
<A HREF="examples/wireless2.tcl">here</A>. 
</P>
Run the script. The ns and nam trace files are generated at the end of simulation
run. Running wireless2-out.nam shows the movement of mobilenodes and traffic
in the wired domain. As mentioned earlier, traffic flow for mobilenodes is
not as yet supported in nam. In trace file wireless2-out.tr we see traces for
both wired domain and wireless domain (preceeding with "WL" for wireless).
At 160.0s, a TCP connection is setup between _3_, (which is node_(0))
and 0, (which is W(0)). Note that
the node-ids are created internally by the simulator and are assigned in the
order of node creation. At 170s, another TCP connection is setup in the opposite direction,
from the wired to the wireless domain. For details on CMUTraces see chapter
15 of <A HREF="http://www.isi.edu/nsnam/ns/ns-documentation.html">ns documentation</A>.
</P>

<A NAME="second"></A>
<P>
<STRONG>X.2. Running MobileIP in a simple wired-cum-wireless
topology</STRONG><BR>                                       
</P>

<P>
So far we have created a wired-cum-wireless topology and have exchanged
pkts between a wired and wireless domain via a base-station. But a mobilenode
may roam
outside the domain of its basestation and should still continue to receive
packets destined to it.
In other words it would be interesting to extend mobileIP support in the
wired-cum-wireless scenario we created in <A
HREF="nsscript6.html#first">section X.1</A>.
<BR>For this example we have the same wired domain consisting of 2 wired
nodes, W0 and W1. We have 2 base-station nodes and call them HomeAgent(HA) and
ForeignAgent(FA) respectively.
The wired node W1 is connected to HA and FA as shown in the figure below.
There is a roaming mobilenode called MobileHost(MH) that moves between its
home agent and foreign agents.
We will set up a TCP flow between W0 and MH. As MH moves out from the
domain of its HA, into the domain of FA, we will observe how pkts destined
for MH is redirected by its HA to the FA as per mobileIP protocol
definitions. See fig2 below for the topology described above.
</P>
<P>
<IMG SRC="images/wireless3.gif" WIDTH=490 HEIGHT=500 ALT="Fig.2"> 
</P>
<P>
We shall edit <A HREF="examples/wireless2.tcl">wireless2.tcl</A> created
in <A HREF="nsscript6.html#first">section X.1</A> to create
the wireless-mip script called wireless3.tcl. It may be possible that
the whole of wireless3.tcl is not discussed here. So for convinience,
you may download a copy of wireless3.tcl from <A
HREF="examples/wireless3.tcl">here.</A>
</P>
<P>
Change number of mobilenodes and time of simulation,

<TABLE BGCOLOR="#eeeeee" CELLPADDING=5><TD><CODE><PRE>
set opt(nn)             1           ;# just one MH
set opt(stop)           250
</PRE></CODE></TD></TABLE>
</P>
<P>
In this example we will set up the TCP connection as well as define
movement of the MH in the script itself. Hence we are not going to use the
cp and sc files. 
<TABLE BGCOLOR="#eeeeee" CELLPADDING=5><TD><CODE><PRE>
set opt(cp)             ""
set opt(sc)             ""
</PRE></CODE></TD></TABLE>
</P>
<P>
Define the TCP flow starttime,
<TABLE BGCOLOR="#eeeeee" CELLPADDING=5><TD><CODE><PRE>
set opt(ftp1-start)     100.0
</PRE></CODE></TD></TABLE>
</P>
<P>
Change number of wired, base-station and mobile nodes. However note that 
the variable num_bs_nodes is not really used in this script. The
base-station nodes, HA and FA, are individually created and handled.
<TABLE BGCOLOR="#eeeeee" CELLPADDING=5><TD><CODE><PRE>
set num_wired_nodes      2
</PRE></CODE></TD></TABLE>
</P>
<P>
After the 2 lines creating ns instance and setting address format to
hierarchical,
add the following lines to define the topological hierarchy. It is quite similar
to that of wireless2.tcl except that now we have a third domain for the FA.
Change the cluster and node parameters accordingly. 
<TABLE BGCOLOR="#eeeeee" CELLPADDING=5><TD><CODE><PRE>
AddrParams set domain_num_ 3           ;# number of domains
lappend cluster_num 2 1 1              ;# number of clusters in each domain
AddrParams set cluster_num_ $cluster_num
lappend eilastlevel 1 1 2 1            ;# number of nodes in each cluster 
AddrParams set nodes_num_ $eilastlevel ;# of each domain
</PRE></CODE></TD></TABLE>
</P>

<P>
Next set up ns trace and nam files for wireless-mip,

<TABLE BGCOLOR="#eeeeee" CELLPADDING=5><TD><CODE><PRE>
set tracefd  [open wireless3-out.tr w]
set namtrace [open wireless3-out.nam w]
$ns_ trace-all $tracefd
$ns_ namtrace-all-wireless $namtrace $opt(x) $opt(y)
</PRE></CODE></TD></TABLE>
</P>
<P>
So in this topology we have one wired domain (denoted by 0) and 2 wireless
domains (denoted by 1 & 2 respectively). Hence as described in section
X.1, the wired node addresses remain the same, 0.0.0 and 0.1.0.
In the first wireless domain (domain 1) we have base-station, HA and 
mobilenode, MH, in the same single cluster. Their addresses are 1.0.0 and 1.0.1 respectively.
For the second wireless domain (domain 2) we have a base-station, FA with an
address of 2.0.0. However in the course of the simulation, the MH will
move into the domain of FA and we shall see how pkts originating
from a wired domain and destined to MH will reach it as a result of the
MobileIP protocol.
</P>
<P>
Wired nodes will be created as earlier. However in place of a single
base-station node, a HA and FA will be created. Note here that to turn the
mobileIP flag on we have configure the node structure accordingly using option
-mobileIP ON.

<TABLE BGCOLOR="#eeeeee" CELLPADDING=5><TD><CODE><PRE>
# Configure for ForeignAgent and HomeAgent nodes
$ns_ node-config -mobileIP ON \
                 -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 HA and FA
set HA [$ns_ node 1.0.0]
set FA [$ns_ node 2.0.0]
$HA random-motion 0
$FA random-motion 0

#provide some co-ord (fixed) to these base-station nodes. 
$HA set X_ 1.000000000000
$HA set Y_ 2.000000000000
$HA set Z_ 0.000000000000

$FA set X_ 650.000000000000
$FA set Y_ 600.000000000000
$FA set Z_ 0.000000000000
</PRE></CODE></TD></TABLE>
</P>
<P> Next create the mobilehost as follows. Note as before we have to turn off
the option -wiredRouting (used for creation of base-station nodes) before
creating mobilenodes. Also the HA is setup as the home-agent for the mobilehost.
The MH has an address called the care-of-address (COA). Based on the
registration/beacons exchanged between the MH and the base-station node
(of the domain the MH is currently in), the base-station's address is
assigned as the MH's COA. Thus in this simulation, address of HA is assigned
initially as the COA of MH.
As MH moves in to the domain of FA, its COA changes to that of the FA. 
For details on MobileIP implementation in ns, read section 15.2.2 of
(in wireless networking chapter) <A
HREF="http://www.isi.edu/nsnam/ns/ns-documentation.html">ns documentation</A>.
Also see files mip.{cc,h}, mip-reg.{cc,h}, tcl/lib/{ns-mip.tcl, ns-wireless-mip.tcl}.
<TABLE BGCOLOR="#eeeeee" CELLPADDING=5><TD><CODE><PRE>
# configure for mobilehost
$ns_ node-config -wiredRouting OFF

# create mobilehost that would be moving between HA and FA.
# note address of MH indicates its in the same domain as HA.
set MH [$ns_ node 1.0.1]
set node_(0) $MH
set HAaddress [AddrParams set-hieraddr [$HA node-addr]]
[$MH set regagent_] set home_agent_ $HAaddress

# movement of the MH
$MH set Z_ 0.000000000000
$MH set Y_ 2.000000000000
$MH set X_ 2.000000000000

# MH starts to move towards FA (640, 610) at a speed of 20m/s
$ns_ at 100.000000000000 "$MH setdest 640.000000000000 610.000000000000
20.000000000000" 

# and goes back to HA (2, 2) at a speed of 20 m/s
$ns_ at 200.000000000000 "$MH setdest 2.000000000000 2.000000000000
20.000000000000"
</PRE></CODE></TD></TABLE>
</P>
<P>
Create links between Wired nodes and HA/FA and setup TCP connection:

<TABLE BGCOLOR="#eeeeee" CELLPADDING=5><TD><CODE><PRE>
# create links between wired and BaseStation nodes
$ns_ duplex-link $W(0) $W(1) 5Mb 2ms DropTail
$ns_ duplex-link $W(1) $HA 5Mb 2ms DropTail
$ns_ duplex-link $W(1) $FA 5Mb 2ms DropTail

$ns_ duplex-link-op $W(0) $W(1) orient down
$ns_ duplex-link-op $W(1) $HA orient left-down
$ns_ duplex-link-op $W(1) $FA orient right-down

# setup TCP connections between a wired node and the MobileHost

set tcp1 [new Agent/TCP]
$tcp1 set class_ 2  
set sink1 [new Agent/TCPSink]
$ns_ attach-agent $W(0) $tcp1
$ns_ attach-agent $MH $sink1
$ns_ connect $tcp1 $sink1
set ftp1 [new Application/FTP]
$ftp1 attach-agent $tcp1
$ns_ at $opt(ftp1-start) "$ftp1 start"
</PRE></CODE></TD></TABLE>
</P>
<P>
The rest of the script remains unchanged (i.e tell mobilenodes when the simulation
stops). Save and run the script.
Click <A HREF="examples/wireless3.tcl">here</A> for a copy of the file
wireless3.tcl.
</P>
<P> While running the script, you may see warnings like "warning: Route to
base_stn not known: dropping pkt". This means that as the MH moves from
the domain of one base-station into domain of another there may be interim
periods when it is not registered to any base-station and thus doesnot
know whom to forward pkts destined outside its domain.
On completion of the run, ns and nam trace output files "wireless3-out.tr" and
"wireless3-out.nam" are created. The nam output shows the movement of the mobilehost
and traffic flow in the wired domain. 
The ns trace output shows traces for both the wired nodes as well as the wireless
domain. We see routine beacon broadcast/solicitations sent out by HA/FA and
the MH. Initially the TCP pkts are handed down to MH directly by its HA.
As MH moves away from HA domain into the domain of the FA, we find the pkts destined
for MH, being encapsulated and forwarded to the FA which then strips off or
decapsulates the pkt and hands it over to the MH. 
</P>
<HR>
<P>
[<A HREF="nsscript5.html">Previous section</A>]
[<A HREF="nsscript7.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 + -