IPv4

Package: inet.networklayer.ipv4

IPv4

simple module

Implements the IPv4 protocol. The protocol header is represented by the IPv4Datagram message class.

Interfacing with higher layer protocols

To send a packet over IPv4 from a higher layer protocol, the module should fill in an IPv4ControlInfo object, attach it to the packet with cMessage's setControlInfo() method, the send it to the IPv4 module.

When IPv4 sends up a packet to a higher layer protocol, it will also attach an IPv4ControlInfo to the packet, with the source and destination IPv4 address, etc. of the IPv4 datagram in which the packet arrived.

IPv4 can serve several higher-layer protocols. The higher layer protocols should send one or more RegisterProtocol message (a simple cMessage with IPRegisterProtocolCommand controlinfo and kind=IP_C_REGISTER_PROTOCOL) to IPv4 module, for fill up the protocol-to-gateindex map. When delivering packets to them, the output gate is determined from the Protocol field in the IPv4 header.

Routing and interfacing with lower layers

The routing table is stored in the module IPv4RoutingTable. When a datagram needs to be routed, IPv4 queries IPv4RoutingTable for the output interface (or "port") and next hop address of the packet. This is done by directly calling C++ methods (such as findBestMatchingRoute(destAddress)) of IPv4RoutingTable. No message exchange with IPv4RoutingTable takes place.

A routed datagram will be sent to the queueOut gate, with an IPv4ControlInfo object attached. queueOut is expected to be connected to INic modules.

Routing protocol implementations (e.g. OSPF and ISIS) can also query and manipulate the route table by calling IPv4RoutingTable's methods in C++.

Working with ARP

IPv4 module subscribe to completedARPResolution and failedARPResolution signals on ARP module. The ARP module accessed via arpOut gate, should not insert any module between IPv4 and ARP. Before IPv4 module send down a packet to lower layer, ask MACAddress of next hop from ARP via method call. If MACAddress unspecified, then start address resolution via ARP method call and insert packet to a queue specified by next hop addr. When received a completedARPResolution, then send packets from queue of next hop addr. When received a failedARPResolution, then drop packets from queue of next hop addr. When IPv4 module received an ARP packet from Lower Layer on some queueIn gate, then send out this packet on arpOut gate. When received a packet on arpIn gate, then send out this packet on the specified queueOut gate.

Performance model, QoS

In the current form, IPv4 contains a FIFO which queues up IPv4 datagrams; datagrams are processed in order. The processing time is determined by the procDelay module parameter.

The current performance model comes from the QueueBase C++ base class. If you need a more sophisticated performance model, you may change the module implementation (the IPv4 class), and: (1) override the startService() method which determines processing time for a packet, or (2) use a different base class.

See also: IPv4RoutingTable, IPv4ControlInfo, ARP

Author: Andras Varga

Used in compound modules

Name Type Description
IPv4NetworkLayer compound module

Network layer of an IPv4 node.

Parameters

Name Type Default value Description
interfaceTableModule string

The path to the InterfaceTable module

routingTableModule string
arpModule string
icmpModule string
procDelay double 0s
timeToLive int 32
multicastTimeToLive int 32
fragmentTimeout double 60s
forceBroadcast bool false
useProxyARP bool true

Properties

Name Value Description
display i=block/routing

Gates

Name Direction Size Description
transportIn [ ] input
transportOut [ ] output
arpIn input
arpOut output
queueIn [ ] input
queueOut [ ] output

Signals

Name Type Unit
NF_IPv4_MDATA_REGISTER inet::IPv4Datagram
NF_IPv4_NEW_MULTICAST inet::IPv4Datagram
packetReceivedFromUpper cPacket
packetReceivedFromLower cPacket
packetFromLowerDropped cPacket
packetFromUpperDropped cPacket
packetSentToLower cPacket
NF_IPv4_DATA_ON_NONRPF inet::IPv4Datagram
NF_IPv4_DATA_ON_RPF inet::IPv4Datagram
packetSentToUpper cPacket

Source code

