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

📄 nsscript6.htm

📁 介绍了网络仿真软件NS2的使用
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0051)http://www.isi.edu/nsnam/ns/tutorial/nsscript6.html -->
<HTML><HEAD><TITLE>Tutorial for the UCB/LBNL/VINT Network Simulator "ns"</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content="MSHTML 6.00.2900.3199" name=GENERATOR></HEAD>
<BODY text=#000000 bgColor=#ffffff>
<H1 align=center>X. Creating Wired-cum-Wireless and MobileIP Simulations in 
ns</H1>
<P>[<A href="http://www.isi.edu/nsnam/ns/tutorial/nsscript5.html">Previous 
section</A>] [<A href="http://www.isi.edu/nsnam/ns/tutorial/nsscript7.html">Next 
section</A>] [<A href="http://www.isi.edu/nsnam/ns/tutorial/nsindex.html">Back 
to the index</A>] </P>
<P><I>IMPORTANT: This tutorial chapter uses new node APIs which are not 
available in the ns2.1b5 version. So please download the <A 
href="http://www.isi.edu/nsnam/dist/vint/ns-src-current.tar.gz">daily 
snapshot</A> unless a release is made for version ns2.1b6 or higher. The current 
snapshot version is updated daily, so please check the <A 
href="http://www.isi.edu/nsnam/ns/ns-tests.html">validation test results</A> for 
that day before downloading, as these snapshots can sometimes be unstable due to 
ongoing changes made by ns-developers.</I> </P>
<HR>
<A name=first></A>
<P><STRONG>X.1. Creating a simple wired-cum-wireless scenario </STRONG><BR></P>
<P>The wireless simulation described in <A 
href="http://www.isi.edu/nsnam/ns/tutorial/nsscript5.html">section IX</A>, 
supports multi-hop ad-hoc networks or wireless LANs. But we may need to simulate 
a topology of multiple LANs connected through wired nodes, or in other words we 
need to create a wired-cum-wireless topology. </P>
<P>In this section we are going to extend the simple wireless topology created 
in section IX to create a mixed scenario consisting of a wireless and a wired 
domain, where data is exchanged between the mobile and non-mobile nodes. We are 
going to make modifications to the tcl script called <A 
href="http://www.isi.edu/nsnam/ns/tutorial/examples/wireless1.tcl">wireless1.tcl</A> 
created in <A 
href="http://www.isi.edu/nsnam/ns/tutorial/nsscript5.html#second">section 
IX.2</A> and name the resulting wired-cum-wireless scenario file wireless2.tcl. 
</P>
<P>For the mixed scenario, we are going to have 2 wired nodes, W(0) and W(1), 
connected to our wireless domain consisting of 3 mobilenodes (nodes 0, 1 &amp; 
2) via a base-station node, BS. Base station nodes are like gateways between 
wireless and wired domains and allow packets to be exchanged between the two 
types of nodes. For details on base-station node please see section 2 
(wired-cum-wireless networking) of chapter 15 of <A 
href="http://www.isi.edu/nsnam/ns/ns-documentation.html">ns notes&amp;doc (now 
renamed as ns Manual)</A>. Fig1. shows the topology for this example described 
above. </P>
<P><IMG height=600 alt=Fig.1 src="nsscript6.files/wireless2.gif" width=590> </P>
<P>Let us begin by checking what changes need to be made to the list of 
variables defined at the beginning of wireless1.tcl. </P>
<P>The Adhoc routing protocol is changed to DSDV. Also, we define TCP and CBR 
connections between the wired and wireless nodes in the script itself. So we 
won't need to use the connection pattern file used in earlier simulation. Also 
change the simulation stop time. Note here that we use array opt() instead of 
val() simply to illustrate that this is no longer a global array variable and 
its scope is defined only in the test script. 
<TABLE cellPadding=5 bgColor=#eeeeee>
  <TBODY>
  <TR>
    <TD><CODE><PRE>set opt(adhocRouting)   DSDV
