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

#include <MultiNetworkLayerUpperMultiplexer.h>

Inheritance diagram for inet::MultiNetworkLayerUpperMultiplexer:

Public Member Functions

 MultiNetworkLayerUpperMultiplexer ()
 
virtual ~MultiNetworkLayerUpperMultiplexer ()
 

Protected Member Functions

virtual void initialize () override
 
virtual void handleMessage (cMessage *message) override
 
int getProtocolCount ()
 
int getProtocolIndex (cMessage *message)
 

Constructor & Destructor Documentation

inet::MultiNetworkLayerUpperMultiplexer::MultiNetworkLayerUpperMultiplexer ( )
inline
29 {}
virtual inet::MultiNetworkLayerUpperMultiplexer::~MultiNetworkLayerUpperMultiplexer ( )
inlinevirtual
30 {}

Member Function Documentation

int inet::MultiNetworkLayerUpperMultiplexer::getProtocolCount ( )
protected

Referenced by handleMessage(), and initialize().

82 {
83  return 3;
84 }
int inet::MultiNetworkLayerUpperMultiplexer::getProtocolIndex ( cMessage *  message)
protected

Referenced by handleMessage().

87 {
88  cPacket *packet = check_and_cast<cPacket *>(message);
89  cObject *controlInfo = packet->getControlInfo();
90  // TODO: handle the case when some network protocols are disabled
91  if (dynamic_cast<IPv4ControlInfo *>(controlInfo))
92  return 0;
93  else if (dynamic_cast<IPv6ControlInfo *>(controlInfo))
94  return 1;
95  else if (dynamic_cast<GenericNetworkProtocolControlInfo *>(controlInfo))
96  return 2;
97  else
98  throw cRuntimeError("Unknown control info");
99 }
void inet::MultiNetworkLayerUpperMultiplexer::handleMessage ( cMessage *  message)
overrideprotectedvirtual
53 {
54  cGate *arrivalGate = message->getArrivalGate();
55  const char *arrivalGateName = arrivalGate->getBaseName();
56  if (!strcmp(arrivalGateName, "transportUpperIn")) {
57  if (dynamic_cast<cPacket *>(message))
58  send(message, "transportLowerOut", getProtocolCount() * arrivalGate->getIndex() + getProtocolIndex(message));
59  else {
60  // sending down commands
61  for (int i = 0; i < getProtocolCount(); i++) {
62  cMessage *duplicate = message->dup();
63  cObject *controlInfo = message->getControlInfo();
64  if (controlInfo)
65  duplicate->setControlInfo(controlInfo->dup());
66  send(duplicate, "transportLowerOut", getProtocolCount() * arrivalGate->getIndex() + i);
67  }
68  delete message;
69  }
70  }
71  else if (!strcmp(arrivalGateName, "transportLowerIn"))
72  send(message, "transportUpperOut", arrivalGate->getIndex() / getProtocolCount());
73  else if (!strcmp(arrivalGateName, "pingUpperIn"))
74  send(message, "pingLowerOut", getProtocolCount() * arrivalGate->getIndex() + getProtocolIndex(message));
75  else if (!strcmp(arrivalGateName, "pingLowerIn"))
76  send(message, "pingUpperOut", arrivalGate->getIndex() / getProtocolCount());
77  else
78  throw cRuntimeError("Unknown arrival gate");
79 }
int getProtocolIndex(cMessage *message)
Definition: MultiNetworkLayerUpperMultiplexer.cc:86
int getProtocolCount()
Definition: MultiNetworkLayerUpperMultiplexer.cc:81
void inet::MultiNetworkLayerUpperMultiplexer::initialize ( )
overrideprotectedvirtual
29 {
30  int transportUpperInGateSize = gateSize("transportUpperIn");
31  int transportUpperOutGateSize = gateSize("transportUpperOut");
32  if (transportUpperInGateSize != transportUpperOutGateSize)
33  throw cRuntimeError("Connection error: transportUpperIn[] and transportUpperOut[] gate size differ");
34  int transportLowerInGateSize = gateSize("transportLowerIn");
35  int transportLowerOutGateSize = gateSize("transportLowerOut");
36  if (transportLowerInGateSize != transportLowerOutGateSize)
37  throw cRuntimeError("Connection error: transportLowerIn[] and transportLowerOut[] gate size differ");
38  if (transportUpperInGateSize * getProtocolCount() != transportLowerOutGateSize)
39  throw cRuntimeError("Connection error: transportUpperIn[] / transportLowerOut[] gate size ratio not correct");
40  int pingUpperInGateSize = gateSize("pingUpperIn");
41  int pingUpperOutGateSize = gateSize("pingUpperOut");
42  if (pingUpperInGateSize != pingUpperOutGateSize)
43  throw cRuntimeError("Connection error: pingUpperIn[] and pingUpperOut[] gate size differ");
44  int pingLowerInGateSize = gateSize("pingLowerIn");
45  int pingLowerOutGateSize = gateSize("pingLowerOut");
46  if (pingLowerInGateSize != pingLowerOutGateSize)
47  throw cRuntimeError("Connection error: pingLowerIn[] and pingLowerOut[] gate size differ");
48  if (pingUpperInGateSize * getProtocolCount() != pingLowerOutGateSize)
49  throw cRuntimeError("Connection error: pingUpperIn[] / pingLowerOut[] gate size ratio not correct");
50 }
int getProtocolCount()
Definition: MultiNetworkLayerUpperMultiplexer.cc:81

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