20 #include "ns3/abort.h"    21 #include "ns3/assert.h"    23 #include "ns3/simulation-singleton.h"   191   : m_entries (), m_test (false)
   222   for (uint32_t i = 0; i < 
N_BITS; ++i)
   253   uint32_t netBits = net.
Get ();
   254   uint32_t addrBits = addr.
Get ();
   307   const Ipv4Address addr,
   313   uint32_t addrBits = addr.Get ();
   346                        "Ipv4AddressGeneratorImpl::NextAddress(): Address overflow");
   366   uint32_t addr = 
address.Get ();
   368   NS_ABORT_MSG_UNLESS (addr, 
"Ipv4AddressGeneratorImpl::Add(): Allocating the broadcast address is not a good idea"); 
   370   std::list<Entry>::iterator i;
   380       if (addr >= (*i).addrLow && addr <= (*i).addrHigh)
   394       if (addr < (*i).addrLow - 1)
   405       if (addr == (*i).addrHigh + 1)
   407           std::list<Entry>::iterator j = i;
   412               if (addr == (*j).addrLow)
   415                                 "Address Collision: " << Ipv4Address (addr));
   418                       NS_FATAL_ERROR (
"Ipv4AddressGeneratorImpl::Add(): Address Collision: " << Ipv4Address (addr));
   425           (*i).addrHigh = addr;
   435       if (addr == (*i).addrLow - 1)
   444   entry.addrLow = entry.addrHigh = addr;
   454   uint32_t addr = 
address.Get ();
   456   NS_ABORT_MSG_UNLESS (addr, 
"Ipv4AddressGeneratorImpl::IsAddressAllocated(): Don't check for the broadcast address...");
   458   std::list<Entry>::iterator i;
   464       if (addr >= (*i).addrLow && addr <= (*i).addrHigh)
   479                        "Ipv4AddressGeneratorImpl::IsNetworkAllocated(): network address and mask don't match " << 
address << 
" " << mask);
   481   std::list<Entry>::iterator i;
   491           NS_LOG_LOGIC (
"Ipv4AddressGeneratorImpl::IsNetworkAllocated(): Network already allocated: " <<
   492                         address << 
" " << low << 
"-" << high);
   527   for (uint32_t i = 0; i < 
N_BITS; ++i)
   531           uint32_t index = 
N_BITS - i;
   537   NS_ASSERT_MSG (
false, 
"Ipv4AddressGenerator::MaskToIndex(): Impossible");
   550   ->Init (net, mask, addr);
   559          ->NextNetwork (mask);
   579   ->InitAddress (addr, mask);
   597          ->NextAddress (mask);
   615          ->AddAllocated (addr);
   624          ->IsAddressAllocated (addr);
   633          ->IsNetworkAllocated (addr, mask);
 void Init(const Ipv4Address net, const Ipv4Mask mask, const Ipv4Address addr)
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. 
 
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
 
static void TestMode(void)
Used to turn off fatal errors and assertions, for testing. 
 
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
 
This class holds the state for a given network. 
 
uint32_t MaskToIndex(Ipv4Mask mask) const
Create an index number for the network mask. 
 
a class to represent an Ipv4 address 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 Ipv4Address NextNetwork(const Ipv4Mask mask)
Get the next network according to 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 AddAllocated(const Ipv4Address addr)
Add the Ipv4Address to the list of IPv4 entries. 
 
#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. 
 
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function. 
 
Ipv4Address GetAddress(const Ipv4Mask mask) const
Get the Ipv4Address that will be allocated upon NextAddress () 
 
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 InitAddress(const Ipv4Address addr, const Ipv4Mask mask)
Set the address for the given mask. 
 
void Reset(void)
Reset the networks and Ipv4Address to zero. 
 
Ipv4Address GetNetwork(const Ipv4Mask mask) const
Get the current network of the given Ipv4Mask. 
 
bool IsNetworkAllocated(const Ipv4Address addr, const Ipv4Mask mask)
Check if a network has already allocated addresses. 
 
Ipv4Address CombineMask(Ipv4Mask const &mask) const
Combine this address with a network mask. 
 
static void Reset(void)
Reset the networks and Ipv4Address to zero. 
 
static Ipv4Address GetNetwork(const Ipv4Mask mask)
Get the current network of the given Ipv4Mask. 
 
void InitAddress(const Ipv4Address addr, const Ipv4Mask mask)
Set the address for the given mask. 
 
std::list< Entry > m_entries
contained of allocated addresses 
 
Every class exported by the ns3 library is enclosed in the ns3 namespace. 
 
static bool IsAddressAllocated(const Ipv4Address addr)
Check the Ipv4Address allocation in the list of IPv4 entries. 
 
uint32_t network
the network 
 
static const uint32_t N_BITS
the number of bits in the address 
 
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
 
static Ipv4Address NextAddress(const Ipv4Mask mask)
Allocate the next Ipv4Address for the configured network and mask. 
 
static Ipv4Address GetAddress(const Ipv4Mask mask)
Get the Ipv4Address that will be allocated upon NextAddress () 
 
virtual ~Ipv4AddressGeneratorImpl()
 
uint32_t addrLow
the lowest allocated address 
 
Implementation class of Ipv4AddressGenerator This generator assigns addresses sequentially from a pro...
 
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 Get(void) const
Get the host-order 32-bit IP mask. 
 
uint32_t addrHigh
the highest allocated address 
 
Ipv4Address NextNetwork(const Ipv4Mask mask)
Get the next network according to the given Ipv4Mask. 
 
bool IsAddressAllocated(const Ipv4Address addr)
Check the Ipv4Address allocation in the list of IPv4 entries. 
 
uint32_t Get(void) const
Get the host-order 32-bit IP address. 
 
NetworkState m_netTable[N_BITS]
the available networks 
 
uint32_t mask
the network mask