Download this file

RIBd.cc    471 lines (377 with data), 15.1 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
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
//
// 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 RIBd.cc
* @author Vladimir Vesely (ivesely@fit.vutbr.cz)
* @date Apr 30, 2014
* @brief Kind of a Notification Board for DIF
* @detail
*/
#include "RIBd.h"
const char* MSG_FLO = "Flow";
const char* MSG_FLOPOSI = "Flow+";
const char* MSG_FLONEGA = "Flow-";
const char* CLS_FLOW = "Flow";
const int VAL_DEFINSTANCE = -1;
const int VAL_FLOWPOSI = 1;
const int VAL_FLOWNEGA = 0;
const char* VAL_FLREQ = "Request ";
const char* VAL_FLREQPOSI = "Response+ ";
const char* VAL_FLREQNEGA = "Response- ";
Define_Module(RIBd);
void RIBd::initialize() {
//Init signals and listeners
initSignalsAndListeners();
//Init CDAP gates and connections
initCdapBindings();
//Init MyAddress
initMyAddress();
invokeIdCounter = 0;
}
void RIBd::handleMessage(cMessage *msg) {
}
void RIBd::initCdapBindings() {
//Get RIBDaemon gates
cModule* RibD = this->getParentModule();
cGate* gRibdIn = RibD->gateHalf(GATE_RMTIO, cGate::INPUT);
cGate* gRibdOut = RibD->gateHalf(GATE_RMTIO, cGate::OUTPUT);
//CDAPParent Module gates
cModule* Cdap = RibD->getSubmodule(MOD_CDAP);
cGate* gCdapParentIn;
cGate* gCdapParentOut;
Cdap->getOrCreateFirstUnconnectedGatePair(GATE_SOUTHIO, false, true, *&gCdapParentIn, *&gCdapParentOut);
//CDAPSplitter gates
cModule* CdapSplit = Cdap->getSubmodule(MOD_CDAPSPLIT);
cGate* gSplitIn;
cGate* gSplitOut;
CdapSplit->getOrCreateFirstUnconnectedGatePair(GATE_SOUTHIO, false, true, *&gSplitIn, *&gSplitOut);
cGate* gSplitCaceIn;
cGate* gSplitCaceOut;
CdapSplit->getOrCreateFirstUnconnectedGatePair(GATE_CACEIO, false, true, *&gSplitCaceIn, *&gSplitCaceOut);
cGate* gSplitAuthIn;
cGate* gSplitAuthOut;
CdapSplit->getOrCreateFirstUnconnectedGatePair(GATE_AUTHIO, false, true, *&gSplitAuthIn, *&gSplitAuthOut);
cGate* gSplitCdapIn;
cGate* gSplitCdapOut;
CdapSplit->getOrCreateFirstUnconnectedGatePair(GATE_CDAPIO, false, true, *&gSplitCdapIn, *&gSplitCdapOut);
//CACE Module gates
cModule* CdapCace = Cdap->getSubmodule(MOD_CDAPCACE);
cGate* gCaceIn;
cGate* gCaceOut;
CdapCace->getOrCreateFirstUnconnectedGatePair(GATE_SPLITIO, false, true, *&gCaceIn, *&gCaceOut);
//AUTH Module gates
cModule* CdapAuth = Cdap->getSubmodule(MOD_CDAPAUTH);
cGate* gAuthIn;
cGate* gAuthOut;
CdapAuth->getOrCreateFirstUnconnectedGatePair(GATE_SPLITIO, false, true, *&gAuthIn, *&gAuthOut);
//CDAP Module gates
cModule* CdapCdap = Cdap->getSubmodule(MOD_CDAPCDAP);
cGate* gCdapIn;
cGate* gCdapOut;
CdapCdap->getOrCreateFirstUnconnectedGatePair(GATE_SPLITIO, false, true, *&gCdapIn, *&gCdapOut);
//Connect gates together
gRibdIn->connectTo(gCdapParentIn);
gCdapParentIn->connectTo(gSplitIn);
gSplitOut->connectTo(gCdapParentOut);
gCdapParentOut->connectTo(gRibdOut);
gSplitCaceOut->connectTo(gCaceIn);
gCaceOut->connectTo(gSplitCaceIn);
gSplitAuthOut->connectTo(gAuthIn);
gAuthOut->connectTo(gSplitAuthIn);
gSplitCdapOut->connectTo(gCdapIn);
gCdapOut->connectTo(gSplitCdapIn);
}
void RIBd::sendCreateRequestFlow(Flow* flow) {
Enter_Method("sendCreateRequestFlow()");
//Prepare M_CREATE Flow
CDAP_M_Create* mcref = new CDAP_M_Create(MSG_FLO);
//Prepare object
std::ostringstream os;
os << flow->getFlowName();
object_t flowobj;
flowobj.objectClass = flow->getClassName();
flowobj.objectName = os.str();
flowobj.objectVal = flow;
//TODO: Vesely - Assign appropriate values
flowobj.objectInstance = VAL_DEFINSTANCE;
mcref->setObject(flowobj);
//Append destination address for RMT "routing"
mcref->setDstAddr(flow->getDstNeighbor());
//TODO: Vesely - Work more on InvokeId
mcref->setInvokeID(invokeIdCounter++);
//Send it
signalizeSendData(mcref);
}
void RIBd::processMCreate(CDAPMessage* msg) {
CDAP_M_Create* msg1 = check_and_cast<CDAP_M_Create*>(msg);
EV << "Received M_Create";
object_t object = msg1->getObject();
EV << " with object '" << object.objectClass << "'" << endl;
//CreateRequest Flow
if (dynamic_cast<Flow*>(object.objectVal)) {
Flow* fl = (check_and_cast<Flow*>(object.objectVal))->dup();
//EV << fl->info();
fl->swapFlow();
//EV << "\n===========\n" << fl->info();
signalizeCreateRequestFlow(fl);
}
}
void RIBd::sendDeleteRequestFlow(Flow* flow) {
Enter_Method("sendDeleteRequestFlow()");
//Prepare M_CREATE Flow
CDAP_M_Delete* mdereqf = new CDAP_M_Delete(MSG_FLO);
//Prepare object
std::ostringstream os;
os << flow->getFlowName();
object_t flowobj;
flowobj.objectClass = flow->getClassName();
flowobj.objectName = os.str();
flowobj.objectVal = flow;
//TODO: Vesely - Assign appropriate values
flowobj.objectInstance = VAL_DEFINSTANCE;
mdereqf->setObject(flowobj);
//Append destination address for RMT "routing"
mdereqf->setDstAddr(flow->getDstAddr());
//TODO: Vesely - Work more on InvokeId
mdereqf->setInvokeID(invokeIdCounter++);
//Send it
signalizeSendData(mdereqf);
}
void RIBd::processMCreateR(CDAPMessage* msg) {
CDAP_M_Create_R* msg1 = check_and_cast<CDAP_M_Create_R*>(msg);
EV << "Received M_Create_R";
object_t object = msg1->getObject();
EV << " with object '" << object.objectClass << "'" << endl;
//CreateResponseFlow
if (dynamic_cast<Flow*>(object.objectVal)) {
Flow* flow = (check_and_cast<Flow*>(object.objectVal))->dup();
flow->swapFlow();
//Positive response
if (!msg1->getResult().resultValue) {
signalizeCreateResponseFlowPositive(flow);
}
//Negative response
else
signalizeCreateResponseFlowNegative(flow);
}
}
void RIBd::receiveData(CDAPMessage* msg) {
Enter_Method("receiveData()");
//M_CREATE_Request
if (dynamic_cast<CDAP_M_Create*>(msg)) {
processMCreate(msg);
}
//M_CREATE_Response
else if (dynamic_cast<CDAP_M_Create_R*>(msg)) {
processMCreateR(msg);
}
//M_DELETE_Request
else if (dynamic_cast<CDAP_M_Delete*>(msg)) {
processMDelete(msg);
}
//M_DELETE_Request
else if (dynamic_cast<CDAP_M_Delete_R*>(msg)) {
processMDeleteR(msg);
}
delete msg;
}
void RIBd::initSignalsAndListeners() {
cModule* catcher1 = this->getParentModule();
cModule* catcher2 = this->getParentModule()->getParentModule();
cModule* catcher3 = this->getParentModule()->getParentModule()->getParentModule();
//Signals that this module is emitting
sigRIBDSendData = registerSignal(SIG_RIBD_DataSend);
sigRIBDCreReqFlo = registerSignal(SIG_RIBD_CreateRequestFlow);
sigRIBDDelReqFlo = registerSignal(SIG_RIBD_DeleteRequestFlow);
sigRIBDDelResFlo = registerSignal(SIG_RIBD_DeleteResponseFlow);
sigRIBDAllocResPosi = registerSignal(SIG_AERIBD_AllocateResponsePositive);
sigRIBDAllocResNega = registerSignal(SIG_AERIBD_AllocateResponseNegative);
sigRIBDCreFlow = registerSignal(SIG_RIBD_CreateFlow);
sigRIBDCreResFloPosi = registerSignal(SIG_RIBD_CreateFlowResponsePositive);
sigRIBDCreResFloNega = registerSignal(SIG_RIBD_CreateFlowResponseNegative);
//Signals that this module is processing
lisRIBDCreReqByForward = new LisRIBDCreReq(this);
catcher2->subscribe(SIG_FA_CreateFlowRequestForward, lisRIBDCreReqByForward);
lisRIBDCreReq = new LisRIBDCreReq(this);
catcher2->subscribe(SIG_FAI_CreateFlowRequest, lisRIBDCreReq);
lisRIBDDelReq = new LisRIBDDelReq(this);
catcher2->subscribe(SIG_FAI_DeleteFlowRequest, lisRIBDDelReq);
lisRIBDDelRes = new LisRIBDDelRes(this);
catcher2->subscribe(SIG_FAI_DeleteFlowResponse, lisRIBDDelRes);
lisRIBDCreResNegaFromFa = new LisRIBDCreResNega(this);
catcher2->subscribe(SIG_FA_CreateFlowResponseNegative, lisRIBDCreResNegaFromFa);
lisRIBDCreResNega = new LisRIBDCreResNega(this);
catcher2->subscribe(SIG_FAI_CreateFlowResponseNegative, lisRIBDCreResNega);
lisRIBDCreResPosi = new LisRIBDCreResPosi(this);
catcher2->subscribe(SIG_FAI_CreateFlowResponsePositive, lisRIBDCreResPosi);
lisRIBDCreResPosiForward = new LisRIBDCreResPosi(this);
catcher2->subscribe(SIG_FA_CreateFlowResponseForward, lisRIBDCreResPosiForward);
lisRIBDRcvData = new LisRIBDRcvData(this);
catcher1->subscribe(SIG_CDAP_DateReceive, lisRIBDRcvData);
lisRIBDAllReqFromFai = new LisRIBDAllReqFromFai(this);
catcher3->subscribe(SIG_FAI_AllocateRequest, lisRIBDAllReqFromFai);
lisRIBDCreFloPosi = new LisRIBDCreFloPosi(this);
catcher2->subscribe(SIG_RA_CreateFlowPositive, lisRIBDCreFloPosi);
lisRIBDCreFloNega = new LisRIBDCreFloNega(this);
catcher2->subscribe(SIG_RA_CreateFlowNegative, lisRIBDCreFloNega);
}
void RIBd::receiveAllocationRequestFromFai(Flow* flow) {
Enter_Method("receiveAllocationRequestFromFai()");
//Execute flow allocate
signalizeCreateFlow(flow);
}
void RIBd::sendCreateResponseNegative(Flow* flow) {
Enter_Method("sendCreateResponseFlowNegative()");
//Prepare M_CREATE_R Flow-
CDAP_M_Create_R* mcref = new CDAP_M_Create_R(MSG_FLONEGA);
//Prepare object
std::ostringstream os;
os << flow->getFlowName();
object_t flowobj;
flowobj.objectClass = flow->getClassName();
flowobj.objectName = os.str();
flowobj.objectVal = flow;
//TODO: Vesely - Assign appropriate values
flowobj.objectInstance = VAL_DEFINSTANCE;
mcref->setObject(flowobj);
//Prepare result object
result_t resultobj;
resultobj.resultValue = R_FAIL;
mcref->setResult(resultobj);
//TODO: Vesely - Work more on InvokeId
//Append destination address for RMT "routing"
mcref->setDstAddr(flow->getDstAddr());
//Send it
signalizeSendData(mcref);
}
void RIBd::sendCreateResponsePostive(Flow* flow) {
Enter_Method("sendCreateResponseFlowPositive()");
//Prepare M_CREATE_R Flow+
CDAP_M_Create_R* mcref = new CDAP_M_Create_R(MSG_FLOPOSI);
//Prepare object
std::ostringstream os;
os << flow->getFlowName();
object_t flowobj;
flowobj.objectClass = flow->getClassName();
flowobj.objectName = os.str();
flowobj.objectVal = flow;
//TODO: Vesely - Assign appropriate values
flowobj.objectInstance = VAL_DEFINSTANCE;
mcref->setObject(flowobj);
//Prepare result object
result_t resultobj;
resultobj.resultValue = R_SUCCESS;
mcref->setResult(resultobj);
//TODO: Vesely - Work more on InvokeId
//Append destination address for RMT "routing"
mcref->setDstAddr(flow->getDstAddr());
//Send it
signalizeSendData(mcref);
}
void RIBd::signalizeSendData(CDAPMessage* msg) {
//Setup handle which is for RIBd always 0
msg->setHandle(0);
//Pass message to CDAP
EV << "Emits SendData signal for message " << msg->getName() << endl;
emit(sigRIBDSendData, msg);
}
void RIBd::signalizeAllocateResponsePositive(Flow* flow) {
EV << "Emits AllocateResponsePositive signal for flow" << endl;
emit(sigRIBDAllocResPosi, flow);
}
void RIBd::signalizeCreateRequestFlow(Flow* flow) {
EV << "Emits CreateRequestFlow signal for flow" << endl;
emit(sigRIBDCreReqFlo, flow);
}
void RIBd::signalizeCreateResponseFlowPositive(Flow* flow) {
EV << "Emits CreateResponsetFlowPositive signal for flow" << endl;
emit(sigRIBDCreResFloPosi, flow);
}
void RIBd::signalizeCreateResponseFlowNegative(Flow* flow) {
EV << "Emits CreateResponsetFlowNegative signal for flow" << endl;
emit(sigRIBDCreResFloNega, flow);
}
void RIBd::signalizeCreateFlow(Flow* flow) {
EV << "Emits CreateFlow signal for flow" << endl;
emit(sigRIBDCreFlow, flow);
}
void RIBd::processMDelete(CDAPMessage* msg) {
CDAP_M_Delete* msg1 = check_and_cast<CDAP_M_Delete*>(msg);
EV << "Received M_Delete";
object_t object = msg1->getObject();
EV << " with object '" << object.objectClass << "'" << endl;
//DeleteRequest Flow
if (dynamic_cast<Flow*>(object.objectVal)) {
Flow* fl = (check_and_cast<Flow*>(object.objectVal))->dup();
fl->swapFlow();
signalizeDeleteRequestFlow(fl);
}
}
void RIBd::signalizeDeleteRequestFlow(Flow* flow) {
EV << "Emits DeleteRequestFlow signal for flow" << endl;
emit(sigRIBDDelReqFlo, flow);
}
void RIBd::sendDeleteResponseFlow(Flow* flow) {
Enter_Method("sendDeleteResponseFlow()");
//Prepare M_CREATE_R Flow+
CDAP_M_Delete_R* mderesf = new CDAP_M_Delete_R(MSG_FLOPOSI);
//Prepare object
std::ostringstream os;
os << flow->getFlowName();
object_t flowobj;
flowobj.objectClass = flow->getClassName();
flowobj.objectName = os.str();
flowobj.objectVal = flow;
//TODO: Vesely - Assign appropriate values
flowobj.objectInstance = VAL_DEFINSTANCE;
mderesf->setObject(flowobj);
//Prepare result object
result_t resultobj;
resultobj.resultValue = R_SUCCESS;
mderesf->setResult(resultobj);
//TODO: Vesely - Work more on InvokeId
//Append destination address for RMT "routing"
mderesf->setDstAddr(flow->getDstAddr());
//Send it
signalizeSendData(mderesf);
}
void RIBd::signalizeDeleteResponseFlow(Flow* flow) {
EV << "Emits DeleteResponseFlow signal for flow" << endl;
emit(sigRIBDDelResFlo, flow);
}
void RIBd::receiveCreateFlowPositiveFromRa(Flow* flow) {
signalizeAllocateResponsePositive(flow);
}
void RIBd::receiveCreateFlowNegativeFromRa(Flow* flow) {
signalizeAllocateResponseNegative(flow);
}
void RIBd::signalizeAllocateResponseNegative(Flow* flow) {
EV << "Emits AllocateResponseNegative signal for flow" << endl;
emit(sigRIBDAllocResNega, flow);
}
void RIBd::processMDeleteR(CDAPMessage* msg) {
CDAP_M_Delete_R* msg1 = check_and_cast<CDAP_M_Delete_R*>(msg);
EV << "Received M_Delete_R";
object_t object = msg1->getObject();
EV << " with object '" << object.objectClass << "'" << endl;
//DeleteResponseFlow
if (dynamic_cast<Flow*>(object.objectVal)) {
Flow* flow = (check_and_cast<Flow*>(object.objectVal))->dup();
flow->swapFlow();
signalizeDeleteResponseFlow(flow);
}
}