INET Framework for OMNeT++/OMNEST
inet::DscpMarker Class Reference

DSCP Marker. More...

#include <DscpMarker.h>

Inheritance diagram for inet::DscpMarker:
inet::queueing::PacketProcessorBase inet::queueing::IPassivePacketSink inet::queueing::IActivePacketSource inet::queueing::IPacketProcessor inet::StringFormat::IDirectiveResolver

Public Member Functions

 DscpMarker ()
 
virtual bool supportsPacketPushing (cGate *gate) const override
 Returns true if the processor supports pushing packets at the given gate. More...
 
virtual bool supportsPacketPulling (cGate *gate) const override
 Returns true if the processor supports pulling packets at the given gate. More...
 
virtual queueing::IPassivePacketSinkgetConsumer (cGate *gate) override
 Returns the passive packet sink where packets are pushed or nullptr if the connected module doesn't implement the interface. More...
 
virtual bool canPushSomePacket (cGate *gate) const override
 Returns false if the packet sink is full at the given gate and no more packets can be pushed into it without raising an error. More...
 
virtual bool canPushPacket (Packet *packet, cGate *gate) const override
 Returns true if the given packet can be pushed at the given gate into the packet sink without raising an error. More...
 
virtual void pushPacketStart (Packet *packet, cGate *gate, bps datarate) override
 Starts pushing the packet into the packet sink at the given gate. More...
 
virtual void pushPacketEnd (Packet *packet, cGate *gate) override
 Ends pushing the packet into the packet sink at the given gate. More...
 
virtual void pushPacketProgress (Packet *packet, cGate *gate, bps datarate, b position, b extraProcessableLength=b(0)) override
 Progresses pushing the packet into the packet sink at the given gate. More...
 
virtual void handleCanPushPacketChanged (cGate *gate) override
 Notifies about a change in the possibility of pushing some packet into the passive packet sink at the given gate. More...
 
virtual void pushPacket (Packet *packet, cGate *gate) override
 Pushes the packet into the packet sink at the given gate. More...
 
virtual void handlePushPacketProcessed (Packet *packet, cGate *gate, bool successful) override
 Notifies about the completion of the packet processing for a packet that was pushed earlier independently whether the packet is passed or streamed. More...
 
- Public Member Functions inherited from inet::queueing::PacketProcessorBase
virtual bool supportsPacketSending (cGate *gate) const override
 Returns true if the processor supports sending packets at the given gate. More...
 
virtual bool supportsPacketPassing (cGate *gate) const override
 Returns true if the processor supports passing packets as a whole at the given gate. More...
 
virtual bool supportsPacketStreaming (cGate *gate) const override
 Returns true if the processor supports streaming packets at the given gate. More...
 
virtual const char * resolveDirective (char directive) const override
 
- Public Member Functions inherited from inet::queueing::IPacketProcessor
virtual ~IPacketProcessor ()
 
- Public Member Functions inherited from inet::queueing::IPassivePacketSink
virtual ~IPassivePacketSink ()
 
- Public Member Functions inherited from inet::queueing::IActivePacketSource
virtual ~IActivePacketSource ()
 

Protected Member Functions

virtual void initialize (int stage) override
 
virtual void handleMessage (cMessage *message) override
 
virtual void refreshDisplay () const override
 
virtual bool markPacket (Packet *msg, int dscp)
 
- Protected Member Functions inherited from inet::queueing::PacketProcessorBase
virtual int numInitStages () const override
 
virtual void handlePacketProcessed (Packet *packet)
 
virtual void checkPacketOperationSupport (cGate *gate) const
 
virtual void checkPacketOperationSupport (cGate *startGate, cGate *endGate) const
 
virtual void animate (Packet *packet, cGate *gate, const SendOptions &sendOptions, Action action) const
 
virtual void animatePacket (Packet *packet, cGate *gate, Action action) const
 
virtual void animatePacketStart (Packet *packet, cGate *gate, bps datarate, long transmissionId, Action action) const
 
virtual void animatePacketStart (Packet *packet, cGate *gate, bps datarate, const SendOptions &sendOptions, Action action) const
 
virtual void animatePacketEnd (Packet *packet, cGate *gate, long transmissionId, Action action) const
 
virtual void animatePacketEnd (Packet *packet, cGate *gate, const SendOptions &sendOptions, Action action) const
 
virtual void animatePacketProgress (Packet *packet, cGate *gate, bps datarate, b position, b extraProcessableLength, long transmissionId, Action action) const
 
virtual void animatePacketProgress (Packet *packet, cGate *gate, bps datarate, b position, b extraProcessableLength, const SendOptions &sendOptions, Action action) const
 
