ns-3 Direct Code Execution
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ns3::Ipv4Linux Class Reference

This implementation of Ipv4 for nodes using a real Linux Stack. More...

#include <ipv4-linux.h>

+ Collaboration diagram for ns3::Ipv4Linux:

Public Member Functions

 Ipv4Linux ()
virtual ~Ipv4Linux ()
virtual bool AddAddress (uint32_t interface, Ipv4InterfaceAddress address)
virtual uint32_t AddInterface (Ptr< NetDevice > device)
virtual Ptr< Socket > CreateRawSocket (void)
virtual void DeleteRawSocket (Ptr< Socket > socket)
virtual Ipv4InterfaceAddress GetAddress (uint32_t interface, uint32_t addressIndex) const
virtual int32_t GetInterfaceForAddress (Ipv4Address address) const
 Return the interface number of the interface that has been assigned the specified IP address.
virtual int32_t GetInterfaceForDevice (Ptr< const NetDevice > device) const
virtual int32_t GetInterfaceForPrefix (Ipv4Address address, Ipv4Mask mask) const
 Return the interface number of first interface found that has an Ipv4 address within the prefix specified by the input address and mask parameters.
virtual uint16_t GetMetric (uint32_t interface) const
virtual uint16_t GetMtu (uint32_t interface) const
virtual uint32_t GetNAddresses (uint32_t interface) const
virtual Ptr< NetDevice > GetNetDevice (uint32_t interface)
virtual uint32_t GetNInterfaces (void) const
virtual Ptr< IpL4Protocol > GetProtocol (int protocolNumber) const
virtual Ptr< Ipv4RoutingProtocol > GetRoutingProtocol (void) const
 Get the routing protocol to be used by this Ipv4 stack.
virtual void Insert (Ptr< IpL4Protocol > protocol)
virtual bool IsDestinationAddress (Ipv4Address address, uint32_t iif) const
 Determine whether address and interface corresponding to received packet can be accepted for local delivery.
virtual bool IsForwarding (uint32_t interface) const
virtual bool IsUp (uint32_t interface) const
void PopulateRoutingTable ()
virtual bool RemoveAddress (uint32_t interface, uint32_t addressIndex)
virtual bool RemoveAddress (uint32_t interface, Ipv4Address address)
 Remove the given address on named Ipv4 interface.
virtual Ipv4Address SelectSourceAddress (Ptr< const NetDevice > device, Ipv4Address dst, Ipv4InterfaceAddress::InterfaceAddressScope_e scope)
 Return the first primary source address with scope less than or equal to the requested scope, to use in sending a packet to destination dst out of the specified device.
virtual void Send (Ptr< Packet > packet, Ipv4Address source, Ipv4Address destination, uint8_t protocol, Ptr< Ipv4Route > route)
virtual void SendWithHeader (Ptr< Packet > packet, Ipv4Header ipHeader, Ptr< Ipv4Route > route)
virtual void SetDown (uint32_t interface)
virtual void SetForwarding (uint32_t interface, bool val)
virtual void SetMetric (uint32_t interface, uint16_t metric)
virtual void SetRoutingProtocol (Ptr< Ipv4RoutingProtocol > routingProtocol)
 Register a new routing protocol to be used by this Ipv4 stack.
virtual void SetUp (uint32_t interface)

Static Public Member Functions

static TypeId GetTypeId (void)
static void InstallNode (Ptr< Node > node)

Private Types

typedef std::vector< Ptr
< Ipv4Interface > > 
Ipv4InterfaceList

Private Member Functions

uint32_t AddIpv4Interface (Ptr< Ipv4Interface > interface)
Ptr< Ipv4Interface > GetInterface (uint32_t i) const
virtual bool GetIpForward (void) const
virtual bool GetWeakEsModel (void) const
virtual void SetIpForward (bool forward)
virtual void SetWeakEsModel (bool model)

Private Attributes

Ipv4InterfaceList m_interfaces
bool m_ipForward
uint64_t m_nanoSec
Ptr< Ipv4RoutingProtocol > m_routingProtocol
bool m_weakEsModel

Detailed Description

This implementation of Ipv4 for nodes using a real Linux Stack.

