bug 279: Packets need metadata support for printing without header checking
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Mon, 25 Aug 2008 15:21:01 -0700
changeset 3553 065488d0420c
parent 3552 b822851cb95d
child 3555 bfea2a4da368
child 3556 1c401259af61
bug 279: Packets need metadata support for printing without header checking
examples/wifi-ap.cc
src/common/packet-metadata.cc
src/common/packet-metadata.h
src/common/packet.cc
src/common/packet.h
src/helper/csma-helper.cc
src/helper/point-to-point-helper.cc
src/helper/wifi-helper.cc
utils/bench-packets.cc
--- a/examples/wifi-ap.cc	Mon Aug 25 15:16:35 2008 -0700
+++ b/examples/wifi-ap.cc	Mon Aug 25 15:21:01 2008 -0700
@@ -110,7 +110,7 @@
 
 int main (int argc, char *argv[])
 {
-  Packet::EnableMetadata ();
+  Packet::EnablePrinting ();
 
   // enable rts cts all the time.
   Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("0"));
--- a/src/common/packet-metadata.cc	Mon Aug 25 15:16:35 2008 -0700
+++ b/src/common/packet-metadata.cc	Mon Aug 25 15:21:01 2008 -0700
@@ -32,6 +32,7 @@
 namespace ns3 {
 
 bool PacketMetadata::m_enable = false;
+bool PacketMetadata::m_enableChecking = false;
 bool PacketMetadata::m_metadataSkipped = false;
 uint32_t PacketMetadata::m_maxSize = 0;
 uint16_t PacketMetadata::m_chunkUid = 0;
@@ -59,6 +60,13 @@
   m_enable = true;
 }
 
