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

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 28 of file ipv4-address-generator.h.

Member Function Documentation

◆ AddAllocated()

bool ns3::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 590 of file ipv4-address-generator.cc.

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

Referenced by AddressCollisionTestCase::DoRun(), and ns3::Ipv4AddressHelper::NewAddress().

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

◆ GetAddress()

Ipv4Address ns3::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 566 of file ipv4-address-generator.cc.

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

+ Here is the call graph for this function:

◆ GetNetwork()

Ipv4Address ns3::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 550 of file ipv4-address-generator.cc.

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

Referenced by NetworkNumberAllocatorTestCase::DoRun().

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

◆ Init()

void ns3::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 534 of file ipv4-address-generator.cc.

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

Referenced by AddressAllocatorTestCase::DoRun(), ExampleAddressGeneratorTestCase::DoRun(), NetworkAndAddressTestCase::DoRun(), and NetworkNumberAllocatorTestCase::DoRun().

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

◆ InitAddress()

void ns3::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 558 of file ipv4-address-generator.cc.

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

Referenced by ExampleAddressGeneratorTestCase::DoRun().

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

◆ IsAddressAllocated()

bool ns3::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 598 of file ipv4-address-generator.cc.

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

Referenced by AddressCollisionTestCase::DoRun().

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

◆ IsNetworkAllocated()

bool ns3::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 606 of file ipv4-address-generator.cc.

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

+ Here is the call graph for this function:

◆ NextAddress()

Ipv4Address ns3::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 574 of file ipv4-address-generator.cc.

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

Referenced by AddressAllocatorTestCase::DoRun(), ExampleAddressGeneratorTestCase::DoRun(), and NetworkAndAddressTestCase::DoRun().

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

◆ NextNetwork()

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

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

Referenced by ExampleAddressGeneratorTestCase::DoRun(), NetworkAndAddressTestCase::DoRun(), and NetworkNumberAllocatorTestCase::DoRun().

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

◆ Reset()

void ns3::Ipv4AddressGenerator::Reset ( )
static

Reset the networks and Ipv4Address to zero.

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

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

Referenced by AddressAllocatorHelperTestCase::DoTeardown(), AddressAllocatorTestCase::DoTeardown(), AddressCollisionTestCase::DoTeardown(), ExampleAddressGeneratorTestCase::DoTeardown(), IpAddressHelperTestCasev4::DoTeardown(), NetworkAllocatorHelperTestCase::DoTeardown(), NetworkAndAddressTestCase::DoTeardown(), NetworkNumberAllocatorTestCase::DoTeardown(), and ResetAllocatorHelperTestCase::DoTeardown().

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

◆ TestMode()

void ns3::Ipv4AddressGenerator::TestMode ( )
static

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

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

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

Referenced by AddressCollisionTestCase::DoRun().

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

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