The main goal of this class is not to do the stack job which is done by the real code .... but it is used to not redo the wheel and in particular to be able to reuse these 2 standards NS-3 Helpers for two tasks: 1 - assign address to devices using Ipv4AddressHelper, 2 - create the static routes using Ipv4GlobalRoutingHelper

Definition at line 39 of file ipv4-linux.h.

Member Typedef Documentation

typedef std::vector<Ptr<Ipv4Interface> > ns3::Ipv4Linux::Ipv4InterfaceList
private

Definition at line 332 of file ipv4-linux.h.

Constructor & Destructor Documentation

ns3::Ipv4Linux::Ipv4Linux ( )

Definition at line 66 of file ipv4-linux.cc.

ns3::Ipv4Linux::~Ipv4Linux ( )
virtual

Definition at line 72 of file ipv4-linux.cc.

Member Function Documentation

bool ns3::Ipv4Linux::AddAddress ( uint32_t  interface,
Ipv4InterfaceAddress  address 
)
virtual
Parameters
interfaceInterface number of an Ipv4 interface
addressIpv4InterfaceAddress address to associate with the underlying Ipv4 interface
Returns
true if the operation succeeded

Definition at line 271 of file ipv4-linux.cc.

References GetInterface(), m_nanoSec, m_routingProtocol, and ns3::RunIp().

+ Here is the call graph for this function:

uint32_t ns3::Ipv4Linux::AddInterface ( Ptr< NetDevice >  device)
virtual
Parameters
devicedevice to add to the list of Ipv4 interfaces which can be used as output interfaces during packet forwarding.
Returns
the index of the Ipv4 interface added.

Once a device has been added, it can never be removed: if you want to disable it, you can invoke Ipv4::SetDown which will make sure that it is never used during packet forwarding.

Definition at line 93 of file ipv4-linux.cc.

References AddIpv4Interface(), and m_ipForward.

+ Here is the call graph for this function:

uint32_t ns3::Ipv4Linux::AddIpv4Interface ( Ptr< Ipv4Interface >  interface)
private

Definition at line 103 of file ipv4-linux.cc.

References m_interfaces.

Referenced by AddInterface().

+ Here is the caller graph for this function:

Ptr< Socket > ns3::Ipv4Linux::CreateRawSocket ( void  )
virtual

Do nothing

Definition at line 552 of file ipv4-linux.cc.

void ns3::Ipv4Linux::DeleteRawSocket ( Ptr< Socket >  socket)
virtual

Do nothing

Definition at line 561 of file ipv4-linux.cc.

Ipv4InterfaceAddress ns3::Ipv4Linux::GetAddress ( uint32_t  interface,
uint32_t  addressIndex 
) const
virtual

Because addresses can be removed, the addressIndex is not guaranteed to be static across calls to this method.

Parameters
interfaceInterface number of an Ipv4 interface
addressIndexindex of Ipv4InterfaceAddress
Returns
the Ipv4InterfaceAddress associated to the interface and addressIndex

Definition at line 303 of file ipv4-linux.cc.

References GetInterface().

Referenced by IsDestinationAddress(), and SelectSourceAddress().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Ptr< Ipv4Interface > ns3::Ipv4Linux::GetInterface ( uint32_t  i) const
private

Definition at line 536 of file ipv4-linux.cc.

References m_interfaces.

Referenced by AddAddress(), GetAddress(), GetMetric(), GetMtu(), GetNAddresses(), GetNetDevice(), IsForwarding(), IsUp(), RemoveAddress(), SetDown(), SetForwarding(), SetMetric(), and SetUp().

+ Here is the caller graph for this function:

int32_t ns3::Ipv4Linux::GetInterfaceForAddress ( Ipv4Address  address) const
virtual

Return the interface number of the interface that has been assigned the specified IP address.

Parameters
addressThe IP address being searched for
Returns
The interface number of the Ipv4 interface with the given address or -1 if not found.

Each IP interface has one or more IP addresses associated with it. This method searches the list of interfaces for one that holds a particular address. This call takes an IP address as a parameter and returns the interface number of the first interface that has been assigned that address, or -1 if not found. There must be an exact match; this method will not match broadcast or multicast addresses.

Definition at line 119 of file ipv4-linux.cc.

References m_interfaces.

