10#include "ns3/assert.h"
12#include "ns3/simulation-singleton.h"
248 "Ipv4AddressGeneratorImpl::Init (): Inconsistent network and mask");
250 "Ipv4AddressGeneratorImpl::Init (): Inconsistent address and mask");
263 "Ipv4AddressGeneratorImpl::Init(): Address overflow");
303 "Ipv4AddressGeneratorImpl::InitAddress(): Address overflow");
332 "Ipv4AddressGeneratorImpl::NextAddress(): Address overflow");
355 "Ipv4AddressGeneratorImpl::Add(): Allocating the broadcast address is not a good idea");
357 std::list<Entry>::iterator i;
367 if (addr >= (*i).addrLow && addr <= (*i).addrHigh)
370 "Ipv4AddressGeneratorImpl::Add(): Address Collision: " <<
Ipv4Address(addr));
374 "Ipv4AddressGeneratorImpl::Add(): Address Collision: " <<
Ipv4Address(addr));
383 if (addr < (*i).addrLow - 1)
394 if (addr == (*i).addrHigh + 1)
401 if (addr == (*j).addrLow)
404 "Address Collision: "
408 NS_FATAL_ERROR(
"Ipv4AddressGeneratorImpl::Add(): Address Collision: "
416 (*i).addrHigh = addr;
426 if (addr == (*i).addrLow - 1)
449 "Ipv4AddressGeneratorImpl::IsAddressAllocated(): Don't check for the broadcast address...");
455 if (addr >= (*i).addrLow && addr <= (*i).addrHigh)
457 NS_LOG_LOGIC(
"Ipv4AddressGeneratorImpl::IsAddressAllocated(): Address Collision: "
471 address == address.CombineMask(mask),
472 "Ipv4AddressGeneratorImpl::IsNetworkAllocated(): network address and mask don't match "
473 << address <<
" " << mask);
485 "Ipv4AddressGeneratorImpl::IsNetworkAllocated(): Network already allocated: "
486 << address <<
" " << low <<
"-" << high);
524 "Ipv4AddressGenerator::MaskToIndex(): Illegal Mask");
529 NS_ASSERT_MSG(
false,
"Ipv4AddressGenerator::MaskToIndex(): Impossible");
static Ipv4Address NextAddress(const Ipv4Mask mask)
Allocate the next Ipv4Address for the configured network and mask.
static void InitAddress(const Ipv4Address addr, const Ipv4Mask mask)
Set the address for the given mask.
static void TestMode()
Used to turn off fatal errors and assertions, for testing.
static Ipv4Address NextNetwork(const Ipv4Mask mask)
Get the next network according to the given Ipv4Mask.
static void Reset()
Reset the networks and Ipv4Address to zero.
static bool AddAllocated(const Ipv4Address addr)
Add the Ipv4Address to the list of IPv4 entries.
static bool IsAddressAllocated(const Ipv4Address addr)
Check the Ipv4Address allocation in the list of IPv4 entries.
static Ipv4Address GetNetwork(const Ipv4Mask mask)
Get the current network of the given Ipv4Mask.
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.
static bool IsNetworkAllocated(const Ipv4Address addr, const Ipv4Mask mask)
Check if a network has already allocated addresses.
static Ipv4Address GetAddress(const Ipv4Mask mask)
Get the Ipv4Address that will be allocated upon NextAddress ()
This class holds the allocated addresses.
uint32_t addrHigh
the highest allocated address
uint32_t addrLow
the lowest allocated address
This class holds the state for a given network.
uint32_t addrMax
the maximum address
uint32_t mask
the network mask
uint32_t network
the network
Implementation class of Ipv4AddressGenerator This generator assigns addresses sequentially from a pro...
uint32_t MaskToIndex(Ipv4Mask mask) const
Create an index number for the network mask.
Ipv4Address GetNetwork(const Ipv4Mask mask) const
Get the current network of the given Ipv4Mask.
Ipv4Address GetAddress(const Ipv4Mask mask) const
Get the Ipv4Address that will be allocated upon NextAddress ()
virtual ~Ipv4AddressGeneratorImpl()
Ipv4AddressGeneratorImpl()
void Init(const Ipv4Address net, const Ipv4Mask mask, const Ipv4Address addr)
Initialise the base network, mask and address for the generator.
bool IsNetworkAllocated(const Ipv4Address addr, const Ipv4Mask mask)
Check if a network has already allocated addresses.
bool AddAllocated(const Ipv4Address addr)
Add the Ipv4Address to the list of IPv4 entries.
static const uint32_t N_BITS
the number of bits in the address
void InitAddress(const Ipv4Address addr, const Ipv4Mask mask)
Set the address for the given mask.
NetworkState m_netTable[N_BITS]
the available networks
std::list< Entry > m_entries
contained of allocated addresses
void TestMode()
Used to turn off fatal errors and assertions, for testing.
static const uint32_t MOST_SIGNIFICANT_BIT
MSB set to 1.
bool IsAddressAllocated(const Ipv4Address addr)
Check the Ipv4Address allocation in the list of IPv4 entries.
void Reset()
Reset the networks and Ipv4Address to zero.
bool m_test
test mode (if true)
Ipv4Address NextAddress(const Ipv4Mask mask)
Allocate the next Ipv4Address for the configured network and mask.
Ipv4Address NextNetwork(const Ipv4Mask mask)
Get the next network according to the given Ipv4Mask.
Ipv4 addresses are stored in host order in this class.
Ipv4Address CombineMask(const Ipv4Mask &mask) const
Combine this address with a network mask.
uint32_t Get() const
Get the host-order 32-bit IP address.
a class to represent an Ipv4 address mask
uint32_t Get() const
Get the host-order 32-bit IP mask.
static T * Get()
Get a pointer to the singleton instance.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if a condition is false, with a message.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Every class exported by the ns3 library is enclosed in the ns3 namespace.