INET Framework for OMNeT++/OMNEST
inet::physicallayer::ErrorModelBase Class Reference

#include <ErrorModelBase.h>

Inheritance diagram for inet::physicallayer::ErrorModelBase:
inet::physicallayer::IErrorModel inet::IPrintableObject inet::physicallayer::ApskErrorModel inet::physicallayer::Ieee80211BerTableErrorModel inet::physicallayer::Ieee80211ErrorModelBase inet::physicallayer::StochasticErrorModel inet::physicallayer::Ieee80211NistErrorModel inet::physicallayer::Ieee80211YansErrorModel inet::physicallayer::Ieee80211OfdmErrorModel

Public Types

enum  CorruptionMode {
  CorruptionMode::CM_UNDEFINED = -1, CorruptionMode::CM_PACKET, CorruptionMode::CM_CHUNK, CorruptionMode::CM_BYTE,
  CorruptionMode::CM_BIT
}
 
enum  SnirMode { SnirMode::SM_UNDEFINED = -1, SnirMode::SM_MIN, SnirMode::SM_MEAN }
 
- Public Types inherited from inet::IPrintableObject
enum  PrintLevel {
  PRINT_LEVEL_TRACE, PRINT_LEVEL_DEBUG, PRINT_LEVEL_DETAIL, PRINT_LEVEL_INFO,
  PRINT_LEVEL_COMPLETE = INT_MIN
}
 
enum  PrintFlag { PRINT_FLAG_FORMATTED = (1 << 0), PRINT_FLAG_MULTILINE = (1 << 1) }
 

Protected Member Functions

virtual void initialize (int stage) override
 
virtual double getScalarSnir (const ISnir *snir) const
 
virtual bool hasProbabilisticError (b length, double ber) const
 
virtual PacketcorruptBits (const Packet *packet, double ber, bool &isCorrupted) const
 
virtual PacketcorruptBytes (const Packet *packet, double ber, bool &isCorrupted) const
 
virtual PacketcorruptChunks (const Packet *packet, double ber, bool &isCorrupted) const
 
virtual PacketcorruptPacket (const Packet *packet, bool &isCorrupted) const
 
virtual PacketcomputeCorruptedPacket (const Packet *packet, double ber) const
 
virtual PacketcomputeCorruptedPacket (const ISnir *snir) const override
 

Protected Attributes

CorruptionMode corruptionMode = CorruptionMode::CM_UNDEFINED
 
SnirMode snirMode = SnirMode::SM_UNDEFINED
 
double snirOffset = NaN
 

Additional Inherited Members

- Public Member Functions inherited from inet::physicallayer::IErrorModel
virtual double computePacketErrorRate (const ISnir *snir, IRadioSignal::SignalPart part) const =0
 Returns the packet error rate based on SNIR, modulation, FEC encoding and any other physical layer characteristics. More...
 
virtual double computeBitErrorRate (const ISnir *snir, IRadioSignal::SignalPart part) const =0
 Returns the bit error rate based on SNIR, modulation, FEC encoding and any other physical layer characteristics. More...
 
virtual double computeSymbolErrorRate (const ISnir *snir, IRadioSignal::SignalPart part) const =0
 Returns the symbol error rate based on SNIR, modulation, and any other physical layer characteristics. More...
 
- Public Member Functions inherited from inet::IPrintableObject
virtual ~IPrintableObject ()
 
virtual std::ostream & printToStream (std::ostream &stream, int level, int evFlags=0) const
 Prints this object to the provided output stream. More...
 
virtual std::string printToString () const
 
virtual std::string printToString (int level, int evFlags=0) const
 
virtual std::string getInfoStringRepresentation (int evFlags=0) const
 
virtual std::string getDetailStringRepresentation (int evFlags=0) const
 
virtual std::string getDebugStringRepresentation (int evFlags=0) const
 
virtual std::string getTraceStringRepresentation (int evFlags=0) const
 
virtual std::string getCompleteStringRepresentation (int evFlags=0) const
 

Member Enumeration Documentation

◆ CorruptionMode

Enumerator
CM_UNDEFINED 
CM_PACKET 
CM_CHUNK 
CM_BYTE 
CM_BIT 
20  {
21  CM_UNDEFINED = -1,
22  CM_PACKET,
23  CM_CHUNK,
24  CM_BYTE,
25  CM_BIT
26  };

◆ SnirMode

Enumerator
SM_UNDEFINED 
SM_MIN 
SM_MEAN 
28  {
29  SM_UNDEFINED = -1,
30  SM_MIN,
31  SM_MEAN
32  };

Member Function Documentation

◆ computeCorruptedPacket() [1/2]

Packet * inet::physicallayer::ErrorModelBase::computeCorruptedPacket ( const ISnir snir) const
overrideprotectedvirtual

Implements inet::physicallayer::IErrorModel.

