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

#include <CrcCheckerBase.h>

Inheritance diagram for inet::CrcCheckerBase:
inet::queueing::PacketFilterBase inet::queueing::PacketProcessorBase inet::queueing::IPacketFilter inet::queueing::IPacketProcessor inet::StringFormat::IDirectiveResolver inet::queueing::IPacketFlow inet::queueing::IPacketSink inet::queueing::IPacketSource inet::queueing::IPassivePacketSink inet::queueing::IActivePacketSink inet::queueing::IPassivePacketSource inet::queueing::IActivePacketSource inet::CrcHeaderChecker

Protected Member Functions

virtual bool checkDisabledCrc (const Packet *packet, uint16_t crc) const
 
virtual bool checkDeclaredCorrectCrc (const Packet *packet, uint16_t crc) const
 
virtual bool checkDeclaredIncorrectCrc (const Packet *packet, uint16_t crc) const
 
virtual bool checkComputedCrc (const Packet *packet, uint16_t crc) const
 
virtual bool checkCrc (const Packet *packet, CrcMode crcMode, uint16_t crc) const
 
- Protected Member Functions inherited from inet::queueing::PacketFilterBase
virtual void initialize (int stage) override
 
virtual void handleMessage (cMessage *message) override
 
virtual void processPacket (Packet *packet)
 
virtual bool isStreamingPacket () const
 
virtual void startPacketStreaming (Packet *packet)
 
virtual void endPacketStreaming (Packet *packet)
 
virtual void checkPacketStreaming (Packet *packet)
 
virtual void dropPacket (Packet *packet)
 
virtual void dropPacket (Packet *packet, PacketDropReason reason, int limit=-1) override
 
virtual const char * resolveDirective (char directive) const override
 
- Protected Member Functions inherited from inet::queueing::PacketProcessorBase
virtual int numInitStages () const override
 
virtual void refreshDisplay () 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 updateDisplayString () const
 

Additional Inherited Members

- Public Member Functions inherited from inet::queueing::PacketFilterBase
virtual 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 IPassivePacketSourcegetProvider (cGate *gate) override
 Returns the passive packet source from where packets are pulled or nullptr if the connected module doesn't implement the interface. More...
 
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 bool supportsPacketStreaming (cGate *gate) const override
 Returns true if the processor supports streaming packets at the given gate. 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 pushPacket (Packet *packet, cGate *gate) override
 Pushes the packet into the packet sink at the given gate. 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 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...
 
virtual bool canPullSomePacket (cGate *gate) const override
 Returns false if the packet source is empty at the given gate and no more packets can be pulled from it without raising an error. More...
 
virtual PacketcanPullPacket (cGate *gate) const override
 Returns the packet that can be pulled at the given gate. More...
 
virtual PacketpullPacket (cGate *gate) override
 Pulls the packet from the packet source at the given gate. More...
 
virtual PacketpullPacketStart (cGate *gate, bps datarate) override
 Starts pulling the packet from the packet source at the given gate. More...
 
virtual PacketpullPacketEnd (cGate *gate) override
 Ends pulling the packet from the packet source at the given gate. More...
 
virtual PacketpullPacketProgress (cGate *gate, bps datarate, b position, b extraProcessableLength) override
 Progresses pulling the packet from the packet source at the given gate. More...
 
virtual void handlePullPacketProcessed (Packet *packet, cGate *gate, bool successful) override
 Notifies about the completion of the packet processing for a packet that was pulled earlier independently whether the packet is passed or streamed. More...
 
virtual void handleCanPullPacketChanged (cGate *gate) override
 Notifies about a change in the possibility of pulling some packet from the passive packet source at the given gate. 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...
 
- Public Member Functions inherited from inet::queueing::IPacketProcessor
virtual ~IPacketProcessor ()
 
- Public Member Functions inherited from inet::queueing::IPacketFilter
virtual bool matchesPacket (const Packet *packet) const =0
 Returns true if the filter matches the given packet. More...
 
- Public Member Functions inherited from inet::queueing::IPassivePacketSink
virtual ~IPassivePacketSink ()
 
- Public Member Functions inherited from inet::queueing::IActivePacketSink
virtual ~IActivePacketSink ()
 
- Public Member Functions inherited from inet::queueing::IPassivePacketSource
virtual ~IPassivePacketSource ()
 
- Public Member Functions inherited from inet::queueing::IActivePacketSource
virtual ~IActivePacketSource ()
 
- Protected Types inherited from inet::queueing::PacketProcessorBase
enum  Action { PUSH, PULL }
 
- Protected Attributes inherited from inet::queueing::PacketFilterBase
bool backpressure = false
 
cGate * inputGate = nullptr
 
