A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ipv6-address.h
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 Mac48Address;
37 
45 {
46 public:
50  Ipv6Address ();
51 
56  Ipv6Address (char const* address);
57 
63  Ipv6Address (uint8_t address[16]);
64 
69  Ipv6Address (Ipv6Address const & addr);
70 
75  Ipv6Address (Ipv6Address const* addr);
76 
80  ~Ipv6Address ();
81 
86  void Set (char const* address);
87 
94  void Set (uint8_t address[16]);
95 
102  bool IsEqual (const Ipv6Address& other) const;
103 
109  void Serialize (uint8_t buf[16]) const;
110 
116  static Ipv6Address Deserialize (const uint8_t buf[16]);
117 
124 
131 
137 
145 
152 
159  void Print (std::ostream& os) const;
160 
165  bool IsLocalhost () const;
166 
171  bool IsMulticast () const;
172 
177  bool IsLinkLocalMulticast () const;
178 
183  bool IsAllNodesMulticast () const;
184 
189  bool IsAllRoutersMulticast () const;
190 
195  bool IsAllHostsMulticast () const;
196 
201  bool IsLinkLocal () const;
202 
207  bool IsSolicitedMulticast () const;
208 
213  bool IsAny () const;
214 
221  Ipv6Address CombinePrefix (Ipv6Prefix const & prefix);
222 
228  static bool IsMatchingType (const Address& address);
229 
234  bool IsIpv4MappedAddress();
235 
239  operator Address () const;
240 
246  static Ipv6Address ConvertFrom (const Address& address);
247 
252  static Ipv6Address GetZero ();
253 
258  static Ipv6Address GetAny ();
259 
265 
271 
277 
282  static Ipv6Address GetLoopback ();
283 
288  static Ipv6Address GetOnes ();
289 
295  void GetBytes (uint8_t buf[16]) const;
296 
297 private:
302  Address ConvertTo (void) const;
303 
308  static uint8_t GetType (void);
309 
313  uint8_t m_address[16];
314 
315  friend bool operator == (Ipv6Address const &a, Ipv6Address const &b);
316  friend bool operator != (Ipv6Address const &a, Ipv6Address const &b);
317  friend bool operator < (Ipv6Address const &a, Ipv6Address const &b);
318 };
319 
327 {
328 public:
332  Ipv6Prefix ();
333 
338  Ipv6Prefix (uint8_t prefix[16]);
339 
344  Ipv6Prefix (char const* prefix);
345 
351  Ipv6Prefix (uint8_t prefix);
352 
357  Ipv6Prefix (Ipv6Prefix const& prefix);
358 
363  Ipv6Prefix (Ipv6Prefix const* prefix);
364 
368  ~Ipv6Prefix ();
369 
376  bool IsMatch (Ipv6Address a, Ipv6Address b) const;
377 
382  void GetBytes (uint8_t buf[16]) const;
383 
388  uint8_t GetPrefixLength () const;
389 
395  bool IsEqual (const Ipv6Prefix& other) const;
396 
403  void Print (std::ostream &os) const;
404 
409  static Ipv6Prefix GetLoopback ();
410 
415  static Ipv6Prefix GetOnes ();
416 
421  static Ipv6Prefix GetZero ();
422 
423 private:
427  uint8_t m_prefix[16];
428 };
429 
435 
441 
442 std::ostream& operator << (std::ostream& os, Ipv6Address const& address);
443 std::ostream& operator<< (std::ostream& os, Ipv6Prefix const& prefix);
444 std::istream & operator >> (std::istream &is, Ipv6Address &address);
445 std::istream & operator >> (std::istream &is, Ipv6Prefix &prefix);
446 
447 inline bool operator == (const Ipv6Address& a, const Ipv6Address& b)
448 {
449  return (!std::memcmp (a.m_address, b.m_address, 16));
450 }
451 
452 inline bool operator != (const Ipv6Address& a, const Ipv6Address& b)
453 {
454  return std::memcmp (a.m_address, b.m_address, 16);
455 }
456 
457 inline bool operator < (const Ipv6Address& a, const Ipv6Address& b)
458 {
459  return (std::memcmp (a.m_address, b.m_address, 16) < 0);
460 }
461 
466 class Ipv6AddressHash : public std::unary_function<Ipv6Address, size_t>
467 {
468 public:
473  size_t operator () (Ipv6Address const &x) const;
474 };
475 
476 bool operator == (Ipv6Prefix const &a, Ipv6Prefix const &b);
477 bool operator != (Ipv6Prefix const &a, Ipv6Prefix const &b);
478 
479 } /* namespace ns3 */
480 
481 #endif /* IPV6_ADDRESS_H */
482 
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)
Definition: angles.cc:49
static Ipv6Address MakeAutoconfiguredAddress(Mac48Address addr, Ipv6Address prefix)
Make the autoconfigured IPv6 address with Mac48Address.
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).
bool IsEqual(const Ipv6Prefix &other) const
Comparison operation between two Ipv6Prefix.
static Ipv6Address GetAny()
Get the "any" (::) Ipv6Address.
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).
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
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.
void Set(char const *address)
Sets an Ipv6Address by parsing the input C-string.
static Ipv6Address GetAllHostsMulticast()
Get the "all hosts multicast" address.
#define ATTRIBUTE_HELPER_HEADER(type)
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:43
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
Hash function class for IPv6 addresses.
Definition: ipv6-address.h:466
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).
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 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.