RouteInput and Multicast Forwarding on ad hoc networks

73 views
Skip to first unread message

Sergio Maeso

unread,
Oct 30, 2016, 7:39:24 AM10/30/16
to ns-3-users
Hi!

I'm writing a simple routing protocol that should perform classic flooding of multicast packets (RFC6621). For that purpose I write an scenario with 25 wireless nodes placed on a 5X5 rectangular configuration without movement, connected by using ad-hoc wifi. The distance between the nodes is far enough so that just the nearest nodes can speak to each other. One of the nodes (23 with IP = 10.1.1.24) send 1 packet to a multicast address to test the routing module.

I wrote some methods for my routing protocol like these ones (which I think are the most important) :

        Ptr<Ipv4MulticastRoute> RoutingProtocol::LookupStatic(Ipv4Address origin,Ipv4Address group,uint32_t interface, uint8_t ttl) {
            Ptr<Ipv4MulticastRoute> mrtentry = 0;
            mrtentry = Create<Ipv4MulticastRoute> ();
            mrtentry->SetGroup(group);
            mrtentry->SetOrigin(origin);
            mrtentry->SetParent(iidout);
            mrtentry->SetOutputTtl(iidout,ttl);
            return mrtentry;
        }

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

            NS_ASSERT(m_ipv4 != 0); // Check if input device supports IP
            NS_ASSERT(m_ipv4->GetInterfaceForDevice(idev) >= 0);
           
            Ipv4Address dst = header.GetDestination ();
            Ipv4Address origin = header.GetSource ();
            Ipv4Address m_mainAddress = getMainLocalAddr();
            uint32_t outif = m_ipv4->GetInterfaceForDevice(idev);
            uint8_t outttl = header.GetTtl();
            if (origin==m_mainAddress){
                return true;                // Consume self-originated packets
            }
            if(outttl<1){
                return true;
            }
            if (dst.IsMulticast()) {    // If it is multicast
                Ptr<Ipv4MulticastRoute> mrtentry = LookupStatic(origin,dst, outif, outttl);
                if (mrtentry){

                    // checkhash just checks if the packet has been already sent

                    if(checkhash(p,origin)) {
                        NS_LOG_INFO("FORWARD from " << mrtentry->GetOrigin() << " to "<< mrtentry->GetGroup()<< " via "<< outif << " TTL:"<< unsigned(outttl)-1);
                        mcb(mrtentry, p, header);
                        return true;
                    }
                    else{
                        return false;
                    }
                }
              
            }
            return false;
        }


But the output is this:

At time 25s client sent 21 bytes to 224.0.1.187 port 5683 type DISCOVERY

At time 25.0009s server received 21 bytes from 10.1.1.24 port 49153 (DISCOVERY)
At time 25.0009s server sent 122 bytes to 10.1.1.24 port 49153
PACKET: 10.1.1.24ns3::UdpHeader (length: 29 49153 > 5683) Payload (size=21) HASH  : 882363410 (NEW)
FORWARD from 10.1.1.24 to 224.0.1.187 via 1 TTL:63

At time 25.0009s server received 21 bytes from 10.1.1.24 port 49153 (DISCOVERY)
At time 25.0009s server sent 122 bytes to 10.1.1.24 port 49153
PACKET: 10.1.1.24ns3::UdpHeader (length: 29 49153 > 5683) Payload (size=21) HASH  : 882363410 (NEW)
FORWARD from 10.1.1.24 to 224.0.1.187 via 1 TTL:63

At time 25.0009s server received 21 bytes from 10.1.1.24 port 49153 (DISCOVERY)
At time 25.0009s server sent 122 bytes to 10.1.1.24 port 49153
PACKET: 10.1.1.24ns3::UdpHeader (length: 29 49153 > 5683) Payload (size=21) HASH  : 882363410 (NEW)
FORWARD from 10.1.1.24 to 224.0.1.187 via 1 TTL:63

At time 25.0009s server received 21 bytes from 10.1.1.24 port 49153 (DISCOVERY)
At time 25.0009s server sent 122 bytes to 10.1.1.24 port 49153
PACKET: 10.1.1.24ns3::UdpHeader (length: 29 49153 > 5683) Payload (size=21) HASH  : 882363410 (REPEATED)

