A Discrete-Event Network Simulator
API
ns3::Ipv4AddressGeneratorImpl Class Reference

Implementation class of Ipv4AddressGenerator This generator assigns addresses sequentially from a provided network address; used in topology code. More...

+ Collaboration diagram for ns3::Ipv4AddressGeneratorImpl:

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 ()
 Reset the networks and Ipv4Address to zero. More...
 
void TestMode ()
 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< Entrym_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...
 

Detailed Description

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 40 of file ipv4-address-generator.cc.

Constructor & Destructor Documentation

◆ Ipv4AddressGeneratorImpl()

ns3::Ipv4AddressGeneratorImpl::Ipv4AddressGeneratorImpl ( )

Definition at line 192 of file ipv4-address-generator.cc.

References NS_LOG_FUNCTION, and Reset().

+ Here is the call graph for this function:

◆ ~Ipv4AddressGeneratorImpl()

ns3::Ipv4AddressGeneratorImpl::~Ipv4AddressGeneratorImpl ( )
virtual

Definition at line 239 of file ipv4-address-generator.cc.

References NS_LOG_FUNCTION.

Member Function Documentation

◆ AddAllocated()

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 ()

Parameters
addrThe Ipv4Address to be added to the list of Ipv4 entries
Returns
true on success

Definition at line 358 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().

+ Here is the caller graph for this function:

◆ GetAddress()

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 ()

Parameters
maskThe Ipv4Mask for the current network
Returns
the IPv4 address

Definition at line 319 of file ipv4-address-generator.cc.

References m_netTable, MaskToIndex(), and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

◆ GetNetwork()

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

Parameters
maskThe Ipv4Mask for the current network
Returns
the IPv4 address of the current network

Definition at line 279 of file ipv4-address-generator.cc.

References m_netTable, MaskToIndex(), and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

◆ Init()

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.

Parameters
netThe network for the base Ipv4Address
maskThe network mask of the base Ipv4Address
addrThe base address used for initialization

Definition at line 245 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.

+ Here is the call graph for this function:

◆ InitAddress()

void ns3::Ipv4AddressGeneratorImpl::InitAddress ( const Ipv4Address  addr,
const Ipv4Mask  mask 
)

Set the address for the given mask.

Parameters
addrThe address to set for the current mask
maskThe 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.

+ Here is the call graph for this function:

◆ IsAddressAllocated()

bool ns3::Ipv4AddressGeneratorImpl::IsAddressAllocated ( const Ipv4Address  addr)

Check the Ipv4Address allocation in the list of IPv4 entries.

Parameters
addrThe Ipv4Address to be checked in the list of Ipv4 entries
Returns
true if the address is already allocated

Definition at line 452 of file ipv4-address-generator.cc.

References first::address, m_entries, NS_ABORT_MSG_UNLESS, NS_LOG_FUNCTION, and NS_LOG_LOGIC.

◆ IsNetworkAllocated()

bool ns3::Ipv4AddressGeneratorImpl::IsNetworkAllocated ( const Ipv4Address  addr,
const Ipv4Mask  mask 
)

Check if a network has already allocated addresses.

Parameters
addrThe Ipv4 network to be checked
maskThe Ipv4 network mask
Returns
true if the network is already allocated

Definition at line 477 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.

+ Here is the call graph for this function:

◆ MaskToIndex()

uint32_t ns3::Ipv4AddressGeneratorImpl::MaskToIndex ( Ipv4Mask  mask) const
private

Create an index number for the network mask.

Parameters
maskthe mask to index
Returns
an index

Definition at line 512 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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ NextAddress()

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.

Parameters
maskThe Ipv4Mask for the current network
Returns
the IPv4 address

Definition at line 330 of file ipv4-address-generator.cc.

References AddAllocated(), ns3::Ipv4AddressGeneratorImpl::NetworkState::addr, m_netTable, MaskToIndex(), NS_ABORT_MSG_UNLESS, and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

◆ NextNetwork()

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.

Parameters
maskThe Ipv4Mask used to set the next network
Returns
the IPv4 address of the next network

Definition at line 288 of file ipv4-address-generator.cc.

References m_netTable, MaskToIndex(), ns3::Ipv4AddressGeneratorImpl::NetworkState::network, and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

◆ Reset()

◆ TestMode()

void ns3::Ipv4AddressGeneratorImpl::TestMode ( )

Used to turn off fatal errors and assertions, for testing.

Definition at line 505 of file ipv4-address-generator.cc.

References m_test, and NS_LOG_FUNCTION.

Member Data Documentation

◆ m_entries

std::list<Entry> ns3::Ipv4AddressGeneratorImpl::m_entries
private

contained of allocated addresses

Definition at line 188 of file ipv4-address-generator.cc.

Referenced by AddAllocated(), IsAddressAllocated(), IsNetworkAllocated(), and Reset().

◆ m_netTable

NetworkState ns3::Ipv4AddressGeneratorImpl::m_netTable[N_BITS]
private

the available networks

Definition at line 176 of file ipv4-address-generator.cc.

Referenced by GetAddress(), GetNetwork(), Init(), InitAddress(), NextAddress(), NextNetwork(), and Reset().

◆ m_test

bool ns3::Ipv4AddressGeneratorImpl::m_test
private

test mode (if true)

Definition at line 189 of file ipv4-address-generator.cc.

Referenced by AddAllocated(), Reset(), and TestMode().

◆ MOST_SIGNIFICANT_BIT

const uint32_t ns3::Ipv4AddressGeneratorImpl::MOST_SIGNIFICANT_BIT = 0x80000000
staticprivate

MSB set to 1.

Definition at line 154 of file ipv4-address-generator.cc.

Referenced by Reset().

◆ N_BITS

const uint32_t ns3::Ipv4AddressGeneratorImpl::N_BITS = 32
staticprivate

the number of bits in the address

Definition at line 153 of file ipv4-address-generator.cc.

Referenced by MaskToIndex(), and Reset().


The documentation for this class was generated from the following file: