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

The IPv4 representation of a network interface. More...

#include "ipv4-interface.h"

+ Inheritance diagram for ns3::Ipv4Interface:
+ Collaboration diagram for ns3::Ipv4Interface:

Public Member Functions

 Ipv4Interface ()
 By default, Ipv4 interface are created in the "down" state with no IP addresses. More...
 
 Ipv4Interface (const Ipv4Interface &)=delete
 
 ~Ipv4Interface () override
 
bool AddAddress (Ipv4InterfaceAddress address)
 
void AddAddressCallback (Callback< void, Ptr< Ipv4Interface >, Ipv4InterfaceAddress > addAddressCallback)
 This callback is set when an address is added from an interface with auto-generated Arp cache and it allow the neighbor cache helper to update neighbor's Arp cache. More...
 
Ipv4InterfaceAddress GetAddress (uint32_t index) const
 
Ptr< ArpCacheGetArpCache () const
 
Ptr< NetDeviceGetDevice () const
 
uint16_t GetMetric () const
 
uint32_t GetNAddresses () const
 
bool IsDown () const
 
bool IsForwarding () const
 
bool IsUp () const
 These are IP interface states and may be distinct from NetDevice states, such as found in real implementations (where the device may be down but IP interface state is still up). More...
 
Ipv4Interfaceoperator= (const Ipv4Interface &)=delete
 
Ipv4InterfaceAddress RemoveAddress (Ipv4Address address)
 Remove the given Ipv4 address from the interface. More...
 
Ipv4InterfaceAddress RemoveAddress (uint32_t index)
 
void RemoveAddressCallback (Callback< void, Ptr< Ipv4Interface >, Ipv4InterfaceAddress > removeAddressCallback)
 This callback is set when an address is removed from an interface with auto-generated Arp cache and it allow the neighbor cache helper to update neighbor's Arp cache. More...
 
void Send (Ptr< Packet > p, const Ipv4Header &hdr, Ipv4Address dest)
 
void SetArpCache (Ptr< ArpCache > arpCache)
 Set ARP cache used by this interface. More...
 
void SetDevice (Ptr< NetDevice > device)
 Set the NetDevice. More...
 
void SetDown ()
 Disable this interface. More...
 
void SetForwarding (bool val)
 
void SetMetric (uint16_t metric)
 
void SetNode (Ptr< Node > node)
 Set node associated with interface. More...
 
void SetTrafficControl (Ptr< TrafficControlLayer > tc)
 Set the TrafficControlLayer. More...
 
void SetUp ()
 Enable this interface. More...
 
- Public Member Functions inherited from ns3::Object
 Object ()
 Constructor. More...
 
 ~Object () override
 Destructor. More...
 
void AggregateObject (Ptr< Object > other)
 Aggregate two Objects together. More...
 
void Dispose ()
 Dispose of this Object. More...
 
AggregateIterator GetAggregateIterator () const
 Get an iterator to the Objects aggregated to this one. More...
 
TypeId GetInstanceTypeId () const override
 Get the most derived TypeId for this Object. More...
 
template<typename T >
Ptr< T > GetObject () const
 Get a pointer to the requested aggregated Object. More...
 
template<>
Ptr< ObjectGetObject () const
 Specialization of () for objects of type ns3::Object. More...
 
template<typename T >
Ptr< T > GetObject (TypeId tid) const
 Get a pointer to the requested aggregated Object by TypeId. More...
 
template<>
Ptr< ObjectGetObject (TypeId tid) const
 Specialization of (TypeId tid) for objects of type ns3::Object. More...
 
void Initialize ()
 Invoke DoInitialize on all Objects aggregated to this one. More...
 
bool IsInitialized () const
 Check if the object has been initialized. More...
 
- Public Member Functions inherited from ns3::SimpleRefCount< Object, ObjectBase, ObjectDeleter >
 SimpleRefCount ()
 Default constructor. More...
 
 SimpleRefCount (const SimpleRefCount &o[[maybe_unused]])
 Copy constructor. More...
 