//
// Implements the IPv4 protocol. The protocol header is represented
// by the ~IPv4Datagram message class.
//
// <b>Interfacing with higher layer protocols</b>
//
// To send a packet over IPv4 from a higher layer protocol, the module should
// fill in an ~IPv4ControlInfo object, attach it to the packet with cMessage's
// setControlInfo() method, the send it to the ~IPv4 module.
//
// When ~IPv4 sends up a packet to a higher layer protocol, it will also attach
// an ~IPv4ControlInfo to the packet, with the source and destination IPv4 address,
// etc. of the IPv4 datagram in which the packet arrived.
//
// ~IPv4 can serve several higher-layer protocols. The higher layer protocols should
// send one or more RegisterProtocol message (a simple cMessage with
// ~IPRegisterProtocolCommand controlinfo and kind=IP_C_REGISTER_PROTOCOL)
// to IPv4 module, for fill up the protocol-to-gateindex map.
// When delivering packets to them, the output gate is determined from the Protocol
// field in the IPv4 header.
//
// <b>Routing and interfacing with lower layers</b>
//
// The routing table is stored in the module ~IPv4RoutingTable. When a datagram
// needs to be routed, ~IPv4 queries ~IPv4RoutingTable for the output interface
// (or "port") and next hop address of the packet. This is done by directly
// calling C++ methods (such as findBestMatchingRoute(destAddress)) of ~IPv4RoutingTable.
// No message exchange with ~IPv4RoutingTable takes place.
//
// A routed datagram will be sent to the queueOut gate, with an
// ~IPv4ControlInfo  object attached. queueOut is expected to be
// connected to ~INic modules.
//
// Routing protocol implementations (e.g. OSPF and ISIS) can also query
// and manipulate the route table by calling ~IPv4RoutingTable's methods in C++.
//
// <b>Working with ARP</b>
//
// IPv4 module subscribe to completedARPResolution and failedARPResolution signals on ARP module.
// The ARP module accessed via arpOut gate, should not insert any module between IPv4 and ARP.
// Before IPv4 module send down a packet to lower layer, ask MACAddress of next hop from ARP via
// method call. If MACAddress unspecified, then start address resolution via ARP method call and
// insert packet to a queue specified by next hop addr.
// When received a completedARPResolution, then send packets from queue of next hop addr.
// When received a failedARPResolution, then drop packets from queue of next hop addr.
// When IPv4 module received an ARP packet from Lower Layer on some queueIn gate,
// then send out this packet on arpOut gate. When received a packet on arpIn gate,
// then send out this packet on the specified queueOut gate.
//
// <b>Performance model, QoS</b>
//
// In the current form, ~IPv4 contains a FIFO which queues up IPv4 datagrams;
// datagrams are processed in order. The processing time is determined by the
// procDelay module parameter.
//
// The current performance model comes from the QueueBase C++ base class.
// If you need a more sophisticated performance model, you may change the
// module implementation (the IPv4 class), and: (1) override the startService()
// method which determines processing time for a packet, or (2) use a
// different base class.
//
// @see ~IPv4RoutingTable, ~IPv4ControlInfo, ~ARP
//
// @author Andras Varga
//
simple IPv4
{
    parameters:
        string interfaceTableModule;   // The path to the InterfaceTable module
        string routingTableModule;
        string arpModule;
        string icmpModule;
        double procDelay @unit("s") = default(0s);
        int timeToLive = default(32);
        int multicastTimeToLive = default(32);
        double fragmentTimeout @unit("s") = default(60s);
        bool forceBroadcast = default(false);
        bool useProxyARP = default(true);
        @display("i=block/routing");
        @signal[packetSentToUpper](type=cPacket);
        @signal[packetReceivedFromUpper](type=cPacket);
        @signal[packetFromUpperDropped](type=cPacket);
        @signal[packetSentToLower](type=cPacket);
        @signal[packetReceivedFromLower](type=cPacket);
        @signal[packetFromLowerDropped](type=cPacket);
        @signal[NF_IPv4_NEW_MULTICAST](type=inet::IPv4Datagram);
        @signal[NF_IPv4_DATA_ON_NONRPF](type=inet::IPv4Datagram);
        @signal[NF_IPv4_DATA_ON_RPF](type=inet::IPv4Datagram);
        @signal[NF_IPv4_MDATA_REGISTER](type=inet::IPv4Datagram);
    gates:
        input transportIn[] @labels(IPv4ControlInfo/down,TCPSegment,UDPPacket);
        output transportOut[] @labels(IPv4ControlInfo/up,TCPSegment,UDPPacket);
        input arpIn @labels(ARPPacket+Ieee802Ctrl);
        output arpOut @labels(ARPPacket+Ieee802Ctrl,IPv4Datagram+Ieee802Ctrl);
        input queueIn[] @labels(IPv4Datagram,ARPPacket,Ieee802Ctrl);
        output queueOut[] @labels(IPv4Datagram,ARPPacket,Ieee802Ctrl);
}
File: src/inet/networklayer/ipv4/IPv4.ned