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

Implementation of MatrixCloudDelayer. More...

#include <MatrixCloudDelayer.h>

Inheritance diagram for inet::MatrixCloudDelayer:
inet::CloudDelayerBase 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 (INetworkDatagram *datagram, const InterfaceEntry *inputInterfaceEntry, const InterfaceEntry *&outputInterfaceEntry, L3Address &nextHopAddress) 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 (INetworkDatagram *datagram, const InterfaceEntry *inputInterfaceEntry, const InterfaceEntry *&outputInterfaceEntry, L3Address &nextHopAddress) 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 (INetworkDatagram *datagram, const InterfaceEntry *inputInterfaceEntry, const InterfaceEntry *&outputInterfaceEntry, L3Address &nextHopAddress) 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 (INetworkDatagram *datagram, const InterfaceEntry *inputInterfaceEntry) 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 (INetworkDatagram *datagram, const InterfaceEntry *&outputInterfaceEntry, L3Address &nextHopAddress) 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
 
IInterfaceTableift = nullptr
 
cModule * host = nullptr
 
- Protected Attributes inherited from inet::CloudDelayerBase
IPv4ipv4Layer
 

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::INetfilter::IHook
virtual ~IHook ()
 

Detailed Description

Implementation of MatrixCloudDelayer.

See NED file for details.

Member Typedef Documentation

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

Constructor & Destructor Documentation

inet::MatrixCloudDelayer::~MatrixCloudDelayer ( )
protectedvirtual
128 {
129  for (auto & elem : matrixEntries)
130  delete elem;
131  matrixEntries.clear();
132 }
MatrixEntryPtrVector matrixEntries
Definition: MatrixCloudDelayer.h:85

Member Function Documentation

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.

161 {
162  Descriptor *descriptor = getOrCreateDescriptor(srcID, destID);
163  outDrop = descriptor->dropPar->boolValue(this);
164  outDelay = SIMTIME_ZERO;
165  if (!outDrop) {
166  outDelay = descriptor->delayPar->doubleValue(this, "s");
167  double datarate = descriptor->dataratePar->doubleValue(this, "bps");
168  ASSERT(outDelay >= 0);
169  ASSERT(datarate > 0.0);
170  simtime_t curTime = simTime();
171  if (curTime + outDelay < descriptor->lastSent)
172  outDelay = descriptor->lastSent - curTime;
173 
174  const cPacket *pk = dynamic_cast<const cPacket *>(msg);
175  if (pk)
176  outDelay += pk->getBitLength() / datarate;
177 
178  descriptor->lastSent = curTime + outDelay;
179  }
180 }
MatrixCloudDelayer::Descriptor * getOrCreateDescriptor(int srcID, int destID)
Definition: MatrixCloudDelayer.cc:182
MatrixCloudDelayer::Descriptor * inet::MatrixCloudDelayer::getOrCreateDescriptor ( int  srcID,
int  destID 
)
protected

Referenced by calculateDropAndDelay().

183 {
184  IDPair idPair(srcID, destID);
185  auto it = idPairToDescriptorMap.find(idPair);
186  if (it != idPairToDescriptorMap.end())
187  return &(it->second);
188 
189  std::string src = getPathOfConnectedNodeOnIfaceID(srcID);
190  std::string dest = getPathOfConnectedNodeOnIfaceID(destID);
191 
192  // find first matching node in XML
193  MatrixEntry *reverseMatrixEntry = nullptr;
194  for (auto & elem : matrixEntries) {
195  MatrixEntry *matrixEntry = elem;
196  if (matrixEntry->matches(src.c_str(), dest.c_str())) {
197  MatrixCloudDelayer::Descriptor& descriptor = idPairToDescriptorMap[idPair];
198  descriptor.delayPar = &matrixEntry->delayPar;
199  descriptor.dataratePar = &matrixEntry->dataratePar;
200  descriptor.dropPar = &matrixEntry->dropPar;
201  descriptor.lastSent = simTime();
202  if (matrixEntry->symmetric) {
203  if (reverseMatrixEntry) // existing previous asymmetric entry which matching to (dest,src)
204  throw cRuntimeError("Inconsistent xml config between '%s' and '%s' nodes (at %s and %s)",
205  src.c_str(), dest.c_str(), matrixEntry->entity->getSourceLocation(),
206  reverseMatrixEntry->entity->getSourceLocation());
207  IDPair reverseIdPair(destID, srcID);
208  MatrixCloudDelayer::Descriptor& rdescriptor = idPairToDescriptorMap[reverseIdPair];
209  rdescriptor = descriptor;
210  }
211  return &descriptor;
212  }
213  else if (!matrixEntry->symmetric && !reverseMatrixEntry && matrixEntry->matches(dest.c_str(), src.c_str())) {
214  // store first matched asymmetric reverse entry to reverseMatrixEntry
215  reverseMatrixEntry = matrixEntry;
216  }
217  }
218  throw cRuntimeError("The 'traffic' xml entity not found for communication from '%s' to '%s' node", src.c_str(),
219  dest.c_str());
220 }
std::pair< int, int > IDPair
Definition: MatrixCloudDelayer.h:81
MatrixEntryPtrVector matrixEntries
Definition: MatrixCloudDelayer.h:85
std::string getPathOfConnectedNodeOnIfaceID(int id)
returns path of connected node for the interface specified by &#39;id&#39;
Definition: MatrixCloudDelayer.cc:222
IDPairToDescriptorMap idPairToDescriptorMap
Definition: MatrixCloudDelayer.h:86
std::string inet::MatrixCloudDelayer::getPathOfConnectedNodeOnIfaceID ( int  id)
protected

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