uint32_t GetReferenceCount () const
 Get the reference count of the object. More...
 
SimpleRefCountoperator= (const SimpleRefCount &o[[maybe_unused]])
 Assignment operator. More...
 
void Ref () const
 Increment the reference count. More...
 
void Unref () const
 Decrement the reference count. More...
 
- Public Member Functions inherited from ns3::ObjectBase
virtual ~ObjectBase ()
 Virtual destructor. More...
 
void GetAttribute (std::string name, AttributeValue &value) const
 Get the value of an attribute, raising fatal errors if unsuccessful. More...
 
bool GetAttributeFailSafe (std::string name, AttributeValue &value) const
 Get the value of an attribute without raising errors. More...
 
void SetAttribute (std::string name, const AttributeValue &value)
 Set a single attribute, raising fatal errors if unsuccessful. More...
 
bool SetAttributeFailSafe (std::string name, const AttributeValue &value)
 Set a single attribute without raising errors. More...
 
bool TraceConnect (std::string name, std::string context, const CallbackBase &cb)
 Connect a TraceSource to a Callback with a context. More...
 
bool TraceConnectWithoutContext (std::string name, const CallbackBase &cb)
 Connect a TraceSource to a Callback without a context. More...
 
bool TraceDisconnect (std::string name, std::string context, const CallbackBase &cb)
 Disconnect from a TraceSource a Callback previously connected with a context. More...
 
bool TraceDisconnectWithoutContext (std::string name, const CallbackBase &cb)
 Disconnect from a TraceSource a Callback previously connected without a context. More...
 

Static Public Member Functions

static TypeId GetTypeId ()
 Get the type ID. More...
 
- Static Public Member Functions inherited from ns3::Object
static TypeId GetTypeId ()
 Register this type. More...
 
- Static Public Member Functions inherited from ns3::ObjectBase
static TypeId GetTypeId ()
 Get the type ID. More...
 

Protected Member Functions

void DoDispose () override
 Destructor implementation. More...
 
- Protected Member Functions inherited from ns3::Object
 Object (const Object &o)
 Copy an Object. More...
 
virtual void DoInitialize ()
 Initialize() implementation. More...
 
virtual void NotifyNewAggregate ()
 Notify all Objects aggregated to this one of a new Object being aggregated. More...
 
- Protected Member Functions inherited from ns3::ObjectBase
void ConstructSelf (const AttributeConstructionList &attributes)
 Complete construction of ObjectBase; invoked by derived classes. More...
 
virtual void NotifyConstructionCompleted ()
 Notifier called once the ObjectBase is fully constructed. More...
 

Private Types

typedef std::list< Ipv4InterfaceAddressIpv4InterfaceAddressList
 Container for the Ipv4InterfaceAddresses. More...
 
typedef std::list< Ipv4InterfaceAddress >::const_iterator Ipv4InterfaceAddressListCI
 Container Iterator for the Ipv4InterfaceAddresses. More...
 
typedef std::list< Ipv4InterfaceAddress >::iterator Ipv4InterfaceAddressListI
 Const Container Iterator for the Ipv4InterfaceAddresses. More...
 

Private Member Functions

void DoSetup ()
 Initialize interface. More...
 

Private Attributes

Callback< void, Ptr< Ipv4Interface >, Ipv4InterfaceAddressm_addAddressCallback
 add address callback More...
 
Ptr< ArpCachem_cache
 ARP cache. More...
 
Ptr< NetDevicem_device
 The associated NetDevice. More...
 
bool m_forwarding
 Forwarding state. More...
 
Ipv4InterfaceAddressList m_ifaddrs
 Address list. More...
 
bool m_ifup
 The state of this interface. More...
 
uint16_t m_metric
 Interface metric. More...
 
Ptr< Nodem_node
 The associated node. More...
 
Callback< void, Ptr< Ipv4Interface >, Ipv4InterfaceAddressm_removeAddressCallback
 remove address callback More...
 
Ptr< TrafficControlLayerm_tc
 The associated TrafficControlLayer. More...
 

