Implement the Ipv4 layer. More...
#include <ipv4-l3-protocol.h>
Public Types | |
enum | DropReason { DROP_TTL_EXPIRED = 1, DROP_NO_ROUTE, DROP_BAD_CHECKSUM, DROP_INTERFACE_DOWN, DROP_ROUTE_ERROR } |
Reason why a packet has been dropped. More... | |
Public Member Functions | |
void | SetNode (Ptr< Node > node) |
void | SetRoutingProtocol (Ptr< Ipv4RoutingProtocol > routingProtocol) |
Register a new routing protocol to be used by this Ipv4 stack. | |
Ptr< Ipv4RoutingProtocol > | GetRoutingProtocol (void) const |
Get the routing protocol to be used by this Ipv4 stack. | |
Ptr< Socket > | CreateRawSocket (void) |
void | DeleteRawSocket (Ptr< Socket > socket) |
void | Insert (Ptr< Ipv4L4Protocol > protocol) |
Ptr< Ipv4L4Protocol > | GetProtocol (int protocolNumber) const |
void | Remove (Ptr< Ipv4L4Protocol > protocol) |
void | SetDefaultTtl (uint8_t ttl) |
void | Receive (Ptr< NetDevice > device, Ptr< const Packet > p, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType) |
void | Send (Ptr< Packet > packet, Ipv4Address source, Ipv4Address destination, uint8_t protocol, Ptr< Ipv4Route > route) |
uint32_t | AddInterface (Ptr< NetDevice > device) |
Ptr< Ipv4Interface > | GetInterface (uint32_t i) const |
uint32_t | GetNInterfaces (void) const |
int32_t | GetInterfaceForAddress (Ipv4Address addr) const |
Return the interface number of the interface that has been assigned the specified IP address. | |
int32_t | GetInterfaceForPrefix (Ipv4Address addr, 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. | |
int32_t | GetInterfaceForDevice (Ptr< const NetDevice > device) const |
bool | IsDestinationAddress (Ipv4Address address, uint32_t iif) const |
Determine whether address and interface corresponding to received packet can be accepted for local delivery. | |
bool | AddAddress (uint32_t i, Ipv4InterfaceAddress address) |
Ipv4InterfaceAddress | GetAddress (uint32_t interfaceIndex, uint32_t addressIndex) const |
uint32_t | GetNAddresses (uint32_t interface) const |
bool | RemoveAddress (uint32_t interfaceIndex, uint32_t addressIndex) |
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. | |
void | SetMetric (uint32_t i, uint16_t metric) |
uint16_t | GetMetric (uint32_t i) const |
uint16_t | GetMtu (uint32_t i) const |
bool | IsUp (uint32_t i) const |
void | SetUp (uint32_t i) |
void | SetDown (uint32_t i) |
bool | IsForwarding (uint32_t i) const |
void | SetForwarding (uint32_t i, bool val) |
Ptr< NetDevice > | GetNetDevice (uint32_t i) |
Static Public Member Functions | |
static TypeId | GetTypeId (void) |
This method returns the TypeId associated to ns3::Ipv4L3Protocol. | |
Static Public Attributes | |
static const uint16_t | PROT_NUMBER |
Protected Member Functions | |
virtual void | DoDispose (void) |
virtual void | NotifyNewAggregate () |
Friends | |
class | Ipv4L3ProtocolTestCase |
Implement the Ipv4 layer.
This is the actual implementation of IP. It contains APIs to send and receive packets at the IP layer, as well as APIs for IP routing.
This class contains two distinct groups of trace sources. The trace sources 'Rx' and 'Tx' are called, respectively, immediately after receiving from the NetDevice and immediately before sending to a NetDevice for transmitting a packet. These are low level trace sources that include the Ipv4Header already serialized into the packet. In contrast, the Drop, SendOutgoing, UnicastForward, and LocalDeliver trace sources are slightly higher-level and pass around the Ipv4Header as an explicit parameter and not as part of the packet.
Reason why a packet has been dropped.
DROP_TTL_EXPIRED |
Packet TTL has expired |
DROP_NO_ROUTE |
No route to host |
DROP_BAD_CHECKSUM |
Bad checksum |
DROP_INTERFACE_DOWN |
Interface is down so can not send packet |
DROP_ROUTE_ERROR |
Route error |
bool ns3::Ipv4L3Protocol::AddAddress | ( | uint32_t | interface, | |
Ipv4InterfaceAddress | address | |||
) | [virtual] |
interface | Interface number of an Ipv4 interface | |
address | Ipv4InterfaceAddress address to associate with the underlying Ipv4 interface |
Implements ns3::Ipv4.
device | device to add to the list of Ipv4 interfaces which can be used as output interfaces during packet forwarding. |
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.
Implements ns3::Ipv4.
virtual void ns3::Ipv4L3Protocol::DoDispose | ( | void | ) | [protected, virtual] |
This method is called by Object::Dispose or by the object's destructor, whichever comes first.
Subclasses are expected to implement their real destruction code in an overriden 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.
Ipv4InterfaceAddress ns3::Ipv4L3Protocol::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.
interface | Interface number of an Ipv4 interface | |
addressIndex | index of Ipv4InterfaceAddress |
Implements ns3::Ipv4.
int32_t ns3::Ipv4L3Protocol::GetInterfaceForAddress | ( | Ipv4Address | address | ) | const [virtual] |
Return the interface number of the interface that has been assigned the specified IP address.
address | The IP address being searched for |
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.
Implements ns3::Ipv4.
int32_t ns3::Ipv4L3Protocol::GetInterfaceForDevice | ( | Ptr< const NetDevice > | device | ) | const [virtual] |
device | The NetDevice for an Ipv4Interface |
Implements ns3::Ipv4.
int32_t ns3::Ipv4L3Protocol::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.
address | The IP address assigned to the interface of interest. | |
mask | The IP prefix to use in the mask |
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.
Implements ns3::Ipv4.
uint16_t ns3::Ipv4L3Protocol::GetMetric | ( | uint32_t | interface | ) | const [virtual] |
uint16_t ns3::Ipv4L3Protocol::GetMtu | ( | uint32_t | interface | ) | const [virtual] |
uint32_t ns3::Ipv4L3Protocol::GetNAddresses | ( | uint32_t | interface | ) | const [virtual] |
interface | Interface number of an Ipv4 interface |
Implements ns3::Ipv4.
uint32_t ns3::Ipv4L3Protocol::GetNInterfaces | ( | void | ) | const [virtual] |
Implements ns3::Ipv4.
Ptr<Ipv4L4Protocol> ns3::Ipv4L3Protocol::GetProtocol | ( | int | protocolNumber | ) | const |
protocolNumber | number of protocol to lookup in this L4 Demux |
This method is typically called by lower layers to forward packets up the stack to the right protocol. It is also called from NodeImpl::GetUdp for example.
Ptr<Ipv4RoutingProtocol> ns3::Ipv4L3Protocol::GetRoutingProtocol | ( | void | ) | const [virtual] |
Get the routing protocol to be used by this Ipv4 stack.
Implements ns3::Ipv4.
static TypeId ns3::Ipv4L3Protocol::GetTypeId | ( | void | ) | [static] |
This method returns the TypeId associated to ns3::Ipv4L3Protocol.
This object is accessible through the following paths with Config::Set and Config::Connect:
Attributes defined for this type:
Attributes defined in parent class ns3::Ipv4:
TraceSources defined for this type:
Reimplemented from ns3::Ipv4.
void ns3::Ipv4L3Protocol::Insert | ( | Ptr< Ipv4L4Protocol > | protocol | ) |
protocol | a template for the protocol to add to this L4 Demux. |
Invoke Copy on the input template to get a copy of the input protocol which can be used on the Node on which this L4 Demux is running. The new L4Protocol is registered internally as a working L4 Protocol and returned from this method. The caller does not get ownership of the returned pointer.
bool ns3::Ipv4L3Protocol::IsDestinationAddress | ( | Ipv4Address | address, | |
uint32_t | iif | |||
) | const [virtual] |
Determine whether address and interface corresponding to received packet can be accepted for local delivery.
address | The IP address being considered | |
iif | The 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.
Implements ns3::Ipv4.
bool ns3::Ipv4L3Protocol::IsForwarding | ( | uint32_t | interface | ) | const [virtual] |
bool ns3::Ipv4L3Protocol::IsUp | ( | uint32_t | interface | ) | const [virtual] |
virtual void ns3::Ipv4L3Protocol::NotifyNewAggregate | ( | ) | [protected, virtual] |
This function will notify other components connected to the node that a new stack member is now connected This will be used to notify Layer 3 protocol of layer 4 protocol stack to connect them together.
Reimplemented from ns3::Object.
void ns3::Ipv4L3Protocol::Receive | ( | Ptr< NetDevice > | device, | |
Ptr< const Packet > | p, | |||
uint16_t | protocol, | |||
const Address & | from, | |||
const Address & | to, | |||
NetDevice::PacketType | packetType | |||
) |
Lower layer calls this method after calling L3Demux::Lookup The ARP subclass needs to know from which NetDevice this packet is coming to:
device | network device | |
p | the packet | |
protocol | protocol value | |
from | address of the correspondant | |
to | address of the destination | |
packetType | type of the packet |
void ns3::Ipv4L3Protocol::Remove | ( | Ptr< Ipv4L4Protocol > | protocol | ) |
protocol | protocol to remove from this demux. |
The input value to this method should be the value returned from the Ipv4L4Protocol::Insert method.
bool ns3::Ipv4L3Protocol::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.
interface | Interface number of an Ipv4 interface | |
addressIndex | index of Ipv4InterfaceAddress to remove |
Implements ns3::Ipv4.
Ipv4Address ns3::Ipv4L3Protocol::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.
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.
device | output NetDevice (optionally provided, only to constrain the search) | |
dst | Destination address to match, if device is provided | |
scope | Scope of returned address must be less than or equal to this |
Implements ns3::Ipv4.
void ns3::Ipv4L3Protocol::Send | ( | Ptr< Packet > | packet, | |
Ipv4Address | source, | |||
Ipv4Address | destination, | |||
uint8_t | protocol, | |||
Ptr< Ipv4Route > | route | |||
) |
packet | packet to send | |
source | source address of packet | |
destination | address of packet | |
protocol | number of packet | |
route | route entry |
Higher-level layers call this method to send a packet down the stack to the MAC and PHY layers.
void ns3::Ipv4L3Protocol::SetDefaultTtl | ( | uint8_t | ttl | ) |
ttl | default ttl to use |
When we need to send an ipv4 packet, we use this default ttl value.
void ns3::Ipv4L3Protocol::SetDown | ( | uint32_t | interface | ) | [virtual] |
void ns3::Ipv4L3Protocol::SetForwarding | ( | uint32_t | interface, | |
bool | val | |||
) | [virtual] |
void ns3::Ipv4L3Protocol::SetMetric | ( | uint32_t | interface, | |
uint16_t | metric | |||
) | [virtual] |
void ns3::Ipv4L3Protocol::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.
routingProtocol | smart pointer to Ipv4RoutingProtocol object |
Implements ns3::Ipv4.
void ns3::Ipv4L3Protocol::SetUp | ( | uint32_t | interface | ) | [virtual] |