The IPv4 representation of a network interface. More...
#include "ipv4-interface.h"
Public Member Functions | |
Ipv4Interface () | |
By default, Ipv4 interface are created in the "down" state with no IP addresses. | |
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. | |
Ipv4InterfaceAddress | GetAddress (uint32_t index) const |
Ptr< ArpCache > | GetArpCache () const |
Ptr< NetDevice > | GetDevice () 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). | |
Ipv4Interface & | operator= (const Ipv4Interface &)=delete |
Ipv4InterfaceAddress | RemoveAddress (Ipv4Address address) |
Remove the given Ipv4 address from the interface. | |
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. | |
void | Send (Ptr< Packet > p, const Ipv4Header &hdr, Ipv4Address dest) |
void | SetArpCache (Ptr< ArpCache > arpCache) |
Set ARP cache used by this interface. | |
void | SetDevice (Ptr< NetDevice > device) |
Set the NetDevice. | |
void | SetDown () |
Disable this interface. | |
void | SetForwarding (bool val) |
void | SetMetric (uint16_t metric) |
void | SetNode (Ptr< Node > node) |
Set node associated with interface. | |
void | SetTrafficControl (Ptr< TrafficControlLayer > tc) |
Set the TrafficControlLayer. | |
void | SetUp () |
Enable this interface. | |
Public Member Functions inherited from ns3::Object | |
Object () | |
Constructor. | |
~Object () override | |
Destructor. | |
void | AggregateObject (Ptr< Object > other) |
Aggregate two Objects together. | |
void | Dispose () |
Dispose of this Object. | |
AggregateIterator | GetAggregateIterator () const |
Get an iterator to the Objects aggregated to this one. | |
TypeId | GetInstanceTypeId () const override |
Get the most derived TypeId for this Object. | |
template<typename T > | |
Ptr< T > | GetObject () const |
Get a pointer to the requested aggregated Object. | |
template<> | |
Ptr< Object > | GetObject () const |
Specialization of () for objects of type ns3::Object. | |
template<typename T > | |
Ptr< T > | GetObject (TypeId tid) const |
Get a pointer to the requested aggregated Object by TypeId. | |
template<> | |
Ptr< Object > | GetObject (TypeId tid) const |
Specialization of (TypeId tid) for objects of type ns3::Object. | |
void | Initialize () |
Invoke DoInitialize on all Objects aggregated to this one. | |
bool | IsInitialized () const |
Check if the object has been initialized. | |
void | UnidirectionalAggregateObject (Ptr< Object > other) |
Aggregate an Object to another Object. | |
Public Member Functions inherited from ns3::SimpleRefCount< Object, ObjectBase, ObjectDeleter > | |
SimpleRefCount () | |
Default constructor. | |
SimpleRefCount (const SimpleRefCount &o) | |
Copy constructor. | |
uint32_t | GetReferenceCount () const |
Get the reference count of the object. | |
SimpleRefCount & | operator= (const SimpleRefCount &o) |
Assignment operator. | |
void | Ref () const |
Increment the reference count. | |
void | Unref () const |
Decrement the reference count. | |
Public Member Functions inherited from ns3::ObjectBase | |
virtual | ~ObjectBase () |
Virtual destructor. | |
void | GetAttribute (std::string name, AttributeValue &value, bool permissive=false) const |
Get the value of an attribute, raising fatal errors if unsuccessful. | |
bool | GetAttributeFailSafe (std::string name, AttributeValue &value) const |
Get the value of an attribute without raising errors. | |
void | SetAttribute (std::string name, const AttributeValue &value) |
Set a single attribute, raising fatal errors if unsuccessful. | |
bool | SetAttributeFailSafe (std::string name, const AttributeValue &value) |
Set a single attribute without raising errors. | |
bool | TraceConnect (std::string name, std::string context, const CallbackBase &cb) |
Connect a TraceSource to a Callback with a context. | |
bool | TraceConnectWithoutContext (std::string name, const CallbackBase &cb) |
Connect a TraceSource to a Callback without a context. | |
bool | TraceDisconnect (std::string name, std::string context, const CallbackBase &cb) |
Disconnect from a TraceSource a Callback previously connected with a context. | |
bool | TraceDisconnectWithoutContext (std::string name, const CallbackBase &cb) |
Disconnect from a TraceSource a Callback previously connected without a context. | |
Static Public Member Functions | |
static TypeId | GetTypeId () |
Get the type ID. | |
Static Public Member Functions inherited from ns3::Object | |
static TypeId | GetTypeId () |
Register this type. | |
Static Public Member Functions inherited from ns3::ObjectBase | |
static TypeId | GetTypeId () |
Get the type ID. | |
Protected Member Functions | |
void | DoDispose () override |
Destructor implementation. | |
Protected Member Functions inherited from ns3::Object | |
Object (const Object &o) | |
Copy an Object. | |
virtual void | DoInitialize () |
Initialize() implementation. | |
virtual void | NotifyNewAggregate () |
Notify all Objects aggregated to this one of a new Object being aggregated. | |
Protected Member Functions inherited from ns3::ObjectBase | |
void | ConstructSelf (const AttributeConstructionList &attributes) |
Complete construction of ObjectBase; invoked by derived classes. | |
virtual void | NotifyConstructionCompleted () |
Notifier called once the ObjectBase is fully constructed. | |
Private Types | |
typedef std::list< Ipv4InterfaceAddress > | Ipv4InterfaceAddressList |
Container for the Ipv4InterfaceAddresses. | |
typedef std::list< Ipv4InterfaceAddress >::const_iterator | Ipv4InterfaceAddressListCI |
Container Iterator for the Ipv4InterfaceAddresses. | |
typedef std::list< Ipv4InterfaceAddress >::iterator | Ipv4InterfaceAddressListI |
Const Container Iterator for the Ipv4InterfaceAddresses. | |
Private Member Functions | |
void | DoSetup () |
Initialize interface. | |
Private Attributes | |
Callback< void, Ptr< Ipv4Interface >, Ipv4InterfaceAddress > | m_addAddressCallback |
add address callback | |
Ptr< ArpCache > | m_cache |
ARP cache. | |
Ptr< NetDevice > | m_device |
The associated NetDevice. | |
bool | m_forwarding |
Forwarding state. | |
Ipv4InterfaceAddressList | m_ifaddrs |
Address list. | |
bool | m_ifup |
The state of this interface. | |
uint16_t | m_metric |
Interface metric. | |
Ptr< Node > | m_node |
The associated node. | |
Callback< void, Ptr< Ipv4Interface >, Ipv4InterfaceAddress > | m_removeAddressCallback |
remove address callback | |
Ptr< TrafficControlLayer > | m_tc |
The associated TrafficControlLayer. | |
Additional Inherited Members | |
Related Symbols inherited from ns3::ObjectBase | |
static TypeId | GetObjectIid () |
Ensure the TypeId for ObjectBase gets fully configured to anchor the inheritance tree properly. | |
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 43 of file ipv4-interface.h.
|
private |
Container for the Ipv4InterfaceAddresses.
Definition at line 217 of file ipv4-interface.h.
|
private |
Container Iterator for the Ipv4InterfaceAddresses.
Definition at line 222 of file ipv4-interface.h.
|
private |
Const Container Iterator for the Ipv4InterfaceAddresses.
Definition at line 227 of file ipv4-interface.h.
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 52 of file ipv4-interface.cc.
References NS_LOG_FUNCTION.
|
override |
Definition at line 64 of file ipv4-interface.cc.
References NS_LOG_FUNCTION.
|
delete |
bool ns3::Ipv4Interface::AddAddress | ( | Ipv4InterfaceAddress | address | ) |
address | The Ipv4InterfaceAddress to add to the interface |
Definition at line 311 of file ipv4-interface.cc.
References m_addAddressCallback, m_ifaddrs, and NS_LOG_FUNCTION.
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.
addAddressCallback | Callback when remove an address. |
Definition at line 412 of file ipv4-interface.cc.
References m_addAddressCallback, and NS_LOG_FUNCTION.
|
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 70 of file ipv4-interface.cc.
References ns3::Object::DoDispose(), m_cache, m_device, m_node, m_tc, and NS_LOG_FUNCTION.
|
private |
Initialize interface.
Definition at line 104 of file ipv4-interface.cc.
References ns3::Object::GetObject(), m_cache, m_device, m_node, and NS_LOG_FUNCTION.
Referenced by SetDevice(), and SetNode().
Ipv4InterfaceAddress ns3::Ipv4Interface::GetAddress | ( | uint32_t | index | ) | const |
index | Index of Ipv4InterfaceAddress to return |
Definition at line 323 of file ipv4-interface.cc.
References m_ifaddrs, NS_FATAL_ERROR, and NS_LOG_FUNCTION.
Definition at line 148 of file ipv4-interface.cc.
References m_cache, and NS_LOG_FUNCTION.
Referenced by GetTypeId().
Definition at line 120 of file ipv4-interface.cc.
References m_device, and NS_LOG_FUNCTION.
Referenced by ns3::Ipv4L3ClickProtocol::GetNetDevice(), and ns3::Ipv4L3Protocol::GetNetDevice().
uint16_t ns3::Ipv4Interface::GetMetric | ( | ) | const |
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 134 of file ipv4-interface.cc.
References m_metric, and NS_LOG_FUNCTION.
uint32_t ns3::Ipv4Interface::GetNAddresses | ( | ) | const |
Definition at line 304 of file ipv4-interface.cc.
References m_ifaddrs, and NS_LOG_FUNCTION.
|
static |
Get the type ID.
Definition at line 32 of file ipv4-interface.cc.
References GetArpCache(), ns3::MakePointerAccessor(), ns3::MakePointerChecker(), SetArpCache(), and ns3::TypeId::SetParent().
bool ns3::Ipv4Interface::IsDown | ( | ) | const |
Definition at line 167 of file ipv4-interface.cc.
References m_ifup, and NS_LOG_FUNCTION.
bool ns3::Ipv4Interface::IsForwarding | ( | ) | const |
Definition at line 188 of file ipv4-interface.cc.
References m_forwarding, and NS_LOG_FUNCTION.
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).
Definition at line 160 of file ipv4-interface.cc.
References m_ifup, and NS_LOG_FUNCTION.
Referenced by Send().
|
delete |
Ipv4InterfaceAddress ns3::Ipv4Interface::RemoveAddress | ( | Ipv4Address | address | ) |
Remove the given Ipv4 address from the interface.
address | The Ipv4 address to remove |
Definition at line 377 of file ipv4-interface.cc.
References ns3::Ipv4Address::GetLoopback(), m_ifaddrs, m_removeAddressCallback, NS_LOG_FUNCTION, and NS_LOG_WARN.
Ipv4InterfaceAddress ns3::Ipv4Interface::RemoveAddress | ( | uint32_t | index | ) |
index | Index of Ipv4InterfaceAddress to remove |
Definition at line 347 of file ipv4-interface.cc.
References m_ifaddrs, m_removeAddressCallback, NS_FATAL_ERROR, and NS_LOG_FUNCTION.
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.
removeAddressCallback | Callback when remove an address. |
Definition at line 404 of file ipv4-interface.cc.
References m_removeAddressCallback, and NS_LOG_FUNCTION.
void ns3::Ipv4Interface::Send | ( | Ptr< Packet > | p, |
const Ipv4Header & | hdr, | ||
Ipv4Address | dest ) |
p | packet to send |
hdr | IPv4 header |
dest | next hop address of packet. |
This method will eventually call the private SendTo method which must be implemented by subclasses.
Definition at line 202 of file ipv4-interface.cc.
References ns3::Create(), ns3::DynamicCast(), 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().
Set ARP cache used by this interface.
arpCache | the ARP cache |
Definition at line 141 of file ipv4-interface.cc.
References m_cache, and NS_LOG_FUNCTION.
Referenced by GetTypeId().
Set the NetDevice.
device | NetDevice |
Definition at line 89 of file ipv4-interface.cc.
References DoSetup(), m_device, and NS_LOG_FUNCTION.
void ns3::Ipv4Interface::SetDown | ( | ) |
Disable this interface.
Definition at line 181 of file ipv4-interface.cc.
References m_ifup, and NS_LOG_FUNCTION.
void ns3::Ipv4Interface::SetForwarding | ( | bool | val | ) |
val | Whether to enable or disable IP forwarding for input datagrams |
Definition at line 195 of file ipv4-interface.cc.
References m_forwarding, and NS_LOG_FUNCTION.
void ns3::Ipv4Interface::SetMetric | ( | uint16_t | metric | ) |
metric | 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 choose to ignore it.
Definition at line 127 of file ipv4-interface.cc.
References m_metric, and NS_LOG_FUNCTION.
Set node associated with interface.
node | node |
Definition at line 81 of file ipv4-interface.cc.
References DoSetup(), m_node, and NS_LOG_FUNCTION.
Referenced by ns3::Ipv4L3ClickProtocol::AddInterface(), and ns3::Ipv4L3Protocol::AddInterface().
void ns3::Ipv4Interface::SetTrafficControl | ( | Ptr< TrafficControlLayer > | tc | ) |
Set the TrafficControlLayer.
tc | TrafficControlLayer object |
Definition at line 97 of file ipv4-interface.cc.
References m_tc, and NS_LOG_FUNCTION.
void ns3::Ipv4Interface::SetUp | ( | ) |
Enable this interface.
Definition at line 174 of file ipv4-interface.cc.
References m_ifup, and NS_LOG_FUNCTION.
|
private |
add address callback
Definition at line 240 of file ipv4-interface.h.
Referenced by AddAddress(), and AddAddressCallback().
ARP cache.
Definition at line 236 of file ipv4-interface.h.
Referenced by DoDispose(), DoSetup(), GetArpCache(), Send(), and SetArpCache().
The associated NetDevice.
Definition at line 234 of file ipv4-interface.h.
Referenced by DoDispose(), DoSetup(), GetDevice(), Send(), and SetDevice().
|
private |
Forwarding state.
Definition at line 230 of file ipv4-interface.h.
Referenced by IsForwarding(), and SetForwarding().
|
private |
Address list.
Definition at line 232 of file ipv4-interface.h.
Referenced by AddAddress(), GetAddress(), GetNAddresses(), RemoveAddress(), RemoveAddress(), and Send().
|
private |
|
private |
Interface metric.
Definition at line 231 of file ipv4-interface.h.
Referenced by GetMetric(), and SetMetric().
The associated node.
Definition at line 233 of file ipv4-interface.h.
Referenced by DoDispose(), DoSetup(), Send(), and SetNode().
|
private |
remove address callback
Definition at line 238 of file ipv4-interface.h.
Referenced by RemoveAddress(), RemoveAddress(), and RemoveAddressCallback().
|
private |
The associated TrafficControlLayer.
Definition at line 235 of file ipv4-interface.h.
Referenced by DoDispose(), Send(), and SetTrafficControl().