48 #include "ns3/assert.h" 72 static uint32_t
lookuphash (
unsigned char* k, uint32_t length, uint32_t level)
75 #define mix(a, b, c) \ 77 (a) -= (b); (a) -= (c); (a) ^= ((c) >> 13); \ 78 (b) -= (c); (b) -= (a); (b) ^= ((a) << 8); \ 79 (c) -= (a); (c) -= (b); (c) ^= ((b) >> 13); \ 80 (a) -= (b); (a) -= (c); (a) ^= ((c) >> 12); \ 81 (b) -= (c); (b) -= (a); (b) ^= ((a) << 16); \ 82 (c) -= (a); (c) -= (b); (c) ^= ((b) >> 5); \ 83 (a) -= (b); (a) -= (c); (a) ^= ((c) >> 3); \ 84 (b) -= (c); (b) -= (a); (b) ^= ((a) << 10); \ 85 (c) -= (a); (c) -= (b); (c) ^= ((b) >> 15); \ 102 a += (k[0] + ((ub4)k[1] << 8) + ((ub4)k[2] << 16) + ((ub4)k[3] << 24));
103 b += (k[4] + ((ub4)k[5] << 8) + ((ub4)k[6] << 16) + ((ub4)k[7] << 24));
104 c += (k[8] + ((ub4)k[9] << 8) + ((ub4)k[10] << 16) + ((ub4)k[11] << 24));
114 case 11: c += ((ub4)k[10] << 24);
115 case 10: c += ((ub4)k[9] << 16);
116 case 9: c += ((ub4)k[8] << 8);
117 case 8: b += ((ub4)k[7] << 24);
118 case 7: b += ((ub4)k[6] << 16);
119 case 6: b += ((ub4)k[5] << 8);
121 case 4: a += ((ub4)k[3] << 24);
122 case 3: a += ((ub4)k[2] << 16);
123 case 2: a += ((ub4)k[1] << 8);
153 static const char xdigits_l[] =
"0123456789abcdef";
154 static const char xdigits_u[] =
"0123456789ABCDEF";
155 unsigned char tmp[16];
156 unsigned char* tp = tmp;
157 unsigned char*
const endp = tp + 16;
158 unsigned char* colonp = 0;
159 const char* xdigits = 0;
161 const char* curtok = 0;
164 int seen_xdigits = 0;
165 unsigned int val = 0;
167 memset (tp, 0x00, 16);
180 while ((ch = *
address++) !=
'\0')
184 if ((pch = strchr ((xdigits = xdigits_l), ch)) == 0)
186 pch = strchr ((xdigits = xdigits_u), ch);
192 val |= (pch - xdigits);
194 if (++seen_xdigits > 4)
219 *tp++ = (
unsigned char)(val >> 8) & 0xff;
220 *tp++ = (
unsigned char) val & 0xff;
228 if (ch ==
'.' && (endp - tp > 3 )) &&
229 inet_pton4 (curtok, tp) > 0)
245 *tp++ = (
unsigned char)(val >> 8) & 0xff;
246 *tp++ = (
unsigned char) val & 0xff;
255 const int n = tp - colonp;
263 for (i = 1; i <=
n; i++)
265 endp[-i] = colonp[
n - i];
277 memcpy (addr, tmp, 16);
355 uint8_t buf[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
356 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 };
393 if (ipv6Addr.
IsAny ())
409 memset (buf2+8, 0, 8);
411 memcpy (buf2 + 14, buf, 2);
429 memcpy (buf2 + 8, buf, 3);
432 memcpy (buf2 + 13, buf + 3, 3);
449 memcpy (buf2 + 8, buf, 8);
465 memset (buf2+8, 0, 8);
467 memcpy (buf2 + 14, buf, 2);
496 if (ipv6Addr.
IsAny ())
512 memset (buf2, 0x00,
sizeof (buf2));
515 memcpy (buf2 + 14, buf, 2);
532 memset (buf2, 0x00,
sizeof (buf2));
535 memcpy (buf2 + 8, buf, 3);
538 memcpy (buf2 + 13, buf + 3, 3);
554 memset (buf2, 0x00,
sizeof (buf2));
557 memcpy (buf2 + 8, buf, 8);
573 memset (buf2, 0x00,
sizeof (buf2));
576 memcpy (buf2 + 14, buf, 2);
593 memset (buf, 0x00,
sizeof (buf));
632 int8_t bestBase = -1;
655 if (bestBase == -1 || curLen > bestLen)
666 if (bestBase == -1 || curLen > bestLen)
672 if (bestBase != -1 && bestLen < 2)
677 for (i = 0; i < 8;) {
690 os << std::hex << (
unsigned int)
address[i];
694 if (bestBase != -1 && (bestBase + bestLen) == 8)
705 return (*
this == localhost);
731 uint8_t v4MappedPrefix[12] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
732 0x00, 0x00, 0xff, 0xff };
733 if (memcmp(
m_address, v4MappedPrefix,
sizeof(v4MappedPrefix)) == 0)
752 for (i = 0; i < 16; i++)
754 addr[i] = addr[i] & pref[i];
767 if (buf[0] == 0xff &&
783 return (*
this == allNodesI || *
this == allNodesL || *
this == allNodesR);
793 return (*
this == allroutersI || *
this == allroutersL || *
this == allroutersR || *
this == allroutersS);
800 return (*
this == any);
906 static Ipv6Address ones (
"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff");
984 NS_ASSERT_MSG (autoLength <= prefixLength,
"Ipv6Prefix: address and prefix are not compatible: " <<
Ipv6Address (prefix) <<
"/" << +prefixLength);
995 NS_ASSERT_MSG (autoLength <= prefixLength,
"Ipv6Prefix: address and prefix are not compatible: " <<
Ipv6Address (prefix) <<
"/" << +prefixLength);
1029 for (i = nb; i < 16; i++)
1065 for (i = 0; i < 16; i++)
1125 uint8_t prefixLength = 0;
1128 for(int8_t i=15; i>=0 && !stop; i--)
1132 for(uint8_t j=0; j<8 && !stop; j++)
1134 if ((mask & 1) == 0)
1146 return 128 - prefixLength;
static bool IsMatchingType(const Address &address)
If the Address matches the type.
static bool IsMatchingType(const Address &address)
static Ipv4Address Deserialize(const uint8_t buf[4])
static Ipv6Address GetLoopback()
Get the loopback address.
std::istream & operator>>(std::istream &is, Angles &a)
initialize a struct Angles from input
bool IsLocalhost() const
If the IPv6 address is localhost (::1).
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Ipv4Address GetIpv4MappedAddress() const
Return the Ipv4 address.
Ipv6Address()
Default constructor.
uint8_t m_address[16]
The address representation on 128 bits (16 bytes).
bool IsIpv4MappedAddress() const
If the address is an IPv4-mapped address.
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Ipv6Prefix()
Default constructor.
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
void SetPrefixLength(uint8_t prefixLength)
Set prefix length.
static Mac16Address ConvertFrom(const Address &address)
static bool IsMatchingType(const Address &address)
static Ipv6Address MakeAutoconfiguredLinkLocalAddress(Address mac)
Make the autoconfigured link-local IPv6 address from a Mac address.
#define ATTRIBUTE_HELPER_CPP(type)
Define the attribute value, accessor and checkers for class type
static Ipv6Address Deserialize(const uint8_t buf[16])
Deserialize this address.
static Ipv6Address MakeAutoconfiguredAddress(Address addr, Ipv6Address prefix)
Make the autoconfigured IPv6 address from a Mac address.
void GetBytes(uint8_t buf[16]) const
Get the bytes corresponding to the address.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
static Ipv6Address GetAny()
Get the "any" (::) Ipv6Address.
Address ConvertTo(void) const
convert the IPv6Address object to an Address object.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
void GetBytes(uint8_t buf[16]) const
Get the bytes corresponding to the prefix.
void CopyTo(uint8_t buffer[2]) const
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
static bool IsMatchingType(const Address &address)
Check that a generic Address is compatible with Mac8Address.
static Ipv6Prefix GetZero()
Get the zero prefix ( /0).
static uint32_t lookuphash(unsigned char *k, uint32_t length, uint32_t level)
Get a hash key.
uint8_t m_prefixLength
The prefix length.
size_t operator()(Ipv6Address const &x) const
Unary operator to hash IPv6 address.
a polymophic address class
bool IsMatch(Ipv6Address a, Ipv6Address b) const
If the Address match the type.
bool IsSolicitedMulticast() const
If the IPv6 address is a Solicited multicast address.
void CopyTo(uint8_t buffer[6]) const
NS_DEPRECATED_3_31 bool IsEqual(const Ipv6Address &other) const
Comparison operation between two Ipv6Addresses.
bool IsDocumentation() const
If the IPv6 address is a documentation address (2001:DB8::/32).
static Ipv6Address GetZero()
Get the 0 (::) Ipv6Address.
void CopyTo(uint8_t buffer[8]) const
A class used for addressing MAC8 MAC's.
bool IsLinkLocal() const
If the IPv6 address is a link-local address (fe80::/64).
Ipv6Address CombinePrefix(Ipv6Prefix const &prefix) const
Combine this address with a prefix.
uint8_t GetMinimumPrefixLength() const
Get the minimum prefix length, i.e., 128 - the length of the largest sequence trailing zeroes...
void Set(char const *address)
Sets an Ipv6Address by parsing the input C-string.
static Mac48Address ConvertFrom(const Address &address)
static Ipv6Address GetAllHostsMulticast()
Get the "all hosts multicast" address.
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
bool IsAllRoutersMulticast() const
If the IPv6 address is "all routers multicast" (ff02::2/8).
bool IsMulticast() const
If the IPv6 address is multicast (ff00::/8).
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool IsAllNodesMulticast() const
If the IPv6 address is "all nodes multicast" (ff02::1/8).
bool HasPrefix(Ipv6Prefix const &prefix) const
Compares an address and a prefix.
std::string reference
reference tag
static Ipv6Address GetAllNodesMulticast()
Get the "all nodes multicast" address.
uint8_t m_prefix[16]
The prefix representation.
static bool AsciiToIpv6Host(const char *address, uint8_t addr[16])
Convert an IPv6 C-string into a 128-bit representation.
This class can contain 16 bit addresses.
uint8_t GetPrefixLength() const
Get prefix length.
NS_DEPRECATED_3_31 bool IsEqual(const Ipv6Prefix &other) const
Comparison operation between two Ipv6Prefix.
void Print(std::ostream &os) const
Print this address to the given output stream.
bool IsLinkLocalMulticast() const
If the IPv6 address is link-local multicast (ff02::/16).
Describes an IPv6 address.
Ipv4 addresses are stored in host order in this class.
static Ipv6Prefix GetOnes()
Get the "all-1" IPv6 mask (ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff).
bool m_initialized
IPv6 address has been explicitly initialized to a valid value.
static Mac64Address ConvertFrom(const Address &address)
~Ipv6Address()
Destructor.
static Ipv6Address GetOnes()
Get the "all-1" IPv6 address (ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff).
static Ipv6Prefix GetLoopback()
Get the loopback prefix ( /128).
Describes an IPv6 prefix.
static bool IsMatchingType(const Address &address)
static Ipv6Address MakeIpv4MappedAddress(Ipv4Address addr)
Make the Ipv4-mapped IPv6 address.
static uint8_t Register(void)
Allocate a new type id for a new type of address.
static Mac8Address ConvertFrom(const Address &address)
Convert a generic address to a Mac8Address.
static uint8_t GetType(void)
Return the Type of address.
void Print(std::ostream &os) const
Print this address to the given output stream.
bool IsInitialized(void) const
void Serialize(uint8_t buf[4]) const
Serialize this address to a 4-byte buffer.
void CopyTo(uint8_t *pBuffer) const
Writes address to buffer parameter.
bool IsAny() const
If the IPv6 address is the "Any" address.
void Serialize(uint8_t buf[16]) const
Serialize this address to a 16-byte buffer.
static Ipv6Address MakeSolicitedAddress(Ipv6Address addr)
Make the solicited IPv6 address.
static Ipv6Address GetAllRoutersMulticast()
Get the "all routers multicast" address.
static Ipv6Address ConvertFrom(const Address &address)
Convert the Address object into an Ipv6Address ones.