Parent: [62f79d] (diff)

Download this file

RMT.cc    428 lines (368 with data), 10.6 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
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
//
// Copyright Š 2014 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 RMT.cc
* @author Tomas Hykel (xhykel01@stud.fit.vutbr.cz)
* @brief Relaying and Multiplexing Task
* @detail
*/
#include <RMT.h>
Define_Module(RMT);
RMT::RMT()
{
relayOn = false;
onWire = false;
waitingMsgs = 0;
}
RMT::~RMT() {}
void RMT::initialize()
{
WATCH_PTRMAP(efcpiToQueue);
fwTable = ModuleAccess<PDUForwardingTable>("pduForwardingTable").get();
queues = ModuleAccess<RMTQueueManager>("rmtQueueManager").get();
cModule* ipcModule = getParentModule()->getParentModule();
thisIpcAddr = Address(ipcModule->par("ipcAddress").stringValue(),
ipcModule->par("difName").stringValue());
// register signal for notifying others about a missing local EFCP instance
sigRMTNoConnID = registerSignal(SIG_RMT_NoConnId);
// listen for a signal indicating that a new message has arrived into a queue
lisRMTMsgRcvd = new LisRMTPDURcvd(this);
getParentModule()->subscribe(SIG_RMT_MessageReceived, lisRMTMsgRcvd);
schedPolicy = ModuleAccess<RMTSchedulingBase>("schedulingPolicy").get();
qMonPolicy = ModuleAccess<RMTQMonitorBase>("queueMonitorPolicy").get();
}
/**
* Schedules an end-of-queue-service event.
*
*/
void RMT::scheduleServiceEnd()
{
scheduleAt(simTime() + getParentModule()->par("queueServiceTime").doubleValue() / 1000,
new cMessage("queueServiceDone"));
}
/**
* Tries to begin service of a message that has newly arrived into a queue.
* If servicing takes place right now, the wait counter is increased instead.
*
*/
void RMT::invokeSchedulingPolicy(cObject* obj)
{
Enter_Method("invokeSchedulingPolicy()");
// invoke monitor policy
qMonPolicy->run(dynamic_cast<RMTQueue*>(obj));
if (!waitingMsgs)
{
scheduleServiceEnd();
}
else
{
waitingMsgs++;
}
}
/**
* Creates a gate to be used for connection to an EFCP instance.
*
* @param efcpiId CEP-id to be used in the gate's name
*/
void RMT::createEfcpiGate(unsigned int efcpiId)
{
if (efcpiOut.count(efcpiId))
{
return;
}
cModule* rmtModule = getParentModule();
std::ostringstream gateName_str;
gateName_str << GATE_EFCPIO_ << efcpiId;
this->addGate(gateName_str.str().c_str(), cGate::INOUT, false);
cGate* rmtIn = this->gateHalf(gateName_str.str().c_str(), cGate::INPUT);
cGate* rmtOut = this->gateHalf(gateName_str.str().c_str(), cGate::OUTPUT);
rmtModule->addGate(gateName_str.str().c_str(), cGate::INOUT, false);
cGate* rmtModuleIn = rmtModule->gateHalf(gateName_str.str().c_str(), cGate::INPUT);
cGate* rmtModuleOut = rmtModule->gateHalf(gateName_str.str().c_str(), cGate::OUTPUT);
rmtModuleIn->connectTo(rmtIn);
rmtOut->connectTo(rmtModuleOut);
efcpiOut[efcpiId] = rmtOut;
efcpiIn[efcpiId] = rmtIn;
// RMT<->EFCP interconnection shall be done by the FAI
}
/**
* Removes a gate used for an EFCP instance.
*
* @param efcpiId CEP-id of the gate meant for removal
*/
void RMT::deleteEfcpiGate(unsigned int efcpiId)
{
if (!efcpiOut.count(efcpiId))
{
return;
}
cModule* rmtModule = getParentModule();
std::ostringstream gateName_str;
gateName_str << GATE_EFCPIO_ << efcpiId;
cGate* rmtOut = this->gateHalf(gateName_str.str().c_str(), cGate::OUTPUT);
cGate* rmtModuleIn = rmtModule->gateHalf(gateName_str.str().c_str(), cGate::INPUT);
rmtOut->disconnect();
rmtModuleIn->disconnect();
this->deleteGate(gateName_str.str().c_str());
rmtModule->deleteGate(gateName_str.str().c_str());
deleteEfcpiToQueueMapping(efcpiId);
efcpiOut.erase(efcpiId);
efcpiIn.erase(efcpiId);
}
/**
* Creates a direct mapping from an EFCPI input gate to a RMT queue.
*
* @param cepId EFCP ID
* @param outQueue output RMT queue
*/
void RMT::addEfcpiToQueueMapping(unsigned cepId, RMTQueue* outQueue)
{
efcpiToQueue[efcpiIn[cepId]] = outQueue;
}
/**
* Deletes a direct EFCPI->queue mapping.
*
* @param cepId EFCP ID
*/
void RMT::deleteEfcpiToQueueMapping(unsigned cepId)
{
efcpiToQueue.erase(efcpiIn[cepId]);
}
/**
* Wrapper around forwarding table lookup returning the target output gate itself.
*
* @param destAddr destination address
* @param qosId qos-id
* @return RMT gate leading to an output RMT queue
*/
cGate* RMT::fwTableLookup(Address& destAddr, short qosId)
{
cGate* outGate = NULL;
RMTQueue* outQueue = fwTable->lookup(destAddr, qosId);
if (outQueue != NULL)
{
outGate = outQueue->getRmtAccessGate();
}
return outGate;
}
/**
* Passes a PDU from an EFCP instance to an appropriate output queue.
*
* @param pdu PDU to be passed
*/
void RMT::efcpiToPort(PDU_Base* pdu)
{
cGate* outGate = NULL;
outGate = efcpiToQueue[pdu->getArrivalGate()]->getRmtAccessGate();
if (outGate != NULL)
{
EV << this->getFullPath() << " passing a PDU to an output queue" << endl;
send(pdu, outGate);
}
else
{
EV << this->getFullPath() << "efcpi->port-id mapping not present!" << endl;
}
}
/**
* Passes a PDU from an (N-1)-port to an EFCP instance.
*
* @param pdu PDU to be passed
*/
void RMT::portToEfcpi(PDU_Base* pdu)
{
unsigned cepId = pdu->getConnId().getDstCepId();
cGate* efcpiGate = efcpiOut[cepId];
if (efcpiGate != NULL)
{
EV << this->getFullPath() << " passing a PDU upwards to EFCPI " << cepId << endl;
send(pdu, efcpiGate);
}
else
{
EV << this->getFullPath() << " EFCPI " << cepId << " isn't present on this system! Notifying other modules." << endl;
emit(sigRMTNoConnID, pdu);
//delete pdu;
}
}
/**
* Passes a PDU from an EFCP instance to another local EFCP instance.
*
* @param pdu PDU to be passed
*/
void RMT::efcpiToEfcpi(PDU_Base* pdu)
{
portToEfcpi(pdu);
}
/**
* Passes a CDAP mesage from an (N-1)-port instance to RIB daemon.
*
* @param cdap CDAP message to be passed
*/
void RMT::portToRIB(CDAPMessage* cdap)
{
send(cdap, "ribdIo$o");
}
/**
* Passes a CDAP mesage from the RIB daemon to an appropriate output queue.
*
* @param cdap CDAP message to be passed
*/
void RMT::RIBToPort(CDAPMessage* cdap)
{
cGate* outGate = NULL;
if (!onWire)
{
outGate = fwTableLookup(cdap->getDstAddr(), -1);
}
else
{
outGate = queues->getFirst(RMTQueue::OUTPUT)->getRmtAccessGate();
}
if (outGate != NULL)
{
EV << this->getFullPath() << " passing a CDAP message to an output queue" << endl;
send(cdap, outGate);
}
else
{
EV << "there isn't any suitable output queue available!" << endl;
}
}
/**
* Relays incoming message to an output queue based on data from PDUFwTable.
*
* @param msg either a PDU or a CDAP message to be relayed
*/
void RMT::portToPort(cMessage* msg)
{
Address destAddr;
short qosId;
if (dynamic_cast<PDU_Base*>(msg) != NULL)
{
destAddr = ((PDU_Base*)msg)->getDstAddr();
qosId = ((PDU_Base*)msg)->getConnId().getQoSId();
}
else if (dynamic_cast<CDAPMessage*>(msg) != NULL)
{
destAddr = ((CDAPMessage*)msg)->getDstAddr();
qosId = -1;
}
cGate* outGate = NULL;
if (onWire)
{
outGate = queues->getFirst(RMTQueue::OUTPUT)->getRmtAccessGate();
}
else
{
outGate = fwTableLookup(destAddr, qosId);
}
if (outGate != NULL)
{
EV << this->getFullPath() << " relaying a message" << endl;
send(msg, outGate);
}
else
{
EV << this->getFullPath() << " I can't reach any suitable (N-1)-flow! Seems like none is allocated." << endl;
}
}
/**
* The main finite state machine of Relaying and Multiplexing task.
* Makes a decision about what to do with incoming message based on arrival gate,
* message type, message destination address and RMT mode of operation.
*
* @param msg either a PDU or a CDAP message
*/
void RMT::processMessage(cMessage* msg)
{
std::string gate = msg->getArrivalGate()->getName();
if (dynamic_cast<PDU_Base*>(msg) != NULL)
{ // PDU arrival
PDU_Base* pdu = (PDU_Base*) msg;
if (gate.substr(0, 2) == "in")
{
if (pdu->getDstAddr() == thisIpcAddr)
{
portToEfcpi(pdu);
}
else if (relayOn)
{
portToPort(msg);
}
else
{
EV << getFullPath() << " This PDU isn't for me! Holding it here." << endl;
}
}
else if (gate.substr(0, 7) == GATE_EFCPIO_)
{
if (pdu->getDstAddr() == thisIpcAddr)
{
efcpiToEfcpi(pdu);
}
else
{
efcpiToPort(pdu);
}
}
}
else if (dynamic_cast<CDAPMessage*>(msg) != NULL)
{ // management message arrival
CDAPMessage* cdap = (CDAPMessage*) msg;
if (gate.substr(0, 2) == "in")
{
if (cdap->getDstAddr() == thisIpcAddr)
{
portToRIB(cdap);
}
else
{
portToPort(msg);
}
}
else
{
RIBToPort(cdap);
}
}
else
{
EV << this->getFullPath() << " message type not supported" << endl;
delete msg;
}
}
void RMT::handleMessage(cMessage *msg)
{
if (msg->isSelfMessage())
{
if (!opp_strcmp(msg->getFullName(), "queueServiceDone"))
{
schedPolicy->run(queues);
if (waitingMsgs)
{
scheduleServiceEnd();
waitingMsgs--;
}
}
delete msg;
}
else
{
processMessage(msg);
}
}