Referenced by getOrCreateDescriptor().

223 {
224  InterfaceEntry *ie = ift->getInterfaceById(id);
225  if (!ie)
226  throw cRuntimeError("The interface id=%i not found in interfacetable", id);
227 
228  int gateId;
229  cGate *connectedGate = nullptr;
230 
231  if ((gateId = ie->getNodeOutputGateId()) != -1)
232  connectedGate = host->gate(gateId)->getPathEndGate();
233  else if ((gateId = ie->getNodeInputGateId()) != -1)
234  connectedGate = host->gate(gateId)->getPathStartGate();
235 
236  if (!connectedGate)
237  throw cRuntimeError("Interface '%s' (id=%i) not connected", ie->getFullName(), id);
238 
239  cModule *connNode = findContainingNode(connectedGate->getOwnerModule());
240  if (!connNode)
241  throw cRuntimeError("The connected node is unknown at interface '%s' (id=%i)", ie->getFullName(), id);
242 
243  return connNode->getFullPath();
244 }
virtual InterfaceEntry * getInterfaceById(int id) const =0
Returns an interface by its Id.
cModule * host
Definition: MatrixCloudDelayer.h:89
cModule * findContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:56
uint16_t id
Definition: TCP_NSC.cc:85
IInterfaceTable * ift
Definition: MatrixCloudDelayer.h:88
void inet::MatrixCloudDelayer::initialize ( int  stage)
overrideprotectedvirtual

Reimplemented from inet::CloudDelayerBase.

135 {
136  using namespace xmlutils;
137 
139 
140  if (stage == INITSTAGE_LOCAL) {
141  host = getContainingNode(this);
142  ift = getModuleFromPar<IInterfaceTable>(par("interfaceTableModule"), this);
143  cXMLElement *configEntity = par("config").xmlValue();
144  // parse XML config
145  if (strcmp(configEntity->getTagName(), "internetCloud"))
146  throw cRuntimeError("Cannot read internetCloud configuration, unaccepted '%s' entity at %s", configEntity->getTagName(),
147  configEntity->getSourceLocation());
148  bool defaultSymmetric = getBoolAttribute(*configEntity, "symmetric");
149  const cXMLElement *parameterEntity = getUniqueChild(configEntity, "parameters");
150  cXMLElementList trafficEntities = parameterEntity->getChildrenByTagName("traffic");
151  for (auto & trafficEntitie : trafficEntities) {
152  cXMLElement *trafficEntity = trafficEntitie;
153  MatrixEntry *matrixEntry = new MatrixEntry(trafficEntity, defaultSymmetric);
154  matrixEntries.push_back(matrixEntry);
155  }
156  }
157 }
cModule * host
Definition: MatrixCloudDelayer.h:89
MatrixEntryPtrVector matrixEntries
Definition: MatrixCloudDelayer.h:85
const cXMLElement * getUniqueChild(const cXMLElement *node, const char *name)
Definition: XMLUtils.cc:8
virtual void initialize(int stage) override
Definition: CloudDelayerBase.cc:43
Local initializations.
Definition: InitStages.h:35
cModule * getContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:65
IInterfaceTable * ift
Definition: MatrixCloudDelayer.h:88
virtual int inet::MatrixCloudDelayer::numInitStages ( ) const
inlineoverrideprotectedvirtual

Reimplemented from inet::CloudDelayerBase.

93 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116

Member Data Documentation

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

Referenced by getOrCreateDescriptor().

IInterfaceTable* inet::MatrixCloudDelayer::ift = nullptr
protected
MatrixEntryPtrVector inet::MatrixCloudDelayer::matrixEntries
protected

The documentation for this class was generated from the following files: