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 m_initialized = false;
152}
153
155{
156 // Do not add function logging here, to avoid stack overflow
157 memcpy(m_address, addr.m_address, 16);
158 m_initialized = true;
159}
160
162{
163 // Do not add function logging here, to avoid stack overflow
164 memcpy(m_address, addr->m_address, 16);
165 m_initialized = true;
166}
167
168Ipv6Address::Ipv6Address(const char* address)
169{
170 NS_LOG_FUNCTION(this << address);
171
172 if (inet_pton(AF_INET6, address, m_address) <= 0)
173 {
174 memset(m_address, 0x00, 16);
175 NS_LOG_LOGIC("Error, can not build an IPv6 address from an invalid string: " << address);
176 m_initialized = false;
177 return;
178 }
179 m_initialized = 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 m_initialized = true;
188}
189
191{
192 /* do nothing */
193 NS_LOG_FUNCTION(this);
194}
195
196void
197Ipv6Address::Set(const char* address)
198{
199 NS_LOG_FUNCTION(this << address);
200 if (inet_pton(AF_INET6, address, m_address) <= 0)
201 {
202 memset(m_address, 0x00, 16);
203 NS_LOG_LOGIC("Error, can not build an IPv6 address from an invalid string: " << address);
204 m_initialized = false;
205 return;
206 }
207 m_initialized = true;
208}
209
210void
211Ipv6Address::Set(uint8_t address[16])
212{
213 /* 128 bit => 16 bytes */
214 NS_LOG_FUNCTION(this << &address);
215 memcpy(m_address, address, 16);
216 m_initialized = true;
217}
218
219void
220Ipv6Address::Serialize(uint8_t buf[16]) const
221{
222 NS_LOG_FUNCTION(this << &buf);
223 memcpy(buf, m_address, 16);
224}
225
227Ipv6Address::Deserialize(const uint8_t buf[16])
228{
229 NS_LOG_FUNCTION(&buf);
230 Ipv6Address ipv6((uint8_t*)buf);
231 ipv6.m_initialized = true;
232 return ipv6;
233}
234
237{
238 NS_LOG_FUNCTION(addr);
239 uint8_t buf[16] = {
240 0x00,
241 0x00,
242 0x00,
243 0x00,
244 0x00,
245 0x00,
246 0x00,
247 0x00,
248 0x00,
249 0x00,
250 0xff,
251 0xff,
252 0x00,
253 0x00,
254 0x00,
255 0x00,
256 };
257 addr.Serialize(&buf[12]);
258 return Ipv6Address(buf);
259}
260
263{
264 NS_LOG_FUNCTION(this);
265 uint8_t buf[16];
266 Ipv4Address v4Addr;
267
268 Serialize(buf);
269 v4Addr = Ipv4Address::Deserialize(&buf[12]);
270 return v4Addr;
271}
272
275{
276 Ipv6Address ipv6Addr = Ipv6Address::GetAny();
277
279 {
281 }
282 else if (Mac48Address::IsMatchingType(addr))
283 {
285 }
286 else if (Mac16Address::IsMatchingType(addr))
287 {
289 }
290 else if (Mac8Address::IsMatchingType(addr))
291 {
293 }
294
295 if (ipv6Addr.IsAny())
296 {
297 NS_ABORT_MSG("Unknown address type");
298 }
299 return ipv6Addr;
300}
301
304{
305 Ipv6Address ipv6PrefixAddr = Ipv6Address::GetOnes().CombinePrefix(prefix);
306 return MakeAutoconfiguredAddress(addr, ipv6PrefixAddr);
307}
308
311{
312 NS_LOG_FUNCTION(addr << prefix);
313 Ipv6Address ret;
314 uint8_t buf[2];
315 uint8_t buf2[16];
316
317 addr.CopyTo(buf);
318 prefix.GetBytes(buf2);
319 memset(buf2 + 8, 0, 8);
320
321 memcpy(buf2 + 14, buf, 2);
322 buf2[11] = 0xff;
323 buf2[12] = 0xfe;
324
325 ret.Set(buf2);
326 return ret;
327}
328
331{
332 NS_LOG_FUNCTION(addr << prefix);
333 Ipv6Address ret;
334 uint8_t buf[16];
335 uint8_t buf2[16];
336
337 addr.CopyTo(buf);
338 prefix.GetBytes(buf2);
339
340 memcpy(buf2 + 8, buf, 3);
341 buf2[11] = 0xff;
342 buf2[12] = 0xfe;
343 memcpy(buf2 + 13, buf + 3, 3);
344 buf2[8] ^= 0x02;
345
346 ret.Set(buf2);
347 return ret;
348}
349
352{
353 NS_LOG_FUNCTION(addr << prefix);
354 Ipv6Address ret;
355 uint8_t buf[8];
356 uint8_t buf2[16];
357
358 addr.CopyTo(buf);
359 prefix.GetBytes(buf2);
360
361 memcpy(buf2 + 8, buf, 8);
362
363 ret.Set(buf2);
364 return ret;
365}
366
369{
370 NS_LOG_FUNCTION(addr << prefix);
371 Ipv6Address ret;
372 uint8_t buf[2];
373 uint8_t buf2[16];
374
375 buf[0] = 0;
376 addr.CopyTo(&buf[1]);
377 prefix.GetBytes(buf2);
378 memset(buf2 + 8, 0, 8);
379
380 memcpy(buf2 + 14, buf, 2);
381 buf2[11] = 0xff;
382 buf2[12] = 0xfe;
383
384 ret.Set(buf2);
385 return ret;
386}
387
390{
391 Ipv6Address ipv6Addr = Ipv6Address::GetAny();
392
394 {
396 }
397 else if (Mac48Address::IsMatchingType(addr))
398 {
400 }
401 else if (Mac16Address::IsMatchingType(addr))
402 {
404 }
405 else if (Mac8Address::IsMatchingType(addr))
406 {
408 }
409
410 if (ipv6Addr.IsAny())
411 {
412 NS_ABORT_MSG("Unknown address type");
413 }
414 return ipv6Addr;
415}
416
419{
420 NS_LOG_FUNCTION(addr);
421 Ipv6Address ret;
422 uint8_t buf[2];
423 uint8_t buf2[16];
424
425 addr.CopyTo(buf);
426
427 memset(buf2, 0x00, sizeof(buf2));
428 buf2[0] = 0xfe;
429 buf2[1] = 0x80;
430 memcpy(buf2 + 14, buf, 2);
431 buf2[11] = 0xff;
432 buf2[12] = 0xfe;
433
434 ret.Set(buf2);
435 return ret;
436}
437
440{
441 NS_LOG_FUNCTION(addr);
442 Ipv6Address ret;
443 uint8_t buf[16];
444 uint8_t buf2[16];
445
446 addr.CopyTo(buf);
447
448 memset(buf2, 0x00, sizeof(buf2));
449 buf2[0] = 0xfe;
450 buf2[1] = 0x80;
451 memcpy(buf2 + 8, buf, 3);
452 buf2[11] = 0xff;
453 buf2[12] = 0xfe;
454 memcpy(buf2 + 13, buf + 3, 3);
455 buf2[8] ^= 0x02;
456
457 ret.Set(buf2);
458 return ret;
459}
460
463{
464 NS_LOG_FUNCTION(addr);
465 Ipv6Address ret;
466 uint8_t buf[8];
467 uint8_t buf2[16];
468
469 addr.CopyTo(buf);
470
471 memset(buf2, 0x00, sizeof(buf2));
472 buf2[0] = 0xfe;
473 buf2[1] = 0x80;
474 memcpy(buf2 + 8, buf, 8);
475
476 ret.Set(buf2);
477 return ret;
478}
479
482{
483 NS_LOG_FUNCTION(addr);
484 Ipv6Address ret;
485 uint8_t buf[2];
486 uint8_t buf2[16];
487
488 buf[0] = 0;
489 addr.CopyTo(&buf[1]);
490
491 memset(buf2, 0x00, sizeof(buf2));
492 buf2[0] = 0xfe;
493 buf2[1] = 0x80;
494 memcpy(buf2 + 14, buf, 2);
495 buf2[11] = 0xff;
496 buf2[12] = 0xfe;
497
498 ret.Set(buf2);
499 return ret;
500}
501
504{
505 NS_LOG_FUNCTION(addr);
506 uint8_t buf[16];
507 uint8_t buf2[16];
508 Ipv6Address ret;
509
510 addr.Serialize(buf2);
511
512 memset(buf, 0x00, sizeof(buf));
513 buf[0] = 0xff;
514 buf[1] = 0x02;
515 buf[11] = 0x01;
516 buf[12] = 0xff;
517 buf[13] = buf2[13];
518 buf[14] = buf2[14];
519 buf[15] = buf2[15];
520
521 ret.Set(buf);
522 return ret;
523}
524
525void
526Ipv6Address::Print(std::ostream& os) const
527{
528 NS_LOG_FUNCTION(this << &os);
529
530 char str[INET6_ADDRSTRLEN];
531
532 if (inet_ntop(AF_INET6, m_address, str, INET6_ADDRSTRLEN))
533 {
534 os << str;
535 }
536}
537
538bool
540{
541 NS_LOG_FUNCTION(this);
542 static Ipv6Address localhost("::1");
543 return (*this == localhost);
544}
545
546bool
548{
549 NS_LOG_FUNCTION(this);
550 return m_address[0] == 0xff;
551}
552
553bool
555{
556 NS_LOG_FUNCTION(this);
557 return m_address[0] == 0xff && m_address[1] == 0x02;
558}
559
560bool
562{
563 NS_LOG_FUNCTION(this);
564 static uint8_t v4MappedPrefix[12] =
565 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff};
566 return memcmp(m_address, v4MappedPrefix, sizeof(v4MappedPrefix)) == 0;
567}
568
571{
572 NS_LOG_FUNCTION(this << prefix);
573 Ipv6Address ipv6;
574 uint8_t addr[16];
575 uint8_t pref[16];
576 unsigned int i = 0;
577
578 memcpy(addr, m_address, 16);
579 ((Ipv6Prefix)prefix).GetBytes(pref);
580
581 /* a little bit ugly... */
582 for (i = 0; i < 16; i++)
583 {
584 addr[i] = addr[i] & pref[i];
585 }
586 ipv6.Set(addr);
587 return ipv6;
588}
589
590bool
592{
593 NS_LOG_FUNCTION(this);
594
595 static Ipv6Address documentation("ff02::1:ff00:0");
596 return CombinePrefix(Ipv6Prefix(104)) == documentation;
597}
598
599bool
601{
602 NS_LOG_FUNCTION(this);
603 static Ipv6Address allNodesI("ff01::1");
604 static Ipv6Address allNodesL("ff02::1");
605 static Ipv6Address allNodesR("ff03::1");
606 return (*this == allNodesI || *this == allNodesL || *this == allNodesR);
607}
608
609bool
611{
612 NS_LOG_FUNCTION(this);
613 static Ipv6Address allroutersI("ff01::2");
614 static Ipv6Address allroutersL("ff02::2");
615 static Ipv6Address allroutersR("ff03::2");
616 static Ipv6Address allroutersS("ff05::2");
617 return (*this == allroutersI || *this == allroutersL || *this == allroutersR ||
618 *this == allroutersS);
619}
620
621bool
623{
624 NS_LOG_FUNCTION(this);
625 static Ipv6Address any("::");
626 return (*this == any);
627}
628
629bool
631{
632 NS_LOG_FUNCTION(this);
633 static Ipv6Address documentation("2001:db8::0");
634 return CombinePrefix(Ipv6Prefix(32)) == documentation;
635}
636
637bool
639{
640 NS_LOG_FUNCTION(this << prefix);
641
642 Ipv6Address masked = CombinePrefix(prefix);
643 Ipv6Address reference = Ipv6Address::GetOnes().CombinePrefix(prefix);
644
645 return masked == reference;
646}
647
648bool
650{
651 NS_LOG_FUNCTION(address);
652 return address.CheckCompatible(GetType(), 16);
653}
654
655Ipv6Address::
656operator Address() const
657{
658 return ConvertTo();
659}
660
663{
664 NS_LOG_FUNCTION(this);
665 uint8_t buf[16];
666 Serialize(buf);
667 return Address(GetType(), buf, 16);
668}
669
672{
673 NS_LOG_FUNCTION(address);
674 NS_ASSERT(address.CheckCompatible(GetType(), 16));
675 uint8_t buf[16];
676 address.CopyTo(buf);
677 return Deserialize(buf);
678}
679
680uint8_t
682{
684 static uint8_t type = Address::Register();
685 return type;
686}
687
690{
692 static Ipv6Address nmc("ff02::1");
693 return nmc;
694}
695
698{
700 static Ipv6Address rmc("ff02::2");
701 return rmc;
702}
703
706{
708 static Ipv6Address hmc("ff02::3");
709 return hmc;
710}
711
714{
716 static Ipv6Address loopback("::1");
717 return loopback;
718}
719
722{
724 static Ipv6Address zero("::");
725 return zero;
726}
727
730{
732 static Ipv6Address any("::");
733 return any;
734}
735
738{
740 static Ipv6Address ones("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff");
741 return ones;
742}
743
744void
745Ipv6Address::GetBytes(uint8_t buf[16]) const
746{
747 NS_LOG_FUNCTION(this << &buf);
748 memcpy(buf, m_address, 16);
749}
750
751bool
753{
754 NS_LOG_FUNCTION(this);
755 static Ipv6Address linkLocal("fe80::0");
756 return CombinePrefix(Ipv6Prefix(64)) == linkLocal;
757}
758
759bool
761{
762 NS_LOG_FUNCTION(this);
763 return m_initialized;
764}
765
766std::ostream&
767operator<<(std::ostream& os, const Ipv6Address& address)
768{
769 address.Print(os);
770 return os;
771}
772
773std::istream&
774operator>>(std::istream& is, Ipv6Address& address)
775{
776 std::string str;
777 is >> str;
778 address = Ipv6Address(str.c_str());
779 return is;
780}
781
783{
784 NS_LOG_FUNCTION(this);
785 memset(m_prefix, 0x00, 16);
786 m_prefixLength = 64;
787}
788
789Ipv6Prefix::Ipv6Prefix(const char* prefix)
790{
791 NS_LOG_FUNCTION(this << prefix);
792 if (inet_pton(AF_INET6, prefix, m_prefix) <= 0)
793 {
794 NS_ABORT_MSG("Error, can not build an IPv6 prefix from an invalid string: " << prefix);
795 }
797}
798
799Ipv6Prefix::Ipv6Prefix(uint8_t prefix[16])
800{
801 NS_LOG_FUNCTION(this << &prefix);
802 memcpy(m_prefix, prefix, 16);
804}
805
806Ipv6Prefix::Ipv6Prefix(const char* prefix, uint8_t prefixLength)
807{
808 NS_LOG_FUNCTION(this << prefix);
809 if (inet_pton(AF_INET6, prefix, m_prefix) <= 0)
810 {
811 NS_ABORT_MSG("Error, can not build an IPv6 prefix from an invalid string: " << prefix);
812 }
813 uint8_t autoLength = GetMinimumPrefixLength();
814 NS_ASSERT_MSG(autoLength <= prefixLength,
815 "Ipv6Prefix: address and prefix are not compatible: " << Ipv6Address(prefix)
816 << "/" << +prefixLength);
817
818 m_prefixLength = prefixLength;
819}
820
821Ipv6Prefix::Ipv6Prefix(uint8_t prefix[16], uint8_t prefixLength)
822{
823 NS_LOG_FUNCTION(this << &prefix);
824 memcpy(m_prefix, prefix, 16);
825
826 uint8_t autoLength = GetMinimumPrefixLength();
827 NS_ASSERT_MSG(autoLength <= prefixLength,
828 "Ipv6Prefix: address and prefix are not compatible: " << Ipv6Address(prefix)
829 << "/" << +prefixLength);
830
831 m_prefixLength = prefixLength;
832}
833
835{
836 NS_LOG_FUNCTION(this << static_cast<uint32_t>(prefix));
837 unsigned int nb = 0;
838 unsigned int mod = 0;
839 unsigned int i = 0;
840
841 memset(m_prefix, 0x00, 16);
842 m_prefixLength = prefix;
843
844 NS_ASSERT(prefix <= 128);
845
846 nb = prefix / 8;
847 mod = prefix % 8;
848
849 // protect memset with 'nb > 0' check to suppress
850 // __warn_memset_zero_len compiler errors in some gcc>4.5.x
851 if (nb > 0)
852 {
853 memset(m_prefix, 0xff, nb);
854 }
855 if (mod)
856 {
857 m_prefix[nb] = 0xff << (8 - mod);
858 }
859
860 if (nb < 16)
861 {
862 nb++;
863 for (i = nb; i < 16; i++)
864 {
865 m_prefix[i] = 0x00;
866 }
867 }
868}
869
871{
872 memcpy(m_prefix, prefix.m_prefix, 16);
874}
875
877{
878 memcpy(m_prefix, prefix->m_prefix, 16);
880}
881
883{
884 /* do nothing */
885 NS_LOG_FUNCTION(this);
886}
887
888bool
890{
891 NS_LOG_FUNCTION(this << a << b);
892 uint8_t addrA[16];
893 uint8_t addrB[16];
894 unsigned int i = 0;
895
896 a.GetBytes(addrA);
897 b.GetBytes(addrB);
898
899 /* a little bit ugly... */
900 for (i = 0; i < 16; i++)
901 {
902 if ((addrA[i] & m_prefix[i]) != (addrB[i] & m_prefix[i]))
903 {
904 return false;
905 }
906 }
907 return true;
908}
909
910void
911Ipv6Prefix::Print(std::ostream& os) const
912{
913 NS_LOG_FUNCTION(this << &os);
914
915 os << "/" << (unsigned int)GetPrefixLength();
916}
917
920{
922 static Ipv6Prefix prefix((uint8_t)128);
923 return prefix;
924}
925
928{
930 static Ipv6Prefix ones((uint8_t)128);
931 return ones;
932}
933
936{
938 static Ipv6Prefix prefix((uint8_t)0);
939 return prefix;
940}
941
942void
943Ipv6Prefix::GetBytes(uint8_t buf[16]) const
944{
945 NS_LOG_FUNCTION(this << &buf);
946 memcpy(buf, m_prefix, 16);
947}
948
951{
952 uint8_t prefixBytes[16];
953 memcpy(prefixBytes, m_prefix, 16);
954
955 Ipv6Address convertedPrefix = Ipv6Address(prefixBytes);
956 return convertedPrefix;
957}
958
959uint8_t
961{
962 NS_LOG_FUNCTION(this);
963 return m_prefixLength;
964}
965
966void
967Ipv6Prefix::SetPrefixLength(uint8_t prefixLength)
968{
969 NS_LOG_FUNCTION(this);
970 m_prefixLength = prefixLength;
971}
972
973uint8_t
975{
976 NS_LOG_FUNCTION(this);
977
978 uint8_t prefixLength = 0;
979 bool stop = false;
980
981 for (int8_t i = 15; i >= 0 && !stop; i--)
982 {
983 uint8_t mask = m_prefix[i];
984
985 for (uint8_t j = 0; j < 8 && !stop; j++)
986 {
987 if ((mask & 1) == 0)
988 {
989 mask = mask >> 1;
990 prefixLength++;
991 }
992 else
993 {
994 stop = true;
995 }
996 }
997 }
998
999 return 128 - prefixLength;
1000}
1001
1002std::ostream&
1003operator<<(std::ostream& os, const Ipv6Prefix& prefix)
1004{
1005 prefix.Print(os);
1006 return os;
1007}
1008
1009std::istream&
1010operator>>(std::istream& is, Ipv6Prefix& prefix)
1011{
1012 std::string str;
1013 is >> str;
1014 prefix = Ipv6Prefix(str.c_str());
1015 return is;
1016}
1017
1018size_t
1020{
1021 uint8_t buf[16];
1022
1023 x.GetBytes(buf);
1024
1025 return lookuphash(buf, sizeof(buf), 0);
1026}
1027
1030
1031} /* namespace ns3 */
a polymophic address class
Definition address.h:90
static uint8_t Register()
Allocate a new type id for a new type of address.
Definition address.cc:135
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).
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).
bool m_initialized
IPv6 address has been explicitly initialized to a valid value.
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
If the Address match the type.
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_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:271
#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.
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.