Hi, 

 

I am a newer. When I use nrlolsr as adhoc routing protocol for
wired-cum-wireless simulation with the following script in NS2, I found
the udp connection can be set up between wired and wireless nodes, but
the tcp communication can't work. Do you have any idea what's wrong?

 

Basically, my tcl script is based the example of "wireless2.tcl" which
is using DSDV routing protocol. In "wireless2.tcl", the TCP link can be
created between wireless node and wired node after a gateway node is
defined as base-station. I am trying to do same thing but it seems it
doesn't work.

 

 

Do you think there is any chance to use HNA message for gateway
discovery in NS2 simulations? How can I simulate wired-cum-wireless
scenario by using HNA message to detect the gateway which has two
interfaces? 

 

Regards,

Hailing

 

 

# ======================================================================

 

# Define options

 

# ======================================================================

 

set opt(namfile)         out.nam

 

set opt(tracefile)       out.tr

 

set opt(x)               500;                #x dimension of the
topography

 

set opt(y)               500;                #y dimension of the
topography

 

set opt(wirelessNodes)   3;                  #mobile nodes

 

set opt(wiredNodes)      2;                  #hosts and routers

 

               

 

set  gatewayNodes    1;                  #gateways

 

 

 

set val(stop)            60.0;               #simulation time

 

set val(start-src)       0

 

set val(stop-src)        60.0

 

 

 

 

 

set val(chan)           Channel/WirelessChannel    ;# channel type

 

set val(prop)           Propagation/TwoRayGround   ;# radio-propagation

model

 

set val(netif)          Phy/WirelessPhy            ;# network interface
type

 

set val(mac)            Mac/802_11                 ;# MAC type

 

set val(ifq)            Queue/DropTail/PriQueue    ;# interface queue
type

 

set val(ll)             LL                         ;# link layer type

 

set val(ant)            Antenna/OmniAntenna        ;# antenna model

 

set val(ifqlen)         50                         ;# max packet in ifq

 

set val(nn)             3                         ;# number of
mobilenodes

 

set val(rp)             ProtolibManetKernel         ;# routing protocol

 

 

 

 

 

# ======================================================================

 

 

 

#---------------------------

 

#Initialize Global Variables

 

#---------------------------

 

#create a simulator object

 

set ns [new Simulator]

 

$ns color 0 Brown

 

 

 

#----------------------------------------

 

#Define The Hierachial Topology Structure

 

#----------------------------------------

 

$ns node-config -addressType hierarchical

 

#Nbr of domains

 

AddrParams set domain_num_ 2

 

#Nbr of clusters (=subdomains) in each domain

 

lappend clusterNbr 2 1 

 

# API fuction 

 

AddrParams set cluster_num_ $clusterNbr

 

#Nbr of nodes in each cluster

 

lappend eilastlevel 1 1 4 

 

AddrParams set nodes_num_ $eilastlevel

 

 

 

 

 

#create trace objects for ns and nam

 

#$ns use-newtrace

 

set nstrace [open $opt(tracefile) w]

 

$ns trace-all $nstrace

 

 

 

set namtrace [open $opt(namfile) w]

 

$ns namtrace-all-wireless $namtrace $opt(x) $opt(y)

 

 

 

 

 

#create a topology object and define topology (500mx500m)

 

set topo [new Topography]

 

$topo load_flatgrid $opt(x) $opt(y)

 

 

 

 

 

#create God (General Operations Director)

 

 

 

create-god [expr $opt(wirelessNodes)+$gatewayNodes]

 

#create wired nodes

 

set temp {0.0.0 0.1.0}

 

for {set i 0} {$i < $opt(wiredNodes)} {incr i} {

 

    set host($i) [$ns node [lindex $temp $i]]

 

}

 

 

 

#--------------------------------------

 

#Configure for Gateway and Mobile Nodes

 

#--------------------------------------

 

#Use hierarchical addresses for GWs and MNs

 

 

 

#configure for mobile nodes and gateways

 

 

 

 

 

set chan_1_ [new $val(chan)]

 

 

 

 

 

$ns node-config -adhocRouting $val(rp) \

 

            -llType $val(ll) \

 

            -macType $val(mac) \

 

            -ifqType $val(ifq) \

 

            -ifqLen $val(ifqlen) \

 

            -antType $val(ant) \

 

            -propType $val(prop) \

 

            -phyType $val(netif) \

 

            -channel $chan_1_ \

 

            -topoInstance $topo \

 

            -agentTrace ON \

 

            -routerTrace ON \

 

            -macTrace OFF \

 

            -movementTrace ON

 

 

 

#configure for gateways

 

$ns node-config -wiredRouting ON

 

 

 

#create gateway

 

set gw(0) [$ns node 1.0.0]

 

 

 

 

 

set p(0) [new Agent/NrlolsrAgent]

 

$ns attach-agent $gw(0) $p(0)

 

$ns at 0.0 "$p(0) startup -tcj .75 -hj .5 -tci 2.5 -hi .5 -d 8 -l
/tmp/olsr.log"

 

[$gw(0) set ragent_] attach-manet $p(0)

 

$p(0) attach-protolibManetKernel [$gw(0) set ragent_]

 

 

 

 

 

 

 

#set initial coordinates

 

$gw(0) set X_ 200.0

 

$gw(0) set Y_ 200.0

 

$gw(0) set Z_ 0.0

 

$ns at 0.00 "$gw(0) setdest 200 200 20"

 

 

 

#configure for mobile nodes

 

$ns node-config -wiredRouting OFF

 

#create mobile nodes in the same domain as gw(0)

 

set temp {1.0.1 1.0.2 1.0.3}

 