Additional Inherited Members

Detailed Description

The IPv4 representation of a network interface.

This class roughly corresponds to the struct in_device of Linux; the main purpose is to provide address-family specific information (addresses) about an interface.

By default, Ipv4 interface are created in the "down" state no IP addresses. Before becoming usable, the user must add an address of some type and invoke Setup on them.

Definition at line 54 of file ipv4-interface.h.

Member Typedef Documentation

◆ Ipv4InterfaceAddressList

Container for the Ipv4InterfaceAddresses.

Definition at line 228 of file ipv4-interface.h.

◆ Ipv4InterfaceAddressListCI

Container Iterator for the Ipv4InterfaceAddresses.

Definition at line 233 of file ipv4-interface.h.

◆ Ipv4InterfaceAddressListI

Const Container Iterator for the Ipv4InterfaceAddresses.

Definition at line 238 of file ipv4-interface.h.

Constructor & Destructor Documentation

◆ Ipv4Interface() [1/2]

ns3::Ipv4Interface::Ipv4Interface ( )

By default, Ipv4 interface are created in the "down" state with no IP addresses.

Before becoming usable, the user must invoke SetUp on them once an Ipv4 address and mask have been set.

Definition at line 63 of file ipv4-interface.cc.

References NS_LOG_FUNCTION.

◆ ~Ipv4Interface()

ns3::Ipv4Interface::~Ipv4Interface ( )
override

Definition at line 75 of file ipv4-interface.cc.

References NS_LOG_FUNCTION.

◆ Ipv4Interface() [2/2]

ns3::Ipv4Interface::Ipv4Interface ( const Ipv4Interface )
delete

Member Function Documentation

◆ AddAddress()

bool ns3::Ipv4Interface::AddAddress ( Ipv4InterfaceAddress  address)
Parameters
addressThe Ipv4InterfaceAddress to add to the interface
Returns
true if succeeded

Definition at line 322 of file ipv4-interface.cc.

References m_addAddressCallback, m_ifaddrs, and NS_LOG_FUNCTION.

Referenced by ns3::Ipv4L3ClickProtocol::AddAddress(), ns3::Ipv4L3Protocol::AddAddress(), AddIpv4Address(), DynamicNeighborCacheTest::AddIpv4Address(), and DynamicPartialTest::AddIpv4Address().

+ Here is the caller graph for this function:

◆ AddAddressCallback()

void ns3::Ipv4Interface::AddAddressCallback ( Callback< void, Ptr< Ipv4Interface >, Ipv4InterfaceAddress addAddressCallback)

This callback is set when an address is added from an interface with auto-generated Arp cache and it allow the neighbor cache helper to update neighbor's Arp cache.

Parameters
addAddressCallbackCallback when remove an address.

Definition at line 423 of file ipv4-interface.cc.

References m_addAddressCallback, and NS_LOG_FUNCTION.

Referenced by ns3::NeighborCacheHelper::PopulateNeighborEntriesIpv4().

+ Here is the caller graph for this function:

◆ DoDispose()

void ns3::Ipv4Interface::DoDispose ( void  )
overrideprotectedvirtual

Destructor implementation.

This method is called by Dispose() or by the Object's destructor, whichever comes first.

Subclasses are expected to implement their real destruction code in an overridden version of this method and chain up to their parent's implementation once they are done. i.e, for simplicity, the destructor of every subclass should be empty and its content should be moved to the associated DoDispose() method.

It is safe to call GetObject() from within this method.

Reimplemented from ns3::Object.

Definition at line 81 of file ipv4-interface.cc.

References ns3::Object::DoDispose(), m_cache, m_device, m_node, m_tc, and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

◆ DoSetup()

void ns3::Ipv4Interface::DoSetup ( )
private

Initialize interface.

Definition at line 115 of file ipv4-interface.cc.

References ns3::Object::GetObject(), m_cache, m_device, m_node, and NS_LOG_FUNCTION.

Referenced by SetDevice(), and SetNode().

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

