Cleanup of ipv4endpointdemux and tcpl4protocol
authorRaj Bhattacharjea <raj.b@gatech.edu>
Wed, 12 Mar 2008 15:33:11 -0400
changeset 2364 a78056f7a7b4
parent 2363 fec623ea779b
child 2365 89da0ca7c55e
Cleanup of ipv4endpointdemux and tcpl4protocol
src/internet-node/ipv4-end-point-demux.cc
src/internet-node/tcp-l4-protocol.cc
--- a/src/internet-node/ipv4-end-point-demux.cc	Wed Mar 12 14:52:29 2008 -0400
+++ b/src/internet-node/ipv4-end-point-demux.cc	Wed Mar 12 15:33:11 2008 -0400
@@ -228,8 +228,7 @@
 
       if (isBroadcast)
         {
-          std::cout  << "Found bcast, localaddr " << endP->GetLocalAddress() 
-                     << std::endl;
+          NS_LOG_DEBUG("Found bcast, localaddr " << endP->GetLocalAddress());
         }
 
       if (isBroadcast && (endP->GetLocalAddress() != Ipv4Address::GetAny()))
@@ -259,7 +258,7 @@
         { // Only local port matches exactly
           retval1.push_back(endP);
         }
-      if ((localAddressMatchesExact || ((isBroadcast && localAddressMatchesWildCard)))&&
+      if ((localAddressMatchesExact || (isBroadcast && localAddressMatchesWildCard))&&
           remotePeerMatchesWildCard &&
            remoteAddressMatchesWildCard)
         { // Only local port and local address matches exactly
@@ -280,96 +279,10 @@
     }
 
   // Here we find the most exact match
-  // first some debug
-#ifdef JUST_DEBUG
-  if (!retval4.empty()) std::cout << "Matches 4" << std::endl;
-  else if (!retval3.empty()) std::cout << "Matches 3" << std::endl;
-  else if (!retval2.empty()) std::cout << "Matches 2" << std::endl;
-  else if (!retval1.empty()) std::cout << "Matches 1" << std::endl;
-#endif
-  // end debug
   if (!retval4.empty()) return retval4;
   if (!retval3.empty()) return retval3;
   if (!retval2.empty()) return retval2;
   return retval1;  // might be empty if no matches
-  
-#ifdef REMOVE_FOR_TESTING  
-  uint32_t genericity = 3;
-  Ipv4EndPoint *generic = 0;
-  for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) 
-    {
-      //Ipv4EndPoint* endP = *i;
-      NS_LOG_DEBUG ("Looking at endpoint dport=" << (*i)->GetLocalPort ()
-                    << " daddr=" << (*i)->GetLocalAddress ()
-                    << " sport=" << (*i)->GetPeerPort ()
-                    << " saddr=" << (*i)->GetPeerAddress ());
-      if ((*i)->GetLocalPort () != dport) 
-        {
-          NS_LOG_LOGIC ("Skipping endpoint " << &(*i)
-                        << " because endpoint dport "
-                        << (*i)->GetLocalPort ()
-                        << " does not match packet dport " << dport);
-          continue;
-        }
-      bool isBroadcast = 
-        (daddr.IsBroadcast () ||
-         daddr.IsSubnetDirectedBroadcast (incomingInterface->GetNetworkMask ()));
-      Ipv4Address incomingInterfaceAddr = incomingInterface->GetAddress ();
-
-      NS_LOG_DEBUG ("dest addr " << daddr << " broadcast? " << isBroadcast
-                    << " localInterface="<< (*i)->GetLocalInterface ());
-      bool localAddressMatches;
-      if (isBroadcast)
-        {
-          if ((*i)->GetLocalInterface () == Ipv4Address::GetAny ())
-            {
-              localAddressMatches = true;
-            }
-          else
-            {
-              localAddressMatches = ((*i)->GetLocalInterface () == incomingInterfaceAddr);
-            }
-        }
-      else
-        {
-          localAddressMatches = ((*i)->GetLocalAddress () == daddr);
-        }
-      NS_LOG_LOGIC ("Local address matches: " << localAddressMatches);
-      NS_LOG_LOGIC ("Peer port matches: " << 
-        bool ((*i)->GetPeerPort () == sport || (*i)->GetPeerPort () == 0));
-      NS_LOG_LOGIC ("Peer address matches: " << 
-        bool ((*i)->GetPeerAddress () == saddr ||
-        (*i)->GetPeerAddress () == Ipv4Address::GetAny ()));
-      
-      if ( localAddressMatches
-           && ((*i)->GetPeerPort () == sport || (*i)->GetPeerPort () == 0)
-           && ((*i)->GetPeerAddress () == saddr || (*i)->GetPeerAddress () == Ipv4Address::GetAny ()))
-        {
-          NS_LOG_LOGIC ("MATCH");
-          /* this is an exact match. */
-          retval.push_back (*i);
-        }
-      uint32_t tmp = 0;
-      if ((*i)->GetLocalAddress () == Ipv4Address::GetAny ()) 
-        {
-          tmp ++;
-        }
-      if ((*i)->GetPeerAddress () == Ipv4Address::GetAny ()) 
-        {
-          tmp ++;
-        }
-      if (tmp < genericity) 
-        {
-          generic = (*i);
-          genericity = tmp;
-        }
-    }
-  if (retval.size () == 0 && generic != 0)
-    {
-      retval.push_back (generic);
-    }
-  return retval;
-#endif
 }
 
 uint16_t
--- a/src/internet-node/tcp-l4-protocol.cc	Wed Mar 12 14:52:29 2008 -0400
+++ b/src/internet-node/tcp-l4-protocol.cc	Wed Mar 12 15:33:11 2008 -0400
@@ -429,13 +429,11 @@
     source.Print (oss);
     oss<<" source port: "<<tcpHeader.GetSourcePort ();
     NS_LOG_LOGIC (oss.str ());
+    return;
   }
-  for (Ipv4EndPointDemux::EndPointsI endPoint = endPoints.begin ();
-       endPoint != endPoints.end (); endPoint++)
-    {
-      NS_LOG_LOGIC ("TcpL4Protocol "<<this<<" forwarding up to endpoint/socket");
-      (*endPoint)->ForwardUp (packet, source, tcpHeader.GetSourcePort ());
-    }
+  NS_ASSERT_MSG (endPoints.size() == 1 , "Demux returned more than one endpoint");
+  NS_LOG_LOGIC ("TcpL4Protocol "<<this<<" forwarding up to endpoint/socket");
+  (*endPoints.begin ())->ForwardUp (packet, source, tcpHeader.GetSourcePort ());
 }
 
 void