int32_t ns3::Ipv4Linux::GetInterfaceForDevice ( Ptr< const NetDevice >  device) const
virtual
Parameters
deviceThe NetDevice for an Ipv4Interface
Returns
The interface number of an Ipv4 interface or -1 if not found.

Definition at line 253 of file ipv4-linux.cc.

References m_interfaces.

Referenced by SelectSourceAddress().

+ Here is the caller graph for this function:

int32_t ns3::Ipv4Linux::GetInterfaceForPrefix ( Ipv4Address  address,
Ipv4Mask  mask 
) const
virtual

Return the interface number of first interface found that has an Ipv4 address within the prefix specified by the input address and mask parameters.

Parameters
addressThe IP address assigned to the interface of interest.
maskThe IP prefix to use in the mask
Returns
The interface number of the Ipv4 interface with the given address or -1 if not found.

Each IP interface has one or more IP addresses associated with it. This method searches the list of interfaces for the first one found that holds an address that is included within the prefix formed by the input address and mask parameters. The value -1 is returned if no match is found.

Definition at line 225 of file ipv4-linux.cc.

References m_interfaces.

bool ns3::Ipv4Linux::GetIpForward ( void  ) const
privatevirtual

Definition at line 496 of file ipv4-linux.cc.

References m_ipForward.

uint16_t ns3::Ipv4Linux::GetMetric ( uint32_t  interface) const
virtual
Parameters
interfaceThe interface number of an Ipv4 interface
Returns
routing metric (cost) associated to the underlying Ipv4 interface

Definition at line 421 of file ipv4-linux.cc.

References GetInterface().

+ Here is the call graph for this function:

uint16_t ns3::Ipv4Linux::GetMtu ( uint32_t  interface) const
virtual
Parameters
interfaceInterface number of Ipv4 interface
Returns
the Maximum Transmission Unit (in bytes) associated to the underlying Ipv4 interface

Definition at line 428 of file ipv4-linux.cc.

References GetInterface().

+ Here is the call graph for this function:

uint32_t ns3::Ipv4Linux::GetNAddresses ( uint32_t  interface) const
virtual
Parameters
interfaceInterface number of an Ipv4 interface
Returns
the number of Ipv4InterfaceAddress entries for the interface.

Definition at line 296 of file ipv4-linux.cc.

References GetInterface().

Referenced by IsDestinationAddress(), and SelectSourceAddress().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Ptr< NetDevice > ns3::Ipv4Linux::GetNetDevice ( uint32_t  interface)
virtual
Parameters
interfaceThe interface number of an Ipv4 interface.
Returns
The NetDevice associated with the Ipv4 interface number.

Definition at line 246 of file ipv4-linux.cc.

References GetInterface().

+ Here is the call graph for this function:

uint32_t ns3::Ipv4Linux::GetNInterfaces ( void  ) const
virtual
Returns
the number of interfaces added by the user.

Definition at line 112 of file ipv4-linux.cc.

References m_interfaces.

Referenced by IsDestinationAddress(), and SelectSourceAddress().

+ Here is the caller graph for this function:

Ptr< IpL4Protocol > ns3::Ipv4Linux::GetProtocol ( int  protocolNumber) const
virtual

Do nothing

Definition at line 546 of file ipv4-linux.cc.

Ptr< Ipv4RoutingProtocol > ns3::Ipv4Linux::GetRoutingProtocol ( void  ) const
virtual

Get the routing protocol to be used by this Ipv4 stack.

Returns
smart pointer to Ipv4RoutingProtocol object, or null pointer if none

Definition at line 86 of file ipv4-linux.cc.

References m_routingProtocol.

Referenced by PopulateRoutingTable().

+ Here is the caller graph for this function:

TypeId ns3::Ipv4Linux::GetTypeId ( void  )
static

Definition at line 57 of file ipv4-linux.cc.

bool ns3::Ipv4Linux::GetWeakEsModel ( void  ) const
privatevirtual

Definition at line 508 of file ipv4-linux.cc.

References m_weakEsModel.

Referenced by IsDestinationAddress().

+ Here is the caller graph for this function:

void ns3::Ipv4Linux::Insert ( Ptr< IpL4Protocol >  protocol)
virtual

Do nothing

Definition at line 154 of file ipv4-linux.cc.

void ns3::Ipv4Linux::InstallNode ( Ptr< Node >  node)
static

