Check for the common error of enabling packet metadata in the middle of a simulation, and give appropriate advice in this case. Closes #78.
authorGustavo J. A. M. Carneiro <gjc@inescporto.pt>
Mon, 24 Sep 2007 16:11:43 +0100
changeset 1525 648048bca501
parent 1524 3ead2b66f2e4
child 1526 46623ec253f4
child 1751 58ab7d757354
Check for the common error of enabling packet metadata in the middle of a simulation, and give appropriate advice in this case. Closes #78.
src/common/packet-metadata.cc
src/common/packet-metadata.h
--- a/src/common/packet-metadata.cc	Mon Sep 24 11:00:08 2007 +0100
+++ b/src/common/packet-metadata.cc	Mon Sep 24 16:11:43 2007 +0100
@@ -31,6 +31,7 @@
 namespace ns3 {
 
 bool PacketMetadata::m_enable = false;
+bool PacketMetadata::m_metadataSkipped = false;
 uint32_t PacketMetadata::m_maxSize = 0;
 uint16_t PacketMetadata::m_chunkUid = 0;
 PacketMetadata::DataFreeList PacketMetadata::m_freeList;
@@ -47,6 +48,13 @@
 void 
 PacketMetadata::Enable (void)
 {
+  NS_ASSERT_MSG (!m_metadataSkipped,
+                 "Error: attempting to enable the packet metadata "
+                 "subsystem too late in the simulation, which is not allowed.\n"
+                 "A common cause for this problem is to enable ASCII tracing "
+                 "after sending any packets.  One way to fix this problem is "
+                 "to call ns3::PacketMetadata::Enable () near the beginning of"
+                 " the program, before any packets are sent.");
   m_enable = true;
 }
 
@@ -686,6 +694,7 @@
 {
   if (!m_enable)
     {
+      m_metadataSkipped = true;
       return;
     }
   struct PacketMetadata::SmallItem item;
@@ -703,6 +712,7 @@
 {
   if (!m_enable) 
     {
+      m_metadataSkipped = true;
       return;
     }
   struct PacketMetadata::SmallItem item;
@@ -738,6 +748,7 @@
 {
   if (!m_enable)
     {
+      m_metadataSkipped = true;
       return;
     }
   struct PacketMetadata::SmallItem item;
@@ -755,6 +766,7 @@
 {
   if (!m_enable) 
     {
+      m_metadataSkipped = true;
       return;
     }
   struct PacketMetadata::SmallItem item;
@@ -790,6 +802,7 @@
 {
   if (!m_enable) 
     {
+      m_metadataSkipped = true;
       return;
     }
   if (m_tail == 0xffff)
@@ -846,6 +859,7 @@
 {
   if (!m_enable)
     {
+      m_metadataSkipped = true;
       return;
     }
 }
@@ -854,6 +868,7 @@
 {
   if (!m_enable) 
     {
+      m_metadataSkipped = true;
       return;
     }
   NS_ASSERT (m_data != 0);
@@ -910,6 +925,7 @@
 {
   if (!m_enable) 
     {
+      m_metadataSkipped = true;
       return;
     }
   NS_ASSERT (m_data != 0);
--- a/src/common/packet-metadata.h	Mon Sep 24 11:00:08 2007 +0100
+++ b/src/common/packet-metadata.h	Mon Sep 24 16:11:43 2007 +0100
@@ -234,6 +234,12 @@
   
   static DataFreeList m_freeList;
   static bool m_enable;
+
+  // set to true when adding metadata to a packet is skipped because
+  // m_enable is false; used to detect enabling of metadata in the
+  // middle of a simulation, which isn't allowed.
+  static bool m_metadataSkipped;
+
   static uint32_t m_maxSize;
   static uint16_t m_chunkUid;