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
ipv4-address-generator.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2008 University of Washington
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*/
6
7
#ifndef IPV4_ADDRESS_GENERATOR_H
8
#define IPV4_ADDRESS_GENERATOR_H
9
10
#include "ns3/ipv4-address.h"
11
12
namespace
ns3
13
{
14
15
/**
16
* \ingroup address
17
* \ingroup ipv4
18
*
19
* \brief This generator assigns addresses sequentially from a provided
20
* network address; used in topology code.
21
*
22
* \note BEWARE: this class acts as a Singleton.
23
* In other terms, two different instances of Ipv4AddressGenerator will
24
* pick IPv4 numbers from the same pool. Changing the network in one of them
25
* will also change the network in the other instances.
26
*
27
*/
28
class
Ipv4AddressGenerator
29
{
30
public
:
31
/**
32
* \brief Initialise the base network, mask and address for the generator
33
*
34
* The first call to NextAddress() or GetAddress() will return the
35
* value passed in.
36
*
37
* \param net The network for the base Ipv4Address
38
* \param mask The network mask of the base Ipv4Address
39
* \param addr The base address used for initialization
40
*/
41
static
void
Init
(
const
Ipv4Address
net,
42
const
Ipv4Mask
mask,
43
const
Ipv4Address
addr =
"0.0.0.1"
);
44
45
/**
46
* \brief Get the next network according to the given Ipv4Mask
47
*
48
* This operation is a pre-increment, meaning that the internal state
49
* is changed before returning the new network address.
50
*
51
* This also resets the address to the base address that was
52
* used for initialization.
53
*
54
* \param mask The Ipv4Mask used to set the next network
55
* \returns the IPv4 address of the next network
56
*/
57
static
Ipv4Address
NextNetwork
(
const
Ipv4Mask
mask);
58
59
/**
60
* \brief Get the current network of the given Ipv4Mask
61
*
62
* Does not change the internal state; this just peeks at the current
63
* network
64
*
65
* \param mask The Ipv4Mask for the current network
66
* \returns the IPv4 address of the current network
67
*/
68
static
Ipv4Address
GetNetwork
(
const
Ipv4Mask
mask);
69
70
/**
71
* \brief Set the address for the given mask
72
*
73
* \param addr The address to set for the current mask
74
* \param mask The Ipv4Mask whose address is to be set
75
*/
76
static
void
InitAddress
(
const
Ipv4Address
addr,
const
Ipv4Mask
mask);
77
78
/**
79
* \brief Allocate the next Ipv4Address for the configured network and mask
80
*
81
* This operation is a post-increment, meaning that the first address
82
* allocated will be the one that was initially configured.
83
*
84
* \param mask The Ipv4Mask for the current network
85
* \returns the IPv4 address
86
*/
87
static
Ipv4Address
NextAddress
(
const
Ipv4Mask
mask);
88
89
/**
90
* \brief Get the Ipv4Address that will be allocated upon NextAddress ()
91
*
92
* Does not change the internal state; just is used to peek the next
93
* address that will be allocated upon NextAddress ()
94
*
95
* \param mask The Ipv4Mask for the current network
96
* \returns the IPv4 address
97
*/
98
static
Ipv4Address
GetAddress
(
const
Ipv4Mask
mask);
99
100
/**
101
* \brief Reset the networks and Ipv4Address to zero
102
*/
103
static
void
Reset
();
104
105
/**
106
* \brief Add the Ipv4Address to the list of IPv4 entries
107
*
108
* Typically, this is used by external address allocators that want
109
* to make use of this class's ability to track duplicates. AddAllocated
110
* is always called internally for any address generated by NextAddress ()
111
*
112
* \param addr The Ipv4Address to be added to the list of Ipv4 entries
113
* \returns true on success
114
*/
115
static
bool
AddAllocated
(
const
Ipv4Address
addr);
116
117
/**
118
* \brief Check the Ipv4Address allocation in the list of IPv4 entries
119
*
120
* \param addr The Ipv4Address to be checked in the list of Ipv4 entries
121
* \returns true if the network is already allocated
122
*/
123
static
bool
IsAddressAllocated
(
const
Ipv4Address
addr);
124
125
/**
126
* \brief Check if a network has already allocated addresses
127
*
128
* \param addr The Ipv4 network to be checked
129
* \param mask The Ipv4 network mask
130
* \returns true if the network is already allocated
131
*/
132
static
bool
IsNetworkAllocated
(
const
Ipv4Address
addr,
const
Ipv4Mask
mask);
133
134
/**
135
* \brief Used to turn off fatal errors and assertions, for testing
136
*/
137
static
void
TestMode
();
138
};
139
140
}
// namespace ns3
141
142
#endif
/* IPV4_ADDRESS_GENERATOR_H */
ns3::Ipv4AddressGenerator
This generator assigns addresses sequentially from a provided network address; used in topology code.
Definition
ipv4-address-generator.h:29
ns3::Ipv4AddressGenerator::NextAddress
static Ipv4Address NextAddress(const Ipv4Mask mask)
Allocate the next Ipv4Address for the configured network and mask.
Definition
ipv4-address-generator.cc:574
ns3::Ipv4AddressGenerator::InitAddress
static void InitAddress(const Ipv4Address addr, const Ipv4Mask mask)
Set the address for the given mask.
Definition
ipv4-address-generator.cc:558
ns3::Ipv4AddressGenerator::TestMode
static void TestMode()
Used to turn off fatal errors and assertions, for testing.
Definition
ipv4-address-generator.cc:614
ns3::Ipv4AddressGenerator::NextNetwork
static Ipv4Address NextNetwork(const Ipv4Mask mask)
Get the next network according to the given Ipv4Mask.
Definition
ipv4-address-generator.cc:542
ns3::Ipv4AddressGenerator::Reset
static void Reset()
Reset the networks and Ipv4Address to zero.
Definition
ipv4-address-generator.cc:582
ns3::Ipv4AddressGenerator::AddAllocated
static bool AddAllocated(const Ipv4Address addr)
Add the Ipv4Address to the list of IPv4 entries.
Definition
ipv4-address-generator.cc:590
ns3::Ipv4AddressGenerator::IsAddressAllocated
static bool IsAddressAllocated(const Ipv4Address addr)
Check the Ipv4Address allocation in the list of IPv4 entries.
Definition
ipv4-address-generator.cc:598
ns3::Ipv4AddressGenerator::GetNetwork
static Ipv4Address GetNetwork(const Ipv4Mask mask)
Get the current network of the given Ipv4Mask.
Definition
ipv4-address-generator.cc:550
ns3::Ipv4AddressGenerator::Init
static void Init(const Ipv4Address net, const Ipv4Mask mask, const Ipv4Address addr="0.0.0.1")
Initialise the base network, mask and address for the generator.
Definition
ipv4-address-generator.cc:534
ns3::Ipv4AddressGenerator::IsNetworkAllocated
static bool IsNetworkAllocated(const Ipv4Address addr, const Ipv4Mask mask)
Check if a network has already allocated addresses.
Definition
ipv4-address-generator.cc:606
ns3::Ipv4AddressGenerator::GetAddress
static Ipv4Address GetAddress(const Ipv4Mask mask)
Get the Ipv4Address that will be allocated upon NextAddress ()
Definition
ipv4-address-generator.cc:566
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition
ipv4-address.h:31
ns3::Ipv4Mask
a class to represent an Ipv4 address mask
Definition
ipv4-address.h:246
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
internet
model
ipv4-address-generator.h
Generated on Fri Nov 8 2024 13:59:01 for ns-3 by
1.11.0