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

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

#include "ipv6-address-generator.h"

Static Public Member Functions

static bool AddAllocated (const Ipv6Address addr)
 Add the Ipv6Address to the list of IPv6 entries. More...
 
static Ipv6Address GetAddress (const Ipv6Prefix prefix)
 Get the Ipv6Address that will be allocated upon NextAddress () More...
 
static Ipv6Address GetNetwork (const Ipv6Prefix prefix)
 Get the current network of the given Ipv6Prefix. More...
 
static void Init (const Ipv6Address net, const Ipv6Prefix prefix, const Ipv6Address interfaceId="::1")
 Initialise the base network and interfaceId for the generator. More...
 
static void InitAddress (const Ipv6Address interfaceId, const Ipv6Prefix prefix)
 Set the interfaceId for the given Ipv6Prefix. More...
 
static bool IsAddressAllocated (const Ipv6Address addr)
 Check the Ipv6Address allocation in the list of IPv6 entries. More...
 
static bool IsNetworkAllocated (const Ipv6Address addr, const Ipv6Prefix prefix)
 Check if a network has already allocated addresses. More...
 
static Ipv6Address NextAddress (const Ipv6Prefix prefix)
 Allocate the next Ipv6Address for the configured network and prefix. More...
 
static Ipv6Address NextNetwork (const Ipv6Prefix prefix)
 Get the next network according to the given Ipv6Prefix. More...
 
static void Reset ()
 Reset the networks and Ipv6Address to zero. More...
 
static void TestMode ()
 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.

It also keeps track of all addresses assigned to perform duplicate detection.

Global unicast IPv6 addresses based on RFC 4291 definition:

|         n bits          |   m bits  |       128-n-m bits         |
+-------------------------+-----------+----------------------------+
| global routing prefix   | subnet ID |       interface ID         |
+-------------------------+-----------+----------------------------+

In this class, the first two quantities (n + m) are what is called the 'net', and the 'prefix' defines the length in bits of (n + m).

The way this is expected to be used is that, after initializing the network and interfaceId to a number, a user can call NextAddress () repeatedly to obtain new interface IDs with the current network (for multiple addresses on the link) and can call NextNetwork () to increment the subnet ID.

The interface ID is often an EUI-64 address derived from the MAC address, but can also be a pseudo-random value (RFC 3041). This implementation does not generate EUI-64-based interface IDs.

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

Definition at line 61 of file ipv6-address-generator.h.

Member Function Documentation

◆ AddAllocated()

bool ns3::Ipv6AddressGenerator::AddAllocated ( const Ipv6Address  addr)
static

Add the Ipv6Address to the list of IPv6 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 Ipv6Address to be added to the list of Ipv6 entries
Returns
true on success

Definition at line 730 of file ipv6-address-generator.cc.

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

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

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

◆ GetAddress()

Ipv6Address ns3::Ipv6AddressGenerator::GetAddress ( const Ipv6Prefix  prefix)
static

Get the Ipv6Address 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
prefixThe Ipv6Prefix for the current network
Returns
the IPv6 address

Definition at line 706 of file ipv6-address-generator.cc.

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

+ Here is the call graph for this function:

◆ GetNetwork()

Ipv6Address ns3::Ipv6AddressGenerator::GetNetwork ( const Ipv6Prefix  prefix)
static

Get the current network of the given Ipv6Prefix.

Does not change the internal state; this just peeks at the current network

Parameters
prefixThe Ipv6Prefix for the current network
Returns
the IPv6 address of the current network

Definition at line 690 of file ipv6-address-generator.cc.

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

Referenced by ns3::CsmaStarHelper::AssignIpv6Addresses(), ns3::PointToPointDumbbellHelper::AssignIpv6Addresses(), ns3::PointToPointGridHelper::AssignIpv6Addresses(), and ns3::PointToPointStarHelper::AssignIpv6Addresses().

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

◆ Init()