◆ GetAddress()

◆ GetArpCache()

Ptr< ArpCache > ns3::Ipv4Interface::GetArpCache ( ) const
Returns
ARP cache used by this interface

Definition at line 159 of file ipv4-interface.cc.

References m_cache, and NS_LOG_FUNCTION.

Referenced by ns3::NeighborCacheHelper::AddEntry(), FlushTest::DoRun(), ns3::NeighborCacheHelper::FlushAutoGenerated(), GetTypeId(), ns3::Ipv4L3Protocol::Receive(), and ns3::NeighborCacheHelper::UpdateCacheByIpv4AddressRemoved().

+ Here is the caller graph for this function:

◆ GetDevice()

◆ GetMetric()

uint16_t ns3::Ipv4Interface::GetMetric ( ) const
Returns
configured routing metric (cost) of this interface

Note: This is synonymous to the Metric value that ifconfig prints out. It is used by ns-3 global routing, but other routing daemons may choose to ignore it.

Definition at line 145 of file ipv4-interface.cc.

References m_metric, and NS_LOG_FUNCTION.

Referenced by ns3::Ipv4L3ClickProtocol::GetMetric(), and ns3::Ipv4L3Protocol::GetMetric().

+ Here is the caller graph for this function:

◆ GetNAddresses()

◆ GetTypeId()

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

Get the type ID.

Returns
type ID

Definition at line 43 of file ipv4-interface.cc.

References GetArpCache(), ns3::MakePointerAccessor(), SetArpCache(), and ns3::TypeId::SetParent().

+ Here is the call graph for this function:

◆ IsDown()

bool ns3::Ipv4Interface::IsDown ( ) const
Returns
true if this interface is disabled, false otherwise.

Definition at line 178 of file ipv4-interface.cc.

References m_ifup, and NS_LOG_FUNCTION.

◆ IsForwarding()

bool ns3::Ipv4Interface::IsForwarding ( ) const
Returns
true if this interface is enabled for IP forwarding of input datagrams

Definition at line 199 of file ipv4-interface.cc.

References m_forwarding, and NS_LOG_FUNCTION.

◆ IsUp()

bool ns3::Ipv4Interface::IsUp ( ) const

These are IP interface states and may be distinct from NetDevice states, such as found in real implementations (where the device may be down but IP interface state is still up).

Returns
true if this interface is enabled, false otherwise.

Definition at line 171 of file ipv4-interface.cc.

References m_ifup, and NS_LOG_FUNCTION.

Referenced by ns3::Ipv4L3ClickProtocol::IsUp(), ns3::Ipv4L3Protocol::IsUp(), ns3::Ipv4L3ClickProtocol::Receive(), ns3::Ipv4L3Protocol::Receive(), Send(), and ns3::Ipv4L3Protocol::SendRealOut().

+ Here is the caller graph for this function:

◆ operator=()

Ipv4Interface& ns3::Ipv4Interface::operator= ( const Ipv4Interface )
delete

◆ RemoveAddress() [1/2]

Ipv4InterfaceAddress ns3::Ipv4Interface::RemoveAddress ( Ipv4Address  address)

Remove the given Ipv4 address from the interface.

Parameters
addressThe Ipv4 address to remove
Returns
The removed Ipv4 interface address
The null interface address if the interface did not contain the address or if loopback address was passed as argument

Definition at line 388 of file ipv4-interface.cc.

References first::address, ns3::Ipv4Address::GetLoopback(), m_ifaddrs, m_removeAddressCallback, NS_LOG_FUNCTION, and NS_LOG_WARN.

+ Here is the call graph for this function:

◆ RemoveAddress() [2/2]

Ipv4InterfaceAddress ns3::Ipv4Interface::RemoveAddress ( uint32_t  index)
Parameters
indexIndex of Ipv4InterfaceAddress to remove
Returns
The Ipv4InterfaceAddress address whose index is index

Definition at line 358 of file ipv4-interface.cc.

References m_ifaddrs, m_removeAddressCallback, NS_FATAL_ERROR, and NS_LOG_FUNCTION.

