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

Implementation of MatrixCloudDelayer. More...

#include <MatrixCloudDelayer.h>

Inheritance diagram for inet::MatrixCloudDelayer:
inet::CloudDelayerBase inet::NetfilterBase::HookBase inet::INetfilter::IHook

Classes

class  Descriptor
 
class  Matcher
 
class  MatrixEntry
 

Protected Types

typedef std::pair< int, int > IdPair
 
typedef std::map< IdPair, DescriptorIdPairToDescriptorMap
 
typedef std::vector< MatrixEntry * > MatrixEntryPtrVector
 

Protected Member Functions

virtual ~MatrixCloudDelayer ()
 
virtual int numInitStages () const override
 
virtual void initialize (int stage) override
 
virtual void calculateDropAndDelay (const cMessage *msg, int srcID, int destID, bool &outDrop, simtime_t &outDelay) override
 returns isDrop and delay for this msg More...
 
MatrixCloudDelayer::DescriptorgetOrCreateDescriptor (int srcID, int destID)
 
std::string getPathOfConnectedNodeOnIfaceID (int id)
 returns path of connected node for the interface specified by 'id' More...
 
- Protected Member Functions inherited from inet::CloudDelayerBase
virtual void finish () override
 
virtual void handleMessage (cMessage *msg) override
 
virtual INetfilter::IHook::Result datagramPreRoutingHook (Packet *datagram) override
 This is the first hook called by the network protocol before it routes a datagram that was received from the lower layer. More...
 
virtual INetfilter::IHook::Result datagramForwardHook (Packet *datagram) override
 This is the second hook called by the network protocol before it sends a datagram to the lower layer. More...
 
virtual INetfilter::IHook::Result datagramPostRoutingHook (Packet *datagram) override
 This is the last hook called by the network protocol before it sends a datagram to the lower layer. More...
 
virtual INetfilter::IHook::Result datagramLocalInHook (Packet *datagram) override
 This is the last hook called by the network protocol before it sends a datagram to the upper layer. More...
 
virtual INetfilter::IHook::Result datagramLocalOutHook (Packet *datagram) override
 This is the first hook called by the network protocol before it routes a datagram that was received from the upper layer. More...
 

Protected Attributes

MatrixEntryPtrVector matrixEntries
 
IdPairToDescriptorMap idPairToDescriptorMap
 
ModuleRefByPar< IInterfaceTableift
 
cModule * host = nullptr
 
- Protected Attributes inherited from inet::CloudDelayerBase
ModuleRefByPar< INetfilternetworkProtocol
 
- Protected Attributes inherited from inet::NetfilterBase::HookBase
std::vector< INetfilter * > netfilters
 

Additional Inherited Members

- Public Types inherited from inet::INetfilter::IHook
enum  Type {
  PREROUTING, LOCALIN, FORWARD, POSTROUTING,
  LOCALOUT
}
 
enum  Result { ACCEPT, DROP, QUEUE, STOLEN }
 
- Public Member Functions inherited from inet::CloudDelayerBase
 CloudDelayerBase ()
 
 ~CloudDelayerBase ()
 
- Public Member Functions inherited from inet::NetfilterBase::HookBase
virtual ~HookBase ()
 
void registeredTo (INetfilter *nf)
 
void unregisteredFrom (INetfilter *nf)
 
bool isRegisteredHook (INetfilter *nf)
 
- Public Member Functions inherited from inet::INetfilter::IHook
virtual ~IHook ()
 

Detailed Description

Implementation of MatrixCloudDelayer.

See NED file for details.

Member Typedef Documentation

◆ IdPair

typedef std::pair<int, int> inet::MatrixCloudDelayer::IdPair
protected

◆ IdPairToDescriptorMap

◆ MatrixEntryPtrVector

Constructor & Destructor Documentation

◆ ~MatrixCloudDelayer()

inet::MatrixCloudDelayer::~MatrixCloudDelayer ( )
protectedvirtual
92 {
93  for (auto& elem : matrixEntries)
94  delete elem;
95  matrixEntries.clear();
96 }

Member Function Documentation

◆ calculateDropAndDelay()

void inet::MatrixCloudDelayer::calculateDropAndDelay ( const cMessage *  msg,
int  srcID,
int  destID,
bool &  outDrop,
simtime_t &  outDelay 
)
overrideprotectedvirtual

