--- a/src/DAF/IRM/IRM.cc
+++ b/src/DAF/IRM/IRM.cc
@@ -58,19 +58,7 @@
//Signals that this module emits
sigIRMAllocReq = registerSignal(SIG_IRM_AllocateRequest);
sigIRMDeallocReq = registerSignal(SIG_IRM_DeallocateRequest);
- sigIRMAllocResPosi = registerSignal(SIG_IRM_AllocateResponsePositive);
- sigIRMAllocResNega = registerSignal(SIG_IRM_AllocateResponseNegative);
-
- //Signals that this module is processing
- // AllocationResponseNegative from FA
- lisAllocResNegaFa = new LisIRMAllocResNegaFa(this);
- catcher->subscribe(SIG_FA_AllocateResponseNegative, this->lisAllocResNegaFa);
- // AllocationResponseNegative from FAI
- lisAllocResNegaFai = new LisIRMAllocResNegaFai(this);
- catcher->subscribe(SIG_FAI_AllocateResponseNegative, this->lisAllocResNegaFai);
- // AllocationRequest from FAI
- this->lisAllocReqFai = new LisIRMAllocReqFai(this);
- catcher->subscribe(SIG_FAI_AllocateRequest, this->lisAllocReqFai);
+
// Allocate Request from App
this->lisAllocReq = new LisIRMAllocReq(this);
catcher->subscribe(SIG_AE_AllocateRequest, this->lisAllocReq);
@@ -80,23 +68,38 @@
}
bool IRM::createBindings(Flow* flow) {
+ Enter_Method("createBindings()");
EV << "Attempts to create bindings and bind registration of gates"<< endl;
//Retrieve IPC process with allocated flow and prepared bindings
- cModule* Ipc = ConTable->findEntryByFlow(flow)->getIpc();
+ ConnectionTableEntry* cte = ConTable->findEntryByFlow(flow);
+ //if (!cte) {
+ // EV << "======================" << endl << flow->info() << endl;
+ // return false;
+ //}
+ cModule* Ipc = cte->getIpc();
cModule* Ap = this->getParentModule();
- //Create connections
+ //Decide portId
+ int portId = flow->getSrcPortId();
+ /*
+ if ( DifAllocator->isAppLocal(flow->getDstApni().getApn()) )
+ portId = flow->getDstPortId();
+ else if ( DifAllocator->isAppLocal(flow->getSrcApni().getApn()) )
+ portId
+ else
+ throw("Binding to inconsistant PortId occured!");
+ */
// Retrieve IPC gates
std::ostringstream nam1;
- nam1 << GATE_NORTHIO << flow->getSrcPortId();
+ nam1 << GATE_NORTHIO_ << portId;
cGate* g1i = Ipc->gateHalf(nam1.str().c_str(), cGate::INPUT);
cGate* g1o = Ipc->gateHalf(nam1.str().c_str(), cGate::OUTPUT);
// Add AP gates
std::ostringstream nam2;
- nam2 << GATE_SOUTHIO << flow->getSrcPortId();
+ nam2 << GATE_SOUTHIO_ << portId;
Ap->addGate(nam2.str().c_str(), cGate::INOUT, false);
cGate* g2i = Ap->gateHalf(nam2.str().c_str(), cGate::INPUT);
cGate* g2o = Ap->gateHalf(nam2.str().c_str(), cGate::OUTPUT);
@@ -109,11 +112,11 @@
//TODO: Status check
// Connect gates together
- g1o->connectTo(g2o);
- g2o->connectTo(g3i);
-
- g3o->connectTo(g2i);
- g2i->connectTo(g1i);
+ g1o->connectTo(g2i);
+ g2i->connectTo(g3i);
+
+ g3o->connectTo(g2o);
+ g2o->connectTo(g1i);
//Set south-half of the routing in ConnectionTable
bool status = ConTable->setSouthGates(flow, g3i, g3o);
@@ -121,22 +124,63 @@
return status;
}
-void IRM::receiveAllocationRequest(cObject* obj) {
+bool IRM::receiveAllocationRequestFromAe(Flow* flow) {
Enter_Method("receiveAllocateRequest()");
EV << this->getFullPath() << " received Allocation Request" << endl;
- Flow* flow = dynamic_cast<Flow*>(obj);
+ //Command target FA to allocate flow
+ FABase* fab = ConTable->getFa(flow);
+ bool status = false;
+
+ if (fab) {
+ //signalizeAllocateRequest(fl);
+ status = fab->receiveAllocateRequest(flow);
+ //If AllocationRequest NOT ended by creating connections
+ if (!status)
+ EV << "Flow not allocated!\n" << flow << endl;
+ }
+ else
+ EV << "FA could not be found in ConnectionTable!" << endl;
+
+ return status;
+}
+
+bool IRM::receiveDeallocationRequestFromAe(Flow* flow) {
+ Enter_Method("receiveDeallocateRequest()");
+ EV << this->getFullPath() << " received DeallocationRequest" << endl;
+
+ //Command target FA to allocate flow
+ FABase* fab = ConTable->getFa(flow);
+ bool status = false;
+
+ if (fab) {
+ //signalizeDeallocateRequest(fl);
+ status = fab->receiveDeallocateRequest(flow);
+ }
+ else
+ EV << "FA could not be found in ConnectionTable!" << endl;
+
+ return status;
+}
+
+void IRM::signalizeAllocateRequest(Flow* flow) {
+ //EV << "!!!!VYemitovano" << endl;
+ //EV << "Emits AllocReq Flow = " << flow->getSrcApni() << "_" << flow->getDstApni() << endl;
+ emit(sigIRMAllocReq, flow);
+}
+
+void IRM::newFlow(Flow* flow) {
+ Enter_Method("newFlow()");
+ //Create a new record in ConnectionTable
+ ConTable->insertNew(flow);
//Ask DA which IPC to use to reach dst App
- DirectoryEntry* de = DifAllocator->resolveApn(flow->getDstApni().getApn());
-
- if (de == NULL) {
- EV << "DA does not know target application" << endl;
+ const Address* ad = DifAllocator->resolveApnToBestAddress(flow->getDstApni().getApn());
+ if (ad == NULL) {
+ EV << "DifAllocator returned NULL for resolving " << flow->getDstApni().getApn() << endl;
return;
}
-
- //TODO: Vesely - Now using first available APN to DIFMember mapping
- Address addr = de->getSupportedDifs().front();
+ Address addr = *ad;
//TODO: Vesely - New IPC must be enrolled or DIF created
if (!DifAllocator->isDifLocal(addr.getDifName())) {
@@ -149,63 +193,60 @@
//Store info into ConnectionTable
ConTable->setFa(flow, DifAllocator->findFaInsideIpc(targetIpc));
-
-
- //Command target FA to allocate flow
- bool status = ConTable->getFa(flow)->receiveAllocateRequest(flow);
-
- //If AllocationRequest ended by creating connections
- if (status)
- status = createBindings(flow);
- //Allocation either failed OR app not found
- else
- EV << "Flow not allocated!\n" << flow << endl;
-
- //TODO: Vesely - Change ConnectionTable status
-}
-
-void IRM::receiveDeallocationRequest(cObject* obj) {
- Enter_Method("receiveDeallocateRequest()");
- EV << this->getFullPath() << " received DeallocationRequest" << endl;
- Flow* fl = dynamic_cast<Flow*>(obj);
- signalizeDeallocateRequest(fl);
-}
-
-void IRM::receiveAllocationResponseNegativeAppNotFound(cObject* obj) {
- EV << this->getFullPath() << " received Negative Allocation Response App not found" << endl;
-}
-
-void IRM::receiveAllocationResponseNegative(cObject* obj) {
- //Flow* fl = dynamic_cast<Flow*>(obj);
- EV << this->getFullPath() << " received Negative Allocation Response" << endl;
-}
-
-void IRM::receiveAllocationRequestFromFAI(cObject* obj) {
- //EV << this->getFullPath() << " received AllocationRequest from FAI" << endl;
- Flow* fl = dynamic_cast<Flow*>(obj);
- //TODO: Vesely - Simulate AllocationResponses
- if (true) {
- this->signalizeAllocateResponsePositive(fl);
- }
- else {
- this->signalizeAllocateResponseNegative(fl);
- }
-}
-
-void IRM::signalizeAllocateRequest(Flow* flow) {
- //EV << "!!!!VYemitovano" << endl;
- //EV << "Emits AllocReq Flow = " << flow->getSrcApni() << "_" << flow->getDstApni() << endl;
- emit(sigIRMAllocReq, flow);
}
void IRM::signalizeDeallocateRequest(Flow* flow) {
emit(sigIRMDeallocReq, flow);
}
-void IRM::signalizeAllocateResponsePositive(Flow* flow) {
- emit(sigIRMAllocResPosi, flow);
-}
-
-void IRM::signalizeAllocateResponseNegative(Flow* flow) {
- emit(sigIRMAllocResNega, flow);
-}
+ConnectionTable* IRM::getConTable() const {
+ return ConTable;
+}
+
+bool IRM::receiveAllocationResponsePositiveFromIpc(Flow* flow) {
+ Enter_Method("allocationResponsePositive()");
+ bool status = createBindings(flow);
+ return status;
+}
+
+bool IRM::deleteBindings(Flow* flow) {
+ Enter_Method("deleteBindings()");
+ EV << "Attempts to delete bindings"<< endl;
+ //Retrieve IPC process with allocated flow and prepared bindings
+
+ ConnectionTableEntry* cte = ConTable->findEntryByFlow(flow);
+ cModule* Ipc = cte->getIpc();
+ cModule* Ap = this->getParentModule();
+
+ //Decide portId
+ int portId = flow->getSrcPortId();
+
+ // Retrieve IPC gates
+ std::ostringstream nam1;
+ nam1 << GATE_NORTHIO_ << portId;
+ cGate* g1i = Ipc->gateHalf(nam1.str().c_str(), cGate::INPUT);
+ cGate* g1o = Ipc->gateHalf(nam1.str().c_str(), cGate::OUTPUT);
+
+ // Add AP gates
+ std::ostringstream nam2;
+ nam2 << GATE_SOUTHIO_ << portId;
+ cGate* g2i = Ap->gateHalf(nam2.str().c_str(), cGate::INPUT);
+ cGate* g2o = Ap->gateHalf(nam2.str().c_str(), cGate::OUTPUT);
+
+ // Add IRM gates
+ cGate* g3i = this->gateHalf(nam2.str().c_str(), cGate::INPUT);
+ cGate* g3o = this->gateHalf(nam2.str().c_str(), cGate::OUTPUT);
+
+ // Connect gates together
+ g1o->disconnect();
+ g2i->disconnect();
+ g3i->disconnect();
+
+ g3o->disconnect();
+ g2o->disconnect();
+ g1i->disconnect();
+
+ return !g1o->isConnected() && !g1i->isConnected()
+ && !g2o->isConnected() && !g2i->isConnected()
+ && !g3o->isConnected() && !g3i->isConnected();
+}