142 {
143  auto transmittedPacket = snir->getReception()->getTransmission()->getPacket();
145  auto receivedPacket = computeCorruptedPacket(transmittedPacket, ber);
146  receivedPacket->clearTags();
147  receivedPacket->addTag<PacketProtocolTag>()->setProtocol(transmittedPacket->getTag<PacketProtocolTag>()->getProtocol());
148  return receivedPacket;
149 }

◆ computeCorruptedPacket() [2/2]

Packet * inet::physicallayer::ErrorModelBase::computeCorruptedPacket ( const Packet packet,
double  ber 
) const
protectedvirtual

Reimplemented in inet::physicallayer::Ieee80211ErrorModelBase.

114 {
115  bool isCorrupted = false;
116  Packet *corruptedPacket = nullptr;
117  // TODO this while loop looks bad, but we don't have any other chance now, because the decision whether the reception is successful or not has been already made
118  while (!isCorrupted) {
119  switch (corruptionMode) {
121  corruptedPacket = corruptPacket(packet, isCorrupted);
122  break;
124  corruptedPacket = corruptChunks(packet, ber, isCorrupted);
125  break;
127  corruptedPacket = corruptBytes(packet, ber, isCorrupted);
128  break;
130  corruptedPacket = corruptBits(packet, ber, isCorrupted);
131  break;
132  default:
133  throw cRuntimeError("Unknown corruption mode");
134  }
135  if (!isCorrupted)
136  delete corruptedPacket;
137  }
138  return corruptedPacket;
139 }

Referenced by inet::physicallayer::Ieee80211ErrorModelBase::computeCorruptedPacket(), and computeCorruptedPacket().

◆ corruptBits()

Packet * inet::physicallayer::ErrorModelBase::corruptBits ( const Packet packet,
double  ber,
bool &  isCorrupted 
) const
protectedvirtual
60 {
61  std::vector<bool> corruptedBits;
62  const auto& all = packet->peekAllAsBits();
63  for (bool bit : all->getBits()) {
64  if (hasProbabilisticError(b(1), ber)) {
65  isCorrupted = true;
66  bit = !bit;
67  }
68  corruptedBits.push_back(bit);
69  }
70  return new Packet(packet->getName(), makeShared<BitsChunk>(corruptedBits));
71 }

Referenced by computeCorruptedPacket().

◆ corruptBytes()

Packet * inet::physicallayer::ErrorModelBase::corruptBytes ( const Packet packet,
double  ber,
bool &  isCorrupted 
) const
protectedvirtual
74 {
75  std::vector<uint8_t> corruptedBytes;
76  const auto& all = packet->peekAllAsBytes();
77  for (uint8_t byte : all->getBytes()) {
78  if (hasProbabilisticError(B(1), ber)) {
79  isCorrupted = true;
80  byte = ~byte;
81  }
82  corruptedBytes.push_back(byte);
83  }
84  return new Packet(packet->getName(), makeShared<BytesChunk>(corruptedBytes));
85 }

Referenced by computeCorruptedPacket().

◆ corruptChunks()

Packet * inet::physicallayer::ErrorModelBase::corruptChunks ( const Packet packet,
double  ber,
bool &  isCorrupted 
) const
protectedvirtual
88 {
89  b offset = b(0);
90  auto corruptedPacket = new Packet(packet->getName());
91  while (auto chunk = packet->peekAt(offset, b(-1), Chunk::PF_ALLOW_NULLPTR)) {
92  if (hasProbabilisticError(chunk->getChunkLength(), ber)) {
93  isCorrupted = true;
94  auto corruptedChunk = chunk->dupShared();
95  corruptedChunk->markIncorrect();
96  corruptedPacket->insertAtBack(corruptedChunk);
97  }
98  else
99  corruptedPacket->insertAtBack(chunk);
100  offset += chunk->getChunkLength();
101  }
102  return corruptedPacket;
103 }

Referenced by computeCorruptedPacket().

◆ corruptPacket()

Packet * inet::physicallayer::ErrorModelBase::corruptPacket ( const Packet packet,
bool &  isCorrupted 
) const
protectedvirtual
106 {
107  isCorrupted = true;
108  auto corruptedPacket = packet->dup();
109  corruptedPacket->setBitError(true);
110  return corruptedPacket;
111 }

Referenced by computeCorruptedPacket().

◆ getScalarSnir()

double inet::physicallayer::ErrorModelBase::getScalarSnir ( const ISnir snir) const
protectedvirtual

◆ hasProbabilisticError()

bool inet::physicallayer::ErrorModelBase::hasProbabilisticError ( b  length,
double  ber 
) const
protectedvirtual
54 {
55  ASSERT(0.0 < ber && ber <= 1.0);
56  return dblrand() < 1 - std::pow((1 - ber), length.get());
57 }

Referenced by corruptBits(), corruptBytes(), and corruptChunks().

