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