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

TODO documentation. More...

#include <SimpleClassifier.h>

Inheritance diagram for inet::SimpleClassifier:
inet::IScriptable inet::IRSVPClassifier inet::IClassifier

Classes

struct  FECEntry
 

Public Member Functions

 SimpleClassifier ()
 
- Public Member Functions inherited from inet::IScriptable
virtual ~IScriptable ()
 
- Public Member Functions inherited from inet::IRSVPClassifier
virtual ~IRSVPClassifier ()
 
- Public Member Functions inherited from inet::IClassifier
virtual ~IClassifier ()
 

Protected Member Functions

virtual void initialize (int stage) override
 
virtual int numInitStages () const override
 
virtual void handleMessage (cMessage *msg) override
 
virtual void processCommand (const cXMLElement &node) override
 Called by ScenarioManager whenever a script command needs to be carried out by the module. More...
 
virtual bool lookupLabel (IPv4Datagram *ipdatagram, LabelOpVector &outLabel, std::string &outInterface, int &color) override
 The ipdatagram argument is an input parameter, the rest (outLabel, outInterface, color) are output parameters only. More...
 
virtual void bind (const SessionObj_t &session, const SenderTemplateObj_t &sender, int inLabel) override
 
virtual void readTableFromXML (const cXMLElement *fectable)
 
virtual void readItemFromXML (const cXMLElement *fec)
 
std::vector< FECEntry >::iterator findFEC (int fecid)
 

Protected Attributes

IPv4Address routerId
 
int maxLabel = 0
 
std::vector< FECEntrybindings
 
LIBTablelt = nullptr
 
RSVPrsvp = nullptr
 

Detailed Description

TODO documentation.

Constructor & Destructor Documentation

inet::SimpleClassifier::SimpleClassifier ( )
inline
63 {}

Member Function Documentation

void inet::SimpleClassifier::bind ( const SessionObj_t session,
const SenderTemplateObj_t sender,
int  inLabel 
)
overrideprotectedvirtual

Implements inet::IRSVPClassifier.

92 {
93  for (auto & elem : bindings) {
94  if (elem.session != session)
95  continue;
96 
97  if (elem.sender != sender)
98  continue;
99 
100  elem.inLabel = inLabel;
101  }
102 }
std::vector< FECEntry > bindings
Definition: SimpleClassifier.h:58
std::vector< SimpleClassifier::FECEntry >::iterator inet::SimpleClassifier::findFEC ( int  fecid)
protected
200 {
201  auto it = bindings.begin();
202  for ( ; it != bindings.end(); it++) {
203  if (it->id == fecid)
204  break;
205  }
206  return it;
207 }
std::vector< FECEntry > bindings
Definition: SimpleClassifier.h:58
void inet::SimpleClassifier::handleMessage ( cMessage *  msg)
overrideprotectedvirtual
50 {
51  ASSERT(false);
52 }
void inet::SimpleClassifier::initialize ( int  stage)
overrideprotectedvirtual
30 {
31  cSimpleModule::initialize(stage);
32 
33  if (stage == INITSTAGE_LOCAL) {
34  maxLabel = 0;
35  WATCH_VECTOR(bindings);
36  }
37  else if (stage == INITSTAGE_ROUTING_PROTOCOLS) {
38  IIPv4RoutingTable *rt = getModuleFromPar<IIPv4RoutingTable>(par("routingTableModule"), this);
39  routerId = rt->getRouterId();
40 
41  lt = getModuleFromPar<LIBTable>(par("libTableModule"), this);
42 
43  rsvp = getModuleFromPar<RSVP>(par("rsvpModule"), this);
44 
45  readTableFromXML(par("config").xmlValue());
46  }
47 }
std::vector< FECEntry > bindings
Definition: SimpleClassifier.h:58
IPv4Address routerId
Definition: SimpleClassifier.h:55
virtual void readTableFromXML(const cXMLElement *fectable)
Definition: SimpleClassifier.cc:117
int maxLabel
Definition: SimpleClassifier.h:56
LIBTable * lt
Definition: SimpleClassifier.h:59
Initialization of routing protocols.
Definition: InitStages.h:101
RSVP * rsvp
Definition: SimpleClassifier.h:60
Local initializations.
Definition: InitStages.h:35
bool inet::SimpleClassifier::lookupLabel ( IPv4Datagram ipdatagram,
LabelOpVector outLabel,
std::string &  outInterface,
int &  color 
)
overrideprotectedvirtual