◆ initialize()

void inet::physicallayer::ErrorModelBase::initialize ( int  stage)
overrideprotectedvirtual

Reimplemented in inet::physicallayer::Ieee80211OfdmErrorModel, inet::physicallayer::StochasticErrorModel, and inet::physicallayer::Ieee80211BerTableErrorModel.

17 {
18  if (stage == INITSTAGE_LOCAL) {
19  const char *corruptionModeString = par("corruptionMode");
20  if (!strcmp("packet", corruptionModeString))
22  else if (!strcmp("chunk", corruptionModeString))
24  else if (!strcmp("byte", corruptionModeString))
26  else if (!strcmp("bit", corruptionModeString))
28  else
29  throw cRuntimeError("Unknown corruption mode");
30  const char *snirModeString = par("snirMode");
31  if (!strcmp("min", snirModeString))
33  else if (!strcmp("mean", snirModeString))
35  else
36  throw cRuntimeError("Unknown SNIR mode: '%s'", snirModeString);
37  snirOffset = inet::math::dB2fraction(par("snirOffset"));
38  }
39 }

Referenced by inet::physicallayer::Ieee80211OfdmErrorModel::initialize().

Member Data Documentation

◆ corruptionMode

◆ snirMode

SnirMode inet::physicallayer::ErrorModelBase::snirMode = SnirMode::SM_UNDEFINED
protected

Referenced by getScalarSnir(), and initialize().

◆ snirOffset

double inet::physicallayer::ErrorModelBase::snirOffset = NaN
protected

Referenced by getScalarSnir(), and initialize().


The documentation for this class was generated from the following files:
inet::Chunk::PF_ALLOW_NULLPTR
@ PF_ALLOW_NULLPTR
Definition: Chunk.h:278
inet::physicallayer::IErrorModel::computeBitErrorRate
virtual double computeBitErrorRate(const ISnir *snir, IRadioSignal::SignalPart part) const =0
Returns the bit error rate based on SNIR, modulation, FEC encoding and any other physical layer chara...
inet::physicallayer::ErrorModelBase::CorruptionMode::CM_CHUNK
@ CM_CHUNK
inet::physicallayer::IRadioSignal::SIGNAL_PART_WHOLE
@ SIGNAL_PART_WHOLE
Definition: IRadioSignal.h:26
inet::physicallayer::ErrorModelBase::corruptChunks
virtual Packet * corruptChunks(const Packet *packet, double ber, bool &isCorrupted) const
Definition: ErrorModelBase.cc:87
inet::physicallayer::ErrorModelBase::snirOffset
double snirOffset
Definition: ErrorModelBase.h:37
inet::physicallayer::ErrorModelBase::CorruptionMode::CM_PACKET
@ CM_PACKET
inet::physicallayer::ErrorModelBase::snirMode
SnirMode snirMode
Definition: ErrorModelBase.h:36
inet::physicallayer::ErrorModelBase::corruptBits
virtual Packet * corruptBits(const Packet *packet, double ber, bool &isCorrupted) const
Definition: ErrorModelBase.cc:59
PacketProtocolTag
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down PacketProtocolTag
Definition: IUdp-gates.txt:25
inet::physicallayer::ErrorModelBase::SnirMode::SM_MEAN
@ SM_MEAN
inet::physicallayer::ErrorModelBase::corruptionMode
CorruptionMode corruptionMode
Definition: ErrorModelBase.h:35
inet::units::units::B
intscale< b, 1, 8 > B
Definition: Units.h:1168
inet::physicallayer::ErrorModelBase::computeCorruptedPacket
virtual Packet * computeCorruptedPacket(const Packet *packet, double ber) const
Definition: ErrorModelBase.cc:113
inet::physicallayer::ErrorModelBase::corruptBytes
virtual Packet * corruptBytes(const Packet *packet, double ber, bool &isCorrupted) const
Definition: ErrorModelBase.cc:73
inet::math::dB2fraction
double dB2fraction(double dB)
Converts a dB value to fraction.
Definition: INETMath.h:153
inet::physicallayer::ErrorModelBase::CorruptionMode::CM_BYTE
@ CM_BYTE
inet::INITSTAGE_LOCAL
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
inet::units::values::b
value< int64_t, units::b > b
Definition: Units.h:1241
inet::physicallayer::ErrorModelBase::corruptPacket
virtual Packet * corruptPacket(const Packet *packet, bool &isCorrupted) const
Definition: ErrorModelBase.cc:105
inet::physicallayer::ErrorModelBase::hasProbabilisticError
virtual bool hasProbabilisticError(b length, double ber) const
Definition: ErrorModelBase.cc:53
inet::physicallayer::ErrorModelBase::SnirMode::SM_MIN
@ SM_MIN
inet::physicallayer::ErrorModelBase::CorruptionMode::CM_BIT
@ CM_BIT