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

Maps protocol numbers to output gates. More...

#include <ProtocolMap.h>

Classes

struct  Entry
 

Public Member Functions

 ProtocolMapping ()
 
 ~ProtocolMapping ()
 
void addProtocolMapping (int protocol, int gateIndex)
 
void parseProtocolMapping (const char *s)
 
int findOutputGateForProtocol (int protocol) const
 find output gate index for protocol ID and returns it. More...
 
int getOutputGateForProtocol (int protocol) const
 find output gate index for protocol ID and returns it. More...
 

Protected Types

typedef std::vector< EntryEntries
 

Protected Attributes

Entries entries
 

Detailed Description

Maps protocol numbers to output gates.

Member Typedef Documentation

typedef std::vector<Entry> inet::ProtocolMapping::Entries
protected

Constructor & Destructor Documentation

inet::ProtocolMapping::ProtocolMapping ( )
inline
45 {}
inet::ProtocolMapping::~ProtocolMapping ( )
inline
46 {}

Member Function Documentation

void inet::ProtocolMapping::addProtocolMapping ( int  protocol,
int  gateIndex 
)

Referenced by inet::GenericNetworkProtocol::handleMessage(), inet::IPv6::handleMessage(), inet::IPv4::handleMessage(), and inet::NetworkProtocolBase::handleUpperCommand().

83 {
84  int registered = findOutputGateForProtocol(protocol);
85  if (registered == -2)
86  entries.push_back(Entry(protocol, gateIndex));
87  else if (registered == gateIndex)
88  EV_WARN << "The protocol " << protocol << " already registered to gate index=" << gateIndex << endl;
89  else
90  throw cRuntimeError("The protocol %d should not register to gate index=%d because it already registered to gate index=%d.", protocol, gateIndex, registered);
91 }
Entries entries
Definition: ProtocolMap.h:42
uint8_t protocol
Definition: TCP_NSC.cc:88
int findOutputGateForProtocol(int protocol) const
find output gate index for protocol ID and returns it.
Definition: ProtocolMap.cc:64
int inet::ProtocolMapping::findOutputGateForProtocol ( int  protocol) const

find output gate index for protocol ID and returns it.

Returns -2 if not found.

Referenced by addProtocolMapping(), getOutputGateForProtocol(), inet::IPv6::localDeliver(), inet::IPv4::reassembleAndDeliverFinish(), and inet::GenericNetworkProtocol::sendDatagramToHL().

65 {
66  for (const auto & elem : entries)
67  if (elem.protocolNumber == protocol)
68  return elem.outGateIndex;
69 
70 
71  return -2; // illegal gateindex
72 }
Entries entries
Definition: ProtocolMap.h:42
uint8_t protocol
Definition: TCP_NSC.cc:88
int inet::ProtocolMapping::getOutputGateForProtocol ( int  protocol) const

find output gate index for protocol ID and returns it.

Throws an error if not found.

Referenced by inet::IPv4::handleIncomingICMP(), inet::IPv6::handleReceivedICMP(), inet::IPv4::sendOnTransportOutGateByProtocolId(), and inet::NetworkProtocolBase::sendUp().

75 {
77  if (ret >= -1)
78  return ret;
79  throw cRuntimeError("No output gate defined in protocolMapping for protocol number %d", protocol);
80 }
uint8_t protocol
Definition: TCP_NSC.cc:88
int findOutputGateForProtocol(int protocol) const
find output gate index for protocol ID and returns it.
Definition: ProtocolMap.cc:64
void inet::ProtocolMapping::parseProtocolMapping ( const char *  s)
25 {
26  while (isspace(*s))
27  s++;
28 
29  while (*s) {
30  Entry entry(-1, -1);
31 
32  if (!isdigit(*s))
33  throw cRuntimeError("Syntax error: protocol number expected");
34  entry.protocolNumber = atoi(s);
35  while (isdigit(*s))
36  s++;
37 
38  if (*s++ != ':')
39  throw cRuntimeError("Syntax error: colon expected");
40 
41  while (isspace(*s))
42  s++;
43  if (!isdigit(*s))
44  throw cRuntimeError("Syntax error in script: output gate index expected");
45  entry.outGateIndex = atoi(s);
46  while (isdigit(*s))
47  s++;
48 
49  // add
50  entries.push_back(entry);
51 
52  // skip delimiter
53  while (isspace(*s))
54  s++;
55  if (!*s)
56  break;
57  if (*s++ != ',')
58  throw cRuntimeError("Syntax error: comma expected");
59  while (isspace(*s))
60  s++;
61  }
62 }
Entries entries
Definition: ProtocolMap.h:42
value< double, units::s > s
Definition: Units.h:1049

Member Data Documentation

Entries inet::ProtocolMapping::entries
protected

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