21 #include "ns3/abort.h"
22 #include "ns3/assert.h"
24 #include "ns3/simulation-singleton.h"
204 uint8_t prefix[16] = { 0};
206 for (uint32_t i = 0; i <
N_BITS; ++i)
208 for (uint32_t j = 0; j < 16; ++j)
212 for (uint32_t j = 0; j < 15; ++j)
214 prefix[15 - j] >>= 1;
215 prefix[15 - j] |= (prefix[15 - j - 1] & 1);
218 for (uint32_t j = 0; j < 15; ++j)
223 for (uint32_t j = 0; j < 15; ++j)
228 for (uint32_t j = 0; j < 16; ++j)
257 uint8_t prefixBits[16];
261 uint8_t interfaceIdBits[16];
262 interfaceId.
GetBytes (interfaceIdBits);
275 for (int32_t j = 15 - a; j >= 0; j--)
279 for (uint32_t j = 0; j < a; j++)
283 for (uint32_t j = 15; j >= a; j--)
288 for (int32_t j = 0; j < 16; j++)
304 for (uint32_t j = 0; j < 16 - a; ++j)
308 for (uint32_t j = 16 - a; j < 16; ++j)
312 for (uint32_t j = 0; j < 15; j++)
315 nw[j] |= nw[j + 1] >> (8 - b);
317 nw[15] = nw[15] << b;
330 uint8_t interfaceIdBits[16];
332 for (int32_t j = 0; j < 16; j++)
337 for (int32_t j = 15; j >= 0; j--)
353 for (uint32_t j = 0; j < 16 - a; ++j)
357 for (uint32_t j = 16 - a; j < 16; ++j)
361 for (uint32_t j = 0; j < 15; j++)
364 nw[j] |= nw[j + 1] >> (8 - b);
366 nw[15] = nw[15] << b;
380 uint8_t interfaceIdBits[16];
381 interfaceId.
GetBytes (interfaceIdBits);
383 for (uint32_t j = 0; j < 16; ++j)
399 for (uint32_t j = 0; j < 16 - a; ++j)
403 for (uint32_t j = 16 - a; j < 16; ++j)
407 for (uint32_t j = 0; j < 15; j++)
410 nw[j] |= nw[j + 1] >> (8 - b);
412 nw[15] = nw[15] << b;
413 for (uint32_t j = 0; j < 16; j++)
431 for (uint32_t j = 0; j < 16 - a; ++j)
435 for (uint32_t j = 16 - a; j < 16; ++j)
439 for (uint32_t j = 0; j < 15; j++)
442 ad[j] |= ad[j + 1] >> (8 - b);
444 ad[15] = ad[15] << b;
445 for (uint32_t j = 0; j < 16; j++)
451 for (int32_t j = 15; j >= 0; j--)
480 std::list<Entry>::iterator i;
507 for (uint32_t j = 0; j < 16; j++)
509 taddr[j] = (*i).addrLow[j];
523 for (uint32_t j = 0; j < 16; j++)
525 taddr[j] = (*i).addrLow[j];
530 std::list<Entry>::iterator j = i;
548 for (uint32_t j = 0; j < 16; j++)
550 (*i).addrHigh[j] = addr[j];
561 for (uint32_t j = 0; j < 16; j++)
563 taddr[j] = (*i).addrLow[j];
569 for (uint32_t j = 0; j < 16; j++)
571 (*i).addrLow[j] = addr[j];
578 for (uint32_t j = 0; j < 16; j++)
607 uint8_t prefixBits[16];
610 for (int32_t i = 15; i >= 0; --i)
612 for (uint32_t j = 0; j < 8; ++j)
614 if (prefixBits[i] & 1)
616 uint32_t index =
N_BITS - (15 - i) * 8 - j;
623 NS_ASSERT_MSG (
false,
"Ipv6AddressGenerator::PrefixToIndex(): Impossible");
636 ->Init (net, prefix, interfaceId);
645 ->NextNetwork (prefix);
654 ->GetNetwork (prefix);
665 ->InitAddress (interfaceId, prefix);
674 ->GetAddress (prefix);
683 ->NextAddress (prefix);
701 ->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)
This class holds the allocated addresses.
uint8_t prefix[16]
/internal the network prefix
uint32_t PrefixToIndex(Ipv6Prefix prefix) const
Create an index number for the prefix.
Ipv6Address m_base
/internal base address
static Ipv6Address NextNetwork(const Ipv6Prefix prefix)
Get the next network according to the given Ipv6Prefix.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
uint8_t addrMax[16]
/internal the maximum address
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if cond is false.
void Reset(void)
Reset the networks and Ipv6Address to zero.
#define NS_FATAL_ERROR(msg)
fatal error handling
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]
/internal 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]
/internal the available networks
std::list< Entry > m_entries
/internal contained of allocated addresses
static const uint32_t N_BITS
/internal the number of bits in the address
#define NS_LOG_LOGIC(msg)
Ipv6Address GetAddress(const Ipv6Prefix prefix) const
Get the Ipv6Address that will be allocated upon NextAddress ()
uint32_t shift
/internal a shift
uint8_t addr[16]
/internal the address
static const uint32_t MOST_SIGNIFICANT_BIT
/internal 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)
NS_LOG_COMPONENT_DEFINE("Ipv6AddressGenerator")
Describes an IPv6 address.
bool m_test
/internal test mode (if true)
static void Reset(void)
Reset the networks and Ipv6Address to zero.
void GetBytes(uint8_t buf[16]) const
Get the bytes corresponding to the prefix.
#define NS_LOG_DEBUG(msg)
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]
/internal 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]
/internal 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.