26 /** |
26 /** |
27 * \ingroup address |
27 * \ingroup address |
28 * |
28 * |
29 * \brief This generator assigns addresses sequentially from a provided |
29 * \brief This generator assigns addresses sequentially from a provided |
30 * network address; used in topology code. |
30 * network address; used in topology code. |
|
31 * |
|
32 * \note BEWARE: this class acts as a Singleton. |
|
33 * In other terms, two different instances of Ipv4AddressGenerator will |
|
34 * pick IPv4 numbers from the same pool. Changing the network in one of them |
|
35 * will also change the network in the other instances. |
|
36 * |
31 */ |
37 */ |
32 class Ipv4AddressGenerator { |
38 class Ipv4AddressGenerator { |
33 public: |
39 public: |
|
40 /** |
|
41 * \brief Initialise the base network, mask and address for the generator |
|
42 * |
|
43 * The first call to NextAddress() or GetAddress() will return the |
|
44 * value passed in. |
|
45 * |
|
46 * \param net The network for the base Ipv4Address |
|
47 * \param mask The network mask of the base Ipv4Address |
|
48 * \param addr The base address used for initialization |
|
49 */ |
34 static void Init (const Ipv4Address net, const Ipv4Mask mask, |
50 static void Init (const Ipv4Address net, const Ipv4Mask mask, |
35 const Ipv4Address addr = "0.0.0.1"); |
51 const Ipv4Address addr = "0.0.0.1"); |
36 |
52 |
|
53 /** |
|
54 * \brief Get the next network according to the given Ipv4Mask |
|
55 * |
|
56 * This operation is a pre-increment, meaning that the internal state |
|
57 * is changed before returning the new network address. |
|
58 * |
|
59 * This also resets the address to the base address that was |
|
60 * used for initialization. |
|
61 * |
|
62 * \param mask The Ipv4Mask used to set the next network |
|
63 * \returns the IPv4 address of the next network |
|
64 */ |
37 static Ipv4Address NextNetwork (const Ipv4Mask mask); |
65 static Ipv4Address NextNetwork (const Ipv4Mask mask); |
|
66 |
|
67 /** |
|
68 * \brief Get the current network of the given Ipv4Mask |
|
69 * |
|
70 * Does not change the internal state; this just peeks at the current |
|
71 * network |
|
72 * |
|
73 * \param mask The Ipv4Mask for the current network |
|
74 * \returns the IPv4 address of the current network |
|
75 */ |
38 static Ipv4Address GetNetwork (const Ipv4Mask mask); |
76 static Ipv4Address GetNetwork (const Ipv4Mask mask); |
39 |
77 |
|
78 /** |
|
79 * \brief Set the address for the given mask |
|
80 * |
|
81 * \param addr The address to set for the current mask |
|
82 * \param mask The Ipv4Mask whose address is to be set |
|
83 */ |
40 static void InitAddress (const Ipv4Address addr, const Ipv4Mask mask); |
84 static void InitAddress (const Ipv4Address addr, const Ipv4Mask mask); |
|
85 |
|
86 /** |
|
87 * \brief Allocate the next Ipv4Address for the configured network and mask |
|
88 * |
|
89 * This operation is a post-increment, meaning that the first address |
|
90 * allocated will be the one that was initially configured. |
|
91 * |
|
92 * \param mask The Ipv4Mask for the current network |
|
93 * \returns the IPv4 address |
|
94 */ |
41 static Ipv4Address NextAddress (const Ipv4Mask mask); |
95 static Ipv4Address NextAddress (const Ipv4Mask mask); |
|
96 |
|
97 /** |
|
98 * \brief Get the Ipv4Address that will be allocated upon NextAddress () |
|
99 * |
|
100 * Does not change the internal state; just is used to peek the next |
|
101 * address that will be allocated upon NextAddress () |
|
102 * |
|
103 * \param mask The Ipv4Mask for the current network |
|
104 * \returns the IPv4 address |
|
105 */ |
42 static Ipv4Address GetAddress (const Ipv4Mask mask); |
106 static Ipv4Address GetAddress (const Ipv4Mask mask); |
43 |
107 |
|
108 /** |
|
109 * \brief Reset the networks and Ipv4Address to zero |
|
110 */ |
44 static void Reset (void); |
111 static void Reset (void); |
|
112 |
|
113 /** |
|
114 * \brief Add the Ipv4Address to the list of IPv4 entries |
|
115 * |
|
116 * Typically, this is used by external address allocators that want |
|
117 * to make use of this class's ability to track duplicates. AddAllocated |
|
118 * is always called internally for any address generated by NextAddress () |
|
119 * |
|
120 * \param addr The Ipv4Address to be added to the list of Ipv4 entries |
|
121 * \returns true on success |
|
122 */ |
45 static bool AddAllocated (const Ipv4Address addr); |
123 static bool AddAllocated (const Ipv4Address addr); |
46 |
124 |
|
125 /** |
|
126 * \brief Used to turn off fatal errors and assertions, for testing |
|
127 */ |
47 static void TestMode (void); |
128 static void TestMode (void); |
48 }; |
129 }; |
49 |
130 |
50 } // namespace ns3 |
131 } // namespace ns3 |
51 |
132 |