set opt(cp)     	""       ;# cp file not used
set opt(stop)   	300      ;# time to stop simulation
</PRE></CODE></TD></TR></TBODY></TABLE>We define the start times for TCP flows 
here: 
<TABLE cellPadding=5 bgColor=#eeeeee>
  <TBODY>
  <TR>
    <TD><CODE><PRE>set opt(ftp1-start)      160.0
set opt(ftp2-start)      170.0
</PRE></CODE></TD></TR></TBODY></TABLE>Also add the following line to define 
number of wired and base-station nodes: 
<TABLE cellPadding=5 bgColor=#eeeeee>
  <TBODY>
  <TR>
    <TD><CODE><PRE>set num_wired_nodes      2
set num_bs_nodes         1
</PRE></CODE></TD></TR></TBODY></TABLE></P>
<P>Now we move to the main part of the program. For mixed simulations we need to 
use hierarchical routing in order to route packets between wireless and wired 
domains. As explained in section 15.2.1 of <A 
href="http://www.isi.edu/nsnam/ns/ns-documentation.html">ns Manual</A>, in ns, 
the routing information for wired nodes are based on connectivity of the 
topology, i.e how are nodes connected to one another through Links. This 
connectivity information is used to populate the forwarding tables in each wired 
node. However wireless nodes have no concept of "links". Packets are routed in a 
wireless topology using their adhoc routing protocols which build forwarding 
tables by exchanging routing queries among its neighbours. So inorder to 
exchange pkts among these wired and wireless nodes, we use base-stations which 
act as gateways between the two domains. We seggregate wired and wireless nodes 
by placing them in different domains. Domains and sub-domains (or clusters as 
they are called here) are defined by means of hierarchical topology structure as 
shown below. After line "set ns [new Simulator]", add the following lines: 
<TABLE cellPadding=5 bgColor=#eeeeee>
  <TBODY>
  <TR>
    <TD><CODE><PRE>$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 4              ;# number of nodes in each cluster
AddrParams set nodes_num_ $eilastlevel ;# for each domain
</PRE></CODE></TD></TR></TBODY></TABLE></P>
<P>In the above lines we first configure the node object to have addresstype as 
Hierarchical. Next the topology hierarchy is defined. Number of domains in this 
topology is 2 (one for the wired nodes and one for the wireless). Number of 
clusters in each of these domains is defined as "2 1" which indicates the first 
domain (wired) to have 2 clusters and the second (wireless) to have 1 cluster. 
The next line defines the number of nodes in each of these clusters which is "1 
1 4"; i.e one node in each of the first 2 clusters (in wired domain) and 4 nodes 
in the cluster in the wireless domain. So the topology is defined into a 3-level 
hierarchy (see the topology figure above). </P>
<P>Next we setup tracing for the simulation. Note here that for 
wired-cum-wireless simulation traces may be generated for both wired and 
wireless domains. Both the traces are written into the same output file defined 
here as wireless2-out.tr. In order to differentiate wireless traces from wired 
ones, all wireless traces begin with "WL". We also setup nam traces. As 
mentioned earlier nam traces for wireless nodes currently show node movements 
only. 
<TABLE cellPadding=5 bgColor=#eeeeee>
  <TBODY>
  <TR>
    <TD><CODE><PRE>set 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)
</PRE></CODE></TD></TR></TBODY></TABLE></P>
<P>Next we need to create the wired, wireless and base-station nodes. Note here 
that for all node creations, you have to pass the hierarchical address of the 
node. So after line "create-god $opt(nn)", add the following lines for creating 
wired nodes: 
<TABLE cellPadding=5 bgColor=#eeeeee>
  <TBODY>
  <TR>
    <TD><CODE><PRE># create wired nodes
