Udp

Package: inet.transportlayer.udp

Udp

simple module

UDP protocol implementation, for IPv4 (Ipv4) and IPv6 (Ipv6).

The UDP protocol header is represented by the class UdpHeader.

Communication with clients (applications)

The module can (should) be connected to several applications. For sending an UDP packet, the application should attach an UdpControlInfo object to the payload, and send it to Udp. Udp will also attach an UdpControlInfo object to any payload message in sends up to the application.

For receiving Udp packets, the connected applications should first "bind" to the given UDP port. This can be done by sending an arbitrary message with message kind UDP_C_BIND and an UdpControlInfo attached with srcPort filled in.

When UDP receives an ICMP error (IcmpHeader or Icmpv6Header) that refers to an UDP socket, it reports the error to the corresponding application by sending a message with kind UDP_I_ERROR.

Communication with the IP (IPv4/IPv6) layer

The Udp model relies on sending and receiving L3AddressReq/L3AddressInd tags attached to UDP packets.

CRC operation modes for outgoing UDP packets (crcMode parameter in UDP module):

  • "disabled" means the outgoing packet will have its CRC set to 0 (serializable)
  • "declared" means the outgoing packet will have the correct CRC declared without actually computing it, the value is set to 0xC00D (not serializable)
  • "computed" means the outgoing packet will have the correctly computed CRC as defined by the RFC (serializable) CRC operation modes for incoming UDP packets (crcMode field in UdpHeader chunk):
  • CRC_DISABLED means the incoming packet must have its CRC set to 0 (serializable)
  • CRC_DECLARED_CORRECT means the incoming packet is assumed to have a correct CRC without the actual value (not serializable)
  • CRC_DECLARED_INCORRECT means the incoming packet is assumed to have an incorrect CRC without the actual value (not serializable)
  • CRC_COMPUTED means the incoming packet has a potentially incorrect CRC that is to be verified as defined by the RFC (serializable) The incoming packet also fails the CRC verification if any relevant chunk is marked incorrect.

See also: UdpHeader, UdpControlInfo, UdpCommandCode

Udp

Inheritance diagram

The following diagram shows inheritance relationships for this type. Unresolved types are missing from the diagram.

Parameters

Name Type Default value Description
interfaceTableModule string

The path to the InterfaceTable module

icmpModule string "^.ipv4.icmp"
icmpv6Module string "^.ipv6.icmpv6"
crcMode string "declared"
defaultMulticastLoop bool true

Properties

Name Value Description
display i=block/transport
selfMessageKinds

kind not used in self messages or model doesn't use any self message

directSendKinds

kind not used in sendDirect() messages or model doesn't use any sendDirect()

Gates

Name Direction Size Description
appIn input
ipIn input
appOut output
ipOut output

Signals

Name Type Unit
packetReceived cPacket
packetSent cPacket
packetReceivedFromUpper cPacket
packetReceivedFromLower cPacket
packetDropped inet::Packet
packetSentToLower cPacket
packetSentToUpper cPacket

Statistics

Name Title Source Record Unit Interpolation Mode
packetReceived packets received packetReceived count, sum(packetBytes), vector(packetBytes) none
passedUpPk packets passed up packetSentToUpper count, vector(count) none
packetSent packets sent packetSent count, sum(packetBytes), vector(packetBytes) none
droppedPkBadChecksum packets dropped (checksum error) packetDropReasonIsIncorrectlyReceived(packetDropped) count, vector(count) none
droppedPkWrongPort packets dropped (wrong port) packetDropReasonIsNoPortFound(packetDropped) count, vector(count) none

Direct method calls (observed)

call tofunctioninfo
MessageDispatcherMessageDispatcher::arrivedarrived
MessageDispatcherMessageDispatcher::handleRegisterProtocolhandleRegisterProtocol
MessageDispatcherMessageDispatcher::handleRegisterServicehandleRegisterService
InterfaceTableInterfaceTable::interfaceChangedinterfaceChanged
Icmpv6Icmpv6::sendErrorMessagesendErrorMessage(datagram, type=%d, code=%d)
IcmpIcmp::sendErrorMessagesendErrorMessage(datagram, type=%d, code=%d)
Igmpv2Igmpv2::receiveSignalipv4MulticastGroupJoined
Igmpv2Igmpv2::receiveSignalipv4MulticastGroupLeft
Ipv4Ipv4::registerHookregisterHook()
Ipv6Ipv6::registerHookregisterHook()

Called methods (observed)

functioninfocall from
Udp::handleOperationStagehandleOperationStageScenarioManager, SimpleEpEnergyManagement, SimpleEpEnergyStorage

Incoming messages (observed)

