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

Implements the MPLS protocol; see the NED file for more info. More...

#include <MPLS.h>

Inheritance diagram for inet::MPLS:

Protected Member Functions

virtual void initialize (int stage) override
 
virtual int numInitStages () const override
 
virtual void handleMessage (cMessage *msg) override
 
virtual void processPacketFromL3 (cMessage *msg)
 
virtual void processPacketFromL2 (cMessage *msg)
 
virtual void processMPLSPacketFromL2 (MPLSPacket *mplsPacket)
 
virtual bool tryLabelAndForwardIPv4Datagram (IPv4Datagram *ipdatagram)
 
virtual void labelAndForwardIPv4Datagram (IPv4Datagram *ipdatagram)
 
virtual void sendToL2 (cMessage *msg, int gateIndex)
 
virtual void doStackOps (MPLSPacket *mplsPacket, const LabelOpVector &outLabel)
 

Protected Attributes

simtime_t delay1
 
LIBTablelt
 
IInterfaceTableift
 
IClassifierpct
 

Detailed Description

Implements the MPLS protocol; see the NED file for more info.

Member Function Documentation

void inet::MPLS::doStackOps ( MPLSPacket mplsPacket,
const LabelOpVector outLabel 
)
protectedvirtual

Referenced by processMPLSPacketFromL2(), and tryLabelAndForwardIPv4Datagram().

145 {
146  unsigned int n = outLabel.size();
147 
148  EV_INFO << "doStackOps: " << outLabel << endl;
149 
150  for (unsigned int i = 0; i < n; i++) {
151  switch (outLabel[i].optcode) {
152  case PUSH_OPER:
153  mplsPacket->pushLabel(outLabel[i].label);
154  break;
155 
156  case SWAP_OPER:
157  ASSERT(mplsPacket->hasLabel());
158  mplsPacket->swapLabel(outLabel[i].label);
159  break;
160 
161  case POP_OPER:
162  ASSERT(mplsPacket->hasLabel());
163  mplsPacket->popLabel();
164  break;
165 
166  default:
167  throw cRuntimeError("Unknown MPLS OptCode %d", outLabel[i].optcode);
168  break;
169  }
170  }
171 }
#define POP_OPER
Definition: LIBTable.h:33
#define SWAP_OPER
Definition: LIBTable.h:32
#define PUSH_OPER
Definition: LIBTable.h:31
void inet::MPLS::handleMessage ( cMessage *  msg)
overrideprotectedvirtual
50 {
51  if (!strcmp(msg->getArrivalGate()->getName(), "ifIn")) {
52  EV_INFO << "Processing message from L2: " << msg << endl;
54  }
55  else if (!strcmp(msg->getArrivalGate()->getName(), "netwIn")) {
56  EV_INFO << "Processing message from L3: " << msg << endl;
58  }
59  else {
60  throw cRuntimeError("unexpected message: %s", msg->getName());
61  }
62 }
virtual void processPacketFromL3(cMessage *msg)
Definition: MPLS.cc:69
virtual void processPacketFromL2(cMessage *msg)
Definition: MPLS.cc:173
void inet::MPLS::initialize ( int  stage)
overrideprotectedvirtual
37 {
38  cSimpleModule::initialize(stage);
39 
40  if (stage == INITSTAGE_LOCAL) {
41  // interfaceTable must be initialized
42 
43  lt = getModuleFromPar<LIBTable>(par("libTableModule"), this);
44  ift = getModuleFromPar<IInterfaceTable>(par("interfaceTableModule"), this);
45  pct = getModuleFromPar<IClassifier>(par("classifierModule"), this);
46  }
47 }
IInterfaceTable * ift
Definition: MPLS.h:46
IClassifier * pct
Definition: MPLS.h:47
Local initializations.
Definition: InitStages.h:35
LIBTable * lt
Definition: MPLS.h:45
void inet::MPLS::labelAndForwardIPv4Datagram ( IPv4Datagram ipdatagram)
protectedvirtual

Referenced by processPacketFromL3().

130 {
131  if (tryLabelAndForwardIPv4Datagram(ipdatagram))
132  return;
133 
134  // handling our outgoing IPv4 traffic that didn't match any FEC/LSP
135  // do not use labelAndForwardIPv4Datagram for packets arriving to ingress!
136 
137  EV_INFO << "FEC not resolved, doing regular L3 routing" << endl;
138 
139  int gateIndex = ipdatagram->getArrivalGate()->getIndex();
140 
141  sendToL2(ipdatagram, gateIndex);
142 }
virtual bool tryLabelAndForwardIPv4Datagram(IPv4Datagram *ipdatagram)
Definition: MPLS.cc:94
virtual void sendToL2(cMessage *msg, int gateIndex)
Definition: MPLS.cc:64
virtual int inet::MPLS::numInitStages ( ) const
inlineoverrideprotectedvirtual
51 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
void inet::MPLS::processMPLSPacketFromL2 ( MPLSPacket mplsPacket)
protectedvirtual