returns isDrop and delay for this msg

Reimplemented from inet::CloudDelayerBase.

125 {
126  Descriptor *descriptor = getOrCreateDescriptor(srcID, destID);
127  outDrop = descriptor->dropPar->boolValue(this);
128  outDelay = SIMTIME_ZERO;
129  if (!outDrop) {
130  outDelay = descriptor->delayPar->doubleValue(this, "s");
131  double datarate = descriptor->dataratePar->doubleValue(this, "bps");
132  ASSERT(outDelay >= 0);
133  ASSERT(datarate > 0.0);
134  simtime_t curTime = simTime();
135  if (curTime + outDelay < descriptor->lastSent)
136  outDelay = descriptor->lastSent - curTime;
137 
138  const cPacket *pk = dynamic_cast<const cPacket *>(msg);
139  if (pk)
140  outDelay += pk->getBitLength() / datarate;
141 
142  descriptor->lastSent = curTime + outDelay;
143  }
144 }

◆ getOrCreateDescriptor()

MatrixCloudDelayer::Descriptor * inet::MatrixCloudDelayer::getOrCreateDescriptor ( int  srcID,
int  destID 
)
protected
147 {
148  IdPair idPair(srcID, destID);
149  auto it = idPairToDescriptorMap.find(idPair);
150  if (it != idPairToDescriptorMap.end())
151  return &(it->second);
152 
153  std::string src = getPathOfConnectedNodeOnIfaceID(srcID);
154  std::string dest = getPathOfConnectedNodeOnIfaceID(destID);
155 
156  // find first matching node in XML
157  MatrixEntry *reverseMatrixEntry = nullptr;
158  for (auto& elem : matrixEntries) {
159  MatrixEntry *matrixEntry = elem;
160  if (matrixEntry->matches(src.c_str(), dest.c_str())) {
161  MatrixCloudDelayer::Descriptor& descriptor = idPairToDescriptorMap[idPair];
162  descriptor.delayPar = &matrixEntry->delayPar;
163  descriptor.dataratePar = &matrixEntry->dataratePar;
164  descriptor.dropPar = &matrixEntry->dropPar;
165  descriptor.lastSent = simTime();
166  if (matrixEntry->symmetric) {
167  if (reverseMatrixEntry) // existing previous asymmetric entry which matching to (dest,src)
168  throw cRuntimeError("Inconsistent xml config between '%s' and '%s' nodes (at %s and %s)",
169  src.c_str(), dest.c_str(), matrixEntry->entity->getSourceLocation(),
170  reverseMatrixEntry->entity->getSourceLocation());
171  IdPair reverseIdPair(destID, srcID);
172  MatrixCloudDelayer::Descriptor& rdescriptor = idPairToDescriptorMap[reverseIdPair];
173  rdescriptor = descriptor;
174  }
175  return &descriptor;
176  }
177  else if (!matrixEntry->symmetric && !reverseMatrixEntry && matrixEntry->matches(dest.c_str(), src.c_str())) {
178  // store first matched asymmetric reverse entry to reverseMatrixEntry
179  reverseMatrixEntry = matrixEntry;
180  }
181  }
182  throw cRuntimeError("The 'traffic' xml entity not found for communication from '%s' to '%s' node", src.c_str(),
183  dest.c_str());
184 }

Referenced by calculateDropAndDelay().

◆ getPathOfConnectedNodeOnIfaceID()

std::string inet::MatrixCloudDelayer::getPathOfConnectedNodeOnIfaceID ( int  id)
protected

returns path of connected node for the interface specified by 'id'

187 {
188  NetworkInterface *ie = ift->getInterfaceById(id);
189  if (!ie)
190  throw cRuntimeError("The interface id=%i not found in interfacetable", id);
191 
192  int gateId;
193  cGate *connectedGate = nullptr;
194 
195  if ((gateId = ie->getNodeOutputGateId()) != -1)
196  connectedGate = host->gate(gateId)->getPathEndGate();
197  else if ((gateId = ie->getNodeInputGateId()) != -1)
198  connectedGate = host->gate(gateId)->getPathStartGate();
199 
200  if (!connectedGate)
201  throw cRuntimeError("Interface '%s' (id=%i) not connected", ie->getFullName(), id);
202 
203  cModule *connNode = findContainingNode(connectedGate->getOwnerModule());
204  if (!connNode)
205  throw cRuntimeError("The connected node is unknown at interface '%s' (id=%i)", ie->getFullName(), id);
206 
207  return connNode->getFullPath();
208 }