ModuleRef< IActivePacketSourceproducer
 
ModuleRef< IPassivePacketSourceprovider
 
cGate * outputGate = nullptr
 
ModuleRef< IPassivePacketSinkconsumer
 
ModuleRef< IActivePacketSinkcollector
 
int inProgressStreamId = -1
 
int numDroppedPackets = 0
 
b droppedTotalLength = b(-1)
 
- Protected Attributes inherited from inet::queueing::PacketProcessorBase
const char * displayStringTextFormat = nullptr
 
int numProcessedPackets = -1
 
b processedTotalLength = b(-1)
 

Member Function Documentation

◆ checkComputedCrc()

bool inet::CrcCheckerBase::checkComputedCrc ( const Packet packet,
uint16_t  crc 
) const
protectedvirtual
37 {
38  if (receivedCrc == 0x0000)
39  return true;
40  else {
41  const auto& data = packet->peekDataAsBytes();
42  auto bytes = data->getBytes();
43  uint16_t computedCrc = TcpIpChecksum::checksum(bytes.data(), packet->getByteLength() - 2);
44  // NOTE: the correct bit must be checked, because the data may not be corrupted precisely depending on the corruption mode
45  return receivedCrc == computedCrc && data->isCorrect() && !packet->hasBitError();
46  }
47 }

Referenced by checkCrc().

◆ checkCrc()

bool inet::CrcCheckerBase::checkCrc ( const Packet packet,
CrcMode  crcMode,
uint16_t  crc 
) const
protectedvirtual
50 {
51  switch (crcMode) {
52  case CRC_DISABLED:
53  return checkDisabledCrc(packet, crc);
55  return checkDeclaredCorrectCrc(packet, crc);
57  return checkDeclaredIncorrectCrc(packet, crc);
58  case CRC_COMPUTED:
59  return checkComputedCrc(packet, crc);
60  default:
61  throw cRuntimeError("Unknown CRC mode: %d", (int)crcMode);
62  }
63 }

Referenced by inet::CrcHeaderChecker::matchesPacket().

◆ checkDeclaredCorrectCrc()

bool inet::CrcCheckerBase::checkDeclaredCorrectCrc ( const Packet packet,
uint16_t  crc 
) const
protectedvirtual
22 {
23  const auto& data = packet->peekData();
24  if (crc != 0xC00D)
25  throw cRuntimeError("CRC value differs from expected");
26  return data->isCorrect() && !packet->hasBitError();
27 }

Referenced by checkCrc().

◆ checkDeclaredIncorrectCrc()

bool inet::CrcCheckerBase::checkDeclaredIncorrectCrc ( const Packet packet,
uint16_t  crc 
) const
protectedvirtual
30 {
31  if (crc != 0xBAAD)
32  throw cRuntimeError("CRC value differs from expected");
33  return false;
34 }

Referenced by checkCrc().

◆ checkDisabledCrc()

bool inet::CrcCheckerBase::checkDisabledCrc ( const Packet packet,
uint16_t  crc 
) const
protectedvirtual
15 {
16  if (crc != 0x0000)
17  throw cRuntimeError("CRC value differs from expected");
18  return true;
19 }

Referenced by checkCrc().


The documentation for this class was generated from the following files:
inet::CRC_COMPUTED
@ CRC_COMPUTED
Definition: CrcMode_m.h:59
inet::CRC_DISABLED
@ CRC_DISABLED
Definition: CrcMode_m.h:56
inet::CrcCheckerBase::checkDeclaredCorrectCrc
virtual bool checkDeclaredCorrectCrc(const Packet *packet, uint16_t crc) const
Definition: CrcCheckerBase.cc:21
inet::TcpIpChecksum::checksum
static uint16_t checksum(const void *addr, unsigned int count)
Definition: TcpIpChecksum.h:33
inet::CrcCheckerBase::checkDisabledCrc
virtual bool checkDisabledCrc(const Packet *packet, uint16_t crc) const
Definition: CrcCheckerBase.cc:14
inet::CRC_DECLARED_CORRECT
@ CRC_DECLARED_CORRECT
Definition: CrcMode_m.h:57
inet::CRC_DECLARED_INCORRECT
@ CRC_DECLARED_INCORRECT
Definition: CrcMode_m.h:58
inet::CrcCheckerBase::checkDeclaredIncorrectCrc
virtual bool checkDeclaredIncorrectCrc(const Packet *packet, uint16_t crc) const
Definition: CrcCheckerBase.cc:29
inet::CrcCheckerBase::checkComputedCrc
virtual bool checkComputedCrc(const Packet *packet, uint16_t crc) const
Definition: CrcCheckerBase.cc:36