Definition at line 514 of file ipv4-linux.cc.

Referenced by ns3::LinuxStackHelper::Install().

+ Here is the caller graph for this function:

bool ns3::Ipv4Linux::IsDestinationAddress ( Ipv4Address  address,
uint32_t  iif 
) const
virtual

Determine whether address and interface corresponding to received packet can be accepted for local delivery.

Parameters
addressThe IP address being considered
iifThe incoming Ipv4 interface index

This method can be used to determine whether a received packet has an acceptable address for local delivery on the host. The address may be a unicast, multicast, or broadcast address. This method will return true if address is an exact match of a unicast address on one of the host's interfaces (see below), if address corresponds to a multicast group that the host has joined (and the incoming device is acceptable), or if address corresponds to a broadcast address.

If the Ipv4 attribute WeakEsModel is true, the unicast address may match any of the Ipv4 addresses on any interface. If the attribute is false, the address must match one assigned to the incoming device.

Definition at line 160 of file ipv4-linux.cc.

References GetAddress(), GetNAddresses(), GetNInterfaces(), and GetWeakEsModel().

+ Here is the call graph for this function:

bool ns3::Ipv4Linux::IsForwarding ( uint32_t  interface) const
virtual
Parameters
interfaceInterface number of Ipv4 interface
Returns
true if IP forwarding enabled for input datagrams on this device

Definition at line 468 of file ipv4-linux.cc.

References GetInterface().

+ Here is the call graph for this function:

bool ns3::Ipv4Linux::IsUp ( uint32_t  interface) const
virtual
Parameters
interfaceInterface number of Ipv4 interface
Returns
true if the underlying interface is in the "up" state, false otherwise.

Definition at line 435 of file ipv4-linux.cc.

References GetInterface().

+ Here is the call graph for this function:

void ns3::Ipv4Linux::PopulateRoutingTable ( )

Definition at line 567 of file ipv4-linux.cc.

References GetRoutingProtocol(), m_nanoSec, and ns3::RunIp().

Referenced by ns3::LinuxStackHelper::PopulateRoutingTables().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool ns3::Ipv4Linux::RemoveAddress ( uint32_t  interface,
uint32_t  addressIndex 
)
virtual

Remove the address at addressIndex on named interface. The addressIndex for all higher indices will decrement by one after this method is called; so, for example, to remove 5 addresses from an interface i, one could call RemoveAddress (i, 0); 5 times.

Parameters
interfaceInterface number of an Ipv4 interface
addressIndexindex of Ipv4InterfaceAddress to remove
Returns
true if the operation succeeded

Definition at line 311 of file ipv4-linux.cc.

References GetInterface(), and m_routingProtocol.

+ Here is the call graph for this function:

bool ns3::Ipv4Linux::RemoveAddress ( uint32_t  interface,
Ipv4Address  address 
)
virtual

Remove the given address on named Ipv4 interface.

Parameters
interfaceInterface number of an Ipv4 interface
addressThe address to remove
Returns
true if the operation succeeded

Definition at line 328 of file ipv4-linux.cc.

References GetInterface(), and m_routingProtocol.

+ Here is the call graph for this function:

Ipv4Address ns3::Ipv4Linux::SelectSourceAddress ( Ptr< const NetDevice >  device,
Ipv4Address  dst,
Ipv4InterfaceAddress::InterfaceAddressScope_e  scope 
)
virtual

Return the first primary source address with scope less than or equal to the requested scope, to use in sending a packet to destination dst out of the specified device.

This method mirrors the behavior of Linux inet_select_addr() and is provided because interfaces may have multiple IP addresses configured on them with different scopes, and with a primary and secondary status. Secondary addresses are never returned.

See Also
Ipv4InterfaceAddress

If a non-zero device pointer is provided, the method first tries to return a primary address that is configured on that device, and whose subnet matches that of dst and whose scope is less than or equal to the requested scope. If a primary address does not match the subnet of dst but otherwise matches the scope, it is returned. If no such address on the device is found, the other devices are searched in order of their interface index, but not considering dst as a factor in the search. Because a loopback interface is typically the first one configured on a node, it will be the first alternate device to be tried. Addresses scoped at LINK scope are not returned in this phase.

