11#include "ns3/assert.h" 
   13#include "ns3/simulation-singleton.h" 
  198    uint8_t prefix[16] = {0};
 
  208            prefix[15 - j] >>= 1;
 
  209            prefix[15 - j] |= (prefix[15 - j - 1] & 1);
 
 
  250    uint8_t prefixBits[16];
 
  254    uint8_t interfaceIdBits[16];
 
  255    interfaceId.
GetBytes(interfaceIdBits);
 
  268    for (
int32_t j = 15 - a; j >= 0; j--)
 
  270        m_netTable[index].network[j + a] = netBits[j];
 
  281    for (
int32_t j = 0; j < 16; j++)
 
  283        m_netTable[index].addr[j] = interfaceIdBits[j];
 
 
  291    uint8_t nw[16] = {0};
 
  295    for (
uint32_t j = 0; j < 16 - a; ++j)
 
  302        nw[j] |= nw[j + 1] >> (8 - b);
 
  304    nw[15] = nw[15] << b;
 
 
  316    uint8_t interfaceIdBits[16];
 
  317    m_base.GetBytes(interfaceIdBits);
 
  318    for (
int32_t j = 0; j < 16; j++)
 
  320        m_netTable[index].addr[j] = interfaceIdBits[j];
 
  323    for (
int32_t j = 15; j >= 0; j--)
 
  339    for (
uint32_t j = 0; j < 16 - a; ++j)
 
  343    for (
uint32_t j = 16 - a; j < 16; ++j)
 
  350        nw[j] |= nw[j + 1] >> (8 - b);
 
  352    nw[15] = nw[15] << b;
 
 
  363    uint8_t interfaceIdBits[16];
 
  364    interfaceId.
GetBytes(interfaceIdBits);
 
  368        m_netTable[index].addr[j] = interfaceIdBits[j];
 
 
  379    uint8_t nw[16] = {0};
 
  382    for (
uint32_t j = 0; j < 16 - a; ++j)
 
  389        nw[j] |= nw[j + 1] >> (8 - b);
 
  391    nw[15] = nw[15] << b;
 
 
  407    uint8_t ad[16] = {0};
 
  410    for (
uint32_t j = 0; j < 16 - a; ++j)
 
  417        ad[j] |= ad[j + 1] >> (8 - b);
 
  419    ad[15] = ad[15] << b;
 
  426    for (
int32_t j = 15; j >= 0; j--)
 
 
  453    address.GetBytes(addr);
 
  455    std::list<Entry>::iterator i;
 
  470                "Ipv6AddressGeneratorImpl::Add(): Address Collision: " << 
Ipv6Address(addr));
 
  474                    "Ipv6AddressGeneratorImpl::Add(): Address Collision: " << 