virtual void pushOrSendPacket (Packet *packet, cGate *gate, IPassivePacketSink *consumer)
 
virtual void pushOrSendPacketStart (Packet *packet, cGate *gate, IPassivePacketSink *consumer, bps datarate, int transmissionId)
 
virtual void pushOrSendPacketEnd (Packet *packet, cGate *gate, IPassivePacketSink *consumer, int transmissionId)
 
virtual void pushOrSendPacketProgress (Packet *packet, cGate *gate, IPassivePacketSink *consumer, bps datarate, b position, b extraProcessableLength, int transmissionId)
 
virtual void animatePush (Packet *packet, cGate *gate, const SendOptions &sendOptions) const
 
virtual void animatePushPacket (Packet *packet, cGate *gate) const
 
virtual void animatePushPacketStart (Packet *packet, cGate *gate, bps datarate, long transmissionId) const
 
virtual void animatePushPacketStart (Packet *packet, cGate *gate, bps datarate, const SendOptions &sendOptions) const
 
virtual void animatePushPacketEnd (Packet *packet, cGate *gate, long transmissionId) const
 
virtual void animatePushPacketEnd (Packet *packet, cGate *gate, const SendOptions &sendOptions) const
 
virtual void animatePushPacketProgress (Packet *packet, cGate *gate, bps datarate, b position, b extraProcessableLength, long transmissionId) const
 
virtual void animatePushPacketProgress (Packet *packet, cGate *gate, bps datarate, b position, b extraProcessableLength, const SendOptions &sendOptions) const
 
virtual void animatePull (Packet *packet, cGate *gate, const SendOptions &sendOptions) const
 
virtual void animatePullPacket (Packet *packet, cGate *gate) const
 
virtual void animatePullPacketStart (Packet *packet, cGate *gate, bps datarate, long transmissionId) const
 
virtual void animatePullPacketStart (Packet *packet, cGate *gate, bps datarate, const SendOptions &sendOptions) const
 
virtual void animatePullPacketEnd (Packet *packet, cGate *gate, long transmissionId) const
 
virtual void animatePullPacketEnd (Packet *packet, cGate *gate, const SendOptions &sendOptions) const
 
virtual void animatePullPacketProgress (Packet *packet, cGate *gate, bps datarate, b position, b extraProcessableLength, long transmissionId) const
 
virtual void animatePullPacketProgress (Packet *packet, cGate *gate, bps datarate, b position, b extraProcessableLength, const SendOptions &sendOptions) const
 
virtual void dropPacket (Packet *packet, PacketDropReason reason, int limit=-1)
 
virtual void updateDisplayString () const
 

Protected Attributes

cGate * outputGate = nullptr
 
IPassivePacketSinkconsumer = nullptr
 
std::vector< int > dscps
 
int numRcvd = 0
 
int numMarked = 0
 
- Protected Attributes inherited from inet::queueing::PacketProcessorBase
const char * displayStringTextFormat = nullptr
 
int numProcessedPackets = -1
 
b processedTotalLength = b(-1)
 

Static Protected Attributes

static simsignal_t packetMarkedSignal = registerSignal("packetMarked")
 

Additional Inherited Members

- Protected Types inherited from inet::queueing::PacketProcessorBase
enum  Action { PUSH, PULL }
 

Detailed Description

DSCP Marker.

Constructor & Destructor Documentation

◆ DscpMarker()

inet::DscpMarker::DscpMarker ( )
inline
36 {}

Member Function Documentation

◆ canPushPacket()

virtual bool inet::DscpMarker::canPushPacket ( Packet packet,
cGate *  gate 
) const
inlineoverridevirtual

Returns true if the given packet can be pushed at the given gate into the packet sink without raising an error.

The packet must not be nullptr. The gate must be a valid gate of this module and it must support pushing packets.

Implements inet::queueing::IPassivePacketSink.

44 { return true; }

◆ canPushSomePacket()

virtual bool inet::DscpMarker::canPushSomePacket ( cGate *  gate) const
inlineoverridevirtual

Returns false if the packet sink is full at the given gate and no more packets can be pushed into it without raising an error.

The gate must be a valid gate of this module and it must support pushing packets.

Implements inet::queueing::IPassivePacketSink.

43 { return true; }

◆ getConsumer()

virtual queueing::IPassivePacketSink* inet::DscpMarker::getConsumer ( cGate *  gate)
inlineoverridevirtual

Returns the passive packet sink where packets are pushed or nullptr if the connected module doesn't implement the interface.

The gate parameter must be a valid gate of this module.

Implements inet::queueing::IActivePacketSource.

