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

TODO documentation. More...

#include <LIBTable.h>

Inheritance diagram for inet::LIBTable:

Classes

struct  LIBEntry
 

Public Member Functions

virtual bool resolveLabel (std::string inInterface, int inLabel, LabelOpVector &outLabel, std::string &outInterface, int &color)
 
virtual int installLibEntry (int inLabel, std::string inInterface, const LabelOpVector &outLabel, std::string outInterface, int color)
 
virtual void removeLibEntry (int inLabel)
 

Static Public Member Functions

static LabelOpVector pushLabel (int label)
 
static LabelOpVector swapLabel (int label)
 
static LabelOpVector popLabel ()
 

Protected Member Functions

virtual void initialize (int stage) override
 
virtual int numInitStages () const override
 
virtual void handleMessage (cMessage *msg) override
 
virtual void readTableFromXML (const cXMLElement *libtable)
 

Protected Attributes

int maxLabel
 
std::vector< LIBEntrylib
 

Detailed Description

TODO documentation.

Member Function Documentation

void inet::LIBTable::handleMessage ( cMessage *  msg)
overrideprotectedvirtual
39 {
40  ASSERT(false);
41 }
void inet::LIBTable::initialize ( int  stage)
overrideprotectedvirtual
25 {
26  cSimpleModule::initialize(stage);
27 
28  if (stage == INITSTAGE_LOCAL) {
29  maxLabel = 0;
30  WATCH_VECTOR(lib);
31  }
32  else if (stage == INITSTAGE_NETWORK_LAYER) {
33  // read configuration
34  readTableFromXML(par("config").xmlValue());
35  }
36 }
std::vector< LIBEntry > lib
Definition: LIBTable.h:66
Initialization of network-layer protocols, stage 1.
Definition: InitStages.h:72
Local initializations.
Definition: InitStages.h:35
int maxLabel
Definition: LIBTable.h:65
virtual void readTableFromXML(const cXMLElement *libtable)
Definition: LIBTable.cc:105
int inet::LIBTable::installLibEntry ( int  inLabel,
std::string  inInterface,
const LabelOpVector outLabel,
std::string  outInterface,
int  color 
)
virtual

Referenced by inet::LDP::processLABEL_MAPPING(), inet::LDP::processLABEL_REQUEST(), and inet::LDP::updateFecListEntry().

66 {
67  if (inLabel == -1) {
68  LIBEntry newItem;
69  newItem.inLabel = ++maxLabel;
70  newItem.inInterface = inInterface;
71  newItem.outLabel = outLabel;
72  newItem.outInterface = outInterface;
73  newItem.color = color;
74  lib.push_back(newItem);
75  return newItem.inLabel;
76  }
77  else {
78  for (auto & elem : lib) {
79  if (elem.inLabel != inLabel)
80  continue;
81 
82  elem.inInterface = inInterface;
83  elem.outLabel = outLabel;
84  elem.outInterface = outInterface;
85  elem.color = color;
86  return inLabel;
87  }
88  ASSERT(false);
89  return 0; // prevent warning
90  }
91 }
std::vector< LIBEntry > lib
Definition: LIBTable.h:66
int maxLabel
Definition: LIBTable.h:65
virtual int inet::LIBTable::numInitStages ( ) const
inlineoverrideprotectedvirtual
70 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
LabelOpVector inet::LIBTable::popLabel ( )
static

Referenced by inet::LDP::processLABEL_REQUEST(), and inet::LDP::updateFecListEntry().

184 {
185  LabelOpVector vec;
186  LabelOp lop;
187  lop.optcode = POP_OPER;
188  lop.label = 0;
189  vec.push_back(lop);
190  return vec;
191 }
std::vector< LabelOp > LabelOpVector
Definition: LIBTable.h:44
#define POP_OPER
Definition: LIBTable.h:33
LabelOpVector inet::LIBTable::pushLabel ( int  label)
static

Referenced by inet::LDP::lookupLabel().

164 {
165  LabelOpVector vec;
166  LabelOp lop;
167  lop.optcode = PUSH_OPER;
168  lop.label = label;
169  vec.push_back(lop);
170  return vec;
171 }
std::vector< LabelOp > LabelOpVector
Definition: LIBTable.h:44
#define PUSH_OPER
Definition: LIBTable.h:31
void inet::LIBTable::readTableFromXML ( const cXMLElement *  libtable)
protectedvirtual

Referenced by initialize().

