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

A helper class to make life easier while doing simple IPv4 address assignment in scripts. More...

#include "ipv4-address-helper.h"

+ Collaboration diagram for ns3::Ipv4AddressHelper:

Public Member Functions

 Ipv4AddressHelper ()
 Construct a helper class to make life easier while doing simple IPv4 address assignment in scripts. More...
 
 Ipv4AddressHelper (Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
 Construct a helper class to make life easier while doing simple IPv4 address assignment in scripts. More...
 
Ipv4InterfaceContainer Assign (const NetDeviceContainer &c)
 Assign IP addresses to the net devices specified in the container based on the current network prefix and address base. More...
 
Ipv4Address NewAddress ()
 Increment the IP address counter used to allocate IP addresses. More...
 
Ipv4Address NewNetwork ()
 Increment the network number and reset the IP address counter to the base value provided in the SetBase method. More...
 
void SetBase (Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
 Set the base network number, network mask and base address. More...
 

Private Member Functions

uint32_t NumAddressBits (uint32_t maskbits) const
 Returns the number of address bits (hostpart) for a given netmask. More...
 

Private Attributes

uint32_t m_address
 address More...
 
uint32_t m_base
 base address More...
 
uint32_t m_mask
 network mask More...
 
uint32_t m_max
 maximum allowed address More...
 
uint32_t m_network
 network address More...
 
uint32_t m_shift
 shift, equivalent to the number of bits in the hostpart More...
 

Detailed Description

A helper class to make life easier while doing simple IPv4 address assignment in scripts.

This class is a very simple IPv4 address generator. You can think of it as a simple local number incrementer. It has no notion that IP addresses are part of a global address space. If you have a complicated address assignment situation you may want to look at the Ipv4AddressGenerator which does recognize that IP address and network number generation is part of a global problem. Ipv4AddressHelper is a simple class to make simple problems easy to handle.

We do call into the global address generator to make sure that there are no duplicate addresses generated.

See also
Ipv4AddressGenerator

Definition at line 48 of file ipv4-address-helper.h.

Constructor & Destructor Documentation

◆ Ipv4AddressHelper() [1/2]

ns3::Ipv4AddressHelper::Ipv4AddressHelper ( )

Construct a helper class to make life easier while doing simple IPv4 address assignment in scripts.

Definition at line 38 of file ipv4-address-helper.cc.

References m_address, m_base, m_mask, m_max, m_network, m_shift, and NS_LOG_FUNCTION_NOARGS.

◆ Ipv4AddressHelper() [2/2]

ns3::Ipv4AddressHelper::Ipv4AddressHelper ( Ipv4Address  network,
Ipv4Mask  mask,
Ipv4Address  base = "0.0.0.1" 
)

Construct a helper class to make life easier while doing simple IPv4 address assignment in scripts.

This version sets the base and mask in the constructor

Parameters
networkthe network part
maskthe address mask
basethe host part to start from

Definition at line 55 of file ipv4-address-helper.cc.

References first::address, NS_LOG_FUNCTION_NOARGS, and SetBase().

+ Here is the call graph for this function:

Member Function Documentation

◆ Assign()

Ipv4InterfaceContainer ns3::Ipv4AddressHelper::Assign ( const NetDeviceContainer c)

Assign IP addresses to the net devices specified in the container based on the current network prefix and address base.

The address helper allocates IP addresses based on a given network number and initial IP address. In order to separate the network number and IP address parts, SetBase was given an initial value and a network mask. The one bits of this mask define the prefix category from which the helper will allocate new network numbers. An initial value for the network numbers was provided in the base parameter of the SetBase method in the bits corresponding to positions in the mask that were 1. An initial value for the IP address counter was also provided in the base parameter in the bits corresponding to positions in the mask that were 0.

This method gets new addresses for each net device in the container. For each net device in the container, the helper finds the associated node and looks up the Ipv4 interface corresponding to the net device. It then sets the Ipv4Address and mask in the interface to the appropriate values. If the addresses overflow the number of bits allocated for them by the network mask in the SetBase method, the system will NS_ASSERT and halt.

Parameters
cThe NetDeviceContainer holding the collection of net devices we are asked to assign Ipv4 addresses to.
Returns
A container holding the added NetDevices
See also
SetBase
NewNetwork

Definition at line 132 of file ipv4-address-helper.cc.

References ns3::Ipv4InterfaceContainer::Add(), ns3::TrafficControlHelper::Default(), ns3::NetDeviceContainer::Get(), ns3::NetDeviceContainer::GetN(), ns3::Object::GetObject(), ns3::TrafficControlHelper::Install(), nsclick-simple-lan::ipv4, m_mask, NewAddress(), NS_ASSERT_MSG, NS_LOG_FUNCTION_NOARGS, and NS_LOG_LOGIC.

Referenced by ns3::EmuEpcHelper::EmuEpcHelper(), ns3::NoBackhaulEpcHelper::NoBackhaulEpcHelper(), ns3::EmuEpcHelper::AddEnb(), ns3::PointToPointEpcHelper::AddEnb(), ns3::NoBackhaulEpcHelper::AddX2Interface(), ns3::PointToPointDumbbellHelper::AssignIpv4Addresses(), ns3::PointToPointGridHelper::AssignIpv4Addresses(), ns3::NoBackhaulEpcHelper::AssignUeIpv4Address(), ns3::olsr::Bug780Test::CreateNodes(), ThreeGppHttpObjectTestCase::CreateSimpleInternetNode(), Ipv4DeduplicationTest::DoRun(), Ipv4DeduplicationPerformanceTest::DoRun(), EpcS1uDlTestCase::DoRun(), EpcS1uUlTestCase::DoRun(), LteCellSelectionTestCase::DoRun(), LenaCqaFfMacSchedulerTestCase1::DoRun(), LenaCqaFfMacSchedulerTestCase2::DoRun(), ns3::LenaDeactivateBearerTestCase::DoRun(), LenaFdTbfqFfMacSchedulerTestCase1::DoRun(), LenaFdTbfqFfMacSchedulerTestCase2::DoRun(), LteDistributedFfrAreaTestCase::DoRun(), LenaPssFfMacSchedulerTestCase1::DoRun(), LenaPssFfMacSchedulerTestCase2::DoRun(), LteRadioLinkFailureTestCase::DoRun(), LenaTdTbfqFfMacSchedulerTestCase1::DoRun(), LenaTdTbfqFfMacSchedulerTestCase2::DoRun(), LteUeMeasurementsHandoverTestCase::DoRun(), LteEpcE2eDataTestCase::DoRun(), LteHandoverTargetTestCase::DoRun(), LteX2HandoverMeasuresTestCase::DoRun(), LteX2HandoverTestCase::DoRun(), NixVectorRoutingTest::DoRun(), CsmaMulticastTestCase::DoRun(), CsmaPingTestCase::DoRun(), CsmaRawIpSocketTestCase::DoRun(), PingTestCase::DoSetup(), and RoutingExperiment::Run().

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

◆ NewAddress()

Ipv4Address ns3::Ipv4AddressHelper::NewAddress ( )

Increment the IP address counter used to allocate IP addresses.

The address helper allocates IP addresses based on a given network number and initial IP address. In order to separate the network number and IP address parts, SetBase was given an initial network number value, a network mask and an initial address base.

This method increments IP address counter. A check is made to ensure that the address returned will not overflow the number of bits allocated to IP addresses in SetBase (the number of address bits is defined by the number of mask bits that are not '1').

For example, if the network number was set to 192.168.0.0 with a mask of 255.255.255.0 and a base address of 0.0.0.3 in SetBase, the next call to NewAddress will return 192.168.1.3. The NewAddress method has post-increment semantics. A following NewAddress would return 192.168.0.4, etc., until the 253rd call which would assert due to an address overflow.

Returns
The value of the newly allocated IP address.
See also
SetBase
NewNetwork

Definition at line 100 of file ipv4-address-helper.cc.

References ns3::Ipv4AddressGenerator::AddAllocated(), m_address, m_max, m_network, m_shift, and NS_ASSERT_MSG.

Referenced by Assign(), NetworkAllocatorHelperTestCase::DoRun(), AddressAllocatorHelperTestCase::DoRun(), ResetAllocatorHelperTestCase::DoRun(), and IpAddressHelperTestCasev4::DoRun().

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

◆ NewNetwork()

Ipv4Address ns3::Ipv4AddressHelper::NewNetwork ( )

Increment the network number and reset the IP address counter to the base value provided in the SetBase method.

The address helper allocates IP addresses based on a given network number and initial IP address. In order to separate the network number and IP address parts, SetBase was given an initial network number value, a network mask and an initial address base.

This method increments the network number and resets the IP address counter to the last base value used. For example, if the network number was set to 192.168.0.0 with a mask of 255.255.255.0 and a base address of 0.0.0.3 in the SetBase call; a call to NewNetwork will increment the network number counter resulting in network numbers incrementing as 192.168.1.0, 192.168.2.0, etc. After each network number increment, the IP address counter is reset to the initial value specified in SetBase. In this case, that would be 0.0.0.3. so if you were to call NewAddress after the increment that resulted in a network number of 192.168.2.0, the allocated addresses returned by NewAddress would be 192.168.2.3, 192.168.2.4, etc.

Returns
The value of the incremented network number that will be used in following address allocations.
See also
SetBase
NewAddress

Definition at line 123 of file ipv4-address-helper.cc.

References m_address, m_base, m_network, m_shift, and NS_LOG_FUNCTION_NOARGS.

Referenced by ns3::NoBackhaulEpcHelper::NoBackhaulEpcHelper(), ns3::PointToPointEpcHelper::AddEnb(), ns3::NoBackhaulEpcHelper::AddX2Interface(), ns3::PointToPointDumbbellHelper::AssignIpv4Addresses(), ns3::PointToPointGridHelper::AssignIpv4Addresses(), NetworkAllocatorHelperTestCase::DoRun(), ResetAllocatorHelperTestCase::DoRun(), and IpAddressHelperTestCasev4::DoRun().

+ Here is the caller graph for this function:

◆ NumAddressBits()

uint32_t ns3::Ipv4AddressHelper::NumAddressBits ( uint32_t  maskbits) const
private

Returns the number of address bits (hostpart) for a given netmask.

Parameters
maskbitsthe netmask
Returns
the number of bits in the hostpart

Definition at line 193 of file ipv4-address-helper.cc.

References ns3::N_BITS, NS_ASSERT_MSG, NS_LOG_FUNCTION_NOARGS, and NS_LOG_LOGIC.

Referenced by SetBase().

+ Here is the caller graph for this function:

◆ SetBase()

void ns3::Ipv4AddressHelper::SetBase ( Ipv4Address  network,
Ipv4Mask  mask,
Ipv4Address  base = "0.0.0.1" 
)

Set the base network number, network mask and base address.

The address helper allocates IP addresses based on a given network number and mask combination along with an initial IP address.

For example, if you want to use a /24 prefix with an initial network number of 192.168.1 (corresponding to a mask of 255.255.255.0) and you want to start allocating IP addresses out of that network beginning at 192.168.1.3, you would call

SetBase ("192.168.1.0", "255.255.255.0", "0.0.0.3");

If you don't care about the initial address it defaults to "0.0.0.1" in which case you can simply use,

SetBase ("192.168.1.0", "255.255.255.0");

and the first address generated will be 192.168.1.1.

Parameters
networkThe Ipv4Address containing the initial network number to use during allocation. The bits outside the network mask are not used.
maskThe Ipv4Mask containing one bits in each bit position of the network number.
baseAn optional Ipv4Address containing the initial address used for IP address allocation. Will be combined (ORed) with the network number to generate the first IP address. Defaults to 0.0.0.1.

Definition at line 64 of file ipv4-address-helper.cc.

References first::address, ns3::Ipv4Address::Get(), ns3::Ipv4Mask::Get(), m_address, m_base, m_mask, m_max, m_network, m_shift, NS_ASSERT_MSG, NS_LOG_FUNCTION_NOARGS, NS_LOG_LOGIC, and NumAddressBits().

Referenced by ns3::EmuEpcHelper::EmuEpcHelper(), Ipv4AddressHelper(), ns3::NoBackhaulEpcHelper::NoBackhaulEpcHelper(), ns3::PointToPointEpcHelper::PointToPointEpcHelper(), ThreeGppHttpObjectTestCase::ThreeGppHttpObjectTestCase(), ns3::olsr::Bug780Test::CreateNodes(), NetworkAllocatorHelperTestCase::DoRun(), AddressAllocatorHelperTestCase::DoRun(), ResetAllocatorHelperTestCase::DoRun(), IpAddressHelperTestCasev4::DoRun(), Ipv4DeduplicationTest::DoRun(), Ipv4DeduplicationPerformanceTest::DoRun(), EpcS1uDlTestCase::DoRun(), EpcS1uUlTestCase::DoRun(), LteCellSelectionTestCase::DoRun(), LenaCqaFfMacSchedulerTestCase1::DoRun(), LenaCqaFfMacSchedulerTestCase2::DoRun(), ns3::LenaDeactivateBearerTestCase::DoRun(), LenaFdTbfqFfMacSchedulerTestCase1::DoRun(), LenaFdTbfqFfMacSchedulerTestCase2::DoRun(), LteDistributedFfrAreaTestCase::DoRun(), LenaPssFfMacSchedulerTestCase1::DoRun(), LenaPssFfMacSchedulerTestCase2::DoRun(), LteRadioLinkFailureTestCase::DoRun(), LenaTdTbfqFfMacSchedulerTestCase1::DoRun(), LenaTdTbfqFfMacSchedulerTestCase2::DoRun(), LteUeMeasurementsHandoverTestCase::DoRun(), LteEpcE2eDataTestCase::DoRun(), LteHandoverTargetTestCase::DoRun(), LteX2HandoverMeasuresTestCase::DoRun(), LteX2HandoverTestCase::DoRun(), NixVectorRoutingTest::DoRun(), CsmaMulticastTestCase::DoRun(), CsmaPingTestCase::DoRun(), CsmaRawIpSocketTestCase::DoRun(), PingTestCase::DoSetup(), LteAggregationThroughputScaleTestCase::GetThroughput(), and RoutingExperiment::Run().

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

Member Data Documentation

◆ m_address

uint32_t ns3::Ipv4AddressHelper::m_address
private

address

Definition at line 191 of file ipv4-address-helper.h.

Referenced by Ipv4AddressHelper(), NewAddress(), NewNetwork(), and SetBase().

◆ m_base

uint32_t ns3::Ipv4AddressHelper::m_base
private

base address

Definition at line 192 of file ipv4-address-helper.h.

Referenced by Ipv4AddressHelper(), NewNetwork(), and SetBase().

◆ m_mask

uint32_t ns3::Ipv4AddressHelper::m_mask
private

network mask

Definition at line 190 of file ipv4-address-helper.h.

Referenced by Ipv4AddressHelper(), Assign(), and SetBase().

◆ m_max

uint32_t ns3::Ipv4AddressHelper::m_max
private

maximum allowed address

Definition at line 194 of file ipv4-address-helper.h.

Referenced by Ipv4AddressHelper(), NewAddress(), and SetBase().

◆ m_network

uint32_t ns3::Ipv4AddressHelper::m_network
private

network address

Definition at line 189 of file ipv4-address-helper.h.

Referenced by Ipv4AddressHelper(), NewAddress(), NewNetwork(), and SetBase().

◆ m_shift

uint32_t ns3::Ipv4AddressHelper::m_shift
private

shift, equivalent to the number of bits in the hostpart

Definition at line 193 of file ipv4-address-helper.h.

Referenced by Ipv4AddressHelper(), NewAddress(), NewNetwork(), and SetBase().


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