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) /* all the case statements fall through */
112 {
113 case 11:
114 c += ((ub4)k[10] << 24);
115 case 10:
116 c += ((ub4)k[9] << 16);
117 case 9:
118 c += ((ub4)k[8] << 8); /* the first byte of c is reserved for the length */
119 case 8:
120 b += ((ub4)k[7] << 24);
121 case 7:
122 b += ((ub4)k[6] << 16);
123 case 6:
124 b += ((ub4)k[5] << 8);
125 case 5:
126 b += k[4];
127 case 4:
128 a += ((ub4)k[3] << 24);
129 case 3:
130 a += ((ub4)k[2] << 16);
131 case 2:
132 a += ((ub4)k[1] << 8);
133 case 1:
134 a += k[0];
135 /* case 0: nothing left to add */
136 }
137 mixHashKey(a, b, c);
138
139 /* report the result */
140 return c;
141 }
142
143#ifdef __cplusplus
144}
145#endif
146
148{
149 NS_LOG_FUNCTION(this);
150 memset(m_address, 0x00, 16);
151}
152
154{
155 // Do not add function logging here, to avoid stack overflow
156 memcpy(m_address, addr.m_address, 16);
157}
158
160{
161 // Do not add function logging here, to avoid stack overflow
162 memcpy(m_address, addr->m_address, 16);
163}
164
165Ipv6Address::Ipv6Address(const char* address)
166{
167 NS_LOG_FUNCTION(this << address);
168
169 if (inet_pton(AF_INET6, address, m_address) <= 0)
170 {
171 NS_ABORT_MSG("Error, can not build an IPv6 address from an invalid string: " << address);
172 return;
173 }
174}
175
176bool
177Ipv6Address::CheckCompatible(const std::string& addressStr)
178{
179 NS_LOG_FUNCTION(addressStr);
180
181 uint8_t buffer[16];
182
183 if (inet_pton(AF_INET6, addressStr.c_str(), &buffer) <= 0)
184 {
185 NS_LOG_WARN("Error, can not build an IPv6 address from an invalid string: " << addressStr);
186 return false;
187 }
188 return true;
189}
190
191Ipv6Address::Ipv6Address(uint8_t address[16])
192{
193 NS_LOG_FUNCTION(this << &address);
194 /* 128 bit => 16 bytes */
195 memcpy(m_address, address, 16);
196}
197
199{
200 /* do nothing */
201 NS_LOG_FUNCTION(this);
202}
203
204void
205Ipv6Address::Set(const char* address)
206{
207 NS_LOG_FUNCTION(this << address);
208 if (inet_pton(AF_INET6, address, m_address) <= 0)
209 {
210 memset(m_address, 0x00, 16);
211 NS_ABORT_MSG("Error, can not set an IPv6 address from an invalid string: " << address);
212 return;
213 }
214}
215
216void
217Ipv6Address::Set(uint8_t address[16])
218{
219 /* 128 bit => 16 bytes */
220 NS_LOG_FUNCTION(this << &address);
221 memcpy(m_address, address, 16);
222}
223
224void
225Ipv6Address::Serialize(uint8_t buf[16]) const
226{
227 NS_LOG_FUNCTION(this << &buf);
228 memcpy(buf, m_address, 16);
229}
230
232Ipv6Address::Deserialize(const uint8_t buf[16])
233{
234 NS_LOG_FUNCTION(&buf);
235 Ipv6Address ipv6((uint8_t*)buf);
236 return ipv6;
237}
238
241{
242 NS_LOG_FUNCTION(addr);
243 uint8_t buf[16] = {
244 0x00,
245 0x00,
246 0x00,
247 0x00,
248 0x00,
249 0x00,
250 0x00,
251 0x00,
252 0x00,
253 0x00,
254 0xff,
255 0xff,
256 0x00,
257 0x00,
258 0x00,
259 0x00,
260 };
261 addr.Serialize(&buf[12]);
262 return Ipv6Address(buf);
263}
264
267{
268 NS_LOG_FUNCTION(this);
269 uint8_t buf[16];
270 Ipv4Address v4Addr;
271
272 Serialize(buf);
273 v4Addr = Ipv4Address::Deserialize(&buf[12]);
274 return v4Addr;
275}
276
279{
280 Ipv6Address ipv6Addr = Ipv6Address::GetAny();
281
283 {
285 }
286 else if (Mac48Address::IsMatchingType(addr))
287 {
289 }
290 else if (Mac16Address::IsMatchingType(addr))
291 {
293 }
294 else if (Mac8Address::IsMatchingType(addr))
295 {
297 }
298
299 if (ipv6Addr.IsAny())
300 {
301 NS_ABORT_MSG("Unknown address type");
302 }
303 return ipv6Addr;
304}
305
308{
309 Ipv6Address ipv6PrefixAddr = Ipv6Address::GetOnes().CombinePrefix(prefix);
310 return MakeAutoconfiguredAddress(addr, ipv6PrefixAddr);
311}
312
315{
316 NS_LOG_FUNCTION(addr << prefix);
317 Ipv6Address ret;
318 uint8_t buf[2];
319 uint8_t buf2[16];
320
321 addr.CopyTo(buf);
322 prefix.GetBytes(buf2);
323 memset(buf2 + 8, 0, 8);
324
325 memcpy(buf2 + 14, buf, 2);
326 buf2[11] = 0xff;
327 buf2[12] = 0xfe;
328
329 ret.Set(buf2);
330 return ret;
331}
332
335{
336 NS_LOG_FUNCTION(addr << prefix);
337 Ipv6Address ret;
338 uint8_t buf[16];
339 uint8_t buf2[16];
340
341 addr.CopyTo(buf);
342 prefix.GetBytes(buf2);
343
344 memcpy(buf2 + 8, buf, 3);
345 buf2[11] = 0xff;
346 buf2[12] = 0xfe;
347 memcpy(buf2 + 13, buf + 3, 3);
348 buf2[8] ^= 0x02;
349
350 ret.Set(buf2);
351 return ret;
352}
353
356{
357 NS_LOG_FUNCTION(addr << prefix);
358 Ipv6Address ret;
359 uint8_t buf[8];
360 uint8_t buf2[16];
361
362 addr.CopyTo(buf);
363 prefix.GetBytes(buf2);
364
365 memcpy(buf2 + 8, buf, 8);
366
367 ret.Set(buf2);
368 return ret;
369}
370
373{
374 NS_LOG_FUNCTION(addr << prefix);
375 Ipv6Address ret;
376 uint8_t buf[2];
377 uint8_t buf2[16];
378
379 buf[0] = 0;
380 addr.CopyTo(&buf[1]);
381 prefix.GetBytes(buf2);
382 memset(buf2 + 8, 0, 8);
383
384 memcpy(buf2 + 14, buf, 2);
385 buf2[11] = 0xff;
386 buf2[12] = 0xfe;
387
388 ret.Set(buf2);
389 return ret;
390}
391
394{
395 Ipv6Address ipv6Addr = Ipv6Address::GetAny();
396
398 {
400 }
401 else if (Mac48Address::IsMatchingType(addr))
402 {
404 }
405 else if (Mac16Address::IsMatchingType(addr))
406 {
408 }
409 else if (Mac8Address::IsMatchingType(addr))
410 {
412 }
413
414 if (ipv6Addr.IsAny())
415 {
416 NS_ABORT_MSG("Unknown address type");
417 }
418 return ipv6Addr;
419}
420
423{
424 NS_LOG_FUNCTION(addr);
425 Ipv6Address ret;
426 uint8_t buf[2];
427 uint8_t buf2[16];
428
429 addr.CopyTo(buf);
430
431 memset(buf2, 0x00, sizeof(buf2));
432 buf2[0] = 0xfe;
433 buf2[1] = 0x80;
434 memcpy(buf2 + 14, buf, 2);
435 buf2[11] = 0xff;
436 buf2[12] = 0xfe;
437
438 ret.Set(buf2);
439 return ret;
440}
441
444{
445 NS_LOG_FUNCTION(addr);
446 Ipv6Address ret;
447 uint8_t buf[16];
448 uint8_t buf2[16];
449
450 addr.CopyTo(buf);
451
452 memset(buf2, 0x00, sizeof(buf2));
453 buf2[0] = 0xfe;
454 buf2[1] = 0x80;
455 memcpy(buf2 + 8, buf, 3);
456 buf2[11] = 0xff;
457 buf2[12] = 0xfe;
458 memcpy(buf2 + 13, buf + 3, 3);
459 buf2[8] ^= 0x02;
460
461 ret.Set(buf2);
462 return ret;
463}
464
467{
468 NS_LOG_FUNCTION(addr);
469 Ipv6Address ret;
470 uint8_t buf[8];
471 uint8_t buf2[16];
472
473 addr.CopyTo(buf);
474
475 memset(buf2, 0x00, sizeof(buf2));
476 buf2[0] = 0xfe;
477 buf2[1] = 0x80;
478 memcpy(buf2 + 8, buf, 8);
479
480 ret.Set(buf2);
481 return ret;
482}
483
486{
487 NS_LOG_FUNCTION(addr);
488 Ipv6Address ret;
489 uint8_t buf[2];
490 uint8_t buf2[16];
491
492 buf[0] = 0;
493 addr.CopyTo(&buf[1]);
494
495 memset(buf2, 0x00, sizeof(buf2));
496 buf2[0] = 0xfe;
497 buf2[1] = 0x80;
498 memcpy(buf2 + 14, buf, 2);
499 buf2[11] = 0xff;
500 buf2[12] = 0xfe;
501
502 ret.Set(buf2);
503 return ret;
504}
505
508{
509 NS_LOG_FUNCTION(addr);
510 uint8_t buf[16];
511 uint8_t buf2[16];
512 Ipv6Address ret;
513
514 addr.Serialize(buf2);
515
516 memset(buf, 0x00, sizeof(buf));
517 buf[0] = 0xff;
518 buf[1] = 0x02;
519 buf[11] = 0x01;
520 buf[12] = 0xff;
521 buf[13] = buf2[13];
522 buf[14] = buf2[14];
523 buf[15] = buf2[15];
524
525 ret.Set(buf);
526 return ret;
527}
528
529void
530Ipv6Address::Print(std::ostream& os) const
531{
532 NS_LOG_FUNCTION(this << &os);
533
534 char str[INET6_ADDRSTRLEN];
535
536 if (inet_ntop(AF_INET6, m_address, str, INET6_ADDRSTRLEN))
537 {
538 os << str;
539 }
540}
541
542bool
544{
545 NS_LOG_FUNCTION(this);
546 static Ipv6Address localhost("::1");
547 return (*this == localhost);
548}
549
550bool
552{
553 NS_LOG_FUNCTION(this);
554 return m_address[0] == 0xff;
555}
556
557bool
559{
560 NS_LOG_FUNCTION(this);
561 return m_address[0] == 0xff && m_address[1] == 0x02;
562}
563
564bool
566{
567 NS_LOG_FUNCTION(this);
568 static uint8_t v4MappedPrefix[12] =
569 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff};
570 return memcmp(m_address, v4MappedPrefix, sizeof(v4MappedPrefix)) == 0;
571}
572
575{
576 NS_LOG_FUNCTION(this << prefix);
577 Ipv6Address ipv6;
578 uint8_t addr[16];
579 uint8_t pref[16];
580 unsigned int i = 0;
581
582 memcpy(addr, m_address, 16);
583 ((Ipv6Prefix)prefix).GetBytes(pref);
584
585 /* a little bit ugly... */
586 for (i = 0; i < 16; i++)
587 {
588 addr[i] = addr[i] & pref[i];
589 }
590 ipv6.Set(addr);
591 return ipv6;
592}
593
594bool
596{
597 NS_LOG_FUNCTION(this);
598
599 static Ipv6Address documentation("ff02::1:ff00:0");
600 return CombinePrefix(Ipv6Prefix(104)) == documentation;
601}
602
603bool
605{
606 NS_LOG_FUNCTION(this);
607 static Ipv6Address allNodesI("ff01::1");
608 static Ipv6Address allNodesL("ff02::1");
609 static Ipv6Address allNodesR("ff03::1");
610 return (*this == allNodesI || *this == allNodesL || *this == allNodesR);
611}
612
613bool
615{
616 NS_LOG_FUNCTION(this);
617 static Ipv6Address allroutersI("ff01::2");
618 static Ipv6Address allroutersL("ff02::2");
619 static Ipv6Address allroutersR("ff03::2");
620 static Ipv6Address allroutersS("ff05::2");
621 return (*this == allroutersI || *this == allroutersL || *this == allroutersR ||
622 *this == allroutersS);
623}
624
625bool
627{
628 NS_LOG_FUNCTION(this);
629 static Ipv6Address any("::");
630 return (*this == any);
631}
632
633bool
635{
636 NS_LOG_FUNCTION(this);
637 static Ipv6Address documentation("2001:db8::0");
638 return CombinePrefix(Ipv6Prefix(32)) == documentation;
639}
640
641bool
643{
644 NS_LOG_FUNCTION(this << prefix);
645
646 Ipv6Address masked = CombinePrefix(prefix);
647 Ipv6Address reference = Ipv6Address::GetOnes().CombinePrefix(prefix);
648
649 return masked == reference;
650}
651
652bool
654{
655 NS_LOG_FUNCTION(address);
656 return address.CheckCompatible(GetType(), 16);
657}
658
659Ipv6Address::
660operator Address() const
661{
662 return ConvertTo();
663}
664
667{
668 NS_LOG_FUNCTION(this);
669 uint8_t buf[16];
670 Serialize(buf);
671 return Address(GetType(), buf, 16);
672}
673
676{
677 NS_LOG_FUNCTION(address);
678 NS_ASSERT(address.CheckCompatible(GetType(), 16));
679 uint8_t buf[16];
680 address.CopyTo(buf);
681 return Deserialize(buf);
682}
683
684uint8_t
686{
688 static uint8_t type = Address::Register("IpAddress", 16);
689 return type;
690}
691
694{
696 static Ipv6Address nmc("ff02::1");
697 return nmc;
698}
699
702{
704 static Ipv6Address rmc("ff02::2");
705 return rmc;
706}
707
710{
712 static Ipv6Address hmc("ff02::3");
713 return hmc;
714}
715
718{
720 static Ipv6Address loopback("::1");
721 return loopback;
722}
723
726{
728 static Ipv6Address zero("::");
729 return zero;
730}
731
734{
736 static Ipv6Address any("::");
737 return any;
738}
739
742{
744 static Ipv6Address ones("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff");
745 return ones;
746}
747
748void
749Ipv6Address::GetBytes(uint8_t buf[16]) const
750{
751 NS_LOG_FUNCTION(this << &buf);
752 memcpy(buf, m_address, 16);
753}
754
755bool
757{
758 NS_LOG_FUNCTION(this);
759 static Ipv6Address linkLocal("fe80::0");
760 return CombinePrefix(Ipv6Prefix(64)) == linkLocal;
761}
762
763bool
765{
766 NS_LOG_FUNCTION(this);
767 return true;
768}
769
770std::ostream&
771operator<<(std::ostream& os, const Ipv6Address& address)
772{
773 address.Print(os);
774 return os;
775}
776
777std::istream&
778operator>>(std::istream& is, Ipv6Address& address)
779{
780 std::string str;
781 is >> str;
782 address = Ipv6Address(str.c_str());
783 return is;
784}
785
787{
788 NS_LOG_FUNCTION(this);
789 memset(m_prefix, 0x00, 16);
790 m_prefixLength = 0;
791}
792
793Ipv6Prefix::Ipv6Prefix(const char* prefix)
794{
795 NS_LOG_FUNCTION(this << prefix);
796 if (inet_pton(AF_INET6, prefix, m_prefix) <= 0)
797 {
798 NS_ABORT_MSG("Error, can not build an IPv6 prefix from an invalid string: " << prefix);
799 }
801}
802
803Ipv6Prefix::Ipv6Prefix(uint8_t prefix[16])
804{
805 NS_LOG_FUNCTION(this << &prefix);
806 memcpy(m_prefix, prefix, 16);
808}
809
810Ipv6Prefix::Ipv6Prefix(const char* prefix, uint8_t prefixLength)
811{
812 NS_LOG_FUNCTION(this << prefix);
813 if (inet_pton(AF_INET6, prefix, m_prefix) <= 0)
814 {
815 NS_ABORT_MSG("Error, can not build an IPv6 prefix from an invalid string: " << prefix);
816 }
817 uint8_t autoLength = GetMinimumPrefixLength();
818 NS_ASSERT_MSG(autoLength <= prefixLength,
819 "Ipv6Prefix: address and prefix are not compatible: " << Ipv6Address(prefix)
820 << "/" << +prefixLength);
821
822 m_prefixLength = prefixLength;
823}
824
825Ipv6Prefix::Ipv6Prefix(uint8_t prefix[16], uint8_t prefixLength)
826{
827 NS_LOG_FUNCTION(this << &prefix);
828 memcpy(m_prefix, prefix, 16);
829
830 uint8_t autoLength = GetMinimumPrefixLength();
831 NS_ASSERT_MSG(autoLength <= prefixLength,
832 "Ipv6Prefix: address and prefix are not compatible: " << Ipv6Address(prefix)
833 << "/" << +prefixLength);
834
835 m_prefixLength = prefixLength;
836}
837
839{
840 NS_LOG_FUNCTION(this << static_cast<uint32_t>(prefix));
841 unsigned int nb = 0;
842 unsigned int mod = 0;
843 unsigned int i = 0;
844
845 memset(m_prefix, 0x00, 16);
846 m_prefixLength = prefix;
847
848 NS_ASSERT(prefix <= 128);
849
850 nb = prefix / 8;
851 mod = prefix % 8;
852
853 // protect memset with 'nb > 0' check to suppress
854 // __warn_memset_zero_len compiler errors in some gcc>4.5.x
855 if (nb > 0)
856 {
857 memset(m_prefix, 0xff, nb);
858 }
859 if (mod)
860 {
861 m_prefix[nb] = 0xff << (8 - mod);
862 }
863
864 if (nb < 16)
865 {
866 nb++;
867 for (i = nb; i < 16; i++)
868 {
869 m_prefix[i] = 0x00;
870 }
871 }
872}
873
875{
876 memcpy(m_prefix, prefix.m_prefix, 16);
878}
879
881{
882 memcpy(m_prefix, prefix->m_prefix, 16);
884}
885
887{
888 /* do nothing */
889 NS_LOG_FUNCTION(this);
890}
891
892bool
894{
895 NS_LOG_FUNCTION(this << a << b);
896 uint8_t addrA[16];
897 uint8_t addrB[16];
898 unsigned int i = 0;
899
900 a.GetBytes(addrA);
901 b.GetBytes(addrB);
902
903 /* a little bit ugly... */
904 for (i = 0; i < 16; i++)
905 {
906 if ((addrA[i] & m_prefix[i]) != (addrB[i] & m_prefix[i]))
907 {
908 return false;
909 }
910 }
911 return true;
912}
913
914void
915Ipv6Prefix::Print(std::ostream& os) const
916{
917 NS_LOG_FUNCTION(this << &os);
918
919 os << "/" << (unsigned int)GetPrefixLength();
920}
921
924{
926 static Ipv6Prefix prefix((uint8_t)128);
927 return prefix;
928}
929
932{
934 static Ipv6Prefix ones((uint8_t)128);
935 return ones;
936}
937
940{
942 static Ipv6Prefix prefix((uint8_t)0);
943 return prefix;
944}
945
946void
947Ipv6Prefix::GetBytes(uint8_t buf[16]) const
948{
949 NS_LOG_FUNCTION(this << &buf);
950 memcpy(buf, m_prefix, 16);
951}
952
955{
956 uint8_t prefixBytes[16];
957 memcpy(prefixBytes, m_prefix, 16);
958
959 Ipv6Address convertedPrefix = Ipv6Address(prefixBytes);
960 return convertedPrefix;
961}
962
963uint8_t
965{
966 NS_LOG_FUNCTION(this);
967 return m_prefixLength;
968}
969
970void
971Ipv6Prefix::SetPrefixLength(uint8_t prefixLength)
972{
973 NS_LOG_FUNCTION(this);
974 m_prefixLength = prefixLength;
975}
976
977uint8_t
979{
980 NS_LOG_FUNCTION(this);
981
982 uint8_t prefixLength = 0;
983 bool stop = false;
984
985 for (int8_t i = 15; i >= 0 && !stop; i--)
986 {
987 uint8_t mask = m_prefix[i];
988
989 for (uint8_t j = 0; j < 8 && !stop; j++)
990 {
991 if ((mask & 1) == 0)
992 {
993 mask = mask >> 1;
994 prefixLength++;
995 }
996 else
997 {
998 stop = true;
999 }
1000 }
1001 }
1002
1003 return 128 - prefixLength;
1004}
1005
1006std::ostream&
1007operator<<(std::ostream& os, const Ipv6Prefix& prefix)
1008{
1009 prefix.Print(os);
1010 return os;
1011}
1012
1013std::istream&
1014operator>>(std::istream& is, Ipv6Prefix& prefix)
1015{
1016 std::string str;
1017 is >> str;
1018 prefix = Ipv6Prefix(str.c_str());
1019 return is;
1020}
1021
1022size_t
1024{
1025 uint8_t buf[16];
1026
1027 x.GetBytes(buf);
1028
1029 return lookuphash(buf, sizeof(buf), 0);
1030}
1031
1034
1035} /* namespace ns3 */
cairo_uint64_t x
_cairo_uint_96by64_32x64_divrem:
a polymophic address class
Definition address.h:111
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:156
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:191
#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:250
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.