diff --git a/CHANGES.md b/CHANGES.md index e6e186311..270852aff 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -24,6 +24,7 @@ Changes from ns-3.36 to ns-3.37 * Adds support for channel paging to the **LrWpanPhy** (only placeholder, a single modulation/band is currently supported). * Adds supporting structures used by **LrWpanMac** (PAN descriptor, Command Payload Header, Capability Field). +* Mac(8|16|48|64)Address address allocation pool is now reset between consecutive runs. ### Changes to build system diff --git a/src/aodv/test/bug-606-test-0-0.pcap b/src/aodv/test/bug-606-test-0-0.pcap index 381064256..3d9f332be 100644 Binary files a/src/aodv/test/bug-606-test-0-0.pcap and b/src/aodv/test/bug-606-test-0-0.pcap differ diff --git a/src/aodv/test/bug-606-test-1-0.pcap b/src/aodv/test/bug-606-test-1-0.pcap index b981c2586..1d52314f9 100644 Binary files a/src/aodv/test/bug-606-test-1-0.pcap and b/src/aodv/test/bug-606-test-1-0.pcap differ diff --git a/src/aodv/test/bug-606-test-2-0.pcap b/src/aodv/test/bug-606-test-2-0.pcap index e01f61ce9..ed25f2e17 100644 Binary files a/src/aodv/test/bug-606-test-2-0.pcap and b/src/aodv/test/bug-606-test-2-0.pcap differ diff --git a/src/mesh/test/dot11s/hwmp-proactive-regression-test-0-1.pcap b/src/mesh/test/dot11s/hwmp-proactive-regression-test-0-1.pcap index 34d11b579..673b43a55 100644 Binary files a/src/mesh/test/dot11s/hwmp-proactive-regression-test-0-1.pcap and b/src/mesh/test/dot11s/hwmp-proactive-regression-test-0-1.pcap differ diff --git a/src/mesh/test/dot11s/hwmp-proactive-regression-test-1-1.pcap b/src/mesh/test/dot11s/hwmp-proactive-regression-test-1-1.pcap index 13bf7d0ec..5aae5025e 100644 Binary files a/src/mesh/test/dot11s/hwmp-proactive-regression-test-1-1.pcap and b/src/mesh/test/dot11s/hwmp-proactive-regression-test-1-1.pcap differ diff --git a/src/mesh/test/dot11s/hwmp-proactive-regression-test-2-1.pcap b/src/mesh/test/dot11s/hwmp-proactive-regression-test-2-1.pcap index 819410118..151814e0f 100644 Binary files a/src/mesh/test/dot11s/hwmp-proactive-regression-test-2-1.pcap and b/src/mesh/test/dot11s/hwmp-proactive-regression-test-2-1.pcap differ diff --git a/src/mesh/test/dot11s/hwmp-proactive-regression-test-3-1.pcap b/src/mesh/test/dot11s/hwmp-proactive-regression-test-3-1.pcap index b5e250e35..60fe9e4e7 100644 Binary files a/src/mesh/test/dot11s/hwmp-proactive-regression-test-3-1.pcap and b/src/mesh/test/dot11s/hwmp-proactive-regression-test-3-1.pcap differ diff --git a/src/mesh/test/dot11s/hwmp-proactive-regression-test-4-1.pcap b/src/mesh/test/dot11s/hwmp-proactive-regression-test-4-1.pcap index ce7eb4841..fbd10dc8b 100644 Binary files a/src/mesh/test/dot11s/hwmp-proactive-regression-test-4-1.pcap and b/src/mesh/test/dot11s/hwmp-proactive-regression-test-4-1.pcap differ diff --git a/src/mesh/test/dot11s/hwmp-proactive-regression.cc b/src/mesh/test/dot11s/hwmp-proactive-regression.cc index b16b5662b..029a6fbed 100644 --- a/src/mesh/test/dot11s/hwmp-proactive-regression.cc +++ b/src/mesh/test/dot11s/hwmp-proactive-regression.cc @@ -118,13 +118,9 @@ HwmpProactiveRegressionTest::CreateDevices () // 2. setup mesh MeshHelper mesh = MeshHelper::Default (); - // Due to the fact that MAC addresses are set by a local static variable - // that already allocates addresses to the previous tests in regression.cc, - // the first allocated address in this test will be 00:00:00:00:00:0b. - // (pmp allocates 2, simplest allocates 2, and reactive allocates 6) - // Therefore, the middle node will have address 00:00:00:00:00:0d, + // The middle node will have address 00:00:00:00:00:03, // so we set this to the root as per the comment in the header file. - mesh.SetStackInstaller ("ns3::Dot11sStack", "Root", Mac48AddressValue (Mac48Address ("00:00:00:00:00:0d"))); + mesh.SetStackInstaller ("ns3::Dot11sStack", "Root", Mac48AddressValue (Mac48Address ("00:00:00:00:00:03"))); mesh.SetMacType ("RandomStart", TimeValue (Seconds (0.1))); mesh.SetNumberOfInterfaces (1); NetDeviceContainer meshDevices = mesh.Install (wifiPhy, *m_nodes); diff --git a/src/mesh/test/dot11s/hwmp-proactive-regression.h b/src/mesh/test/dot11s/hwmp-proactive-regression.h index 265872d21..0312a33fc 100644 --- a/src/mesh/test/dot11s/hwmp-proactive-regression.h +++ b/src/mesh/test/dot11s/hwmp-proactive-regression.h @@ -36,7 +36,7 @@ using namespace ns3; * \verbatim * Src Root Dst * (node ID) 0 1 2 3 4 - * (MAC) 00:0b 00:0c 00:0d 00:0e 00:0f + * (MAC) 00:01 00:02 00:03 00:04 00:05 * | |<--------|-------->| | Proactive PREQ * | |-------->| | | PREP * | | |<--------| | PREP diff --git a/src/mesh/test/dot11s/hwmp-reactive-regression-test-0-1.pcap b/src/mesh/test/dot11s/hwmp-reactive-regression-test-0-1.pcap index d0387e8d6..027cc4ddc 100644 Binary files a/src/mesh/test/dot11s/hwmp-reactive-regression-test-0-1.pcap and b/src/mesh/test/dot11s/hwmp-reactive-regression-test-0-1.pcap differ diff --git a/src/mesh/test/dot11s/hwmp-reactive-regression-test-1-1.pcap b/src/mesh/test/dot11s/hwmp-reactive-regression-test-1-1.pcap index bc53070a6..a6fdc6ac4 100644 Binary files a/src/mesh/test/dot11s/hwmp-reactive-regression-test-1-1.pcap and b/src/mesh/test/dot11s/hwmp-reactive-regression-test-1-1.pcap differ diff --git a/src/mesh/test/dot11s/hwmp-reactive-regression-test-2-1.pcap b/src/mesh/test/dot11s/hwmp-reactive-regression-test-2-1.pcap index 5fc02e842..0ce9355ae 100644 Binary files a/src/mesh/test/dot11s/hwmp-reactive-regression-test-2-1.pcap and b/src/mesh/test/dot11s/hwmp-reactive-regression-test-2-1.pcap differ diff --git a/src/mesh/test/dot11s/hwmp-reactive-regression-test-3-1.pcap b/src/mesh/test/dot11s/hwmp-reactive-regression-test-3-1.pcap index b5b635d32..9fbaa18e8 100644 Binary files a/src/mesh/test/dot11s/hwmp-reactive-regression-test-3-1.pcap and b/src/mesh/test/dot11s/hwmp-reactive-regression-test-3-1.pcap differ diff --git a/src/mesh/test/dot11s/hwmp-reactive-regression-test-4-1.pcap b/src/mesh/test/dot11s/hwmp-reactive-regression-test-4-1.pcap index 6e978bb4c..bd1557eec 100644 Binary files a/src/mesh/test/dot11s/hwmp-reactive-regression-test-4-1.pcap and b/src/mesh/test/dot11s/hwmp-reactive-regression-test-4-1.pcap differ diff --git a/src/mesh/test/dot11s/hwmp-reactive-regression-test-5-1.pcap b/src/mesh/test/dot11s/hwmp-reactive-regression-test-5-1.pcap index d730363c9..fa3dedaa5 100644 Binary files a/src/mesh/test/dot11s/hwmp-reactive-regression-test-5-1.pcap and b/src/mesh/test/dot11s/hwmp-reactive-regression-test-5-1.pcap differ diff --git a/src/mesh/test/dot11s/hwmp-simplest-regression-test-0-1.pcap b/src/mesh/test/dot11s/hwmp-simplest-regression-test-0-1.pcap index 82086cefc..d921b4059 100644 Binary files a/src/mesh/test/dot11s/hwmp-simplest-regression-test-0-1.pcap and b/src/mesh/test/dot11s/hwmp-simplest-regression-test-0-1.pcap differ diff --git a/src/mesh/test/dot11s/hwmp-simplest-regression-test-1-1.pcap b/src/mesh/test/dot11s/hwmp-simplest-regression-test-1-1.pcap index a9ab92bd5..5562e4272 100644 Binary files a/src/mesh/test/dot11s/hwmp-simplest-regression-test-1-1.pcap and b/src/mesh/test/dot11s/hwmp-simplest-regression-test-1-1.pcap differ diff --git a/src/mesh/test/dot11s/hwmp-target-flags-regression-test-0-1.pcap b/src/mesh/test/dot11s/hwmp-target-flags-regression-test-0-1.pcap index 14d38beb3..0e6f58413 100644 Binary files a/src/mesh/test/dot11s/hwmp-target-flags-regression-test-0-1.pcap and b/src/mesh/test/dot11s/hwmp-target-flags-regression-test-0-1.pcap differ diff --git a/src/mesh/test/dot11s/hwmp-target-flags-regression-test-1-1.pcap b/src/mesh/test/dot11s/hwmp-target-flags-regression-test-1-1.pcap index c70898906..842e69fd0 100644 Binary files a/src/mesh/test/dot11s/hwmp-target-flags-regression-test-1-1.pcap and b/src/mesh/test/dot11s/hwmp-target-flags-regression-test-1-1.pcap differ diff --git a/src/mesh/test/dot11s/hwmp-target-flags-regression-test-2-1.pcap b/src/mesh/test/dot11s/hwmp-target-flags-regression-test-2-1.pcap index f178ad166..4d3c49db6 100644 Binary files a/src/mesh/test/dot11s/hwmp-target-flags-regression-test-2-1.pcap and b/src/mesh/test/dot11s/hwmp-target-flags-regression-test-2-1.pcap differ diff --git a/src/mesh/test/dot11s/hwmp-target-flags-regression-test-3-1.pcap b/src/mesh/test/dot11s/hwmp-target-flags-regression-test-3-1.pcap index 96da9999e..9dc1938a8 100644 Binary files a/src/mesh/test/dot11s/hwmp-target-flags-regression-test-3-1.pcap and b/src/mesh/test/dot11s/hwmp-target-flags-regression-test-3-1.pcap differ diff --git a/src/network/utils/mac16-address.cc b/src/network/utils/mac16-address.cc index f0485136d..e0b746096 100644 --- a/src/network/utils/mac16-address.cc +++ b/src/network/utils/mac16-address.cc @@ -22,6 +22,7 @@ #include "ns3/address.h" #include "ns3/assert.h" #include "ns3/log.h" +#include "ns3/simulator.h" #include #include #include @@ -56,6 +57,7 @@ AsciiToLowCase (char c) } } +uint64_t Mac16Address::m_allocationIndex = 0; Mac16Address::Mac16Address () { @@ -140,14 +142,26 @@ Mac16Address Mac16Address::Allocate (void) { NS_LOG_FUNCTION_NOARGS (); - static uint64_t id = 0; - id++; + + if (m_allocationIndex == 0) + { + Simulator::ScheduleDestroy (Mac16Address::ResetAllocationIndex); + } + + m_allocationIndex++; Mac16Address address; - address.m_address[0] = (id >> 8) & 0xff; - address.m_address[1] = (id >> 0) & 0xff; + address.m_address[0] = (m_allocationIndex >> 8) & 0xff; + address.m_address[1] = m_allocationIndex & 0xff; return address; } +void +Mac16Address::ResetAllocationIndex () +{ + NS_LOG_FUNCTION_NOARGS (); + m_allocationIndex = 0; +} + uint8_t Mac16Address::GetType (void) { diff --git a/src/network/utils/mac16-address.h b/src/network/utils/mac16-address.h index 52642f569..4a75f3edf 100644 --- a/src/network/utils/mac16-address.h +++ b/src/network/utils/mac16-address.h @@ -86,6 +86,21 @@ public: */ static Mac16Address Allocate (void); + /** + * Reset the Mac16Address allocation index. + * + * This function resets (to zero) the global integer + * that is used for unique address allocation. + * It is automatically called whenever + * \code + * SimulatorDestroy (); + * \endcode + * is called. It may also be optionally called + * by user code if there is a need to force a reset + * of this allocation index. + */ + static void ResetAllocationIndex (); + /** * \returns the broadcast address (0xFFFF) */ @@ -191,6 +206,7 @@ private: */ friend std::istream& operator>> (std::istream& is, Mac16Address & address); + static uint64_t m_allocationIndex; //!< Address allocation index uint8_t m_address[2]; //!< address value }; diff --git a/src/network/utils/mac48-address.cc b/src/network/utils/mac48-address.cc index 1d9bbf6fa..5789dfc6f 100644 --- a/src/network/utils/mac48-address.cc +++ b/src/network/utils/mac48-address.cc @@ -21,6 +21,7 @@ #include "ns3/address.h" #include "ns3/assert.h" #include "ns3/log.h" +#include "ns3/simulator.h" #include #include #include @@ -56,6 +57,7 @@ AsciiToLowCase (char c) } } +uint64_t Mac48Address::m_allocationIndex = 0; Mac48Address::Mac48Address () { @@ -135,17 +137,30 @@ Mac48Address Mac48Address::Allocate (void) { NS_LOG_FUNCTION_NOARGS (); - static uint64_t id = 0; - id++; + + if (m_allocationIndex == 0) + { + Simulator::ScheduleDestroy (Mac48Address::ResetAllocationIndex); + } + + m_allocationIndex++; Mac48Address address; - address.m_address[0] = (id >> 40) & 0xff; - address.m_address[1] = (id >> 32) & 0xff; - address.m_address[2] = (id >> 24) & 0xff; - address.m_address[3] = (id >> 16) & 0xff; - address.m_address[4] = (id >> 8) & 0xff; - address.m_address[5] = (id >> 0) & 0xff; + address.m_address[0] = (m_allocationIndex >> 40) & 0xff; + address.m_address[1] = (m_allocationIndex >> 32) & 0xff; + address.m_address[2] = (m_allocationIndex >> 24) & 0xff; + address.m_address[3] = (m_allocationIndex >> 16) & 0xff; + address.m_address[4] = (m_allocationIndex >> 8) & 0xff; + address.m_address[5] = m_allocationIndex & 0xff; return address; } + +void +Mac48Address::ResetAllocationIndex () +{ + NS_LOG_FUNCTION_NOARGS (); + m_allocationIndex = 0; +} + uint8_t Mac48Address::GetType (void) { diff --git a/src/network/utils/mac48-address.h b/src/network/utils/mac48-address.h index a012b3764..98684a7d2 100644 --- a/src/network/utils/mac48-address.h +++ b/src/network/utils/mac48-address.h @@ -90,6 +90,21 @@ public: */ static Mac48Address Allocate (void); + /** + * Reset the Mac48Address allocation index. + * + * This function resets (to zero) the global integer + * that is used for unique address allocation. + * It is automatically called whenever + * \code + * SimulatorDestroy (); + * \endcode + * is called. It may also be optionally called + * by user code if there is a need to force a reset + * of this allocation index. + */ + static void ResetAllocationIndex (); + /** * \returns true if this is a broadcast address, false otherwise. */ @@ -195,6 +210,7 @@ private: */ friend std::istream& operator>> (std::istream& is, Mac48Address & address); + static uint64_t m_allocationIndex; //!< Address allocation index uint8_t m_address[6]; //!< address value }; diff --git a/src/network/utils/mac64-address.cc b/src/network/utils/mac64-address.cc index ddcd19b4c..4efcc5907 100644 --- a/src/network/utils/mac64-address.cc +++ b/src/network/utils/mac64-address.cc @@ -21,6 +21,7 @@ #include "ns3/address.h" #include "ns3/assert.h" #include "ns3/log.h" +#include "ns3/simulator.h" #include #include #include @@ -56,6 +57,7 @@ AsciiToLowCase (char c) } } +uint64_t Mac64Address::m_allocationIndex = 0; Mac64Address::Mac64Address () { @@ -137,19 +139,32 @@ Mac64Address Mac64Address::Allocate (void) { NS_LOG_FUNCTION_NOARGS (); - static uint64_t id = 0; - id++; + + if (m_allocationIndex == 0) + { + Simulator::ScheduleDestroy (Mac64Address::ResetAllocationIndex); + } + + m_allocationIndex++; Mac64Address address; - address.m_address[0] = (id >> 56) & 0xff; - address.m_address[1] = (id >> 48) & 0xff; - address.m_address[2] = (id >> 40) & 0xff; - address.m_address[3] = (id >> 32) & 0xff; - address.m_address[4] = (id >> 24) & 0xff; - address.m_address[5] = (id >> 16) & 0xff; - address.m_address[6] = (id >> 8) & 0xff; - address.m_address[7] = (id >> 0) & 0xff; + address.m_address[0] = (m_allocationIndex >> 56) & 0xff; + address.m_address[1] = (m_allocationIndex >> 48) & 0xff; + address.m_address[2] = (m_allocationIndex >> 40) & 0xff; + address.m_address[3] = (m_allocationIndex >> 32) & 0xff; + address.m_address[4] = (m_allocationIndex >> 24) & 0xff; + address.m_address[5] = (m_allocationIndex >> 16) & 0xff; + address.m_address[6] = (m_allocationIndex >> 8) & 0xff; + address.m_address[7] = m_allocationIndex & 0xff; return address; } + +void +Mac64Address::ResetAllocationIndex () +{ + NS_LOG_FUNCTION_NOARGS (); + m_allocationIndex = 0; +} + uint8_t Mac64Address::GetType (void) { diff --git a/src/network/utils/mac64-address.h b/src/network/utils/mac64-address.h index 73e7498df..da22a650d 100644 --- a/src/network/utils/mac64-address.h +++ b/src/network/utils/mac64-address.h @@ -88,6 +88,22 @@ public: * \returns newly allocated mac64Address */ static Mac64Address Allocate (void); + + /** + * Reset the Mac64Address allocation index. + * + * This function resets (to zero) the global integer + * that is used for unique address allocation. + * It is automatically called whenever + * \code + * SimulatorDestroy (); + * \endcode + * is called. It may also be optionally called + * by user code if there is a need to force a reset + * of this allocation index. + */ + static void ResetAllocationIndex (); + private: /** * \returns a new Address instance @@ -147,6 +163,7 @@ private: */ friend std::istream& operator>> (std::istream& is, Mac64Address & address); + static uint64_t m_allocationIndex; //!< Address allocation index uint8_t m_address[8]; //!< address value }; diff --git a/src/network/utils/mac8-address.cc b/src/network/utils/mac8-address.cc index fb6fced64..3f47117fe 100644 --- a/src/network/utils/mac8-address.cc +++ b/src/network/utils/mac8-address.cc @@ -20,9 +20,15 @@ #include "mac8-address.h" #include "ns3/address.h" +#include "ns3/simulator.h" +#include "ns3/log.h" namespace ns3 { +NS_LOG_COMPONENT_DEFINE ("Mac8Address"); + +uint8_t Mac8Address::m_allocationIndex = 0; + Mac8Address::Mac8Address () { m_address = 255; @@ -88,20 +94,34 @@ Mac8Address::GetBroadcast () { return Mac8Address (255); } + Mac8Address Mac8Address::Allocate () { - static uint8_t nextAllocated = 0; + NS_LOG_FUNCTION_NOARGS (); - uint8_t address = nextAllocated++; - if (nextAllocated == 255) + if (m_allocationIndex == 0) { - nextAllocated = 0; + Simulator::ScheduleDestroy (Mac8Address::ResetAllocationIndex); + } + + uint8_t address = m_allocationIndex++; + if (m_allocationIndex == 255) + { + m_allocationIndex = 0; } return Mac8Address (address); } +void +Mac8Address::ResetAllocationIndex () +{ + NS_LOG_FUNCTION_NOARGS (); + + m_allocationIndex = 0; +} + bool operator < (const Mac8Address &a, const Mac8Address &b) { diff --git a/src/network/utils/mac8-address.h b/src/network/utils/mac8-address.h index 6720f5fb1..3f1a2c82a 100644 --- a/src/network/utils/mac8-address.h +++ b/src/network/utils/mac8-address.h @@ -107,8 +107,23 @@ public: */ static Mac8Address Allocate (); + /** + * Reset the Mac8Address allocation index. + * + * This function resets (to zero) the global integer + * that is used for unique address allocation. + * It is automatically called whenever + * \code + * SimulatorDestroy (); + * \endcode + * is called. It may also be optionally called + * by user code if there is a need to force a reset + * of this allocation index. + */ + static void ResetAllocationIndex (); private: + static uint8_t m_allocationIndex; //!< Address allocation index uint8_t m_address; //!< The address. /**