for {set i 3} {$i < $opt(wirelessNodes)+3} {incr i} {

 

    set mobile($i) [$ns node [lindex $temp [expr $i-3]]]

 

    $mobile($i) base-station [AddrParams addr2id [$gw(0) node-addr]]

 

    $mobile($i) random-motion 1

 

      set p($i) [new Agent/NrlolsrAgent]

 

      $ns attach-agent $mobile($i) $p($i)

 

      $ns at 0.0 "$p($i) startup -tcj .75 -hj .5 -tci 2.5 -hi .5 -d 8 -l
/tmp/olsr.log"

 

      [$mobile($i) set ragent_] attach-manet $p($i)

 

      $p($i) attach-protolibManetKernel [$mobile($i) set ragent_]

 

                        ;# enable random motion

 

}

 

 

 

$mobile(3) set X_ 100

 

$mobile(3) set Y_ 300

 

$mobile(3) set Z_ 0.0

 

 

 

$mobile(4) set X_ 300

 

$mobile(4) set Y_ 300

 

$mobile(4) set Z_ 0.0

 

 

 

$mobile(5) set X_ 400

 

$mobile(5) set Y_ 200

 

$mobile(5) set Z_ 0.0

 

 

 

puts ""

 

puts "host0 = [$host(0) node-addr] = [AddrParams addr2id [$host(0)
node-addr]]"

 

puts "host1 = [$host(1) node-addr] = [AddrParams addr2id [$host(1)
node-addr]]"

 

puts "gw0 = [$gw(0) node-addr] = [AddrParams addr2id [$gw(0)
node-addr]]"

 

for {set i 3} {$i < $opt(wirelessNodes)+3} {incr i} {

 

    puts "mobile($i) = [$mobile($i) node-addr] = [AddrParams addr2id

[$mobile($i) node-addr]]"

 

}

 

puts ""

 

 

 

$host(0) color blue

 

$host(1) color blue

 

$gw(0) color red 

 

$host(0) shape box

 

$host(1) shape box

 

$gw(0) shape hexagon

 

 

 

 

 

 

 

$ns at 0.0 "$host(0) label \"HOST 0\""

 

$ns at 0.0 "$host(1) label \"HOST 1\""

 

$ns at 0.0 "$gw(0) label GATEWAY"

 

for {set i 3} {$i < $opt(wirelessNodes)+3} {incr i} {

 

    $ns at 0.0 "$mobile($i) label \"MN $i\""

 

}

 

 

 

 

 

#create links between wired nodes and gateway node

 

$ns duplex-link $host(0) $host(1) 5Mb 100ms DropTail

 

$ns duplex-link $host(1) $gw(0) 5Mb 50ms DropTail

 

 

 

$ns duplex-link-op $host(0) $host(1) orient right

 

$ns duplex-link-op $host(1) $gw(0) orient right-up

 

 

 

#---------------------

 

#Setup Traffic

 

#---------------------

 

# Set a TCP connection between host(1) and mobile(4)

 

set tcp1 [new Agent/TCP]

 

$tcp1 set class_ 2

 

set sink1 [new Agent/TCPSink]

 

$ns attach-agent $host(1) $tcp1

 

$ns attach-agent $mobile(4) $sink1

 

$ns connect $tcp1 $sink1

 

set ftp1 [new Application/FTP]

 

$ftp1 attach-agent $tcp1

 

$ns at 0.0 "$ftp1 start" 

 

puts "ftp1 start!!!"

 

 

 

#MN5 ==> HOST1

 

set src [new Agent/UDP]

 

set dst [new Agent/Null]

 

$ns attach-agent $mobile(5) $src

 

$ns attach-agent $host(1) $dst

 

#$src set fid_ 0

 

$ns connect $src $dst

 

 

 

 

 

set cbr [new Application/Traffic/CBR]

 

$cbr attach-agent $src

 

$cbr set packetSize_ 512

 

$cbr set interval_ 0.1

 

$ns at $val(start-src) "$cbr start"

 

$ns at $val(stop-src) "$cbr stop"

 

 

 

$ns at $val(start-src) "$ns trace-annotate \"MN 5 ==> HOST 1 at

t=$val(start-src) s!\""

 

 

 

#---------------------

 

#Setup Node Movement

 

#---------------------

 

$ns at 0.5 "$mobile(5) setdest 100 450 10"

 

$ns at 0.5 "$ns trace-annotate \"MN 5 starts moving at t=0.5 s.\""

 

$ns at 0.5 "$mobile(5) add-mark m1 green circle"

 

 

 

 

 

 

 

#-----------------------------------

 

#Define Node Initial Position In Nam

 

#-----------------------------------

 

#20 defines the node size in nam, must adjust it according to your
scenario

 

#The function must be called after mobility model is defined

 

for {set i 3} {$i < $opt(wirelessNodes)+3} {incr i} {

 

    $ns initial_node_pos $mobile($i) 20

 

}

 

 

 

#-----------------------------------

 

#Tell Nodes When The Simulation Ends

 

#-----------------------------------

 

for {set i 3} {$i < $opt(wirelessNodes)+3} {incr i} {

 

    $ns at $val(stop).0 "$mobile($i) reset";

 

}

 

$ns at $val(stop).0 "$gw(0) reset";

 

$ns at $val(stop).0001 "stop"

 

$ns at $val(stop).0002 "puts \"NS EXITING...\" ; $ns halt"

 

 

 

proc stop {} {

 

    global ns nstrace namtrace opt

 

    $ns flush-trace

 

    close $nstrace

 

    close $namtrace

 

    exec nam $opt(namfile) &

 

    exit 0

 

}

 

 

 

puts "Starting simulation..."

 

$ns at 0.0 "$ns set-animation-rate 5ms"

 

 

 

$ns run

 

 

 

 

Reply via email to