Referenced by processPacketFromL2().

196 {
197  int gateIndex = mplsPacket->getArrivalGate()->getIndex();
198  InterfaceEntry *ie = ift->getInterfaceByNetworkLayerGateIndex(gateIndex);
199  std::string senderInterface = ie->getName();
200  ASSERT(mplsPacket->hasLabel());
201  int oldLabel = mplsPacket->getTopLabel();
202 
203  EV_INFO << "Received " << mplsPacket << " from L2, label=" << oldLabel << " inInterface=" << senderInterface << endl;
204 
205  if (oldLabel == -1) {
206  // This is a IPv4 native packet (RSVP/TED traffic)
207  // Decapsulate the message and pass up to L3
208  EV_INFO << ": decapsulating and sending up\n";
209 
210  IPv4Datagram *ipdatagram = check_and_cast<IPv4Datagram *>(mplsPacket->decapsulate());
211  delete mplsPacket;
212  send(ipdatagram, "netwOut", gateIndex);
213  return;
214  }
215 
216  LabelOpVector outLabel;
217  std::string outInterface;
218  int color;
219 
220  bool found = lt->resolveLabel(senderInterface, oldLabel, outLabel, outInterface, color);
221  if (!found) {
222  EV_INFO << "discarding packet, incoming label not resolved" << endl;
223 
224  delete mplsPacket;
225  return;
226  }
227 
228  int outgoingPort = ift->getInterfaceByName(outInterface.c_str())->getNetworkLayerGateIndex();
229 
230  doStackOps(mplsPacket, outLabel);
231 
232  if (mplsPacket->hasLabel()) {
233  // forward labeled packet
234 
235  EV_INFO << "forwarding packet to " << outInterface << endl;
236 
237  if (mplsPacket->hasPar("color")) {
238  mplsPacket->par("color") = color;
239  }
240  else {
241  mplsPacket->addPar("color") = color;
242  }
243 
244  //ASSERT(labelIf[outgoingPort]);
245 
246  sendToL2(mplsPacket, outgoingPort);
247  }
248  else {
249  // last label popped, decapsulate and send out IPv4 datagram
250 
251  EV_INFO << "decapsulating IPv4 datagram" << endl;
252 
253  IPv4Datagram *nativeIP = check_and_cast<IPv4Datagram *>(mplsPacket->decapsulate());
254  delete mplsPacket;
255 
256  if (outgoingPort != -1) {
257  sendToL2(nativeIP, outgoingPort);
258  }
259  else {
260  send(nativeIP, "netwOut", gateIndex);
261  }
262  }
263 }
IInterfaceTable * ift
Definition: MPLS.h:46
std::vector< LabelOp > LabelOpVector
Definition: LIBTable.h:44
virtual InterfaceEntry * getInterfaceByName(const char *name) const =0
Returns an interface given by its name.
virtual InterfaceEntry * getInterfaceByNetworkLayerGateIndex(int index)=0
Returns an interface given by its getNetworkLayerGateIndex().
LIBTable * lt
Definition: MPLS.h:45
virtual void doStackOps(MPLSPacket *mplsPacket, const LabelOpVector &outLabel)
Definition: MPLS.cc:144
virtual bool resolveLabel(std::string inInterface, int inLabel, LabelOpVector &outLabel, std::string &outInterface, int &color)
Definition: LIBTable.cc:43
virtual void sendToL2(cMessage *msg, int gateIndex)
Definition: MPLS.cc:64
void inet::MPLS::processPacketFromL2 ( cMessage *  msg)
protectedvirtual

Referenced by handleMessage().

174 {
175  IPv4Datagram *ipdatagram = dynamic_cast<IPv4Datagram *>(msg);
176  MPLSPacket *mplsPacket = dynamic_cast<MPLSPacket *>(msg);
177 
178  if (mplsPacket) {
179  processMPLSPacketFromL2(mplsPacket);
180  }
181  else if (ipdatagram) {
182  // IPv4 datagram arrives at Ingress router. We'll try to classify it
183  // and add an MPLS header
184 
185  if (!tryLabelAndForwardIPv4Datagram(ipdatagram)) {
186  int gateIndex = ipdatagram->getArrivalGate()->getIndex();
187  send(ipdatagram, "netwOut", gateIndex);
188  }
189  }
190  else {
191  throw cRuntimeError("Unknown message received");
192  }
193 }
virtual bool tryLabelAndForwardIPv4Datagram(IPv4Datagram *ipdatagram)
Definition: MPLS.cc:94
virtual void processMPLSPacketFromL2(MPLSPacket *mplsPacket)
Definition: MPLS.cc:195
void inet::MPLS::processPacketFromL3 ( cMessage *  msg)
protectedvirtual