+void 
+PacketMetadata::EnableChecking (void)
+{
+  Enable ();
+  m_enableChecking = true;
+}
+
 void
 PacketMetadata::ReserveCopy (uint32_t size)
 {
@@ -630,13 +638,21 @@
   if ((item.typeUid & 0xfffffffe) != uid ||
       item.size != size)
     {
-      NS_FATAL_ERROR ("Removing unexpected header.");
+      if (m_enableChecking)
+        {
+          NS_FATAL_ERROR ("Removing unexpected header.");
+        }
+      return;
     }
   else if (item.typeUid != uid &&
            (extraItem.fragmentStart != 0 ||
             extraItem.fragmentEnd != size))
     {
-      NS_FATAL_ERROR ("Removing incomplete header.");
+      if (m_enableChecking)
+        {
+          NS_FATAL_ERROR ("Removing incomplete header.");
+        }
+      return;
     }
   if (m_head + read == m_used)
     {
@@ -688,13 +704,21 @@
   if ((item.typeUid & 0xfffffffe) != uid ||
       item.size != size)
     {
-      NS_FATAL_ERROR ("Removing unexpected trailer.");
+      if (m_enableChecking)
+        {
+          NS_FATAL_ERROR ("Removing unexpected trailer.");
+        }
+      return;
     }
   else if (item.typeUid != uid &&
            (extraItem.fragmentStart != 0 ||
             extraItem.fragmentEnd != size))
     {
-      NS_FATAL_ERROR ("Removing incomplete trailer.");
+      if (m_enableChecking)
+        {
+          NS_FATAL_ERROR ("Removing incomplete trailer.");
+        }
+      return;
     }
   if (m_tail + read == m_used)
     {
--- a/src/common/packet-metadata.h	Mon Aug 25 15:16:35 2008 -0700
+++ b/src/common/packet-metadata.h	Mon Aug 25 15:21:01 2008 -0700
@@ -125,6 +125,7 @@
   };
 
   static void Enable (void);
+  static void EnableChecking (void);
 
   inline PacketMetadata (uint32_t uid, uint32_t size);
   inline PacketMetadata (PacketMetadata const &o);
@@ -279,6 +280,7 @@
   
   static DataFreeList m_freeList;
   static bool m_enable;
+  static bool m_enableChecking;
 
   // set to true when adding metadata to a packet is skipped because
   // m_enable is false; used to detect enabling of metadata in the
--- a/src/common/packet.cc	Mon Aug 25 15:16:35 2008 -0700
+++ b/src/common/packet.cc	Mon Aug 25 15:21:01 2008 -0700
@@ -459,9 +459,23 @@
 Packet::EnableMetadata (void)
 {
   NS_LOG_FUNCTION_NOARGS ();
+  EnableChecking ();
+}
+
+void
+Packet::EnablePrinting (void)
+{
+  NS_LOG_FUNCTION_NOARGS ();
   PacketMetadata::Enable ();
 }
 
+void
+Packet::EnableChecking (void)
+{
+  NS_LOG_FUNCTION_NOARGS ();
+  PacketMetadata::EnableChecking ();
+}
+
 Buffer 
 Packet::Serialize (void) const
 {
--- a/src/common/packet.h	Mon Aug 25 15:16:35 2008 -0700
+++ b/src/common/packet.h	Mon Aug 25 15:21:01 2008 -0700
@@ -30,6 +30,7 @@
 #include "ns3/callback.h"
 #include "ns3/assert.h"
 #include "ns3/ptr.h"
+#include "ns3/deprecated.h"
 
 namespace ns3 {
 
@@ -310,13 +311,17 @@
 
   PacketMetadata::ItemIterator BeginItem (void) const;
 
+  static void EnableMetadata (void) NS_DEPRECATED;
+
   /**
    * By default, packets do not keep around enough metadata to
    * perform the operations requested by the Print methods. If you
    * want to be able to invoke any of the two ::Print methods, 
    * you need to invoke this method at least once during the 
    * simulation setup and before any packet is created.
-   *
+   */
+  static void EnablePrinting (void);
+  /**
    * The packet metadata is also used to perform extensive
    * sanity checks at runtime when performing operations on a 
    * Packet. For example, this metadata is used to verify that
@@ -324,7 +329,7 @@
    * was actually present at the front of the packet. These
    * errors will be detected and will abort the program.
    */
-  static void EnableMetadata (void);
+  static void EnableChecking (void);
 
   /**
    * \returns a byte buffer
--- a/src/helper/csma-helper.cc	Mon Aug 25 15:16:35 2008 -0700
+++ b/src/helper/csma-helper.cc	Mon Aug 25 15:21:01 2008 -0700
@@ -122,7 +122,7 @@
 void 
 CsmaHelper::EnableAscii (std::ostream &os, uint32_t nodeid, uint32_t deviceid)
 {
-  Packet::EnableMetadata ();
+  Packet::EnablePrinting ();
   std::ostringstream oss;
   oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::CsmaNetDevice/Rx";
   Config::Connect (oss.str (), MakeBoundCallback (&CsmaHelper::AsciiRxEvent, &os));
--- a/src/helper/point-to-point-helper.cc	Mon Aug 25 15:16:35 2008 -0700
+++ b/src/helper/point-to-point-helper.cc	Mon Aug 25 15:21:01 2008 -0700
@@ -122,7 +122,7 @@
 void 
 PointToPointHelper::EnableAscii (std::ostream &os, uint32_t nodeid, uint32_t deviceid)
 {
-  Packet::EnableMetadata ();
+  Packet::EnablePrinting ();
   std::ostringstream oss;
   oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::PointToPointNetDevice/Rx";
   Config::Connect (oss.str (), MakeBoundCallback (&PointToPointHelper::AsciiRxEvent, &os));
--- a/src/helper/wifi-helper.cc	Mon Aug 25 15:16:35 2008 -0700
+++ b/src/helper/wifi-helper.cc	Mon Aug 25 15:21:01 2008 -0700
@@ -193,7 +193,7 @@
 void 
 WifiHelper::EnableAscii (std::ostream &os, uint32_t nodeid, uint32_t deviceid)
 {
-    Packet::EnableMetadata ();
+  Packet::EnablePrinting ();
   std::ostringstream oss;
   oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/RxOk";
   Config::Connect (oss.str (), MakeBoundCallback (&AsciiPhyRxOkEvent, &os));
--- a/utils/bench-packets.cc	Mon Aug 25 15:16:35 2008 -0700
+++ b/utils/bench-packets.cc	Mon Aug 25 15:21:01 2008 -0700
@@ -282,7 +282,7 @@
   runBench (&benchC, n, "c");
   runBench (&benchD, n, "d");
 
-  Packet::EnableMetadata ();
+  Packet::EnablePrinting ();
   runBench (&benchA, n, "meta-a");
   runBench (&benchB, n, "meta-b");
   runBench (&benchC, n, "meta-c");