A Discrete-Event Network Simulator
API
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/deprecated.h"
28#include "ns3/ipv4-address.h"
29
30#include <cstring>
31#include <ostream>
32#include <stdint.h>
33
34namespace ns3
35{
36
37class Ipv6Prefix;
38class Mac16Address;
39class Mac48Address;
40class Mac64Address;
41
50{
51 public:
56
61 Ipv6Address(const char* address);
62
68 Ipv6Address(uint8_t address[16]);
69
74 Ipv6Address(const Ipv6Address& addr);
75
80 Ipv6Address(const Ipv6Address* addr);
81
86
91 void Set(const char* 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(const Ipv6Prefix& prefix) const;
314
321 Ipv6Address CombinePrefix(const Ipv6Prefix& 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() 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() const;
407
412 static uint8_t GetType();
413
417 uint8_t m_address[16];
419
427 friend bool operator==(const Ipv6Address& a, const Ipv6Address& b);
428
436 friend bool operator!=(const Ipv6Address& a, const Ipv6Address& b);
437
445 friend bool operator<(const Ipv6Address& a, const Ipv6Address& b);
446};
447
456{
457 public:
461 Ipv6Prefix();
462
471 Ipv6Prefix(uint8_t prefix[16]);
472
481 Ipv6Prefix(const char* prefix);
482
488 Ipv6Prefix(uint8_t prefix[16], uint8_t prefixLength);
489
495 Ipv6Prefix(const char* prefix, uint8_t prefixLength);
496
502 Ipv6Prefix(uint8_t prefix);
503
508 Ipv6Prefix(const Ipv6Prefix& prefix);
509
514 Ipv6Prefix(const Ipv6Prefix* 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
558 uint8_t GetMinimumPrefixLength() const;
559
566 void Print(std::ostream& os) const;
567
572 static Ipv6Prefix GetLoopback();
573
578 static Ipv6Prefix GetOnes();
579
584 static Ipv6Prefix GetZero();
585
586 private:
590 uint8_t m_prefix[16];
591
596
604 friend bool operator==(const Ipv6Prefix& a, const Ipv6Prefix& b);
605
613 friend bool operator!=(const Ipv6Prefix& a, const Ipv6Prefix& b);
614};
615
618
626std::ostream& operator<<(std::ostream& os, const Ipv6Address& address);
627
635std::ostream& operator<<(std::ostream& os, const Ipv6Prefix& prefix);
636
644std::istream& operator>>(std::istream& is, Ipv6Address& address);
645
653std::istream& operator>>(std::istream& is, Ipv6Prefix& prefix);
654
655inline bool
657{
658 return (!std::memcmp(a.m_address, b.m_address, 16));
659}
660
661inline bool
663{
664 return std::memcmp(a.m_address, b.m_address, 16);
665}
666
667inline bool
668operator<(const Ipv6Address& a, const Ipv6Address& b)
669{
670 return (std::memcmp(a.m_address, b.m_address, 16) < 0);
671}
672
673inline bool
675{
676 return (!std::memcmp(a.m_prefix, b.m_prefix, 16));
677}
678
679inline bool
681{
682 return std::memcmp(a.m_prefix, b.m_prefix, 16);
683}
684
690{
691 public:
697 size_t operator()(const Ipv6Address& x) const;
698};
699
700} /* namespace ns3 */
701
702#endif /* IPV6_ADDRESS_H */
a polymophic address class
Definition: address.h:92
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:43
Hash function class for IPv6 addresses.
Definition: ipv6-address.h:690
size_t operator()(const Ipv6Address &x) const
Returns the hash of an IPv6 address.
Describes an IPv6 address.
Definition: ipv6-address.h:50
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:662
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:656
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:668
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:418
uint8_t m_address[16]
The address representation on 128 bits (16 bytes).
Definition: ipv6-address.h:417
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:456
uint8_t m_prefixLength
The prefix length.
Definition: ipv6-address.h:595
static Ipv6Prefix GetLoopback()
Get the loopback prefix ( /128).
~Ipv6Prefix()
Destructor.
uint8_t m_prefix[16]
The prefix representation.
Definition: ipv6-address.h:590
friend bool operator==(const Ipv6Prefix &a, const Ipv6Prefix &b)
Equal to operator.
Definition: ipv6-address.h:674
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:680
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
address
Definition: first.py:40
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:665
bool operator==(const EventId &a, const EventId &b)
Definition: event-id.h:157
ATTRIBUTE_HELPER_HEADER(ValueClassTest)
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
mac
Definition: third.py:85