106 {
107  using namespace xmlutils;
108 
109  ASSERT(libtable);
110  ASSERT(!strcmp(libtable->getTagName(), "libtable"));
111  checkTags(libtable, "libentry");
112  cXMLElementList list = libtable->getChildrenByTagName("libentry");
113  for (auto & elem : list) {
114  const cXMLElement& entry = *elem;
115 
116  checkTags(&entry, "inLabel inInterface outLabel outInterface color");
117 
118  LIBEntry newItem;
119  newItem.inLabel = getParameterIntValue(&entry, "inLabel");
120  newItem.inInterface = getParameterStrValue(&entry, "inInterface");
121  newItem.outInterface = getParameterStrValue(&entry, "outInterface");
122  newItem.color = getParameterIntValue(&entry, "color", 0);
123 
124  cXMLElementList ops = getUniqueChild(&entry, "outLabel")->getChildrenByTagName("op");
125  for (auto & ops_oit : ops) {
126  const cXMLElement& op = *ops_oit;
127  const char *val = op.getAttribute("value");
128  const char *code = op.getAttribute("code");
129  ASSERT(code);
130  LabelOp l;
131 
132  if (!strcmp(code, "push")) {
133  l.optcode = PUSH_OPER;
134  ASSERT(val);
135  l.label = atoi(val);
136  ASSERT(l.label > 0);
137  }
138  else if (!strcmp(code, "pop")) {
139  l.optcode = POP_OPER;
140  ASSERT(!val);
141  }
142  else if (!strcmp(code, "swap")) {
143  l.optcode = SWAP_OPER;
144  ASSERT(val);
145  l.label = atoi(val);
146  ASSERT(l.label > 0);
147  }
148  else
149  ASSERT(false);
150 
151  newItem.outLabel.push_back(l);
152  }
153 
154  lib.push_back(newItem);
155 
156  ASSERT(newItem.inLabel > 0);
157 
158  if (newItem.inLabel > maxLabel)
159  maxLabel = newItem.inLabel;
160  }
161 }
std::vector< LIBEntry > lib
Definition: LIBTable.h:66
#define POP_OPER
Definition: LIBTable.h:33
const cXMLElement * getUniqueChild(const cXMLElement *node, const char *name)
Definition: XMLUtils.cc:8
const char * getParameterStrValue(const cXMLElement *ptr, const char *name, const char *def)
Definition: XMLUtils.cc:75
void checkTags(const cXMLElement *node, const char *allowed)
Definition: XMLUtils.cc:54
int maxLabel
Definition: LIBTable.h:65
int getParameterIntValue(const cXMLElement *ptr, const char *name, int def)
Definition: XMLUtils.cc:105
#define SWAP_OPER
Definition: LIBTable.h:32
#define PUSH_OPER
Definition: LIBTable.h:31
void inet::LIBTable::removeLibEntry ( int  inLabel)
virtual

Referenced by inet::LDP::processLABEL_RELEASE(), and inet::LDP::rebuildFecList().

94 {
95  for (unsigned int i = 0; i < lib.size(); i++) {
96  if (lib[i].inLabel != inLabel)
97  continue;
98 
99  lib.erase(lib.begin() + i);
100  return;
101  }
102  ASSERT(false);
103 }
std::vector< LIBEntry > lib
Definition: LIBTable.h:66
bool inet::LIBTable::resolveLabel ( std::string  inInterface,
int  inLabel,
LabelOpVector outLabel,
std::string &  outInterface,
int &  color 
)
virtual

Referenced by inet::MPLS::processMPLSPacketFromL2().

45 {
46  bool any = (inInterface.length() == 0);
47 
48  for (auto & elem : lib) {
49  if (!any && elem.inInterface != inInterface)
50  continue;
51 
52  if (elem.inLabel != inLabel)
53  continue;
54 
55  outLabel = elem.outLabel;
56  outInterface = elem.outInterface;
57  color = elem.color;
58 
59  return true;
60  }
61  return false;
62 }
std::vector< LIBEntry > lib
Definition: LIBTable.h:66
LabelOpVector inet::LIBTable::swapLabel ( int  label)
static

Referenced by inet::LDP::processLABEL_MAPPING(), inet::LDP::processLABEL_REQUEST(), and inet::LDP::updateFecListEntry().

174 {
175  LabelOpVector vec;
176  LabelOp lop;
177  lop.optcode = SWAP_OPER;
178  lop.label = label;
179  vec.push_back(lop);
180  return vec;
181 }
std::vector< LabelOp > LabelOpVector
Definition: LIBTable.h:44
#define SWAP_OPER
Definition: LIBTable.h:32

Member Data Documentation

std::vector<LIBEntry> inet::LIBTable::lib
protected
int inet::LIBTable::maxLabel
protected

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