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