OLSR: get main address of the peer from the UDP source address and the 'interface association' table; this way the UDP source address need not be the same as the main address.
authorGustavo J. A. M. Carneiro <gjc@inescporto.pt>
Sun, 03 Feb 2008 18:50:55 +0000
changeset 2306 6f947d8c8f41
parent 2305 518187ed457c
child 2307 2e115ea02b46
OLSR: get main address of the peer from the UDP source address and the 'interface association' table; this way the UDP source address need not be the same as the main address.
src/routing/olsr/olsr-agent-impl.cc
--- a/src/routing/olsr/olsr-agent-impl.cc	Sun Feb 03 18:29:25 2008 +0000
+++ b/src/routing/olsr/olsr-agent-impl.cc	Sun Feb 03 18:50:55 2008 +0000
@@ -346,32 +346,36 @@
       DuplicateTuple *duplicated = m_state.FindDuplicateTuple
         (messageHeader.GetOriginatorAddress (),
          messageHeader.GetMessageSequenceNumber ());
+
+      // Get main address of the peer, which may be different from the packet source address
+      const IfaceAssocTuple *ifaceAssoc = m_state.FindIfaceAssocTuple (inetSourceAddr.GetIpv4 ());
+      Ipv4Address peerMainAddress;
+      if (ifaceAssoc != NULL)
+        {
+          peerMainAddress = ifaceAssoc->mainAddr;
+        }
+      else
+        {
+          peerMainAddress = inetSourceAddr.GetIpv4 () ;
+        }
       
       if (duplicated == NULL)
         {
-          // Note: normally inetSourceAddr.GetIpv4 () should be equal
-          // to messageHeader.GetOriginatorAddress (), but something
-          // was broken inside NS-3 UDP sockets and the ability to
-          // override source address (via Bind()) is no longer
-          // available.  Bottom line is, OLSR packets are no longer
-          // being sent with the main address, and to work around this
-          // issue we look at the Originator Address field of OLSR
-          // messages contained in the packet.
           switch (messageHeader.GetMessageType ())
             {
             case olsr::MessageHeader::HELLO_MESSAGE:
               NS_LOG_DEBUG ("OLSR node received HELLO message of size " << messageHeader.GetSerializedSize ());
-              ProcessHello (messageHeader, m_mainAddress, messageHeader.GetOriginatorAddress ());
+              ProcessHello (messageHeader, m_mainAddress, peerMainAddress);
               break;
 
             case olsr::MessageHeader::TC_MESSAGE:
               NS_LOG_DEBUG ("OLSR node received TC message of size " << messageHeader.GetSerializedSize ());
-              ProcessTc (messageHeader, messageHeader.GetOriginatorAddress ());
+              ProcessTc (messageHeader, peerMainAddress);
               break;
 
             case olsr::MessageHeader::MID_MESSAGE:
               NS_LOG_DEBUG ("OLSR node received MID message of size " << messageHeader.GetSerializedSize ());
-              ProcessMid (messageHeader, messageHeader.GetOriginatorAddress ());
+              ProcessMid (messageHeader, peerMainAddress);
               break;
 
             default:
@@ -404,7 +408,7 @@
           // Remaining messages are also forwarded using the default algorithm.
           if (messageHeader.GetMessageType ()  != olsr::MessageHeader::HELLO_MESSAGE)
             ForwardDefault (messageHeader, duplicated,
-                            m_mainAddress, messageHeader.GetOriginatorAddress ());
+                            m_mainAddress, peerMainAddress);
         }
 	
     }