At time 25.0009s server received 21 bytes from 10.1.1.24 port 49153 (DISCOVERY)
At time 25.0009s server sent 122 bytes to 10.1.1.24 port 49153
PACKET: 10.1.1.24ns3::UdpHeader (length: 29 49153 > 5683) Payload (size=21) HASH  : 882363410 (REPEATED)

At time 25.0009s server received 21 bytes from 10.1.1.24 port 49153 (DISCOVERY)
At time 25.0009s server sent 122 bytes to 10.1.1.24 port 49153
PACKET: 10.1.1.24ns3::UdpHeader (length: 29 49153 > 5683) Payload (size=21) HASH  : 882363410 (REPEATED)


At time 25.0108s client received 122 bytes from 10.1.1.23 port 5683
At time 25.0129s client received 122 bytes from 10.1.1.19 port 5683
At time 25.0151s client received 122 bytes from 10.1.1.19 port 5683
At time 25.0173s client received 122 bytes from 10.1.1.23 port 5683
At time 26.005s  client received 122 bytes from 10.1.1.25 port 5683
At time 26.0076s client received 122 bytes from 10.1.1.25 port 5683


As you can see, just the nearest nodes receive the packet and answer it. As the code is in a very early stage I did not intend to receive the answer for the nodes that are far away from node 23 but they did not even receive the transmission and that seems strange to me. What am I doing wrong?

Thanks in advance

Sergio Maeso

unread,
Oct 30, 2016, 7:48:02 AM10/30/16
to ns-3-users
Maybe I'm not being clear at the end of this post. It seems that my protocol is doing some kind of weird stuff cause the nodes that receive the transmission seem to forward it just to themselves (that's the reason for the "REPEATED" label on the packets). Why is this happening?

Tommaso Pecorella

unread,
Oct 30, 2016, 7:58:34 PM10/30/16
to ns-3-users
Hi,

without the topology and a more clear log, it's hard to say.
To make the log clearer, add the node ID to the log lines - it's not that obvious that the nodes are processing their own packets.

Last but not least, randomize things. I don't know the RFC, but from a quick check it seems that it's not mentioning the randomization part.
If you have a diamond topology, and a node at one edge sends a message, the next two nodes will hear it (about at the same time) and they will both retransmit it (more or less at the same time).
If you're unlucky, this will end up in a storm of collisions. My suggestion: add some random time to desynchronize stuff.

In any case, while debugging, use a simple line topology. It doesn't have the sync issue and it will help in finding the problem.

Cheers,

T.

Sergio Maeso

unread,
Nov 2, 2016, 5:59:30 AM11/2/16
to ns-3-users
I modified the doce and that's what it dumps.

    [23] At time 25s client sent 21 bytes to 224.0.1.187 port 5683 type DISCOVERY

    [18] At time 25.0009s server 10.1.1.19 received 21 bytes from 10.1.1.24 port 49153 (DISCOVERY)
    [18] At time 25.0009s server 10.1.1.19 sent 122 bytes to 10.1.1.24 port 49153
    [18] PACKET: 10.1.1.24ns3::UdpHeader (length: 29 49153 > 5683) Payload (size=21) HASH  : 882363410 (NEW)
    [18] FORWARD from 10.1.1.24 to 224.0.1.187 via 1 TTL:63

    [22] At time 25.0009s server 10.1.1.23 received 21 bytes from 10.1.1.24 port 49153 (DISCOVERY)
    [22] At time 25.0009s server 10.1.1.23 sent 122 bytes to 10.1.1.24 port 49153
    [22] PACKET: 10.1.1.24ns3::UdpHeader (length: 29 49153 > 5683) Payload (size=21) HASH  : 882363410 (NEW)
    [22] FORWARD from 10.1.1.24 to 224.0.1.187 via 1 TTL:63

    [24] At time 25.0009s server 10.1.1.25 received 21 bytes from 10.1.1.24 port 49153 (DISCOVERY)
    [24] At time 25.0009s server 10.1.1.25 sent 122 bytes to 10.1.1.24 port 49153
    [24] PACKET: 10.1.1.24ns3::UdpHeader (length: 29 49153 > 5683) Payload (size=21) HASH  : 882363410 (NEW)
    [24] FORWARD from 10.1.1.24 to 224.0.1.187 via 1 TTL:63

    [18] At time 25.0009s server 10.1.1.19 received 21 bytes from 10.1.1.24 port 49153 (DISCOVERY)
    [18] At time 25.0009s server 10.1.1.19 sent 122 bytes to 10.1.1.24 port 49153
    [18] PACKET: 10.1.1.24ns3::UdpHeader (length: 29 49153 > 5683) Payload (size=21) HASH  : 882363410 (REPEATED)

    [22] At time 25.0009s server 10.1.1.23 received 21 bytes from 10.1.1.24 port 49153 (DISCOVERY)
    [22] At time 25.0009s server 10.1.1.23 sent 122 bytes to 10.1.1.24 port 49153
    [22] PACKET: 10.1.1.24ns3::UdpHeader (length: 29 49153 > 5683) Payload (size=21) HASH  : 882363410 (REPEATED)

    [24] At time 25.0009s server 10.1.1.25 received 21 bytes from 10.1.1.24 port 49153 (DISCOVERY)
    [24] At time 25.0009s server 10.1.1.25 sent 122 bytes to 10.1.1.24 port 49153
    [24] PACKET: 10.1.1.24ns3::UdpHeader (length: 29 49153 > 5683) Payload (size=21) HASH  : 882363410 (REPEATED)

    [23] At time 25.0108s client received 122 bytes from 10.1.1.23 port 5683
    [23] At time 25.0129s client received 122 bytes from 10.1.1.19 port 5683
    [23] At time 25.0151s client received 122 bytes from 10.1.1.19 port 5683
    [23] At time 25.0173s client received 122 bytes from 10.1.1.23 port 5683
    [23] At time 26.005s client received 122 bytes from 10.1.1.25 port 5683
    [23] At time 26.0076s client received 122 bytes from 10.1.1.25 port 5683


