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 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
18 */
19
20#include "ipv6-address.h"
21
22#include "mac16-address.h"
23#include "mac48-address.h"
24#include "mac64-address.h"
25
26#include "ns3/assert.h"
27#include "ns3/log.h"
28
29#include <iomanip>
30#include <memory>
31
32#ifdef __WIN32__
33#include <WS2tcpip.h>
34#else
35#include <arpa/inet.h>
36#endif
37
38namespace ns3
39{
40
41NS_LOG_COMPONENT_DEFINE("Ipv6Address");
42
43#ifdef __cplusplus
44extern "C"
45{ /* } */
46#endif
47
56 static uint32_t lookuphash(unsigned char* k, uint32_t length, uint32_t level)
57 {
58 NS_LOG_FUNCTION(k << length << level);
59#define mix(a, b, c) \
60 ({ \
61 (a) -= (b); \
62 (a) -= (c); \
63 (a) ^= ((c) >> 13); \
64 (b) -= (c); \
65 (b) -= (a); \
66 (b) ^= ((a) << 8); \
67 (c) -= (a); \
68 (c) -= (b); \
69 (c) ^= ((b) >> 13); \
70 (a) -= (b); \
71 (a) -= (c); \
72 (a) ^= ((c) >> 12); \
73 (b) -= (c); \
74 (b) -= (a); \
75 (b) ^= ((a) << 16); \
76 (c) -= (a); \
77 (c) -= (b); \
78 (c) ^= ((b) >> 5); \
79 (a) -= (b); \
80 (a) -= (c); \
81 (a) ^= ((c) >> 3); \
82 (b) -= (c); \
83 (b) -= (a); \
84 (b) ^= ((a) << 10); \
85 (c) -= (a); \
86 (c) -= (b); \
87 (c) ^= ((b) >> 15); \
88 })
89
90 typedef uint32_t ub4; /* unsigned 4-byte quantities */
91 uint32_t a = 0;
92 uint32_t b = 0;
93 uint32_t c = 0;
94 uint32_t len = 0;
95
96 /* Set up the internal state */
97 len = length;
98 a = b = 0x9e3779b9; /* the golden ratio; an arbitrary value */
99 c = level; /* the previous hash value */
100
101 /* handle most of the key */
102 while (len >= 12)
103 {
104 a += (k[0] + ((ub4)k[1] << 8) + ((ub4)k[2] << 16) + ((ub4)k[3] << 24));
105 b += (k[4] + ((ub4)k[5] << 8) + ((ub4)k[6] << 16) + ((ub4)k[7] << 24));
106 c += (k[8] + ((ub4)k[9] << 8) + ((ub4)k[10] << 16) + ((ub4)k[11] << 24));
107 mix(a, b, c);
108 k += 12;
109 len -= 12;
110 }
111
112 /* handle the last 11 bytes */
113 c += length;
114 switch (len) /* all the case statements fall through */
115 {
116 case 11:
117 c += ((ub4)k[10] << 24);
118 case 10:
119 c += ((ub4)k[9] << 16);
120 case 9:
121 c += ((ub4)k[8] << 8); /* the first byte of c is reserved for the length */
122 case 8:
123 b += ((ub4)k[7] << 24);
124 case 7:
125 b += ((ub4)k[6] << 16);
126 case 6:
127 b += ((ub4)k[5] << 8);
128 case 5:
129 b += k[4];
130 case 4:
131 a += ((ub4)k[3] << 24);
132 case 3:
133 a += ((ub4)k[2] << 16);
134 case 2:
135 a += ((ub4)k[1] << 8);
136 case 1:
137 a += k[0];
138 /* case 0: nothing left to add */
139 }
140 mix(a, b, c);
141
142#undef mix
143
144 /* report the result */
145 return c;
146 }
147
148#ifdef __cplusplus
149}
150#endif
151
153{
154 NS_LOG_FUNCTION(this);
155 memset(m_address, 0x00, 16);
156 m_initialized = false;
157}
158
160{
161 // Do not add function logging here, to avoid stack overflow
162 memcpy(m_address, addr.m_address, 16);
163 m_initialized = true;
164}
165
167{
168 // Do not add function logging here, to avoid stack overflow
169 memcpy(m_address, addr->m_address, 16);
170 m_initialized = true;
171}
172
173Ipv6Address::Ipv6Address(const char* address)
174{
175 NS_LOG_FUNCTION(this << address);
176
177 if (inet_pton(AF_INET6, address, m_address) <= 0)
178 {
179 memset(m_address, 0x00, 16);
180 NS_LOG_LOGIC("Error, can not build an IPv6 address from an invalid string: " << address);
181 m_initialized = false;
182 return;
183 }
184 m_initialized = true;
185}
186
187Ipv6Address::Ipv6Address(uint8_t address[16])
188{
189 NS_LOG_FUNCTION(this << &address);
190 /* 128 bit => 16 bytes */
191 memcpy(m_address, address, 16);
192 m_initialized = true;
193}
194
196{
197 /* do nothing */
198 NS_LOG_FUNCTION(this);
199}
200
201void
202Ipv6Address::Set(const char* address)
203{
204 NS_LOG_FUNCTION(this << address);
205 if (inet_pton(AF_INET6, address, m_address) <= 0)
206 {
207 memset(m_address, 0x00, 16);
208 NS_LOG_LOGIC("Error, can not build an IPv6 address from an invalid string: " << address);
209 m_initialized = false;
210 return;
211 }
212 m_initialized = true;
213}
214
215void
216Ipv6Address::Set(uint8_t address[16])
217{
218 /* 128 bit => 16 bytes */
219 NS_LOG_FUNCTION(this << &address);
220 memcpy(m_address, address, 16);
221 m_initialized = true;
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 ipv6.m_initialized = true;
237 return ipv6;
238}
239
242{
243 NS_LOG_FUNCTION(addr);
244 uint8_t buf[16] = {
245 0x00,
246 0x00,
247 0x00,
248 0x00,
249 0x00,
250 0x00,
251 0x00,
252 0x00,
253 0x00,
254 0x00,
255 0xff,
256 0xff,
257 0x00,
258 0x00,
259 0x00,
260 0x00,
261 };
262 addr.Serialize(&buf[12]);
263 return (Ipv6Address(buf));
264}
265
268{
269 NS_LOG_FUNCTION(this);
270 uint8_t buf[16];
271 Ipv4Address v4Addr;
272
273 Serialize(buf);
274 v4Addr = Ipv4Address::Deserialize(&buf[12]);
275 return (v4Addr);
276}
277
280{
281 Ipv6Address ipv6Addr = Ipv6Address::GetAny();
282
284 {
286 }
287 else if (Mac48Address::IsMatchingType(addr))
288 {
290 }
291 else if (Mac16Address::IsMatchingType(addr))
292 {
294 }
295 else if (Mac8Address::IsMatchingType(addr))
296 {
298 }
299
300 if (ipv6Addr.IsAny())
301 {
302 NS_ABORT_MSG("Unknown address type");
303 }
304 return ipv6Addr;
305}
306
309{
310 Ipv6Address ipv6PrefixAddr = Ipv6Address::GetOnes().CombinePrefix(prefix);
311 return MakeAutoconfiguredAddress(addr, ipv6PrefixAddr);
312}
313
316{
317 NS_LOG_FUNCTION(addr << prefix);
318 Ipv6Address ret;
319 uint8_t buf[2];
320 uint8_t buf2[16];
321
322 addr.CopyTo(buf);
323 prefix.GetBytes(buf2);
324 memset(buf2 + 8, 0, 8);
325
326 memcpy(buf2 + 14, buf, 2);
327 buf2[11] = 0xff;
328 buf2[12] = 0xfe;
329
330 ret.Set(buf2);
331 return ret;
332}
333
336{
337 NS_LOG_FUNCTION(addr << prefix);
338 Ipv6Address ret;
339 uint8_t buf[16];
340 uint8_t buf2[16];
341
342 addr.CopyTo(buf);
343 prefix.GetBytes(buf2);
344
345 memcpy(buf2 + 8, buf, 3);
346 buf2[11] = 0xff;
347 buf2[12] = 0xfe;
348 memcpy(buf2 + 13, buf + 3, 3);
349 buf2[8] ^= 0x02;
350
351 ret.Set(buf2);
352 return ret;
353}
354
357{
358 NS_LOG_FUNCTION(addr << prefix);
359 Ipv6Address ret;
360 uint8_t buf[8];
361 uint8_t buf2[16];
362
363 addr.CopyTo(buf);
364 prefix.GetBytes(buf2);
365
366 memcpy(buf2 + 8, buf, 8);
367
368 ret.Set(buf2);
369 return ret;
370}
371
374{
375 NS_LOG_FUNCTION(addr << prefix);
376 Ipv6Address ret;
377 uint8_t buf[2];
378 uint8_t buf2[16];
379
380 buf[0] = 0;
381 addr.CopyTo(&buf[1]);
382 prefix.GetBytes(buf2);
383 memset(buf2 + 8, 0, 8);
384
385 memcpy(buf2 + 14, buf, 2);
386 buf2[11] = 0xff;
387 buf2[12] = 0xfe;
388
389 ret.Set(buf2);
390 return ret;
391}
392
395{
396 Ipv6Address ipv6Addr = Ipv6Address::GetAny();
397
399 {
401 }
402 else if (Mac48Address::IsMatchingType(addr))
403 {
405 }
406 else if (Mac16Address::IsMatchingType(addr))
407 {
409 }
410 else if (Mac8Address::IsMatchingType(addr))
411 {
413 }
414
415 if (ipv6Addr.IsAny())
416 {
417 NS_ABORT_MSG("Unknown address type");
418 }
419 return ipv6Addr;
420}
421
424{
425 NS_LOG_FUNCTION(addr);
426 Ipv6Address ret;
427 uint8_t buf[2];
428 uint8_t buf2[16];
429
430 addr.CopyTo(buf);
431
432 memset(buf2, 0x00, sizeof(buf2));
433 buf2[0] = 0xfe;
434 buf2[1] = 0x80;
435 memcpy(buf2 + 14, buf, 2);
436 buf2[11] = 0xff;
437 buf2[12] = 0xfe;
438
439 ret.Set(buf2);
440 return ret;
441}
442
445{
446 NS_LOG_FUNCTION(addr);
447 Ipv6Address ret;
448 uint8_t buf[16];
449 uint8_t buf2[16];
450
451 addr.CopyTo(buf);
452
453 memset(buf2, 0x00, sizeof(buf2));
454 buf2[0] = 0xfe;
455 buf2[1] = 0x80;
456 memcpy(buf2 + 8, buf, 3);
457 buf2[11] = 0xff;
458 buf2[12] = 0xfe;
459 memcpy(buf2 + 13, buf + 3, 3);
460 buf2[8] ^= 0x02;
461
462 ret.Set(buf2);
463 return ret;
464}
465
468{
469 NS_LOG_FUNCTION(addr);
470 Ipv6Address ret;
471 uint8_t buf[8];
472 uint8_t buf2[16];
473
474 addr.CopyTo(buf);
475
476 memset(buf2, 0x00, sizeof(buf2));
477 buf2[0] = 0xfe;
478 buf2[1] = 0x80;
479 memcpy(buf2 + 8, buf, 8);
480
481 ret.Set(buf2);
482 return ret;
483}
484
487{
488 NS_LOG_FUNCTION(addr);
489 Ipv6Address ret;
490 uint8_t buf[2];
491 uint8_t buf2[16];
492
493 buf[0] = 0;
494 addr.CopyTo(&buf[1]);
495
496 memset(buf2, 0x00, sizeof(buf2));
497 buf2[0] = 0xfe;
498 buf2[1] = 0x80;
499 memcpy(buf2 + 14, buf, 2);
500 buf2[11] = 0xff;
501 buf2[12] = 0xfe;
502
503 ret.Set(buf2);
504 return ret;
505}
506
509{
510 NS_LOG_FUNCTION(addr);
511 uint8_t buf[16];
512 uint8_t buf2[16];
513 Ipv6Address ret;
514
515 addr.Serialize(buf2);
516
517 memset(buf, 0x00, sizeof(buf));
518 buf[0] = 0xff;
519 buf[1] = 0x02;
520 buf[11] = 0x01;
521 buf[12] = 0xff;
522 buf[13] = buf2[13];
523 buf[14] = buf2[14];
524 buf[15] = buf2[15];
525
526 ret.Set(buf);
527 return ret;
528}
529
530void
531Ipv6Address::Print(std::ostream& os) const
532{
533 NS_LOG_FUNCTION(this << &os);
534
535 char str[INET6_ADDRSTRLEN];
536
537 if (inet_ntop(AF_INET6, m_address, str, INET6_ADDRSTRLEN))
538 {
539 os << str;
540 }
541}
542
543bool
545{
546 NS_LOG_FUNCTION(this);
547 static Ipv6Address localhost("::1");
548 return (*this == localhost);
549}
550
551bool
553{
554 NS_LOG_FUNCTION(this);
555 return m_address[0] == 0xff;
556}
557
558bool
560{
561 NS_LOG_FUNCTION(this);
562 return m_address[0] == 0xff && m_address[1] == 0x02;
563}
564
565bool
567{
568 NS_LOG_FUNCTION(this);
569 static uint8_t v4MappedPrefix[12] =
570 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff};
571 if (memcmp(m_address, v4MappedPrefix, sizeof(v4MappedPrefix)) == 0)
572 {
573 return (true);
574 }
575 return (false);
576}
577
580{
581 NS_LOG_FUNCTION(this << prefix);
582 Ipv6Address ipv6;
583 uint8_t addr[16];
584 uint8_t pref[16];
585 unsigned int i = 0;
586
587 memcpy(addr, m_address, 16);
588 ((Ipv6Prefix)prefix).GetBytes(pref);
589
590 /* a little bit ugly... */
591 for (i = 0; i < 16; i++)
592 {
593 addr[i] = addr[i] & pref[i];
594 }
595 ipv6.Set(addr);
596 return ipv6;
597}
598
599bool
601{
602 NS_LOG_FUNCTION(this);
603
604 static Ipv6Address documentation("ff02::1:ff00:0");
605 return CombinePrefix(Ipv6Prefix(104)) == documentation;
606}
607
608bool
610{
611 NS_LOG_FUNCTION(this);
612 static Ipv6Address allNodesI("ff01::1");
613 static Ipv6Address allNodesL("ff02::1");
614 static Ipv6Address allNodesR("ff03::1");
615 return (*this == allNodesI || *this == allNodesL || *this == allNodesR);
616}
617
618bool
620{
621 NS_LOG_FUNCTION(this);
622 static Ipv6Address allroutersI("ff01::2");
623 static Ipv6Address allroutersL("ff02::2");
624 static Ipv6Address allroutersR("ff03::2");
625 static Ipv6Address allroutersS("ff05::2");
626 return (*this == allroutersI || *this == allroutersL || *this == allroutersR ||
627 *this == allroutersS);
628}
629
630bool
632{
633 NS_LOG_FUNCTION(this);
634 static Ipv6Address any("::");
635 return (*this == any);
636}
637
638bool
640{
641 NS_LOG_FUNCTION(this);
642 static Ipv6Address documentation("2001:db8::0");
643 return CombinePrefix(Ipv6Prefix(32)) == documentation;
644}
645
646bool
648{
649 NS_LOG_FUNCTION(this << prefix);
650
651 Ipv6Address masked = CombinePrefix(prefix);
652 Ipv6Address reference = Ipv6Address::GetOnes().CombinePrefix(prefix);
653
654 return (masked == reference);
655}
656
657bool
659{
660 NS_LOG_FUNCTION(address);
661 return address.CheckCompatible(GetType(), 16);
662}
663
664Ipv6Address::operator Address() const
665{
666 return ConvertTo();
667}
668
671{
672 NS_LOG_FUNCTION(this);
673 uint8_t buf[16];
674 Serialize(buf);
675 return Address(GetType(), buf, 16);
676}
677
680{
681 NS_LOG_FUNCTION(address);
682 NS_ASSERT(address.CheckCompatible(GetType(), 16));
683 uint8_t buf[16];
684 address.CopyTo(buf);
685 return Deserialize(buf);
686}
687
688uint8_t
690{
692 static uint8_t type = Address::Register();
693 return type;
694}
695
698{
700 static Ipv6Address nmc("ff02::1");
701 return nmc;
702}
703
706{
708 static Ipv6Address rmc("ff02::2");
709 return rmc;
710}
711
714{
716 static Ipv6Address hmc("ff02::3");
717 return hmc;
718}
719
722{
724 static Ipv6Address loopback("::1");
725 return loopback;
726}
727
730{
732 static Ipv6Address zero("::");
733 return zero;
734}
735
738{
740 static Ipv6Address any("::");
741 return any;
742}
743
746{
748 static Ipv6Address ones("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff");
749 return ones;
750}
751
752void
753Ipv6Address::GetBytes(uint8_t buf[16]) const
754{
755 NS_LOG_FUNCTION(this << &buf);
756 memcpy(buf, m_address, 16);
757}
758
759bool
761{
762 NS_LOG_FUNCTION(this);
763 static Ipv6Address linkLocal("fe80::0");
764 return CombinePrefix(Ipv6Prefix(64)) == linkLocal;
765}
766
767bool
769{
770 NS_LOG_FUNCTION(this);
771 return (m_initialized);
772}
773
774std::ostream&
775operator<<(std::ostream& os, const Ipv6Address& address)
776{
777 address.Print(os);
778 return os;
779}
780
781std::istream&
782operator>>(std::istream& is, Ipv6Address& address)
783{
784 std::string str;
785 is >> str;
786 address = Ipv6Address(str.c_str());
787 return is;
788}
789
791{
792 NS_LOG_FUNCTION(this);
793 memset(m_prefix, 0x00, 16);
794 m_prefixLength = 64;
795}
796
797Ipv6Prefix::Ipv6Prefix(const char* prefix)
798{
799 NS_LOG_FUNCTION(this << prefix);
800 if (inet_pton(AF_INET6, prefix, m_prefix) <= 0)
801 {
802 NS_ABORT_MSG("Error, can not build an IPv6 prefix from an invalid string: " << prefix);
803 }
805}
806
807Ipv6Prefix::Ipv6Prefix(uint8_t prefix[16])
808{
809 NS_LOG_FUNCTION(this << &prefix);
810 memcpy(m_prefix, prefix, 16);
812}
813
814Ipv6Prefix::Ipv6Prefix(const char* prefix, uint8_t prefixLength)
815{
816 NS_LOG_FUNCTION(this << prefix);
817 if (inet_pton(AF_INET6, prefix, m_prefix) <= 0)
818 {
819 NS_ABORT_MSG("Error, can not build an IPv6 prefix from an invalid string: " << prefix);
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
829Ipv6Prefix::Ipv6Prefix(uint8_t prefix[16], uint8_t prefixLength)
830{
831 NS_LOG_FUNCTION(this << &prefix);
832 memcpy(m_prefix, prefix, 16);
833
834 uint8_t autoLength = GetMinimumPrefixLength();
835 NS_ASSERT_MSG(autoLength <= prefixLength,
836 "Ipv6Prefix: address and prefix are not compatible: " << Ipv6Address(prefix)
837 << "/" << +prefixLength);
838
839 m_prefixLength = prefixLength;
840}
841
843{
844 NS_LOG_FUNCTION(this << static_cast<uint32_t>(prefix));
845 unsigned int nb = 0;
846 unsigned int mod = 0;
847 unsigned int i = 0;
848
849 memset(m_prefix, 0x00, 16);
850 m_prefixLength = prefix;
851
852 NS_ASSERT(prefix <= 128);
853
854 nb = prefix / 8;
855 mod = prefix % 8;
856
857 // protect memset with 'nb > 0' check to suppress
858 // __warn_memset_zero_len compiler errors in some gcc>4.5.x
859 if (nb > 0)
860 {
861 memset(m_prefix, 0xff, nb);
862 }
863 if (mod)
864 {
865 m_prefix[nb] = 0xff << (8 - mod);
866 }
867
868 if (nb < 16)
869 {
870 nb++;
871 for (i = nb; i < 16; i++)
872 {
873 m_prefix[i] = 0x00;
874 }
875 }
876}
877
879{
880 memcpy(m_prefix, prefix.m_prefix, 16);
882}
883
885{
886 memcpy(m_prefix, prefix->m_prefix, 16);
888}
889
891{
892 /* do nothing */
893 NS_LOG_FUNCTION(this);
894}
895
896bool
898{
899 NS_LOG_FUNCTION(this << a << b);
900 uint8_t addrA[16];
901 uint8_t addrB[16];
902 unsigned int i = 0;
903
904 a.GetBytes(addrA);
905 b.GetBytes(addrB);
906
907 /* a little bit ugly... */
908 for (i = 0; i < 16; i++)
909 {
910 if ((addrA[i] & m_prefix[i]) != (addrB[i] & m_prefix[i]))
911 {
912 return false;
913 }
914 }
915 return true;
916}
917
918void
919Ipv6Prefix::Print(std::ostream& os) const
920{
921 NS_LOG_FUNCTION(this << &os);
922
923 os << "/" << (unsigned int)GetPrefixLength();
924}
925
928{
930 static Ipv6Prefix prefix((uint8_t)128);
931 return prefix;
932}
933
936{
938 static Ipv6Prefix ones((uint8_t)128);
939 return ones;
940}
941
944{
946 static Ipv6Prefix prefix((uint8_t)0);
947 return prefix;
948}
949
950void
951Ipv6Prefix::GetBytes(uint8_t buf[16]) const
952{
953 NS_LOG_FUNCTION(this << &buf);
954 memcpy(buf, m_prefix, 16);
955}
956
959{
960 uint8_t prefixBytes[16];
961 memcpy(prefixBytes, m_prefix, 16);
962
963 Ipv6Address convertedPrefix = Ipv6Address(prefixBytes);
964 return convertedPrefix;
965}
966
967uint8_t
969{
970 NS_LOG_FUNCTION(this);
971 return m_prefixLength;
972}
973
974void
975Ipv6Prefix::SetPrefixLength(uint8_t prefixLength)
976{
977 NS_LOG_FUNCTION(this);
978 m_prefixLength = prefixLength;
979}
980
981uint8_t
983{
984 NS_LOG_FUNCTION(this);
985
986 uint8_t prefixLength = 0;
987 bool stop = false;
988
989 for (int8_t i = 15; i >= 0 && !stop; i--)
990 {
991 uint8_t mask = m_prefix[i];
992
993 for (uint8_t j = 0; j < 8 && !stop; j++)
994 {
995 if ((mask & 1) == 0)
996 {
997 mask = mask >> 1;
998 prefixLength++;
999 }
1000 else
1001 {
1002 stop = true;
1003 }
1004 }
1005 }
1006
1007 return 128 - prefixLength;
1008}
1009
1010std::ostream&
1011operator<<(std::ostream& os, const Ipv6Prefix& prefix)
1012{
1013 prefix.Print(os);
1014 return os;
1015}
1016
1017std::istream&
1018operator>>(std::istream& is, Ipv6Prefix& prefix)
1019{
1020 std::string str;
1021 is >> str;
1022 prefix = Ipv6Prefix(str.c_str());
1023 return is;
1024}
1025
1026size_t
1028{
1029 uint8_t buf[16];
1030
1031 x.GetBytes(buf);
1032
1033 return lookuphash(buf, sizeof(buf), 0);
1034}
1035
1038
1039} /* namespace ns3 */
a polymophic address class
Definition: address.h:100
static uint8_t Register()
Allocate a new type id for a new type of address.
Definition: address.cc:146
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
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.
Definition: ipv6-address.h:49
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.
Definition: ipv6-address.h:417
uint8_t m_address[16]
The address representation on 128 bits (16 bytes).
Definition: ipv6-address.h:416
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.
Definition: ipv6-address.h:455
uint8_t m_prefixLength
The prefix length.
Definition: ipv6-address.h:594
static Ipv6Prefix GetLoopback()
Get the loopback prefix ( /128).
~Ipv6Prefix()
Destructor.
uint8_t m_prefix[16]
The prefix representation.
Definition: ipv6-address.h:589
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.
Definition: mac16-address.h:44
static bool IsMatchingType(const Address &address)
static Mac16Address ConvertFrom(const Address &address)
void CopyTo(uint8_t buffer[2]) const
an EUI-48 address
Definition: mac48-address.h:46
static bool IsMatchingType(const Address &address)
static Mac48Address ConvertFrom(const Address &address)
void CopyTo(uint8_t buffer[6]) const
an EUI-64 address
Definition: mac64-address.h:46
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.
Definition: mac8-address.h:44
static Mac8Address ConvertFrom(const Address &address)
Convert a generic address to a Mac8Address.
Definition: mac8-address.cc:61
static bool IsMatchingType(const Address &address)
Check that a generic Address is compatible with Mac8Address.
Definition: mac8-address.cc:70
void CopyTo(uint8_t *pBuffer) const
Writes address to buffer parameter.
Definition: mac8-address.cc:87
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:66
#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:86
#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:49
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:282
#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 mix(a, b, c)
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:129
std::istream & operator>>(std::istream &is, Angles &a)
Definition: angles.cc:153
static uint32_t lookuphash(unsigned char *k, uint32_t length, uint32_t level)
Get a hash key.
Definition: ipv6-address.cc:56