A helper class to make life easier while doing simple IPv4 address assignment in scripts. More...
#include "ipv4-address-helper.h"
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 (void) |
Increment the IP address counter used to allocate IP addresses. More... | |
Ipv4Address | NewNetwork (void) |
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... | |
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.
Definition at line 47 of file ipv4-address-helper.h.
ns3::Ipv4AddressHelper::Ipv4AddressHelper | ( | ) |
Construct a helper class to make life easier while doing simple IPv4 address assignment in scripts.
Definition at line 36 of file ipv4-address-helper.cc.
References m_address, m_base, m_mask, m_max, m_network, m_shift, and NS_LOG_FUNCTION_NOARGS.
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
network | the network part |
mask | the address mask |
base | the host part to start from |
Definition at line 53 of file ipv4-address-helper.cc.
References first::address, NS_LOG_FUNCTION_NOARGS, and SetBase().
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.
c | The NetDeviceContainer holding the collection of net devices we are asked to assign Ipv4 addresses to. |
Definition at line 134 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(), m_mask, NewAddress(), NS_ASSERT_MSG(), NS_LOG_FUNCTION_NOARGS, and NS_LOG_LOGIC().
Referenced by ns3::PointToPointEpcHelper::AddEnb(), ns3::EmuEpcHelper::AddEnb(), ns3::PointToPointEpcHelper::AddX2Interface(), RoutingHelper::AssignIpAddresses(), ns3::PointToPointGridHelper::AssignIpv4Addresses(), ns3::PointToPointDumbbellHelper::AssignIpv4Addresses(), ns3::PointToPointEpcHelper::AssignUeIpv4Address(), ns3::EmuEpcHelper::AssignUeIpv4Address(), ns3::olsr::Bug780Test::CreateNodes(), ns3::olsr::HelloRegressionTest::CreateNodes(), ns3::olsr::TcRegressionTest::CreateNodes(), ThreeGppHttpObjectTestCase::CreateSimpleInternetNode(), ns3::EmuEpcHelper::DoInitialize(), ns3::LenaDeactivateBearerTestCase::DoRun(), UdpClientServerTestCase::DoRun(), CsmaBridgeTestCase::DoRun(), LenaCqaFfMacSchedulerTestCase1::DoRun(), LenaPssFfMacSchedulerTestCase1::DoRun(), LenaTdTbfqFfMacSchedulerTestCase1::DoRun(), LenaFdTbfqFfMacSchedulerTestCase1::DoRun(), Ipv4RipTest::DoRun(), Ipv4StaticRoutingSlash32TestCase::DoRun(), Ns3TcpLossTestCase::DoRun(), Ns3TcpStateTestCase::DoRun(), LteX2HandoverTestCase::DoRun(), LenaTdTbfqFfMacSchedulerTestCase2::DoRun(), EpcS1uDlTestCase::DoRun(), LenaPssFfMacSchedulerTestCase2::DoRun(), LteCellSelectionTestCase::DoRun(), LenaCqaFfMacSchedulerTestCase2::DoRun(), LenaFdTbfqFfMacSchedulerTestCase2::DoRun(), LteX2HandoverMeasuresTestCase::DoRun(), LteEpcE2eDataTestCase::DoRun(), LteHandoverTargetTestCase::DoRun(), UdpTraceClientServerTestCase::DoRun(), CsmaBroadcastTestCase::DoRun(), UdpEchoClientSetFillTestCase::DoRun(), CsmaMulticastTestCase::DoRun(), Ipv4RipCountToInfinityTest::DoRun(), EpcS1uUlTestCase::DoRun(), ns3::TcpGeneralTest::DoRun(), LteDistributedFfrAreaTestCase::DoRun(), Ns3TcpCwndTestCase2::DoRun(), CsmaOneSubnetTestCase::DoRun(), LteUeMeasurementsHandoverTestCase::DoRun(), Ipv4RipSplitHorizonStrategyTest::DoRun(), CsmaPingTestCase::DoRun(), CsmaRawIpSocketTestCase::DoRun(), Ipv4DynamicGlobalRoutingTestCase::DoRun(), Ipv4GlobalRoutingSlash32TestCase::DoRun(), LinkTest::DoSetup(), LanTest::DoSetup(), TwoLinkTest::DoSetup(), TwoLanTest::DoSetup(), experiment(), RoutingExperiment::Run(), and WifiInterferenceTestCase::WifiSimpleInterference().
Ipv4Address ns3::Ipv4AddressHelper::NewAddress | ( | void | ) |
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.
Definition at line 101 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().
Ipv4Address ns3::Ipv4AddressHelper::NewNetwork | ( | void | ) |
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.
Definition at line 125 of file ipv4-address-helper.cc.
References m_address, m_base, m_network, m_shift, and NS_LOG_FUNCTION_NOARGS.
Referenced by ns3::PointToPointEpcHelper::AddEnb(), ns3::PointToPointEpcHelper::AddX2Interface(), ns3::PointToPointGridHelper::AssignIpv4Addresses(), ns3::PointToPointDumbbellHelper::AssignIpv4Addresses(), NetworkAllocatorHelperTestCase::DoRun(), ResetAllocatorHelperTestCase::DoRun(), and IpAddressHelperTestCasev4::DoRun().
|
private |
Returns the number of address bits (hostpart) for a given netmask.
maskbits | the netmask |
Definition at line 181 of file ipv4-address-helper.cc.
References ns3::N_BITS, NS_ASSERT_MSG(), NS_LOG_FUNCTION_NOARGS, and NS_LOG_LOGIC().
Referenced by 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.
network | The Ipv4Address containing the initial network number to use during allocation. The bits outside the network mask are not used. |
mask | The Ipv4Mask containing one bits in each bit position of the network number. |
base | An 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 63 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 RoutingHelper::AssignIpAddresses(), ns3::olsr::Bug780Test::CreateNodes(), ns3::olsr::HelloRegressionTest::CreateNodes(), ns3::olsr::TcRegressionTest::CreateNodes(), ns3::EmuEpcHelper::DoInitialize(), NetworkAllocatorHelperTestCase::DoRun(), ns3::LenaDeactivateBearerTestCase::DoRun(), UdpClientServerTestCase::DoRun(), CsmaBridgeTestCase::DoRun(), LenaCqaFfMacSchedulerTestCase1::DoRun(), LenaPssFfMacSchedulerTestCase1::DoRun(), LenaTdTbfqFfMacSchedulerTestCase1::DoRun(), LenaFdTbfqFfMacSchedulerTestCase1::DoRun(), Ipv4RipTest::DoRun(), Ipv4StaticRoutingSlash32TestCase::DoRun(), Ns3TcpLossTestCase::DoRun(), Ns3TcpStateTestCase::DoRun(), LteX2HandoverTestCase::DoRun(), AddressAllocatorHelperTestCase::DoRun(), LenaTdTbfqFfMacSchedulerTestCase2::DoRun(), EpcS1uDlTestCase::DoRun(), LenaPssFfMacSchedulerTestCase2::DoRun(), LteCellSelectionTestCase::DoRun(), LenaCqaFfMacSchedulerTestCase2::DoRun(), LenaFdTbfqFfMacSchedulerTestCase2::DoRun(), LteX2HandoverMeasuresTestCase::DoRun(), LteEpcE2eDataTestCase::DoRun(), LteHandoverTargetTestCase::DoRun(), UdpTraceClientServerTestCase::DoRun(), ResetAllocatorHelperTestCase::DoRun(), CsmaBroadcastTestCase::DoRun(), IpAddressHelperTestCasev4::DoRun(), UdpEchoClientSetFillTestCase::DoRun(), CsmaMulticastTestCase::DoRun(), Ipv4RipCountToInfinityTest::DoRun(), EpcS1uUlTestCase::DoRun(), ns3::TcpGeneralTest::DoRun(), LteDistributedFfrAreaTestCase::DoRun(), Ns3TcpCwndTestCase2::DoRun(), CsmaOneSubnetTestCase::DoRun(), LteUeMeasurementsHandoverTestCase::DoRun(), Ipv4RipSplitHorizonStrategyTest::DoRun(), CsmaPingTestCase::DoRun(), CsmaRawIpSocketTestCase::DoRun(), Ipv4DynamicGlobalRoutingTestCase::DoRun(), Ipv4GlobalRoutingSlash32TestCase::DoRun(), LinkTest::DoSetup(), LanTest::DoSetup(), TwoLinkTest::DoSetup(), TwoLanTest::DoSetup(), experiment(), LteAggregationThroughputScaleTestCase::GetThroughput(), Ipv4AddressHelper(), ns3::PointToPointEpcHelper::PointToPointEpcHelper(), RoutingExperiment::Run(), ThreeGppHttpObjectTestCase::ThreeGppHttpObjectTestCase(), and WifiInterferenceTestCase::WifiSimpleInterference().
|
private |
address
Definition at line 193 of file ipv4-address-helper.h.
Referenced by Ipv4AddressHelper(), NewAddress(), NewNetwork(), and SetBase().
|
private |
base address
Definition at line 194 of file ipv4-address-helper.h.
Referenced by Ipv4AddressHelper(), NewNetwork(), and SetBase().
|
private |
network mask
Definition at line 192 of file ipv4-address-helper.h.
Referenced by Assign(), Ipv4AddressHelper(), and SetBase().
|
private |
maximum allowed address
Definition at line 196 of file ipv4-address-helper.h.
Referenced by Ipv4AddressHelper(), NewAddress(), and SetBase().
|
private |
network address
Definition at line 191 of file ipv4-address-helper.h.
Referenced by Ipv4AddressHelper(), NewAddress(), NewNetwork(), and SetBase().
|
private |
shift, equivalent to the number of bits in the hostpart
Definition at line 195 of file ipv4-address-helper.h.
Referenced by Ipv4AddressHelper(), NewAddress(), NewNetwork(), and SetBase().