Ipv6Address(addr));
 
  486            taddr[j] = (*i).addrLow[j];
 
  502            taddr[j] = (*i).addrLow[j];
 
  515                                 "Address Collision: " 
  519                        NS_FATAL_ERROR(
"Ipv6AddressGeneratorImpl::Add(): Address Collision: " 
  529                (*i).addrHigh[j] = addr[j];
 
  542            taddr[j] = (*i).addrLow[j];
 
  550                (*i).addrLow[j] = addr[j];
 
 
  571    address.GetBytes(addr);
 
  582            NS_LOG_LOGIC(
"Ipv6AddressGeneratorImpl::IsAddressAllocated(): Address Collision: " 
 
  596        address == address.CombinePrefix(prefix),
 
  597        "Ipv6AddressGeneratorImpl::IsNetworkAllocated(): network address and mask don't match " 
  598            << address << 
" " << prefix);
 
  610                "Ipv6AddressGeneratorImpl::IsNetworkAllocated(): Network already allocated: " 
  611                << address << 
" " << low << 
"-" << high);
 
 
  639    uint8_t prefixBits[16];
 
  642    for (
int32_t i = 15; i >= 0; --i)
 
  646            if (prefixBits[i] & 1)
 
  650                                    "Ip64AddressGenerator::PrefixToIndex(): Illegal Prefix");
 
  656    NS_ASSERT_MSG(
false, 
"Ipv6AddressGenerator::PrefixToIndex(): Impossible");
 
 
static void Init(const Ipv6Address net, const Ipv6Prefix prefix, const Ipv6Address interfaceId="::1")
Initialise the base network and interfaceId for the generator.
static void TestMode()
Used to turn off fatal errors and assertions, for testing.
static Ipv6Address NextAddress(const Ipv6Prefix prefix)
Allocate the next Ipv6Address for the configured network and prefix.
static Ipv6Address GetNetwork(const Ipv6Prefix prefix)
Get the current network of the given Ipv6Prefix.
static void InitAddress(const Ipv6Address interfaceId, const Ipv6Prefix prefix)
Set the interfaceId for the given Ipv6Prefix.
static bool IsNetworkAllocated(const Ipv6Address addr, const Ipv6Prefix prefix)
Check if a network has already allocated addresses.
static bool AddAllocated(const Ipv6Address addr)
Add the Ipv6Address to the list of IPv6 entries.
static Ipv6Address GetAddress(const Ipv6Prefix prefix)
Get the Ipv6Address that will be allocated upon NextAddress ().
static Ipv6Address NextNetwork(const Ipv6Prefix prefix)
Get the next network according to the given Ipv6Prefix.
static bool IsAddressAllocated(const Ipv6Address addr)
Check the Ipv6Address allocation in the list of IPv6 entries.
static void Reset()
Reset the networks and Ipv6Address to zero.
This class holds the allocated addresses.
uint8_t addrLow[16]
the lowest allocated address
uint8_t addrHigh[16]
the highest allocated address
This class holds the state for a given network.
uint8_t addrMax[16]
the maximum address
uint8_t addr[16]
the address
uint8_t network[16]
the network
uint8_t prefix[16]
the network prefix
void Reset()
Reset the networks and Ipv6Address to zero.
static const uint32_t MOST_SIGNIFICANT_BIT
MSB set to 1.
Ipv6Address m_base
base address
virtual ~Ipv6AddressGeneratorImpl()
NetworkState m_netTable[N_BITS]
the available networks
Ipv6AddressGeneratorImpl()
bool m_test
test mode (if true)
bool AddAllocated(const Ipv6Address addr)
Add the Ipv6Address to the list of IPv6 entries.
Ipv6Address GetAddress(const Ipv6Prefix prefix) const
Get the Ipv6Address that will be allocated upon NextAddress ().
uint32_t PrefixToIndex(Ipv6Prefix prefix) const
Create an index number for the prefix.
Ipv6Address NextNetwork(const Ipv6Prefix prefix)
Get the next network according to the given Ipv6Prefix.
void TestMode()
Used to turn off fatal errors and assertions, for testing.
std::list< Entry > m_entries
contained of allocated addresses
static const uint32_t N_BITS
the number of bits in the address
void Init(const Ipv6Address net, const Ipv6Prefix prefix, const Ipv6Address interfaceId)
Initialise the base network and interfaceId for the generator.
void InitAddress(const Ipv6Address interfaceId, const Ipv6Prefix prefix)
Set the interfaceId for the given Ipv6Prefix.
bool IsNetworkAllocated(const Ipv6Address addr, const Ipv6Prefix prefix)
Check if a network has already allocated addresses.
Ipv6Address GetNetwork(const Ipv6Prefix prefix) const
Get the current network of the given Ipv6Prefix.
bool IsAddressAllocated(const Ipv6Address addr)
Check the Ipv6Address allocation in the list of IPv6 entries.
Ipv6Address NextAddress(const Ipv6Prefix prefix)
Allocate the next Ipv6Address for the configured network and prefix.
Describes an IPv6 address.
void GetBytes(uint8_t buf[16]) const
Get the bytes corresponding to the address.
Ipv6Address CombinePrefix(const Ipv6Prefix &prefix) const
Combine this address with a prefix.
Describes an IPv6 prefix.
void GetBytes(uint8_t buf[16]) const
Get the bytes corresponding to the prefix.
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_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#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.