41 { return this; }

◆ handleCanPushPacketChanged()

virtual void inet::DscpMarker::handleCanPushPacketChanged ( cGate *  gate)
inlineoverridevirtual

Notifies about a change in the possibility of pushing some packet into the passive packet sink at the given gate.

This method is called, for example, when a new packet can be inserted into a queue. It allows the source to push a new packet into the queue.

The gate parameter must be a valid gate of this module.

Implements inet::queueing::IActivePacketSource.

50 {}

◆ handleMessage()

void inet::DscpMarker::handleMessage ( cMessage *  message)
overrideprotectedvirtual
57 {
58  auto packet = check_and_cast<Packet *>(message);
59  pushPacket(packet, packet->getArrivalGate());
60 }

◆ handlePushPacketProcessed()

virtual void inet::DscpMarker::handlePushPacketProcessed ( Packet packet,
cGate *  gate,
bool  successful 
)
inlineoverridevirtual

Notifies about the completion of the packet processing for a packet that was pushed earlier independently whether the packet is passed or streamed.

This method is called, for example, when a previously pushed packet is failed to be processed successfully. It allows the source to retry the operation.

The gate parameter must be a valid gate of this module. The packet must not be nullptr.

Implements inet::queueing::IActivePacketSource.

62 {}

◆ initialize()

void inet::DscpMarker::initialize ( int  stage)
overrideprotectedvirtual

Reimplemented from inet::queueing::PacketProcessorBase.

38 {
40  if (stage == INITSTAGE_LOCAL) {
41  outputGate = gate("out");
42  consumer = findConnectedModule<IPassivePacketSink>(outputGate);
43  parseDSCPs(par("dscps"), "dscps", dscps);
44  if (dscps.empty())
45  dscps.push_back(DSCP_BE);
46  while ((int)dscps.size() < gateSize("in"))
47  dscps.push_back(dscps.back());
48 
49  numRcvd = 0;
50  numMarked = 0;
51  WATCH(numRcvd);
52  WATCH(numMarked);
53  }
54 }

◆ markPacket()

bool inet::DscpMarker::markPacket ( Packet msg,
int  dscp 
)
protectedvirtual
86 {
87  EV_DETAIL << "Marking packet with dscp=" << dscpToString(dscp) << "\n";
88 
89  b offset(0);
90  auto protocol = packet->getTag<PacketProtocolTag>()->getProtocol();
91 
92  if (protocol->getLayer() == Protocol::LinkLayer) {
94 #ifdef INET_WITH_ETHERNET
95  auto ethHeader = packet->peekDataAt<EthernetMacHeader>(offset);
96  if (isEth2Header(*ethHeader)) {
97  offset += ethHeader->getChunkLength();
98  protocol = ProtocolGroup::ethertype.getProtocol(ethHeader->getTypeOrLength());
99  }
100 #else
101  throw cRuntimeError("Ethernet feature is disabled");
102 #endif // #ifdef INET_WITH_ETHERNET
103  }
104  else
105  return false;
106  }
107 
108  if (protocol->getLayer() != Protocol::NetworkLayer)
109  return false;
110 #ifdef INET_WITH_IPv4
111  else if (protocol == &Protocol::ipv4) {
112  packet->removeTagIfPresent<NetworkProtocolInd>();
113  auto ipv4Header = packet->removeDataAt<Ipv4Header>(offset);
114  ipv4Header->setDscp(dscp);
115  Ipv4::insertCrc(ipv4Header); // recalculate IP header checksum
116  auto networkProtocolInd = packet->addTagIfAbsent<NetworkProtocolInd>();
117  networkProtocolInd->setProtocol(protocol);
118  networkProtocolInd->setNetworkProtocolHeader(ipv4Header);
119  packet->insertDataAt(ipv4Header, offset);
120  return true;
121  }
122 #endif // ifdef INET_WITH_IPv4
123 #ifdef INET_WITH_IPv6
124  else if (protocol == &Protocol::ipv6) {
125  packet->removeTagIfPresent<NetworkProtocolInd>();
126  auto ipv6Header = packet->removeDataAt<Ipv6Header>(offset);
127  ipv6Header->setDscp(dscp);
128  auto networkProtocolInd = packet->addTagIfAbsent<NetworkProtocolInd>();
129  networkProtocolInd->setProtocol(protocol);
130  networkProtocolInd->setNetworkProtocolHeader(ipv6Header);
131  packet->insertDataAt(ipv6Header, offset);
132  return true;
133  }
134 #endif // ifdef INET_WITH_IPv6
135  return false;
136 }

◆ pushPacket()

