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 
33 namespace ns3 {
34 
35 class Ipv6Prefix;
36 class Mac16Address;
37 class Mac48Address;
38 class Mac64Address;
39 
47 {
48 public:
52  Ipv6Address ();
53 
58  Ipv6Address (char const* address);
59 
65  Ipv6Address (uint8_t address[16]);
66 
71  Ipv6Address (Ipv6Address const & addr);
72 
77  Ipv6Address (Ipv6Address const* addr);
78 
82  ~Ipv6Address ();
83 
88  void Set (char const* address);
89 
96  void Set (uint8_t address[16]);
97 
104  bool IsEqual (const Ipv6Address& other) const;
105 
111  void Serialize (uint8_t buf[16]) const;
112 
118  static Ipv6Address Deserialize (const uint8_t buf[16]);
119 
126 
133 
139 
147 
155 
163 
170 
177 
184 
191  void Print (std::ostream& os) const;
192 
197  bool IsLocalhost () const;
198 
203  bool IsMulticast () const;
204 
209  bool IsLinkLocalMulticast () const;
210 
215  bool IsAllNodesMulticast () const;
216 
221  bool IsAllRoutersMulticast () const;
222 
227  bool IsAllHostsMulticast () const;
228 
233  bool IsLinkLocal () const;
234 
239  bool IsSolicitedMulticast () const;
240 
245  bool IsAny () const;
246 
251  bool IsDocumentation () const;
252 
259  Ipv6Address CombinePrefix (Ipv6Prefix const & prefix);
260 
266  static bool IsMatchingType (const Address& address);
267 
272  bool IsIpv4MappedAddress() const;
273 
277  operator Address () const;
278 
284  static Ipv6Address ConvertFrom (const Address& address);
285 
290  static Ipv6Address GetZero ();
291 
296  static Ipv6Address GetAny ();
297 
303 
309 
315 
320  static Ipv6Address GetLoopback ();
321 
326  static Ipv6Address GetOnes ();
327 
333  void GetBytes (uint8_t buf[16]) const;
334 
335 private:
340  Address ConvertTo (void) const;
341 
346  static uint8_t GetType (void);
347 
351  uint8_t m_address[16];
352 
360  friend bool operator == (Ipv6Address const &a, Ipv6Address const &b);
361 
369  friend bool operator != (Ipv6Address const &a, Ipv6Address const &b);
370 
378  friend bool operator < (Ipv6Address const &a, Ipv6Address const &b);
379 };
380 
388 {
389 public:
393  Ipv6Prefix ();
394 
399  Ipv6Prefix (uint8_t prefix[16]);
400 
405  Ipv6Prefix (char const* prefix);
406 
412  Ipv6Prefix (uint8_t prefix);
413 
418  Ipv6Prefix (Ipv6Prefix const& prefix);
419 
424  Ipv6Prefix (Ipv6Prefix const* prefix);
425 
429  ~Ipv6Prefix ();
430 
437  bool IsMatch (Ipv6Address a, Ipv6Address b) const;
438 
443  void GetBytes (uint8_t buf[16]) const;
444 
449  uint8_t GetPrefixLength () const;
450 
456  bool IsEqual (const Ipv6Prefix& other) const;
457 
464  void Print (std::ostream &os) const;
465 
470  static Ipv6Prefix GetLoopback ();
471 
476  static Ipv6Prefix GetOnes ();
477 
482  static Ipv6Prefix GetZero ();
483 
484 private:
488  uint8_t m_prefix[16];
489 
497  friend bool operator == (Ipv6Prefix const &a, Ipv6Prefix const &b);
498 
506  friend bool operator != (Ipv6Prefix const &a, Ipv6Prefix const &b);
507 };
508 
514 
520 
528 std::ostream & operator << (std::ostream& os, Ipv6Address const& address);
529 
537 std::ostream & operator << (std::ostream& os, Ipv6Prefix const& prefix);
538 
546 std::istream & operator >> (std::istream &is, Ipv6Address &address);
547 
555 std::istream & operator >> (std::istream &is, Ipv6Prefix &prefix);
556 
557 inline bool operator == (const Ipv6Address& a, const Ipv6Address& b)
558 {
559  return (!std::memcmp (a.m_address, b.m_address, 16));
560 }
561 
562 inline bool operator != (const Ipv6Address& a, const Ipv6Address& b)
563 {
564  return std::memcmp (a.m_address, b.m_address, 16);
565 }
566 
567 inline bool operator < (const Ipv6Address& a, const Ipv6Address& b)
568 {
569  return (std::memcmp (a.m_address, b.m_address, 16) < 0);
570 }
571 
572 inline bool operator == (const Ipv6Prefix& a, const Ipv6Prefix& b)
573 {
574  return (!std::memcmp (a.m_prefix, b.m_prefix, 16));
575 }
576 
577 inline bool operator != (const Ipv6Prefix& a, const Ipv6Prefix& b)
578 {
579  return std::memcmp (a.m_prefix, b.m_prefix, 16);
580 }
581 
586 class Ipv6AddressHash : public std::unary_function<Ipv6Address, size_t>
587 {
588 public:
594  size_t operator () (Ipv6Address const &x) const;
595 };
596 
597 } /* namespace ns3 */
598 
599 #endif /* IPV6_ADDRESS_H */
600 
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.
ATTRIBUTE_HELPER_HEADER(ObjectFactory)
static Ipv6Address GetLoopback()
Get the loopback address.
std::istream & operator>>(std::istream &is, Angles &a)
initialize a struct Angles from input
Definition: angles.cc:49
Ipv6Address()
Default constructor.
uint8_t m_address[16]
The address representation on 128 bits (16 bytes).
Definition: ipv6-address.h:351
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:562
Ipv6Prefix()
Default constructor.
friend bool operator<(Ipv6Address const &a, Ipv6Address const &b)
Less than to operator.
Definition: ipv6-address.h:567
friend bool operator==(Ipv6Prefix const &a, Ipv6Prefix const &b)
Equal to operator.
Definition: ipv6-address.h:572
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).
bool IsAllHostsMulticast() const
If the IPv6 address is "all hosts multicast" (ff02::3/8).
friend bool operator!=(Ipv6Prefix const &a, Ipv6Prefix const &b)
Not equal to operator.
Definition: ipv6-address.h:577
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:86
an EUI-64 address
Definition: mac64-address.h:41
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.
bool operator<(const int64x64_t &lhs, const int64x64_t &rhs)
Less than operator.
Definition: int64x64-128.h:327
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)
print a struct Angles to output
Definition: angles.cc:43
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:1217
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:488
This class can contain 16 bit addresses.
Definition: mac16-address.h:39
Hash function class for IPv6 addresses.
Definition: ipv6-address.h:586
static Ipv6Address MakeAutoconfiguredLinkLocalAddress(Mac16Address mac)
Make the autoconfigured link-local IPv6 address with Mac16Address.
Describes an IPv6 address.
Definition: ipv6-address.h:46
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).
void GetBytes(uint8_t buf[16]) const
Get the bytes corresponding to the prefix.
bool operator==(const EventId &a, const EventId &b)
Definition: event-id.cc:89
~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:387
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:557
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.