And I think I've a clue! In order to allow the transmission of multicast packets, I added these few lines to my script:

  for( uint32_t a = 0; a < nodes.GetN(); a = a + 1 )
    {
        //NS_LOG_INFO ("\tREGISTERING MULTICAST NODE " << a);
        staticRouting.SetDefaultMulticastRoute(nodes.Get(a),devices.Get(a));
    }

   
The documentation of this function states the following:

    "We tell the routing system what to do in the case where a specific route to a destination multicast group is not found. (..) This method is only used in initially sending packets off of a host. The default multicast route is not consulted during forwarding – exact routes must be specified using AddMulticastRoute for that case."

So I think I should do something like this in order to create routes from each node to every other node (quite a mess):

  for( uint32_t a = 0; a < nodes.GetN(); a = a + 1 )
  {
    Ptr<Node> anode = nodes.Get(a); // Get pointer to ith node in container
    Ptr<Ipv4> aipv4 = anode->GetObject<Ipv4>(); // Get Ipv4 instance of the node
    Ipv4Address mcastIpSource = aipv4->GetAddress (1,0).GetLocal(); // Get Ipv4InterfaceAddress of xth interface.
    NS_LOG_INFO ("\tNODE " << a << ": " << mcastIpSource);
    for( uint32_t b = 0; b < nodes.GetN(); b = b + 1 )
    {
      if(a!=b){
        Ptr<Node> mcastRouter = nodes.Get (b);  // The node in question
        Ptr<NetDevice> inputdev = devices.Get (b);  // The input NetDevice
        staticRouting.AddMulticastRoute (mcastRouter, mcastIpSource, multicastGroup, inputdev, inputdev);
        NS_LOG_INFO ("\t\t--> " << b );

      }
    }
  }
 
I also changed the returns of my routing algorithm to this:

                    if(checkhash(p,origin)) { // If datagram is new
                        uint32_t nodeid = m_ipv4->GetObject<Node>()->GetId();
                        NS_LOG_INFO("["<<nodeid<<"] FORWARD from " << mrtentry->GetOrigin() << " to "<< mrtentry->GetGroup()<< " via "<< outif << " TTL:"<< unsigned(outttl)-1);
                        return false;    // leave the responsability to the beforementioned multicast routes
                    }
                    else{
                        return true;    // I'll take care of it! (And I dont do anything cause is repeated)
                    }

                   
With this changes all the nodes receive the packets (As I can see for the routing algorithm outputs) but the clients that process the packets are still the same (just 22,18 and 24 like before) . I need to figure out how to fix this, but we're advancing at least. Suggestions are welcome, though!!
Reply all
Reply to author
Forward
0 new messages