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 <iomanip>
19#include <memory>
20
21#ifdef __WIN32__
22#include <WS2tcpip.h>
23#else
24#include <arpa/inet.h>
25#include <sys/socket.h>
26#endif
27
28namespace ns3
29{
30
31NS_LOG_COMPONENT_DEFINE("Ipv6Address");
32
33#ifdef __cplusplus
34extern "C"
35{ /* } */
36#endif
37 /**
38 * @brief Mix hash keys in-place for lookuphash
39 *
40 * @param a first word of the hash key
41 * @param b second word of the hash key
42 * @param c third word of the hash key
43 */
45 {
46 (a) -= (b);
47 (a) -= (c);
48 (a) ^= ((c) >> 13);
49 (b) -= (c);
50 (b) -= (a);
51 (b) ^= ((a) << 8);
52 (c) -= (a);
53 (c) -= (b);
54 (c) ^= ((b) >> 13);
55 (a) -= (b);
56 (a) -= (c);
57 (a) ^= ((c) >> 12);
58 (b) -= (c);
59 (b) -= (a);
60 (b) ^= ((a) << 16);
61 (c) -= (a);
62 (c) -= (b);
63 (c) ^= ((b) >> 5);
64 (a) -= (b);
65 (a) -= (c);
66 (a) ^= ((c) >> 3);
67 (b) -= (c);
68 (b) -= (a);
69 (b) ^= ((a) << 10);
70 (c) -= (a);
71 (c) -= (b);
72 (c) ^= ((b) >> 15);
73 }
74
75 /**
76 * @brief Get a hash key.
77 * @param k the key
78 * @param length the length of the key
79 * @param level the previous hash, or an arbitrary value
80 * @return hash
81 * @note Adapted from Jens Jakobsen implementation (chillispot).
82 */
83 static uint32_t lookuphash(unsigned char* k, uint32_t length, uint32_t level)
84 {
85 NS_LOG_FUNCTION(k << length << level);
86
87 typedef uint32_t ub4; /* unsigned 4-byte quantities */
88 uint32_t a = 0;
89 uint32_t b = 0;
90 uint32_t c = 0;
91 uint32_t len = 0;
92
93 /* Set up the internal state */
94 len = length;
95 a = b = 0x9e3779b9; /* the golden ratio; an arbitrary value */
96 c = level; /* the previous hash value */
97
98 /* handle most of the key */
99 while (len >= 12)
100 {
101 a += (k[0] + ((ub4)k[1] << 8) + ((ub4)k[2] << 16) + ((ub4)k[3] << 24));
102 b += (k[4] + ((ub4)k[5] << 8) + ((ub4)k[6] << 16) + ((ub4)k[7] << 24));
103 c += (k[8] + ((ub4)k[9] << 8) + ((ub4)k[10] << 16) + ((ub4)k[11] << 24));
104 mixHashKey(a, b, c);
105 k += 12;
106 len -= 12;
107 }
108
109 /* handle the last 11 bytes */
110 c += length;
111 switch (len)
112 {
113 // clang-format off
114 case 11: c += ((ub4)k[10] << 24); [[fallthrough]];
115 case 10: c += ((ub4)k[9] << 16); [[fallthrough]];
116 case 9: c += ((ub4)k[8] << 8); [[fallthrough]]; /* the first byte of c is reserved for the length */
117 case 8: b += ((ub4)k[7] << 24); [[fallthrough]];
118 case 7: b += ((ub4)k[6] << 16); [[fallthrough]];
119 case 6: b += ((ub4)k[5] << 8); [[fallthrough]];
120 case 5: b += k[4]; [[fallthrough]];
121 case 4: a += ((ub4)k[3] << 24); [[fallthrough]];
122 case 3: a += ((ub4)k[2] << 16); [[fallthrough]];
123 case 2: a += ((ub4)k[1] << 8); [[fallthrough]];
124 case 1: a += k[0];
125 /* case 0: nothing left to add */
126 // clang-format on
127 }
128 mixHashKey(a, b, c);
129
130 /* report the result */
131 return c;
132 }
133
134#ifdef __cplusplus
135}
136#endif
137
139{
140 NS_LOG_FUNCTION(this);
141 memset(m_address, 0x00, 16);
142}
143
145{
146 // Do not add function logging here, to avoid stack overflow
147 memcpy(m_address, addr.m_address, 16);
148}
149
151{
152 // Do not add function logging here, to avoid stack overflow
153 memcpy(m_address, addr->m_address, 16);
154}
155
156Ipv6Address::Ipv6Address(const char* address)
157{
158 NS_LOG_FUNCTION(this << address);
159
160 if (inet_pton(AF_INET6, address, m_address) <= 0)
161 {
162 NS_ABORT_MSG("Error, can not build an IPv6 address from an invalid string: " << address);
163 return;
164 }
165}
166
167bool
168Ipv6Address::CheckCompatible(const std::string& addressStr)
169{
170 NS_LOG_FUNCTION(addressStr);
171
172 uint8_t buffer[16];
173
174 if (inet_pton(AF_INET6, addressStr.c_str(), &buffer) <= 0)
175 {
176 NS_LOG_WARN("Error, can not build an IPv6 address from an invalid string: " << addressStr);
177 return false;
178 }
179 return true;
180}
181
182Ipv6Address::Ipv6Address(uint8_t address[16])
183{
184 NS_LOG_FUNCTION(this << &address);
185 /* 128 bit => 16 bytes */
186 memcpy(m_address, address, 16);
187}
188
190{
191 /* do nothing */
192 NS_LOG_FUNCTION(this);
193}
194
195void
196Ipv6Address::Set(const char* address)
197{
198 NS_LOG_FUNCTION(this << address);
199 if (inet_pton(AF_INET6, address, m_address) <= 0)
200 {
201 memset(m_address, 0x00, 16);
202 NS_ABORT_MSG("Error, can not set an IPv6 address from an invalid string: " << address);
203 return;
204 }
205}
206
207void
208Ipv6Address::Set(uint8_t address[16])
209{
210 /* 128 bit => 16 bytes */
211 NS_LOG_FUNCTION(this << &address);
212 memcpy(m_address, address, 16);
213}
214
215void
216Ipv6Address::Serialize(uint8_t buf[16]) const
217{
218 NS_LOG_FUNCTION(this << &buf);
219 memcpy(buf, m_address, 16);
220}
221
223Ipv6Address::Deserialize(const uint8_t buf[16])
224{
225 NS_LOG_FUNCTION(&buf);
226 Ipv6Address ipv6((uint8_t*)buf);
227 return ipv6;
228}
229
232{
233 NS_LOG_FUNCTION(addr);
234 uint8_t buf[16] = {
235 0x00,
236 0x00,
237 0x00,
238 0x00,
239 0x00,
240 0x00,
241 0x00,
242 0x00,
243 0x00,
244 0x00,
245 0xff,
246 0xff,
247 0x00,
248 0x00,
249 0x00,
250 0x00,
251 };
252 addr.Serialize(&buf[12]);
253 return Ipv6Address(buf);
254}
255
258{
259 NS_LOG_FUNCTION(this);
260 uint8_t buf[16];
261 Ipv4Address v4Addr;
262
263 Serialize(buf);
264 v4Addr = Ipv4Address::Deserialize(&buf[12]);
265 return v4Addr;
266}
267
270{
271 Ipv6Address ipv6Addr = Ipv6Address::GetAny();
272
274 {
276 }
277 else if (Mac48Address::IsMatchingType(addr))
278 {
280 }
281 else if (Mac16Address::IsMatchingType(addr))
282 {
284 }
285 else if (Mac8Address::IsMatchingType(addr))
286 {
288 }
289
290 if (ipv6Addr.IsAny())
291 {
292 NS_ABORT_MSG("Unknown address type");
293 }
294 return ipv6Addr;
295}
296
299{
300 Ipv6Address ipv6PrefixAddr = Ipv6Address::GetOnes().CombinePrefix(prefix);
301 return MakeAutoconfiguredAddress(addr, ipv6PrefixAddr);
302}
303
306{
307 NS_LOG_FUNCTION(addr << prefix);
308 Ipv6Address ret;
309 uint8_t buf[2];
310 uint8_t buf2[16];
311
312 addr.CopyTo(buf);
313 prefix.GetBytes(buf2);
314 memset(buf2 + 8, 0, 8);
315
316 memcpy(buf2 + 14, buf, 2);
317 buf2[11] = 0xff;
318 buf2[12] = 0xfe;
319
320 ret.Set(buf2);
321 return ret;
322}
323
326{
327 NS_LOG_FUNCTION(addr << prefix);
328 Ipv6Address ret;
329 uint8_t buf[16];
330 uint8_t buf2[16];
331
332 addr.CopyTo(buf);
333 prefix.GetBytes(buf2);
334
335 memcpy(buf2 + 8, buf, 3);
336 buf2[11] = 0xff;
337 buf2[12] = 0xfe;
338 memcpy(buf2 + 13, buf + 3, 3);
339 buf2[8] ^= 0x02;
340
341 ret.Set(buf2);
342 return ret;
343}
344
347{
348 NS_LOG_FUNCTION(addr << prefix);
349 Ipv6Address ret;
350 uint8_t buf[8];
351 uint8_t buf2[16];
352
353 addr.CopyTo(buf);
354 prefix.GetBytes(buf2);
355
356 memcpy(buf2 + 8, buf, 8);
357
358 ret.Set(buf2);
359 return ret;
360}
361
364{
365 NS_LOG_FUNCTION(addr << prefix);
366 Ipv6Address ret;
367 uint8_t buf[2];
368 uint8_t buf2[16];
369
370 buf[0] = 0;
371 addr.CopyTo(&buf[1]);
372 prefix.GetBytes(buf2);
373 memset(buf2 + 8, 0, 8);
374
375 memcpy(buf2 + 14, buf, 2);
376 buf2[11] = 0xff;
377 buf2[12] = 0xfe;
378
379 ret.Set(buf2);
380 return ret;
381}
382
385{
386 Ipv6Address ipv6Addr = Ipv6Address::GetAny();
387
389 {
391 }
392 else if (Mac48Address::IsMatchingType(addr))
393 {
395 }
396 else if (Mac16Address::IsMatchingType(addr))
397 {
399 }
400 else if (Mac8Address::IsMatchingType(addr))
401 {
403 }
404
405 if (ipv6Addr.IsAny())
406 {
407 NS_ABORT_MSG("Unknown address type");
408 }
409 return ipv6Addr;
410}
411
414{
415 NS_LOG_FUNCTION(addr);
416 Ipv6Address ret;
417 uint8_t buf[2];
418 uint8_t buf2[16];
419
420 addr.CopyTo(buf);
421
422 memset(buf2, 0x00, sizeof(buf2));
423 buf2[0] = 0xfe;
424 buf2[1] = 0x80;
425 memcpy(buf2 + 14, buf, 2);
426 buf2[11] = 0xff;
427 buf2[12] = 0xfe;
428
429 ret.Set(buf2);
430 return ret;
431}
432
435{
436 NS_LOG_FUNCTION(addr);
437 Ipv6Address ret;
438 uint8_t buf[16];
439 uint8_t buf2[16];
440
441 addr.CopyTo(buf);
442
443 memset(buf2, 0x00, sizeof(buf2));
444 buf2[0] = 0xfe;
445 buf2[1] = 0x80;
446 memcpy(buf2 + 8, buf, 3);
447 buf2[11] = 0xff;
448 buf2[12] = 0xfe;
449 memcpy(buf2 + 13, buf + 3, 3);
450 buf2[8] ^= 0x02;
451
452 ret.Set(buf2);
453 return ret;
454}
455
458{
459 NS_LOG_FUNCTION(addr);
460 Ipv6Address ret;
461 uint8_t buf[8];
462 uint8_t buf2[16];
463
464 addr.CopyTo(buf);
465
466 memset(buf2, 0x00, sizeof(buf2));
467 buf2[0] = 0xfe;
468 buf2[1] = 0x80;
469 memcpy(buf2 + 8, buf, 8);
470
471 ret.Set(buf2);
472 return ret;
473}
474
477{
478 NS_LOG_FUNCTION(addr);
479 Ipv6Address ret;
480 uint8_t buf[2];
481 uint8_t buf2[16];
482
483 buf[0] = 0;
484 addr.CopyTo(&buf[1]);
485
486 memset(buf2, 0x00, sizeof(buf2));
487 buf2[0] = 0xfe;
488 buf2[1] = 0x80;
489 memcpy(buf2 + 14, buf, 2);
490 buf2[11] = 0xff;
491 buf2[12] = 0xfe;
492
493 ret.Set(buf2);
494 return ret;
495}
496
499{
500 NS_LOG_FUNCTION(addr);
501 uint8_t buf[16];
502 uint8_t buf2[16];
503 Ipv6Address ret;
504
505 addr.Serialize(buf2);
506
507 memset(buf, 0x00, sizeof(buf));
508 buf[0] = 0xff;
509 buf[1] = 0x02;
510 buf[11] = 0x01;
511 buf[12] = 0xff;
512 buf[13] = buf2[13];
513 buf[14] = buf2[14];
514 buf[15] = buf2[15];
515
516 ret.Set(buf);
517 return ret;
518}
519
520void
521Ipv6Address::Print(std::ostream& os) const
522{
523 NS_LOG_FUNCTION(this << &os);
524
525 char str[INET6_ADDRSTRLEN];
526
527 if (inet_ntop(AF_INET6, m_address, str, INET6_ADDRSTRLEN))
528 {
529 os << str;
530 }
531}
532
533bool
535{
536 NS_LOG_FUNCTION(this);
537 static Ipv6Address localhost("::1");
538 return (*this == localhost);
539}
540
541bool
543{
544 NS_LOG_FUNCTION(this);
545 return m_address[0] == 0xff;
546}
547
548bool
550{
551 NS_LOG_FUNCTION(this);
552 return m_address[0] == 0xff && m_address[1] == 0x02;
553}
554
555bool
557{
558 NS_LOG_FUNCTION(this);
559 static uint8_t v4MappedPrefix[12] =
560 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff};
561 return memcmp(m_address, v4MappedPrefix, sizeof(v4MappedPrefix)) == 0;
562}
563
566{
567 NS_LOG_FUNCTION(this << prefix);
568 Ipv6Address ipv6;
569 uint8_t addr[16];
570 uint8_t pref[16];
571 unsigned int i = 0;
572
573 memcpy(addr, m_address, 16);
574 ((Ipv6Prefix)prefix).GetBytes(pref);
575
576 /* a little bit ugly... */
577 for (i = 0; i < 16; i++)
578 {
579 addr[i] = addr[i] & pref[i];
580 }
581 ipv6.Set(addr);
582 return ipv6;
583}
584
585bool
587{
588 NS_LOG_FUNCTION(this);
589
590 static Ipv6Address documentation("ff02::1:ff00:0");
591 return CombinePrefix(Ipv6Prefix(104)) == documentation;
592}
593
594bool
596{
597 NS_LOG_FUNCTION(this);
598 static Ipv6Address allNodesI("ff01::1");
599 static Ipv6Address allNodesL("ff02::1");
600 static Ipv6Address allNodesR("ff03::1");
601 return (*this == allNodesI || *this == allNodesL || *this == allNodesR);
602}
603
604bool
606{
607 NS_LOG_FUNCTION(this);
608 static Ipv6Address allroutersI("ff01::2");
609 static Ipv6Address allroutersL("ff02::2");
610 static Ipv6Address allroutersR("ff03::2");
611 static Ipv6Address allroutersS("ff05::2");
612 return (*this == allroutersI || *this == allroutersL || *this == allroutersR ||
613 *this == allroutersS);
614}
615
616bool
618{
619 NS_LOG_FUNCTION(this);
620 static Ipv6Address any("::");
621 return (*this == any);
622}
623
624bool
626{
627 NS_LOG_FUNCTION(this);
628 static Ipv6Address documentation("2001:db8::0");
629 return CombinePrefix(Ipv6Prefix(32)) == documentation;
630}
631
632bool
634{
635 NS_LOG_FUNCTION(this << prefix);
636
637 Ipv6Address masked = CombinePrefix(prefix);
638 Ipv6Address reference = Ipv6Address::GetOnes().CombinePrefix(prefix);
639
640 return masked == reference;
641}
642
643bool
645{
646 NS_LOG_FUNCTION(address);
647 return address.CheckCompatible(GetType(), 16);
648}
649
650Ipv6Address::
651operator Address() const
652{
653 return ConvertTo();
654}
655
658{
659 NS_LOG_FUNCTION(this);
660 uint8_t buf[16];
661 Serialize(buf);
662 return Address(GetType(), buf, 16);
663}
664
667{
668 NS_LOG_FUNCTION(address);
669 NS_ASSERT(address.CheckCompatible(GetType(), 16));
670 uint8_t buf[16];
671 address.CopyTo(buf);
672 return Deserialize(buf);
673}
674
675uint8_t
677{
679 static uint8_t type = Address::Register("IpAddress", 16);
680 return type;
681}
682
685{
687 static Ipv6Address nmc("ff02::1");
688 return nmc;
689}
690
693{
695 static Ipv6Address rmc("ff02::2");
696 return rmc;
697}
698
701{
703 static Ipv6Address hmc("ff02::3");
704 return hmc;
705}
706
709{
711 static Ipv6Address loopback("::1");
712 return loopback;
713}
714
717{
719 static Ipv6Address zero("::");
720 return zero;
721}
722
725{
727 static Ipv6Address any("::");
728 return any;
729}
730
733{
735 static Ipv6Address ones("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff");
736 return ones;
737}
738
739void
740Ipv6Address::GetBytes(uint8_t buf[16]) const
741{
742 NS_LOG_FUNCTION(this << &buf);
743 memcpy(buf, m_address, 16);
744}
745
746bool
748{
749 NS_LOG_FUNCTION(this);
750 static Ipv6Address linkLocal("fe80::0");
751 return CombinePrefix(Ipv6Prefix(64)) == linkLocal;
752}
753
754bool
756{
757 NS_LOG_FUNCTION(this);
758 return true;
759}
760
761std::ostream&
762operator<<(std::ostream& os, const Ipv6Address& address)
763{
764 address.Print(os);
765 return os;
766}
767
768std::istream&
769operator>>(std::istream& is, Ipv6Address& address)
770{
771 std::string str;
772 is >> str;
773 address = Ipv6Address(str.c_str());
774 return is;
775}
776
778{
779 NS_LOG_FUNCTION(this);
780 memset(m_prefix, 0x00, 16);
781 m_prefixLength = 0;
782}
783
784Ipv6Prefix::Ipv6Prefix(const char* prefix)
785{
786 NS_LOG_FUNCTION(this << prefix);
787 if (inet_pton(AF_INET6, prefix, m_prefix) <= 0)
788 {
789 NS_ABORT_MSG("Error, can not build an IPv6 prefix from an invalid string: " << prefix);
790 }
792}
793
794Ipv6Prefix::Ipv6Prefix(uint8_t prefix[16])
795{
796 NS_LOG_FUNCTION(this << &prefix);
797 memcpy(m_prefix, prefix, 16);
799}
800
801Ipv6Prefix::Ipv6Prefix(const char* prefix, uint8_t prefixLength)
802{
803 NS_LOG_FUNCTION(this << prefix);
804 if (inet_pton(AF_INET6, prefix, m_prefix) <= 0)
805 {
806 NS_ABORT_MSG("Error, can not build an IPv6 prefix from an invalid string: " << prefix);
807 }
808 uint8_t autoLength = GetMinimumPrefixLength();
809 NS_ASSERT_MSG(autoLength <= prefixLength,
810 "Ipv6Prefix: address and prefix are not compatible: " << Ipv6Address(prefix)
811 << "/" << +prefixLength);
812
813 m_prefixLength = prefixLength;
814}
815
816Ipv6Prefix::Ipv6Prefix(uint8_t prefix[16], uint8_t prefixLength)
817{
818 NS_LOG_FUNCTION(this << &prefix);
819 memcpy(m_prefix, prefix, 16);
820
821 uint8_t autoLength = GetMinimumPrefixLength();
822 NS_ASSERT_MSG(autoLength <= prefixLength,
823 "Ipv6Prefix: address and prefix are not compatible: " << Ipv6Address(prefix)
824 << "/" << +prefixLength);
825
826 m_prefixLength = prefixLength;
827}
828
830{
831 NS_LOG_FUNCTION(this << static_cast<uint32_t>(prefix));
832 unsigned int nb = 0;
833 unsigned int mod = 0;
834 unsigned int i = 0;
835
836 memset(m_prefix, 0x00, 16);
837 m_prefixLength = prefix;
838
839 NS_ASSERT(prefix <= 128);
840
841 nb = prefix / 8;
842 mod = prefix % 8;
843
844 // protect memset with 'nb > 0' check to suppress
845 // __warn_memset_zero_len compiler errors in some gcc>4.5.x
846 if (nb > 0)
847 {
848 memset(m_prefix, 0xff, nb);
849 }
850 if (mod)
851 {
852 m_prefix[nb] = 0xff << (8 - mod);
853 }
854
855 if (nb < 16)
856 {
857 nb++;
858 for (i = nb; i < 16; i++)
859 {
860 m_prefix[i] = 0x00;
861 }
862 }
863}
864
866{
867 memcpy(m_prefix, prefix.m_prefix, 16);
869}
870
872{
873 memcpy(m_prefix, prefix->m_prefix, 16);
875}
876
878{
879 /* do nothing */
880 NS_LOG_FUNCTION(this);
881}
882
883bool
885{
886 NS_LOG_FUNCTION(this << a << b);
887 uint8_t addrA[16];
888 uint8_t addrB[16];
889 unsigned int i = 0;
890
891 a.GetBytes(addrA);
892 b.GetBytes(addrB);
893
894 /* a little bit ugly... */
895 for (i = 0; i < 16; i++)
896 {
897 if ((addrA[i] & m_prefix[i]) != (addrB[i] & m_prefix[i]))
898 {
899 return false;
900 }
901 }
902 return true;
903}
904
905void
906Ipv6Prefix::Print(std::ostream& os) const
907{
908 NS_LOG_FUNCTION(this << &os);
909
910 os << "/" << (unsigned int)GetPrefixLength();
911}
912
915{
917 static Ipv6Prefix prefix((uint8_t)128);
918 return prefix;
919}
920
923{
925 static Ipv6Prefix ones((uint8_t)128);
926 return ones;
927}
928
931{
933 static Ipv6Prefix prefix((uint8_t)0);
934 return prefix;
935}
936
937void
938Ipv6Prefix::GetBytes(uint8_t buf[16]) const
939{
940 NS_LOG_FUNCTION(this << &buf);
941 memcpy(buf, m_prefix, 16);
942}
943
946{
947 uint8_t prefixBytes[16];
948 memcpy(prefixBytes, m_prefix, 16);
949
950 Ipv6Address convertedPrefix = Ipv6Address(prefixBytes);
951 return convertedPrefix;
952}
953
954uint8_t
956{
957 NS_LOG_FUNCTION(this);
958 return m_prefixLength;
959}
960
961void
962Ipv6Prefix::SetPrefixLength(uint8_t prefixLength)
963{
964 NS_LOG_FUNCTION(this);
965 m_prefixLength = prefixLength;
966}
967
968uint8_t
970{
971 NS_LOG_FUNCTION(this);
972
973 uint8_t prefixLength = 0;
974 bool stop = false;
975
976 for (int8_t i = 15; i >= 0 && !stop; i--)
977 {
978 uint8_t mask = m_prefix[i];
979
980 for (uint8_t j = 0; j < 8 && !stop; j++)
981 {
982 if ((mask & 1) == 0)
983 {
984 mask = mask >> 1;
985 prefixLength++;
986 }
987 else
988 {
989 stop = true;
990 }
991 }
992 }
993
994 return 128 - prefixLength;
995}
996
997std::ostream&
998operator<<(std::ostream& os, const Ipv6Prefix& prefix)
999{
1000 prefix.Print(os);
1001 return os;
1002}
1003
1004std::istream&
1005operator>>(std::istream& is, Ipv6Prefix& prefix)
1006{
1007 std::string str;
1008 is >> str;
1009 prefix = Ipv6Prefix(str.c_str());
1010 return is;
1011}
1012
1013size_t
1015{
1016 uint8_t buf[16];
1017
1018 x.GetBytes(buf);
1019
1020 return lookuphash(buf, sizeof(buf), 0);
1021}
1022
1025
1026} /* 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.
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 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.
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.
~Ipv6Address()
Destructor.
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.
Ipv6Address()
Default constructor.
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).
uint8_t m_address[16]
The address representation on 128 bits (16 bytes).
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.
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.
static Ipv6Prefix GetLoopback()
Get the loopback prefix ( /128).
~Ipv6Prefix()
Destructor.
uint8_t m_prefix[16]
The prefix representation.
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.
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.
Ipv6Prefix()
Default constructor.
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
void mixHashKey(uint32_t &a, uint32_t &b, uint32_t &c)
Mix hash keys in-place for lookuphash.
static uint32_t lookuphash(unsigned char *k, uint32_t length, uint32_t level)
Get a hash key.