A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
ipv6-address-generator.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2008 University of Washington
3
* Copyright (c) 2011 Atishay Jain
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
19
#ifndef IPV6_ADDRESS_GENERATOR_H
20
#define IPV6_ADDRESS_GENERATOR_H
21
22
#include "ns3/ipv6-address.h"
23
24
namespace
ns3
25
{
26
27
/**
28
* \ingroup address
29
* \ingroup ipv6
30
*
31
* \brief This generator assigns addresses sequentially from a provided
32
* network address; used in topology code. It also keeps track of all
33
* addresses assigned to perform duplicate detection.
34
*
35
* Global unicast IPv6 addresses based on \RFC{4291} definition:
36
*
37
* | n bits | m bits | 128-n-m bits |
38
* +-------------------------+-----------+----------------------------+
39
* | global routing prefix | subnet ID | interface ID |
40
* +-------------------------+-----------+----------------------------+
41
*
42
* In this class, the first two quantities (n + m) are what is called the
43
* 'net', and the 'prefix' defines the length in bits of (n + m).
44
*
45
* The way this is expected to be used is that, after initializing the
46
* network and interfaceId to a number, a user can call NextAddress ()
47
* repeatedly to obtain new interface IDs with the current network (for
48
* multiple addresses on the link) and can call NextNetwork () to increment
49
* the subnet ID.
50
*
51
* The interface ID is often an EUI-64 address derived from the MAC address,
52
* but can also be a pseudo-random value (\RFC{3041}). This implementation
53
* does not generate EUI-64-based interface IDs.
54
*
55
* \note BEWARE: this class acts as a Singleton.
56
* In other terms, two different instances of Ipv6AddressGenerator will
57
* pick IPv6 numbers from the same pool. Changing the network in one of them
58
* will also change the network in the other instances.
59
*
60
*/
61
class
Ipv6AddressGenerator
62
{
63
public
:
64
/**
65
* \brief Initialise the base network and interfaceId for the generator
66
*
67
* The first call to NextAddress() or GetAddress() will return the
68
* value passed in.
69
*
70
* \param net The network for the base Ipv6Address
71
* \param prefix The prefix of the base Ipv6Address
72
* \param interfaceId The base interface ID used for initialization
73
*/
74
static
void
Init
(
const
Ipv6Address
net,
75
const
Ipv6Prefix
prefix,
76
const
Ipv6Address
interfaceId =
"::1"
);
77
78
/**
79
* \brief Get the next network according to the given Ipv6Prefix
80
*
81
* This operation is a pre-increment, meaning that the internal state
82
* is changed before returning the new network address.
83
*
84
* This also resets the interface ID to the base interface ID that was
85
* used for initialization.
86
*
87
* \param prefix The Ipv6Prefix used to set the next network
88
* \returns the IPv6 address of the next network
89
*/
90
static
Ipv6Address
NextNetwork
(
const
Ipv6Prefix
prefix);
91
92
/**
93
* \brief Get the current network of the given Ipv6Prefix
94
*
95
* Does not change the internal state; this just peeks at the current
96
* network
97
*
98
* \param prefix The Ipv6Prefix for the current network
99
* \returns the IPv6 address of the current network
100
*/
101
static
Ipv6Address
GetNetwork
(
const
Ipv6Prefix
prefix);
102
103
/**
104
* \brief Set the interfaceId for the given Ipv6Prefix
105
*
106
* \param interfaceId The interfaceId to set for the current Ipv6Prefix
107
* \param prefix The Ipv6Prefix whose address is to be set
108
*/
109
static
void
InitAddress
(
const
Ipv6Address
interfaceId,
const
Ipv6Prefix
prefix);
110
111
/**
112
* \brief Allocate the next Ipv6Address for the configured network and prefix
113
*
114
* This operation is a post-increment, meaning that the first address
115
* allocated will be the one that was initially configured.
116
*
117
* \param prefix The Ipv6Prefix for the current network
118
* \returns the IPv6 address
119
*/
120
static
Ipv6Address
NextAddress
(
const
Ipv6Prefix
prefix);
121
122
/**
123
* \brief Get the Ipv6Address that will be allocated upon NextAddress ()
124
*
125
* Does not change the internal state; just is used to peek the next
126
* address that will be allocated upon NextAddress ()
127
*
128
* \param prefix The Ipv6Prefix for the current network
129
* \returns the IPv6 address
130
*/
131
static
Ipv6Address
GetAddress
(
const
Ipv6Prefix
prefix);
132
133
/**
134
* \brief Reset the networks and Ipv6Address to zero
135
*/
136
static
void
Reset
();
137
138
/**
139
* \brief Add the Ipv6Address to the list of IPv6 entries
140
*
141
* Typically, this is used by external address allocators that want
142
* to make use of this class's ability to track duplicates. AddAllocated
143
* is always called internally for any address generated by NextAddress ()
144
*
145
* \param addr The Ipv6Address to be added to the list of Ipv6 entries
146
* \returns true on success
147
*/
148
static
bool
AddAllocated
(
const
Ipv6Address
addr);
149
150
/**
151
* \brief Check the Ipv6Address allocation in the list of IPv6 entries
152
*
153
* \param addr The Ipv6Address to be checked in the list of Ipv4 entries
154
* \returns true if the address is already allocated
155
*/
156
static
bool
IsAddressAllocated
(
const
Ipv6Address
addr);
157
158
/**
159
* \brief Check if a network has already allocated addresses
160
*
161
* \param addr The Ipv6 network to be checked
162
* \param prefix The Ipv6 network prefix
163
* \returns true if the network is already allocated
164
*/
165
static
bool
IsNetworkAllocated
(
const
Ipv6Address
addr,
const
Ipv6Prefix
prefix);
166
167
/**
168
* \brief Used to turn off fatal errors and assertions, for testing
169
*/
170
static
void
TestMode
();
171
};
172
173
};
// namespace ns3
174
175
#endif
/* IPV6_ADDRESS_GENERATOR_H */
ns3::Ipv6AddressGenerator
This generator assigns addresses sequentially from a provided network address; used in topology code.
Definition:
ipv6-address-generator.h:62
ns3::Ipv6AddressGenerator::Init
static void Init(const Ipv6Address net, const Ipv6Prefix prefix, const Ipv6Address interfaceId="::1")
Initialise the base network and interfaceId for the generator.
Definition:
ipv6-address-generator.cc:672
ns3::Ipv6AddressGenerator::TestMode
static void TestMode()
Used to turn off fatal errors and assertions, for testing.
Definition:
ipv6-address-generator.cc:754
ns3::Ipv6AddressGenerator::NextAddress
static Ipv6Address NextAddress(const Ipv6Prefix prefix)
Allocate the next Ipv6Address for the configured network and prefix.
Definition:
ipv6-address-generator.cc:714
ns3::Ipv6AddressGenerator::GetNetwork
static Ipv6Address GetNetwork(const Ipv6Prefix prefix)
Get the current network of the given Ipv6Prefix.
Definition:
ipv6-address-generator.cc:690
ns3::Ipv6AddressGenerator::InitAddress
static void InitAddress(const Ipv6Address interfaceId, const Ipv6Prefix prefix)
Set the interfaceId for the given Ipv6Prefix.
Definition:
ipv6-address-generator.cc:698
ns3::Ipv6AddressGenerator::IsNetworkAllocated
static bool IsNetworkAllocated(const Ipv6Address addr, const Ipv6Prefix prefix)
Check if a network has already allocated addresses.
Definition:
ipv6-address-generator.cc:746
ns3::Ipv6AddressGenerator::AddAllocated
static bool AddAllocated(const Ipv6Address addr)
Add the Ipv6Address to the list of IPv6 entries.
Definition:
ipv6-address-generator.cc:730
ns3::Ipv6AddressGenerator::GetAddress
static Ipv6Address GetAddress(const Ipv6Prefix prefix)
Get the Ipv6Address that will be allocated upon NextAddress ()
Definition:
ipv6-address-generator.cc:706
ns3::Ipv6AddressGenerator::NextNetwork
static Ipv6Address NextNetwork(const Ipv6Prefix prefix)
Get the next network according to the given Ipv6Prefix.
Definition:
ipv6-address-generator.cc:682
ns3::Ipv6AddressGenerator::IsAddressAllocated
static bool IsAddressAllocated(const Ipv6Address addr)
Check the Ipv6Address allocation in the list of IPv6 entries.
Definition:
ipv6-address-generator.cc:738
ns3::Ipv6AddressGenerator::Reset
static void Reset()
Reset the networks and Ipv6Address to zero.
Definition:
ipv6-address-generator.cc:722
ns3::Ipv6Address
Describes an IPv6 address.
Definition:
ipv6-address.h:49
ns3::Ipv6Prefix
Describes an IPv6 prefix.
Definition:
ipv6-address.h:455
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
internet
model
ipv6-address-generator.h
Generated on Tue May 28 2024 23:35:53 for ns-3 by
1.9.6