gatemsgkindctrltags
appInPacket0 (UdpCommandCode::UDP_C_DATA)DispatchProtocolReq, SocketReq, DirectionTag?, HopLimitReq?, InterfaceReq?, L3AddressReq?, L4PortReq?
appInRequest1 (UdpCommandCode::UDP_C_BIND)UdpBindCommandDispatchProtocolReq, SocketReq
appInRequest2 (UdpCommandCode::UDP_C_CONNECT)UdpConnectCommandDispatchProtocolReq, SocketReq
appInRequest3 (UdpCommandCode::UDP_C_SETOPTION)UdpJoinMulticastGroupsCommandDispatchProtocolReq, SocketReq
appInRequest3 (UdpCommandCode::UDP_C_SETOPTION)UdpLeaveMulticastGroupsCommandDispatchProtocolReq, SocketReq
appInRequest3 (UdpCommandCode::UDP_C_SETOPTION)UdpSetBroadcastCommandDispatchProtocolReq, SocketReq
appInRequest3 (UdpCommandCode::UDP_C_SETOPTION)UdpSetMulticastInterfaceCommandDispatchProtocolReq, SocketReq
appInRequest3 (UdpCommandCode::UDP_C_SETOPTION)UdpSetMulticastLoopCommandDispatchProtocolReq, SocketReq
appInRequest3 (UdpCommandCode::UDP_C_SETOPTION)UdpSetTimeToLiveCommandDispatchProtocolReq, SocketReq
appInRequest4 (UdpCommandCode::UDP_C_CLOSE)UdpCloseCommandDispatchProtocolReq, SocketReq
ipInPacket0DispatchProtocolReq, L3AddressInd, PacketProtocolTag, DirectionTag?, DispatchProtocolInd?, DscpInd?, EcnInd?, ErrorRateInd?, HopLimitInd?, Ieee802SapInd?, InterfaceInd?, MacAddressInd?, NetworkProtocolInd?, SignalPowerInd?, SignalTimeInd?, SnirInd?, TosInd?, UserPriorityInd?, physicallayer::Ieee80211ChannelInd?, physicallayer::Ieee80211ModeInd?
ipInPacket4DispatchProtocolReq, DscpInd, EcnInd, HopLimitInd, InterfaceInd, L3AddressInd, MacAddressInd, NetworkProtocolInd, PacketProtocolTag, TosInd

Outgoing messages (observed)

gatemsgkindctrltags
appOutIndication1 (UdpStatusInd::UDP_I_ERROR)UdpErrorIndicationL3AddressInd, L4PortInd, SocketInd
appOutIndication2 (UdpStatusInd::UDP_I_SOCKET_CLOSED)UdpSocketClosedIndicationSocketInd
appOutPacket0 (UdpStatusInd::UDP_I_DATA)DscpInd, EcnInd, HopLimitInd, InterfaceInd, L3AddressInd, L4PortInd, NetworkProtocolInd, SocketInd, TosInd, TransportProtocolInd, DirectionTag?, DispatchProtocolInd?, ErrorRateInd?, Ieee802SapInd?, MacAddressInd?, SignalPowerInd?, SignalTimeInd?, SnirInd?, UserPriorityInd?, physicallayer::Ieee80211ChannelInd?, physicallayer::Ieee80211ModeInd?
ipOutPacket0DispatchProtocolReq, L3AddressReq, MulticastReq, PacketProtocolTag, TransportProtocolInd, DirectionTag?, HopLimitReq?, InterfaceReq?

Packet operations (observed)

chunkTypepacketAction
peekDataAsBytes, peekDataAt, setFrontOffset, trim
BytesChunkpeekDataAt
IcmpHeaderpeekAtFront, popAtFront
Icmpv6HeaderpeekAtFront, popAtFront
Ipv4HeaderinsertAtFront, popAtFront
Ipv6HeaderinsertAtFront, popAtFront
UdpHeaderinsertAtFront, peekAtFront, popAtFront

Shared Tagging operations (observed)

tagTypetagAction
DispatchProtocolReqaddTagIfAbsent, removeTagIfPresent
ErrorRateIndfindTag
HopLimitReqaddTag, findTag
InterfaceIndgetTag
InterfaceReqaddTagIfAbsent, findTag
L3AddressIndaddTag, getTag
L3AddressReqaddTagIfAbsent
L4PortIndaddTag, addTagIfAbsent
L4PortReqremoveTagIfPresent
MulticastReqaddTag, findTag
NetworkProtocolIndgetTag
PacketProtocolTagaddTagIfAbsent, getTag, removeTag, removeTagIfPresent
SocketIndaddTag, addTagIfAbsent
SocketReqgetTag, removeTag
TransportProtocolIndaddTagIfAbsent

Tagging operations (observed)

