Implementation class of Ipv4AddressGenerator This generator assigns addresses sequentially from a provided network address; used in topology code. More...
Classes | |
class | Entry |
This class holds the allocated addresses. More... | |
class | NetworkState |
This class holds the state for a given network. More... | |
Public Member Functions | |
Ipv4AddressGeneratorImpl () | |
virtual | ~Ipv4AddressGeneratorImpl () |
bool | AddAllocated (const Ipv4Address addr) |
Add the Ipv4Address to the list of IPv4 entries. More... | |
Ipv4Address | GetAddress (const Ipv4Mask mask) const |
Get the Ipv4Address that will be allocated upon NextAddress () More... | |
Ipv4Address | GetNetwork (const Ipv4Mask mask) const |
Get the current network of the given Ipv4Mask. More... | |
void | Init (const Ipv4Address net, const Ipv4Mask mask, const Ipv4Address addr) |
Initialise the base network, mask and address for the generator. More... | |
void | InitAddress (const Ipv4Address addr, const Ipv4Mask mask) |
Set the address for the given mask. More... | |
bool | IsAddressAllocated (const Ipv4Address addr) |
Check the Ipv4Address allocation in the list of IPv4 entries. More... | |
bool | IsNetworkAllocated (const Ipv4Address addr, const Ipv4Mask mask) |
Check if a network has already allocated addresses. More... | |
Ipv4Address | NextAddress (const Ipv4Mask mask) |
Allocate the next Ipv4Address for the configured network and mask. More... | |
Ipv4Address | NextNetwork (const Ipv4Mask mask) |
Get the next network according to the given Ipv4Mask. More... | |
void | Reset (void) |
Reset the networks and Ipv4Address to zero. More... | |
void | TestMode (void) |
Used to turn off fatal errors and assertions, for testing. More... | |
Private Member Functions | |
uint32_t | MaskToIndex (Ipv4Mask mask) const |
Create an index number for the network mask. More... | |
Private Attributes | |
std::list< Entry > | m_entries |
contained of allocated addresses More... | |
NetworkState | m_netTable [N_BITS] |
the available networks More... | |
bool | m_test |
test mode (if true) More... | |
Static Private Attributes | |
static const uint32_t | MOST_SIGNIFICANT_BIT = 0x80000000 |
MSB set to 1. More... | |
static const uint32_t | N_BITS = 32 |
the number of bits in the address More... | |
Implementation class of Ipv4AddressGenerator This generator assigns addresses sequentially from a provided network address; used in topology code.
It also keeps track of all addresses assigned to perform duplicate detection.
Definition at line 38 of file ipv4-address-generator.cc.
ns3::Ipv4AddressGeneratorImpl::Ipv4AddressGeneratorImpl | ( | ) |
Definition at line 190 of file ipv4-address-generator.cc.
References NS_LOG_FUNCTION, and Reset().
|
virtual |
Definition at line 236 of file ipv4-address-generator.cc.
References NS_LOG_FUNCTION.
bool ns3::Ipv4AddressGeneratorImpl::AddAllocated | ( | const Ipv4Address | addr | ) |
Add the Ipv4Address to the list of IPv4 entries.
Typically, this is used by external address allocators that want to make use of this class's ability to track duplicates. AddAllocated is always called internally for any address generated by NextAddress ()
addr | The Ipv4Address to be added to the list of Ipv4 entries |
Definition at line 362 of file ipv4-address-generator.cc.
References first::address, ns3::Ipv4AddressGeneratorImpl::Entry::addrHigh, ns3::Ipv4AddressGeneratorImpl::Entry::addrLow, m_entries, m_test, NS_ABORT_MSG_UNLESS, NS_FATAL_ERROR, NS_LOG_FUNCTION, and NS_LOG_LOGIC.
Referenced by NextAddress().
Ipv4Address ns3::Ipv4AddressGeneratorImpl::GetAddress | ( | const Ipv4Mask | mask | ) | const |
Get the Ipv4Address that will be allocated upon NextAddress ()
Does not change the internal state; just is used to peek the next address that will be allocated upon NextAddress ()
mask | The Ipv4Mask for the current network |
Definition at line 320 of file ipv4-address-generator.cc.
References m_netTable, MaskToIndex(), and NS_LOG_FUNCTION.
Ipv4Address ns3::Ipv4AddressGeneratorImpl::GetNetwork | ( | const Ipv4Mask | mask | ) | const |
Get the current network of the given Ipv4Mask.
Does not change the internal state; this just peeks at the current network
mask | The Ipv4Mask for the current network |
Definition at line 277 of file ipv4-address-generator.cc.
References m_netTable, MaskToIndex(), and NS_LOG_FUNCTION.
void ns3::Ipv4AddressGeneratorImpl::Init | ( | const Ipv4Address | net, |
const Ipv4Mask | mask, | ||
const Ipv4Address | addr | ||
) |
Initialise the base network, mask and address for the generator.
The first call to NextAddress() or GetAddress() will return the value passed in.
net | The network for the base Ipv4Address |
mask | The network mask of the base Ipv4Address |
addr | The base address used for initialization |
Definition at line 242 of file ipv4-address-generator.cc.
References ns3::Ipv4AddressGeneratorImpl::NetworkState::addr, ns3::Ipv4Address::Get(), ns3::Ipv4Mask::Get(), m_netTable, MaskToIndex(), ns3::Ipv4AddressGeneratorImpl::NetworkState::network, NS_ABORT_MSG_UNLESS, NS_LOG_FUNCTION, and ns3::Ipv4AddressGeneratorImpl::NetworkState::shift.
void ns3::Ipv4AddressGeneratorImpl::InitAddress | ( | const Ipv4Address | addr, |
const Ipv4Mask | mask | ||
) |
Set the address for the given mask.
addr | The address to set for the current mask |
mask | The Ipv4Mask whose address is to be set |
Definition at line 306 of file ipv4-address-generator.cc.
References ns3::Ipv4AddressGeneratorImpl::NetworkState::addr, ns3::Ipv4Address::Get(), m_netTable, MaskToIndex(), NS_ABORT_MSG_UNLESS, and NS_LOG_FUNCTION.
bool ns3::Ipv4AddressGeneratorImpl::IsAddressAllocated | ( | const Ipv4Address | addr | ) |
Check the Ipv4Address allocation in the list of IPv4 entries.
addr | The Ipv4Address to be checked in the list of Ipv4 entries |
Definition at line 450 of file ipv4-address-generator.cc.
References first::address, m_entries, NS_ABORT_MSG_UNLESS, NS_LOG_FUNCTION, and NS_LOG_LOGIC.
bool ns3::Ipv4AddressGeneratorImpl::IsNetworkAllocated | ( | const Ipv4Address | addr, |
const Ipv4Mask | mask | ||
) |
Check if a network has already allocated addresses.
Definition at line 474 of file ipv4-address-generator.cc.
References first::address, ns3::Ipv4Address::CombineMask(), m_entries, NS_ABORT_MSG_UNLESS, NS_LOG_FUNCTION, and NS_LOG_LOGIC.
|
private |
Create an index number for the network mask.
mask | the mask to index |
Definition at line 509 of file ipv4-address-generator.cc.
References ns3::Ipv4Mask::Get(), N_BITS, NS_ABORT_MSG_UNLESS, NS_ASSERT_MSG, and NS_LOG_FUNCTION.
Referenced by GetAddress(), GetNetwork(), Init(), InitAddress(), NextAddress(), and NextNetwork().
Ipv4Address ns3::Ipv4AddressGeneratorImpl::NextAddress | ( | const Ipv4Mask | mask | ) |
Allocate the next Ipv4Address for the configured network and mask.
This operation is a post-increment, meaning that the first address allocated will be the one that was initially configured.
mask | The Ipv4Mask for the current network |
Definition at line 333 of file ipv4-address-generator.cc.
References AddAllocated(), ns3::Ipv4AddressGeneratorImpl::NetworkState::addr, m_netTable, MaskToIndex(), NS_ABORT_MSG_UNLESS, and NS_LOG_FUNCTION.
Ipv4Address ns3::Ipv4AddressGeneratorImpl::NextNetwork | ( | const Ipv4Mask | mask | ) |
Get the next network according to the given Ipv4Mask.
This operation is a pre-increment, meaning that the internal state is changed before returning the new network address.
This also resets the address to the base address that was used for initialization.
mask | The Ipv4Mask used to set the next network |
Definition at line 287 of file ipv4-address-generator.cc.
References m_netTable, MaskToIndex(), ns3::Ipv4AddressGeneratorImpl::NetworkState::network, and NS_LOG_FUNCTION.
void ns3::Ipv4AddressGeneratorImpl::Reset | ( | void | ) |
Reset the networks and Ipv4Address to zero.
Definition at line 198 of file ipv4-address-generator.cc.
References ns3::Ipv4AddressGeneratorImpl::NetworkState::addr, ns3::Ipv4AddressGeneratorImpl::NetworkState::addrMax, m_entries, m_netTable, m_test, ns3::Ipv4AddressGeneratorImpl::NetworkState::mask, MOST_SIGNIFICANT_BIT, N_BITS, ns3::Ipv4AddressGeneratorImpl::NetworkState::network, NS_LOG_FUNCTION, and ns3::Ipv4AddressGeneratorImpl::NetworkState::shift.
Referenced by Ipv4AddressGeneratorImpl().
void ns3::Ipv4AddressGeneratorImpl::TestMode | ( | void | ) |
Used to turn off fatal errors and assertions, for testing.
Definition at line 502 of file ipv4-address-generator.cc.
References m_test, and NS_LOG_FUNCTION.
contained of allocated addresses
Definition at line 186 of file ipv4-address-generator.cc.
Referenced by AddAllocated(), IsAddressAllocated(), IsNetworkAllocated(), and Reset().
|
private |
the available networks
Definition at line 174 of file ipv4-address-generator.cc.
Referenced by GetAddress(), GetNetwork(), Init(), InitAddress(), NextAddress(), NextNetwork(), and Reset().
|
private |
test mode (if true)
Definition at line 187 of file ipv4-address-generator.cc.
Referenced by AddAllocated(), Reset(), and TestMode().
|
staticprivate |
|
staticprivate |
the number of bits in the address
Definition at line 151 of file ipv4-address-generator.cc.
Referenced by MaskToIndex(), and Reset().