src/internet-node/ipv4-end-point-demux.cc
changeset 1504 36ecc970ba96
parent 984 3202c053eacc
child 1513 d16f6fd70397
--- a/src/internet-node/ipv4-end-point-demux.cc	Thu Sep 13 12:37:30 2007 -0700
+++ b/src/internet-node/ipv4-end-point-demux.cc	Thu Sep 13 17:47:42 2007 -0700
@@ -21,18 +21,21 @@
 
 #include "ipv4-end-point-demux.h"
 #include "ipv4-end-point.h"
-#include "ns3/debug.h"
+#include "ns3/log.h"
 
 namespace ns3{
 
-NS_DEBUG_COMPONENT_DEFINE ("Ipv4EndPointDemux");
+NS_LOG_COMPONENT_DEFINE ("Ipv4EndPointDemux");
 
 Ipv4EndPointDemux::Ipv4EndPointDemux ()
   : m_ephemeral (1025)
-{}
+{
+  NS_LOG_FUNCTION;
+}
 
 Ipv4EndPointDemux::~Ipv4EndPointDemux ()
 {
+  NS_LOG_FUNCTION;
   for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) 
     {
       Ipv4EndPoint *endPoint = *i;
@@ -44,6 +47,7 @@
 bool
 Ipv4EndPointDemux::LookupPortLocal (uint16_t port)
 {
+  NS_LOG_FUNCTION;
   for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) 
     {
       if ((*i)->GetLocalPort  () == port) 
@@ -57,6 +61,7 @@
 bool
 Ipv4EndPointDemux::LookupLocal (Ipv4Address addr, uint16_t port)
 {
+  NS_LOG_FUNCTION;
   for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) 
     {
       if ((*i)->GetLocalPort () == port &&
@@ -71,44 +76,49 @@
 Ipv4EndPoint *
 Ipv4EndPointDemux::Allocate (void)
 {
-  NS_DEBUG ("Ipv4EndPointDemux::Allocate ()");
+  NS_LOG_FUNCTION;
   uint16_t port = AllocateEphemeralPort ();
   if (port == 0) 
     {
-      NS_DEBUG ("Ipv4EndPointDemux::Allocate ephemeral port allocation failed.");
+      NS_LOG_WARN ("Ephemeral port allocation failed.");
       return 0;
     }
   Ipv4EndPoint *endPoint = new Ipv4EndPoint (Ipv4Address::GetAny (), port);
   m_endPoints.push_back (endPoint);
   return endPoint;
 }
+
 Ipv4EndPoint *
 Ipv4EndPointDemux::Allocate (Ipv4Address address)
 {
-  NS_DEBUG ("Ipv4EndPointDemux::Allocate (address=" << address << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << address << ")");
   uint16_t port = AllocateEphemeralPort ();
   if (port == 0) 
     {
-      NS_DEBUG ("Ipv4EndPointDemux::Allocate ephemeral port allocation failed.");
+      NS_LOG_WARN ("Ephemeral port allocation failed.");
       return 0;
     }
   Ipv4EndPoint *endPoint = new Ipv4EndPoint (address, port);
   m_endPoints.push_back (endPoint);
   return endPoint;
 }
+
 Ipv4EndPoint *
 Ipv4EndPointDemux::Allocate (uint16_t port)
 {
+  NS_LOG_FUNCTION;
   return Allocate (Ipv4Address::GetAny (), port);
 }
+
 Ipv4EndPoint *
 Ipv4EndPointDemux::Allocate (Ipv4Address address, uint16_t port)
 {
-  NS_DEBUG ("Ipv4EndPointDemux::Allocate (address=" << address
-            << ", port=" << port << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(" << address << ", " << port << ")");
   if (LookupLocal (address, port)) 
     {
-      NS_DEBUG ("Ipv4EndPointDemux::Allocate duplicate address/port; failing.");
+      NS_LOG_WARN ("Duplicate address/port; failing.");
       return 0;
     }
   Ipv4EndPoint *endPoint = new Ipv4EndPoint (address, port);
@@ -120,10 +130,11 @@
 Ipv4EndPointDemux::Allocate (Ipv4Address localAddress, uint16_t localPort,
 			     Ipv4Address peerAddress, uint16_t peerPort)
 {
-  NS_DEBUG ("Ipv4EndPointDemux::Allocate (localAddress=" << localAddress
-            << ", localPort=" << localPort
-            << ", peerAddress=" << peerAddress
-            << ", peerPort=" << peerPort << ")");
+  NS_LOG_FUNCTION;
+  NS_LOG_PARAM ("(localAddress=" << localAddress
+    << ", localPort=" << localPort
+    << ", peerAddress=" << peerAddress
+    << ", peerPort=" << peerPort << ")");
   for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) 
     {
       if ((*i)->GetLocalPort () == localPort &&
@@ -131,7 +142,7 @@
           (*i)->GetPeerPort () == peerPort &&
           (*i)->GetPeerAddress () == peerAddress) 
         {
-          NS_DEBUG ("Ipv4EndPointDemux::Allocate: no way we can allocate this end-point.");
+          NS_LOG_WARN ("No way we can allocate this end-point.");
           /* no way we can allocate this end-point. */
           return 0;
         }
@@ -145,6 +156,7 @@
 void 
 Ipv4EndPointDemux::DeAllocate (Ipv4EndPoint *endPoint)
 {
+  NS_LOG_FUNCTION;
   for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) 
     {
       if (*i == endPoint)
@@ -156,7 +168,6 @@
     }
 }
 
-
 /*
  * If we have an exact match, we return it.
  * Otherwise, if we find a generic match, we return it.
@@ -166,40 +177,42 @@
 Ipv4EndPointDemux::Lookup (Ipv4Address daddr, uint16_t dport, 
                            Ipv4Address saddr, uint16_t sport)
 {
+  NS_LOG_FUNCTION;
   uint32_t genericity = 3;
   Ipv4EndPoint *generic = 0;
   EndPoints retval;
 
-  NS_DEBUG ("Ipv4EndPointDemux::Lookup (daddr=" << daddr << ", dport=" << dport
-            << ", saddr=" << saddr << ", sport=" << sport
-            << ")");
+  NS_LOG_PARAM ("(daddr=" << daddr << ", dport=" << dport
+    << ", saddr=" << saddr << ", sport=" << sport << ")");
+
   for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) 
     {
-      NS_DEBUG ("Ipv4EndPointDemux::Lookup against " << 
-                (*i)->GetLocalAddress ()
-                << ":" << 
-                (*i)->GetLocalPort () 
-                << " " << 
-                (*i)->GetPeerAddress () 
-                << ":" 
-                << (*i)->GetPeerPort ());
+      NS_LOG_LOGIC ("Ipv4EndPointDemux::Lookup against " << 
+                    (*i)->GetLocalAddress ()
+                    << ":" << 
+                    (*i)->GetLocalPort () 
+                    << " " << 
+                    (*i)->GetPeerAddress () 
+                    << ":" 
+                    << (*i)->GetPeerPort ());
+
       if ((*i)->GetLocalPort () != dport) 
         {
           continue;
         }
-      NS_DEBUG ("Ipv4EndPointDemux::Lookup local address matches: "
-                << bool ((*i)->GetLocalAddress () == daddr || daddr.IsBroadcast ()));
-      NS_DEBUG ("Ipv4EndPointDemux::Lookup peer port matches: "
-                << bool ((*i)->GetPeerPort () == sport || sport == 0));
-      NS_DEBUG ("Ipv4EndPointDemux::Lookup peer address matches: "
-                << bool ((*i)->GetPeerAddress () == saddr ||
-                         (*i)->GetPeerAddress () == Ipv4Address::GetAny ()));
+      NS_LOG_LOGIC ("Local address matches: " << 
+        bool ((*i)->GetLocalAddress () == daddr || daddr.IsBroadcast ()));
+      NS_LOG_LOGIC ("Peer port matches: " << 
+        bool ((*i)->GetPeerPort () == sport || sport == 0));
+      NS_LOG_LOGIC ("Peer address matches: " << 
+        bool ((*i)->GetPeerAddress () == saddr ||
+        (*i)->GetPeerAddress () == Ipv4Address::GetAny ()));
       
       if ( ((*i)->GetLocalAddress () == daddr || daddr.IsBroadcast ())
            && ((*i)->GetPeerPort () == sport || (*i)->GetPeerPort () == 0)
            && ((*i)->GetPeerAddress () == saddr || (*i)->GetPeerAddress () == Ipv4Address::GetAny ()))
         {
-          NS_DEBUG ("Ipv4EndPointDemux::Lookup MATCH");
+          NS_LOG_LOGIC ("MATCH");
           /* this is an exact match. */
           retval.push_back (*i);
         }
@@ -228,6 +241,7 @@
 uint16_t
 Ipv4EndPointDemux::AllocateEphemeralPort (void)
 {
+  NS_LOG_FUNCTION;
   uint16_t port = m_ephemeral;
   do 
     {