If no device pointer is provided, the same logic as above applies, only that there is no preferred device that is consulted first. This means that if the device pointer is null, input parameter dst will be ignored.

If there are no possible addresses to return, a warning log message is issued and the all-zeroes address is returned.

Parameters
deviceoutput NetDevice (optionally provided, only to constrain the search)
dstDestination address to match, if device is provided
scopeScope of returned address must be less than or equal to this
Returns
the first primary Ipv4Address that meets the search criteria

Definition at line 351 of file ipv4-linux.cc.

References GetAddress(), GetInterfaceForDevice(), GetNAddresses(), and GetNInterfaces().

+ Here is the call graph for this function:

void ns3::Ipv4Linux::Send ( Ptr< Packet >  packet,
Ipv4Address  source,
Ipv4Address  destination,
uint8_t  protocol,
Ptr< Ipv4Route >  route 
)
virtual

Do nothing

Definition at line 141 of file ipv4-linux.cc.

void ns3::Ipv4Linux::SendWithHeader ( Ptr< Packet >  packet,
Ipv4Header  ipHeader,
Ptr< Ipv4Route >  route 
)
virtual

Do nothing

Definition at line 148 of file ipv4-linux.cc.

void ns3::Ipv4Linux::SetDown ( uint32_t  interface)
virtual
Parameters
interfaceInterface number of Ipv4 interface

Set the interface into the "down" state. In this state, it is ignored during Ipv4 forwarding.

Definition at line 455 of file ipv4-linux.cc.

References GetInterface(), and m_routingProtocol.

+ Here is the call graph for this function:

void ns3::Ipv4Linux::SetForwarding ( uint32_t  interface,
bool  val 
)
virtual
Parameters
interfaceInterface number of Ipv4 interface
valValue to set the forwarding flag

If set to true, IP forwarding is enabled for input datagrams on this device

Definition at line 477 of file ipv4-linux.cc.

References GetInterface().

+ Here is the call graph for this function:

void ns3::Ipv4Linux::SetIpForward ( bool  forward)
privatevirtual

Definition at line 485 of file ipv4-linux.cc.

References m_interfaces, and m_ipForward.

void ns3::Ipv4Linux::SetMetric ( uint32_t  interface,
uint16_t  metric 
)
virtual
Parameters
interfaceThe interface number of an Ipv4 interface
metricrouting metric (cost) associated to the underlying Ipv4 interface

Definition at line 413 of file ipv4-linux.cc.

References GetInterface().

+ Here is the call graph for this function:

void ns3::Ipv4Linux::SetRoutingProtocol ( Ptr< Ipv4RoutingProtocol >  routingProtocol)
virtual

Register a new routing protocol to be used by this Ipv4 stack.

This call will replace any routing protocol that has been previously registered. If you want to add multiple routing protocols, you must add them to a Ipv4ListRoutingProtocol directly.

Parameters
routingProtocolsmart pointer to Ipv4RoutingProtocol object

Definition at line 78 of file ipv4-linux.cc.

References m_routingProtocol.

void ns3::Ipv4Linux::SetUp ( uint32_t  interface)
virtual
Parameters
interfaceInterface number of Ipv4 interface

Set the interface into the "up" state. In this state, it is considered valid during Ipv4 forwarding.

Definition at line 442 of file ipv4-linux.cc.

References GetInterface(), and m_routingProtocol.

+ Here is the call graph for this function:

void ns3::Ipv4Linux::SetWeakEsModel ( bool  model)
privatevirtual

Definition at line 502 of file ipv4-linux.cc.

References m_weakEsModel.

Member Data Documentation

bool ns3::Ipv4Linux::m_ipForward
private

Definition at line 334 of file ipv4-linux.h.

Referenced by AddInterface(), GetIpForward(), and SetIpForward().

uint64_t ns3::Ipv4Linux::m_nanoSec
private

Definition at line 337 of file ipv4-linux.h.

Referenced by AddAddress(), and PopulateRoutingTable().

Ptr<Ipv4RoutingProtocol> ns3::Ipv4Linux::m_routingProtocol
private
bool ns3::Ipv4Linux::m_weakEsModel
private

Definition at line 335 of file ipv4-linux.h.

Referenced by GetWeakEsModel(), and SetWeakEsModel().


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