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 
106  void Serialize (uint8_t buf[16]) const;
107 
113  static Ipv6Address Deserialize (const uint8_t buf[16]);
114 
121 
128 
134 
145 
157 
168 
179 
187 
198 
208 
218 
228 
235 
245 
252  void Print (std::ostream& os) const;
253 
258  bool IsLocalhost () const;
259 
264  bool IsMulticast () const;
265 
270  bool IsLinkLocalMulticast () const;
271 
276  bool IsAllNodesMulticast () const;
277 
282  bool IsAllRoutersMulticast () const;
283 
288  bool IsLinkLocal () const;
289 
294  bool IsSolicitedMulticast () const;
295 
300  bool IsAny () const;
301 
306  bool IsDocumentation () const;
307 
313  bool HasPrefix (Ipv6Prefix const& prefix) const;
314 
321  Ipv6Address CombinePrefix (Ipv6Prefix const & prefix) const;
322 
328  static bool IsMatchingType (const Address& address);
329 
334  bool IsIpv4MappedAddress() const;
335 
339  operator Address () const;
340 
346  static Ipv6Address ConvertFrom (const Address& address);
347 
351  bool IsInitialized (void) const;
352 
357  static Ipv6Address GetZero ();
358 
363  static Ipv6Address GetAny ();
364 
370 
376 
382 
387  static Ipv6Address GetLoopback ();
388 
393  static Ipv6Address GetOnes ();
394 
399  void GetBytes (uint8_t buf[16]) const;
400 
401 private:
406  Address ConvertTo (void) const;
407 
412  static uint8_t GetType (void);
413 
417  uint8_t m_address[16];
419 
427  friend bool operator == (Ipv6Address const &a, Ipv6Address const &b);
428 
436  friend bool operator != (Ipv6Address const &a, Ipv6Address const &b);
437 
445  friend bool operator < (Ipv6Address const &a, Ipv6Address const &b);
446 };
447 
456 {
457 public:
461  Ipv6Prefix ();
462 
471  Ipv6Prefix (uint8_t prefix[16]);
472 
481  Ipv6Prefix (char const* prefix);
482 
488  Ipv6Prefix (uint8_t prefix[16], uint8_t prefixLength);
489 
495  Ipv6Prefix (char const* prefix, uint8_t prefixLength);
496 
502  Ipv6Prefix (uint8_t prefix);
503 
508  Ipv6Prefix (Ipv6Prefix const& prefix);
509 
514  Ipv6Prefix (Ipv6Prefix const* prefix);
515 
519  ~Ipv6Prefix ();
520 
527  bool IsMatch (Ipv6Address a, Ipv6Address b) const;
528 
533  void GetBytes (uint8_t buf[16]) const;
534 
540 
545  uint8_t GetPrefixLength () const;
546 
551  void SetPrefixLength (uint8_t prefixLength);
552 
557  uint8_t GetMinimumPrefixLength () const;
558 
565  void Print (std::ostream &os) const;
566 
571  static Ipv6Prefix GetLoopback ();
572 
577  static Ipv6Prefix GetOnes ();
578 
583  static Ipv6Prefix GetZero ();
584 
585 private:
589  uint8_t m_prefix[16];
590 
594  uint8_t m_prefixLength;
595 
603  friend bool operator == (Ipv6Prefix const &a, Ipv6Prefix const &b);
604 
612  friend bool operator != (Ipv6Prefix const &a, Ipv6Prefix const &b);
613 };
614 
617 
625 std::ostream & operator << (std::ostream& os, Ipv6Address const& address);
626 
634 std::ostream & operator << (std::ostream& os, Ipv6Prefix const& prefix);
635 
643 std::istream & operator >> (std::istream &is, Ipv6Address &address);
644 
652 std::istream & operator >> (std::istream &is, Ipv6Prefix &prefix);
653 
654 inline bool operator == (const Ipv6Address& a, const Ipv6Address& b)
655 {
656  return (!std::memcmp (a.m_address, b.m_address, 16));
657 }
658 
659 inline bool operator != (const Ipv6Address& a, const Ipv6Address& b)
660 {
661  return std::memcmp (a.m_address, b.m_address, 16);
662 }
663 
664 inline bool operator < (const Ipv6Address& a, const Ipv6Address& b)
665 {
666  return (std::memcmp (a.m_address, b.m_address, 16) < 0);
667 }
668 
669 inline bool operator == (const Ipv6Prefix& a, const Ipv6Prefix& b)
670 {
671  return (!std::memcmp (a.m_prefix, b.m_prefix, 16));
672 }
673 
674 inline bool operator != (const Ipv6Prefix& a, const Ipv6Prefix& b)
675 {
676  return std::memcmp (a.m_prefix, b.m_prefix, 16);
677 }
678 
684 {
685 public:
691  size_t operator () (Ipv6Address const &x) const;
692 };
693 
694 } /* namespace ns3 */
695 
696 #endif /* IPV6_ADDRESS_H */
697 
ns3::Ipv6Address::IsLocalhost
bool IsLocalhost() const
If the IPv6 address is localhost (::1).
Definition: ipv6-address.cc:707
ns3::Ipv6Prefix::IsMatch
bool IsMatch(Ipv6Address a, Ipv6Address b) const
If the Address match the type.
Definition: ipv6-address.cc:1045
ns3::Ipv6Address::Deserialize
static Ipv6Address Deserialize(const uint8_t buf[16])
Deserialize this address.
Definition: ipv6-address.cc:344
ns3::Ipv6Address::operator!=
friend bool operator!=(Ipv6Address const &a, Ipv6Address const &b)
Not equal to operator.
Definition: ipv6-address.h:659
ns3::Ipv6Address::Set
void Set(char const *address)
Sets an Ipv6Address by parsing the input C-string.
Definition: ipv6-address.cc:323
ns3::Ipv6Prefix::operator!=
friend bool operator!=(Ipv6Prefix const &a, Ipv6Prefix const &b)
Not equal to operator.
Definition: ipv6-address.h:674
ns3::Ipv6Address::IsMatchingType
static bool IsMatchingType(const Address &address)
If the Address matches the type.
Definition: ipv6-address.cc:827
ns3::Mac8Address
A class used for addressing MAC8 MAC's.
Definition: mac8-address.h:43
ns3::Ipv6Prefix::GetMinimumPrefixLength
uint8_t GetMinimumPrefixLength() const
Get the minimum prefix length, i.e., 128 - the length of the largest sequence trailing zeroes.
Definition: ipv6-address.cc:1121
ns3::Ipv6Address::IsIpv4MappedAddress
bool IsIpv4MappedAddress() const
If the address is an IPv4-mapped address.
Definition: ipv6-address.cc:734
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::Ipv6Address::MakeSolicitedAddress
static Ipv6Address MakeSolicitedAddress(Ipv6Address addr)
Make the solicited IPv6 address.
Definition: ipv6-address.cc:590
ns3::Ipv6Prefix::GetBytes
void GetBytes(uint8_t buf[16]) const
Get the bytes corresponding to the prefix.
Definition: ipv6-address.cc:1094
ns3::Ipv6Prefix::GetOnes
static Ipv6Prefix GetOnes()
Get the "all-1" IPv6 mask (ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff).
Definition: ipv6-address.cc:1080
ns3::Mac16Address
This class can contain 16 bit addresses.
Definition: mac16-address.h:42
ns3::operator<
bool operator<(const EventId &a, const EventId &b)
Definition: event-id.h:160
ns3::Ipv6Address::m_address
uint8_t m_address[16]
The address representation on 128 bits (16 bytes).
Definition: ipv6-address.h:417
ns3::Ipv6Address::GetAllHostsMulticast
static Ipv6Address GetAllHostsMulticast()
Get the "all hosts multicast" address.
Definition: ipv6-address.cc:876
ns3::Ipv6Address::~Ipv6Address
~Ipv6Address()
Destructor.
Definition: ipv6-address.cc:317
ns3::Ipv6Address::IsInitialized
bool IsInitialized(void) const
Definition: ipv6-address.cc:928
ns3::Ipv6Address::IsAllNodesMulticast
bool IsAllNodesMulticast() const
If the IPv6 address is "all nodes multicast" (ff02::1/8).
Definition: ipv6-address.cc:778
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
ns3::Ipv6Address
Describes an IPv6 address.
Definition: ipv6-address.h:50
ns3::Mac48Address
an EUI-48 address
Definition: mac48-address.h:44
ns3::Ipv6Address::GetBytes
void GetBytes(uint8_t buf[16]) const
Get the bytes corresponding to the address.
Definition: ipv6-address.cc:911
third.mac
mac
Definition: third.py:99
ns3::Ipv6Address::GetLoopback
static Ipv6Address GetLoopback()
Get the loopback address.
Definition: ipv6-address.cc:883
ns3::Mac64Address
an EUI-64 address
Definition: mac64-address.h:44
ns3::Ipv6Address::HasPrefix
bool HasPrefix(Ipv6Prefix const &prefix) const
Compares an address and a prefix.
Definition: ipv6-address.cc:816
ns3::Ipv6Address::Serialize
void Serialize(uint8_t buf[16]) const
Serialize this address to a 16-byte buffer.
Definition: ipv6-address.cc:338
ns3::Ipv6Prefix::Print
void Print(std::ostream &os) const
Print this address to the given output stream.
Definition: ipv6-address.cc:1066
ns3::Ipv6Prefix::SetPrefixLength
void SetPrefixLength(uint8_t prefixLength)
Set prefix length.
Definition: ipv6-address.cc:1115
ns3::Ipv6Address::IsSolicitedMulticast
bool IsSolicitedMulticast() const
If the IPv6 address is a Solicited multicast address.
Definition: ipv6-address.cc:766
ns3::Ipv6Address::IsLinkLocal
bool IsLinkLocal() const
If the IPv6 address is a link-local address (fe80::/64).
Definition: ipv6-address.cc:917
ns3::Ipv6Address::CombinePrefix
Ipv6Address CombinePrefix(Ipv6Prefix const &prefix) const
Combine this address with a prefix.
Definition: ipv6-address.cc:746
ns3::Ipv6Address::operator==
friend bool operator==(Ipv6Address const &a, Ipv6Address const &b)
Equal to operator.
Definition: ipv6-address.h:654
mac8-address.h
ns3::Address
a polymophic address class
Definition: address.h:91
ns3::Ipv6Prefix::operator==
friend bool operator==(Ipv6Prefix const &a, Ipv6Prefix const &b)
Equal to operator.
Definition: ipv6-address.h:669
ns3::Ipv6Address::GetIpv4MappedAddress
Ipv4Address GetIpv4MappedAddress() const
Return the Ipv4 address.
Definition: ipv6-address.cc:361
ns3::Ipv6Address::ConvertFrom
static Ipv6Address ConvertFrom(const Address &address)
Convert the Address object into an Ipv6Address ones.
Definition: ipv6-address.cc:846
ns3::Ipv6Address::Print
void Print(std::ostream &os) const
Print this address to the given output stream.
Definition: ipv6-address.cc:612
ns3::Ipv6Prefix::~Ipv6Prefix
~Ipv6Prefix()
Destructor.
Definition: ipv6-address.cc:1039
ns3::Ipv6Prefix::GetZero
static Ipv6Prefix GetZero()
Get the zero prefix ( /0).
Definition: ipv6-address.cc:1087
first.address
address
Definition: first.py:44
ns3::operator==
bool operator==(const EventId &a, const EventId &b)
Definition: event-id.h:142
ns3::Ipv6Prefix::m_prefix
uint8_t m_prefix[16]
The prefix representation.
Definition: ipv6-address.h:589
ns3::Ipv6Prefix::ConvertToIpv6Address
Ipv6Address ConvertToIpv6Address() const
Convert the Prefix into an IPv6 Address.
Definition: ipv6-address.cc:1100
ns3::Ipv6Address::GetZero
static Ipv6Address GetZero()
Get the 0 (::) Ipv6Address.
Definition: ipv6-address.cc:890
ns3::Ipv6Address::m_initialized
bool m_initialized
IPv6 address has been explicitly initialized to a valid value.
Definition: ipv6-address.h:418
ns3::Ipv6Address::IsLinkLocalMulticast
bool IsLinkLocalMulticast() const
If the IPv6 address is link-local multicast (ff02::/16).
Definition: ipv6-address.cc:724
ns3::Ipv6Prefix::m_prefixLength
uint8_t m_prefixLength
The prefix length.
Definition: ipv6-address.h:594
ns3::Ipv6Address::MakeAutoconfiguredAddress
static Ipv6Address MakeAutoconfiguredAddress(Address addr, Ipv6Address prefix)
Make the autoconfigured IPv6 address from a Mac address.
Definition: ipv6-address.cc:372
ns3::Ipv6Address::IsMulticast
bool IsMulticast() const
If the IPv6 address is multicast (ff00::/8).
Definition: ipv6-address.cc:714
ns3::Ipv6Address::MakeAutoconfiguredLinkLocalAddress
static Ipv6Address MakeAutoconfiguredLinkLocalAddress(Address mac)
Make the autoconfigured link-local IPv6 address from a Mac address.
Definition: ipv6-address.cc:481
ns3::Ipv6Address::GetAllNodesMulticast
static Ipv6Address GetAllNodesMulticast()
Get the "all nodes multicast" address.
Definition: ipv6-address.cc:862
ns3::Ipv6Prefix::Ipv6Prefix
Ipv6Prefix()
Default constructor.
Definition: ipv6-address.cc:948
ns3::Ipv6AddressHash
Hash function class for IPv6 addresses.
Definition: ipv6-address.h:684
ns3::Ipv6Prefix::GetPrefixLength
uint8_t GetPrefixLength() const
Get prefix length.
Definition: ipv6-address.cc:1109
ns3::Ipv6Address::GetAny
static Ipv6Address GetAny()
Get the "any" (::) Ipv6Address.
Definition: ipv6-address.cc:897
ns3::Ipv6Address::operator<
friend bool operator<(Ipv6Address const &a, Ipv6Address const &b)
Less than to operator.
Definition: ipv6-address.h:664
sample-rng-plot.x
list x
Definition: sample-rng-plot.py:34
ns3::operator!=
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
ns3::Ipv6Address::GetOnes
static Ipv6Address GetOnes()
Get the "all-1" IPv6 address (ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff).
Definition: ipv6-address.cc:904
ns3::Ipv6Prefix::GetLoopback
static Ipv6Prefix GetLoopback()
Get the loopback prefix ( /128).
Definition: ipv6-address.cc:1073
ns3::Ipv6Address::ConvertTo
Address ConvertTo(void) const
convert the IPv6Address object to an Address object.
Definition: ipv6-address.cc:838
ns3::Ipv6Address::MakeIpv4MappedAddress
static Ipv6Address MakeIpv4MappedAddress(Ipv4Address addr)
Make the Ipv4-mapped IPv6 address.
Definition: ipv6-address.cc:352
ns3::Ipv6Address::IsAny
bool IsAny() const
If the IPv6 address is the "Any" address.
Definition: ipv6-address.cc:797
ns3::operator<<
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:137
ns3::Ipv6Address::IsDocumentation
bool IsDocumentation() const
If the IPv6 address is a documentation address (2001:DB8::/32).
Definition: ipv6-address.cc:805
ns3::Ipv6Prefix
Describes an IPv6 prefix.
Definition: ipv6-address.h:456
ns3::Ipv6Address::GetType
static uint8_t GetType(void)
Return the Type of address.
Definition: ipv6-address.cc:855
ns3::Ipv6Address::GetAllRoutersMulticast
static Ipv6Address GetAllRoutersMulticast()
Get the "all routers multicast" address.
Definition: ipv6-address.cc:869
ns3::Ipv6Address::IsAllRoutersMulticast
bool IsAllRoutersMulticast() const
If the IPv6 address is "all routers multicast" (ff02::2/8).
Definition: ipv6-address.cc:787
ns3::Ipv6Address::Ipv6Address
Ipv6Address()
Default constructor.
Definition: ipv6-address.cc:281
ATTRIBUTE_HELPER_HEADER
#define ATTRIBUTE_HELPER_HEADER(type)
Declare the attribute value, accessor and checkers for class type
Definition: attribute-helper.h:390
ns3::Ipv6AddressHash::operator()
size_t operator()(Ipv6Address const &x) const
Returns the hash of an IPv6 address.
Definition: ipv6-address.cc:1163
ns3::operator>>
std::istream & operator>>(std::istream &is, Angles &a)
Definition: angles.cc:160