tagTypetagAction
Ipv4InterfaceDatagetTagForUpdate
Ipv6InterfaceDatagetTagForUpdate

Source code

//
// UDP protocol implementation, for IPv4 (~Ipv4) and IPv6 (~Ipv6).
//
// The UDP protocol header is represented by the class ~UdpHeader.
//
// <b>Communication with clients (applications)</b>
//
// The module can (should) be connected to several applications.
// For sending an UDP packet, the application should attach an ~UdpControlInfo
// object to the payload, and send it to ~Udp.
// ~Udp will also attach an ~UdpControlInfo object to any payload
// message in sends up to the application.
//
// For receiving Udp packets, the connected applications should first
// "bind" to the given UDP port. This can be done by sending an
// arbitrary message with message kind UDP_C_BIND and an ~UdpControlInfo
// attached with srcPort filled in.
//
// When UDP receives an ICMP error (~IcmpHeader or ~Icmpv6Header)
// that refers to an UDP socket, it reports the error to the corresponding
// application by sending a message with kind UDP_I_ERROR.
//
// <b>Communication with the IP (IPv4/IPv6) layer</b>
//
// The ~Udp model relies on sending and receiving ~L3AddressReq/~L3AddressInd
// tags attached to UDP packets.
//
// CRC operation modes for outgoing UDP packets (crcMode parameter in UDP module):
//  - "disabled" means the outgoing packet will have its CRC set to 0 (serializable)
//  - "declared" means the outgoing packet will have the correct CRC declared
//     without actually computing it, the value is set to 0xC00D (not serializable)
//  - "computed" means the outgoing packet will have the correctly computed CRC
//     as defined by the RFC (serializable)
// CRC operation modes for incoming UDP packets (crcMode field in ~UdpHeader chunk):
//  - CRC_DISABLED means the incoming packet must have its CRC set to 0 (serializable)
//  - CRC_DECLARED_CORRECT means the incoming packet is assumed to have a
//    correct CRC without the actual value (not serializable)
//  - CRC_DECLARED_INCORRECT means the incoming packet is assumed to have an
//    incorrect CRC without the actual value (not serializable)
//  - CRC_COMPUTED means the incoming packet has a potentially incorrect CRC
//    that is to be verified as defined by the RFC (serializable)
// The incoming packet also fails the CRC verification if any relevant chunk is marked incorrect.
//
// @see ~UdpHeader, ~UdpControlInfo, ~UdpCommandCode
//
simple Udp like IUdp
{
    parameters:
        string interfaceTableModule;   // The path to the InterfaceTable module
        string icmpModule = default("^.ipv4.icmp");
        string icmpv6Module = default("^.ipv6.icmpv6");
        string crcMode @enum("disabled","declared","computed") = default("declared");
        bool defaultMulticastLoop = default(true);
        @display("i=block/transport");
        @signal[packetSentToUpper](type=cPacket);
        @signal[packetReceivedFromUpper](type=cPacket);
        @signal[packetSentToLower](type=cPacket);
        @signal[packetReceivedFromLower](type=cPacket);
        @signal[packetDropped](type=inet::Packet);
        @signal[packetSent](type=cPacket);
        @signal[packetReceived](type=cPacket);
        @statistic[packetSent](title="packets sent"; source=packetSent; record=count,"sum(packetBytes)","vector(packetBytes)"; interpolationmode=none);
        @statistic[packetReceived](title="packets received"; source=packetReceived; record=count,"sum(packetBytes)","vector(packetBytes)"; interpolationmode=none);
        @statistic[passedUpPk](title="packets passed up"; source=packetSentToUpper; record=count,"vector(count)"; interpolationmode=none);
        @statistic[droppedPkWrongPort](title="packets dropped (wrong port)"; source=packetDropReasonIsNoPortFound(packetDropped); record=count,"vector(count)"; interpolationmode=none);
        @statistic[droppedPkBadChecksum](title="packets dropped (checksum error)"; source=packetDropReasonIsIncorrectlyReceived(packetDropped); record=count,"vector(count)"; interpolationmode=none);
        @selfMessageKinds();    // kind not used in self messages or model doesn't use any self message
        @directSendKinds();     // kind not used in sendDirect() messages or model doesn't use any sendDirect()

    gates:
        input appIn @labels(UdpControlInfo/down) @messageKinds(inet::UdpCommandCode);
        input ipIn @labels(UdpHeader,Ipv4ControlInfo/up,Ipv6ControlInfo/up);
        output appOut @labels(UdpControlInfo/up) @messageKinds(inet::UdpStatusInd);
        output ipOut @labels(UdpHeader,Ipv4ControlInfo/down,Ipv6ControlInfo/down);
}

File: src/inet/transportlayer/udp/Udp.ned