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 * 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
12namespace 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 */
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 */
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.
a class to represent an Ipv4 address mask
Every class exported by the ns3 library is enclosed in the ns3 namespace.