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

Represents the Label Information Base (LIB) for MPLS. 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

Represents the Label Information Base (LIB) for MPLS.

Member Function Documentation

◆ handleMessage()

void inet::LibTable::handleMessage ( cMessage *  msg)
overrideprotectedvirtual
33 {
34  ASSERT(false);
35 }

◆ initialize()

void inet::LibTable::initialize ( int  stage)
overrideprotectedvirtual
19 {
20  cSimpleModule::initialize(stage);
21 
22  if (stage == INITSTAGE_LOCAL) {
23  maxLabel = 0;
24  WATCH_VECTOR(lib);
25  }
26  else if (stage == INITSTAGE_NETWORK_LAYER) {
27  // read configuration
28  readTableFromXML(par("config"));
29  }
30 }

◆ installLibEntry()

int inet::LibTable::installLibEntry ( int  inLabel,
std::string  inInterface,
const LabelOpVector outLabel,
std::string  outInterface,
int  color 
)
virtual
60 {
61  if (inLabel == -1) {
62  LibEntry newItem;
63  newItem.inLabel = ++maxLabel;
64  newItem.inInterface = inInterface;
65  newItem.outLabel = outLabel;
66  newItem.outInterface = outInterface;
67  newItem.color = color;
68  lib.push_back(newItem);
69  return newItem.inLabel;
70  }
71  else {
72  for (auto& elem : lib) {
73  if (elem.inLabel != inLabel)
74  continue;
75 
76  elem.inInterface = inInterface;
77  elem.outLabel = outLabel;
78  elem.outInterface = outInterface;
79  elem.color = color;
80  return inLabel;
81  }
82  ASSERT(false);
83  return 0; // prevent warning
84  }
85 }

◆ numInitStages()

virtual int inet::LibTable::numInitStages ( ) const
inlineoverrideprotectedvirtual
57 { return NUM_INIT_STAGES; }

◆ popLabel()

LabelOpVector inet::LibTable::popLabel ( )
static
178 {
179  LabelOpVector vec;
180  LabelOp lop;
181  lop.optcode = POP_OPER;
182  lop.label = 0;
183  vec.push_back(lop);
184  return vec;
185 }

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

◆ pushLabel()

LabelOpVector inet::LibTable::pushLabel ( int  label)
static
158 {
159  LabelOpVector vec;
160  LabelOp lop;
161  lop.optcode = PUSH_OPER;
162  lop.label = label;
163  vec.push_back(lop);
164  return vec;
165 }

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

◆ readTableFromXML()

void inet::LibTable::readTableFromXML ( const cXMLElement *  libtable)
protectedvirtual
100 {
101  using namespace xmlutils;
102 
103  ASSERT(libtable);
104  ASSERT(!strcmp(libtable->getTagName(), "libtable"));
105  checkTags(libtable, "libentry");
106  cXMLElementList list = libtable->getChildrenByTagName("libentry");
107  for (auto& elem : list) {
108  const cXMLElement& entry = *elem;
109 
110  checkTags(&entry, "inLabel inInterface outLabel outInterface color");
111 
112  LibEntry newItem;
113  newItem.inLabel = getParameterIntValue(&entry, "inLabel");
114  newItem.inInterface = getParameterStrValue(&entry, "inInterface");
115  newItem.outInterface = getParameterStrValue(&entry, "outInterface");
116  newItem.color = getParameterIntValue(&entry, "color", 0);
117 
118  cXMLElementList ops = getUniqueChild(&entry, "outLabel")->getChildrenByTagName("op");
119  for (auto& ops_oit : ops) {
120  const cXMLElement& op = *ops_oit;
121  const char *val = op.getAttribute("value");
122  const char *code = op.getAttribute("code");
123  ASSERT(code);
124  LabelOp l;
125 
126  if (!strcmp(code, "push")) {
127  l.optcode = PUSH_OPER;
128  ASSERT(val);
129  l.label = atoi(val);
130  ASSERT(l.label > 0);
131  }
132  else if (!strcmp(code, "pop")) {
133  l.optcode = POP_OPER;
134  ASSERT(!val);
135  }
136  else if (!strcmp(code, "swap")) {
137  l.optcode = SWAP_OPER;
138  ASSERT(val);
139  l.label = atoi(val);
140  ASSERT(l.label > 0);
141  }
142  else
143  ASSERT(false);
144 
145  newItem.outLabel.push_back(l);
146  }
147 
148  lib.push_back(newItem);
149 
150  ASSERT(newItem.inLabel > 0);
151 
152  if (newItem.inLabel > maxLabel)
153  maxLabel = newItem.inLabel;
154  }
155 }

Referenced by initialize().

◆ removeLibEntry()

void inet::LibTable::removeLibEntry ( int  inLabel)
virtual
88 {
89  for (unsigned int i = 0; i < lib.size(); i++) {
90  if (lib[i].inLabel != inLabel)
91  continue;
92 
93  lib.erase(lib.begin() + i);
94  return;
95  }
96  ASSERT(false);
97 }

◆ resolveLabel()

bool inet::LibTable::resolveLabel ( std::string  inInterface,
int  inLabel,
LabelOpVector outLabel,
std::string &  outInterface,
int &  color 
)
virtual
39 {
40  bool any = (inInterface.length() == 0);
41 
42  for (auto& elem : lib) {
43  if (!any && elem.inInterface != inInterface)
44  continue;
45 
46  if (elem.inLabel != inLabel)
47  continue;
48 
49  outLabel = elem.outLabel;
50  outInterface = elem.outInterface;
51  color = elem.color;
52 
53  return true;
54  }
55  return false;
56 }

◆ swapLabel()

LabelOpVector inet::LibTable::swapLabel ( int  label)
static
168 {
169  LabelOpVector vec;
170  LabelOp lop;
171  lop.optcode = SWAP_OPER;
172  lop.label = label;
173  vec.push_back(lop);
174  return vec;
175 }

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

Member Data Documentation

◆ lib

std::vector<LibEntry> inet::LibTable::lib
protected

◆ maxLabel

int inet::LibTable::maxLabel
protected

The documentation for this class was generated from the following files:
inet::xmlutils::getParameterIntValue
int getParameterIntValue(const cXMLElement *ptr, const char *name, int def)
Definition: XMLUtils.cc:106
inet::INITSTAGE_NETWORK_LAYER
INET_API InitStage INITSTAGE_NETWORK_LAYER
Initialization of network layer protocols.
inet::LibTable::readTableFromXML
virtual void readTableFromXML(const cXMLElement *libtable)
Definition: LibTable.cc:99
inet::SWAP_OPER
@ SWAP_OPER
Definition: LibTable.h:22
inet::xmlutils::checkTags
void checkTags(const cXMLElement *node, const char *allowed)
Definition: XMLUtils.cc:55
inet::xmlutils::getParameterStrValue
const char * getParameterStrValue(const cXMLElement *ptr, const char *name, const char *def)
Definition: XMLUtils.cc:76
inet::LabelOpVector
std::vector< LabelOp > LabelOpVector
Definition: LibTable.h:32
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:
inet::LibTable::maxLabel
int maxLabel
Definition: LibTable.h:52
NUM_INIT_STAGES
#define NUM_INIT_STAGES
Definition: InitStageRegistry.h:73
inet::LibTable::lib
std::vector< LibEntry > lib
Definition: LibTable.h:53
inet::POP_OPER
@ POP_OPER
Definition: LibTable.h:23
inet::PUSH_OPER
@ PUSH_OPER
Definition: LibTable.h:21