set temp {0.0.0 0.1.0}           ;# hierarchical addresses to be used
for {set i 0} {$i &lt; $num_wired_nodes} {incr i} {
    set W($i) [$ns_ node [lindex $temp $i]]
}
</PRE></CODE></TD></TR></TBODY></TABLE></P>
<P>In order to create base-station node, we need to configure the node structure 
as shown below. This is part of the new node API which consists of first 
configuring and then creating nodes. Refer to <A 
href="http://www.isi.edu/nsnam/ns/tutorial/nsscript5.html#newAPI">node API</A> 
in chapterIX for details about the new node API. Since base-station nodes are 
gateways between wired and wireless domains they need to have wired routing 
mechanism turned on which is done by setting node-config option -wiredRouting 
ON. After creating the base-station node we reconfigure for wireless node and so 
turn wiredRouting OFF. All other node-config options used for base-station 
remains the same for mobilenode. Also the BS(0) node is assigned as the 
base-station node for all the mobilenodes in the wireless domain, so that all 
pkts originating from mobilenodes and destined outside the wireless domain, will 
be forwarded by mobilenodes towards their assigned base-station. </P>
<P>Note that it is important for the base-station node to be in the same domain 
as the wireless nodes. This is so that all pkts originating from the wired 
domain, and destined for a wireless node will reach the base-station which then 
uses its adhoc routing protocol to route the pkt to its correct destination. 
Thus in a mixed simulation involving wired and wireless nodes its necessary : 
<BR>1) to turn on hierarchical routing <BR>2) to create separate domains for 
wired and wireless nodes. There may be multiple wired and wireless domains to 
simulate multiple networks. <BR>3) to have one base-station node in every 
wireless domain, thru which the wireless nodes may communicate with nodes 
outside their domain. </P>Let us go step by step for this example to see how the 
hierarchy is created. Here we have two domains, domain 0 , for wired and domain 
1, for wireless. The two wired nodes are placed in 2 separate clusters, 0 and 1; 
thus their addresses look like 0(domain 0).0(cluster 0).0(only node) and 0 (same 
domain 0).1(cluster 1).0(again only node). <BR>As for the wireless nodes, they 
are in domain 1; we have defined one cluster (0), so all nodes are in this 
cluster. Hence the addresses are: <BR>Base-station: 1(second domain,1).0(cluster 
0).0(first node in cluster) <BR>WL node#1 : 1.0.1(second node in cluster) <BR>WL 
node#2 : 1.0.2(third node) <BR>WL node#3 : 1.0.3(fourth node) <BR>We could have 
placed the two wired nodes in the same cluster in wired domain 0. Also we could 
have placed other wireless nodes in different clusters in wireless domain 1. 
Also depending on our topology we may have got rid of clusters altogether, and 
simply have had 2 layers of hierarchy, the domains and the nodes. 
<TABLE cellPadding=5 bgColor=#eeeeee>
  <TBODY>
  <TR>
    <TD><CODE><PRE># 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
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 $temp 0]]
$BS(0) random-motion 0               ;# disable random motion

#provide some co-ordinates (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)
# Note there has been a change of the earlier AddrParams 
# function 'set-hieraddr' to 'addr2id'.

#configure for mobilenodes
$ns_ node-config -wiredRouting OFF

# now create mobilenodes
for {set j 0} {$j &lt; $opt(nn)} {incr j} {
    set node_($j) [ $ns_ node [lindex $temp \
            [expr $j+1]] ]
    $node_($j) base-station [AddrParams addr2id \
            [$BS(0) node-addr]]   ;# provide each mobilenode with
                                  ;# hier address of its base-station
}
</PRE></CODE></TD></TR></TBODY></TABLE>
<P></P>
<P>Next connect wired nodes and BS and setup TCP traffic between wireless node, 
node_(0) and wired node W(0), and between W(1) and node_(2), as shown below: 
<TABLE cellPadding=5 bgColor=#eeeeee>
  <TBODY>
  <TR>
    <TD><CODE><PRE>#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 connections
set tcp1 [new Agent/TCP]
$tcp1 set class_ 2
set sink1 [new Agent/TCPSink]
$ns_ attach-agent $node_(0) $tcp1
$ns_ attach-agent $W(0) $sink1
$ns_ connect $tcp1 $sink1
set ftp1 [new Application/FTP]
$ftp1 attach-agent $tcp1
$ns_ at $opt(ftp1-start) "$ftp1 start"

⌨️ 快捷键说明

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