# HG changeset patch # User cdfreire # Date 1308669285 -7200 # Node ID 3aa7dfca1d27f9dcb0e0f5e8b442e5ae52a5405b # Parent 3881cbe7fcc7c66cd4c5a84a5a204a80627b41da Support disabling of packet metadata, mainly so that tests can roll back configuration changes. diff -r 3881cbe7fcc7 -r 3aa7dfca1d27 src/network/model/packet-metadata.cc --- a/src/network/model/packet-metadata.cc Mon Jun 20 17:04:42 2011 +0200 +++ b/src/network/model/packet-metadata.cc Tue Jun 21 17:14:45 2011 +0200 @@ -67,6 +67,26 @@ m_enableChecking = true; } +void +PacketMetadata::Disable (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 = false; +} + +void +PacketMetadata::DisableChecking (void) +{ + Disable (); + m_enableChecking = false; +} + void PacketMetadata::ReserveCopy (uint32_t size) { diff -r 3881cbe7fcc7 -r 3aa7dfca1d27 src/network/model/packet-metadata.h --- a/src/network/model/packet-metadata.h Mon Jun 20 17:04:42 2011 +0200 +++ b/src/network/model/packet-metadata.h Tue Jun 21 17:14:45 2011 +0200 @@ -127,6 +127,9 @@ static void Enable (void); static void EnableChecking (void); + static void Disable (void); + static void DisableChecking (void); + inline PacketMetadata (uint64_t uid, uint32_t size); inline PacketMetadata (PacketMetadata const &o); inline PacketMetadata &operator = (PacketMetadata const& o); diff -r 3881cbe7fcc7 -r 3aa7dfca1d27 src/network/model/packet.cc --- a/src/network/model/packet.cc Mon Jun 20 17:04:42 2011 +0200 +++ b/src/network/model/packet.cc Tue Jun 21 17:14:45 2011 +0200 @@ -560,6 +560,20 @@ PacketMetadata::EnableChecking (); } +void +Packet::DisablePrinting (void) +{ + NS_LOG_FUNCTION_NOARGS (); + PacketMetadata::Disable (); +} + +void +Packet::DisableChecking (void) +{ + NS_LOG_FUNCTION_NOARGS (); + PacketMetadata::DisableChecking (); +} + uint32_t Packet::GetSerializedSize (void) const { uint32_t size = 0; diff -r 3881cbe7fcc7 -r 3aa7dfca1d27 src/network/model/packet.h --- a/src/network/model/packet.h Mon Jun 20 17:04:42 2011 +0200 +++ b/src/network/model/packet.h Tue Jun 21 17:14:45 2011 +0200 @@ -429,6 +429,14 @@ * errors will be detected and will abort the program. */ static void EnableChecking (void); + /** + * \sa EnablePrinting + */ + static void DisablePrinting (void); + /** + * \sa EnableChecking + */ + static void DisableChecking (void); /** * For packet serializtion, the total size is checked # HG changeset patch # User cdfreire # Date 1310034624 -7200 # Node ID 891c9d1aa185973a6f839a6d7bd771b36cfa6c20 # Parent b9cfa43318dd3fe7292c91f8f234f7905098ca91 Config reset for test teardown diff -r b9cfa43318dd -r 891c9d1aa185 src/core/model/config.cc --- a/src/core/model/config.cc Thu Jul 07 11:47:03 2011 +0200 +++ b/src/core/model/config.cc Thu Jul 07 12:30:24 2011 +0200 @@ -603,6 +603,11 @@ { return GlobalValue::BindFailSafe (name, value); } +void Reset () +{ + AttributeList::GetGlobal ()->Reset (); + GlobalValue::ResetAll (); +} void ConnectWithoutContext (std::string path, const CallbackBase &cb) { Singleton::Get ()->ConnectWithoutContext (path, cb); diff -r b9cfa43318dd -r 891c9d1aa185 src/core/model/config.h --- a/src/core/model/config.h Thu Jul 07 11:47:03 2011 +0200 +++ b/src/core/model/config.h Thu Jul 07 12:30:24 2011 +0200 @@ -110,6 +110,11 @@ * This function undoes the work of Config::ConnectWithContext. */ void Disconnect (std::string path, const CallbackBase &cb); +/** + * This method resets the effect of all SetDefault, SetDefaultFailSafe, + * SetGlobal, and SetGlobalFailSafe calls. + */ +void Reset (); /** * \brief hold a set of objects which match a specific search string. diff -r b9cfa43318dd -r 891c9d1aa185 src/core/model/global-value.cc --- a/src/core/model/global-value.cc Thu Jul 07 11:47:03 2011 +0200 +++ b/src/core/model/global-value.cc Thu Jul 07 12:30:24 2011 +0200 @@ -49,6 +49,7 @@ void GlobalValue::InitializeFromEnv (void) { + m_value = m_initialValue->Copy (); #ifdef HAVE_GETENV char *envVar = getenv ("NS_GLOBAL_VALUE"); if (envVar == 0) @@ -88,9 +89,22 @@ return m_help; } void +GlobalValue::ResetValue (void) +{ + InitializeFromEnv (); +} +void +GlobalValue::ResetAll (void) +{ + for (Iterator i = Begin (); i != End (); i++) + { + (*i)->ResetValue (); + } +} +void GlobalValue::GetValue (AttributeValue &value) const { - bool ok = m_checker->Copy (*m_initialValue, value); + bool ok = m_checker->Copy (*m_value, value); if (ok) { return; @@ -100,7 +114,7 @@ { NS_FATAL_ERROR ("GlobalValue name="<Set (m_initialValue->SerializeToString (m_checker)); + str->Set (m_value->SerializeToString (m_checker)); } Ptr GlobalValue::GetChecker (void) const @@ -113,7 +127,7 @@ { if (m_checker->Check (value)) { - m_initialValue = value.Copy (); + m_value = value.Copy (); return true; } // attempt to convert to string. @@ -134,7 +148,7 @@ { return false; } - m_checker->Copy (*v, *PeekPointer (m_initialValue)); + m_checker->Copy (*v, *PeekPointer (m_value)); return true; } diff -r b9cfa43318dd -r 891c9d1aa185 src/core/model/global-value.h --- a/src/core/model/global-value.h Thu Jul 07 11:47:03 2011 +0200 +++ b/src/core/model/global-value.h Thu Jul 07 12:30:24 2011 +0200 @@ -84,6 +84,10 @@ * \param value the new value to set in this GlobalValue. */ bool SetValue (const AttributeValue &value); + /** + * Reset the global value to its default/initial value. + */ + void ResetValue (); /** * \param name the name of the global value @@ -136,6 +140,11 @@ * */ static void GetValueByName (std::string name, AttributeValue &value); + + /** + * Resets all GlobalValue s to their defaults. + */ + static void ResetAll (); private: @@ -145,6 +154,7 @@ void InitializeFromEnv (void); std::string m_name; std::string m_help; + Ptr m_value; Ptr m_initialValue; Ptr m_checker; }; # HG changeset patch # User cdfreire@antar.inria.fr # Date 1310400952 -7200 # Node ID 3a47732b48a91059d5b11853681ce0042017d144 # Parent e421e4239c455be6628a6ac162900d0583e002c9 Make Mac48Address use a global value for its MAC sequence tracking, allowing its manipulation through Config. diff -r 34605964f100 -r c25325ce6381 src/network/utils/mac48-address.cc --- a/src/network/utils/mac48-address.cc Fri Jun 17 15:03:42 2011 +0200 +++ b/src/network/utils/mac48-address.cc Wed Jul 13 15:39:15 2011 +0200 @@ -20,10 +20,17 @@ #include "mac48-address.h" #include "ns3/address.h" #include "ns3/assert.h" +#include "ns3/uinteger.h" +#include "ns3/global-value.h" #include #include #include +static ns3::GlobalValue g_Mac48Origin ("Mac48Origin", + "The initial value the Mac48Address::Allocate helper will use.", + ns3::UintegerValue (0), + ns3::MakeUintegerChecker ()); + namespace ns3 { ATTRIBUTE_HELPER_CPP (Mac48Address); @@ -118,7 +125,10 @@ Mac48Address Mac48Address::Allocate (void) { - static uint64_t id = 0; + UintegerValue value; + g_Mac48Origin.GetValue (value); + uint64_t id = value.Get(); + id++; Mac48Address address; address.m_address[0] = (id >> 40) & 0xff; @@ -127,6 +137,10 @@ address.m_address[3] = (id >> 16) & 0xff; address.m_address[4] = (id >> 8) & 0xff; address.m_address[5] = (id >> 0) & 0xff; + + value.Set(id); + g_Mac48Origin.SetValue (value); + return address; } uint8_t