A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ipv6-address.cc
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007-2008 Louis Pasteur University
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
19  */
20 
21 #include <iomanip>
22 #include <memory.h>
23 
24 #include "ns3/log.h"
25 #include "ns3/assert.h"
26 
27 #include "mac48-address.h"
28 #include "ipv6-address.h"
29 
30 NS_LOG_COMPONENT_DEFINE ("Ipv6Address");
31 
32 namespace ns3 {
33 
34 #ifdef __cplusplus
35 extern "C"
36 { /* } */
37 #endif
38 
47 static uint32_t lookuphash (unsigned char* k, uint32_t length, uint32_t level)
48 {
49  NS_LOG_FUNCTION (k << length << level);
50 #define mix(a, b, c) \
51  ({ \
52  (a) -= (b); (a) -= (c); (a) ^= ((c) >> 13); \
53  (b) -= (c); (b) -= (a); (b) ^= ((a) << 8); \
54  (c) -= (a); (c) -= (b); (c) ^= ((b) >> 13); \
55  (a) -= (b); (a) -= (c); (a) ^= ((c) >> 12); \
56  (b) -= (c); (b) -= (a); (b) ^= ((a) << 16); \
57  (c) -= (a); (c) -= (b); (c) ^= ((b) >> 5); \
58  (a) -= (b); (a) -= (c); (a) ^= ((c) >> 3); \
59  (b) -= (c); (b) -= (a); (b) ^= ((a) << 10); \
60  (c) -= (a); (c) -= (b); (c) ^= ((b) >> 15); \
61  })
62 
63  typedef uint32_t ub4; /* unsigned 4-byte quantities */
64  uint32_t a = 0;
65  uint32_t b = 0;
66  uint32_t c = 0;
67  uint32_t len = 0;
68 
69  /* Set up the internal state */
70  len = length;
71  a = b = 0x9e3779b9; /* the golden ratio; an arbitrary value */
72  c = level; /* the previous hash value */
73 
74  /* handle most of the key */
75  while (len >= 12)
76  {
77  a += (k[0] + ((ub4)k[1] << 8) + ((ub4)k[2] << 16) + ((ub4)k[3] << 24));
78  b += (k[4] + ((ub4)k[5] << 8) + ((ub4)k[6] << 16) + ((ub4)k[7] << 24));
79  c += (k[8] + ((ub4)k[9] << 8) + ((ub4)k[10] << 16) + ((ub4)k[11] << 24));
80  mix (a, b, c);
81  k += 12;
82  len -= 12;
83  }
84 
85  /* handle the last 11 bytes */
86  c += length;
87  switch (len) /* all the case statements fall through */
88  {
89  case 11: c += ((ub4)k[10] << 24);
90  case 10: c += ((ub4)k[9] << 16);
91  case 9: c += ((ub4)k[8] << 8); /* the first byte of c is reserved for the length */
92  case 8: b += ((ub4)k[7] << 24);
93  case 7: b += ((ub4)k[6] << 16);
94  case 6: b += ((ub4)k[5] << 8);
95  case 5: b += k[4];
96  case 4: a += ((ub4)k[3] << 24);
97  case 3: a += ((ub4)k[2] << 16);
98  case 2: a += ((ub4)k[1] << 8);
99  case 1: a += k[0];
100  /* case 0: nothing left to add */
101  }
102  mix (a, b, c);
103 
104 #undef mix
105 
106  /* report the result */
107  return c;
108 }
109 
110 #ifdef __cplusplus
111 }
112 #endif
113 
120 static bool AsciiToIpv6Host (const char *address, uint8_t addr[16])
121 {
122  NS_LOG_FUNCTION (address << &addr);
123  static const char xdigits_l[] = "0123456789abcdef";
124  static const char xdigits_u[] = "0123456789ABCDEF";
125  unsigned char tmp[16];
126  unsigned char* tp = tmp;
127  unsigned char* endp = 0;
128  unsigned char* colonp = 0;
129  const char* xdigits = 0;
130 #if 0
131  const char* curtok = 0;
132 #endif
133  int ch = 0;
134  int seen_xdigits = 0;
135  unsigned int val = 0;
136 
137  memset (tp, 0x00, 16);
138  endp = tp + 16;
139 
140  /* Leading :: requires some special handling. */
141  if (*address == ':')
142  {
143  if (*++address != ':')
144  {
145  return (0);
146  }
147  }
148 #if 0
149  curtok = address;
150 #endif
151  while ((ch = *address++) != '\0')
152  {
153  const char *pch = 0;
154 
155  if ((pch = strchr ((xdigits = xdigits_l), ch)) == 0)
156  {
157  pch = strchr ((xdigits = xdigits_u), ch);
158  }
159 
160  if (pch != 0)
161  {
162  val <<= 4;
163  val |= (pch - xdigits);
164 
165  if (++seen_xdigits > 4)
166  {
167  return (0);
168  }
169  continue;
170  }
171  if (ch == ':')
172  {
173 #if 0
174  curtok = address;
175 #endif
176 
177  if (!seen_xdigits)
178  {
179  if (colonp)
180  return (0);
181  colonp = tp;
182  continue;
183  }
184 
185  if (tp + 2 > endp)
186  {
187  return (0);
188  }
189 
190  *tp++ = (unsigned char)(val >> 8) & 0xff;
191  *tp++ = (unsigned char) val & 0xff;
192  seen_xdigits = 0;
193  val = 0;
194  continue;
195  }
196 
197  /* TODO Handle IPv4 mapped address (2001::192.168.0.1) */
198 #if 0
199  if (ch == '.' && ((tp + 4 /*NS_INADDRSZ*/) <= endp) &&
200  inet_pton4 (curtok, tp) > 0)
201  {
202  tp += 4 /*NS_INADDRSZ*/;
203  seen_xdigits = 0;
204  break; /* '\0' was seen by inet_pton4(). */
205  }
206 #endif
207  return (0);
208  }
209 
210  if (seen_xdigits)
211  {
212  if (tp + 2 > endp)
213  {
214  return (0);
215  }
216  *tp++ = (unsigned char)(val >> 8) & 0xff;
217  *tp++ = (unsigned char) val & 0xff;
218  }
219 
220  if (colonp != 0)
221  {
222  /*
223  * Since some memmove ()'s erroneously fail to handle
224  * overlapping regions, we'll do the shift by hand.
225  */
226  const int n = tp - colonp;
227  int i = 0;
228 
229  if (tp == endp)
230  {
231  return (0);
232  }
233 
234  for (i = 1; i <= n; i++)
235  {
236  endp[-i] = colonp[n - i];
237  colonp[n - i] = 0;
238  }
239 
240  tp = endp;
241  }
242 
243  if (tp != endp)
244  {
245  return (0);
246  }
247 
248  memcpy (addr, tmp, 16);
249  return (1);
250 }
251 
253 {
254  NS_LOG_FUNCTION (this);
255  memset (m_address, 0x00, 16);
256 }
257 
259 {
260  // Do not add function logging here, to avoid stack overflow
261  memcpy (m_address, addr.m_address, 16);
262 }
263 
265 {
266  // Do not add function logging here, to avoid stack overflow
267  memcpy (m_address, addr->m_address, 16);
268 }
269 
270 Ipv6Address::Ipv6Address (char const* address)
271 {
272  NS_LOG_FUNCTION (this << address);
273  AsciiToIpv6Host (address, m_address);
274 }
275 
276 Ipv6Address::Ipv6Address (uint8_t address[16])
277 {
278  NS_LOG_FUNCTION (this << &address);
279  /* 128 bit => 16 bytes */
280  memcpy (m_address, address, 16);
281 }
282 
284 {
285  /* do nothing */
286  NS_LOG_FUNCTION (this);
287 }
288 
289 void Ipv6Address::Set (char const* address)
290 {
291  NS_LOG_FUNCTION (this << address);
292  AsciiToIpv6Host (address, m_address);
293 }
294 
295 void Ipv6Address::Set (uint8_t address[16])
296 {
297  /* 128 bit => 16 bytes */
298  NS_LOG_FUNCTION (this << &address);
299  memcpy (m_address, address, 16);
300 }
301 
302 void Ipv6Address::Serialize (uint8_t buf[16]) const
303 {
304  NS_LOG_FUNCTION (this << &buf);
305  memcpy (buf, m_address, 16);
306 }
307 
308 Ipv6Address Ipv6Address::Deserialize (const uint8_t buf[16])
309 {
310  NS_LOG_FUNCTION (&buf);
311  Ipv6Address ipv6 ((uint8_t*)buf);
312  return ipv6;
313 }
314 
316 {
317  NS_LOG_FUNCTION (addr);
318  uint8_t buf[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
319  0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 };
320  addr.Serialize (&buf[12]);
321  return (Ipv6Address (buf));
322 }
323 
325 {
326  NS_LOG_FUNCTION (this);
327  uint8_t buf[16];
328  Ipv4Address v4Addr;
329 
330  Serialize (buf);
331  v4Addr = Ipv4Address::Deserialize (&buf[12]);
332  return (v4Addr);
333 }
334 
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 
356 {
357  NS_LOG_FUNCTION (addr);
358  Ipv6Address ret;
359  uint8_t buf[16];
360  uint8_t buf2[16];
361 
362  addr.CopyTo (buf);
363 
364  memset (buf2, 0x00, sizeof (buf2));
365  buf2[0] = 0xfe;
366  buf2[1] = 0x80;
367  memcpy (buf2 + 8, buf, 3);
368  buf2[11] = 0xff;
369  buf2[12] = 0xfe;
370  memcpy (buf2 + 13, buf + 3, 3);
371  buf2[8] |= 0x02;
372 
373  ret.Set (buf2);
374  return ret;
375 }
376 
378 {
379  NS_LOG_FUNCTION (addr);
380  uint8_t buf[16];
381  uint8_t buf2[16];
382  Ipv6Address ret;
383 
384  addr.Serialize (buf2);
385 
386  memset (buf, 0x00, sizeof (buf));
387  buf[0] = 0xff;
388  buf[1] = 0x02;
389  buf[11] = 0x01;
390  buf[12] = 0xff;
391  buf[13] = buf2[13];
392  buf[14] = buf2[14];
393  buf[15] = buf2[15];
394 
395  ret.Set (buf);
396  return ret;
397 }
398 
399 void Ipv6Address::Print (std::ostream& os) const
400 {
401  NS_LOG_FUNCTION (this << &os);
402  os << std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_address[0]
403  << std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_address[1] << ":"
404  << std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_address[2]
405  << std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_address[3] << ":"
406  << std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_address[4]
407  << std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_address[5] << ":"
408  << std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_address[6]
409  << std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_address[7] << ":"
410  << std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_address[8]
411  << std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_address[9] << ":"
412  << std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_address[10]
413  << std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_address[11] << ":"
414  << std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_address[12]
415  << std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_address[13] << ":"
416  << std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_address[14]
417  << std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_address[15]
418  << std::dec << std::setfill (' ');
419 }
420 
422 {
423  NS_LOG_FUNCTION (this);
424  static Ipv6Address localhost ("::1");
425  return (*this == localhost);
426 }
427 
429 {
430  NS_LOG_FUNCTION (this);
431  if (m_address[0] == 0xff)
432  {
433  return true;
434  }
435  return false;
436 }
437 
439 {
440  NS_LOG_FUNCTION (this);
441  if (m_address[0] == 0xff && m_address[1] == 0x02)
442  {
443  return true;
444  }
445  return false;
446 }
447 
449 {
450  NS_LOG_FUNCTION (this);
451  uint8_t v4MappedPrefix[12] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
452  0x00, 0x00, 0xff, 0xff };
453  if (memcmp(m_address, v4MappedPrefix, sizeof(v4MappedPrefix)) == 0)
454  {
455  return (true);
456  }
457  return (false);
458 }
459 
461 {
462  NS_LOG_FUNCTION (this << prefix);
463  Ipv6Address ipv6;
464  uint8_t addr[16];
465  uint8_t pref[16];
466  unsigned int i = 0;
467 
468  memcpy (addr, m_address, 16);
469  ((Ipv6Prefix)prefix).GetBytes (pref);
470 
471  /* a little bit ugly... */
472  for (i = 0; i < 16; i++)
473  {
474  addr[i] = addr[i] & pref[i];
475  }
476  ipv6.Set (addr);
477  return ipv6;
478 }
479 
481 {
482  NS_LOG_FUNCTION (this);
483  uint8_t buf[16];
484 
485  Serialize (buf);
486 
487  if (buf[0] == 0xff &&
488  buf[1] == 0x02 &&
489  buf[11] == 0x01 &&
490  buf[12] == 0xff)
491  {
492  return true;
493  }
494  return false;
495 }
496 
498 {
499  NS_LOG_FUNCTION (this);
500  static Ipv6Address allnodes ("ff02::1");
501  return (*this == allnodes);
502 }
503 
505 {
506  NS_LOG_FUNCTION (this);
507  static Ipv6Address allrouters ("ff02::2");
508  return (*this == allrouters);
509 }
510 
512 {
513  NS_LOG_FUNCTION (this);
514  static Ipv6Address allhosts ("ff02::3");
515  return (*this == allhosts);
516 }
517 
518 bool Ipv6Address::IsAny () const
519 {
520  NS_LOG_FUNCTION (this);
521  static Ipv6Address any ("::");
522  return (*this == any);
523 }
524 
526 {
527  NS_LOG_FUNCTION (address);
528  return address.CheckCompatible (GetType (), 16);
529 }
530 
531 Ipv6Address::operator Address () const
532 {
533  return ConvertTo ();
534 }
535 
537 {
538  NS_LOG_FUNCTION (this);
539  uint8_t buf[16];
540  Serialize (buf);
541  return Address (GetType (), buf, 16);
542 }
543 
545 {
546  NS_LOG_FUNCTION (address);
547  NS_ASSERT (address.CheckCompatible (GetType (), 16));
548  uint8_t buf[16];
549  address.CopyTo (buf);
550  return Deserialize (buf);
551 }
552 
553 uint8_t Ipv6Address::GetType (void)
554 {
556  static uint8_t type = Address::Register ();
557  return type;
558 }
559 
561 {
563  static Ipv6Address nmc ("ff02::1");
564  return nmc;
565 }
566 
568 {
570  static Ipv6Address rmc ("ff02::2");
571  return rmc;
572 }
573 
575 {
577  static Ipv6Address hmc ("ff02::3");
578  return hmc;
579 }
580 
582 {
584  static Ipv6Address loopback ("::1");
585  return loopback;
586 }
587 
589 {
591  static Ipv6Address zero ("::");
592  return zero;
593 }
594 
596 {
598  static Ipv6Address any ("::");
599  return any;
600 }
601 
603 {
605  static Ipv6Address ones ("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff");
606  return ones;
607 }
608 
609 void Ipv6Address::GetBytes (uint8_t buf[16]) const
610 {
611  NS_LOG_FUNCTION (this << &buf);
612  memcpy (buf, m_address, 16);
613 }
614 
616 {
617  NS_LOG_FUNCTION (this);
618  Ipv6Address linkLocal ("fe80::0");
619  if (!IsMulticast () && ((Ipv6Address*)this)->CombinePrefix (Ipv6Prefix (64)) == linkLocal)
620  {
621  return true;
622  }
623  return false;
624 }
625 
626 bool Ipv6Address::IsEqual (const Ipv6Address& other) const
627 {
628  NS_LOG_FUNCTION (this << other);
629  if (!memcmp (m_address, other.m_address, 16))
630  {
631  return true;
632  }
633  return false;
634 }
635 
636 std::ostream& operator << (std::ostream& os, Ipv6Address const& address)
637 {
638  address.Print (os);
639  return os;
640 }
641 
642 std::istream& operator >> (std::istream& is, Ipv6Address& address)
643 {
644  std::string str;
645  is >> str;
646  address = Ipv6Address (str.c_str ());
647  return is;
648 }
649 
651 {
652  NS_LOG_FUNCTION (this);
653  memset (m_prefix, 0x00, 16);
654 }
655 
656 Ipv6Prefix::Ipv6Prefix (char const* prefix)
657 {
658  NS_LOG_FUNCTION (this << prefix);
659  AsciiToIpv6Host (prefix, m_prefix);
660 }
661 
662 Ipv6Prefix::Ipv6Prefix (uint8_t prefix[16])
663 {
664  NS_LOG_FUNCTION (this << &prefix);
665  memcpy (m_prefix, prefix, 16);
666 }
667 
668 Ipv6Prefix::Ipv6Prefix (uint8_t prefix)
669 {
670  NS_LOG_FUNCTION (this << static_cast<uint32_t> (prefix));
671  unsigned int nb=0;
672  unsigned int mod=0;
673  unsigned int i=0;
674 
675  memset (m_prefix, 0x00, 16);
676 
677  NS_ASSERT (prefix <= 128);
678 
679  nb = prefix / 8;
680  mod = prefix % 8;
681 
682  // protect memset with 'nb > 0' check to suppress
683  // __warn_memset_zero_len compiler errors in some gcc>4.5.x
684  if (nb > 0)
685  {
686  memset (m_prefix, 0xff, nb);
687  }
688  if (mod)
689  {
690  m_prefix[nb] = 0xff << (8-mod);
691  }
692 
693  if (nb < 16)
694  {
695  nb++;
696  for (i = nb; i < 16; i++)
697  {
698  m_prefix[i] = 0x00;
699  }
700  }
701 }
702 
704 {
705  memcpy (m_prefix, prefix.m_prefix, 16);
706 }
707 
709 {
710  memcpy (m_prefix, prefix->m_prefix, 16);
711 }
712 
714 {
715  /* do nothing */
716  NS_LOG_FUNCTION (this);
717 }
718 
720 {
721  NS_LOG_FUNCTION (this << a << b);
722  uint8_t addrA[16];
723  uint8_t addrB[16];
724  unsigned int i = 0;
725 
726  a.GetBytes (addrA);
727  b.GetBytes (addrB);
728 
729  /* a little bit ugly... */
730  for (i = 0; i < 16; i++)
731  {
732  if ((addrA[i] & m_prefix[i]) != (addrB[i] & m_prefix[i]))
733  {
734  return false;
735  }
736  }
737  return true;
738 }
739 
740 void Ipv6Prefix::Print (std::ostream &os) const
741 {
742  NS_LOG_FUNCTION (this << &os);
743  os << std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_prefix[0]
744  << std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_prefix[1] << ":"
745  << std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_prefix[2]
746  << std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_prefix[3] << ":"
747  << std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_prefix[4]
748  << std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_prefix[5] << ":"
749  << std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_prefix[6]
750  << std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_prefix[7] << ":"
751  << std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_prefix[8]
752  << std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_prefix[9] << ":"
753  << std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_prefix[10]
754  << std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_prefix[11] << ":"
755  << std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_prefix[12]
756  << std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_prefix[13] << ":"
757  << std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_prefix[14]
758  << std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_prefix[15];
759 }
760 
762 {
764  static Ipv6Prefix prefix ((uint8_t)128);
765  return prefix;
766 }
767 
769 {
771  static Ipv6Prefix ones ((uint8_t)128);
772  return ones;
773 }
774 
776 {
778  static Ipv6Prefix prefix ((uint8_t)0);
779  return prefix;
780 }
781 
782 void Ipv6Prefix::GetBytes (uint8_t buf[16]) const
783 {
784  NS_LOG_FUNCTION (this << &buf);
785  memcpy (buf, m_prefix, 16);
786 }
787 
789 {
790  NS_LOG_FUNCTION (this);
791  uint8_t i = 0;
792  uint8_t prefixLength = 0;
793 
794  for(i = 0; i < 16; i++)
795  {
796  uint8_t mask = m_prefix[i];
797 
798  while(mask != 0)
799  {
800  mask = mask << 1;
801  prefixLength++;
802  }
803  }
804 
805  return prefixLength;
806 }
807 
808 bool Ipv6Prefix::IsEqual (const Ipv6Prefix& other) const
809 {
810  if (!memcmp (m_prefix, other.m_prefix, 16))
811  {
812  return true;
813  }
814  return false;
815 }
816 
817 std::ostream& operator << (std::ostream& os, Ipv6Prefix const& prefix)
818 {
819  prefix.Print (os);
820  return os;
821 }
822 
823 std::istream& operator >> (std::istream& is, Ipv6Prefix& prefix)
824 {
825  std::string str;
826  is >> str;
827  prefix = Ipv6Prefix (str.c_str ());
828  return is;
829 }
830 
831 bool operator == (Ipv6Prefix const &a, Ipv6Prefix const &b)
832 {
833  return a.IsEqual (b);
834 }
835 
836 bool operator != (Ipv6Prefix const &a, Ipv6Prefix const &b)
837 {
838  return !a.IsEqual (b);
839 }
840 
842 {
843  uint8_t buf[16];
844 
845  x.GetBytes (buf);
846 
847  return lookuphash (buf, sizeof (buf), 0);
848 }
849 
852 
853 } /* namespace ns3 */
854 
bool IsMatch(Ipv6Address a, Ipv6Address b) const
If the Address match the type.
static bool IsMatchingType(const Address &address)
If the Address matches the type.
bool IsAny() const
If the IPv6 address is the "Any" address.
static Ipv4Address Deserialize(const uint8_t buf[4])
static Ipv6Address GetLoopback()
Get the loopback address.
std::istream & operator>>(std::istream &is, Angles &a)
Definition: angles.cc:49
static Ipv6Address MakeAutoconfiguredAddress(Mac48Address addr, Ipv6Address prefix)
Make the autoconfigured IPv6 address with Mac48Address.
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:311
Ipv6Address()
Default constructor.
uint8_t m_address[16]
The address representation on 128 bits (16 bytes).
Definition: ipv6-address.h:313
bool IsLinkLocalMulticast() const
If the IPv6 address is link-local multicast (ff02::/16).
Ipv6Prefix()
Default constructor.
static Ipv6Address Deserialize(const uint8_t buf[16])
Deserialize this address.
bool IsLinkLocal() const
If the IPv6 address is a link-local address (fe80::/64).
~Ipv6Prefix()
Destructor.
bool IsAllRoutersMulticast() const
If the IPv6 address is "all routers multicast" (ff02::2/8).
#define NS_ASSERT(condition)
Definition: assert.h:64
bool IsEqual(const Ipv6Prefix &other) const
Comparison operation between two Ipv6Prefix.
static Ipv6Address GetAny()
Get the "any" (::) Ipv6Address.
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
size_t operator()(Ipv6Address const &x) const
Unary operator to hash IPv6 address.
bool IsEqual(const Ipv6Address &other) const
Comparison operation between two Ipv6Addresses.
bool IsAllHostsMulticast() const
If the IPv6 address is "all hosts multicast" (ff02::3/8).
#define NS_LOG_FUNCTION_NOARGS()
Definition: log.h:275
bool IsAllNodesMulticast() const
If the IPv6 address is "all nodes multicast" (ff02::1/8).
static Ipv6Prefix GetZero()
Get the zero prefix ( /0).
static uint32_t lookuphash(unsigned char *k, uint32_t length, uint32_t level)
Get a hash key.
Definition: ipv6-address.cc:47
a polymophic address class
Definition: address.h:86
bool CheckCompatible(uint8_t type, uint8_t len) const
Definition: address.cc:122
void CopyTo(uint8_t buffer[6]) const
Address ConvertTo(void) const
convert the IPv6Address object to an Address object.
static Ipv6Address GetZero()
Get the 0 (::) Ipv6Address.
void Print(std::ostream &os) const
Print this address to the given output stream.
void Serialize(uint8_t buf[4]) const
void GetBytes(uint8_t buf[16]) const
Get the bytes corresponding to the address.
void Set(char const *address)
Sets an Ipv6Address by parsing the input C-string.
static Ipv6Address GetAllHostsMulticast()
Get the "all hosts multicast" address.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:43
#define ATTRIBUTE_HELPER_CPP(type)
bool IsMulticast() const
If the IPv6 address is multicast (ff00::/8).
static Ipv6Address GetAllNodesMulticast()
Get the "all nodes multicast" address.
an EUI-48 address
Definition: mac48-address.h:41
uint8_t m_prefix[16]
The prefix representation.
Definition: ipv6-address.h:427
static bool AsciiToIpv6Host(const char *address, uint8_t addr[16])
Convert an IPv6 C-string into a 128-bit representation.
Describes an IPv6 address.
Definition: ipv6-address.h:44
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
void Print(std::ostream &os) const
Print this address to the given output stream.
bool IsSolicitedMulticast() const
If the IPv6 address is a Solicited multicast address.
static Ipv6Prefix GetOnes()
Get the "all-1" IPv6 mask (ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff).
uint32_t CopyTo(uint8_t buffer[MAX_SIZE]) const
Definition: address.cc:82
void GetBytes(uint8_t buf[16]) const
Get the bytes corresponding to the prefix.
~Ipv6Address()
Destructor.
static Ipv6Address GetOnes()
Get the "all-1" IPv6 address (ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff).
static Ipv6Prefix GetLoopback()
Get the loopback prefix ( /128).
Describes an IPv6 prefix. It is just a bitmask like Ipv4Mask.
Definition: ipv6-address.h:326
Ipv4Address GetIpv4MappedAddress() const
Return the Ipv4 address.
uint8_t GetPrefixLength() const
Get prefix length.
bool IsLocalhost() const
If the IPv6 address is localhost (::1).
static Ipv6Address MakeIpv4MappedAddress(Ipv4Address addr)
Make the Ipv4-mapped IPv6 address.
Ipv6Address CombinePrefix(Ipv6Prefix const &prefix)
Combine this address with a prefix.
static Ipv6Address MakeAutoconfiguredLinkLocalAddress(Mac48Address mac)
Make the autoconfigured link-local IPv6 address with Mac48Address.
bool IsIpv4MappedAddress()
If the address is an IPv4-mapped address.
static uint8_t Register(void)
Definition: address.cc:137
static uint8_t GetType(void)
Return the Type of address.
static Ipv6Address MakeSolicitedAddress(Ipv6Address addr)
Make the solicited IPv6 address.
static Ipv6Address GetAllRoutersMulticast()
Get the "all routers multicast" address.
static Ipv6Address ConvertFrom(const Address &address)
Convert the Address object into an Ipv6Address ones.
void Serialize(uint8_t buf[16]) const
Serialize this address to a 16-byte buffer.