bug 405: add more context to wifi logging
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Wed, 10 Dec 2008 01:47:59 -0800
changeset 4003 49a08376f196
parent 4002 a12900ea255e
child 4004 b181e89d45f1
bug 405: add more context to wifi logging
src/devices/wifi/adhoc-wifi-mac.cc
src/devices/wifi/mac-low.cc
src/devices/wifi/nqap-wifi-mac.cc
src/devices/wifi/nqsta-wifi-mac.cc
--- a/src/devices/wifi/adhoc-wifi-mac.cc	Wed Dec 10 01:34:04 2008 -0800
+++ b/src/devices/wifi/adhoc-wifi-mac.cc	Wed Dec 10 01:47:59 2008 -0800
@@ -33,6 +33,9 @@
 
 NS_OBJECT_ENSURE_REGISTERED (AdhocWifiMac);
 
+#undef NS_LOG_APPEND_CONTEXT
+#define NS_LOG_APPEND_CONTEXT if (m_low != 0) {std::clog << "[mac=" << m_low->GetAddress () << "] ";}
+
 TypeId 
 AdhocWifiMac::GetTypeId (void)
 {
--- a/src/devices/wifi/mac-low.cc	Wed Dec 10 01:34:04 2008 -0800
+++ b/src/devices/wifi/mac-low.cc	Wed Dec 10 01:47:59 2008 -0800
@@ -31,8 +31,9 @@
 
 NS_LOG_COMPONENT_DEFINE ("MacLow");
 
-#define MY_DEBUG(x) \
-  NS_LOG_DEBUG (m_self << " " << x)
+#undef NS_LOG_APPEND_CONTEXT
+#define NS_LOG_APPEND_CONTEXT std::clog << "[mac=" << m_self << "] "
+
 
 namespace ns3 {
 
@@ -457,7 +458,7 @@
 
   //NS_ASSERT (m_phy->IsStateIdle ());
 
-  MY_DEBUG ("startTx size="<< GetSize (m_currentPacket, &m_currentHdr) << 
+  NS_LOG_DEBUG ("startTx size="<< GetSize (m_currentPacket, &m_currentHdr) << 
             ", to=" << m_currentHdr.GetAddr1()<<", listener="<<m_listener);
 
   if (m_txParams.MustSendRts ()) 
@@ -477,7 +478,7 @@
 MacLow::ReceiveError (Ptr<const Packet> packet, double rxSnr)
 {
   NS_LOG_FUNCTION (this << packet << rxSnr);
-  MY_DEBUG ("rx failed ");
+  NS_LOG_DEBUG ("rx failed ");
   if (m_txParams.MustWaitFastAck ()) 
     {
       NS_ASSERT (m_fastAckFailedTimeoutEvent.IsExpired ());
@@ -500,7 +501,7 @@
   packet->RemoveHeader (hdr);
   
   bool isPrevNavZero = IsNavZero ();
-  MY_DEBUG ("duration/id=" << hdr.GetDuration ());
+  NS_LOG_DEBUG ("duration/id=" << hdr.GetDuration ());
   NotifyNav (hdr, txMode, preamble);
   if (hdr.IsRts ()) 
     {
@@ -513,7 +514,7 @@
       if (isPrevNavZero &&
           hdr.GetAddr1 () == m_self) 
         {
-          MY_DEBUG ("rx RTS from=" << hdr.GetAddr2 () << ", schedule CTS");
+          NS_LOG_DEBUG ("rx RTS from=" << hdr.GetAddr2 () << ", schedule CTS");
           NS_ASSERT (m_sendCtsEvent.IsExpired ());
           WifiRemoteStation *station = GetStation (hdr.GetAddr2 ());
           station->ReportRxOk (rxSnr, txMode);
@@ -526,7 +527,7 @@
         } 
       else 
         {
-          MY_DEBUG ("rx RTS from=" << hdr.GetAddr2 () << ", cannot schedule CTS");
+          NS_LOG_DEBUG ("rx RTS from=" << hdr.GetAddr2 () << ", cannot schedule CTS");
         }
     } 
   else if (hdr.IsCts () &&
@@ -534,7 +535,7 @@
            m_ctsTimeoutEvent.IsRunning () &&
            m_currentPacket != 0) 
     {
-      MY_DEBUG ("receive cts from="<<m_currentHdr.GetAddr1 ());
+      NS_LOG_DEBUG ("receive cts from="<<m_currentHdr.GetAddr1 ());
       SnrTag tag;
       packet->FindFirstMatchingTag (tag);
       WifiRemoteStation *station = GetStation (m_currentHdr.GetAddr1 ());
@@ -557,7 +558,7 @@
             m_superFastAckTimeoutEvent.IsRunning ()) &&
            m_txParams.MustWaitAck ()) 
     {
-      MY_DEBUG ("receive ack from="<<m_currentHdr.GetAddr1 ());
+      NS_LOG_DEBUG ("receive ack from="<<m_currentHdr.GetAddr1 ());
       SnrTag tag;
       packet->FindFirstMatchingTag (tag);
       WifiRemoteStation *station = GetStation (m_currentHdr.GetAddr1 ());
@@ -588,7 +589,7 @@
     } 
   else if (hdr.IsCtl ()) 
     {
-      MY_DEBUG ("rx drop " << hdr.GetTypeString ());
+      NS_LOG_DEBUG ("rx drop " << hdr.GetTypeString ());
     } 
   else if (hdr.GetAddr1 () == m_self) 
     {
@@ -597,11 +598,11 @@
       
       if (hdr.IsQosData () && hdr.IsQosNoAck ()) 
         {
-          MY_DEBUG ("rx unicast/noAck from="<<hdr.GetAddr2 ());
+          NS_LOG_DEBUG ("rx unicast/noAck from="<<hdr.GetAddr2 ());
         } 
       else if (hdr.IsData () || hdr.IsMgt ()) 
         {
-          MY_DEBUG ("rx unicast/sendAck from=" << hdr.GetAddr2 ());
+          NS_LOG_DEBUG ("rx unicast/sendAck from=" << hdr.GetAddr2 ());
           NS_ASSERT (m_sendAckEvent.IsExpired ());
           m_sendAckEvent = Simulator::Schedule (GetSifs (),
                                                 &MacLow::SendAckAfterData, this,
@@ -616,7 +617,7 @@
     {
       if (hdr.IsData () || hdr.IsMgt ()) 
         {
-          MY_DEBUG ("rx broadcast from=" << hdr.GetAddr2 ());
+          NS_LOG_DEBUG ("rx broadcast from=" << hdr.GetAddr2 ());
           goto rxPacket;
         } 
       else 
@@ -626,7 +627,7 @@
     } 
   else 
     {
-      //MY_DEBUG_VERBOSE ("rx not-for-me from %d", GetSource (packet));
+      //NS_LOG_DEBUG_VERBOSE ("rx not-for-me from %d", GetSource (packet));
     }
   return;
  rxPacket:
@@ -825,7 +826,7 @@
                      WifiMode txMode)
 {
   NS_LOG_FUNCTION (this << packet << hdr << txMode);
-  MY_DEBUG ("send " << hdr->GetTypeString () <<
+  NS_LOG_DEBUG ("send " << hdr->GetTypeString () <<
             ", to=" << hdr->GetAddr1 () <<
             ", size=" << packet->GetSize () <<
             ", mode=" << txMode <<
@@ -845,7 +846,7 @@
 MacLow::CtsTimeout (void)
 {
   NS_LOG_FUNCTION (this);
-  MY_DEBUG ("cts timeout");
+  NS_LOG_DEBUG ("cts timeout");
   // XXX: should check that there was no rx start before now.
   // we should restart a new cts timeout now until the expected
   // end of rx if there was a rx start before now.
@@ -860,7 +861,7 @@
 MacLow::NormalAckTimeout (void)
 {
   NS_LOG_FUNCTION (this);
-  MY_DEBUG ("normal ack timeout");
+  NS_LOG_DEBUG ("normal ack timeout");
   // XXX: should check that there was no rx start before now.
   // we should restart a new ack timeout now until the expected
   // end of rx if there was a rx start before now.
@@ -880,12 +881,12 @@
   m_listener = 0;
   if (m_phy->IsStateIdle ()) 
     {
-      MY_DEBUG ("fast Ack idle missed");
+      NS_LOG_DEBUG ("fast Ack idle missed");
       listener->MissedAck ();
     }
   else
     {
-      MY_DEBUG ("fast Ack ok");
+      NS_LOG_DEBUG ("fast Ack ok");
     }
 }
 void
@@ -898,12 +899,12 @@
   m_listener = 0;
   if (m_phy->IsStateIdle ()) 
     {
-      MY_DEBUG ("super fast Ack failed");
+      NS_LOG_DEBUG ("super fast Ack failed");
       listener->MissedAck ();
     } 
   else 
     {
-      MY_DEBUG ("super fast Ack ok");
+      NS_LOG_DEBUG ("super fast Ack ok");
       listener->GotAck (0.0, WifiMode ());
     }
 }
@@ -1128,7 +1129,7 @@
   MacLowTransmissionListener *listener = m_listener;
   m_listener = 0;
   listener->MissedAck ();
-  MY_DEBUG ("fast Ack busy but missed");
+  NS_LOG_DEBUG ("fast Ack busy but missed");
 }
 
 void
--- a/src/devices/wifi/nqap-wifi-mac.cc	Wed Dec 10 01:34:04 2008 -0800
+++ b/src/devices/wifi/nqap-wifi-mac.cc	Wed Dec 10 01:47:59 2008 -0800
@@ -37,6 +37,9 @@
 
 NS_OBJECT_ENSURE_REGISTERED (NqapWifiMac);
 
+#undef NS_LOG_APPEND_CONTEXT
+#define NS_LOG_APPEND_CONTEXT if (m_low != 0) {std::clog << "[mac=" << m_low->GetAddress () << "] ";}
+
 TypeId 
 NqapWifiMac::GetTypeId (void)
 {
--- a/src/devices/wifi/nqsta-wifi-mac.cc	Wed Dec 10 01:34:04 2008 -0800
+++ b/src/devices/wifi/nqsta-wifi-mac.cc	Wed Dec 10 01:47:59 2008 -0800
@@ -36,6 +36,9 @@
 
 NS_LOG_COMPONENT_DEFINE ("NqstaWifiMac");
 
+#undef NS_LOG_APPEND_CONTEXT
+#define NS_LOG_APPEND_CONTEXT if (m_low != 0) {std::clog << "[mac=" << m_low->GetAddress () << "] ";}
+
 /*
  * The state machine for this NQSTA is:
  --------------                                          -----------