Hi

I have created a simple routing agent for wireless nodes that
broadcasts the data packets generated by that node to the neighbors.
The nodes which receive this packet print that they have received it
and do not do anything else. I have not created any new packet type as
i'm forwarding whatever is coming from above layers.

In a simulation (script-test.tcl attached) i created a
UDP flow from node 9 to node 0. Since the routing protocol allows
packet to reach only upto the next hop the packet will never reach
node 0.

But i found a strange thing. When i send packet to the next hop as
broadcast, the packet was delivered to node 4 which is very far from
node 9, but when i unicast  the packet with next hop  as 4 it never
reaches node 4.

I'm not able to find any reason for this can you please help me out in
figuring out if anything is missing in my code or configuration?

recv function and the simulation script  that i have used are given below.

Thanks
Amit Khanna

--------------------CODE---------------------------
void
Protoname::recv(Packet* p, Handler* h) {
   struct hdr_cmn *ch =HDR_CMN(p);
       ch->next_hop()=IP_BROADCAST;
       ch->direction() = hdr_cmn::DOWN;
       ch->addr_type() = NS_AF_INET;
       struct hdr_ip *ih = HDR_IP(p);
       //UNCOMMENT HERE
       //ch->next_hop()=4; //uncomment this and packets do not reach node 4
       printf("Node %d:received packet from %d\n", ra_addr(), ih->saddr());
       //if i'm the originator of the packet
       if(ih->saddr()==ra_addr()){
               //if the loop exists drop the packet
               if(ch->num_forwards() >0){
                       drop(p, DROP_RTR_ROUTE_LOOP);
                       return;
               }
               else if (ch->num_forwards() == 0)
                       ch->size() += IP_HDR_LEN;


       }
       if(ih->saddr()==ra_addr()){
               printf("Node %d:broadcasting\n", ra_addr());
                       Scheduler::instance().schedule(target_, p, 0.0);
       }
}
--------------------CODE----------------------------

-------------------------script-test.tcl---------------
# ======================================================================
# Define options
# ======================================================================
set opt(chan)           Channel/WirelessChannel  ;# channel type
set opt(prop)           Propagation/TwoRayGround   ;# radio-propagation model
set opt(netif)          Phy/WirelessPhy          ;# network interface type
set opt(mac)            Mac/802_11               ;# MAC type
set opt(ifq)            Queue/DropTail/PriQueue  ;# interface queue type
set opt(ll)             LL                       ;# link layer type
set opt(ant)            Antenna/OmniAntenna      ;# antenna model
set opt(ifqlen)         50                       ;# max packet in ifq
set opt(nn)             11                       ;# number of mobilenodes
set opt(adhocRouting)   Protoname                 ;# routing protocol

set opt(cp)             ""                       ;# connection pattern file
set opt(sc)             ""                       ;# node movement file.

set opt(x)              1000                     ;# x coordinate of topology
set opt(y)              1000                     ;# y coordinate of topology
set opt(seed) X
set opt(stop)           100                       ;# time to stop simulation

set opt(cbr-start)      45.0
set opt(cbr-stop)       95.0
set opt(pa-start)       7.0
set opt(pa-stop)        37.0
set opt(pa1-start)      9.0
set opt(pa1-stop)       39.0
# ============================================================================

#
# check for random seed
#
if {$opt(seed) > 0} {
    puts "Seeding Random number generator with $opt(seed)\n"
    ns-random $opt(seed)
}

Antenna/OmniAntenna set Gt_ 18.0
Antenna/OmniAntenna set Gr_ 18.0

Phy/WirelessPhy set bandwidth_ 11Mb

Phy/WirelessPhy set freq_ 2.4e+9

Mac/802_11 set dataRate_ 11Mb
Mac/802_11 set basicRate_ 2Mb

Propagation/TwoRayGround set L_ 1.0

#
# create simulator instance
#
set ns_ [new Simulator]

# open traces
$ns_ use-newtrace
set tracefd  [open wtrace.tr w]
set namtrace [open simulation.nam w]
$ns_ trace-all $tracefd
$ns_ namtrace-all-wireless $namtrace $opt(x) $opt(y)

#
# create topography object
#
set topo [new Topography]

#
# define topology
#
$topo load_flatgrid $opt(x) $opt(y)

#
# create God
#
create-god $opt(nn)

#
# configure mobile nodes
#
$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 OFF \
                 -agentTrace ON \
                 -routerTrace ON \
                 -macTrace OFF

for {set i 1} {$i < $opt(nn)} {incr i} {
    set node_($i) [$ns_ node]
}

#
# positions

$node_(1) set X_ 160.0
$node_(1) set Y_ 485.0
$node_(1) set Z_ 15.0

$node_(2) set X_ 305.0
$node_(2) set Y_ 277.0
$node_(2) set Z_ 15.0

$node_(3) set X_ 340.0
$node_(3) set Y_ 226.0
$node_(3) set Z_ 15.0

$node_(4) set X_ 270.0
$node_(4) set Y_ 32.0
$node_(4) set Z_ 15.0

$node_(5) set X_ 476.0
$node_(5) set Y_ 200.0
$node_(5) set Z_ 15.0

$node_(6) set X_ 628.0
$node_(6) set Y_ 320.0
$node_(6) set Z_ 15.0

$node_(7) set X_ 570.0
$node_(7) set Y_ 440.0
$node_(7) set Z_ 15.0

$node_(8) set X_ 780.0
$node_(8) set Y_ 480.0
$node_(8) set Z_ 15.0

$node_(9) set X_ 918.0
$node_(9) set Y_ 597.0
$node_(9) set Z_ 15.0

$node_(10) set X_ 968.0
$node_(10) set Y_ 550.0
$node_(10) set Z_ 15.0

# cores
$ns_ color 1 red
$ns_ color 2 blue
$ns_ color 3 yellow

# setup UDP connection
set udp [new Agent/UDP]
set null [new Agent/Null]
$ns_ attach-agent $node_(10) $udp
$ns_ attach-agent $node_(1) $null
$ns_ connect $udp $null
$udp set fid_ 1
set cbr [new Application/Traffic/CBR]
$cbr set packetSize_ 40
$cbr set rate_ 8Kb
$cbr attach-agent $udp
$ns_ at 5.0 "$cbr start"
$ns_ at 45.0  "$cbr stop"


#
# define initial node position in nam
#
for {set i 1} {$i < $opt(nn)} {incr i} {
    $ns_ initial_node_pos $node_($i) 20
}

#
# tell all nodes when the simulation ends
#
for {set i 1} {$i < $opt(nn) } {incr i} {
    $ns_ at $opt(stop).0 "$node_($i) 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
}

#
# begin simulation
#
puts "Starting Simulation..."

$ns_ run

Reply via email to