network: (fixes #611) Reset MAC address allocation pool between runs
This commit is contained in:
committed by
Tommaso Pecorella
parent
0f8f7125cd
commit
e0f20a49c0
@@ -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
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -22,6 +22,7 @@
|
||||
#include "ns3/address.h"
|
||||
#include "ns3/assert.h"
|
||||
#include "ns3/log.h"
|
||||
#include "ns3/simulator.h"
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "ns3/address.h"
|
||||
#include "ns3/assert.h"
|
||||
#include "ns3/log.h"
|
||||
#include "ns3/simulator.h"
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "ns3/address.h"
|
||||
#include "ns3/assert.h"
|
||||
#include "ns3/log.h"
|
||||
#include "ns3/simulator.h"
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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.
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user