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::operator Address() const
656{
657 return ConvertTo();
658}
659
662{
663 NS_LOG_FUNCTION(this);
664 uint8_t buf[16];
665 Serialize(buf);
666 return Address(GetType(), buf, 16);
667}
668
671{
672 NS_LOG_FUNCTION(address);
673 NS_ASSERT(address.CheckCompatible(GetType(), 16));
674 uint8_t buf[16];
675 address.CopyTo(buf);
676 return Deserialize(buf);
677}
678
679uint8_t
681{
683 static uint8_t type = Address::Register();
684 return type;
685}
686
689{
691 static Ipv6Address nmc("ff02::1");
692 return nmc;
693}
694
697{
699 static Ipv6Address rmc("ff02::2");
700 return rmc;
701}
702
705{
707 static Ipv6Address hmc("ff02::3");
708 return hmc;
709}
710
713{
715 static Ipv6Address loopback("::1");
716 return loopback;
717}
718
721{
723 static Ipv6Address zero("::");
724 return zero;
725}
726
729{
731 static Ipv6Address any("::");
732 return any;
733}
734
737{
739 static Ipv6Address ones("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff");
740 return ones;
741}
742
743void
744Ipv6Address::GetBytes(uint8_t buf[16]) const
745{
746 NS_LOG_FUNCTION(this << &buf);
747 memcpy(buf, m_address, 16);
748}
749
750bool
752{
753 NS_LOG_FUNCTION(this);
754 static Ipv6Address linkLocal("fe80::0");
755 return CombinePrefix(Ipv6Prefix(64)) == linkLocal;
756}
757
758bool
760{
761 NS_LOG_FUNCTION(this);
762 return m_initialized;
763}
764
765std::ostream&
766operator<<(std::ostream& os, const Ipv6Address& address)
767{
768 address.Print(os);
769 return os;
770}
771
772std::istream&
773operator>>(std::istream& is, Ipv6Address& address)
774{
775 std::string str;
776 is >> str;
777 address = Ipv6Address(str.c_str());
778 return is;
779}
780
782{
783 NS_LOG_FUNCTION(this);
784 memset(m_prefix, 0x00, 16);
785 m_prefixLength = 64;
786}
787
788Ipv6Prefix::Ipv6Prefix(const char* prefix)
789{
790 NS_LOG_FUNCTION(this << prefix);
791 if (inet_pton(AF_INET6, prefix, m_prefix) <= 0)
792 {
793 NS_ABORT_MSG("Error, can not build an IPv6 prefix from an invalid string: " << prefix);
794 }
796}
797
798Ipv6Prefix::Ipv6Prefix(uint8_t prefix[16])
799{
800 NS_LOG_FUNCTION(this << &prefix);
801 memcpy(m_prefix, prefix, 16);
803}
804
805Ipv6Prefix::Ipv6Prefix(const char* prefix, uint8_t prefixLength)
806{
807 NS_LOG_FUNCTION(this << prefix);
808 if (inet_pton(AF_INET6, prefix, m_prefix) <= 0)
809 {
810 NS_ABORT_MSG("Error, can not build an IPv6 prefix from an invalid string: " << prefix);
811 }
812 uint8_t autoLength = GetMinimumPrefixLength();
813 NS_ASSERT_MSG(autoLength <= prefixLength,
814 "Ipv6Prefix: address and prefix are not compatible: " << Ipv6Address(prefix)
815 << "/" << +prefixLength);
816
817 m_prefixLength = prefixLength;
818}
819
820Ipv6Prefix::Ipv6Prefix(uint8_t prefix[16], uint8_t prefixLength)
821{
822 NS_LOG_FUNCTION(this << &prefix);
823 memcpy(m_prefix, prefix, 16);
824
825 uint8_t autoLength = GetMinimumPrefixLength();
826 NS_ASSERT_MSG(autoLength <= prefixLength,
827 "Ipv6Prefix: address and prefix are not compatible: " << Ipv6Address(prefix)
828 << "/" << +prefixLength);
829
830 m_prefixLength = prefixLength;
831}
832
834{
835 NS_LOG_FUNCTION(this << static_cast<uint32_t>(prefix));
836 unsigned int nb = 0;
837 unsigned int mod = 0;
838 unsigned int i = 0;
839
840 memset(m_prefix, 0x00, 16);
841 m_prefixLength = prefix;
842
843 NS_ASSERT(prefix <= 128);
844
845 nb = prefix / 8;
846 mod = prefix % 8;
847
848 // protect memset with 'nb > 0' check to suppress
849 // __warn_memset_zero_len compiler errors in some gcc>4.5.x
850 if (nb > 0)
851 {
852 memset(m_prefix, 0xff, nb);
853 }
854 if (mod)
855 {
856 m_prefix[nb] = 0xff << (8 - mod);
857 }
858
859 if (nb < 16)
860 {
861 nb++;
862 for (i = nb; i < 16; i++)
863 {
864 m_prefix[i] = 0x00;
865 }
866 }
867}
868
870{
871 memcpy(m_prefix, prefix.m_prefix, 16);
873}
874
876{
877 memcpy(m_prefix, prefix->m_prefix, 16);
879}
880
882{
883 /* do nothing */
884 NS_LOG_FUNCTION(this);
885}
886
887bool
889{
890 NS_LOG_FUNCTION(this << a << b);
891 uint8_t addrA[16];
892 uint8_t addrB[16];
893 unsigned int i = 0;
894
895 a.GetBytes(addrA);
896 b.GetBytes(addrB);
897
898 /* a little bit ugly... */
899 for (i = 0; i < 16; i++)
900 {
901 if ((addrA[i] & m_prefix[i]) != (addrB[i] & m_prefix[i]))
902 {
903 return false;
904 }
905 }
906 return true;
907}
908
909void
910Ipv6Prefix::Print(std::ostream& os) const
911{
912 NS_LOG_FUNCTION(this << &os);
913
914 os << "/" << (unsigned int)GetPrefixLength();
915}
916
919{
921 static Ipv6Prefix prefix((uint8_t)128);
922 return prefix;
923}
924
927{
929 static Ipv6Prefix ones((uint8_t)128);
930 return ones;
931}
932
935{
937 static Ipv6Prefix prefix((uint8_t)0);
938 return prefix;
939}
940
941void
942Ipv6Prefix::GetBytes(uint8_t buf[16]) const
943{
944 NS_LOG_FUNCTION(this << &buf);
945 memcpy(buf, m_prefix, 16);
946}
947
950{
951 uint8_t prefixBytes[16];
952 memcpy(prefixBytes, m_prefix, 16);
953
954 Ipv6Address convertedPrefix = Ipv6Address(prefixBytes);
955 return convertedPrefix;
956}
957
958uint8_t
960{
961 NS_LOG_FUNCTION(this);
962 return m_prefixLength;
963}
964
965void
966Ipv6Prefix::SetPrefixLength(uint8_t prefixLength)
967{
968 NS_LOG_FUNCTION(this);
969 m_prefixLength = prefixLength;
970}
971
972uint8_t
974{
975 NS_LOG_FUNCTION(this);
976
977 uint8_t prefixLength = 0;
978 bool stop = false;
979
980 for (int8_t i = 15; i >= 0 && !stop; i--)
981 {
982 uint8_t mask = m_prefix[i];
983
984 for (uint8_t j = 0; j < 8 && !stop; j++)
985 {
986 if ((mask & 1) == 0)
987 {
988 mask = mask >> 1;
989 prefixLength++;
990 }
991 else
992 {
993 stop = true;
994 }
995 }
996 }
997
998 return 128 - prefixLength;
999}
1000
1001std::ostream&
1002operator<<(std::ostream& os, const Ipv6Prefix& prefix)
1003{
1004 prefix.Print(os);
1005 return os;
1006}
1007
1008std::istream&
1009operator>>(std::istream& is, Ipv6Prefix& prefix)
1010{
1011 std::string str;
1012 is >> str;
1013 prefix = Ipv6Prefix(str.c_str());
1014 return is;
1015}
1016
1017size_t
1019{
1020 uint8_t buf[16];
1021
1022 x.GetBytes(buf);
1023
1024 return lookuphash(buf, sizeof(buf), 0);
1025}
1026
1029
1030} /* 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.
static double zero
#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.