A Discrete-Event Network Simulator
API
Classes | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
ns3::Ipv4AddressGeneratorImpl Class Reference

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

Constructor & Destructor Documentation

◆ Ipv4AddressGeneratorImpl()

ns3::Ipv4AddressGeneratorImpl::Ipv4AddressGeneratorImpl ( )

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

References NS_LOG_FUNCTION, and Reset().

◆ ~Ipv4AddressGeneratorImpl()

ns3::Ipv4AddressGeneratorImpl::~Ipv4AddressGeneratorImpl ( )
virtual

Definition at line 236 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

Referenced by NextAddress().

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

References m_netTable, MaskToIndex(), and NS_LOG_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

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

References ns3::Ipv4AddressGeneratorImpl::NetworkState::addr, ns3::Ipv4Address::Get(), ns3::Ipv4Mask::Get(), m_netTable, ns3::maskBits, MaskToIndex(), ns3::Ipv4AddressGeneratorImpl::NetworkState::network, NS_ABORT_MSG_UNLESS, NS_LOG_FUNCTION, and ns3::Ipv4AddressGeneratorImpl::NetworkState::shift.

◆ 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

◆ 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 450 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

◆ 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

Referenced by GetAddress(), Init(), and NextAddress().

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

References AddAllocated(), ns3::Ipv4AddressGeneratorImpl::NetworkState::addr, m_netTable, MaskToIndex(), NS_ABORT_MSG_UNLESS, and NS_LOG_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

◆ Reset()

void ns3::Ipv4AddressGeneratorImpl::Reset ( void  )

◆ TestMode()

void ns3::Ipv4AddressGeneratorImpl::TestMode ( void  )

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

Member Data Documentation

◆ m_entries

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

contained of allocated addresses

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

Referenced by IsAddressAllocated(), and Reset().

◆ m_netTable

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

the available networks

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

Referenced by GetAddress(), Init(), NextAddress(), and Reset().

◆ m_test

bool ns3::Ipv4AddressGeneratorImpl::m_test
private

test mode (if true)

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

Referenced by Reset().

◆ MOST_SIGNIFICANT_BIT

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

MSB set to 1.

Definition at line 152 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 151 of file ipv4-address-generator.cc.

Referenced by Reset().


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