void inet::DscpMarker::pushPacket ( Packet packet,
cGate *  gate 
)
overridevirtual

Pushes the packet into the packet sink at the given gate.

This operation pushes the packet as a whole. The onwership of the packet is transferred to the sink.

This method is called, for example, when a packet source module pushes a packet into a queue module.

The sink must not be full at the gate. The packet must not be nullptr. The gate must be a valid gate of this module and it must support pushing and passing packets.

Implements inet::queueing::IPassivePacketSink.

63 {
64  Enter_Method("pushPacket");
65  take(packet);
66  numRcvd++;
67  int dscp = dscps.at(inputGate->getIndex());
68  if (markPacket(packet, dscp)) {
69  emit(packetMarkedSignal, packet);
70  numMarked++;
71  }
73 }

◆ pushPacketEnd()

virtual void inet::DscpMarker::pushPacketEnd ( Packet packet,
cGate *  gate 
)
inlineoverridevirtual

Ends pushing the packet into the packet sink at the given gate.

This is a packet streaming operation. The onwership of the packet is transferred to the sink.

Packet streaming can be started with any of the streaming operations, and ends when the streaming position plus the extra processable packet length equals to the total packet length.

This method is called, for example, when a preemption supporting server module ends streaming a packet to the sink.

The sink must not be full at the gate and no other packet streaming can be in progress. The packet must not be nullptr. The gate must be a valid gate of this module and it must support pushing and streaming packets.

Implements inet::queueing::IPassivePacketSink.

47 { throw cRuntimeError("Invalid operation"); }

◆ pushPacketProgress()

virtual void inet::DscpMarker::pushPacketProgress ( Packet packet,
cGate *  gate,
bps  datarate,
b  position,
b  extraProcessableLength = b(0) 
)
inlineoverridevirtual

Progresses pushing the packet into the packet sink at the given gate.

This is a packet streaming operation. The position specifies where the packet streaming is at the moment. The extra length parameter partially fixes the future of the packet streaming operation. The onwership of the packet is transferred to the sink.

Packet streaming can be started with any of the streaming operations, and ends when the streaming position plus the extra processable packet length equals to the total packet length.

This method is called, for example, to notify the sink about a change in the packet data when a preemption occurs.

The sink must not be full at the gate and no other packet streaming can be in progress. The packet must not be nullptr. The gate must be a valid gate of this module and it must support pushing and streaming packets.

Implements inet::queueing::IPassivePacketSink.

48 { throw cRuntimeError("Invalid operation"); }

◆ pushPacketStart()

virtual void inet::DscpMarker::pushPacketStart ( Packet packet,
cGate *  gate,
bps  datarate 
)
inlineoverridevirtual

Starts pushing the packet into the packet sink at the given gate.

This is a packet streaming operation. The onwership of the packet is transferred to the sink.

Packet streaming can be started with any of the streaming operations, and ends when the streaming position plus the extra processable packet length equals to the total packet length.

This method is called, for example, when a preemption supporting server module starts streaming a packet to the sink.

The sink must not be full at the gate and no other packet streaming can be in progress. The packet must not be nullptr. The gate must be a valid gate of this module and it must support pushing and streaming packets.

Implements inet::queueing::IPassivePacketSink.

46 { throw cRuntimeError("Invalid operation"); }

◆ refreshDisplay()

void inet::DscpMarker::refreshDisplay ( ) const
overrideprotectedvirtual

Reimplemented from inet::queueing::PacketProcessorBase.

76 {
77  char buf[50] = "";
78  if (numRcvd > 0)
79  sprintf(buf + strlen(buf), "rcvd: %d ", numRcvd);
80  if (numMarked > 0)
81  sprintf(buf + strlen(buf), "mark:%d ", numMarked);
82  getDisplayString().setTagArg("t", 0, buf);
83 }

◆ supportsPacketPulling()

virtual bool inet::DscpMarker::supportsPacketPulling ( cGate *  gate) const
inlineoverridevirtual

Returns true if the processor supports pulling packets at the given gate.

Pulling a packet is a synchronous operation that is initiated by the sink module. A pulled packet can be passed as a whole using pullPacket(), or it can be streamed from the source to the sink using pullPacketStart(), pullPacketEnd(), and pullPacketProgress().

For output gates, true means that the connected module can pull packets from this module. For input gates, true means that this module can pull packets from the connected module. For example, a packet server module can pull packets from a queue module.

Connecting incompatible gates raises an error during initialize. The gate parameter must be a valid gate of this module. The gate should be marked with @labels(pull) in the NED file.

Implements inet::queueing::IPacketProcessor.

39 { return false; }

◆ supportsPacketPushing()

