Callbacks at RouteInput in AODVRoutingProtocol

302 views
Skip to first unread message

Ricardo G.

unread,
Mar 25, 2014, 8:03:09 PM3/25/14
to ns-3-...@googlegroups.com
Hi,

I'm using the AODV model as a base to create my own routing protocol. In the RouteInput method it calls to the callbacks defined in the Ipv4RoutingProtocol, I've seen the documentation (here) but I can't figure out what these callbacks call back. Can someone explain it to me?

For instance:

bool
RoutingProtocol::RouteInput (Ptr<const Packet> p, const Ipv4Header &header,
                             
Ptr<const NetDevice> idev, UnicastForwardCallback ucb,
                             
MulticastForwardCallback mcb, LocalDeliverCallback lcb, ErrorCallback ecb)
{
            // Code

            if (lcb.IsNull () == false)
             
{
                NS_LOG_LOGIC
("Broadcast local delivery to " << iface.GetLocal ());
                lcb
(p, header, iif); // Here there is a callback
               
// Fall through to additional processing
             
}
           
else
             
{
                NS_LOG_ERROR
("Unable to deliver packet locally due to null callback " << p->GetUid () << " from " << origin);
                ecb
(p, header, Socket::ERROR_NOROUTETOHOST); // Here there is a callback
             
}
           
if (!EnableBroadcast)
             
{
                NS_LOG_LOGIC
("EnableBroadcast = false");
               
return true;
             
}
             
else
             
{
                NS_LOG_LOGIC
("EnableBroadcast = true");
             
}
           
if (header.GetTtl () > 1)
             
{
                NS_LOG_LOGIC
("Forward broadcast. TTL " << (uint16_t) header.GetTtl ());
               
RoutingTableEntry toBroadcast;
               
if (m_routingTable.LookupRoute (dst, toBroadcast))
                 
{
                   
Ptr<Ipv4Route> route = toBroadcast.GetRoute ();
                    ucb
(route, packet, header); // Here there is a callback                 
                  }
               
else
                 
{
                    NS_LOG_DEBUG
("No route to forward broadcast. Drop packet " << p->GetUid ());
                 
}
             
}
           
else
             
{
                NS_LOG_DEBUG
("TTL "<<header.GetTtl()<<" exceeded. Drop packet " << p->GetUid ());
             
}
           
return true;

            // More code
}

And additionally, what does happen when this method returns true or false?

Thanks! :)

Konstantinos

unread,
Mar 25, 2014, 8:11:47 PM3/25/14
to ns-3-...@googlegroups.com
Hi,

Here is the documentation for routing in NS-3 

The callbacks are used to pass the packets to upper/lower layers. The names should be self explanatory. 

The return is explained in the link you posted
"true if the Ipv4RoutingProtocol takes responsibility for forwarding or delivering the packet, false otherwise"


Ricardo G.

unread,
Mar 25, 2014, 8:34:30 PM3/25/14
to ns-3-...@googlegroups.com
Thanks a lot for your quick answer.

I see now what does happen in three cases, but what happens in case of error callback?

And yes, I read that. I think I dind't explained myself correctly. I suppose if RouteInput returns true the packet is not taken by the upper layer protocol to take care of it, and if it returns false the packet is handled by the upper layer protocol. Am I correct?

Tommaso Pecorella

unread,
Mar 26, 2014, 2:50:33 AM3/26/14
to ns-3-...@googlegroups.com
Hi,

nope. The return value is to indicate that the routing protocol handled the packet in some way. Even discarding it it's a valid way to handle the packet.

This may be definitely confusing, I know. The pint is: you can have multiple routing protocols in a node.

To make the long story short. You can have five possibilities when RouteInput is called:
  1. The packet is for the localhost: "lcb" callback is used.
  2. The packet is to be forwarded and it's unicast: "ucb" callback is used.
  3. The packet is to be forwarded and it's multicast: "mcb" callback is used.
  4. The packet is to be discarded: "ecb" callback is used (this will basically log the packet and discard it).
  5. The routing protocol can't figure out what to do. 
In the 5th case, no callback is used and the routing protocol will return false.

This is used by List Routing, which is, basically, calling all the routing protocols installed in a node (according to their priority order) until one of them returns true.
If no routing protocol is able to handle the packet, the packet will be discarded (equivalent to calling ecb).

As a consequence, if you want to be sure to trash a packet, use ecb and return true.


Hope this helps,

T.

Ricardo G.

unread,
Mar 26, 2014, 12:03:08 PM3/26/14
to ns-3-...@googlegroups.com
Hi Tommaso,

Thank you so much, I get it now. You made it so clear. Again, thanks!

gabriela

unread,
Apr 25, 2016, 5:29:58 PM4/25/16
to ns-3-users
Hello,

Where does RouteInput get called ?

In my simulation, SendPacketFromQueue is called at the sender node, but (sometimes) the packet just vanish, never reaching the receiver. I noticed that RouteInput does not get called at the receiver. In order to understand what is going on, I need to known where it is called.

Can you help me?

Thank you in advance.

Tommaso Pecorella

unread,
Apr 25, 2016, 6:33:22 PM4/25/16
to ns-3-users
grep -r RouteInput src/internet/model/

it will return a lot of things, but if you know a bit of C++ the answer is obvious.

T.

PS: don't reply to dead threads, unless absolutely necessary.

gabriela

unread,
Apr 26, 2016, 1:14:20 PM4/26/16
to ns-3-users
Okay, sorry. 
Thank you for the reply.
Reply all
Reply to author
Forward
0 new messages