Referenced by handleMessage().

70 {
71  using namespace tcp;
72 
73  IPv4Datagram *ipdatagram = check_and_cast<IPv4Datagram *>(msg);
74  //int gateIndex = msg->getArrivalGate()->getIndex();
75 
76  // XXX temporary solution, until TCPSocket and IPv4 are extended to support nam tracing
77  if (ipdatagram->getTransportProtocol() == IP_PROT_TCP) {
78  TCPSegment *seg = check_and_cast<TCPSegment *>(ipdatagram->getEncapsulatedPacket());
79  if (seg->getDestPort() == LDP_PORT || seg->getSrcPort() == LDP_PORT) {
80  ASSERT(!ipdatagram->hasPar("color"));
81  ipdatagram->addPar("color") = LDP_TRAFFIC;
82  }
83  }
84  else if (ipdatagram->getTransportProtocol() == IP_PROT_ICMP) {
85  // ASSERT(!ipdatagram->hasPar("color")); XXX this did not hold sometimes...
86  if (!ipdatagram->hasPar("color"))
87  ipdatagram->addPar("color") = ICMP_TRAFFIC;
88  }
89  // XXX end of temporary area
90 
91  labelAndForwardIPv4Datagram(ipdatagram);
92 }
#define ICMP_TRAFFIC
Definition: MPLS.cc:32
virtual void labelAndForwardIPv4Datagram(IPv4Datagram *ipdatagram)
Definition: MPLS.cc:129
Definition: IPProtocolId_m.h:77
Definition: IPProtocolId_m.h:80
#define LDP_PORT
Definition: LDP.h:35
#define LDP_TRAFFIC
Definition: LDP.h:37
void inet::MPLS::sendToL2 ( cMessage *  msg,
int  gateIndex 
)
protectedvirtual

Referenced by labelAndForwardIPv4Datagram(), processMPLSPacketFromL2(), and tryLabelAndForwardIPv4Datagram().

65 {
66  send(msg, "ifOut", gateIndex);
67 }
bool inet::MPLS::tryLabelAndForwardIPv4Datagram ( IPv4Datagram ipdatagram)
protectedvirtual

Referenced by labelAndForwardIPv4Datagram(), and processPacketFromL2().

95 {
96  LabelOpVector outLabel;
97  std::string outInterface;
98  int color;
99 
100  if (!pct->lookupLabel(ipdatagram, outLabel, outInterface, color)) {
101  EV_WARN << "no mapping exists for this packet" << endl;
102  return false;
103  }
104 
105  ASSERT(outLabel.size() > 0);
106 
107  int outgoingPort = ift->getInterfaceByName(outInterface.c_str())->getNetworkLayerGateIndex();
108 
109  MPLSPacket *mplsPacket = new MPLSPacket(ipdatagram->getName());
110  mplsPacket->encapsulate(ipdatagram);
111  doStackOps(mplsPacket, outLabel);
112 
113  EV_INFO << "forwarding packet to " << outInterface << endl;
114 
115  mplsPacket->addPar("color") = color;
116 
117  if (!mplsPacket->hasLabel()) {
118  // yes, this may happen - if we'are both ingress and egress
119  ipdatagram = check_and_cast<IPv4Datagram *>(mplsPacket->decapsulate()); // XXX FIXME superfluous encaps/decaps
120  delete mplsPacket;
121  sendToL2(ipdatagram, outgoingPort);
122  }
123  else
124  sendToL2(mplsPacket, outgoingPort);
125 
126  return true;
127 }
IInterfaceTable * ift
Definition: MPLS.h:46
std::vector< LabelOp > LabelOpVector
Definition: LIBTable.h:44
virtual InterfaceEntry * getInterfaceByName(const char *name) const =0
Returns an interface given by its name.
IClassifier * pct
Definition: MPLS.h:47
virtual bool lookupLabel(IPv4Datagram *ipdatagram, LabelOpVector &outLabel, std::string &outInterface, int &color)=0
The ipdatagram argument is an input parameter, the rest (outLabel, outInterface, color) are output pa...
virtual void doStackOps(MPLSPacket *mplsPacket, const LabelOpVector &outLabel)
Definition: MPLS.cc:144
virtual void sendToL2(cMessage *msg, int gateIndex)
Definition: MPLS.cc:64

Member Data Documentation

simtime_t inet::MPLS::delay1
protected
LIBTable* inet::MPLS::lt
protected
IClassifier* inet::MPLS::pct
protected

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