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

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

#include "ipv4-address-generator.h"

Static Public Member Functions

static bool AddAllocated (const Ipv4Address addr)
 Add the Ipv4Address to the list of IPv4 entries. More...
 
static Ipv4Address GetAddress (const Ipv4Mask mask)
 Get the Ipv4Address that will be allocated upon NextAddress () More...
 
static Ipv4Address GetNetwork (const Ipv4Mask mask)
 Get the current network of the given Ipv4Mask. More...
 
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. More...
 
static void InitAddress (const Ipv4Address addr, const Ipv4Mask mask)
 Set the address for the given mask. More...
 
static bool IsAddressAllocated (const Ipv4Address addr)
 Check the Ipv4Address allocation in the list of IPv4 entries. More...
 
static bool IsNetworkAllocated (const Ipv4Address addr, const Ipv4Mask mask)
 Check if a network has already allocated addresses. More...
 
static Ipv4Address NextAddress (const Ipv4Mask mask)
 Allocate the next Ipv4Address for the configured network and mask. More...
 
static Ipv4Address NextNetwork (const Ipv4Mask mask)
 Get the next network according to the given Ipv4Mask. More...
 
static void Reset (void)
 Reset the networks and Ipv4Address to zero. More...
 
static void TestMode (void)
 Used to turn off fatal errors and assertions, for testing. More...
 

Detailed Description

This generator assigns addresses sequentially from a provided network address; used in topology code.

Note
BEWARE: this class acts as a Singleton. In other terms, two different instances of Ipv4AddressGenerator will pick IPv4 numbers from the same pool. Changing the network in one of them will also change the network in the other instances.

Definition at line 39 of file ipv4-address-generator.h.

Member Function Documentation

◆ AddAllocated()

bool Ipv4AddressGenerator::AddAllocated ( const Ipv4Address  addr)
static

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

References ns3::SimulationSingleton< T >::Get(), and NS_LOG_FUNCTION_NOARGS.

Referenced by ns3::Ipv4AddressHelper::NewAddress().

◆ GetAddress()

Ipv4Address Ipv4AddressGenerator::GetAddress ( const Ipv4Mask  mask)
static

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

References ns3::SimulationSingleton< T >::Get(), and NS_LOG_FUNCTION_NOARGS.

◆ GetNetwork()

Ipv4Address Ipv4AddressGenerator::GetNetwork ( const Ipv4Mask  mask)
static

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

References ns3::SimulationSingleton< T >::Get(), and NS_LOG_FUNCTION_NOARGS.

◆ Init()

void Ipv4AddressGenerator::Init ( const Ipv4Address  net,
const Ipv4Mask  mask,
const Ipv4Address  addr = "0.0.0.1" 
)
static

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

References ns3::SimulationSingleton< T >::Get(), and NS_LOG_FUNCTION_NOARGS.

◆ InitAddress()

void Ipv4AddressGenerator::InitAddress ( const Ipv4Address  addr,
const Ipv4Mask  mask 
)
static

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

References ns3::SimulationSingleton< T >::Get(), and NS_LOG_FUNCTION_NOARGS.

◆ IsAddressAllocated()

bool Ipv4AddressGenerator::IsAddressAllocated ( const Ipv4Address  addr)
static

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 network is already allocated

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

References ns3::SimulationSingleton< T >::Get(), and NS_LOG_FUNCTION_NOARGS.

◆ IsNetworkAllocated()

bool Ipv4AddressGenerator::IsNetworkAllocated ( const Ipv4Address  addr,
const Ipv4Mask  mask 
)
static

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

References ns3::SimulationSingleton< T >::Get(), and NS_LOG_FUNCTION_NOARGS.

◆ NextAddress()

Ipv4Address Ipv4AddressGenerator::NextAddress ( const Ipv4Mask  mask)
static

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

References ns3::SimulationSingleton< T >::Get(), and NS_LOG_FUNCTION_NOARGS.

◆ NextNetwork()

Ipv4Address Ipv4AddressGenerator::NextNetwork ( const Ipv4Mask  mask)
static

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

References ns3::SimulationSingleton< T >::Get(), and NS_LOG_FUNCTION_NOARGS.

◆ Reset()

void Ipv4AddressGenerator::Reset ( void  )
static

Reset the networks and Ipv4Address to zero.

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

References ns3::SimulationSingleton< T >::Get(), and NS_LOG_FUNCTION_NOARGS.

◆ TestMode()

void Ipv4AddressGenerator::TestMode ( void  )
static

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

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

References ns3::SimulationSingleton< T >::Get(), and NS_LOG_FUNCTION_NOARGS.


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