Referenced by getOrCreateDescriptor().

◆ initialize()

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

Reimplemented from inet::CloudDelayerBase.

99 {
100  using namespace xmlutils;
101 
103 
104  if (stage == INITSTAGE_LOCAL) {
105  host = getContainingNode(this);
106  ift.reference(this, "interfaceTableModule", true);
107  cXMLElement *configEntity = par("config");
108  // parse XML config
109  if (strcmp(configEntity->getTagName(), "internetCloud"))
110  throw cRuntimeError("Cannot read internetCloud configuration, unaccepted '%s' entity at %s", configEntity->getTagName(),
111  configEntity->getSourceLocation());
112  bool defaultSymmetric = getAttributeBoolValue(configEntity, "symmetric");
113  const cXMLElement *parameterEntity = getUniqueChild(configEntity, "parameters");
114  cXMLElementList trafficEntities = parameterEntity->getChildrenByTagName("traffic");
115  for (auto& trafficEntitie : trafficEntities) {
116  cXMLElement *trafficEntity = trafficEntitie;
117  MatrixEntry *matrixEntry = new MatrixEntry(trafficEntity, defaultSymmetric);
118  matrixEntries.push_back(matrixEntry);
119  }
120  }
121 }

◆ numInitStages()

virtual int inet::MatrixCloudDelayer::numInitStages ( ) const
inlineoverrideprotectedvirtual

Reimplemented from inet::CloudDelayerBase.

77 { return NUM_INIT_STAGES; }

Member Data Documentation

◆ host

cModule* inet::MatrixCloudDelayer::host = nullptr
protected

◆ idPairToDescriptorMap

IdPairToDescriptorMap inet::MatrixCloudDelayer::idPairToDescriptorMap
protected

Referenced by getOrCreateDescriptor().

◆ ift

ModuleRefByPar<IInterfaceTable> inet::MatrixCloudDelayer::ift
protected

◆ matrixEntries

MatrixEntryPtrVector inet::MatrixCloudDelayer::matrixEntries
protected

The documentation for this class was generated from the following files:
inet::findContainingNode
cModule * findContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:31
inet::MatrixCloudDelayer::IdPair
std::pair< int, int > IdPair
Definition: MatrixCloudDelayer.h:65
inet::CloudDelayerBase::initialize
virtual void initialize(int stage) override
Definition: CloudDelayerBase.cc:27
inet::MatrixCloudDelayer::getOrCreateDescriptor
MatrixCloudDelayer::Descriptor * getOrCreateDescriptor(int srcID, int destID)
Definition: MatrixCloudDelayer.cc:146
inet::getContainingNode
cModule * getContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:40
inet::MatrixCloudDelayer::host
cModule * host
Definition: MatrixCloudDelayer.h:73
inet::MatrixCloudDelayer::matrixEntries
MatrixEntryPtrVector matrixEntries
Definition: MatrixCloudDelayer.h:69
inet::xmlutils::getAttributeBoolValue
bool getAttributeBoolValue(const cXMLElement *node, const char *attrName, bool defVal)
Definition: XMLUtils.cc:169
inet::xmlutils::getUniqueChild
const cXMLElement * getUniqueChild(const cXMLElement *node, const char *name)
Definition: XMLUtils.cc:9
inet::INITSTAGE_LOCAL
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
NUM_INIT_STAGES
#define NUM_INIT_STAGES
Definition: InitStageRegistry.h:73
inet::MatrixCloudDelayer::ift
ModuleRefByPar< IInterfaceTable > ift
Definition: MatrixCloudDelayer.h:72
inet::MatrixCloudDelayer::idPairToDescriptorMap
IdPairToDescriptorMap idPairToDescriptorMap
Definition: MatrixCloudDelayer.h:70
inet::MatrixCloudDelayer::getPathOfConnectedNodeOnIfaceID
std::string getPathOfConnectedNodeOnIfaceID(int id)
returns path of connected node for the interface specified by 'id'
Definition: MatrixCloudDelayer.cc:186