void ns3::Ipv6AddressGenerator::Init ( const Ipv6Address  net,
const Ipv6Prefix  prefix,
const Ipv6Address  interfaceId = "::1" 
)
static

Initialise the base network and interfaceId for the generator.

The first call to NextAddress() or GetAddress() will return the value passed in.

Parameters
netThe network for the base Ipv6Address
prefixThe prefix of the base Ipv6Address
interfaceIdThe base interface ID used for initialization

Definition at line 672 of file ipv6-address-generator.cc.

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

Referenced by ns3::CsmaStarHelper::AssignIpv6Addresses(), ns3::PointToPointDumbbellHelper::AssignIpv6Addresses(), ns3::PointToPointGridHelper::AssignIpv6Addresses(), and ns3::PointToPointStarHelper::AssignIpv6Addresses().

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

◆ InitAddress()

void ns3::Ipv6AddressGenerator::InitAddress ( const Ipv6Address  interfaceId,
const Ipv6Prefix  prefix 
)
static

Set the interfaceId for the given Ipv6Prefix.

Parameters
interfaceIdThe interfaceId to set for the current Ipv6Prefix
prefixThe Ipv6Prefix whose address is to be set

Definition at line 698 of file ipv6-address-generator.cc.

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

+ Here is the call graph for this function:

◆ IsAddressAllocated()

bool ns3::Ipv6AddressGenerator::IsAddressAllocated ( const Ipv6Address  addr)
static

Check the Ipv6Address allocation in the list of IPv6 entries.

Parameters
addrThe Ipv6Address to be checked in the list of Ipv4 entries
Returns
true if the address is already allocated

Definition at line 738 of file ipv6-address-generator.cc.

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

+ Here is the call graph for this function:

◆ IsNetworkAllocated()

bool ns3::Ipv6AddressGenerator::IsNetworkAllocated ( const Ipv6Address  addr,
const Ipv6Prefix  prefix 
)
static

Check if a network has already allocated addresses.

Parameters
addrThe Ipv6 network to be checked
prefixThe Ipv6 network prefix
Returns
true if the network is already allocated

Definition at line 746 of file ipv6-address-generator.cc.

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

+ Here is the call graph for this function:

◆ NextAddress()

Ipv6Address ns3::Ipv6AddressGenerator::NextAddress ( const Ipv6Prefix  prefix)
static

Allocate the next Ipv6Address for the configured network and prefix.

This operation is a post-increment, meaning that the first address allocated will be the one that was initially configured.

Parameters
prefixThe Ipv6Prefix for the current network
Returns
the IPv6 address

Definition at line 714 of file ipv6-address-generator.cc.

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

+ Here is the call graph for this function:

◆ NextNetwork()

Ipv6Address ns3::Ipv6AddressGenerator::NextNetwork ( const Ipv6Prefix  prefix)
static

Get the next network according to the given Ipv6Prefix.

This operation is a pre-increment, meaning that the internal state is changed before returning the new network address.

This also resets the interface ID to the base interface ID that was used for initialization.

Parameters
prefixThe Ipv6Prefix used to set the next network
Returns
the IPv6 address of the next network

Definition at line 682 of file ipv6-address-generator.cc.

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

Referenced by ns3::CsmaStarHelper::AssignIpv6Addresses(), ns3::PointToPointDumbbellHelper::AssignIpv6Addresses(), ns3::PointToPointGridHelper::AssignIpv6Addresses(), and ns3::PointToPointStarHelper::AssignIpv6Addresses().

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

◆ Reset()

void ns3::Ipv6AddressGenerator::Reset ( )
static

Reset the networks and Ipv6Address to zero.

Definition at line 722 of file ipv6-address-generator.cc.

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

+ Here is the call graph for this function:

◆ TestMode()

void ns3::Ipv6AddressGenerator::TestMode ( )
static

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

Definition at line 754 of file ipv6-address-generator.cc.

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

+ Here is the call graph for this function:

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