21 #include "ns3/abort.h"
22 #include "ns3/assert.h"
24 #include "ns3/simulation-singleton.h"
191 uint8_t prefix[16] = { 0};
193 for (uint32_t i = 0; i <
N_BITS; ++i)
195 for (uint32_t j = 0; j < 16; ++j)
199 for (uint32_t j = 0; j < 15; ++j)
201 prefix[15 - j] >>= 1;
202 prefix[15 - j] |= (prefix[15 - j - 1] & 1);
205 for (uint32_t j = 0; j < 15; ++j)
210 for (uint32_t j = 0; j < 15; ++j)
215 for (uint32_t j = 0; j < 16; ++j)
244 uint8_t prefixBits[16];
248 uint8_t interfaceIdBits[16];
249 interfaceId.
GetBytes (interfaceIdBits);
262 for (int32_t j = 15 - a; j >= 0; j--)
266 for (uint32_t j = 0; j < a; j++)
270 for (uint32_t j = 15; j >= a; j--)
275 for (int32_t j = 0; j < 16; j++)
291 for (uint32_t j = 0; j < 16 - a; ++j)
295 for (uint32_t j = 16 - a; j < 16; ++j)
299 for (uint32_t j = 0; j < 15; j++)
302 nw[j] |= nw[j + 1] >> (8 - b);
304 nw[15] = nw[15] << b;
317 uint8_t interfaceIdBits[16];
319 for (int32_t j = 0; j < 16; j++)
324 for (int32_t j = 15; j >= 0; j--)
340 for (uint32_t j = 0; j < 16 - a; ++j)
344 for (uint32_t j = 16 - a; j < 16; ++j)
348 for (uint32_t j = 0; j < 15; j++)
351 nw[j] |= nw[j + 1] >> (8 - b);
353 nw[15] = nw[15] << b;
367 uint8_t interfaceIdBits[16];
368 interfaceId.
GetBytes (interfaceIdBits);
370 for (uint32_t j = 0; j < 16; ++j)
386 for (uint32_t j = 0; j < 16 - a; ++j)
390 for (uint32_t j = 16 - a; j < 16; ++j)
394 for (uint32_t j = 0; j < 15; j++)
397 nw[j] |= nw[j + 1] >> (8 - b);
399 nw[15] = nw[15] << b;
400 for (uint32_t j = 0; j < 16; j++)
418 for (uint32_t j = 0; j < 16 - a; ++j)
422 for (uint32_t j = 16 - a; j < 16; ++j)
426 for (uint32_t j = 0; j < 15; j++)
429 ad[j] |= ad[j + 1] >> (8 - b);
431 ad[15] = ad[15] << b;
432 for (uint32_t j = 0; j < 16; j++)
438 for (int32_t j = 15; j >= 0; j--)
467 std::list<Entry>::iterator i;
494 for (uint32_t j = 0; j < 16; j++)
496 taddr[j] = (*i).addrLow[j];
510 for (uint32_t j = 0; j < 16; j++)
512 taddr[j] = (*i).addrLow[j];
517 std::list<Entry>::iterator j = i;
535 for (uint32_t j = 0; j < 16; j++)
537 (*i).addrHigh[j] = addr[j];
548 for (uint32_t j = 0; j < 16; j++)
550 taddr[j] = (*i).addrLow[j];
556 for (uint32_t j = 0; j < 16; j++)
558 (*i).addrLow[j] = addr[j];
565 for (uint32_t j = 0; j < 16; j++)
594 uint8_t prefixBits[16];
597 for (int32_t i = 15; i >= 0; --i)
599 for (uint32_t j = 0; j < 8; ++j)
601 if (prefixBits[i] & 1)
603 uint32_t index =
N_BITS - (15 - i) * 8 - j;
610 NS_ASSERT_MSG (
false,
"Ipv6AddressGenerator::PrefixToIndex(): Impossible");
623 ->Init (net, prefix, interfaceId);
632 ->NextNetwork (prefix);
641 ->GetNetwork (prefix);
652 ->InitAddress (interfaceId, prefix);
661 ->GetAddress (prefix);
670 ->NextAddress (prefix);
688 ->AddAllocated (addr);
Ipv6Address GetNetwork(const Ipv6Prefix prefix) const
Get the current network of the given Ipv6Prefix.
This class holds the state for a given network.
#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 allocated addresses.
uint8_t prefix[16]
the network prefix
uint32_t PrefixToIndex(Ipv6Prefix prefix) const
Create an index number for the prefix.
Ipv6Address m_base
base address
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
static Ipv6Address NextNetwork(const Ipv6Prefix prefix)
Get the next network according to the given Ipv6Prefix.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
uint8_t addrMax[16]
the maximum address
static T * Get(void)
Get a pointer to the singleton instance.
void Reset(void)
Reset the networks and Ipv6Address to zero.
static void InitAddress(const Ipv6Address interfaceId, const Ipv6Prefix prefix)
Set the interfaceId for the given Ipv6Prefix.
Ipv6AddressGeneratorImpl()
static void Init(const Ipv6Address net, const Ipv6Prefix prefix, const Ipv6Address interfaceId="::1")
Initialise the base network and interfaceId for the generator.
uint8_t network[16]
the network
void InitAddress(const Ipv6Address interfaceId, const Ipv6Prefix prefix)
Set the interfaceId for the given Ipv6Prefix.
void GetBytes(uint8_t buf[16]) const
Get the bytes corresponding to the address.
NetworkState m_netTable[N_BITS]
the available networks
std::list< Entry > m_entries
contained of allocated addresses
static const uint32_t N_BITS
the number of bits in the address
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Ipv6Address GetAddress(const Ipv6Prefix prefix) const
Get the Ipv6Address that will be allocated upon NextAddress ()
uint8_t addr[16]
the address
static const uint32_t MOST_SIGNIFICANT_BIT
MSB set to 1.
Implementation class of Ipv6AddressGenerator This generator assigns addresses sequentially from a pro...
static void TestMode(void)
Used to turn off fatal errors and assertions, for testing.
void TestMode(void)
Used to turn off fatal errors and assertions, for testing.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Describes an IPv6 address.
bool m_test
test mode (if true)
static void Reset(void)
Reset the networks and Ipv6Address to zero.
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if a condition is false, with a message.
void GetBytes(uint8_t buf[16]) const
Get the bytes corresponding to the prefix.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Ipv6Address NextNetwork(const Ipv6Prefix prefix)
Get the next network according to the given Ipv6Prefix.
static Ipv6Address GetAddress(const Ipv6Prefix prefix)
Get the Ipv6Address that will be allocated upon NextAddress ()
Describes an IPv6 prefix.
static bool AddAllocated(const Ipv6Address addr)
Add the Ipv6Address to the list of IPv6 entries.
uint8_t addrLow[16]
the lowest allocated address
Ipv6Address NextAddress(const Ipv6Prefix prefix)
Allocate the next Ipv6Address for the configured network and prefix.
void Init(const Ipv6Address net, const Ipv6Prefix prefix, const Ipv6Address interfaceId)
Initialise the base network and interfaceId for the generator.
virtual ~Ipv6AddressGeneratorImpl()
static Ipv6Address NextAddress(const Ipv6Prefix prefix)
Allocate the next Ipv6Address for the configured network and prefix.
uint8_t addrHigh[16]
the highest allocated address
bool AddAllocated(const Ipv6Address addr)
Add the Ipv6Address to the list of IPv6 entries.
static Ipv6Address GetNetwork(const Ipv6Prefix prefix)
Get the current network of the given Ipv6Prefix.