Switch to side-by-side view

--- a/src/DIF/RIB/RIBd.cc
+++ b/src/DIF/RIB/RIBd.cc
@@ -24,6 +24,7 @@
 
 #include "RIBd.h"
 
+const char* MSG_CONGEST         = "Congestion";
 const char* MSG_FLO             = "Flow";
 const char* MSG_FLOPOSI         = "Flow+";
 const char* MSG_FLONEGA         = "Flow-";
@@ -45,8 +46,6 @@
     initCdapBindings();
     //Init MyAddress
     initMyAddress();
-
-    invokeIdCounter = 0;
 }
 
 void RIBd::handleMessage(cMessage *msg) {
@@ -137,8 +136,10 @@
     //Append destination address for RMT "routing"
     mcref->setDstAddr(flow->getDstNeighbor());
 
-    //TODO: Vesely - Work more on InvokeId
-    mcref->setInvokeID(invokeIdCounter++);
+    //Generate InvokeId
+    if (!flow->getAllocInvokeId())
+        flow->setAllocInvokeId(getNewInvokeId());
+    mcref->setInvokeID(flow->getAllocInvokeId());
 
     //Send it
     signalizeSendData(mcref);
@@ -181,8 +182,10 @@
     //Append destination address for RMT "routing"
     mdereqf->setDstAddr(flow->getDstAddr());
 
-    //TODO: Vesely - Work more on InvokeId
-    mdereqf->setInvokeID(invokeIdCounter++);
+    //Generate InvokeId
+    if (!flow->getDeallocInvokeId())
+        flow->setDeallocInvokeId(getNewInvokeId());
+    mdereqf->setInvokeID(flow->getDeallocInvokeId());
 
     //Send it
     signalizeSendData(mdereqf);
@@ -231,6 +234,10 @@
     else if (dynamic_cast<CDAP_M_Write*>(msg)) {
         processMWrite(msg);
     }
+    //M_START
+    else if (dynamic_cast<CDAP_M_Start*>(msg)) {
+        processMStart(msg);
+    }
 
     delete msg;
 }
@@ -251,6 +258,7 @@
     sigRIBDCreResFloPosi = registerSignal(SIG_RIBD_CreateFlowResponsePositive);
     sigRIBDCreResFloNega = registerSignal(SIG_RIBD_CreateFlowResponseNegative);
     sigRIBDFwdUpdateRecv = registerSignal(SIG_RIBD_ForwardingUpdateReceived);
+    sigRIBDCongNotif     = registerSignal(SIG_RIBD_CongestionNotification);
 
     //Signals that this module is processing
 
@@ -287,6 +295,10 @@
 
     lisRIBDFwdInfoUpdate = new LisRIBDFwdInfoUpdate(this);
     catcher2->subscribe(SIG_PDUFTG_FwdInfoUpdate, lisRIBDFwdInfoUpdate);
+
+    lisRIBDCongNotif = new LisRIBDCongesNotif(this);
+    catcher2->subscribe(SIG_RA_InvokeSlowdown, lisRIBDCongNotif);
+
 }
 
 void RIBd::receiveAllocationRequestFromFai(Flow* flow) {
@@ -348,7 +360,8 @@
     resultobj.resultValue = R_SUCCESS;
     mcref->setResult(resultobj);
 
-    //TODO: Vesely - Work more on InvokeId
+    //Generate InvokeId
+    mcref->setInvokeID(flow->getAllocInvokeId());
 
     //Append destination address for RMT "routing"
     mcref->setDstAddr(flow->getDstAddr());
@@ -360,6 +373,7 @@
 void RIBd::signalizeSendData(CDAPMessage* msg) {
     //Setup handle which is for RIBd always 0
     msg->setHandle(0);
+    msg->setBitLength(msg->getBitLength() + msg->getHeaderBitLength());
     //Pass message to CDAP
     EV << "Emits SendData signal for message " << msg->getName() << endl;
     emit(sigRIBDSendData, msg);
@@ -433,7 +447,8 @@
     resultobj.resultValue = R_SUCCESS;
     mderesf->setResult(resultobj);
 
-    //TODO: Vesely - Work more on InvokeId
+    //Generate InvokeId
+    mderesf->setInvokeID(flow->getDeallocInvokeId());
 
     //Append destination address for RMT "routing"
     mderesf->setDstAddr(flow->getDstAddr());
@@ -477,6 +492,33 @@
 
 }
 
+void RIBd::sendCongestionNotification(PDU* pdu) {
+    Enter_Method("sendCongestionNotification()");
+
+    //Prepare M_START ConDescr
+    CDAP_M_Start* mstarcon = new CDAP_M_Start(MSG_CONGEST);
+    CongestionDescriptor* conDesc = new CongestionDescriptor(pdu->getConnId().getDstCepId(), pdu->getConnId().getSrcCepId(), pdu->getConnId().getQoSId());
+    //Prepare object
+    std::ostringstream os;
+    os << conDesc->getCongesDescrName();
+    object_t condesobj;
+    condesobj.objectClass = conDesc->getClassName();
+    condesobj.objectName = os.str();
+    condesobj.objectVal = conDesc;
+    //TODO: Vesely - Assign appropriate values
+    condesobj.objectInstance = VAL_DEFINSTANCE;
+    mstarcon->setObject(condesobj);
+
+    //Generate InvokeId
+    mstarcon->setInvokeID(DONTCARE_INVOKEID);
+
+    //Append destination address for RMT "routing"
+    mstarcon->setDstAddr(pdu->getSrcAddr());
+
+    //Send it
+    signalizeSendData(mstarcon);
+}
+
 void RIBd::processMWrite(CDAPMessage* msg)
 {
     CDAP_M_Write * msg1 = check_and_cast<CDAP_M_Write *>(msg);
@@ -525,3 +567,25 @@
     /* Finally order to send the data... */
     signalizeSendData(cdapm);
 }
+
+void RIBd::signalizeCongestionNotification(CongestionDescriptor* congDesc) {
+    EV << "Emits CongestionNotification" << endl;
+    emit(sigRIBDCongNotif, congDesc);
+}
+
+void RIBd::processMStart(CDAPMessage* msg) {
+    CDAP_M_Start* msg1 = check_and_cast<CDAP_M_Start*>(msg);
+
+    EV << "Received M_Start";
+    object_t object = msg1->getObject();
+    EV << " with object '" << object.objectClass << "'" << endl;
+
+    //CongestionNotification CongestDescr
+    if (dynamic_cast<CongestionDescriptor*>(object.objectVal)) {
+        CongestionDescriptor* congdesc = (check_and_cast<CongestionDescriptor*>(object.objectVal))->dup();
+        congdesc->getConnectionId().swapCepIds();
+        EV << "\n===========\n" << congdesc->getConnectionId().info();
+        signalizeCongestionNotification(congdesc);
+    }
+
+}