20 #include "ns3/abort.h"
21 #include "ns3/assert.h"
23 #include "ns3/simulation-singleton.h"
174 : m_entries (), m_test (false)
205 for (uint32_t i = 0; i <
N_BITS; ++i)
235 uint32_t maskBits = mask.
Get ();
236 uint32_t netBits = net.
Get ();
237 uint32_t addrBits = addr.
Get ();
241 NS_ABORT_MSG_UNLESS ((netBits & ~maskBits) == 0,
"Ipv4AddressGeneratorImpl::Init (): Inconsistent network and mask");
242 NS_ABORT_MSG_UNLESS ((addrBits & maskBits) == 0,
"Ipv4AddressGeneratorImpl::Init (): Inconsistent address and mask");
295 uint32_t addrBits = addr.
Get ();
328 "Ipv4AddressGeneratorImpl::NextAddress(): Address overflow");
348 uint32_t addr = address.
Get ();
350 NS_ABORT_MSG_UNLESS (addr,
"Ipv4AddressGeneratorImpl::Add(): Allocating the broadcast address is not a good idea");
352 std::list<Entry>::iterator i;
362 if (addr >= (*i).addrLow && addr <= (*i).addrHigh)
376 if (addr < (*i).addrLow - 1)
387 if (addr == (*i).addrHigh + 1)
389 std::list<Entry>::iterator j = i;
394 if (addr == (*j).addrLow)
407 (*i).addrHigh = addr;
417 if (addr == (*i).addrLow - 1)
455 uint32_t maskBits = mask.
Get ();
457 for (uint32_t i = 0; i <
N_BITS; ++i)
461 uint32_t index = N_BITS - i;
462 NS_ABORT_MSG_UNLESS (index > 0 && index < N_BITS,
"Ipv4AddressGenerator::MaskToIndex(): Illegal Mask");
467 NS_ASSERT_MSG (
false,
"Ipv4AddressGenerator::MaskToIndex(): Impossible");
480 ->Init (net, mask, addr);
489 ->NextNetwork (mask);
509 ->InitAddress (addr, mask);
527 ->NextAddress (mask);
545 ->AddAllocated (addr);
void Init(const Ipv4Address net, const Ipv4Mask mask, const Ipv4Address addr)
Initialise the base network, mask and address for the generator.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
This class holds the state for a given network.
a class to represent an Ipv4 address mask
static Ipv4Address NextAddress(const Ipv4Mask mask)
Allocate the next Ipv4Address for the configured network and mask.
This class holds the allocated addresses.
uint32_t addrMax
the maximum address
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
static void InitAddress(const Ipv4Address addr, const Ipv4Mask mask)
Set the address for the given mask.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
void TestMode(void)
Used to turn off fatal errors and assertions, for testing.
bool AddAllocated(const Ipv4Address addr)
Add the Ipv4Address to the list of IPv4 entries.
static void TestMode(void)
Used to turn off fatal errors and assertions, for testing.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
static T * Get(void)
Get a pointer to the singleton instance.
Ipv4AddressGeneratorImpl()
static const uint32_t MOST_SIGNIFICANT_BIT
MSB set to 1.
static void Reset(void)
Reset the networks and Ipv4Address to zero.
void Reset(void)
Reset the networks and Ipv4Address to zero.
uint32_t MaskToIndex(Ipv4Mask mask) const
Create an index number for the network mask.
static Ipv4Address NextNetwork(const Ipv4Mask mask)
Get the next network according to the given Ipv4Mask.
uint32_t Get(void) const
Get the host-order 32-bit IP address.
Ipv4Address GetAddress(const Ipv4Mask mask) const
Get the Ipv4Address that will be allocated upon NextAddress ()
void InitAddress(const Ipv4Address addr, const Ipv4Mask mask)
Set the address for the given mask.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
std::list< Entry > m_entries
contained of allocated addresses
static bool AddAllocated(const Ipv4Address addr)
Add the Ipv4Address to the list of IPv4 entries.
uint32_t network
the network
static const uint32_t N_BITS
the number of bits in the address
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
virtual ~Ipv4AddressGeneratorImpl()
uint32_t addrLow
the lowest allocated address
Implementation class of Ipv4AddressGenerator This generator assigns addresses sequentially from a pro...
static Ipv4Address GetNetwork(const Ipv4Mask mask)
Get the current network of the given Ipv4Mask.
Ipv4 addresses are stored in host order in this class.
Ipv4Address NextAddress(const Ipv4Mask mask)
Allocate the next Ipv4Address for the configured network and mask.
bool m_test
test mode (if true)
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if a condition is false, with a message.
uint32_t addrHigh
the highest allocated address
Ipv4Address NextNetwork(const Ipv4Mask mask)
Get the next network according to the given Ipv4Mask.
Ipv4Address GetNetwork(const Ipv4Mask mask) const
Get the current network of the given Ipv4Mask.
uint32_t Get(void) const
Get the host-order 32-bit IP mask.
NetworkState m_netTable[N_BITS]
the available networks
static Ipv4Address GetAddress(const Ipv4Mask mask)
Get the Ipv4Address that will be allocated upon NextAddress ()
static void Init(const Ipv4Address net, const Ipv4Mask mask, const Ipv4Address addr="0.0.0.1")
Initialise the base network, mask and address for the generator.
uint32_t mask
the network mask