A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
34 namespace ns3 {
35 
36 class Ipv6Prefix;
37 class Mac16Address;
38 class Mac48Address;
39 class Mac64Address;
40 
49 {
50 public:
54  Ipv6Address ();
55 
60  Ipv6Address (char const* address);
61 
67  Ipv6Address (uint8_t address[16]);
68 
73  Ipv6Address (Ipv6Address const & addr);
74 
79  Ipv6Address (Ipv6Address const* addr);
80 
84  ~Ipv6Address ();
85 
90  void Set (char const* address);
91 
98  void Set (uint8_t address[16]);
99 
106  bool IsEqual (const Ipv6Address& other) const;
107 
113  void Serialize (uint8_t buf[16]) const;
114 
120  static Ipv6Address Deserialize (const uint8_t buf[16]);
121 
128 
135 
141 
149 
157 
165 
172 
179 
186 
193  void Print (std::ostream& os) const;
194 
199  bool IsLocalhost () const;
200 
205  bool IsMulticast () const;
206 
211  bool IsLinkLocalMulticast () const;
212 
217  bool IsAllNodesMulticast () const;
218 
223  bool IsAllRoutersMulticast () const;
224 
232  bool IsAllHostsMulticast () const NS_DEPRECATED;
233 
238  bool IsLinkLocal () const;
239 
244  bool IsSolicitedMulticast () const;
245 
250  bool IsAny () const;
251 
256  bool IsDocumentation () const;
257 
264  Ipv6Address CombinePrefix (Ipv6Prefix const & prefix);
265 
271  static bool IsMatchingType (const Address& address);
272 
277  bool IsIpv4MappedAddress() const;
278 
282  operator Address () const;
283 
289  static Ipv6Address ConvertFrom (const Address& address);
290 
295  static Ipv6Address GetZero ();
296 
301  static Ipv6Address GetAny ();
302 
308 
314 
320 
325  static Ipv6Address GetLoopback ();
326 
331  static Ipv6Address GetOnes ();
332 
338  void GetBytes (uint8_t buf[16]) const;
339 
340 private:
345  Address ConvertTo (void) const;
346 
351  static uint8_t GetType (void);
352 
356  uint8_t m_address[16];
357 
365  friend bool operator == (Ipv6Address const &a, Ipv6Address const &b);
366 
374  friend bool operator != (Ipv6Address const &a, Ipv6Address const &b);
375 
383  friend bool operator < (Ipv6Address const &a, Ipv6Address const &b);
384 };
385 
394 {
395 public:
399  Ipv6Prefix ();
400 
405  Ipv6Prefix (uint8_t prefix[16]);
406 
411  Ipv6Prefix (char const* prefix);
412 
418  Ipv6Prefix (uint8_t prefix);
419 
424  Ipv6Prefix (Ipv6Prefix const& prefix);
425 
430  Ipv6Prefix (Ipv6Prefix const* prefix);
431 
435  ~Ipv6Prefix ();
436 
443  bool IsMatch (Ipv6Address a, Ipv6Address b) const;
444 
449  void GetBytes (uint8_t buf[16]) const;
450 
455  uint8_t GetPrefixLength () const;
456 
462  bool IsEqual (const Ipv6Prefix& other) const;
463 
470  void Print (std::ostream &os) const;
471 
476  static Ipv6Prefix GetLoopback ();
477 
482  static Ipv6Prefix GetOnes ();
483 
488  static Ipv6Prefix GetZero ();
489 
490 private:
494  uint8_t m_prefix[16];
495 
503  friend bool operator == (Ipv6Prefix const &a, Ipv6Prefix const &b);
504 
512  friend bool operator != (Ipv6Prefix const &a, Ipv6Prefix const &b);
513 };
514 
517 
525 std::ostream & operator << (std::ostream& os, Ipv6Address const& address);
526 
534 std::ostream & operator << (std::ostream& os, Ipv6Prefix const& prefix);
535 
543 std::istream & operator >> (std::istream &is, Ipv6Address &address);
544 
552 std::istream & operator >> (std::istream &is, Ipv6Prefix &prefix);
553 
554 inline bool operator == (const Ipv6Address& a, const Ipv6Address& b)
555 {
556  return (!std::memcmp (a.m_address, b.m_address, 16));
557 }
558 
559 inline bool operator != (const Ipv6Address& a, const Ipv6Address& b)
560 {
561  return std::memcmp (a.m_address, b.m_address, 16);
562 }
563 
564 inline bool operator < (const Ipv6Address& a, const Ipv6Address& b)
565 {
566  return (std::memcmp (a.m_address, b.m_address, 16) < 0);
567 }
568 
569 inline bool operator == (const Ipv6Prefix& a, const Ipv6Prefix& b)
570 {
571  return (!std::memcmp (a.m_prefix, b.m_prefix, 16));
572 }
573 
574 inline bool operator != (const Ipv6Prefix& a, const Ipv6Prefix& b)
575 {
576  return std::memcmp (a.m_prefix, b.m_prefix, 16);
577 }
578 
583 class Ipv6AddressHash : public std::unary_function<Ipv6Address, size_t>
584 {
585 public:
591  size_t operator () (Ipv6Address const &x) const;
592 };
593 
594 } /* namespace ns3 */
595 
596 #endif /* IPV6_ADDRESS_H */
597 
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 Ipv6Address GetLoopback()
Get the loopback address.
std::istream & operator>>(std::istream &is, Angles &a)
initialize a struct Angles from input
Definition: angles.cc:48
Ipv6Address()
Default constructor.
uint8_t m_address[16]
The address representation on 128 bits (16 bytes).
Definition: ipv6-address.h:356
bool IsLinkLocalMulticast() const
If the IPv6 address is link-local multicast (ff02::/16).
friend bool operator!=(Ipv6Address const &a, Ipv6Address const &b)
Not equal to operator.
Definition: ipv6-address.h:559
Ipv6Prefix()
Default constructor.
friend bool operator<(Ipv6Address const &a, Ipv6Address const &b)
Less than to operator.
Definition: ipv6-address.h:564
friend bool operator==(Ipv6Prefix const &a, Ipv6Prefix const &b)
Equal to operator.
Definition: ipv6-address.h:569
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).
bool IsEqual(const Ipv6Prefix &other) const
Comparison operation between two Ipv6Prefix.
static Ipv6Address GetAny()
Get the "any" (::) Ipv6Address.
static Ipv6Address MakeAutoconfiguredAddress(Mac16Address addr, Ipv6Address prefix)
Make the autoconfigured IPv6 address with Mac16Address.
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 IsDocumentation() const
If the IPv6 address is a documentation address (2001:DB8::/32).
ATTRIBUTE_HELPER_HEADER(BleAccessAddress)
friend bool operator!=(Ipv6Prefix const &a, Ipv6Prefix const &b)
Not equal to operator.
Definition: ipv6-address.h:574
bool IsAllNodesMulticast() const
If the IPv6 address is "all nodes multicast" (ff02::1/8).
static Ipv6Prefix GetZero()
Get the zero prefix ( /0).
a polymophic address class
Definition: address.h:90
an EUI-64 address
Definition: mac64-address.h:43
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 GetBytes(uint8_t buf[16]) const
Get the bytes corresponding to the address.
tuple mac
Definition: third.py:92
void Set(char const *address)
Sets an Ipv6Address by parsing the input C-string.
static Ipv6Address GetAllHostsMulticast()
Get the "all hosts multicast" address.
bool IsAllHostsMulticast() const NS_DEPRECATED
If the IPv6 address is "all hosts multicast" (ff02::3/8).
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:42
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:43
bool operator==(const BleAccessAddress &a, const BleAccessAddress &b)
uint8_t m_prefix[16]
The prefix representation.
Definition: ipv6-address.h:494
bool operator!=(const BleAccessAddress &a, const BleAccessAddress &b)
This class can contain 16 bit addresses.
Definition: mac16-address.h:41
bool operator<(const BleAccessAddress &a, const BleAccessAddress &b)
Hash function class for IPv6 addresses.
Definition: ipv6-address.h:583
static Ipv6Address MakeAutoconfiguredLinkLocalAddress(Mac16Address mac)
Make the autoconfigured link-local IPv6 address with Mac16Address.
Describes an IPv6 address.
Definition: ipv6-address.h:48
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
void Print(std::ostream &os) const
Print this address to the given output stream.
#define NS_DEPRECATED
Mark a function as deprecated.
Definition: deprecated.h:47
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).
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.
Definition: ipv6-address.h:393
Ipv4Address GetIpv4MappedAddress() const
Return the Ipv4 address.
uint8_t GetPrefixLength() const
Get prefix length.
tuple address
Definition: first.py:37
bool IsLocalhost() const
If the IPv6 address is localhost (::1).
friend bool operator==(Ipv6Address const &a, Ipv6Address const &b)
Equal to operator.
Definition: ipv6-address.h:554
static Ipv6Address MakeIpv4MappedAddress(Ipv4Address addr)
Make the Ipv4-mapped IPv6 address.
Ipv6Address CombinePrefix(Ipv6Prefix const &prefix)
Combine this address with a prefix.
bool IsIpv4MappedAddress() const
If the address is an IPv4-mapped address.
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.