Referenced by RemoveIpv4Address(), DynamicNeighborCacheTest::RemoveIpv4Address(), and DynamicPartialTest::RemoveIpv4Address().

+ Here is the caller graph for this function:

◆ RemoveAddressCallback()

void ns3::Ipv4Interface::RemoveAddressCallback ( Callback< void, Ptr< Ipv4Interface >, Ipv4InterfaceAddress removeAddressCallback)

This callback is set when an address is removed from an interface with auto-generated Arp cache and it allow the neighbor cache helper to update neighbor's Arp cache.

Parameters
removeAddressCallbackCallback when remove an address.

Definition at line 415 of file ipv4-interface.cc.

References m_removeAddressCallback, and NS_LOG_FUNCTION.

Referenced by ns3::NeighborCacheHelper::PopulateNeighborEntriesIpv4().

+ Here is the caller graph for this function:

◆ Send()

void ns3::Ipv4Interface::Send ( Ptr< Packet p,
const Ipv4Header hdr,
Ipv4Address  dest 
)
Parameters
ppacket to send
hdrIPv4 header
destnext hop address of packet.

This method will eventually call the private SendTo method which must be implemented by subclasses.

Todo:
additional checks needed here (such as whether multicast goes to loopback)?

Definition at line 213 of file ipv4-interface.cc.

References ns3::Packet::AddHeader(), ns3::Object::GetObject(), ns3::Ipv4Address::IsBroadcast(), ns3::Ipv4Address::IsMulticast(), ns3::Ipv4Address::IsSubnetDirectedBroadcast(), IsUp(), m_cache, m_device, m_ifaddrs, m_node, m_tc, NS_ASSERT, NS_ASSERT_MSG, NS_LOG_FUNCTION, NS_LOG_LOGIC, ns3::NetDevice::PACKET_HOST, ns3::Ipv4L3Protocol::PROT_NUMBER, ns3::TrafficControlLayer::Receive(), and ns3::Simulator::ScheduleNow().

Referenced by ns3::ArpL3Protocol::Receive(), and ns3::Ipv4L3Protocol::SendRealOut().

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

◆ SetArpCache()

void ns3::Ipv4Interface::SetArpCache ( Ptr< ArpCache arpCache)

Set ARP cache used by this interface.

Parameters
arpCachethe ARP cache

Definition at line 152 of file ipv4-interface.cc.

References m_cache, and NS_LOG_FUNCTION.

Referenced by GetTypeId().

+ Here is the caller graph for this function:

◆ SetDevice()

void ns3::Ipv4Interface::SetDevice ( Ptr< NetDevice device)

Set the NetDevice.

Parameters
deviceNetDevice

Definition at line 100 of file ipv4-interface.cc.

References DoSetup(), m_device, and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

◆ SetDown()

void ns3::Ipv4Interface::SetDown ( )

Disable this interface.

Definition at line 192 of file ipv4-interface.cc.

References m_ifup, and NS_LOG_FUNCTION.

Referenced by ns3::Ipv4L3ClickProtocol::SetDown(), and ns3::Ipv4L3Protocol::SetDown().

+ Here is the caller graph for this function:

◆ SetForwarding()

void ns3::Ipv4Interface::SetForwarding ( bool  val)
Parameters
valWhether to enable or disable IP forwarding for input datagrams

Definition at line 206 of file ipv4-interface.cc.

References m_forwarding, and NS_LOG_FUNCTION.

Referenced by ns3::Ipv4L3ClickProtocol::SetForwarding(), and ns3::Ipv4L3Protocol::SetForwarding().

+ Here is the caller graph for this function:

◆ SetMetric()

void ns3::Ipv4Interface::SetMetric ( uint16_t  metric)
Parameters
metricconfigured routing metric (cost) of this interface

Note: This is synonymous to the Metric value that ifconfig prints out. It is used by ns-3 global routing, but other routing daemons choose to ignore it.

Definition at line 138 of file ipv4-interface.cc.