The ipdatagram argument is an input parameter, the rest (outLabel, outInterface, color) are output parameters only.

In subclasses, this function should be implemented to determine the forwarding equivalence class for the IPv4 datagram passed, and map it to an outLabel and outInterface.

The color parameter (which can be set to an arbitrary value) will only be used for the NAM trace if one will be recorded.

Implements inet::IClassifier.

57 {
58  // never label OSPF(TED) and RSVP traffic
59 
60  switch (ipdatagram->getTransportProtocol()) {
61  case IP_PROT_OSPF:
62  case IP_PROT_RSVP:
63  return false;
64 
65  default:
66  break;
67  }
68 
69  // forwarding decision for non-labeled datagrams
70 
71  for (auto & elem : bindings) {
72  if (!elem.dest.isUnspecified() && !elem.dest.equals(ipdatagram->getDestAddress()))
73  continue;
74 
75  if (!elem.src.isUnspecified() && !elem.src.equals(ipdatagram->getSrcAddress()))
76  continue;
77 
78  EV_DETAIL << "packet belongs to fecid=" << elem.id << endl;
79 
80  if (elem.inLabel < 0)
81  return false;
82 
83  return lt->resolveLabel("", elem.inLabel, outLabel, outInterface, color);
84  }
85 
86  return false;
87 }
std::vector< FECEntry > bindings
Definition: SimpleClassifier.h:58
LIBTable * lt
Definition: SimpleClassifier.h:59
Definition: IPProtocolId_m.h:89
Definition: IPProtocolId_m.h:86
virtual bool resolveLabel(std::string inInterface, int inLabel, LabelOpVector &outLabel, std::string &outInterface, int &color)
Definition: LIBTable.cc:43
virtual int inet::SimpleClassifier::numInitStages ( ) const
inlineoverrideprotectedvirtual
67 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
void inet::SimpleClassifier::processCommand ( const cXMLElement &  node)
overrideprotectedvirtual

Called by ScenarioManager whenever a script command needs to be carried out by the module.

The command is represented by the XML element or element tree. The command name can be obtained as:

const char *command = node->getTagName()

Parameters are XML attributes, e.g. a "neighbour" parameter can be retrieved as:

const char *attr = node->getAttribute("neighbour")

More complex input can be passed in child elements.

See also
cXMLElement

Implements inet::IScriptable.