virtual bool inet::DscpMarker::supportsPacketPushing ( cGate *  gate) const
inlineoverridevirtual

Returns true if the processor supports pushing packets at the given gate.

Pushing a packet is a synchronous operation that is initiated by the source module. A pushed packet can be passed as a whole using pushPacket(), or it can be streamed from the source to the sink using pushPacketStart(), pushPacketEnd(), and pushPacketProgress().

For output gates, true means that this module can push packets into the connected module. For input gates, true means that the connected module can push packets into this module. For example, a packet generator module can push packets into a queue module.

Connecting incompatible gates raises an error during initialize. The gate parameter must be a valid gate of this module. The gate should be marked with @labels(push) in the NED file.

Implements inet::queueing::IPacketProcessor.

38 { return true; }

Member Data Documentation

◆ consumer

IPassivePacketSink* inet::DscpMarker::consumer = nullptr
protected

◆ dscps

std::vector<int> inet::DscpMarker::dscps
protected

◆ numMarked

int inet::DscpMarker::numMarked = 0
protected

◆ numRcvd

int inet::DscpMarker::numRcvd = 0
protected

◆ outputGate

cGate* inet::DscpMarker::outputGate = nullptr
protected

◆ packetMarkedSignal

simsignal_t inet::DscpMarker::packetMarkedSignal = registerSignal("packetMarked")
staticprotected

The documentation for this class was generated from the following files:
inet::DscpMarker::numMarked
int numMarked
Definition: DscpMarker.h:31
inet::queueing::PacketProcessorBase::initialize
virtual void initialize(int stage) override
Definition: PacketProcessorBase.cc:16
inet::isEth2Header
bool isEth2Header(const EthernetMacHeader &hdr)
Definition: EthernetMacHeader_m.h:228
inet::queueing::PacketProcessorBase::pushOrSendPacket
virtual void pushOrSendPacket(Packet *packet, cGate *gate, IPassivePacketSink *consumer)
Definition: PacketProcessorBase.cc:126
protocol
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down protocol
Definition: IUdp-gates.txt:25
inet::DscpMarker::pushPacket
virtual void pushPacket(Packet *packet, cGate *gate) override
Pushes the packet into the packet sink at the given gate.
Definition: DscpMarker.cc:62
inet::Protocol::ipv4
static const Protocol ipv4
Definition: Protocol.h:93
inet::Protocol::ipv6
static const Protocol ipv6
Definition: Protocol.h:94
inet::DscpMarker::markPacket
virtual bool markPacket(Packet *msg, int dscp)
Definition: DscpMarker.cc:85
inet::Protocol::LinkLayer
@ LinkLayer
Definition: Protocol.h:23
inet::DscpMarker::consumer
IPassivePacketSink * consumer
Definition: DscpMarker.h:26
PacketProtocolTag
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down PacketProtocolTag
Definition: IUdp-gates.txt:25
inet::DiffservUtil::parseDSCPs
void parseDSCPs(const char *attrValue, const char *attrName, std::vector< int > &result)
Parses a space separated list of DSCP values and puts them into the result vector.
Definition: DiffservUtil.cc:127
inet::Protocol::ethernetMac
static const Protocol ethernetMac
Definition: Protocol.h:65
inet::DSCP_BE
@ DSCP_BE
Definition: Dscp_m.h:87
inet::INITSTAGE_LOCAL
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
inet::DiffservUtil::dscpToString
std::string dscpToString(int dscp)
Returns the string representation of the given DSCP value.
Definition: DiffservUtil.cc:142
inet::units::values::b
value< int64_t, units::b > b
Definition: Units.h:1241
inet::DscpMarker::packetMarkedSignal
static simsignal_t packetMarkedSignal
Definition: DscpMarker.h:33
inet::Protocol::NetworkLayer
@ NetworkLayer
Definition: Protocol.h:23
Enter_Method
#define Enter_Method(...)
Definition: SelfDoc.h:71
inet::Ipv4::insertCrc
static void insertCrc(const Ptr< Ipv4Header > &ipv4Header)
Definition: Ipv4.cc:832
inet::ProtocolGroup::getProtocol
const Protocol * getProtocol(int protocolNumber) const
Definition: ProtocolGroup.cc:31
inet::DscpMarker::numRcvd
int numRcvd
Definition: DscpMarker.h:30
inet::DscpMarker::outputGate
cGate * outputGate
Definition: DscpMarker.h:25
inet::ProtocolGroup::ethertype
static ProtocolGroup ethertype
Definition: ProtocolGroup.h:40
inet::DscpMarker::dscps
std::vector< int > dscps
Definition: DscpMarker.h:28