A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ipv6-address.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007-2008 Louis Pasteur University
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
7 */
8
9#include "ipv6-address.h"
10
11#include "mac16-address.h"
12#include "mac48-address.h"
13#include "mac64-address.h"
14
15#include "ns3/assert.h"
16#include "ns3/log.h"
17
18#include <algorithm>
19#include <iomanip>
20#include <memory>
21
22#ifdef __WIN32__
23#include <WS2tcpip.h>
24#else
25#include <arpa/inet.h>
26#include <sys/socket.h>
27#endif
28
29namespace ns3
30{
31
32NS_LOG_COMPONENT_DEFINE("Ipv6Address");
33
34Ipv6Address::Ipv6Address(const char* address)
35{
36 NS_LOG_FUNCTION(this << address);
37
38 if (inet_pton(AF_INET6, address, m_address.data()) <= 0)
39 {
40 m_address.fill(0x00);
41 NS_ABORT_MSG("Error, can not build an IPv6 address from an invalid string: " << address);
42 return;
43 }
44 m_hash.reset();
45}
46
47bool
48Ipv6Address::CheckCompatible(const std::string& addressStr)
49{
50 NS_LOG_FUNCTION(addressStr);
51
52 uint8_t buffer[16];
53
54 if (inet_pton(AF_INET6, addressStr.c_str(), &buffer) <= 0)
55 {
56 NS_LOG_WARN("Error, can not build an IPv6 address from an invalid string: " << addressStr);
57 return false;
58 }
59 return true;
60}
61
62Ipv6Address::Ipv6Address(uint8_t address[16])
63{
64 NS_LOG_FUNCTION(this << &address);
65 std::copy(address, address + 16, m_address.begin());
66 m_hash.reset();
67}
68
69void
70Ipv6Address::Set(const char* address)
71{
72 NS_LOG_FUNCTION(this << address);
73 if (inet_pton(AF_INET6, address, m_address.data()) <= 0)
74 {
75 m_address.fill(0x00);
76 NS_ABORT_MSG("Error, can not set an IPv6 address from an invalid string: " << address);
77 return;
78 }
79 m_hash.reset();
80}
81
82void
83Ipv6Address::Set(uint8_t address[16])
84{
85 NS_LOG_FUNCTION(this << &address);
86 std::copy(address, address + 16, m_address.begin());
87 m_hash.reset();
88}
89
90void
91Ipv6Address::Serialize(uint8_t buf[16]) const
92{
93 NS_LOG_FUNCTION(this << &buf);
94 std::copy(m_address.begin(), m_address.end(), buf);
95}
96
98Ipv6Address::Deserialize(const uint8_t buf[16])
99{
100 NS_LOG_FUNCTION(&buf);
101 Ipv6Address ipv6((uint8_t*)buf);
102 return ipv6;
103}
104
107{
108 NS_LOG_FUNCTION(addr);
109 uint8_t buf[16] = {0};
110
111 buf[10] = 0xff;
112 buf[11] = 0xff;
113
114 addr.Serialize(&buf[12]);
115 return Ipv6Address(buf);
116}
117
120{
121 NS_LOG_FUNCTION(this);
122 uint8_t buf[16];
123 Ipv4Address v4Addr;
124
125 Serialize(buf);
126 v4Addr = Ipv4Address::Deserialize(&buf[12]);
127 return v4Addr;
128}
129
132{
133 Ipv6Address ipv6Addr = Ipv6Address::GetAny();
134
136 {
138 }
139 else if (Mac48Address::IsMatchingType(addr))
140 {
142 }
143 else if (Mac16Address::IsMatchingType(addr))
144 {
146 }
147 else if (Mac8Address::IsMatchingType(addr))
148 {
150 }
151
152 if (ipv6Addr.IsAny())
153 {
154 NS_ABORT_MSG("Unknown address type");
155 }
156 return ipv6Addr;
157}
158
161{
162 Ipv6Address ipv6PrefixAddr = Ipv6Address::GetOnes().CombinePrefix(prefix);
163 return MakeAutoconfiguredAddress(addr, ipv6PrefixAddr);
164}
165
168{
169 NS_LOG_FUNCTION(addr << prefix);
170 Ipv6Address ret;
171 uint8_t buf[2];
172 uint8_t buf2[16];
173
174 addr.CopyTo(buf);
175 prefix.GetBytes(buf2);
176 memset(buf2 + 8, 0, 8);
177
178 memcpy(buf2 + 14, buf, 2);
179 buf2[11] = 0xff;
180 buf2[12] = 0xfe;
181
182 ret.Set(buf2);
183 return ret;
184}
185
188{
189 NS_LOG_FUNCTION(addr << prefix);
190 Ipv6Address ret;
191 uint8_t buf[16];
192 uint8_t buf2[16];
193
194 addr.CopyTo(buf);
195 prefix.GetBytes(buf2);
196
197 memcpy(buf2 + 8, buf, 3);
198 buf2[11] = 0xff;
199 buf2[12] = 0xfe;
200 memcpy(buf2 + 13, buf + 3, 3);
201 buf2[8] ^= 0x02;
202
203 ret.Set(buf2);
204 return ret;
205}
206
209{
210 NS_LOG_FUNCTION(addr << prefix);
211 Ipv6Address ret;
212 uint8_t buf[8];
213 uint8_t buf2[16];
214
215 addr.CopyTo(buf);
216 prefix.GetBytes(buf2);
217
218 memcpy(buf2 + 8, buf, 8);
219
220 ret.Set(buf2);
221 return ret;
222}
223
226{
227 NS_LOG_FUNCTION(addr << prefix);
228 Ipv6Address ret;
229 uint8_t buf[2];
230 uint8_t buf2[16];
231
232 buf[0] = 0;
233 addr.CopyTo(&buf[1]);
234 prefix.GetBytes(buf2);
235 memset(buf2 + 8, 0, 8);
236
237 memcpy(buf2 + 14, buf, 2);
238 buf2[11] = 0xff;
239 buf2[12] = 0xfe;
240
241 ret.Set(buf2);
242 return ret;
243}
244
247{
248 Ipv6Address ipv6Addr = Ipv6Address::GetAny();
249
251 {
253 }
254 else if (Mac48Address::IsMatchingType(addr))
255 {
257 }
258 else if (Mac16Address::IsMatchingType(addr))
259 {
261 }
262 else if (Mac8Address::IsMatchingType(addr))
263 {
265 }
266
267 if (ipv6Addr.IsAny())
268 {
269 NS_ABORT_MSG("Unknown address type");
270 }
271 return ipv6Addr;
272}
273
276{
277 NS_LOG_FUNCTION(addr);
278 Ipv6Address ret;
279 uint8_t buf[2];
280 uint8_t buf2[16];
281
282 addr.CopyTo(buf);
283
284 memset(buf2, 0x00, sizeof(buf2));
285 buf2[0] = 0xfe;
286 buf2[1] = 0x80;
287 memcpy(buf2 + 14, buf, 2);
288 buf2[11] = 0xff;
289 buf2[12] = 0xfe;
290
291 ret.Set(buf2);
292 return ret;
293}
294
297{
298 NS_LOG_FUNCTION(addr);
299 Ipv6Address ret;
300 uint8_t buf[16];
301 uint8_t buf2[16];
302
303 addr.CopyTo(buf);
304
305 memset(buf2, 0x00, sizeof(buf2));
306 buf2[0] = 0xfe;
307 buf2[1] = 0x80;
308 memcpy(buf2 + 8, buf, 3);
309 buf2[11] = 0xff;
310 buf2[12] = 0xfe;
311 memcpy(buf2 + 13, buf + 3, 3);
312 buf2[8] ^= 0x02;
313
314 ret.Set(buf2);
315 return ret;
316}
317
320{
321 NS_LOG_FUNCTION(addr);
322 Ipv6Address ret;
323 uint8_t buf[8];
324 uint8_t buf2[16];
325
326 addr.CopyTo(buf);
327
328 memset(buf2, 0x00, sizeof(buf2));
329 buf2[0] = 0xfe;
330 buf2[1] = 0x80;
331 memcpy(buf2 + 8, buf, 8);
332
333 ret.Set(buf2);
334 return ret;
335}
336
339{
340 NS_LOG_FUNCTION(addr);
341 Ipv6Address ret;
342 uint8_t buf[2];
343 uint8_t buf2[16];
344
345 buf[0] = 0;
346 addr.CopyTo(&buf[1]);
347
348 memset(buf2, 0x00, sizeof(buf2));
349 buf2[0] = 0xfe;
350 buf2[1] = 0x80;
351 memcpy(buf2 + 14, buf, 2);
352 buf2[11] = 0xff;
353 buf2[12] = 0xfe;
354
355 ret.Set(buf2);
356 return ret;
357}
358
361{
362 NS_LOG_FUNCTION(addr);
363 uint8_t buf[16];
364 uint8_t buf2[16];
365 Ipv6Address ret;
366
367 addr.Serialize(buf2);
368
369 memset(buf, 0x00, sizeof(buf));
370 buf[0] = 0xff;
371 buf[1] = 0x02;
372 buf[11] = 0x01;
373 buf[12] = 0xff;
374 buf[13] = buf2[13];
375 buf[14] = buf2[14];
376 buf[15] = buf2[15];
377
378 ret.Set(buf);
379 return ret;
380}
381
382void
383Ipv6Address::Print(std::ostream& os) const
384{
385 NS_LOG_FUNCTION(this << &os);
386
387 char str[INET6_ADDRSTRLEN];
388
389 if (inet_ntop(AF_INET6, m_address.data(), str, INET6_ADDRSTRLEN))
390 {
391 os << str;
392 }
393}
394
395bool
397{
398 NS_LOG_FUNCTION(this);
399 static Ipv6Address localhost("::1");
400 return (*this == localhost);
401}
402
403bool
405{
406 NS_LOG_FUNCTION(this);
407 return m_address[0] == 0xff;
408}
409
410bool
412{
413 NS_LOG_FUNCTION(this);
414 return m_address[0] == 0xff && m_address[1] == 0x02;
415}
416
417bool
419{
420 NS_LOG_FUNCTION(this);
421 static std::array<uint8_t, 12> v4MappedPrefix =
422 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff};
423 return std::equal(v4MappedPrefix.begin(), v4MappedPrefix.end(), m_address.begin());
424}
425
428{
429 NS_LOG_FUNCTION(this << prefix);
430 Ipv6Address ipv6;
431 uint8_t addr[16];
432 uint8_t pref[16];
433 unsigned int i = 0;
434
435 std::copy(m_address.begin(), m_address.end(), addr);
436 ((Ipv6Prefix)prefix).GetBytes(pref);
437
438 for (i = 0; i < 16; i++)
439 {
440 addr[i] = addr[i] & pref[i];
441 }
442 ipv6.Set(addr);
443 return ipv6;
444}
445
446bool
448{
449 NS_LOG_FUNCTION(this);
450
451 static Ipv6Address documentation("ff02::1:ff00:0");
452 return CombinePrefix(Ipv6Prefix(104)) == documentation;
453}
454
455bool
457{
458 NS_LOG_FUNCTION(this);
459 static Ipv6Address allNodesI("ff01::1");
460 static Ipv6Address allNodesL("ff02::1");
461 static Ipv6Address allNodesR("ff03::1");
462 return (*this == allNodesI || *this == allNodesL || *this == allNodesR);
463}
464
465bool
467{
468 NS_LOG_FUNCTION(this);
469 static Ipv6Address allroutersI("ff01::2");
470 static Ipv6Address allroutersL("ff02::2");
471 static Ipv6Address allroutersR("ff03::2");
472 static Ipv6Address allroutersS("ff05::2");
473 return (*this == allroutersI || *this == allroutersL || *this == allroutersR ||
474 *this == allroutersS);
475}
476
477bool
479{
480 NS_LOG_FUNCTION(this);
481 static Ipv6Address any("::");
482 return (*this == any);
483}
484
485bool
487{
488 NS_LOG_FUNCTION(this);
489 static Ipv6Address documentation("2001:db8::0");
490 return CombinePrefix(Ipv6Prefix(32)) == documentation;
491}
492
493bool
495{
496 NS_LOG_FUNCTION(this << prefix);
497
498 Ipv6Address masked = CombinePrefix(prefix);
499 Ipv6Address reference = Ipv6Address::GetOnes().CombinePrefix(prefix);
500
501 return masked == reference;
502}
503
504bool
506{
507 NS_LOG_FUNCTION(address);
508 return address.CheckCompatible(GetType(), 16);
509}
510
511Ipv6Address::
512operator Address() const
513{
514 return ConvertTo();
515}
516
519{
520 NS_LOG_FUNCTION(this);
521 uint8_t buf[16];
522 Serialize(buf);
523 return Address(GetType(), buf, 16);
524}
525
528{
529 NS_LOG_FUNCTION(address);
530 NS_ASSERT(address.CheckCompatible(GetType(), 16));
531 uint8_t buf[16];
532 address.CopyTo(buf);
533 return Deserialize(buf);
534}
535
536uint8_t
538{
540 static uint8_t type = Address::Register("IpAddress", 16);
541 return type;
542}
543
546{
548 static Ipv6Address nmc("ff02::1");
549 return nmc;
550}
551
554{
556 static Ipv6Address rmc("ff02::2");
557 return rmc;
558}
559
562{
564 static Ipv6Address hmc("ff02::3");
565 return hmc;
566}
567
570{
572 static Ipv6Address loopback("::1");
573 return loopback;
574}
575
578{
580 static Ipv6Address zero("::");
581 return zero;
582}
583
586{
588 static Ipv6Address any("::");
589 return any;
590}
591
594{
596 static Ipv6Address ones("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff");
597 return ones;
598}
599
600void
601Ipv6Address::GetBytes(uint8_t buf[16]) const
602{
603 NS_LOG_FUNCTION(this << &buf);
604 std::copy(m_address.begin(), m_address.end(), buf);
605}
606
607bool
609{
610 NS_LOG_FUNCTION(this);
611 static Ipv6Address linkLocal("fe80::0");
612 return CombinePrefix(Ipv6Prefix(64)) == linkLocal;
613}
614
615bool
617{
618 NS_LOG_FUNCTION(this);
619 return true;
620}
621
622void
624{
625 auto mix = [](uint32_t x, uint32_t y, uint32_t z, int shift) -> uint32_t {
626 x -= y + z;
627 x ^= (shift > 0) ? (z << shift) : (z >> (-shift));
628 return x;
629 };
630
631 a = mix(a, b, c, -13);
632 b = mix(b, c, a, 8);
633 c = mix(c, a, b, -13);
634 a = mix(a, b, c, -12);
635 b = mix(b, c, a, 16);
636 c = mix(c, a, b, -5);
637 a = mix(a, b, c, -3);
638 b = mix(b, c, a, 10);
639 c = mix(c, a, b, -15);
640}
641
644{
645 NS_LOG_FUNCTION(this);
646
647 uint32_t a = 0x9e3779b9; /* the golden ratio; an arbitrary value */
648 uint32_t b = 0x9e3779b9; /* the golden ratio; an arbitrary value */
649 uint32_t c = 0;
650
651 auto fold = [](const uint8_t* a) -> uint32_t {
652 auto f = static_cast<uint32_t>(a[0]);
653 f += static_cast<uint32_t>(a[1]) << 8;
654 f += static_cast<uint32_t>(a[2]) << 16;
655 f += static_cast<uint32_t>(a[3]) << 24;
656 return f;
657 };
658
659 a += fold(&m_address[0]);
660 b += fold(&m_address[4]);
661 c += fold(&m_address[8]);
662 MixHashKey(a, b, c);
663
664 c += 16;
665 a += fold(&m_address[12]);
666 MixHashKey(a, b, c);
667
668 /* set the hash and report the result */
669 m_hash = c;
670 return c;
671}
672
675{
676 if (m_hash)
677 {
678 return m_hash.value();
679 }
680 return GenerateHash();
681}
682
683std::ostream&
684operator<<(std::ostream& os, const Ipv6Address& address)
685{
686 address.Print(os);
687 return os;
688}
689
690std::istream&
691operator>>(std::istream& is, Ipv6Address& address)
692{
693 std::string str;
694 is >> str;
695 address = Ipv6Address(str.c_str());
696 return is;
697}
698
699Ipv6Prefix::Ipv6Prefix(const char* prefix)
700{
701 NS_LOG_FUNCTION(this << prefix);
702 if (inet_pton(AF_INET6, prefix, m_prefix.data()) <= 0)
703 {
704 NS_ABORT_MSG("Error, can not build an IPv6 prefix from an invalid string: " << prefix);
705 }
707}
708
709Ipv6Prefix::Ipv6Prefix(uint8_t prefix[16])
710{
711 NS_LOG_FUNCTION(this << &prefix);
712 std::copy(prefix, prefix + 16, m_prefix.begin());
714}
715
716Ipv6Prefix::Ipv6Prefix(const char* prefix, uint8_t prefixLength)
717{
718 NS_LOG_FUNCTION(this << prefix);
719 if (inet_pton(AF_INET6, prefix, m_prefix.data()) <= 0)
720 {
721 NS_ABORT_MSG("Error, can not build an IPv6 prefix from an invalid string: " << prefix);
722 }
723 uint8_t autoLength = GetMinimumPrefixLength();
724 NS_ASSERT_MSG(autoLength <= prefixLength,
725 "Ipv6Prefix: address and prefix are not compatible: " << Ipv6Address(prefix)
726 << "/" << +prefixLength);
727
728 m_prefixLength = prefixLength;
729}
730
731Ipv6Prefix::Ipv6Prefix(uint8_t prefix[16], uint8_t prefixLength)
732{
733 NS_LOG_FUNCTION(this << &prefix);
734 std::copy(prefix, prefix + 16, m_prefix.begin());
735
736 uint8_t autoLength = GetMinimumPrefixLength();
737 NS_ASSERT_MSG(autoLength <= prefixLength,
738 "Ipv6Prefix: address and prefix are not compatible: " << Ipv6Address(prefix)
739 << "/" << +prefixLength);
740
741 m_prefixLength = prefixLength;
742}
743
745{
746 NS_LOG_FUNCTION(this << static_cast<uint32_t>(prefix));
747 unsigned int nb = 0;
748 unsigned int mod = 0;
749 unsigned int i = 0;
750
751 m_prefix.fill(0x00);
752 m_prefixLength = prefix;
753
754 NS_ASSERT(prefix <= 128);
755
756 nb = prefix / 8;
757 mod = prefix % 8;
758
759 // protect memset with 'nb > 0' check to suppress
760 // __warn_memset_zero_len compiler errors in some gcc>4.5.x
761 if (nb > 0)
762 {
763 memset(m_prefix.data(), 0xff, nb);
764 }
765 if (mod)
766 {
767 m_prefix[nb] = 0xff << (8 - mod);
768 }
769
770 if (nb < 16)
771 {
772 nb++;
773 for (i = nb; i < 16; i++)
774 {
775 m_prefix[i] = 0x00;
776 }
777 }
778}
779
780bool
782{
783 NS_LOG_FUNCTION(this << a << b);
784 uint8_t addrA[16];
785 uint8_t addrB[16];
786 unsigned int i = 0;
787
788 a.GetBytes(addrA);
789 b.GetBytes(addrB);
790
791 /* a little bit ugly... */
792 for (i = 0; i < 16; i++)
793 {
794 if ((addrA[i] & m_prefix[i]) != (addrB[i] & m_prefix[i]))
795 {
796 return false;
797 }
798 }
799 return true;
800}
801
802void
803Ipv6Prefix::Print(std::ostream& os) const
804{
805 NS_LOG_FUNCTION(this << &os);
806
807 os << "/" << (unsigned int)GetPrefixLength();
808}
809
812{
814 static Ipv6Prefix prefix((uint8_t)128);
815 return prefix;
816}
817
820{
822 static Ipv6Prefix ones((uint8_t)128);
823 return ones;
824}
825
828{
830 static Ipv6Prefix prefix((uint8_t)0);
831 return prefix;
832}
833
834void
835Ipv6Prefix::GetBytes(uint8_t buf[16]) const
836{
837 NS_LOG_FUNCTION(this << &buf);
838 memcpy(buf, m_prefix.data(), 16);
839}
840
843{
844 uint8_t prefixBytes[16];
845 memcpy(prefixBytes, m_prefix.data(), 16);
846
847 auto convertedPrefix = Ipv6Address(prefixBytes);
848 return convertedPrefix;
849}
850
851uint8_t
853{
854 NS_LOG_FUNCTION(this);
855 return m_prefixLength;
856}
857
858void
859Ipv6Prefix::SetPrefixLength(uint8_t prefixLength)
860{
861 NS_LOG_FUNCTION(this);
862 m_prefixLength = prefixLength;
863}
864
865uint8_t
867{
868 NS_LOG_FUNCTION(this);
869
870 uint8_t prefixLength = 0;
871 bool stop = false;
872
873 for (int8_t i = 15; i >= 0 && !stop; i--)
874 {
875 uint8_t mask = m_prefix[i];
876
877 for (uint8_t j = 0; j < 8 && !stop; j++)
878 {
879 if ((mask & 1) == 0)
880 {
881 mask = mask >> 1;
882 prefixLength++;
883 }
884 else
885 {
886 stop = true;
887 }
888 }
889 }
890
891 return 128 - prefixLength;
892}
893
894std::ostream&
895operator<<(std::ostream& os, const Ipv6Prefix& prefix)
896{
897 prefix.Print(os);
898 return os;
899}
900
901std::istream&
902operator>>(std::istream& is, Ipv6Prefix& prefix)
903{
904 std::string str;
905 is >> str;
906 prefix = Ipv6Prefix(str.c_str());
907 return is;
908}
909
910size_t
912{
913 return x.GetHash();
914}
915
918
919} /* namespace ns3 */
cairo_uint64_t x
_cairo_uint_96by64_32x64_divrem:
a polymophic address class
Definition address.h:114
static uint8_t Register(const std::string &kind, uint8_t length)
Allocate a new type id for a new type of address.
Definition address.cc:130
Ipv4 addresses are stored in host order in this class.
void Serialize(uint8_t buf[4]) const
Serialize this address to a 4-byte buffer.
static Ipv4Address Deserialize(const uint8_t buf[4])
size_t operator()(const Ipv6Address &x) const
Returns the hash of an IPv6 address.
Describes an IPv6 address.
static uint8_t GetType()
Return the Type of address.
uint32_t GetHash() const
Get the address hash.
bool IsLinkLocal() const
If the IPv6 address is a link-local address (fe80::/64).
bool HasPrefix(const Ipv6Prefix &prefix) const
Compares an address and a prefix.
bool IsSolicitedMulticast() const
If the IPv6 address is a Solicited multicast address.
static Ipv6Address GetAllNodesMulticast()
Get the "all nodes multicast" address.
void Print(std::ostream &os) const
Print this address to the given output stream.
static Ipv6Address MakeSolicitedAddress(Ipv6Address addr)
Make the solicited IPv6 address.
static void MixHashKey(uint32_t &a, uint32_t &b, uint32_t &c)
Mix hash keys in-place for lookuphash.
static Ipv6Address GetAny()
Get the "any" (::) Ipv6Address.
bool IsDocumentation() const
If the IPv6 address is a documentation address (2001:DB8::/32).
static Ipv6Address GetAllHostsMulticast()
Get the "all hosts multicast" address.
Ipv6Address()=default
Default constructor.
bool IsAllNodesMulticast() const
If the IPv6 address is "all nodes multicast" (ff02::1/8).
static bool CheckCompatible(const std::string &addressStr)
Checks if the string contains an Ipv6Address.
bool IsLinkLocalMulticast() const
If the IPv6 address is link-local multicast (ff02::/16).
static Ipv6Address Deserialize(const uint8_t buf[16])
Deserialize this address.
static Ipv6Address GetZero()
Get the 0 (::) Ipv6Address.
static Ipv6Address MakeAutoconfiguredAddress(Address addr, Ipv6Address prefix)
Make the autoconfigured IPv6 address from a Mac address.
bool IsMulticast() const
If the IPv6 address is multicast (ff00::/8).
void GetBytes(uint8_t buf[16]) const
Get the bytes corresponding to the address.
bool IsIpv4MappedAddress() const
If the address is an IPv4-mapped address.
void Set(const char *address)
Sets an Ipv6Address by parsing the input C-string.
void Serialize(uint8_t buf[16]) const
Serialize this address to a 16-byte buffer.
std::optional< uint32_t > m_hash
address hash.
std::array< uint8_t, 16 > m_address
The address representation on 128 bits (16 bytes).
Address ConvertTo() const
convert the IPv6Address object to an Address object.
bool IsAny() const
If the IPv6 address is the "Any" address.
static Ipv6Address GetAllRoutersMulticast()
Get the "all routers multicast" address.
bool IsLocalhost() const
If the IPv6 address is localhost (::1).
static Ipv6Address ConvertFrom(const Address &address)
Convert the Address object into an Ipv6Address ones.
bool IsInitialized() const
static Ipv6Address GetOnes()
Get the "all-1" IPv6 address (ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff).
static Ipv6Address MakeAutoconfiguredLinkLocalAddress(Address mac)
Make the autoconfigured link-local IPv6 address from a Mac address.
Ipv4Address GetIpv4MappedAddress() const
Return the Ipv4 address.
static bool IsMatchingType(const Address &address)
If the Address matches the type.
static Ipv6Address MakeIpv4MappedAddress(Ipv4Address addr)
Make the Ipv4-mapped IPv6 address.
uint32_t GenerateHash() const
Generate and return a hash key.
static Ipv6Address GetLoopback()
Get the loopback address.
Ipv6Address CombinePrefix(const Ipv6Prefix &prefix) const
Combine this address with a prefix.
bool IsAllRoutersMulticast() const
If the IPv6 address is "all routers multicast" (ff02::2/8).
Describes an IPv6 prefix.
uint8_t m_prefixLength
The prefix length.
std::array< uint8_t, 16 > m_prefix
The prefix representation.
static Ipv6Prefix GetLoopback()
Get the loopback prefix ( /128).
void Print(std::ostream &os) const
Print this address to the given output stream.
uint8_t GetPrefixLength() const
Get prefix length.
Ipv6Address ConvertToIpv6Address() const
Convert the Prefix into an IPv6 Address.
Ipv6Prefix()=default
Default constructor.
static Ipv6Prefix GetZero()
Get the zero prefix ( /0).
bool IsMatch(Ipv6Address a, Ipv6Address b) const
Check whether two addresses have the same bits in the prefix portion of their addresses.
static Ipv6Prefix GetOnes()
Get the "all-1" IPv6 mask (ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff).
void SetPrefixLength(uint8_t prefixLength)
Set prefix length.
uint8_t GetMinimumPrefixLength() const
Get the minimum prefix length, i.e., 128 - the length of the largest sequence trailing zeroes.
void GetBytes(uint8_t buf[16]) const
Get the bytes corresponding to the prefix.
This class can contain 16 bit addresses.
static bool IsMatchingType(const Address &address)
static Mac16Address ConvertFrom(const Address &address)
void CopyTo(uint8_t buffer[2]) const
an EUI-48 address
static bool IsMatchingType(const Address &address)
static Mac48Address ConvertFrom(const Address &address)
void CopyTo(uint8_t buffer[6]) const
an EUI-64 address
static bool IsMatchingType(const Address &address)
void CopyTo(uint8_t buffer[8]) const
static Mac64Address ConvertFrom(const Address &address)
A class used for addressing MAC8 MAC's.
static Mac8Address ConvertFrom(const Address &address)
Convert a generic address to a Mac8Address.
static bool IsMatchingType(const Address &address)
Check that a generic Address is compatible with Mac8Address.
void CopyTo(uint8_t *pBuffer) const
Writes address to buffer parameter.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition assert.h:75
#define ATTRIBUTE_HELPER_CPP(type)
Define the attribute value, accessor and checkers for class type.
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition abort.h:38
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:194
#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 ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition log.h:253
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition angles.cc:148
std::istream & operator>>(std::istream &is, Angles &a)
Definition angles.cc:172