107 {
108  if (!strcmp(node.getTagName(), "bind-fec")) {
109  readItemFromXML(&node);
110  }
111  else
112  ASSERT(false);
113 }
virtual void readItemFromXML(const cXMLElement *fec)
Definition: SimpleClassifier.cc:127
void inet::SimpleClassifier::readItemFromXML ( const cXMLElement *  fec)
protectedvirtual
128 {
129  ASSERT(fec);
130  ASSERT(!strcmp(fec->getTagName(), "fecentry") || !strcmp(fec->getTagName(), "bind-fec"));
131 
132  int fecid = getParameterIntValue(fec, "id");
133 
134  auto it = findFEC(fecid);
135 
136  if (getUniqueChildIfExists(fec, "label")) {
137  // bind-fec to label
138  checkTags(fec, "id label destination source");
139 
140  EV_INFO << "binding to a given label" << endl;
141 
142  FECEntry newFec;
143 
144  newFec.id = fecid;
145  newFec.dest = getParameterIPAddressValue(fec, "destination");
146  newFec.src = getParameterIPAddressValue(fec, "source", IPv4Address());
147 
148  newFec.inLabel = getParameterIntValue(fec, "label");
149 
150  if (it == bindings.end()) {
151  // create new binding
152  bindings.push_back(newFec);
153  }
154  else {
155  // update existing binding
156  *it = newFec;
157  }
158  }
159  else if (getUniqueChildIfExists(fec, "lspid")) {
160  // bind-fec to LSP
161  checkTags(fec, "id destination source tunnel_id extended_tunnel_id endpoint lspid");
162 
163  EV_INFO << "binding to a given path" << endl;
164 
165  FECEntry newFec;
166 
167  newFec.id = fecid;
168  newFec.dest = getParameterIPAddressValue(fec, "destination");
169  newFec.src = getParameterIPAddressValue(fec, "source", IPv4Address());
170 
171  newFec.session.Tunnel_Id = getParameterIntValue(fec, "tunnel_id");
172  newFec.session.Extended_Tunnel_Id = getParameterIPAddressValue(fec, "extened_tunnel_id", routerId).getInt();
173  newFec.session.DestAddress = getParameterIPAddressValue(fec, "endpoint", newFec.dest); // ??? always use newFec.dest ???
174 
175  newFec.sender.Lsp_Id = getParameterIntValue(fec, "lspid");
176  newFec.sender.SrcAddress = routerId;
177 
178  newFec.inLabel = rsvp->getInLabel(newFec.session, newFec.sender);
179 
180  if (it == bindings.end()) {
181  // create new binding
182  bindings.push_back(newFec);
183  }
184  else {
185  // update existing binding
186  *it = newFec;
187  }
188  }
189  else {
190  // un-bind
191  checkTags(fec, "id");
192 
193  if (it != bindings.end()) {
194  bindings.erase(it);
195  }
196  }
197 }
std::vector< FECEntry > bindings
Definition: SimpleClassifier.h:58
IPv4Address routerId
Definition: SimpleClassifier.h:55
IPv4Address getParameterIPAddressValue(const cXMLElement *ptr, const char *name, IPv4Address def)
Definition: XMLUtils.cc:120
virtual int getInLabel(const SessionObj_t &session, const SenderTemplateObj_t &sender)
Definition: RSVP.cc:100
RSVP * rsvp
Definition: SimpleClassifier.h:60
void checkTags(const cXMLElement *node, const char *allowed)
Definition: XMLUtils.cc:54
uint32 getInt() const
Returns the address as an int.
Definition: IPv4Address.h:197
int getParameterIntValue(const cXMLElement *ptr, const char *name, int def)
Definition: XMLUtils.cc:105
std::vector< FECEntry >::iterator findFEC(int fecid)
Definition: SimpleClassifier.cc:199
const cXMLElement * getUniqueChildIfExists(const cXMLElement *node, const char *name)
Definition: XMLUtils.cc:17
void inet::SimpleClassifier::readTableFromXML ( const cXMLElement *  fectable)
protectedvirtual
118 {
119  ASSERT(fectable);
120  ASSERT(!strcmp(fectable->getTagName(), "fectable"));
121  checkTags(fectable, "fecentry");
122  cXMLElementList list = fectable->getChildrenByTagName("fecentry");
123  for (auto & elem : list)
124  readItemFromXML(elem);
125 }
virtual void readItemFromXML(const cXMLElement *fec)
Definition: SimpleClassifier.cc:127
void checkTags(const cXMLElement *node, const char *allowed)
Definition: XMLUtils.cc:54

Member Data Documentation

std::vector<FECEntry> inet::SimpleClassifier::bindings
protected
LIBTable* inet::SimpleClassifier::lt = nullptr
protected
int inet::SimpleClassifier::maxLabel = 0
protected
IPv4Address inet::SimpleClassifier::routerId
protected
RSVP* inet::SimpleClassifier::rsvp = nullptr
protected

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