A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ipv6-address.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007-2008 Louis Pasteur University
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
18 */
19
20#ifndef IPV6_ADDRESS_H
21#define IPV6_ADDRESS_H
22
23#include "mac8-address.h"
24
25#include "ns3/address.h"
26#include "ns3/attribute-helper.h"
27#include "ns3/ipv4-address.h"
28
29#include <cstring>
30#include <ostream>
31#include <stdint.h>
32
33namespace ns3
34{
35
36class Ipv6Prefix;
37class Mac16Address;
38class Mac48Address;
39class Mac64Address;
40
49{
50 public:
55
60 Ipv6Address(const char* address);
61
67 Ipv6Address(uint8_t address[16]);
68
73 Ipv6Address(const Ipv6Address& addr);
74
79 Ipv6Address(const Ipv6Address* addr);
80
85
90 void Set(const char* address);
91
98 void Set(uint8_t address[16]);
99
105 void Serialize(uint8_t buf[16]) const;
106
112 static Ipv6Address Deserialize(const uint8_t buf[16]);
113
120
127
133
144
156
167
178
186
197
207
217
227
234
244
251 void Print(std::ostream& os) const;
252
257 bool IsLocalhost() const;
258
263 bool IsMulticast() const;
264
269 bool IsLinkLocalMulticast() const;
270
275 bool IsAllNodesMulticast() const;
276
281 bool IsAllRoutersMulticast() const;
282
287 bool IsLinkLocal() const;
288
293 bool IsSolicitedMulticast() const;
294
299 bool IsAny() const;
300
305 bool IsDocumentation() const;
306
312 bool HasPrefix(const Ipv6Prefix& prefix) const;
313
320 Ipv6Address CombinePrefix(const Ipv6Prefix& prefix) const;
321
327 static bool IsMatchingType(const Address& address);
328
333 bool IsIpv4MappedAddress() const;
334
338 operator Address() const;
339
345 static Ipv6Address ConvertFrom(const Address& address);
346
351 Address ConvertTo() const;
352
356 bool IsInitialized() const;
357
362 static Ipv6Address GetZero();
363
368 static Ipv6Address GetAny();
369
375
381
387
392 static Ipv6Address GetLoopback();
393
398 static Ipv6Address GetOnes();
399
404 void GetBytes(uint8_t buf[16]) const;
405
406 private:
411 static uint8_t GetType();
412
416 uint8_t m_address[16];
418
426 friend bool operator==(const Ipv6Address& a, const Ipv6Address& b);
427
435 friend bool operator!=(const Ipv6Address& a, const Ipv6Address& b);
436
444 friend bool operator<(const Ipv6Address& a, const Ipv6Address& b);
445};
446
455{
456 public:
460 Ipv6Prefix();
461
470 Ipv6Prefix(uint8_t prefix[16]);
471
480 Ipv6Prefix(const char* prefix);
481
487 Ipv6Prefix(uint8_t prefix[16], uint8_t prefixLength);
488
494 Ipv6Prefix(const char* prefix, uint8_t prefixLength);
495
501 Ipv6Prefix(uint8_t prefix);
502
507 Ipv6Prefix(const Ipv6Prefix& prefix);
508
513 Ipv6Prefix(const Ipv6Prefix* prefix);
514
518 ~Ipv6Prefix();
519
526 bool IsMatch(Ipv6Address a, Ipv6Address b) const;
527
532 void GetBytes(uint8_t buf[16]) const;
533
539
544 uint8_t GetPrefixLength() const;
545
550 void SetPrefixLength(uint8_t prefixLength);
551
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
595
603 friend bool operator==(const Ipv6Prefix& a, const Ipv6Prefix& b);
604
612 friend bool operator!=(const Ipv6Prefix& a, const Ipv6Prefix& b);
613};
614
617
625std::ostream& operator<<(std::ostream& os, const Ipv6Address& address);
626
634std::ostream& operator<<(std::ostream& os, const Ipv6Prefix& prefix);
635
643std::istream& operator>>(std::istream& is, Ipv6Address& address);
644
652std::istream& operator>>(std::istream& is, Ipv6Prefix& prefix);
653
654inline bool
656{
657 return (!std::memcmp(a.m_address, b.m_address, 16));
658}
659
660inline bool
662{
663 return std::memcmp(a.m_address, b.m_address, 16);
664}
665
666inline bool
667operator<(const Ipv6Address& a, const Ipv6Address& b)
668{
669 return (std::memcmp(a.m_address, b.m_address, 16) < 0);
670}
671
672inline bool
674{
675 return (!std::memcmp(a.m_prefix, b.m_prefix, 16));
676}
677
678inline bool
680{
681 return std::memcmp(a.m_prefix, b.m_prefix, 16);
682}
683
689{
690 public:
696 size_t operator()(const Ipv6Address& x) const;
697};
698
699} /* namespace ns3 */
700
701#endif /* IPV6_ADDRESS_H */
a polymophic address class
Definition: address.h:100
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
Hash function class for IPv6 addresses.
Definition: ipv6-address.h:689
size_t operator()(const Ipv6Address &x) const
Returns the hash of an IPv6 address.
Describes an IPv6 address.
Definition: ipv6-address.h:49
static uint8_t GetType()
Return the Type of address.
bool IsLinkLocal() const
If the IPv6 address is a link-local address (fe80::/64).
friend bool operator!=(const Ipv6Address &a, const Ipv6Address &b)
Not equal to operator.
Definition: ipv6-address.h:661
bool HasPrefix(const Ipv6Prefix &prefix) const
Compares an address and a prefix.
bool IsSolicitedMulticast() const
If the IPv6 address is a Solicited multicast address.
static Ipv6Address GetAllNodesMulticast()
Get the "all nodes multicast" address.
void Print(std::ostream &os) const
Print this address to the given output stream.
static Ipv6Address MakeSolicitedAddress(Ipv6Address addr)
Make the solicited IPv6 address.
friend bool operator==(const Ipv6Address &a, const Ipv6Address &b)
Equal to operator.
Definition: ipv6-address.h:655
static Ipv6Address GetAny()
Get the "any" (::) Ipv6Address.
bool IsDocumentation() const
If the IPv6 address is a documentation address (2001:DB8::/32).
static Ipv6Address GetAllHostsMulticast()
Get the "all hosts multicast" address.
bool IsAllNodesMulticast() const
If the IPv6 address is "all nodes multicast" (ff02::1/8).
bool IsLinkLocalMulticast() const
If the IPv6 address is link-local multicast (ff02::/16).
friend bool operator<(const Ipv6Address &a, const Ipv6Address &b)
Less than to operator.
Definition: ipv6-address.h:667
static Ipv6Address Deserialize(const uint8_t buf[16])
Deserialize this address.
static Ipv6Address GetZero()
Get the 0 (::) Ipv6Address.
static Ipv6Address MakeAutoconfiguredAddress(Address addr, Ipv6Address prefix)
Make the autoconfigured IPv6 address from a Mac address.
~Ipv6Address()
Destructor.
bool IsMulticast() const
If the IPv6 address is multicast (ff00::/8).
void GetBytes(uint8_t buf[16]) const
Get the bytes corresponding to the address.
bool IsIpv4MappedAddress() const
If the address is an IPv4-mapped address.
void Set(const char *address)
Sets an Ipv6Address by parsing the input C-string.
void Serialize(uint8_t buf[16]) const
Serialize this address to a 16-byte buffer.
Ipv6Address()
Default constructor.
Address ConvertTo() const
convert the IPv6Address object to an Address object.
bool IsAny() const
If the IPv6 address is the "Any" address.
static Ipv6Address GetAllRoutersMulticast()
Get the "all routers multicast" address.
bool IsLocalhost() const
If the IPv6 address is localhost (::1).
bool m_initialized
IPv6 address has been explicitly initialized to a valid value.
Definition: ipv6-address.h:417
uint8_t m_address[16]
The address representation on 128 bits (16 bytes).
Definition: ipv6-address.h:416
static Ipv6Address ConvertFrom(const Address &address)
Convert the Address object into an Ipv6Address ones.
bool IsInitialized() const
static Ipv6Address GetOnes()
Get the "all-1" IPv6 address (ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff).
static Ipv6Address MakeAutoconfiguredLinkLocalAddress(Address mac)
Make the autoconfigured link-local IPv6 address from a Mac address.
Ipv4Address GetIpv4MappedAddress() const
Return the Ipv4 address.
static bool IsMatchingType(const Address &address)
If the Address matches the type.
static Ipv6Address MakeIpv4MappedAddress(Ipv4Address addr)
Make the Ipv4-mapped IPv6 address.
static Ipv6Address GetLoopback()
Get the loopback address.
Ipv6Address CombinePrefix(const Ipv6Prefix &prefix) const
Combine this address with a prefix.
bool IsAllRoutersMulticast() const
If the IPv6 address is "all routers multicast" (ff02::2/8).
Describes an IPv6 prefix.
Definition: ipv6-address.h:455
uint8_t m_prefixLength
The prefix length.
Definition: ipv6-address.h:594
static Ipv6Prefix GetLoopback()
Get the loopback prefix ( /128).
~Ipv6Prefix()
Destructor.
uint8_t m_prefix[16]
The prefix representation.
Definition: ipv6-address.h:589
friend bool operator==(const Ipv6Prefix &a, const Ipv6Prefix &b)
Equal to operator.
Definition: ipv6-address.h:673
void Print(std::ostream &os) const
Print this address to the given output stream.
uint8_t GetPrefixLength() const
Get prefix length.
Ipv6Address ConvertToIpv6Address() const
Convert the Prefix into an IPv6 Address.
static Ipv6Prefix GetZero()
Get the zero prefix ( /0).
bool IsMatch(Ipv6Address a, Ipv6Address b) const
If the Address match the type.
static Ipv6Prefix GetOnes()
Get the "all-1" IPv6 mask (ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff).
friend bool operator!=(const Ipv6Prefix &a, const Ipv6Prefix &b)
Not equal to operator.
Definition: ipv6-address.h:679
void SetPrefixLength(uint8_t prefixLength)
Set prefix length.
Ipv6Prefix()
Default constructor.
uint8_t GetMinimumPrefixLength() const
Get the minimum prefix length, i.e., 128 - the length of the largest sequence trailing zeroes.
void GetBytes(uint8_t buf[16]) const
Get the bytes corresponding to the prefix.
This class can contain 16 bit addresses.
Definition: mac16-address.h:44
an EUI-48 address
Definition: mac48-address.h:46
an EUI-64 address
Definition: mac64-address.h:46
A class used for addressing MAC8 MAC's.
Definition: mac8-address.h:44
#define ATTRIBUTE_HELPER_HEADER(type)
Declare the attribute value, accessor and checkers for class type
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool operator!=(Callback< R, Args... > a, Callback< R, Args... > b)
Inequality test.
Definition: callback.h:676
bool operator==(const EventId &a, const EventId &b)
Definition: event-id.h:157
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:129
std::istream & operator>>(std::istream &is, Angles &a)
Definition: angles.cc:153
bool operator<(const EventId &a, const EventId &b)
Definition: event-id.h:170