A Discrete-Event Network Simulator
API
ipv6-address.h
Go to the documentation of this file.
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 #ifndef IPV6_ADDRESS_H
22 #define IPV6_ADDRESS_H
23 
24 #include <stdint.h>
25 #include <cstring>
26 
27 #include <ostream>
28 
29 #include "ns3/attribute-helper.h"
30 #include "ns3/address.h"
31 #include "ns3/ipv4-address.h"
32 #include "ns3/deprecated.h"
33 #include "mac8-address.h"
34 
35 namespace ns3 {
36 
37 class Ipv6Prefix;
38 class Mac16Address;
39 class Mac48Address;
40 class Mac64Address;
41 
50 {
51 public:
55  Ipv6Address ();
56 
61  Ipv6Address (char const* address);
62 
68  Ipv6Address (uint8_t address[16]);
69 
74  Ipv6Address (Ipv6Address const & addr);
75 
80  Ipv6Address (Ipv6Address const* addr);
81 
85  ~Ipv6Address ();
86 
91  void Set (char const* address);
92 
99  void Set (uint8_t address[16]);
100 
110  bool IsEqual (const Ipv6Address& other) const;
111 
117  void Serialize (uint8_t buf[16]) const;
118 
124  static Ipv6Address Deserialize (const uint8_t buf[16]);
125 
132 
139 
145 
156 
168 
179 
190 
198 
209 
219 
229 
239 
246 
256 
263  void Print (std::ostream& os) const;
264 
269  bool IsLocalhost () const;
270 
275  bool IsMulticast () const;
276 
281  bool IsLinkLocalMulticast () const;
282 
287  bool IsAllNodesMulticast () const;
288 
293  bool IsAllRoutersMulticast () const;
294 
299  bool IsLinkLocal () const;
300 
305  bool IsSolicitedMulticast () const;
306 
311  bool IsAny () const;
312 
317  bool IsDocumentation () const;
318 
324  bool HasPrefix (Ipv6Prefix const& prefix) const;
325 
332  Ipv6Address CombinePrefix (Ipv6Prefix const & prefix) const;
333 
339  static bool IsMatchingType (const Address& address);
340 
345  bool IsIpv4MappedAddress() const;
346 
350  operator Address () const;
351 
357  static Ipv6Address ConvertFrom (const Address& address);
358 
362  bool IsInitialized (void) const;
363 
368  static Ipv6Address GetZero ();
369 
374  static Ipv6Address GetAny ();
375 
381 
387 
393 
398  static Ipv6Address GetLoopback ();
399 
404  static Ipv6Address GetOnes ();
405 
411  void GetBytes (uint8_t buf[16]) const;
412 
413 private:
418  Address ConvertTo (void) const;
419 
424  static uint8_t GetType (void);
425 
429  uint8_t m_address[16];
431 
439  friend bool operator == (Ipv6Address const &a, Ipv6Address const &b);
440 
448  friend bool operator != (Ipv6Address const &a, Ipv6Address const &b);
449 
457  friend bool operator < (Ipv6Address const &a, Ipv6Address const &b);
458 };
459 
468 {
469 public:
473  Ipv6Prefix ();
474 
483  Ipv6Prefix (uint8_t prefix[16]);
484 
493  Ipv6Prefix (char const* prefix);
494 
500  Ipv6Prefix (uint8_t prefix[16], uint8_t prefixLength);
501 
507  Ipv6Prefix (char const* prefix, uint8_t prefixLength);
508 
514  Ipv6Prefix (uint8_t prefix);
515 
520  Ipv6Prefix (Ipv6Prefix const& prefix);
521 
526  Ipv6Prefix (Ipv6Prefix const* prefix);
527 
531  ~Ipv6Prefix ();
532 
539  bool IsMatch (Ipv6Address a, Ipv6Address b) const;
540 
545  void GetBytes (uint8_t buf[16]) const;
546 
551  uint8_t GetPrefixLength () const;
552 
557  void SetPrefixLength (uint8_t prefixLength);
558 
563  uint8_t GetMinimumPrefixLength () const;
564 
574  bool IsEqual (const Ipv6Prefix& other) const;
575 
582  void Print (std::ostream &os) const;
583 
588  static Ipv6Prefix GetLoopback ();
589 
594  static Ipv6Prefix GetOnes ();
595 
600  static Ipv6Prefix GetZero ();
601 
602 private:
606  uint8_t m_prefix[16];
607 
611  uint8_t m_prefixLength;
612 
620  friend bool operator == (Ipv6Prefix const &a, Ipv6Prefix const &b);
621 
629  friend bool operator != (Ipv6Prefix const &a, Ipv6Prefix const &b);
630 };
631 
634 
642 std::ostream & operator << (std::ostream& os, Ipv6Address const& address);
643 
651 std::ostream & operator << (std::ostream& os, Ipv6Prefix const& prefix);
652 
660 std::istream & operator >> (std::istream &is, Ipv6Address &address);
661 
669 std::istream & operator >> (std::istream &is, Ipv6Prefix &prefix);
670 
671 inline bool operator == (const Ipv6Address& a, const Ipv6Address& b)
672 {
673  return (!std::memcmp (a.m_address, b.m_address, 16));
674 }
675 
676 inline bool operator != (const Ipv6Address& a, const Ipv6Address& b)
677 {
678  return std::memcmp (a.m_address, b.m_address, 16);
679 }
680 
681 inline bool operator < (const Ipv6Address& a, const Ipv6Address& b)
682 {
683  return (std::memcmp (a.m_address, b.m_address, 16) < 0);
684 }
685 
686 inline bool operator == (const Ipv6Prefix& a, const Ipv6Prefix& b)
687 {
688  return (!std::memcmp (a.m_prefix, b.m_prefix, 16));
689 }
690 
691 inline bool operator != (const Ipv6Prefix& a, const Ipv6Prefix& b)
692 {
693  return std::memcmp (a.m_prefix, b.m_prefix, 16);
694 }
695 
701 {
702 public:
708  size_t operator () (Ipv6Address const &x) const;
709 };
710 
711 } /* namespace ns3 */
712 
713 #endif /* IPV6_ADDRESS_H */
714 
static bool IsMatchingType(const Address &address)
If the Address matches the type.
static Ipv6Address GetLoopback()
Get the loopback address.
bool IsLocalhost() const
If the IPv6 address is localhost (::1).
Ipv4Address GetIpv4MappedAddress() const
Return the Ipv4 address.
Ipv6Address()
Default constructor.
uint8_t m_address[16]
The address representation on 128 bits (16 bytes).
Definition: ipv6-address.h:429
bool IsIpv4MappedAddress() const
If the address is an IPv4-mapped address.
friend bool operator!=(Ipv6Address const &a, Ipv6Address const &b)
Not equal to operator.
Definition: ipv6-address.h:676
Ipv6Prefix()
Default constructor.
void SetPrefixLength(uint8_t prefixLength)
Set prefix length.
friend bool operator<(Ipv6Address const &a, Ipv6Address const &b)
Less than to operator.
Definition: ipv6-address.h:681
friend bool operator==(Ipv6Prefix const &a, Ipv6Prefix const &b)
Equal to operator.
Definition: ipv6-address.h:686
static Ipv6Address MakeAutoconfiguredLinkLocalAddress(Address mac)
Make the autoconfigured link-local IPv6 address from a Mac address.
static Ipv6Address Deserialize(const uint8_t buf[16])
Deserialize this address.
static Ipv6Address MakeAutoconfiguredAddress(Address addr, Ipv6Address prefix)
Make the autoconfigured IPv6 address from a Mac address.
~Ipv6Prefix()
Destructor.
void GetBytes(uint8_t buf[16]) const
Get the bytes corresponding to the address.
static Ipv6Address GetAny()
Get the "any" (::) Ipv6Address.
Address ConvertTo(void) const
convert the IPv6Address object to an Address object.
void GetBytes(uint8_t buf[16]) const
Get the bytes corresponding to the prefix.
std::istream & operator>>(std::istream &is, Angles &a)
Definition: angles.cc:160
friend bool operator!=(Ipv6Prefix const &a, Ipv6Prefix const &b)
Not equal to operator.
Definition: ipv6-address.h:691
static Ipv6Prefix GetZero()
Get the zero prefix ( /0).
uint8_t m_prefixLength
The prefix length.
Definition: ipv6-address.h:611
size_t operator()(Ipv6Address const &x) const
Returns the hash of an IPv6 address.
a polymophic address class
Definition: address.h:90
bool IsMatch(Ipv6Address a, Ipv6Address b) const
If the Address match the type.
bool operator<(const EventId &a, const EventId &b)
Definition: event-id.h:160
an EUI-64 address
Definition: mac64-address.h:43
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:137
bool IsSolicitedMulticast() const
If the IPv6 address is a Solicited multicast address.
NS_DEPRECATED_3_31 bool IsEqual(const Ipv6Address &other) const
Comparison operation between two Ipv6Addresses.
bool IsDocumentation() const
If the IPv6 address is a documentation address (2001:DB8::/32).
static Ipv6Address GetZero()
Get the 0 (::) Ipv6Address.
mac
Definition: third.py:99
A class used for addressing MAC8 MAC&#39;s.
Definition: mac8-address.h:42
bool IsLinkLocal() const
If the IPv6 address is a link-local address (fe80::/64).
Ipv6Address CombinePrefix(Ipv6Prefix const &prefix) const
Combine this address with a prefix.
uint8_t GetMinimumPrefixLength() const
Get the minimum prefix length, i.e., 128 - the length of the largest sequence trailing zeroes...
void Set(char const *address)
Sets an Ipv6Address by parsing the input C-string.
static Ipv6Address GetAllHostsMulticast()
Get the "all hosts multicast" address.
bool IsAllRoutersMulticast() const
If the IPv6 address is "all routers multicast" (ff02::2/8).
bool operator!=(Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 > a, Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 > b)
Inequality test.
Definition: callback.h:1606
bool IsMulticast() const
If the IPv6 address is multicast (ff00::/8).
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool IsAllNodesMulticast() const
If the IPv6 address is "all nodes multicast" (ff02::1/8).
bool HasPrefix(Ipv6Prefix const &prefix) const
Compares an address and a prefix.
address
Definition: first.py:44
static Ipv6Address GetAllNodesMulticast()
Get the "all nodes multicast" address.
an EUI-48 address
Definition: mac48-address.h:43
uint8_t m_prefix[16]
The prefix representation.
Definition: ipv6-address.h:606
This class can contain 16 bit addresses.
Definition: mac16-address.h:41
uint8_t GetPrefixLength() const
Get prefix length.
NS_DEPRECATED_3_31 bool IsEqual(const Ipv6Prefix &other) const
Comparison operation between two Ipv6Prefix.
void Print(std::ostream &os) const
Print this address to the given output stream.
bool IsLinkLocalMulticast() const
If the IPv6 address is link-local multicast (ff02::/16).
Hash function class for IPv6 addresses.
Definition: ipv6-address.h:700
Describes an IPv6 address.
Definition: ipv6-address.h:49
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
static Ipv6Prefix GetOnes()
Get the "all-1" IPv6 mask (ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff).
#define NS_DEPRECATED_3_31
Tag for things deprecated in version ns-3.31.
Definition: deprecated.h:89
bool m_initialized
IPv6 address has been explicitly initialized to a valid value.
Definition: ipv6-address.h:430
bool operator==(const EventId &a, const EventId &b)
Definition: event-id.h:142
~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.
Definition: ipv6-address.h:467
friend bool operator==(Ipv6Address const &a, Ipv6Address const &b)
Equal to operator.
Definition: ipv6-address.h:671
static Ipv6Address MakeIpv4MappedAddress(Ipv4Address addr)
Make the Ipv4-mapped IPv6 address.
#define ATTRIBUTE_HELPER_HEADER(type)
Declare the attribute value, accessor and checkers for class type
static uint8_t GetType(void)
Return the Type of address.
void Print(std::ostream &os) const
Print this address to the given output stream.
bool IsInitialized(void) const
bool IsAny() const
If the IPv6 address is the "Any" address.
void Serialize(uint8_t buf[16]) const
Serialize this address to a 16-byte buffer.
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.