diff --git a/src/DIF/Enrollment/Enrollment.cc b/src/DIF/Enrollment/Enrollment.cc index 7d15c67d..93f1ded2 100644 --- a/src/DIF/Enrollment/Enrollment.cc +++ b/src/DIF/Enrollment/Enrollment.cc @@ -117,11 +117,6 @@ void Enrollment::initSignalsAndListeners() { sigEnrollmentStopEnrollRes = registerSignal(SIG_ENROLLMENT_StopEnrollmentResponse); sigEnrollmentStartOperReq = registerSignal(SIG_ENROLLMENT_StartOperationRequest); sigEnrollmentStartOperRes = registerSignal(SIG_ENROLLMENT_StartOperationResponse); - sigEnrollmentFinish = registerSignal(SIG_ENROLLMENT_Finished); - - lisEnrollmentAllResPosi = new LisEnrollmentAllResPosi(this); - catcher1->subscribe(SIG_FA_MgmtFlowAllocated, lisEnrollmentAllResPosi); - catcher1->subscribe(SIG_RA_MgmtFlowAllocated, lisEnrollmentAllResPosi); //lisEnrollmentGetFlowFromFaiCreResPosi = new LisEnrollmentGetFlowFromFaiCreResPosi(this); //catcher1->subscribe(SIG_FAI_CreateFlowResponsePositive, lisEnrollmentGetFlowFromFaiCreResPosi); diff --git a/src/DIF/Enrollment/EnrollmentListeners.cc b/src/DIF/Enrollment/EnrollmentListeners.cc index 28565594..103287fe 100644 --- a/src/DIF/Enrollment/EnrollmentListeners.cc +++ b/src/DIF/Enrollment/EnrollmentListeners.cc @@ -31,36 +31,10 @@ #include "DIF/Enrollment/EnrollmentListeners.h" -EnrollmentListeners::EnrollmentListeners(Enrollment* nenrollment): enrollment(nenrollment) { -} - -EnrollmentListeners::~EnrollmentListeners() { - enrollment = NULL; -} - -void LisEnrollmentAllResPosi::receiveSignal(cComponent* src, simsignal_t id, - cObject* obj, cObject* detail) { - EV << "AllocationResponsePositive initiated by " << src->getFullPath() << " and processed by " << enrollment->getFullPath() << endl; - /*Flow* flow = dynamic_cast(obj); - if (flow) { - if (!flow->isManagementFlow()){ - return; - } +#include "Common/Flow.h" +#include "DAF/CDAP/CDAPMessage_m.h" +#include "DIF/Enrollment/Enrollment.h" - enrollment->startCACE(flow); - } - else - EV << "EnrollmentListener reeived unknown object!" << endl; - */ - APNIPair* apnip = dynamic_cast(obj); - if (apnip) { - enrollment->startCACE(apnip); - } - else { - EV << "EnrollmentListener received unknown object!" << endl; - } - -} void LisEnrollmentGetFlowFromFaiCreResPosi::receiveSignal(cComponent* src, simsignal_t id, cObject* obj, cObject* detail) { diff --git a/src/DIF/Enrollment/EnrollmentListeners.h b/src/DIF/Enrollment/EnrollmentListeners.h index 6f8dca74..cf458967 100644 --- a/src/DIF/Enrollment/EnrollmentListeners.h +++ b/src/DIF/Enrollment/EnrollmentListeners.h @@ -33,98 +33,88 @@ #ifndef ENROLLMENTLISTENERS_H_ #define ENROLLMENTLISTENERS_H_ -#include "DIF/Enrollment/Enrollment.h" +#include class Enrollment; +class CDAPMessage; class EnrollmentListeners : public cListener { public: - EnrollmentListeners(Enrollment* nenrollment); - virtual ~EnrollmentListeners(); - virtual void receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject *detail) { - EV << "Signal to Enrollment initiated by " << src->getFullPath() << endl; - } + EnrollmentListeners(Enrollment* enrollment) : enrollment(enrollment) {} + protected: Enrollment* enrollment; -}; - - -class LisEnrollmentAllResPosi : public EnrollmentListeners { - public: - LisEnrollmentAllResPosi(Enrollment* nenrollment): EnrollmentListeners(nenrollment){}; - using EnrollmentListeners::receiveSignal; - virtual void receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject* detail); + void receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject *detail) override = 0; }; class LisEnrollmentGetFlowFromFaiCreResPosi : public EnrollmentListeners { public: LisEnrollmentGetFlowFromFaiCreResPosi(Enrollment* nenrollment): EnrollmentListeners(nenrollment){}; - using EnrollmentListeners::receiveSignal; - virtual void receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject* detail); + void receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject* detail) override; }; class LisEnrollmentStartEnrollReq : public EnrollmentListeners { public: LisEnrollmentStartEnrollReq(Enrollment* nenrollment): EnrollmentListeners(nenrollment){}; - using EnrollmentListeners::receiveSignal; - virtual void receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject* detail); + protected: + void receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject* detail) override; }; class LisEnrollmentStartEnrollRes : public EnrollmentListeners { public: LisEnrollmentStartEnrollRes(Enrollment* nenrollment): EnrollmentListeners(nenrollment){}; - using EnrollmentListeners::receiveSignal; - virtual void receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject* detail); + protected: + void receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject* detail) override; }; class LisEnrollmentStopEnrollReq : public EnrollmentListeners { public: LisEnrollmentStopEnrollReq(Enrollment* nenrollment): EnrollmentListeners(nenrollment){}; - using EnrollmentListeners::receiveSignal; - virtual void receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject* detail); + protected: + void receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject* detail) override; }; class LisEnrollmentStopEnrollRes : public EnrollmentListeners { public: LisEnrollmentStopEnrollRes(Enrollment* nenrollment): EnrollmentListeners(nenrollment){}; - using EnrollmentListeners::receiveSignal; - virtual void receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject* detail); + protected: + void receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject* detail) override; }; class LisEnrollmentStopOperationReq : public EnrollmentListeners { public: LisEnrollmentStopOperationReq(Enrollment* nenrollment): EnrollmentListeners(nenrollment){}; - using EnrollmentListeners::receiveSignal; - virtual void receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject* detail); + protected: + void receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject* detail) override; }; class LisEnrollmentStartOperationRes : public EnrollmentListeners { public: LisEnrollmentStartOperationRes(Enrollment* nenrollment): EnrollmentListeners(nenrollment){}; - using EnrollmentListeners::receiveSignal; - virtual void receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject* detail); + protected: + void receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject* detail) override; }; class LisEnrollmentConResPosi : public EnrollmentListeners { public: LisEnrollmentConResPosi(Enrollment* nenrollment): EnrollmentListeners(nenrollment){}; - using EnrollmentListeners::receiveSignal; - virtual void receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject* detail); + protected: + void receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject* detail) override; }; class LisEnrollmentConResNega : public EnrollmentListeners { public: LisEnrollmentConResNega(Enrollment* nenrollment): EnrollmentListeners(nenrollment){}; - using EnrollmentListeners::receiveSignal; - virtual void receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject* detail); + protected: + void receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject* detail) override; }; class LisEnrollmentConReq : public EnrollmentListeners { public: LisEnrollmentConReq(Enrollment* nenrollment): EnrollmentListeners(nenrollment){}; - using EnrollmentListeners::receiveSignal; - virtual void receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject* detail); + protected: + void receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject* detail) override; }; diff --git a/src/DIF/Enrollment/EnrollmentStateTable.cc b/src/DIF/Enrollment/EnrollmentStateTable.cc index 0d69802f..b4628ad9 100644 --- a/src/DIF/Enrollment/EnrollmentStateTable.cc +++ b/src/DIF/Enrollment/EnrollmentStateTable.cc @@ -69,6 +69,16 @@ void EnrollmentStateTable::handleMessage(cMessage *msg) } +bool EnrollmentStateTable::isConnectedTo(const APN &apn) { + for(auto it = StateTable.begin(); it != StateTable.end(); ++it) { + EnrollmentStateTableEntry est = *it; + if (est.getRemote().getApn() == apn && + est.getCACEConStatus() == EnrollmentStateTableEntry::CON_ESTABLISHED) { + return true; + } + } + return false; +} bool EnrollmentStateTable::isEnrolled(const APN& myApn) { for(auto it = StateTable.begin(); it != StateTable.end(); ++it) { diff --git a/src/DIF/Enrollment/EnrollmentStateTable.h b/src/DIF/Enrollment/EnrollmentStateTable.h index e8c73cc7..cbb9d9cf 100644 --- a/src/DIF/Enrollment/EnrollmentStateTable.h +++ b/src/DIF/Enrollment/EnrollmentStateTable.h @@ -44,6 +44,7 @@ class EnrollmentStateTable : public cSimpleModule public: void insert(EnrollmentStateTableEntry entry); EnrollmentStateTableEntry* findEntryByDstAPN(const APN& apn); + bool isConnectedTo(const APN &apn); bool isEnrolled(const APN& myApn); protected: diff --git a/src/DIF/FA/FA.cc b/src/DIF/FA/FA.cc index b3bc6237..2b3d9f85 100644 --- a/src/DIF/FA/FA.cc +++ b/src/DIF/FA/FA.cc @@ -22,81 +22,62 @@ #include "DIF/FA/FA.h" +#include "Common/Flow.h" +#include "Common/RINASignals.h" +#include "DAF/DA/DA.h" +#include "DIF/EFCP/EFCP.h" +#include "DIF/Enrollment/Enrollment.h" +#include "DIF/Enrollment/EnrollmentStateTable.h" +#include "DIF/FA/FAI.h" +#include "DIF/FA/NFlowTable.h" +#include "DIF/FA/NewFlowRequest/NewFlowRequestBase.h" +#include "DIF/RA/RABase.h" + //Constants -const int RANDOM_NUMBER_GENERATOR = 0; -const int MAX_PORTID = 65535; -const int MAX_CEPID = 65535; const char* MOD_NEFFLOWREQPOLICY = "newFlowRequestPolicy"; -Define_Module(FA); - -FA::FA() { - N_flowTable = NULL; -} +// Signals that this module emits +const simsignal_t FA::createRequestForwardSignal = registerSignal(SIG_FA_CreateFlowRequestForward); +const simsignal_t FA::createResponseNegativeSignal = registerSignal(SIG_FA_CreateFlowResponseNegative); -FA::~FA() { - N_flowTable = NULL; -} +Define_Module(FA); void FA::initPointers() { - N_flowTable = check_and_cast(getParentModule()->getSubmodule(MOD_NFLOWTABLE)); - Efcp = getRINAModule(this, 2, {MOD_EFCP, MOD_EFCP}); - - DifAllocator = getRINAModule(this, 3, {MOD_DIFALLOC, MOD_DA}); - NFloReqPolicy = getRINAModule(this, 1, {MOD_NEFFLOWREQPOLICY}); - RaModule = getRINAModule(this, 2, {MOD_RESALLOC, MOD_RA}); - Enrollment = getRINAModule(this, 2, {MOD_ENROLLMENT, MOD_ENROLLMENTTABLE}); + nFlowTable = getRINAModule(this, 1, {MOD_NFLOWTABLE}); + efcp = getRINAModule(this, 2, {MOD_EFCP, MOD_EFCP}); + + difAllocator = getRINAModule(this, 3, {MOD_DIFALLOC, MOD_DA}); + nFloReqPolicy = getRINAModule(this, 1, {MOD_NEFFLOWREQPOLICY}); + raModule = getRINAModule(this, 2, {MOD_RESALLOC, MOD_RA}); + enrollment = getRINAModule(this, 2, {MOD_ENROLLMENTMODULE, MOD_ENROLLMENT}); + enrollmentStateTable = getRINAModule(this, 2, {MOD_ENROLLMENTMODULE, MOD_ENROLLMENTTABLE}); } void FA::initSignalsAndListeners() { + // tbh should be N-1 IPC Process cModule* catcher3 = this->getModuleByPath("^.^.^"); - cModule* catcher2 = this->getModuleByPath("^.^"); - //Signals that this module is emitting - //sigFACreResPosiFwd = registerSignal(SIG_FA_CreateFlowResponseForward); - sigFACreReqFwd = registerSignal(SIG_FA_CreateFlowRequestForward); - sigFACreResNega = registerSignal(SIG_FA_CreateFlowResponseNegative); - sigFAAllocFinMgmt = registerSignal(SIG_FA_MgmtFlowAllocated); - - //Signals that this module is processing - /* - // AllocateRequest - this->lisAllocReq = new LisFAAllocReq(this); - catcher3->subscribe(SIG_IRM_AllocateRequest, this->lisAllocReq); - // DeallocateRequest - this->lisDeallocReq = new LisFADeallocReq(this); - catcher3->subscribe(SIG_IRM_DeallocateRequest, this->lisDeallocReq); - */ //AllocateResponsePositive - lisCreFloPosi = new LisFACreFloPosi(this); - catcher3->subscribe(SIG_FAI_AllocateResponsePositive, lisCreFloPosi); - - //CreateRequestFlow - lisCreReq = new LisFACreReq(this); - catcher2->subscribe(SIG_RIBD_CreateRequestFlow, lisCreReq); - - //Allocate after management flow is prepared (enrollment done) - lisEnrollFin = new LisFAAllocFinMgmt(this); - //catcher2->subscribe(SIG_FAI_AllocateFinishManagement, lisAllocFinMgmt); - catcher2->subscribe(SIG_ENROLLMENT_Finished, lisEnrollFin); - + catcher3->subscribe(FAI::allocateResponsePositiveSignal, this); } -void FA::initialize() { - initPointers(); - initSignalsAndListeners(); +void FA::initialize(int stage) { + if (stage == 0) { + initPointers(); + initSignalsAndListeners(); - //Setup MyAddress - initMyAddress(); + //Setup MyAddress + initMyAddress(); + } } //XXX: Vesely - Dirty! Needs refactoring... const Address FA::getAddressFromDa(const APN& apn, bool useNeighbor, bool isMgmtFlow) { Address addr; if (!isMgmtFlow) { //Ask DA which IPC to use to reach src App - const Address* ad = DifAllocator->resolveApnToBestAddress(apn, MyAddress.getDifName()); - if (ad == NULL) { - EV << "DifAllocator returned NULL for resolving " << apn << endl; + const Address* ad = difAllocator->resolveApnToBestAddress(apn, myAddress.getDifName()); + if (ad == nullptr) { + EV << " DIF Allocator returned NULL for resolving " << apn << endl; return Address(); } addr = *ad; @@ -104,11 +85,12 @@ const Address FA::getAddressFromDa(const APN& apn, bool useNeighbor, bool isMgmt else { addr = Address(apn); } + if (useNeighbor) { - const APNList* apnlist = DifAllocator->findApnNeigbors(addr.getApn()); + const APNList* apnlist = difAllocator->findApnNeighbors(addr.getApn()); if (apnlist) { - for (ApnCItem it = apnlist->begin(); it != apnlist->end(); ++it) { - Address tmp = Address(it->getName()); + for (const auto &it : *apnlist) { + Address tmp = Address(it.getName()); //EV << "!!!!!" << tmp << endl; if (addr.getDifName() == tmp.getDifName()) { addr = tmp; @@ -117,6 +99,7 @@ const Address FA::getAddressFromDa(const APN& apn, bool useNeighbor, bool isMgmt } } } + return addr; } bool FA::isMalformedFlow(Flow* flow) { @@ -128,16 +111,31 @@ bool FA::isMalformedFlow(Flow* flow) { void FA::handleMessage(cMessage *msg) { if ( msg->isSelfMessage() && !opp_strcmp(msg->getName(), TIM_FAPENDFLOWS) ) { - while (!PendingFlows.empty()) { - NFlowTableEntry* fte = N_flowTable->findEntryByFlow(PendingFlows.front()); - if (fte && fte->getFai()) { + while (!pendingFlows.empty()) { + Flow *flow = pendingFlows.front(); + pendingFlows.pop(); + NFlowTableEntry* fte = nFlowTable->findEntryByFlow(flow); + if (fte == nullptr) { + EV_ERROR << "No flow table entry corresponding to pending flow!" << endl; + continue; + } + + if (fte->getAllocateStatus() == NFlowTableEntry::ALLOC_PEND) { FAIBase* fai = fte->getFai(); - if (fai) { + if (fai != nullptr) { fai->receiveAllocateRequest(); + } else { + EV_ERROR << "No FAI for flow with pending allocation!" << endl; + } + } else if (fte->getAllocateStatus() == NFlowTableEntry::FORWARDING) { + if (raModule->bindNFlowToNM1Flow(flow)) { + receiveNM1FlowCreated(flow); + } else { + EV << "FA waits until N-1 IPC allocates auxilliary N-1 flow" << endl; } } - PendingFlows.pop_front(); } + cancelAndDelete(msg); } else @@ -149,13 +147,13 @@ void FA::handleMessage(cMessage *msg) { bool FA::changeSrcAddress(Flow* flow, bool useNeighbor) { //Add source... if (!useNeighbor) { - flow->setSrcAddr(MyAddress); + flow->setSrcAddr(myAddress); } else { //Ask DA which IPC to use to reach src App - const Address* ad = DifAllocator->resolveApnToBestAddress(flow->getSrcApni().getApn(), MyAddress.getDifName()); - if (ad == NULL) { - EV << "DifAllocator returned NULL for resolving " << flow->getSrcApni().getApn() << endl; + const Address* ad = difAllocator->resolveApnToBestAddress(flow->getSrcApni().getApn(), myAddress.getDifName()); + if (ad == nullptr) { + EV << "difAllocator returned NULL for resolving " << flow->getSrcApni().getApn() << endl; return false; } Address addr = *ad; @@ -166,9 +164,9 @@ bool FA::changeSrcAddress(Flow* flow, bool useNeighbor) { bool FA::changeDstAddresses(Flow* flow, bool useNeighbor) { //Ask DA which IPC to use to reach dst App - const Address* ad = DifAllocator->resolveApnToBestAddress(flow->getDstApni().getApn()); - if (ad == NULL) { - EV << "DifAllocator returned NULL for resolving " << flow->getDstApni().getApn() << endl; + const Address* ad = difAllocator->resolveApnToBestAddress(flow->getDstApni().getApn()); + if (ad == nullptr) { + EV << "difAllocator returned NULL for resolving " << flow->getDstApni().getApn() << endl; return false; } Address addr = *ad; @@ -177,7 +175,7 @@ bool FA::changeDstAddresses(Flow* flow, bool useNeighbor) { //If destination address does have neighbor then use first neighbor address if (useNeighbor) { - const APNList* apnlist = DifAllocator->findApnNeigbors(addr.getIpcAddress()); + const APNList* apnlist = difAllocator->findApnNeighbors(addr.getIpcAddress()); if (apnlist) addr.setIpcAddress(apnlist->front()); } @@ -200,11 +198,12 @@ bool FA::setOriginalAddresses(Flow* flow) { flow->setDstAddr(adr); return true; } + //XXX: Vesely - Dirty! Needs refactoring... bool FA::setNeighborAddresses(Flow* flow) { Address adr; if (!flow->isManagementFlowLocalToIPCP()) { - adr = getAddressFromDa(flow->getSrcApni().getApn(), true, flow->isManagementFlowLocalToIPCP()); + adr = getAddressFromDa(flow->getSrcApni().getApn(), true, false); if (adr.isUnspecified()) return false; flow->setSrcNeighbor(adr); @@ -222,10 +221,10 @@ bool FA::receiveAllocateRequest(Flow* flow) { EV << this->getFullPath() << " received AllocateRequest" << endl; //Insert new Flow into FAITable - N_flowTable->insertNew(flow); + nFlowTable->insertNew(flow); //Change allocation status to pending - N_flowTable->changeAllocStatus(flow, NFlowTableEntry::ALLOC_PEND); + nFlowTable->changeAllocStatus(flow, NFlowTableEntry::ALLOC_PEND); //Add source and destination address in case of data flow if (flow->getSrcAddr() == Address::UNSPECIFIED_ADDRESS @@ -237,21 +236,25 @@ bool FA::receiveAllocateRequest(Flow* flow) { } //Are both Apps local? YES then Degenerate transfer - if ( DifAllocator->isAppLocal( flow->getDstApni().getApn() ) ) { + if ( difAllocator->isAppLocal( flow->getDstApni().getApn() ) ) { flow->setDdtFlag(true); } //Check whether local IPCP is enrolled into DIF + // FIXME the below statement is incorrect. //Successful enrollment implies existence of N-1 mgmt-flow, if not then //FA needs to init allocation of N-1 mgmt-flow - if (!flow->isDdtFlag() && !Enrollment->isEnrolled(MyAddress.getApn())) { - EV << "IPCP not enrolled to DIF, thus executing enrollment!" << endl; - receiveMgmtAllocateRequest(APNamingInfo(MyAddress.getApn()), APNamingInfo(flow->getDstNeighbor().getApn())); + if (!flow->isDdtFlag() && + !enrollmentStateTable->isConnectedTo(flow->getDstNeighbor().getApn())) { + EV << "IPCP not connected to remote IPC, executing CACE" << endl; + receiveMgmtAllocateRequest(APNamingInfo(myAddress.getApn()), + APNamingInfo(flow->getDstNeighbor().getApn())); } //Is malformed? if (isMalformedFlow(flow)){ - N_flowTable->changeAllocStatus(flow, NFlowTableEntry::ALLOC_ERR); + nFlowTable->changeAllocStatus(flow, NFlowTableEntry::ALLOC_ERR); + // FIXME: Shouldn't this come before an attempt to allocate management flow? //TODO: Vesely - What about special signal for errors???? //this->signalizeAllocateResponseNegative(fl); return false; @@ -267,12 +270,9 @@ bool FA::receiveAllocateRequest(Flow* flow) { //Postpone allocation request until management flow is ready bool status; - if ( flow->isDdtFlag() || Enrollment->isEnrolled(MyAddress.getApn()) - ){ + if (flow->isDdtFlag() || enrollmentStateTable->isConnectedTo(flow->getDstNeighbor().getApn())) { status = fai->receiveAllocateRequest(); - } - else - { + } else { status = true; EV << "Management flow is not ready!" << endl; } @@ -283,16 +283,16 @@ bool FA::receiveAllocateRequest(Flow* flow) { } bool FA::receiveMgmtAllocateRequest(Flow* mgmtflow) { + Enter_Method("receiveMgmtAllocateRequest()"); bool status = true; //If N-1 mgmt-flow not ready, then allocate - if (!RaModule->hasFlow(mgmtflow->getDstAddr().getApn().getName(), VAL_MGMTQOSID)) { - status = RaModule->bindNFlowToNM1Flow(mgmtflow); + if (!raModule->hasFlow(mgmtflow->getDstAddr().getApn().getName(), VAL_MGMTQOSID)) { + status = raModule->bindNFlowToNM1Flow(mgmtflow); } - //If N-1 mgmt ready, then starting enrollment procedure - APNIPair* apnip = new APNIPair(mgmtflow->getSrcApni(), mgmtflow->getDstApni()); if (status) { - emit(sigFAAllocFinMgmt, apnip); + // If N-1 mgmt ready, then starting enrollment procedure + enrollment->startCACE(APNIPair(mgmtflow->getSrcApni(), mgmtflow->getDstApni())); } return status; @@ -302,30 +302,35 @@ bool FA::receiveMgmtAllocateRequest(APNamingInfo src, APNamingInfo dst) { Enter_Method("receiveLocalMgmtAllocateRequest()"); EV << this->getFullPath() << " received LocalMgmtAllocateRequest" << endl; - Flow* mgmtflow = new Flow(src, dst); - mgmtflow->setQosRequirements(QoSReq::MANAGEMENT); - mgmtflow->setSrcAddr(Address(src.getApn())); - mgmtflow->setDstAddr(Address(dst.getApn())); - mgmtflow->setSrcNeighbor(Address(src.getApn())); - mgmtflow->setDstNeighbor(Address(dst.getApn())); - bool status = true; //If N-1 mgmt-flow not ready, then allocate - if (!RaModule->hasFlow(mgmtflow->getDstAddr().getApn().getName(), VAL_MGMTQOSID)) { - status = RaModule->bindNFlowToNM1Flow(mgmtflow); + if (!raModule->hasFlow(dst.getApn().getName(), VAL_MGMTQOSID)) { + Flow mgmtflow(src, dst); + mgmtflow.setQosRequirements(QoSReq::MANAGEMENT); + mgmtflow.setSrcAddr(Address(src.getApn())); + mgmtflow.setDstAddr(Address(dst.getApn())); + mgmtflow.setSrcNeighbor(Address(src.getApn())); + mgmtflow.setDstNeighbor(Address(dst.getApn())); + + status = raModule->bindNFlowToNM1Flow(&mgmtflow); } - //If N-1 mgmt ready, then starting enrollment procedure - APNIPair* apnip = new APNIPair(mgmtflow->getSrcApni(), mgmtflow->getDstApni()); if (status) { - emit(sigFAAllocFinMgmt, apnip); + // If N-1 mgmt ready, then starting enrollment procedure + enrollment->startCACE(APNIPair(src, dst)); } return status; } -bool FA::receiveMgmtAllocateFinish() { +bool FA::receiveMgmtAllocateFinish(APNIPair *apnip) { Enter_Method("receiveAllocFinishMgmt()"); + EV << "AllocFinMgmt initiated" << endl; + + TFAIPtrs entries = nFlowTable->findEntriesAffectedByMgmt(apnip); + for (auto &entry : entries) + pendingFlows.push(entry->getFlow()); + scheduleAt(simTime(), new cMessage(TIM_FAPENDFLOWS) ); //TODO: Vesely - Fix unused return value return true; @@ -335,35 +340,31 @@ bool FA::receiveCreateFlowRequestFromRibd(Flow* flow) { Enter_Method("receiveCreateFlowRequest()"); EV << this->getFullPath() << " received CreateFlowRequest" << endl; - bool status; - //Is requested APP local? - if ( DifAllocator->isAppLocal(flow->getSrcApni().getApn()) ){ + if ( difAllocator->isAppLocal(flow->getSrcApni().getApn()) ){ //Check for duplicity - if (!DifAllocator->isAppLocal(flow->getDstApni().getApn()) - && N_flowTable->findEntryByInvokeId(flow->getAllocInvokeId()) + if (!difAllocator->isAppLocal(flow->getDstApni().getApn()) + && nFlowTable->findEntryByInvokeId(flow->getAllocInvokeId()) ) { EV << "Duplicit M_CREATE received thus ignoring!" << endl; return false; } //Insert new Flow into FAITable - N_flowTable->insertNew(flow); + nFlowTable->insertNew(flow); //Change neighbor addresses - //if (!flow->isManagementFlowLocalToIPCP()) { - setNeighborAddresses(flow); - //XXX: Vesely - Dirty! Needs refactoring... - flow->setSrcNeighbor(flow->getSrcAddr()); - //} + setNeighborAddresses(flow); + //XXX: Vesely - Dirty! Needs refactoring... + flow->setSrcNeighbor(flow->getSrcAddr()); EV << "Processing M_CREATE(flow)" << endl; //Change allocation status to pending - N_flowTable->changeAllocStatus(flow, NFlowTableEntry::ALLOC_PEND); + nFlowTable->changeAllocStatus(flow, NFlowTableEntry::ALLOC_PEND); //Create FAI FAI* fai = this->createFAI(flow); - if ( DifAllocator->isAppLocal( flow->getDstApni().getApn() ) ) { + if ( difAllocator->isAppLocal( flow->getDstApni().getApn() ) ) { fai->setDegenerateDataTransfer(true); flow->setDdtFlag(true); } @@ -375,56 +376,59 @@ bool FA::receiveCreateFlowRequestFromRibd(Flow* flow) { flow->getConnectionId().setSrcCepId(fai->getLocalCepId()); //Pass the CreateRequest to newly created FAI - status = fai->receiveCreateRequest(); - + return fai->receiveCreateRequest(); } + //...if not then forward CreateRequest Flow to next neighbor - else { - //App is not local but it should be (based on DA) - if (flow->getSrcAddr() == this->getMyAddress()) { - EV << "Rejecting flow allocation, APN not present on this system!" << endl; - this->signalizeCreateFlowResponseNegative(flow); - return false; - } - // - else { - EV << "Forwarding M_CREATE(flow)" << endl; - - //Before that reverse SRC-DST information back - flow->swapFlow(); - //Insert new Flow into FAITable - N_flowTable->insertNew(flow); - //Change neighbor addresses - setNeighborAddresses(flow); - //Change status to forward - N_flowTable->changeAllocStatus(flow, NFlowTableEntry::FORWARDING); - - //Decrement HopCount - flow->setHopCount(flow->getHopCount() - 1); - if (!flow->getHopCount()) { - //TODO: Vesely - More granular error - N_flowTable->changeAllocStatus(flow, NFlowTableEntry::ALLOC_ERR); - //Schedule M_Create_R(Flow) - EV << "Hopcount decremented to zero!" << endl; - this->signalizeCreateFlowResponseNegative(flow); - return false; - } + // TODO split into new function, add secondary function to easily replace + // this when the time comes + //App is not local but it should be (based on DA) + if (flow->getSrcAddr() == this->getMyAddress()) { + EV << "Rejecting flow allocation, APN not present on this system!" << endl; + emit(this->createResponseNegativeSignal, flow); + return false; + } - // bind this flow to a suitable (N-1)-flow - RABase* raModule = getRINAModule(this, 2, {MOD_RESALLOC, MOD_RA}); - status = raModule->bindNFlowToNM1Flow(flow); + EV << "Forwarding M_CREATE(flow)" << endl; - //EV << "status: " << status << endl; - if (status == true) { - // flow is already allocated - receiveNM1FlowCreated(flow); - } - //else WAIT until allocation of N-1 flow is completed - else { - EV << "FA waits until N-1 IPC allocates auxilliary N-1 flow" << endl; - } - } + //Before that reverse SRC-DST information back + flow->swapFlow(); + //Insert new Flow into FAITable + nFlowTable->insertNew(flow); + //Change neighbor addresses + setNeighborAddresses(flow); + //Change status to forward + nFlowTable->changeAllocStatus(flow, NFlowTableEntry::FORWARDING); + + //Decrement HopCount + flow->setHopCount(flow->getHopCount() - 1); + if (!flow->getHopCount()) { + //TODO: Vesely - More granular error + nFlowTable->changeAllocStatus(flow, NFlowTableEntry::ALLOC_ERR); + //Schedule M_Create_R(Flow) + EV << "Hopcount decremented to zero!" << endl; + emit(this->createResponseNegativeSignal, flow); + return false; } + + // Need to check if connected to remote application first + if (!enrollmentStateTable->isConnectedTo(flow->getDstNeighbor().getApn())) { + EV << "IPCP not connected to remote IPC, executing CACE" << endl; + return receiveMgmtAllocateRequest(APNamingInfo(myAddress.getApn()), + APNamingInfo(flow->getDstNeighbor().getApn())); + } + + // bind this flow to a suitable (N-1)-flow + bool status = raModule->bindNFlowToNM1Flow(flow); + if (status == true) { + // flow is already allocated + receiveNM1FlowCreated(flow); + } + //else WAIT until allocation of N-1 flow is completed + else { + EV << "FA waits until N-1 IPC allocates auxilliary N-1 flow" << endl; + } + return status; } @@ -433,11 +437,11 @@ bool FA::receiveDeallocateRequest(Flow* flow) { EV << this->getFullPath() << " received DeallocateRequest" << endl; //Check flow in table - NFlowTableEntry* fte = N_flowTable->findEntryByFlow(flow); + NFlowTableEntry* fte = nFlowTable->findEntryByFlow(flow); if (fte && fte->getFai()) { //Pass the request to appropriate FAI FAIBase* fai = fte->getFai(); - N_flowTable->changeAllocStatus(fai, NFlowTableEntry::DEALLOC_PEND); + nFlowTable->changeAllocStatus(fai, NFlowTableEntry::DEALLOC_PEND); fai->receiveDeallocateRequest(); return true; @@ -456,14 +460,14 @@ void FA::receiveNM1FlowCreated(Flow* flow) { EV << "Continue M_CREATE(flow) forward!" << endl; Flow* tmpfl = flow->dup(); - N_flowTable->changeAllocStatus(flow, NFlowTableEntry::FORWARDED); + nFlowTable->changeAllocStatus(flow, NFlowTableEntry::FORWARDED); setNeighborAddresses(tmpfl); - this->signalizeCreateFlowRequestForward(tmpfl); + emit(this->createRequestForwardSignal, tmpfl; } bool FA::invokeNewFlowRequestPolicy(Flow* flow) { - return NFloReqPolicy->run(*flow); + return nFloReqPolicy->run(*flow); } FAI* FA::createFAI(Flow* flow) { @@ -495,31 +499,45 @@ FAI* FA::createFAI(Flow* flow) { /* module->getDisplayString().setTagArg("p", 0, "100"); std::ostringstream os; - os << (70 + N_flowTable->getSize() * 50); + os << (70 + nFlowTable->getSize() * 50); module->getDisplayString().setTagArg("p", 1, os.str().c_str()); */ //Prepare return pointer and setup internal FAI pointers FAI* fai = dynamic_cast(module); - fai->postInitialize(this, flow, Efcp); + fai->postInitialize(this, flow, efcp); //Change state in FAITable - N_flowTable->setFaiToFlow(fai, flow); - N_flowTable->changeAllocStatus(flow, NFlowTableEntry::ALLOC_PEND); + nFlowTable->setFaiToFlow(fai, flow); + nFlowTable->changeAllocStatus(flow, NFlowTableEntry::ALLOC_PEND); return fai; } void FA::deinstantiateFai(Flow* flow) { - N_flowTable->changeAllocStatus(flow, NFlowTableEntry::DEINSTANTIATED); + nFlowTable->changeAllocStatus(flow, NFlowTableEntry::DEINSTANTIATED); //TODO: Vesely //Prepare deinstantitation self-message } -void FA::signalizeCreateFlowRequestForward(Flow* flow) { - emit(this->sigFACreReqFwd, flow); -} +void FA::receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject *) { + if (id != FAI::allocateResponsePositiveSignal) + throw cRuntimeError("Flow allocator received unsupported signal type"); + + EV << "Received positive allocation response from " << src->getFullPath() << endl; + Flow *flow = dynamic_cast(obj); + if (flow == nullptr) { + throw cRuntimeError("Flow allocator received "); + } else if (myAddress.getApn() != flow->getSrcApni().getApn()) { + EV << "Allocation response not intended for this FA." << endl; + return; + } else if (flow->isManagementFlowLocalToIPCP()) { + EV << "Management flow allocated!" << endl; + return; + } -void FA::signalizeCreateFlowResponseNegative(Flow* flow) { - emit(this->sigFACreResNega, flow); + // TODO split this into separate functions + TFAIPtrs entries = nFlowTable->findEntriesByDstNeighborAndFwd(flow->getDstApni().getApn()); + for (auto &entry : entries) + receiveNM1FlowCreated(entry->getFlow()); } diff --git a/src/DIF/FA/FA.h b/src/DIF/FA/FA.h index 79606470..f5eaa340 100644 --- a/src/DIF/FA/FA.h +++ b/src/DIF/FA/FA.h @@ -29,40 +29,47 @@ #ifndef FA_H_ #define FA_H_ -//Standard libraries +// Standard libraries #include -#include -//RINASim libraries + +// RINASim libraries #include "DIF/FA/FABase.h" -#include "DIF/FA/FAListeners.h" -#include "DIF/FA/FAI.h" -#include "Common/Flow.h" -#include "DIF/FA/NFlowTable.h" -#include "Common/RINASignals.h" -#include "DIF/EFCP/EFCP.h" #include "Common/ExternConsts.h" -#include "DAF/DA/DA.h" -#include "DIF/RA/RABase.h" -#include "DIF/FA/NewFlowRequest/NewFlowRequestBase.h" -#include "DIF/Enrollment/EnrollmentStateTable.h" -//Constants +// Forward declarations +class DA; +class EFCP; +class EnrollmentStateTable; +class Enrollment; +class FAI; +class Flow; +class NewFlowRequestBase; +class NFlowTable; +class RABase; +class QoSReq; + +class FA : public FABase, public cListener +{ + public: + // Signals + static const simsignal_t createRequestForwardSignal; + static const simsignal_t createResponseNegativeSignal; -extern const int RANDOM_NUMBER_GENERATOR; -extern const int MAX_PORTID; -extern const int MAX_CEPID; -extern const char* MOD_NEWFLOWREQPOLICY; + private: + EFCP* efcp = nullptr; + DA* difAllocator = nullptr; + RABase* raModule = nullptr; + NewFlowRequestBase* nFloReqPolicy = nullptr; + Enrollment* enrollment = nullptr; + EnrollmentStateTable* enrollmentStateTable = nullptr; -class FA : public FABase -{ public: - FA(); - virtual ~FA(); + FA() = default; virtual bool receiveAllocateRequest(Flow* flow); virtual bool receiveMgmtAllocateRequest(Flow* mgmtflow); virtual bool receiveMgmtAllocateRequest(APNamingInfo src, APNamingInfo dst); - virtual bool receiveMgmtAllocateFinish(); + virtual bool receiveMgmtAllocateFinish(APNIPair *apnip); virtual void receiveNM1FlowCreated(Flow* flow); virtual bool receiveDeallocateRequest(Flow* flow); virtual bool receiveCreateFlowRequestFromRibd(Flow* flow); @@ -74,45 +81,25 @@ class FA : public FABase bool invokeNewFlowRequestPolicy(Flow* flow); - //Signals - simsignal_t sigFACreReqFwd; - simsignal_t sigFACreResNega; - simsignal_t sigFACreResPosiFwd; - simsignal_t sigFAAllocFinMgmt; - - //Listeners - //LisFAAllocReq* lisAllocReq; - //LisFADeallocReq* lisDeallocReq; - LisFAAllocFinMgmt* lisEnrollFin; - LisFACreFloPosi* lisCreFloPosi; - LisFACreReq* lisCreReq; - - protected: + private: //SimpleModule overloads - virtual void initialize(); + virtual void initialize(int stage); + virtual int numInitStages() const { return 1; }; virtual void handleMessage(cMessage *msg); - void initPointers(); - private: - EFCP* Efcp; - DA* DifAllocator; - RABase* RaModule; - NewFlowRequestBase* NFloReqPolicy; - EnrollmentStateTable* Enrollment; - - bool isMalformedFlow(Flow* flow); - FAI* createFAI(Flow* flow); + //cListener overload + virtual void receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject *detail); + void initPointers(); void initSignalsAndListeners(); - void signalizeCreateFlowRequestForward(Flow* flow); - void signalizeCreateFlowResponseNegative(Flow* flow); + bool isMalformedFlow(Flow* flow); + FAI* createFAI(Flow* flow); const Address getAddressFromDa(const APN& apn, bool useNeighbor, bool isMgmtFlow); bool changeDstAddresses(Flow* flow, bool useNeighbor); bool changeSrcAddress(Flow* flow, bool useNeighbor); - }; #endif /* FLOWALLOCATOR_H_ */ diff --git a/src/DIF/FA/FABase.cc b/src/DIF/FA/FABase.cc index fdfc5605..cbcfdc42 100644 --- a/src/DIF/FA/FABase.cc +++ b/src/DIF/FA/FABase.cc @@ -23,34 +23,33 @@ #include "DIF/FA/FABase.h" -const char* TIM_FAPENDFLOWS = "FA-PendingFlows"; - -FABase::FABase() { - this->N_flowTable = NULL; -} +#include "DIF/FA/NFlowTable.h" +#include "Common/ExternConsts.h" +#include "Common/APNamingInfo.h" -FABase::~FABase() { - this->N_flowTable = NULL; -} +const int FABase::RANDOM_NUMBER_GENERATOR = 0; +const int FABase::MAX_PORTID = 65535; +const int FABase::MAX_CEPID = 65535; +const char* TIM_FAPENDFLOWS = "FA-PendingFlows"; NFlowTable* FABase::getNFlowTable() const { - return N_flowTable; + return nFlowTable; } void FABase::initMyAddress() { - //Setup MyAddress + //Setup myAddress cModule* ipc = this->getModuleByPath("^.^"); - MyAddress = Address(ipc->par(PAR_IPCADDR), ipc->par(PAR_DIFNAME)); - EV << "SrcAddress that this FA will use is " << MyAddress << endl; + myAddress = Address(ipc->par(PAR_IPCADDR), ipc->par(PAR_DIFNAME)); + EV << "SrcAddress that this FA will use is " << myAddress << endl; std::ostringstream description; - description << "address: " << MyAddress.getIpcAddress() - << "\ndif: " << MyAddress.getDifName(); + description << "address: " << myAddress.getIpcAddress() + << "\ndif: " << myAddress.getDifName(); ipc->getDisplayString().setTagArg("t", 0, description.str().c_str()); ipc->getDisplayString().setTagArg("t", 1, "r"); } const Address& FABase::getMyAddress() const { - return MyAddress; + return myAddress; } diff --git a/src/DIF/FA/FABase.h b/src/DIF/FA/FABase.h index e6ed7f0b..4c11ddbb 100644 --- a/src/DIF/FA/FABase.h +++ b/src/DIF/FA/FABase.h @@ -25,23 +25,27 @@ //Standard libraries #include +#include //RINASim libraries -#include "DIF/FA/NFlowTable.h" +#include "Common/Address.h" extern const char* TIM_FAPENDFLOWS; +class APNamingInfo; +class APNIPair; +class NFlowTable; +class Flow; + class FABase : public cSimpleModule { public: + FABase() = default; - FABase(); - virtual ~FABase(); - - std::list PendingFlows; + std::queue pendingFlows; virtual bool receiveAllocateRequest(Flow* flow) = 0; virtual bool receiveMgmtAllocateRequest(Flow* mgmtflow) = 0; virtual bool receiveMgmtAllocateRequest(APNamingInfo src, APNamingInfo dst) = 0; - virtual bool receiveMgmtAllocateFinish() = 0; + virtual bool receiveMgmtAllocateFinish(APNIPair *apnip) = 0; virtual void receiveNM1FlowCreated(Flow* flow) = 0; //virtual void receiveCreateResponseFlowPositiveFromRibd(Flow* flow) = 0; virtual bool receiveCreateFlowRequestFromRibd(Flow* flow) = 0; @@ -55,16 +59,20 @@ class FABase : public cSimpleModule { NFlowTable* getNFlowTable() const; const Address& getMyAddress() const; + static const int RANDOM_NUMBER_GENERATOR; + static const int MAX_PORTID; + static const int MAX_CEPID; + protected: - NFlowTable* N_flowTable; - Address MyAddress; + NFlowTable* nFlowTable = nullptr; + Address myAddress; //SimpleModule overloads - virtual void initialize() = 0; + virtual void initialize(int stage) override = 0; + virtual int numInitStages() const = 0; virtual void handleMessage(cMessage *msg) = 0; void initMyAddress(); - }; diff --git a/src/DIF/FA/FAI.cc b/src/DIF/FA/FAI.cc index 2e3d4c98..1b296ff3 100644 --- a/src/DIF/FA/FAI.cc +++ b/src/DIF/FA/FAI.cc @@ -22,27 +22,41 @@ #include "DIF/FA/FAI.h" +#include "Common/RINASignals.h" +#include "DIF/FA/FABase.h" +#include "DIF/RA/RABase.h" +#include "DIF/RMT/RMT.h" +#include "DIF/FA/NFlowTable.h" +#include "DIF/EFCP/EFCP.h" +#include "DIF/FA/AllocateRetry/AllocateRetryBase.h" + const char* TIM_CREREQ = "CreateRequestTimer"; const char* MOD_ALLOCRETRYPOLICY= "allocateRetryPolicy"; Define_Module(FAI); -FAI::FAI() : FAIBase() { - FaModule = NULL; - //creReqTimer = NULL; +FAI::FAI() + : FAIBase(), + localPortId(VAL_UNDEF_PORTID), + localCEPId(VAL_UNDEF_PORTID), + remotePortId(VAL_UNDEF_PORTID), + remoteCEPId(VAL_UNDEF_CEPID), + efcp(nullptr), + fa(nullptr) +{ } FAI::~FAI() { - FaModule = NULL; - FlowObject = NULL; - degenerateDataTransfer = false; - localPortId = VAL_UNDEF_PORTID; - localCEPId = VAL_UNDEF_CEPID; - remotePortId = VAL_UNDEF_PORTID; - remoteCEPId = VAL_UNDEF_CEPID; - - //if (creReqTimer) - // cancelAndDelete(creReqTimer); + if (lisDelRes != nullptr) { + delete lisAllocResNega; + delete lisAllocResPosi; + delete lisCreResNega; + delete lisCreResPosi; + delete lisCreResNegaNmO; + delete lisCreResPosiNmO; + delete lisDelReq; + delete lisDelRes; + } } void FAI::initialize() { @@ -51,39 +65,38 @@ void FAI::initialize() { remotePortId = par(PAR_REMOTEPORTID); remoteCEPId = par(PAR_REMOTECEPID); - //creReqTimeout = par(PAR_CREREQTIMEOUT).doubleValue(); - AllocRetryPolicy = getRINAModule(this, 1, {MOD_ALLOCRETRYPOLICY}); WATCH(degenerateDataTransfer); - WATCH_PTR(FlowObject); + WATCH_PTR(flowObject); initSignalsAndListeners(); } void FAI::postInitialize(FABase* fa, Flow* fl, EFCP* efcp) { //Initialize pointers! It cannot be done during model creation :( - this->FaModule = fa; - this->FlowObject = fl; - this->EfcpModule = efcp; + this->fa = fa; + this->flowObject = fl; + this->efcp = efcp; } + bool FAI::receiveAllocateRequest() { Enter_Method("receiveAllocateRequest()"); //Check for proper FSM state - NFlowTable* ft = FaModule->getNFlowTable(); - NFlowTableEntry* fte = ft->findEntryByFlow(FlowObject); + NFlowTable* ft = fa->getNFlowTable(); + NFlowTableEntry* fte = ft->findEntryByFlow(flowObject); if (fte->getAllocateStatus() != NFlowTableEntry::ALLOC_PEND) { EV << "Cannot allocate flow which is not in pending state" << endl; return false; } //Invoke NewFlowReqPolicy - bool status = this->FaModule->invokeNewFlowRequestPolicy(this->FlowObject); + bool status = this->fa->invokeNewFlowRequestPolicy(this->flowObject); if (!status){ EV << "invokeNewFlowPolicy() failed" << endl; - ft->changeAllocStatus(FlowObject, NFlowTableEntry::ALLOC_NEGA); + ft->changeAllocStatus(flowObject, NFlowTableEntry::ALLOC_NEGA); this->signalizeAllocateResponseNegative(); return false; } @@ -91,7 +104,7 @@ bool FAI::receiveAllocateRequest() { status = this->createEFCPI(); if (!status) { EV << "createEFCP() failed" << endl; - ft->changeAllocStatus(FlowObject, NFlowTableEntry::ALLOC_NEGA); + ft->changeAllocStatus(flowObject, NFlowTableEntry::ALLOC_NEGA); this->signalizeAllocateResponseNegative(); return false; } @@ -99,17 +112,15 @@ bool FAI::receiveAllocateRequest() { status = this->createBindings(); if (!status) { EV << "createBindings() failed" << endl; - ft->changeAllocStatus(FlowObject, NFlowTableEntry::ALLOC_NEGA); + ft->changeAllocStatus(flowObject, NFlowTableEntry::ALLOC_NEGA); this->signalizeAllocateResponseNegative(); return false; } - //EV << "!!!!!!" << FlowObject->info() << endl << FlowObject->getDstNeighbor() << endl; - // bind this flow to a suitable (N-1)-flow RABase* raModule = getRINAModule(this, 2, {MOD_RESALLOC, MOD_RA}); - status = isDegenerateDataTransfer() ? true : raModule->bindNFlowToNM1Flow(FlowObject); + status = isDegenerateDataTransfer() ? true : raModule->bindNFlowToNM1Flow(flowObject); //IF flow is already available then schedule M_Create(Flow) if (status) { this->signalizeCreateFlowRequest(); @@ -123,8 +134,8 @@ bool FAI::receiveAllocateResponsePositive() { Enter_Method("receiveAllocateResponsePositive()"); //Check for proper FSM state - NFlowTable* ft = FaModule->getNFlowTable(); - NFlowTableEntry* fte = ft->findEntryByFlow(FlowObject); + NFlowTable* ft = fa->getNFlowTable(); + NFlowTableEntry* fte = ft->findEntryByFlow(flowObject); if (fte->getAllocateStatus() != NFlowTableEntry::ALLOC_PEND) { EV << "Cannot continue allocation of flow which is not in pending state" << endl; return false; @@ -135,7 +146,7 @@ bool FAI::receiveAllocateResponsePositive() { bool status = this->createEFCPI(); if (!status) { EV << "createEFCP() failed" << endl; - ft->changeAllocStatus(FlowObject, NFlowTableEntry::ALLOC_NEGA); + ft->changeAllocStatus(flowObject, NFlowTableEntry::ALLOC_NEGA); //Schedule negative M_Create_R(Flow) this->signalizeCreateFlowResponseNegative(); return false; @@ -145,7 +156,7 @@ bool FAI::receiveAllocateResponsePositive() { status = this->createBindings(); if (!status) { EV << "createBindings() failed" << endl; - ft->changeAllocStatus(FlowObject, NFlowTableEntry::ALLOC_NEGA); + ft->changeAllocStatus(flowObject, NFlowTableEntry::ALLOC_NEGA); //Schedule M_Create_R(Flow-) this->signalizeCreateFlowResponseNegative(); return false; @@ -153,9 +164,9 @@ bool FAI::receiveAllocateResponsePositive() { // bind this flow to a suitable (N-1)-flow RABase* raModule = getRINAModule(this, 2, {MOD_RESALLOC, MOD_RA}); - status = isDegenerateDataTransfer() ? true : raModule->bindNFlowToNM1Flow(FlowObject); + status = isDegenerateDataTransfer() ? true : raModule->bindNFlowToNM1Flow(flowObject); - ft->changeAllocStatus(FlowObject, NFlowTableEntry::TRANSFER); + ft->changeAllocStatus(flowObject, NFlowTableEntry::TRANSFER); //Signalizes M_Create_R(flow) if (status) { this->signalizeCreateFlowResponsePositive(); @@ -167,14 +178,14 @@ bool FAI::receiveAllocateResponsePositive() { void FAI::receiveAllocateResponseNegative() { Enter_Method("receiveAllocateResponseNegative()"); //Check for proper FSM state - NFlowTable* ft = FaModule->getNFlowTable(); - NFlowTableEntry* fte = ft->findEntryByFlow(FlowObject); + NFlowTable* ft = fa->getNFlowTable(); + NFlowTableEntry* fte = ft->findEntryByFlow(flowObject); if (fte->getAllocateStatus() != NFlowTableEntry::ALLOC_PEND) { EV << "Cannot continue allocation of flow which is not in pending state" << endl; return; } - ft->changeAllocStatus(FlowObject, NFlowTableEntry::ALLOC_NEGA); + ft->changeAllocStatus(flowObject, NFlowTableEntry::ALLOC_NEGA); //IF it is not DDT then retry M_CREATE //if (!isDegenerateDataTransfer()) @@ -185,19 +196,19 @@ bool FAI::receiveCreateRequest() { Enter_Method("receiveCreateRequest()"); //Check for proper FSM state - NFlowTable* ft = FaModule->getNFlowTable(); - NFlowTableEntry* fte = ft->findEntryByFlow(FlowObject); + NFlowTable* ft = fa->getNFlowTable(); + NFlowTableEntry* fte = ft->findEntryByFlow(flowObject); if (fte->getAllocateStatus() != NFlowTableEntry::ALLOC_PEND) { EV << "Cannot allocate flow which is not in pending state" << endl; return false; } //Invoke NewFlowReqPolicy - bool status = this->FaModule->invokeNewFlowRequestPolicy(this->FlowObject); + bool status = this->fa->invokeNewFlowRequestPolicy(this->flowObject); if (!status){ EV << "invokeNewFlowPolicy() failed" << endl; //Schedule negative M_Create_R(Flow) - ft->changeAllocStatus(FlowObject, NFlowTableEntry::ALLOC_NEGA); + ft->changeAllocStatus(flowObject, NFlowTableEntry::ALLOC_NEGA); this->signalizeCreateFlowResponseNegative(); return false; } @@ -216,8 +227,8 @@ bool FAI::receiveDeallocateRequest() { Enter_Method("receiveDeallocateRequest()"); //Check for proper FSM state - NFlowTable* ft = FaModule->getNFlowTable(); - NFlowTableEntry* fte = ft->findEntryByFlow(FlowObject); + NFlowTable* ft = fa->getNFlowTable(); + NFlowTableEntry* fte = ft->findEntryByFlow(flowObject); if (fte->getAllocateStatus() != NFlowTableEntry::DEALLOC_PEND) { EV << "Cannot deallocate flow which is not in deallocate pending state" << endl; return false; @@ -236,17 +247,17 @@ void FAI::receiveDeleteRequest(Flow* flow) { Enter_Method("receiveDeleteRequest()"); //Check for proper FSM state - NFlowTable* ft = FaModule->getNFlowTable(); - NFlowTableEntry* fte = ft->findEntryByFlow(FlowObject); + NFlowTable* ft = fa->getNFlowTable(); + NFlowTableEntry* fte = ft->findEntryByFlow(flowObject); if (fte->getAllocateStatus() != NFlowTableEntry::TRANSFER) { EV << "Cannot deallocate flow which is not in transfer state" << endl; return; } - ft->changeAllocStatus(FlowObject, NFlowTableEntry::DEALLOC_PEND); + ft->changeAllocStatus(flowObject, NFlowTableEntry::DEALLOC_PEND); //Get deallocation invokeId from Request - FlowObject->setDeallocInvokeId(flow->getDeallocInvokeId()); + flowObject->setDeallocInvokeId(flow->getDeallocInvokeId()); //Notify application signalizeDeallocateRequestFromFai(); @@ -257,7 +268,7 @@ void FAI::receiveDeleteRequest(Flow* flow) { //Signalizes M_Delete_R(Flow) this->signalizeDeleteFlowResponse(); - ft->changeAllocStatus(FlowObject, NFlowTableEntry::DEALLOCATED); + ft->changeAllocStatus(flowObject, NFlowTableEntry::DEALLOCATED); fte->setTimeDeleted(simTime()); } @@ -274,7 +285,7 @@ bool FAI::receiveCreateResponseNegative() { //...otherwise signalize to AE or RIBd failure else { EV << "invokeAllocateRetryPolicy() failed" << endl; - FaModule->getNFlowTable()->changeAllocStatus(FlowObject, NFlowTableEntry::ALLOC_NEGA); + fa->getNFlowTable()->changeAllocStatus(flowObject, NFlowTableEntry::ALLOC_NEGA); this->signalizeAllocateResponseNegative(); } @@ -286,26 +297,19 @@ bool FAI::receiveCreateResponsePositive(Flow* flow) { //TODO: Vesely - D-Base-2011-015.pdf, p.9 // Create bindings. WTF? Bindings should be already created!'' - //cancelEvent(creReqTimer); - //Change dstCep-Id and dstPortId according to new information - FlowObject->getConnectionId().setDstCepId(flow->getConId().getDstCepId()); - FlowObject->setDstPortId(flow->getDstPortId()); + flowObject->getConnectionId().setDstCepId(flow->getConId().getDstCepId()); + flowObject->setDstPortId(flow->getDstPortId()); remotePortId = flow->getDstPortId(); remoteCEPId = flow->getConId().getDstCepId(); par(PAR_REMOTEPORTID) = remotePortId; par(PAR_REMOTECEPID) = remoteCEPId; //Change status - FaModule->getNFlowTable()->changeAllocStatus(FlowObject, NFlowTableEntry::TRANSFER); + fa->getNFlowTable()->changeAllocStatus(flowObject, NFlowTableEntry::TRANSFER); - //if (FlowObject->isManagementFlowLocalToIPCP()) { - // signalizeAllocateRequestToOtherFais( FlowObject ); - //} - //else { - //Pass Allocate Response to AE or RIBd - this->signalizeAllocateResponsePositive(); - //} + //Pass Allocate Response to AE or RIBd + this->signalizeAllocateResponsePositive(); //FIXME: Vesely - always true return true; @@ -315,8 +319,8 @@ void FAI::receiveDeleteResponse() { Enter_Method("receiveDeleteResponse()"); //Check for proper FSM state - NFlowTable* ft = FaModule->getNFlowTable(); - NFlowTableEntry* fte = ft->findEntryByFlow(FlowObject); + NFlowTable* ft = fa->getNFlowTable(); + NFlowTableEntry* fte = ft->findEntryByFlow(flowObject); if (fte->getAllocateStatus() != NFlowTableEntry::DEALLOC_PEND) { EV << "Cannot deallocate flow which is not in deallocatre pending state" << endl; return; @@ -325,7 +329,7 @@ void FAI::receiveDeleteResponse() { //Notify application signalizeDeallocateRequestFromFai(); - ft->changeAllocStatus(FlowObject, NFlowTableEntry::DEALLOCATED); + ft->changeAllocStatus(flowObject, NFlowTableEntry::DEALLOCATED); fte->setTimeDeleted(simTime()); } @@ -357,14 +361,14 @@ std::ostream& operator<< (std::ostream& os, const FAI& fai) { bool FAI::createEFCPI() { EV << this->getFullPath() << " attempts to create EFCP instance" << endl; //Create EFCPI for local bindings - EFCPInstance* efcpi = EfcpModule->createEFCPI(FlowObject, localCEPId, localPortId); + EFCPInstance* efcpi = efcp->createEFCPI(flowObject, localCEPId, localPortId); return efcpi ? true : false; } bool FAI::createBindings() { EV << this->getFullPath() << " attempts to bind EFCP and RMT" << endl; - cModule* IPCModule = FaModule->getModuleByPath("^.^"); + cModule* IPCModule = fa->getModuleByPath("^.^"); std::ostringstream nameEfcpNorth; nameEfcpNorth << GATE_APPIO_ << localPortId; @@ -373,7 +377,7 @@ bool FAI::createBindings() { cGate* gateEfcpUpOut = efcpModule->gateHalf(nameEfcpNorth.str().c_str(), cGate::OUTPUT); //Management Flow should be connected with RIBd - if (FlowObject->isManagementFlowLocalToIPCP()) { + if (flowObject->isManagementFlowLocalToIPCP()) { std::ostringstream ribdName; ribdName << GATE_EFCPIO_ << localPortId; cModule* ribdModule = getRINAModule(IPCModule, 0, {MOD_RIBDAEMON}); @@ -440,10 +444,10 @@ bool FAI::deleteBindings() { EV << this->getFullPath() << " attempts to disconnect bindings between EFCP, IPC and RMT" << endl; //Flush All messages in EFCPI - EfcpModule->deleteEFCPI(this->getFlow()); + efcp->deleteEFCPI(this->getFlow()); //Management flow - if (FlowObject->isManagementFlowLocalToIPCP()) { + if (flowObject->isManagementFlowLocalToIPCP()) { std::ostringstream ribdName; ribdName << GATE_EFCPIO_ << localPortId; cModule* ribdModule = getRINAModule(this, 2, {MOD_RIBDAEMON}); @@ -461,7 +465,7 @@ bool FAI::deleteBindings() { } //Data flow else { - cModule* IPCModule = FaModule->getModuleByPath("^.^"); + cModule* IPCModule = fa->getModuleByPath("^.^"); std::ostringstream nameIpcDown; nameIpcDown << GATE_NORTHIO_ << localPortId; cGate* gateIpcDownIn = IPCModule->gateHalf(nameIpcDown.str().c_str(), cGate::INPUT); @@ -514,31 +518,13 @@ bool FAI::invokeAllocateRetryPolicy() { void FAI::initSignalsAndListeners() { cModule* catcher2 = this->getModuleByPath("^.^"); cModule* catcher3 = this->getModuleByPath("^.^.^"); - //Signals that module emits - sigFAIAllocReq = registerSignal(SIG_FAI_AllocateRequest); - sigFAIDeallocReq = registerSignal(SIG_FAI_DeallocateRequest); - sigFAIDeallocRes = registerSignal(SIG_FAI_DeallocateResponse); - sigFAIAllocResPosi = registerSignal(SIG_FAI_AllocateResponsePositive); - sigFAIAllocResNega = registerSignal(SIG_FAI_AllocateResponseNegative); - sigFAICreReq = registerSignal(SIG_FAI_CreateFlowRequest); - sigFAIDelReq = registerSignal(SIG_FAI_DeleteFlowRequest); - sigFAIDelRes = registerSignal(SIG_FAI_DeleteFlowResponse); - sigFAICreResNega = registerSignal(SIG_FAI_CreateFlowResponseNegative); - sigFAICreResPosi = registerSignal(SIG_FAI_CreateFlowResponsePositive); - //Signals that module processes - // AllocationRequest - this->lisAllocReq = new LisFAIAllocReq(this); - catcher3->subscribe(SIG_toFAI_AllocateRequest, this->lisAllocReq); // AllocationRespNegative this->lisAllocResNega = new LisFAIAllocResNega(this); catcher3->subscribe(SIG_AERIBD_AllocateResponseNegative, this->lisAllocResNega); // AllocationRespPositive this->lisAllocResPosi = new LisFAIAllocResPosi(this); catcher3->subscribe(SIG_AERIBD_AllocateResponsePositive, this->lisAllocResPosi); -// // CreateFlowRequest -// this->lisCreReq = new LisFAICreReq(this); -// catcher->subscribe(SIG_FAI_CreateFlowRequest, this->lisCreReq); // CreateFlowResponseNegative this->lisCreResNega = new LisFAICreResNega(this); catcher3->subscribe(SIG_RIBD_CreateFlowResponseNegative, this->lisCreResNega); @@ -560,49 +546,45 @@ void FAI::initSignalsAndListeners() { //DeleteResponseFlow lisDelRes = new LisFAIDelRes(this); catcher2->subscribe(SIG_RIBD_DeleteResponseFlow, lisDelRes); - } void FAI::signalizeCreateFlowRequest() { - //creReqTimer = new cMessage(TIM_CREREQ); - //Start timer - //scheduleAt(simTime() + creReqTimeout, creReqTimer); //Signalize RIBd to send M_CREATE(flow) - emit(this->sigFAICreReq, FlowObject); + emit(this->createRequestSignal, flowObject); } void FAI::signalizeDeleteFlowResponse() { - emit(this->sigFAIDelRes, this->FlowObject); + emit(this->deleteResponseSignal, this->flowObject); } void FAI::signalizeCreateFlowResponsePositive() { - emit(this->sigFAICreResPosi, FlowObject); + emit(this->createResponsePositiveSignal, flowObject); } void FAI::signalizeCreateFlowResponseNegative() { - emit(this->sigFAICreResNega, FlowObject); + emit(this->createResponseNegativeSignal, flowObject); } void FAI::signalizeAllocationRequestFromFai() { - EV << "Trying to notify " << FlowObject->getSrcApni() << endl; - emit(sigFAIAllocReq, FlowObject); + EV << "Trying to notify " << flowObject->getSrcApni() << endl; + emit(allocateRequestSignal, flowObject); } void FAI::signalizeDeleteFlowRequest() { - emit(this->sigFAIDelReq, this->FlowObject); + emit(this->deleteRequestSignal, this->flowObject); } void FAI::signalizeAllocateResponseNegative() { - emit(this->sigFAIAllocResNega, this->FlowObject); + emit(this->allocateResponseNegativeSignal, this->flowObject); } void FAI::signalizeDeallocateRequestFromFai() { - emit(this->sigFAIDeallocReq, this->FlowObject); + emit(this->deallocateRequestSignal, this->flowObject); } void FAI::signalizeDeallocateResponseFromFai() { - emit(this->sigFAIDeallocRes, this->FlowObject); + emit(this->deallocateResponseSignal, this->flowObject); } int FAI::getLocalCepId() const { @@ -638,12 +620,12 @@ void FAI::setRemotePortId(int remotePortId) { } void FAI::signalizeAllocateResponsePositive() { - emit(this->sigFAIAllocResPosi, this->FlowObject); + emit(this->allocateResponsePositiveSignal, this->flowObject); } void FAI::createNorthGates() { //Management flow - if (FlowObject->isManagementFlowLocalToIPCP()) { + if (flowObject->isManagementFlowLocalToIPCP()) { std::ostringstream ribdName; ribdName << GATE_EFCPIO_ << localPortId; cModule* ribdModule = getRINAModule(this, 2, {MOD_RIBDAEMON}); @@ -656,7 +638,7 @@ void FAI::createNorthGates() { else { std::ostringstream nameIpcDown; nameIpcDown << GATE_NORTHIO_ << localPortId; - cModule* IPCModule = FaModule->getModuleByPath("^.^"); + cModule* IPCModule = fa->getModuleByPath("^.^"); IPCModule->addGate(nameIpcDown.str().c_str(), cGate::INOUT, false); } return; diff --git a/src/DIF/FA/FAI.h b/src/DIF/FA/FAI.h index 0782bf4c..f955e9f3 100644 --- a/src/DIF/FA/FAI.h +++ b/src/DIF/FA/FAI.h @@ -28,15 +28,12 @@ #ifndef FAI_H_ #define FAI_H_ -//Standard libraries +// Standard libraries #include -//RINASim libraries + +// RINASim libraries #include "DIF/FA/FAIBase.h" -#include "DIF/FA/FABase.h" #include "DIF/FA/FAIListeners.h" -#include "Common/RINASignals.h" -#include "DIF/EFCP/EFCP.h" -#include "DIF/FA/AllocateRetry/AllocateRetryBase.h" //#include "PushBackChannel.h" @@ -44,7 +41,35 @@ extern const char* TIM_CREREQ; extern const char* MOD_ALLOCRETRYPOLICY; +class FABase; +class EFCP; +class AllocateRetryBase; + class FAI : public FAIBase { + private: + int localPortId; + int localCEPId; + int remotePortId; + int remoteCEPId; + + EFCP* efcp; + AllocateRetryBase* AllocRetryPolicy; + + cMessage* creReqTimer; + //double creReqTimeout; + + FABase* fa; + + //Listeners + LisFAIAllocResNega* lisAllocResNega = nullptr; + LisFAIAllocResPosi* lisAllocResPosi = nullptr; + LisFAICreResNega* lisCreResNega = nullptr; + LisFAICreResPosi* lisCreResPosi = nullptr; + LisFAIDelReq* lisDelReq = nullptr; + LisFAIDelRes* lisDelRes = nullptr; + LisFAICreResPosiNminusOne* lisCreResPosiNmO = nullptr; + LisFAICreResNegaNminusOne* lisCreResNegaNmO = nullptr; + public: FAI(); virtual ~FAI(); @@ -64,11 +89,10 @@ class FAI : public FAIBase { virtual void receiveCreateFlowResponsePositiveFromNminusOne(); virtual void receiveCreateFlowResponseNegativeFromNminusOne(); - void postInitialize(FABase* fa, Flow* fl, EFCP* efcp); const FABase* getFa() const { - return FaModule; + return fa; } int getLocalCepId() const; @@ -80,57 +104,11 @@ class FAI : public FAIBase { int getRemotePortId() const; void setRemotePortId(int remotePortId); - protected: - int localPortId; - int localCEPId; - int remotePortId; - int remoteCEPId; - - AllocateRetryBase* AllocRetryPolicy; - - cMessage* creReqTimer; - //double creReqTimeout; - - FABase* FaModule; - - //Signals - simsignal_t sigFAIAllocReq; - simsignal_t sigFAIDeallocReq; - simsignal_t sigFAIDeallocRes; - simsignal_t sigFAIAllocResPosi; - simsignal_t sigFAIAllocResNega; - simsignal_t sigFAICreReq; - simsignal_t sigFAIDelReq; - simsignal_t sigFAIDelRes; - simsignal_t sigFAICreResNega; - simsignal_t sigFAICreResPosi; - - //Listeners - LisFAIAllocReq* lisAllocReq; - LisFAIAllocResNega* lisAllocResNega; - LisFAIAllocResPosi* lisAllocResPosi; - LisFAICreResNega* lisCreResNega; - LisFAICreResPosi* lisCreResPosi; - LisFAIDelReq* lisDelReq; - LisFAIDelRes* lisDelRes; - LisFAICreResPosiNminusOne* lisCreResPosiNmO; - LisFAICreResNegaNminusOne* lisCreResNegaNmO; - + private: virtual void initialize(); virtual void handleMessage(cMessage *msg); - private: - EFCP* EfcpModule; - void initSignalsAndListeners(); - - bool createEFCPI(); - void createNorthGates(); - bool createBindings(); - bool deleteBindings(); - - bool invokeAllocateRetryPolicy(); - void signalizeCreateFlowRequest(); void signalizeCreateFlowResponsePositive(); void signalizeCreateFlowResponseNegative(); @@ -141,8 +119,13 @@ class FAI : public FAIBase { void signalizeDeallocateResponseFromFai(); void signalizeAllocateResponseNegative(); void signalizeAllocateResponsePositive(); - void signalizeAllocateRequestToOtherFais(Flow* flow); + bool createEFCPI(); + void createNorthGates(); + bool createBindings(); + bool deleteBindings(); + + bool invokeAllocateRetryPolicy(); }; //Free function diff --git a/src/DIF/FA/FAIBase.cc b/src/DIF/FA/FAIBase.cc index 2fd211ea..9f730dca 100644 --- a/src/DIF/FA/FAIBase.cc +++ b/src/DIF/FA/FAIBase.cc @@ -22,12 +22,23 @@ #include "DIF/FA/FAIBase.h" -FAIBase::FAIBase() : FlowObject(NULL), degenerateDataTransfer(false) -{ -} +#include "Common/Flow.h" +#include "Common/RINASignals.h" -FAIBase::~FAIBase() { - FlowObject = NULL; - degenerateDataTransfer = false; +const simsignal_t FAIBase::allocateRequestSignal = registerSignal(SIG_FAI_AllocateRequest); +const simsignal_t FAIBase::deallocateRequestSignal = registerSignal(SIG_FAI_DeallocateRequest); +const simsignal_t FAIBase::deallocateResponseSignal = registerSignal(SIG_FAI_DeallocateResponse); +const simsignal_t FAIBase::allocateResponsePositiveSignal = registerSignal(SIG_FAI_AllocateResponsePositive); +const simsignal_t FAIBase::allocateResponseNegativeSignal = registerSignal(SIG_FAI_AllocateResponseNegative); +// Listened to by this IPCP's FANotifier +const simsignal_t FAIBase::createRequestSignal = registerSignal(SIG_FAI_CreateFlowRequest); +const simsignal_t FAIBase::deleteRequestSignal = registerSignal(SIG_FAI_DeleteFlowRequest); +const simsignal_t FAIBase::deleteResponseSignal = registerSignal(SIG_FAI_DeleteFlowResponse); +const simsignal_t FAIBase::createResponseNegativeSignal = registerSignal(SIG_FAI_CreateFlowResponseNegative); +const simsignal_t FAIBase::createResponsePositiveSignal = registerSignal(SIG_FAI_CreateFlowResponsePositive); + +FAIBase::FAIBase() : flowObject(nullptr), degenerateDataTransfer(false) +{ } +FAIBase::~FAIBase() {} diff --git a/src/DIF/FA/FAIBase.h b/src/DIF/FA/FAIBase.h index 7e51ad9e..8bd38a49 100644 --- a/src/DIF/FA/FAIBase.h +++ b/src/DIF/FA/FAIBase.h @@ -25,14 +25,33 @@ //Standard libraries #include -//RINASim libraries -#include "Common/Flow.h" + +class Flow; class FAIBase : public cSimpleModule { + public: + //Signals + static const simsignal_t allocateRequestSignal; + static const simsignal_t deallocateRequestSignal; + static const simsignal_t deallocateResponseSignal; + static const simsignal_t allocateResponsePositiveSignal; + static const simsignal_t allocateResponseNegativeSignal; + static const simsignal_t createRequestSignal; + static const simsignal_t deleteRequestSignal; + static const simsignal_t deleteResponseSignal; + static const simsignal_t createResponseNegativeSignal; + static const simsignal_t createResponsePositiveSignal; + + protected: + Flow* flowObject; + bool degenerateDataTransfer; + public: FAIBase(); virtual ~FAIBase(); + virtual std::string str() const = 0; + virtual bool receiveAllocateRequest() = 0; virtual bool receiveAllocateResponsePositive() = 0; virtual void receiveAllocateResponseNegative() = 0; @@ -46,8 +65,8 @@ class FAIBase : public cSimpleModule { virtual void receiveCreateFlowResponsePositiveFromNminusOne() = 0; virtual void receiveCreateFlowResponseNegativeFromNminusOne() = 0; - Flow* getFlow() { - return FlowObject; + Flow* getFlow() const { + return flowObject; } bool isDegenerateDataTransfer() const { @@ -59,14 +78,9 @@ class FAIBase : public cSimpleModule { } protected: - Flow* FlowObject; - bool degenerateDataTransfer; - //SimpleModule overloads virtual void initialize() = 0; virtual void handleMessage(cMessage *msg) = 0; - - }; #endif /* FAIBASE_H_ */ diff --git a/src/DIF/FA/FAIListeners.cc b/src/DIF/FA/FAIListeners.cc index 3d971e20..bf79ac4d 100644 --- a/src/DIF/FA/FAIListeners.cc +++ b/src/DIF/FA/FAIListeners.cc @@ -20,18 +20,14 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#include "DIF/FA/FAI.h" #include "DIF/FA/FAIListeners.h" +#include "Common/Flow.h" +#include "DIF/FA/FABase.h" +#include "DIF/FA/FAI.h" -FAIListeners::FAIListeners(FAI* nfai) { - this->fai = nfai; - -} - -FAIListeners::~FAIListeners() { - +FAIListeners::FAIListeners(FAI* nfai) : fai(nfai) {} -} +FAIListeners::~FAIListeners() {} void LisFAIAllocResPosi::receiveSignal(cComponent* src, simsignal_t id, cObject* obj, cObject *detail) { @@ -45,25 +41,10 @@ void LisFAIAllocResNega::receiveSignal(cComponent* src, simsignal_t id, cObject* obj, cObject *detail) { EV << "AllocateResponseNegative initiated by " << src->getFullPath() << " and processed by " << fai->getFullPath() << endl; Flow* fl = dynamic_cast(obj); - //EV << "Emitted" << endl << fl->info() << endl << endl << "Recv" << fai->getFlow()->info() << endl; if (fai->getFlow() == fl) fai->receiveAllocateResponseNegative(); } -void LisFAIAllocReq::receiveSignal(cComponent* src, simsignal_t id, - cObject* obj, cObject *detail) { - EV << "AllocateRequest initiated by " << src->getFullPath() << " and processed by " << fai->getFullPath() << endl; - Flow* fl = dynamic_cast(obj); - if ( fai->getFlow()->compare(*fl) ) - fai->receiveAllocateRequest(); -} -/* -void LisFAICreReq::receiveSignal(cComponent* src, simsignal_t id, - cObject* obj) { - EV << "CreateRequest initiated by " << src->getFullPath() << " and processed by " << fai->getFullPath() << endl; - fai->receiveCreateRequest(); -} -*/ void LisFAICreResPosi::receiveSignal(cComponent* src, simsignal_t id, cObject* obj, cObject *detail) { EV << "CreateResponsePositive initiated by " << src->getFullPath() @@ -78,8 +59,6 @@ void LisFAICreResPosi::receiveSignal(cComponent* src, simsignal_t id, //EV << "A!!!!!!!!!!!!!!IN" << endl; fai->receiveCreateResponsePositive(flow); } - - } else EV << "FAIListener received unknown object!" << endl; @@ -119,14 +98,6 @@ void LisFAIDelReq::receiveSignal(cComponent* src, simsignal_t id, cObject* obj, cObject *detail) { EV << "DeleteRequest initiated by " << src->getFullPath() << " and processed by " << fai->getFullPath() << endl; Flow* fl = dynamic_cast(obj); -// EV << fl->info() << endl << "=================="<< endl << fai->getFlow()->info(); -// EV << "srcAPNI = " << (fai->getFlow()->getSrcApni() == fl->getSrcApni()) << endl -// << "dstAPNI = " << (fai->getFlow()->getDstApni() == fl->getDstApni()) << endl -// << "srcPortId = " << (fai->getFlow()->getSrcPortId() == fl->getSrcPortId()) << endl -// << "dstPortId = " << (fai->getFlow()->getDstPortId() == fl->getDstPortId()) << endl -// << "srcAddr = " << (fai->getFlow()->getSrcAddr() == fl->getSrcAddr()) << endl -// << "dstAddr = " << (fai->getFlow()->getDstAddr() == fl->getDstAddr()) << endl; -// EV << "Vysledek> " << (fai->getFlow() == fl) << endl; if ( fai->getFlow()->compare(*fl) ) fai->receiveDeleteRequest(fl); } @@ -138,12 +109,10 @@ void LisFAICreResPosiNminusOne::receiveSignal(cComponent* src, simsignal_t id, Flow* flow = dynamic_cast(obj); if (flow) { - //EV << "!!!!!!!!!Cube " << flow->getConId().getQoSId() << endl; if (fai->getFa()->getMyAddress().getApn() == flow->getSrcApni().getApn() && fai->getFlow()->getConId().getQoSId() == flow->getConId().getQoSId() && !flow->isManagementFlow() ) { - //EV << "B!!!!!!!!!!!!!!IN" << endl; fai->receiveCreateFlowResponsePositiveFromNminusOne(); } diff --git a/src/DIF/FA/FAIListeners.h b/src/DIF/FA/FAIListeners.h index dab2ce62..7d31419d 100644 --- a/src/DIF/FA/FAIListeners.h +++ b/src/DIF/FA/FAIListeners.h @@ -23,7 +23,7 @@ #ifndef FAILISTENERS_H_ #define FAILISTENERS_H_ -#include "DIF/FA/FAI.h" +#include class FAI; class FAIListeners : public cListener { @@ -53,21 +53,6 @@ class LisFAIAllocResNega : public FAIListeners void virtual receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject *detail); }; -class LisFAIAllocReq : public FAIListeners -{ - public: - LisFAIAllocReq(FAI* nfai) : FAIListeners(nfai){}; - using FAIListeners::receiveSignal; - void virtual receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject *detail); -}; -/* -class LisFAICreReq : public FAIListeners -{ - public: - LisFAICreReq(FAI* nfai) : FAIListeners(nfai){}; - void virtual receiveSignal(cComponent *src, simsignal_t id, cObject *obj); -}; -*/ class LisFAICreResPosi : public FAIListeners { public: diff --git a/src/DIF/FA/FAListeners.cc b/src/DIF/FA/FAListeners.cc deleted file mode 100644 index db649587..00000000 --- a/src/DIF/FA/FAListeners.cc +++ /dev/null @@ -1,128 +0,0 @@ -// The MIT License (MIT) -// -// Copyright (c) 2014-2016 Brno University of Technology, PRISTINE project -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -#include "DIF/FA/FAListeners.h" - -void LisFAAllocReq::receiveSignal(cComponent* src, simsignal_t id, cObject* obj, cObject *detail) { - EV << "AllocateRequest initiated by " << src->getFullPath() - << " and processed by " << fa->getFullPath() << endl; - Flow* flow = dynamic_cast(obj); - if (flow) { - fa->receiveAllocateRequest(flow); - } - else - EV << "FAListener received not a flow object!" << endl; -} - -void LisFADeallocReq::receiveSignal(cComponent* src, simsignal_t id, - cObject* obj, cObject *detail) { - EV << "DeallocateRequest initiated by " << src->getFullPath() - << " and processed by " << fa->getFullPath() << endl; - Flow* flow = dynamic_cast(obj); - if (flow) { - fa->receiveDeallocateRequest(flow); - } - else - EV << "FAListener received not a flow object!" << endl; -} - -/** - * - * @param src - * @param id - * @param obj - */ -void LisFACreReq::receiveSignal(cComponent* src, simsignal_t id, cObject* obj, cObject *detail) { - EV << "CreateRequest initiated by " << src->getFullPath() << " and processed by " << fa->getFullPath() << endl; - Flow* flow = dynamic_cast(obj); - if (flow) - fa->receiveCreateFlowRequestFromRibd(flow); - else - EV << "Received not a flow object!" << endl; - return; -} - - -void LisFACreFloPosi::receiveSignal(cComponent* src, simsignal_t id, - cObject* obj, cObject *detail) { - EV << "NM1FlowCreated initiated by " << src->getFullPath() << " and processed by " << fa->getFullPath() << endl; - Flow* flow = dynamic_cast(obj); - if (flow - && fa->getMyAddress().getApn() == flow->getSrcApni().getApn() - && !flow->isManagementFlowLocalToIPCP() ) - { - //EV << "-----\n" << flow->info() << endl; - TFAIPtrs entries = fa->getNFlowTable()->findEntriesByDstNeighborAndFwd(flow->getDstApni().getApn()); - for (TFTPtrsIter it = entries.begin(); it != entries.end(); ++it) { - fa->receiveNM1FlowCreated( (*it)->getFlow() ); - } - } - else { - if (!flow) { EV << "Received not a flow object!" << endl; } - else if (!flow->getConId().getQoSId().compare(VAL_MGMTQOSID)) { EV << "Management flow allocated!" << endl; } - else { EV << "Flow not intended for my FA!" << endl; } - } -} - -void LisFAAllocFinMgmt::receiveSignal(cComponent* src, simsignal_t id, - cObject* obj, cObject *detail) { - EV << "AllocFinMgmt initiated by " << src->getFullPath() << " and processed by " << fa->getFullPath() << endl; - - /* - Flow* flow = dynamic_cast(obj); - EV << flow->info() << endl; - if (flow - && fa->getMyAddress().getApname() == flow->getSrcApni().getApn() - && flow->isManagementFlow()) - { - //Notify pending flows that mgmt flow is prepared - TFAIPtrs entries = fa->getNFlowTable()->findEntriesAffectedByMgmt(flow); - for (TFTPtrsIter it = entries.begin(); it != entries.end(); ++it) { - fa->PendingFlows.push_back((*it)->getFlow()); - } - fa->receiveMgmtAllocateFinish(); - } - else { - if (!flow) { EV << "Received not a flow object!" << endl; } - else if (!flow->getConId().getQoSId().compare(VAL_MGMTQOSID)) { EV << "Management flow allocated!" << endl; } - else { EV << "Flow not intended for my FA!" << endl; } - } - */ - APNIPair* apnip = dynamic_cast(obj); - //EV << "!!!!!" << apnip->info() << endl; - if (apnip && fa->getMyAddress().getApn() == apnip->first.getApn()) { - //EV << "!!!!!Uvnitr" << endl; - //Notify pending flows that mgmt flow is prepared - TFAIPtrs entries = fa->getNFlowTable()->findEntriesAffectedByMgmt(apnip); - for (TFTPtrsIter it = entries.begin(); it != entries.end(); ++it) { - fa->PendingFlows.push_back((*it)->getFlow()); - } - //EV << "!!!!!Venku" << endl; - fa->receiveMgmtAllocateFinish(); - } - else { - EV << "FA received unknown object!" << endl; - } - - - -} diff --git a/src/DIF/FA/FAListeners.h b/src/DIF/FA/FAListeners.h deleted file mode 100644 index b4dab381..00000000 --- a/src/DIF/FA/FAListeners.h +++ /dev/null @@ -1,98 +0,0 @@ -// The MIT License (MIT) -// -// Copyright (c) 2014-2016 Brno University of Technology, PRISTINE project -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -#ifndef FALISTENERS_H_ -#define FALISTENERS_H_ - -#include -#include "DIF/FA/FABase.h" - -class FAListeners : public cListener { - protected: - FABase* fa; - public: - FAListeners(FABase* sfa){ - fa = sfa; - }; - virtual ~FAListeners(){}; - - virtual void receiveSignal(cComponent *src, simsignal_t id, bool b, cObject *detail) { - EV << "Signal to FA initiated by " << src->getFullPath() << endl; - } - -}; - -class LisFAAllocReq : public FAListeners -{ - public: - LisFAAllocReq(FABase* sfa) : FAListeners(sfa){}; - using FAListeners::receiveSignal; - void virtual receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject *detail); -}; - -class LisFAAllocFinMgmt : public FAListeners -{ - public: - LisFAAllocFinMgmt(FABase* sfa) : FAListeners(sfa){}; - using FAListeners::receiveSignal; - void virtual receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject *detail); -}; - - -class LisFACreFloPosi : public FAListeners -{ - public: - LisFACreFloPosi(FABase* sfa) : FAListeners(sfa){}; - using FAListeners::receiveSignal; - void virtual receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject *detail); -}; - -class LisFADeallocReq : public FAListeners -{ - public: - LisFADeallocReq(FABase* sfa) : FAListeners(sfa){}; - using FAListeners::receiveSignal; - void virtual receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject *detail); -}; - -class LisFACreReq : public FAListeners -{ - public: - LisFACreReq(FABase* sfa) : FAListeners(sfa){}; - using FAListeners::receiveSignal; - void virtual receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject *detail); -}; -/* -class LisFACreRes : public FAListeners -{ - public: - LisFACreRes(FABase* sfa) : FAListeners(sfa){}; - void virtual receiveSignal(cComponent *src, simsignal_t id, cObject *obj); -}; -*/ -class LisFADelRes : public FAListeners -{ - public: - LisFADelRes(FABase* sfa) : FAListeners(sfa){}; -}; - -#endif /* FALISTENERS_H_ */ diff --git a/src/DIF/FA/FANotifier.cc b/src/DIF/FA/FANotifier.cc index c656656e..5fe3fc07 100644 --- a/src/DIF/FA/FANotifier.cc +++ b/src/DIF/FA/FANotifier.cc @@ -3,17 +3,19 @@ // 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/. -// +// #include "DIF/FA/FANotifier.h" +#include "DIF/FA/FABase.h" +#include "DIF/RIB/RIBdBase.h" const char* MSG_FLO = "Flow"; const char* MSG_FLOPOSI = "Flow+"; diff --git a/src/DIF/FA/FANotifierBase.cc b/src/DIF/FA/FANotifierBase.cc index b3789d67..d05511b3 100644 --- a/src/DIF/FA/FANotifierBase.cc +++ b/src/DIF/FA/FANotifierBase.cc @@ -3,18 +3,21 @@ // 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/. -// +// #include "DIF/FA/FANotifierBase.h" +const simsignal_t FANotifierBase::allocateResponsePositiveSignal = registerSignal(SIG_AERIBD_AllocateResponsePositive); +const simsignal_t FANotifierBase::allocateResponseNegativeSignal = registerSignal(SIG_AERIBD_AllocateResponseNegative); + const Address& FANotifierBase::getMyAddress() const { return MyAddress; } diff --git a/src/DIF/FA/FANotifierBase.h b/src/DIF/FA/FANotifierBase.h index 3385ba8e..1de913d5 100644 --- a/src/DIF/FA/FANotifierBase.h +++ b/src/DIF/FA/FANotifierBase.h @@ -28,6 +28,9 @@ class FANotifierBase : public cSimpleModule, public CDAPProcessingBase { public: + static const simsignal_t allocateResponsePositiveSignal; + static const simsignal_t allocateResponseNegativeSignal; + virtual void sendCreateRequestFlow(Flow* flow) = 0; virtual void sendCreateResponseNegative(Flow* flow) = 0; virtual void sendCreateResponsePostive(Flow* flow) = 0; diff --git a/src/DIF/FA/FANotifierListeners.cc b/src/DIF/FA/FANotifierListeners.cc index 09f634ca..42a7eb4f 100644 --- a/src/DIF/FA/FANotifierListeners.cc +++ b/src/DIF/FA/FANotifierListeners.cc @@ -3,25 +3,19 @@ // 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/. -// +// #include "DIF/FA/FANotifierListeners.h" -FANotifierListeners::FANotifierListeners(FANotifierBase* nfanb) : fanb(nfanb) -{ -} - -FANotifierListeners::~FANotifierListeners() { - fanb = NULL; -} +#include "DIF/FA/FANotifierBase.h" void LisRIBDCreReq::receiveSignal(cComponent* src, simsignal_t id, cObject* obj, cObject *detail) { EV << "CreateRequest initiated by " << src->getFullPath() @@ -117,4 +111,3 @@ void LisRIBDCreFloPosi::receiveSignal(cComponent* src, simsignal_t id, EV << "RIBdListener received unknown object!" << endl; } - diff --git a/src/DIF/FA/FANotifierListeners.h b/src/DIF/FA/FANotifierListeners.h index 03253fe2..97726f3c 100644 --- a/src/DIF/FA/FANotifierListeners.h +++ b/src/DIF/FA/FANotifierListeners.h @@ -3,82 +3,86 @@ // 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/. -// +// #ifndef FANOTIFIERLISTENERS_H_ #define FANOTIFIERLISTENERS_H_ //Standard libraries #include -//RINASim libraries -#include "DIF/FA/FANotifierBase.h" +class FANotifierBase; class FANotifierListeners : public cListener { public: - FANotifierListeners(FANotifierBase* nfanb); - virtual ~FANotifierListeners(); - virtual void receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject *detail) { - EV << "Signal to FANotifierBase initiated by " << src->getFullPath() << endl; - } + FANotifierListeners(FANotifierBase* fanb) : fanb(fanb) {} protected: FANotifierBase* fanb; + void receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject *detail) override = 0; }; class LisRIBDCreReq : public FANotifierListeners { public: LisRIBDCreReq(FANotifierBase* nfanb) : FANotifierListeners(nfanb){}; - void virtual receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject *detail); + protected: + void receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject *detail) override; }; class LisRIBDDelReq : public FANotifierListeners { public: LisRIBDDelReq(FANotifierBase* nfanb) : FANotifierListeners(nfanb){}; - void virtual receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject *detail); + protected: + void receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject *detail) override; }; class LisRIBDDelRes : public FANotifierListeners { public: LisRIBDDelRes(FANotifierBase* nfanb) : FANotifierListeners(nfanb){}; - void virtual receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject *detail); + protected: + void receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject *detail) override; }; class LisRIBDAllReqFromFai : public FANotifierListeners { public: LisRIBDAllReqFromFai(FANotifierBase* nfanb) : FANotifierListeners(nfanb) {}; - void virtual receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject *detail); + protected: + void receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject *detail) override; }; class LisRIBDCreResNega: public FANotifierListeners { public: LisRIBDCreResNega(FANotifierBase* nfanb) : FANotifierListeners(nfanb) {}; - void virtual receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject *detail); + protected: + void receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject *detail) override; }; class LisRIBDCreResPosi: public FANotifierListeners { public: LisRIBDCreResPosi(FANotifierBase* nfanb) : FANotifierListeners(nfanb) {}; - void virtual receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject *detail); + protected: + void receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject *detail) override; }; class LisRIBDCreFloNega: public FANotifierListeners { public: LisRIBDCreFloNega(FANotifierBase* nfanb) : FANotifierListeners(nfanb) {}; - void virtual receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject *detail); + protected: + void receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject *detail) override; }; class LisRIBDCreFloPosi: public FANotifierListeners { public: LisRIBDCreFloPosi(FANotifierBase* nfanb) : FANotifierListeners(nfanb) {}; - void virtual receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject *detail); + protected: + void receiveSignal(cComponent *src, simsignal_t id, cObject *obj, cObject *detail) override; }; diff --git a/src/DIF/FA/NFlowTable.cc b/src/DIF/FA/NFlowTable.cc index 70844675..b661ab88 100644 --- a/src/DIF/FA/NFlowTable.cc +++ b/src/DIF/FA/NFlowTable.cc @@ -22,228 +22,237 @@ #include "DIF/FA/NFlowTable.h" -//Statistic collextion -const char* SIG_STAT_FT_SIZE = "FT_FlowTableSize"; +#include "Common/APN.h" +#include "Common/Flow.h" +#include "Common/Utils.h" + +// Statistic collextion +const char *SIG_STAT_FT_SIZE = "FT_FlowTableSize"; Define_Module(NFlowTable); +NFlowTable::~NFlowTable() { + for (auto &elem : NFlowTab) + delete elem.getFlow(); +} + void NFlowTable::initialize() { - //Inits + // Inits initSignalsAndListeners(); - //Watchers + // Watchers WATCH_LIST(NFlowTab); } -std::string NFlowTable::info() const { +std::string NFlowTable::str() const +{ std::ostringstream os; os << "id=" << this->getId() << endl; - /* - for(TFTConstIter it = FaiTable.begin(); it != FaiTable.end(); ++it ) - { - FAITableEntry tft = *it; - os << tft << endl; - } - */ return os.str(); } -NFlowTableEntry* NFlowTable::findEntryByDstAddressAndFwd(const APN& apname) { - for(TFTIter it = NFlowTab.begin(); it != NFlowTab.end(); ++it) { - NFlowTableEntry tft = *it; - if (tft.getCFlow()->getDstAddr().getApn() == apname - && tft.getAllocateStatus() == NFlowTableEntry::FORWARDED) - return &(*it); - } - return NULL; -} - -NFlowTableEntry* NFlowTable::findEntryBySrcAddressAndFwd(const APN& apname) { - //EV << "Look APN> " << ipcAddr << endl; - for(TFTIter it = NFlowTab.begin(); it != NFlowTab.end(); ++it) { - NFlowTableEntry tft = *it; - //EV << "XXXX " << tft.getCFlow()->getSrcAddr().getIpcAddress() << endl - // << "YYYY " << (tft.getAllocateStatus() == FAITableEntry::FORWARDED) << endl; - if (tft.getCFlow()->getSrcAddr().getIpcAddress() == apname - && tft.getAllocateStatus() == NFlowTableEntry::FORWARDED) - return &(*it); +NFlowTableEntry *NFlowTable::findEntryByDstAddressAndFwd(const APN &apname) +{ + for (auto &tft : NFlowTab) { + if (tft.getCFlow()->getDstAddr().getApn() == apname && + tft.getAllocateStatus() == NFlowTableEntry::FORWARDED) { + return &tft; + } } - return NULL; - + return nullptr; } -NFlowTableEntry* NFlowTable::findEntryByApns(const APN& srcApn, const APN& dstApn) { - for(TFTIter it = NFlowTab.begin(); it != NFlowTab.end(); ++it) { - NFlowTableEntry tft = *it; - if (tft.getCFlow()->getSrcApni().getApn() == srcApn - && tft.getCFlow()->getDstApni().getApn() == dstApn - && tft.getAllocateStatus() == NFlowTableEntry::FORWARDED) - return &(*it); +NFlowTableEntry *NFlowTable::findEntryBySrcAddressAndFwd(const APN &apname) +{ + for (auto &tft : NFlowTab) { + if (tft.getCFlow()->getSrcAddr().getIpcAddress() == apname && + tft.getAllocateStatus() == NFlowTableEntry::FORWARDED) + return &tft; } - return NULL; + return nullptr; } -TFAIPtrs NFlowTable::findEntriesByDstNeighborAndFwd(const APN& apname) { - TFAIPtrs list; - for(TFTIter it = NFlowTab.begin(); it != NFlowTab.end(); ++it) { - NFlowTableEntry tft = *it; - if (tft.getCFlow()->getDstNeighbor().getApn() == apname - && tft.getAllocateStatus() == NFlowTableEntry::FORWARDING) - list.push_back(&(*it)); +NFlowTableEntry *NFlowTable::findEntryByApns(const APN &srcApn, const APN &dstApn) +{ + for (auto &tft : NFlowTab) { + if (tft.getCFlow()->getSrcApni().getApn() == srcApn && + tft.getCFlow()->getDstApni().getApn() == dstApn && + tft.getAllocateStatus() == NFlowTableEntry::FORWARDED) + return &tft; } - return list; + return nullptr; } -NFlowTableEntry* NFlowTable::findEntryByInvokeId(long invId) { - if (!invId) return NULL; - for(TFTIter it = NFlowTab.begin(); it != NFlowTab.end(); ++it) { - NFlowTableEntry tft = *it; - if (tft.getCFlow()->getAllocInvokeId() == invId) - return &(*it); +TFAIPtrs NFlowTable::findEntriesByDstNeighborAndFwd(const APN &apname) +{ + TFAIPtrs list; + for (auto &tft : NFlowTab) { + if (tft.getCFlow()->getDstNeighbor().getApn() == apname && + tft.getAllocateStatus() == NFlowTableEntry::FORWARDING) { + list.push_back(&tft); + } } - return NULL; + return list; } -/* -TFAIPtrs NFlowTable::findEntriesAffectedByMgmt(const Flow* flow) { - TFAIPtrs list; - for(TFTIter it = FaiTable.begin(); it != FaiTable.end(); ++it) { - NFlowTableEntry tft = *it; - if (tft.getCFlow()->getSrcNeighbor().getApname() == flow->getSrcApni().getApn() - && tft.getCFlow()->getDstNeighbor().getApname() == flow->getDstApni().getApn() - && tft.getAllocateStatus() == NFlowTableEntry::ALLOC_PEND) - list.push_back(&(*it)); +NFlowTableEntry *NFlowTable::findEntryByInvokeId(long invId) +{ + if (!invId) + return nullptr; + for (auto &tft : NFlowTab) { + if (tft.getCFlow()->getAllocInvokeId() == invId) { + return &tft; + } } - return list; + return nullptr; } -*/ -//XXX: Vesely - This search does not yield exact intended match! -NFlowTableEntry* NFlowTable::findMgmtEntryByDstNeighbor(const Address& addr) { - for(TFTIter it = NFlowTab.begin(); it != NFlowTab.end(); ++it) { - NFlowTableEntry tft = *it; - if (tft.getCFlow()->getDstNeighbor() == addr - && tft.getCFlow()->isManagementFlowLocalToIPCP()) - return &(*it); +// XXX: Vesely - This search does not yield exact intended match! +NFlowTableEntry *NFlowTable::findMgmtEntryByDstNeighbor(const Address &addr) +{ + for (auto &tft : NFlowTab) { + if (tft.getCFlow()->getDstNeighbor() == addr && + tft.getCFlow()->isManagementFlowLocalToIPCP()) { + return &tft; + } } - return NULL; + return nullptr; } void NFlowTable::handleMessage(cMessage *msg) { + delete msg; + throw cRuntimeError("This module is not supposed to handle messages"); } -void NFlowTable::insertNew(Flow* flow) { +void NFlowTable::insertNew(Flow *flow) +{ this->insert(NFlowTableEntry(flow)); updateDisplayString(); - //EV << "FT emits signal " << (long)FaiTable.size() << endl; + // EV << "FT emits signal " << (long)FaiTable.size() << endl; emit(sigStatFTSize, (long)NFlowTab.size()); } -void NFlowTable::insert(const NFlowTableEntry& entry) { +void NFlowTable::insert(const NFlowTableEntry &entry) +{ Enter_Method("insertFlow()"); NFlowTab.push_back(entry); } -void NFlowTable::removeByFlow(Flow* flow) { +void NFlowTable::removeByFlow(Flow *flow) +{ Enter_Method("removeFlow()"); - NFlowTableEntry* entry = findEntryByFlow(flow); + NFlowTableEntry *entry = findEntryByFlow(flow); if (entry) NFlowTab.remove(*entry); } -NFlowTableEntry* NFlowTable::findEntryByFlow(const Flow* flow) { - for(TFTIter it = NFlowTab.begin(); it != NFlowTab.end(); ++it) { - NFlowTableEntry tft = *it; - if (*(tft.getCFlow()) == *flow) - return &(*it); +NFlowTableEntry *NFlowTable::findEntryByFlow(const Flow *flow) +{ + for (auto &tft : NFlowTab) { + if (tft.getCFlow() == flow) + return &tft; } - return NULL; + return nullptr; } -NFlowTableEntry* NFlowTable::findEntryByFai(FAIBase* fai) { - for(TFTIter it = NFlowTab.begin(); it != NFlowTab.end(); ++it) { - NFlowTableEntry tft = *it; +NFlowTableEntry *NFlowTable::findEntryByFai(FAIBase *fai) +{ + for (auto &tft : NFlowTab) { if (tft.getFai() == fai) - return &(*it); + return &tft; + } + return nullptr; +} + +NFlowTableEntry *NFlowTable::findEntryByApnisAndQosId(const APN &srcApn, + const APN &dstApn, + const std::string &qosId) +{ + for (auto &tft : NFlowTab) { + if (tft.getCFlow()->getSrcApni().getApn() == srcApn && + tft.getCFlow()->getDstApni().getApn() == dstApn && + tft.getCFlow()->getConId().getQoSId() == qosId) { + return &tft; + } } - return NULL; + return nullptr; } -void NFlowTable::changeAllocStatus(Flow* flow, NFlowTableEntry::EAllocateStatus status) { - NFlowTableEntry* fte = findEntryByFlow(flow); +void NFlowTable::changeAllocStatus(Flow *flow, NFlowTableEntry::EAllocateStatus status) +{ + NFlowTableEntry *fte = findEntryByFlow(flow); if (fte) { fte->setAllocateStatus(status); - } - else + } else { EV << "findByFlow() returned NULL" << endl; + } } -void NFlowTable::changeAllocStatus(FAIBase* fai, NFlowTableEntry::EAllocateStatus status) { - NFlowTableEntry* fte = findEntryByFai(fai); +void NFlowTable::changeAllocStatus(FAIBase *fai, NFlowTableEntry::EAllocateStatus status) +{ + // TODO please return false on failure + NFlowTableEntry *fte = findEntryByFai(fai); if (fte) fte->setAllocateStatus(status); else EV << "findByFai() returned NULL" << endl; } -void NFlowTable::setFaiToFlow(FAIBase* fai, Flow* flow) { - NFlowTableEntry* fte = findEntryByFlow(flow); +void NFlowTable::setFaiToFlow(FAIBase *fai, Flow *flow) +{ + NFlowTableEntry *fte = findEntryByFlow(flow); fte->setFai(fai); } -void NFlowTable::updateDisplayString() { +void NFlowTable::updateDisplayString() +{ // display number of flows std::ostringstream os; os << "records: " << getSize(); setPolicyDisplayString(this, os.str().c_str()); } -void NFlowTable::initSignalsAndListeners() { +void NFlowTable::initSignalsAndListeners() +{ sigStatFTSize = registerSignal(SIG_STAT_FT_SIZE); } -NFlowTableEntry* NFlowTable::findMgmtEntry(const Flow* flow) { - for(TFTIter it = NFlowTab.begin(); it != NFlowTab.end(); ++it) { - NFlowTableEntry tft = *it; - if (tft.getCFlow()->isManagementFlowLocalToIPCP()) - return &(*it); - } - return NULL; -} - -NFlowTableEntry* NFlowTable::findMgmtEntryByDstAddr(const Address& addr) { - for(TFTIter it = NFlowTab.begin(); it != NFlowTab.end(); ++it) { - NFlowTableEntry tft = *it; - if (tft.getCFlow()->getDstAddr() == addr - && tft.getCFlow()->isManagementFlowLocalToIPCP()) - return &(*it); +NFlowTableEntry *NFlowTable::findMgmtEntryByDstAddr(const Address &addr) +{ + for (auto &tft : NFlowTab) { + if (tft.getCFlow()->getDstAddr() == addr && tft.getCFlow()->isManagementFlowLocalToIPCP()) + return &tft; } - return NULL; + return nullptr; } -NFlowTableEntry* NFlowTable::findMgmtEntryByDstApni(const APN& dstApn) { - for(TFTIter it = NFlowTab.begin(); it != NFlowTab.end(); ++it) { - NFlowTableEntry tft = *it; - if (tft.getCFlow()->getDstApni().getApn() == dstApn - && tft.getCFlow()->isManagementFlowLocalToIPCP()) - return &(*it); +NFlowTableEntry *NFlowTable::findMgmtEntryByDstApni(const APN &dstApn) +{ + for (auto &tft : NFlowTab) { + if (tft.getCFlow()->getDstApni().getApn() == dstApn && + tft.getCFlow()->isManagementFlowLocalToIPCP()) { + return &tft; + } } - return NULL; + return nullptr; } -const unsigned int NFlowTable::getSize() const { +unsigned int NFlowTable::getSize() const +{ return NFlowTab.size(); } -TFAIPtrs NFlowTable::findEntriesAffectedByMgmt(const APNIPair* apnip) { +TFAIPtrs NFlowTable::findEntriesAffectedByMgmt(const APNIPair *apnip) +{ TFAIPtrs list; - for(TFTIter it = NFlowTab.begin(); it != NFlowTab.end(); ++it) { - NFlowTableEntry tft = *it; - if (tft.getCFlow()->getSrcAddr().getApn() == apnip->first.getApn() - && tft.getCFlow()->getDstNeighbor().getApn() == apnip->second.getApn() - && tft.getAllocateStatus() == NFlowTableEntry::ALLOC_PEND) - list.push_back(&(*it)); + for (auto &tft : NFlowTab) { + if (tft.getCFlow()->getDstNeighbor().getApn() == apnip->second.getApn()) { + if (tft.getAllocateStatus() == NFlowTableEntry::ALLOC_PEND || + tft.getAllocateStatus() == NFlowTableEntry::FORWARDING) { + list.push_back(&tft); + } + } } return list; } diff --git a/src/DIF/FA/NFlowTable.h b/src/DIF/FA/NFlowTable.h index a1a1d266..549eafe2 100644 --- a/src/DIF/FA/NFlowTable.h +++ b/src/DIF/FA/NFlowTable.h @@ -26,7 +26,6 @@ //Standard libraries #include //RINASim library -#include "Common/Utils.h" #include "DIF/FA/NFlowTableEntry.h" typedef std::list TFAITable; @@ -38,17 +37,21 @@ typedef TFAIPtrs::iterator TFTPtrsIter; //Statistic collextion extern const char* SIG_STAT_FT_SIZE; +class APN; +class Address; +class APNIPair; + class NFlowTable : public cSimpleModule { public: - std::string info() const; + ~NFlowTable() override; + virtual std::string str() const; void insertNew(Flow* flow); void insert(const NFlowTableEntry& entry); void removeByFlow(Flow* flow); - unsigned const int getSize() const; + unsigned int getSize() const; NFlowTableEntry* findEntryByFlow(const Flow* flow); NFlowTableEntry* findEntryByApns(const APN& srcApn, const APN& dstApn); - NFlowTableEntry* findMgmtEntry(const Flow* flow); NFlowTableEntry* findMgmtEntryByDstAddr(const Address& addr); NFlowTableEntry* findMgmtEntryByDstNeighbor(const Address& addr); NFlowTableEntry* findMgmtEntryByDstApni(const APN& dstApn); @@ -58,6 +61,7 @@ class NFlowTable : public cSimpleModule NFlowTableEntry* findEntryBySrcAddressAndFwd(const APN& apname); NFlowTableEntry* findEntryByFai(FAIBase* fai); NFlowTableEntry* findEntryByInvokeId(long invId); + NFlowTableEntry* findEntryByApnisAndQosId(const APN &srcApn, const APN &dstApn, const std::string &qosId); void setFaiToFlow(FAIBase* fai, Flow* flow); void changeAllocStatus(Flow* flow, NFlowTableEntry::EAllocateStatus status); void changeAllocStatus(FAIBase* fai, NFlowTableEntry::EAllocateStatus status); @@ -75,11 +79,4 @@ class NFlowTable : public cSimpleModule TFAITable NFlowTab; }; -//Free functions -/* -std::ostream& operator<< (std::ostream& os, const FlowTable& ft); -std::ostream& operator<< (std::ostream& os, const TFlowTable& ft); -std::ostream& operator<< (std::ostream& os, const TFlowTableEntry& fte); -*/ - #endif diff --git a/src/DIF/FA/NFlowTableEntry.cc b/src/DIF/FA/NFlowTableEntry.cc index 76515cfe..2e0bcf05 100644 --- a/src/DIF/FA/NFlowTableEntry.cc +++ b/src/DIF/FA/NFlowTableEntry.cc @@ -22,28 +22,25 @@ #include "DIF/FA/NFlowTableEntry.h" +//RINASim libraries +#include "DIF/FA/FAIBase.h" +#include "Common/Flow.h" + + NFlowTableEntry::NFlowTableEntry() : - fai(NULL), flow(NULL), + fai(nullptr), flow(nullptr), allocStatus(this->UNKNOWN), timeCreated(0), timeDeleted(0) { } -NFlowTableEntry::NFlowTableEntry(Flow* nflow): fai(NULL), allocStatus(this->UNKNOWN) { +NFlowTableEntry::NFlowTableEntry(Flow* nflow): fai(nullptr), allocStatus(this->UNKNOWN) { this->flow = nflow; this->timeCreated = simTime(); this->timeDeleted = 0; } -NFlowTableEntry::~NFlowTableEntry() { - this->fai = NULL; - this->flow = NULL; - allocStatus = this->UNKNOWN; - timeCreated = 0; - timeDeleted = 0; -} - -std::string NFlowTableEntry::info() const { +std::string NFlowTableEntry::str() const { std::ostringstream os; os << "STATUS: " << this->getAllocateStatusString() << endl; if ( this->getFai() ) @@ -60,7 +57,7 @@ std::string NFlowTableEntry::info() const { } std::ostream& operator <<(std::ostream& os, const NFlowTableEntry& fte) { - return os << fte.info(); + return os << fte.str(); } FAIBase* NFlowTableEntry::getFai() const { @@ -90,8 +87,6 @@ std::string NFlowTableEntry::getAllocateStatusString() const { case FORWARDED: return "allocation forwarded"; default: return "UNKNOWN"; } -// static std::string AllocateStatusStrings[] = {"Pending", "Allocation Positive", "Allocation Negative"}; -// return AllocateStatusStrings[]; } void NFlowTableEntry::setAllocateStatus(EAllocateStatus allocateStatus) { diff --git a/src/DIF/FA/NFlowTableEntry.h b/src/DIF/FA/NFlowTableEntry.h index ed4b74ce..e533d0c0 100644 --- a/src/DIF/FA/NFlowTableEntry.h +++ b/src/DIF/FA/NFlowTableEntry.h @@ -25,9 +25,9 @@ //Standard libraries #include -#include -//RINASim libraries -#include "DIF/FA/FAIBase.h" + +class FAIBase; +class Flow; class NFlowTableEntry { public: @@ -40,11 +40,10 @@ class NFlowTableEntry { NFlowTableEntry(); NFlowTableEntry(Flow* nflow); - virtual ~NFlowTableEntry(); bool operator== (const NFlowTableEntry& other) const; - std::string info() const; + std::string str() const; std::string getAllocateStatusString() const; FAIBase* getFai() const; diff --git a/src/DIF/RA/RA.cc b/src/DIF/RA/RA.cc index 87a6877b..3f395637 100644 --- a/src/DIF/RA/RA.cc +++ b/src/DIF/RA/RA.cc @@ -671,16 +671,14 @@ void RA::postNM1FlowAllocation(NM1FlowTableItem* ftItem) // mark this flow as connected and update info ftItem->setConnectionStatus(NM1FlowTableItem::CON_ESTABLISHED); RMTPort* port = ftItem->getRMTPort(); + Flow* flow = ftItem->getFlow(); port->setOutputReady(); port->setInputReady(); - port->setFlow(ftItem->getFlow()); + port->setFlow(flow); - // if this is a management flow, notify the Enrollment module - if (ftItem->getFlow()->isManagementFlow()) - { - APNIPair* apnip = new APNIPair(ftItem->getFlow()->getSrcApni(), ftItem->getFlow()->getDstApni()); - signalizeMgmtAllocToEnrollment(apnip); - } + // if not already enrolled, attempt to enroll + if (flow->isManagementFlow()) + enrollment->startCACE(APNIPair(flow->getSrcApni(), flow->getDstApni())); } void RA::removeNM1FlowBindings(NM1FlowTableItem* ftItem)