Parent: [6ccca6] (diff)

Download this file

PDUFwdTabGenerator.cc    396 lines (326 with data), 10.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
//
// Copyright Š 2014 - 2015 PRISTINE Consortium (http://ict-pristine.eu)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see http://www.gnu.org/licenses/.
//
/**
* @file PDUFwdTabGenerator.cc
* @author Tomas Hykel (xhykel01@stud.fit.vutbr.cz), Kewin Rausch(kewin.rausch@create-net.org)
* @brief PDU forwarding (routing) table generator.
* @detail Responds to various events happening inside the IPC process
* by adding, removing and editing entries in the forwarding table.
*/
// HOWTO Read: Procedures are sorted by name.
#include "PDUFwdTabGenerator.h"
#include "StaticRoutingPolicy.h"
#include "DistanceVectorPolicy.h"
#ifdef PDUFTG_PRIVATE_DEBUG
std::ofstream pduftg_debug_file;
#endif
Define_Module(PDUFwdTabGenerator);
void PDUFwdTabGenerator::finish()
{
#ifdef PDUFTG_PRIVATE_DEBUG
pduftg_debug_file.flush();
pduftg_debug_file.close();
#endif
}
PDUForwardingTable * PDUFwdTabGenerator::getForwardingTable()
{
return fwTable;
}
Address PDUFwdTabGenerator::getIpcAddress()
{
return ipcAddr;
}
NeighborState * PDUFwdTabGenerator::getNeighborhoodState()
{
return &neiState;
}
NetworkState * PDUFwdTabGenerator::getNetworkState()
{
return &netState;
}
PDUFTGNeighbor * PDUFwdTabGenerator::getNextNeighbor(Address destination, unsigned short qos)
{
RMTPort * p = getForwardingTable()->lookup(destination, qos);
if(p)
{
for(EIter it = neiState.begin(); it != neiState.end(); ++it )
{
PDUFTGNeighbor * e = (*it);
// Found the port used for the forwarding table; so it's the next neighbor.
if(!strcmp(p->info().c_str(), e->getPort()->info().c_str()))
{
return e;
}
}
}
else
{
pduftg_debug(ipcAddr.info() <<
"Neighbor to reach " << destination << " cannot be found.\n");
}
return NULL;
}
NM1FlowTable * PDUFwdTabGenerator::getNM1FlowTable()
{
return flTable;
}
void PDUFwdTabGenerator::handleUpdateMessage(PDUFTGUpdate * info)
{
if(fwdPolicy)
{
// Let the policy decide what to do here.
fwdPolicy->mergeForwardingInfo(info);
}
else
{
pduftg_debug(ipcAddr.info() <<
"> PDUFTG Error: no forwarding policy selected!\n");
}
// Show the status of the forwarding table?
if(showNetState)
{
nstm->getDisplayString().setTagArg("t", 0, prepareFriendlyNetState().c_str());
}
}
void PDUFwdTabGenerator::handleMessage(cMessage * msg)
{
}
void PDUFwdTabGenerator::initialize()
{
// IPCProcess module.
cModule * ipcModule = getParentModule()->getParentModule();
fwdPolicy = check_and_cast<PDUFTGPolicy *>
(getModuleByPath("^.PDUFTGPolicy"));
fwTable = check_and_cast<PDUForwardingTable *>
(getModuleByPath("^.pduForwardingTable"));
flTable = check_and_cast<NM1FlowTable *>
(getModuleByPath("^.nm1FlowTable"));
ipcAddr = Address(
ipcModule->par("ipcAddress").stringValue(),
ipcModule->par("difName").stringValue());
// Will show the fwd table in the simulation?
showNetState = par("netStateVisible").boolValue();
// Where will the report be seen?
nstm = check_and_cast<cModule *>
(getModuleByPath(par("netStateMod").stringValue()));
if(showNetState)
{
// Put the report on the desired position.
nstm->getDisplayString().setTagArg(
"t", 1, par("netStateAlign").stringValue());
}
// Initializes the input/output of the module.
initializeSignalsAndListeners();
#ifdef PDUFTG_PRIVATE_DEBUG
if(!pduftg_debug_file.is_open())
{
pduftg_debug_file.open("pduftg.log");
}
#endif
}
void PDUFwdTabGenerator::initializeSignalsAndListeners()
{
cModule* catcher1 = this->getParentModule()->getParentModule();
// Signal emitters; there will be part of our outputs.
sigPDUFTGFwdInfoUpdate = registerSignal(SIG_PDUFTG_FwdInfoUpdate);
// Signal receivers; there will be part of our inputs.
lisInfoRecv = new LisPDUFTGFwdInfoRecv(this);
catcher1->subscribe(SIG_RIBD_ForwardingUpdateReceived, lisInfoRecv);
}
void PDUFwdTabGenerator::insertFlowInfo(Address addr, unsigned short qos, RMTPort * port)
{
// Is a policy defined?
if(fwdPolicy)
{
fwdPolicy->insertNewFlow(addr, qos, port);
}
// What to do if no policy has been set?
else
{
pduftg_debug(ipcAddr.info() <<
"> PDUFTG Error: no forwarding policy selected!\n");
}
// Show the status of the forwarding table?
if(showNetState)
{
nstm->getDisplayString().setTagArg("t", 0, prepareFriendlyNetState().c_str());
}
}
void PDUFwdTabGenerator::insertNeighbor(Address addr, short unsigned qos, RMTPort * p)
{
// As for network informations, we're interested only on IPC located on
// our same layer. We must not know of N+1 or N-1 IPCs.
//
if(addr.getDifName() == ipcAddr.getDifName())
{
neiState.push_back(new PDUFTGNeighbor(addr, qos, p));
}
}
//void PDUFwdTabGenerator::insertNetInfo(Address dest, short unsigned int qos, RMTPort * port, unsigned int metric)
//{
// // Filter the flows created through RA; we're interested in the information about our
// // DIF, not on the ones of the others(N+1 or N-1).
// //
// if(dest.getDifName() == ipcAddr.getDifName())
// {
// PDUFTGInfo * i = netInfoExists(dest, qos);
//
// // Not already existing in our Flow list.
// if(!i)
// {
// i = new PDUFTGInfo(
// // From...
// ipcAddr,
// // ... to ...
// dest,
// // ... with QoS ...
// qos,
// // ... and metric.
// metric);
//
// // Just push it in the list.
// netState.push_back(i);
// }
// }
//}
std::string PDUFwdTabGenerator::neiInfo()
{
std::stringstream os;
os << "Neighbors counts: " << neiState.size() << "\n";
for(EIter it = neiState.begin(); it != neiState.end(); ++it )
{
PDUFTGNeighbor * e = (*it);
os << "Neighbor " << e->getDestAddr() << endl;
os << "\n";
}
return os.str();
}
std::string PDUFwdTabGenerator::netInfo()
{
std::stringstream os;
os << "Network state counts: " << netState.size() << "\n";
for(NIter it = netState.begin(); it != netState.end(); ++it )
{
PDUFTGInfo * fsi = (*it);
NM1FlowTableItem * p = flTable->findFlowByDstApni(fsi->getDestination().getApname().getName(), fsi->getQoSID());
os << "[From: " << fsi->getSource() << " to: " << fsi->getDestination() << " qos: " << fsi->getQoSID() << " hops: " << fsi->getMetric();
if(p)
{
RMTQueue* o = p->getRMTPort()->getOutputQueues().front();
os << " through port " << o->info() << " (is neighbor)";
}
os << "]\n";
}
return os.str();
}
PDUFTGNeighbor * PDUFwdTabGenerator::neighborExists(Address addr)
{
for(EIter it = neiState.begin(); it != neiState.end(); ++it )
{
PDUFTGNeighbor * e = (*it);
if(e->getDestAddr() == addr)
{
return e;
}
}
return NULL;
}
//PDUFTGInfo * PDUFwdTabGenerator::netInfoExists(Address dest, unsigned short qos)
//{
// for(NIter it = netState.begin(); it != netState.end(); ++it )
// {
// PDUFTGInfo * fsi = (*it);
//
// // Equal condition; same source reach same destination with same qos constrain.
// if(fsi->getDestination() == dest && fsi->getQoSID() == qos)
// {
// return fsi;
// }
// }
//
// return NULL;
//}
void PDUFwdTabGenerator::publishPolicy(PDUFTGPolicy * p)
{
unpublishPolicy();
fwdPolicy = p;
// Recomputes the policy according to the new policy.
fwdPolicy->computeForwardingTable();
}
std::string PDUFwdTabGenerator::prepareFriendlyNetState()
{
std::stringstream os;
for(NIter it = netState.begin(); it != netState.end(); ++it )
{
PDUFTGInfo * fsi = (*it);
os << fsi->getDestination() << ", " << fsi->getMetric() << endl;
}
return os.str();
}
void PDUFwdTabGenerator::unpublishPolicy()
{
// Clean the forwarding table; we'll regenerate it during the apply of a new policy.
fwTable->clean();
// Release the resources.
delete fwdPolicy;
fwdPolicy = NULL;
}
void PDUFwdTabGenerator::removeFlowInfo(RMTPort * port)
{
for(EIter it = neiState.begin(); it != neiState.end(); ++it )
{
PDUFTGNeighbor * e = (*it);
if(port == e->getPort())
{
// Signal the removing of the flow at the policy, first.
fwdPolicy->removeFlow(e->getDestAddr(), e->getQosId());
// Remove the entries previously registered.
removeNeiInfo(e->getDestAddr());
// removeNetInfo(netInfoExists(e->getDestAddr(), e->getQosId()));
return;
}
}
}
void PDUFwdTabGenerator::removeNeiInfo(Address addr)
{
for(EIter it = neiState.begin(); it != neiState.end(); ++it )
{
PDUFTGNeighbor * e = (*it);
if(e->getDestAddr() == addr)
{
neiState.erase(it);
}
}
}
//void PDUFwdTabGenerator::removeNetInfo(PDUFTGInfo * info)
//{
// netState.remove(info);
//}
void PDUFwdTabGenerator::reportBubbleInfo(const char * message)
{
if(showNetState && nstm)
{
nstm->bubble(message);
}
}
void PDUFwdTabGenerator::signalForwardingInfoUpdate(PDUFTGUpdate * info)
{
pduftg_debug(ipcAddr.info() <<
"> Signal an update to " << info->getDestination() << "\n");
// Emit the signal. RIBd shall be there to listen...
emit(sigPDUFTGFwdInfoUpdate, info);
}