References m_metric, and NS_LOG_FUNCTION.

Referenced by ns3::Ipv4L3ClickProtocol::SetMetric(), and ns3::Ipv4L3Protocol::SetMetric().

+ Here is the caller graph for this function:

◆ SetNode()

void ns3::Ipv4Interface::SetNode ( Ptr< Node node)

Set node associated with interface.

Parameters
nodenode

Definition at line 92 of file ipv4-interface.cc.

References DoSetup(), m_node, and NS_LOG_FUNCTION.

Referenced by ns3::Ipv4L3ClickProtocol::AddInterface(), and ns3::Ipv4L3Protocol::AddInterface().

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

◆ SetTrafficControl()

void ns3::Ipv4Interface::SetTrafficControl ( Ptr< TrafficControlLayer tc)

Set the TrafficControlLayer.

Parameters
tcTrafficControlLayer object

Definition at line 108 of file ipv4-interface.cc.

References m_tc, and NS_LOG_FUNCTION.

◆ SetUp()

void ns3::Ipv4Interface::SetUp ( )

Enable this interface.

Definition at line 185 of file ipv4-interface.cc.

References m_ifup, and NS_LOG_FUNCTION.

Referenced by ns3::Ipv4L3ClickProtocol::SetUp(), and ns3::Ipv4L3Protocol::SetUp().

+ Here is the caller graph for this function:

Member Data Documentation

◆ m_addAddressCallback

Callback<void, Ptr<Ipv4Interface>, Ipv4InterfaceAddress> ns3::Ipv4Interface::m_addAddressCallback
private

add address callback

Definition at line 251 of file ipv4-interface.h.

Referenced by AddAddress(), and AddAddressCallback().

◆ m_cache

Ptr<ArpCache> ns3::Ipv4Interface::m_cache
private

ARP cache.

Definition at line 247 of file ipv4-interface.h.

Referenced by DoDispose(), DoSetup(), GetArpCache(), Send(), and SetArpCache().

◆ m_device

Ptr<NetDevice> ns3::Ipv4Interface::m_device
private

The associated NetDevice.

Definition at line 245 of file ipv4-interface.h.

Referenced by DoDispose(), DoSetup(), GetDevice(), Send(), and SetDevice().

◆ m_forwarding

bool ns3::Ipv4Interface::m_forwarding
private

Forwarding state.

Definition at line 241 of file ipv4-interface.h.

Referenced by IsForwarding(), and SetForwarding().

◆ m_ifaddrs

Ipv4InterfaceAddressList ns3::Ipv4Interface::m_ifaddrs
private

Address list.

Definition at line 243 of file ipv4-interface.h.

Referenced by AddAddress(), GetAddress(), GetNAddresses(), RemoveAddress(), and Send().

◆ m_ifup

bool ns3::Ipv4Interface::m_ifup
private

The state of this interface.

Definition at line 240 of file ipv4-interface.h.

Referenced by IsDown(), IsUp(), SetDown(), and SetUp().

◆ m_metric

uint16_t ns3::Ipv4Interface::m_metric
private

Interface metric.

Definition at line 242 of file ipv4-interface.h.

Referenced by GetMetric(), and SetMetric().

◆ m_node

Ptr<Node> ns3::Ipv4Interface::m_node
private

The associated node.

Definition at line 244 of file ipv4-interface.h.

Referenced by DoDispose(), DoSetup(), Send(), and SetNode().

◆ m_removeAddressCallback

Callback<void, Ptr<Ipv4Interface>, Ipv4InterfaceAddress> ns3::Ipv4Interface::m_removeAddressCallback
private

remove address callback

Definition at line 249 of file ipv4-interface.h.

Referenced by RemoveAddress(), and RemoveAddressCallback().

◆ m_tc

Ptr<TrafficControlLayer> ns3::Ipv4Interface::m_tc
private

The associated TrafficControlLayer.

Definition at line 246 of file ipv4-interface.h.

Referenced by DoDispose(), Send(), and SetTrafficControl().


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