21 #include "ns3/abort.h"
22 #include "ns3/assert.h"
24 #include "ns3/simulation-singleton.h"
95 uint8_t prefix[16] = { 0};
97 for (uint32_t i = 0; i <
N_BITS; ++i)
99 for (uint32_t j = 0; j < 16; ++j)
103 for (uint32_t j = 0; j < 15; ++j)
105 prefix[15 - j] >>= 1;
106 prefix[15 - j] |= (prefix[15 - j - 1] & 1);
109 for (uint32_t j = 0; j < 15; ++j)
114 for (uint32_t j = 0; j < 15; ++j)
119 for (uint32_t j = 0; j < 16; ++j)
148 uint8_t prefixBits[16];
152 uint8_t interfaceIdBits[16];
153 interfaceId.
GetBytes (interfaceIdBits);
166 for (int32_t j = 15 - a; j >= 0; j--)
170 for (uint32_t j = 0; j < a; j++)
174 for (uint32_t j = 15; j >= a; j--)
179 for (int32_t j = 0; j < 16; j++)
195 for (uint32_t j = 0; j < 16 - a; ++j)
199 for (uint32_t j = 16 - a; j < 16; ++j)
203 for (uint32_t j = 0; j < 15; j++)
206 nw[j] |= nw[j + 1] >> (8 - b);
208 nw[15] = nw[15] << b;
221 uint8_t interfaceIdBits[16];
223 for (int32_t j = 0; j < 16; j++)
228 for (int32_t j = 15; j >= 0; j--)
244 for (uint32_t j = 0; j < 16 - a; ++j)
248 for (uint32_t j = 16 - a; j < 16; ++j)
252 for (uint32_t j = 0; j < 15; j++)
255 nw[j] |= nw[j + 1] >> (8 - b);
257 nw[15] = nw[15] << b;
271 uint8_t interfaceIdBits[16];
272 interfaceId.
GetBytes (interfaceIdBits);
274 for (uint32_t j = 0; j < 16; ++j)
290 for (uint32_t j = 0; j < 16 - a; ++j)
294 for (uint32_t j = 16 - a; j < 16; ++j)
298 for (uint32_t j = 0; j < 15; j++)
301 nw[j] |= nw[j + 1] >> (8 - b);
303 nw[15] = nw[15] << b;
304 for (uint32_t j = 0; j < 16; j++)
322 for (uint32_t j = 0; j < 16 - a; ++j)
326 for (uint32_t j = 16 - a; j < 16; ++j)
330 for (uint32_t j = 0; j < 15; j++)
333 ad[j] |= ad[j + 1] >> (8 - b);
335 ad[15] = ad[15] << b;
336 for (uint32_t j = 0; j < 16; j++)
342 for (int32_t j = 15; j >= 0; j--)
371 std::list<Entry>::iterator i;
398 for (uint32_t j = 0; j < 16; j++)
400 taddr[j] = (*i).addrLow[j];
414 for (uint32_t j = 0; j < 16; j++)
416 taddr[j] = (*i).addrLow[j];
421 std::list<Entry>::iterator j = i;
439 for (uint32_t j = 0; j < 16; j++)
441 (*i).addrHigh[j] = addr[j];
452 for (uint32_t j = 0; j < 16; j++)
454 taddr[j] = (*i).addrLow[j];
460 for (uint32_t j = 0; j < 16; j++)
462 (*i).addrLow[j] = addr[j];
469 for (uint32_t j = 0; j < 16; j++)
498 uint8_t prefixBits[16];
501 for (int32_t i = 15; i >= 0; --i)
503 for (uint32_t j = 0; j < 8; ++j)
505 if (prefixBits[i] & 1)
507 uint32_t index =
N_BITS - (15 - i) * 8 - j;
514 NS_ASSERT_MSG (
false,
"Ipv6AddressGenerator::PrefixToIndex(): Impossible");
527 ->Init (net, prefix, interfaceId);
536 ->NextNetwork (prefix);
545 ->GetNetwork (prefix);
556 ->InitAddress (interfaceId, prefix);
565 ->GetAddress (prefix);
574 ->NextAddress (prefix);
592 ->AddAllocated (addr);
Ipv6Address GetNetwork(const Ipv6Prefix prefix) const
#define NS_LOG_FUNCTION(parameters)
uint32_t PrefixToIndex(Ipv6Prefix prefix) const
#define NS_LOG_COMPONENT_DEFINE(name)
static Ipv6Address NextNetwork(const Ipv6Prefix prefix)
Get the next network acoording to the given Ipv6Prefix.
#define NS_LOG_FUNCTION_NOARGS()
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if cond is false.
#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.
void InitAddress(const Ipv6Address interfaceId, const Ipv6Prefix prefix)
void GetBytes(uint8_t buf[16]) const
Get the bytes corresponding to the address.
NetworkState m_netTable[N_BITS]
std::list< Entry > m_entries
static const uint32_t N_BITS
#define NS_LOG_LOGIC(msg)
Ipv6Address GetAddress(const Ipv6Prefix prefix) const
static const uint32_t MOST_SIGNIFICANT_BIT
static void TestMode(void)
Used to turn off fatal errors and assertions, for testing.
#define NS_ASSERT_MSG(condition, message)
Describes an IPv6 address.
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)
static Ipv6Address GetAddress(const Ipv6Prefix prefix)
Get the Ipv6Address that will be allocated upon NextAddress()
Describes an IPv6 prefix. It is just a bitmask like Ipv4Mask.
static bool AddAllocated(const Ipv6Address addr)
Add the Ipv6Address to the list of IPv6 entries.
Ipv6Address NextAddress(const Ipv6Prefix prefix)
void Init(const Ipv6Address net, const Ipv6Prefix prefix, const Ipv6Address interfaceId)
virtual ~Ipv6AddressGeneratorImpl()
static Ipv6Address NextAddress(const Ipv6Prefix prefix)
Allocate the next Ipv6Address for the configured network and prefix.
bool AddAllocated(const Ipv6Address addr)
static Ipv6Address GetNetwork(const Ipv6Prefix prefix)
Get the current network of the given Ipv6Prefix.