21 #include "ns3/abort.h"
22 #include "ns3/assert.h"
24 #include "ns3/simulation-singleton.h"
209 uint8_t prefix[16] = {0};
211 for (uint32_t i = 0; i <
N_BITS; ++i)
213 for (uint32_t j = 0; j < 16; ++j)
217 for (uint32_t j = 0; j < 15; ++j)
219 prefix[15 - j] >>= 1;
220 prefix[15 - j] |= (prefix[15 - j - 1] & 1);
223 for (uint32_t j = 0; j < 15; ++j)
228 for (uint32_t j = 0; j < 15; ++j)
233 for (uint32_t j = 0; j < 16; ++j)
261 uint8_t prefixBits[16];
265 uint8_t interfaceIdBits[16];
266 interfaceId.
GetBytes(interfaceIdBits);
279 for (int32_t j = 15 - a; j >= 0; j--)
283 for (uint32_t j = 0; j < a; j++)
287 for (uint32_t j = 15; j >= a; j--)
292 for (int32_t j = 0; j < 16; j++)
302 uint8_t nw[16] = {0};
306 for (uint32_t j = 0; j < 16 - a; ++j)
310 for (uint32_t j = 0; j < 15; j++)
313 nw[j] |= nw[j + 1] >> (8 - b);
315 nw[15] = nw[15] << b;
327 uint8_t interfaceIdBits[16];
329 for (int32_t j = 0; j < 16; j++)
334 for (int32_t j = 15; j >= 0; j--)
350 for (uint32_t j = 0; j < 16 - a; ++j)
354 for (uint32_t j = 16 - a; j < 16; ++j)
358 for (uint32_t j = 0; j < 15; j++)
361 nw[j] |= nw[j + 1] >> (8 - b);
363 nw[15] = nw[15] << b;
374 uint8_t interfaceIdBits[16];
375 interfaceId.
GetBytes(interfaceIdBits);
377 for (uint32_t j = 0; j < 16; ++j)
390 uint8_t nw[16] = {0};
393 for (uint32_t j = 0; j < 16 - a; ++j)
397 for (uint32_t j = 0; j < 15; j++)
400 nw[j] |= nw[j + 1] >> (8 - b);
402 nw[15] = nw[15] << b;
403 for (uint32_t j = 0; j < 16; j++)
418 uint8_t ad[16] = {0};
421 for (uint32_t j = 0; j < 16 - a; ++j)
425 for (uint32_t j = 0; j < 15; j++)
428 ad[j] |= ad[j + 1] >> (8 - b);
430 ad[15] = ad[15] << b;
431 for (uint32_t j = 0; j < 16; j++)
437 for (int32_t j = 15; j >= 0; j--)
466 std::list<Entry>::iterator i;
481 "Ipv6AddressGeneratorImpl::Add(): Address Collision: " <<
Ipv6Address(addr));
485 "Ipv6AddressGeneratorImpl::Add(): Address Collision: " <<
Ipv6Address(addr));
495 for (uint32_t j = 0; j < 16; j++)
497 taddr[j] = (*i).addrLow[j];
511 for (uint32_t j = 0; j < 16; j++)
513 taddr[j] = (*i).addrLow[j];
526 "Address Collision: "
530 NS_FATAL_ERROR(
"Ipv6AddressGeneratorImpl::Add(): Address Collision: "
538 for (uint32_t j = 0; j < 16; j++)
540 (*i).addrHigh[j] = addr[j];
551 for (uint32_t j = 0; j < 16; j++)
553 taddr[j] = (*i).addrLow[j];
559 for (uint32_t j = 0; j < 16; j++)
561 (*i).addrLow[j] = addr[j];
568 for (uint32_t j = 0; j < 16; j++)
593 NS_LOG_LOGIC(
"Ipv6AddressGeneratorImpl::IsAddressAllocated(): Address Collision: "
608 "Ipv6AddressGeneratorImpl::IsNetworkAllocated(): network address and mask don't match "
621 "Ipv6AddressGeneratorImpl::IsNetworkAllocated(): Network already allocated: "
622 <<
address <<
" " << low <<
"-" << high);
650 uint8_t prefixBits[16];
653 for (int32_t i = 15; i >= 0; --i)
655 for (uint32_t j = 0; j < 8; ++j)
657 if (prefixBits[i] & 1)
659 uint32_t index =
N_BITS - (15 - i) * 8 - j;
661 "Ip64AddressGenerator::PrefixToIndex(): Illegal Prefix");
667 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
Implementation class of Ipv6AddressGenerator This generator assigns addresses sequentially from a pro...
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.