RINASim  October 2016
Documentation of framework for OMNeT++
CDAPSplitter.cc
Go to the documentation of this file.
1 // The MIT License (MIT)
2 //
3 // Copyright (c) 2014-2016 Brno University of Technology, PRISTINE project
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 // THE SOFTWARE.
22 
23 #include "CDAPSplitter.h"
24 
26 
28 {
29  MsgLog = dynamic_cast<CDAPMsgLog*>(this->getParentModule()->getSubmodule(MOD_CDAPMSGLOG));
30  if (!MsgLog)
31  error("Pointer to CDAPMsgLog is not initialized!");
32 }
33 
35  MsgLog = NULL;
36 }
37 
39  MsgLog = NULL;
40 }
41 
42 void CDAPSplitter::handleMessage(cMessage *msg)
43 {
44  //Process message
45  if (!dynamic_cast<CDAPMessage*>(msg)) {
46  EV << this->getFullPath() << " received unknown message" << endl;
47  delete msg;
48  return;
49  }
50 
51 
52  CDAPMessage* cdapmsg = check_and_cast<CDAPMessage*>(msg);
53 
54  //Check for unsolicited response
55  if (cdapmsg->getOpCode() % 2 == 0 //is *_R message
56  && !MsgLog->findRequestByInvId(cdapmsg)) //does not have request with appropriate invokeId
57  {
58  EV << "Cannot send/received unsolicited CDAP response thus discarding message" << endl;
59  delete msg;
60  return;
61  }
62 
63  //Output gate pointer
64  cGate* out = nullptr;
65 
66  //Received from south gates
67  if ( strstr(msg->getArrivalGate()->getName(), GATE_SOUTHIO) != NULL ) {
68  MsgLog->insert(cdapmsg, false);
69 
70  //Pass it to the CACE module
71  if (dynamic_cast<CDAP_M_Connect*>(msg) || dynamic_cast<CDAP_M_Connect_R*>(msg) ||
72  dynamic_cast<CDAP_M_Release*>(msg) || dynamic_cast<CDAP_M_Release_R*>(msg) )
73  {
74  out = gateHalf(GATE_CDAPIO, cGate::OUTPUT);
75  }
76 
77  //Pass it to the Auth module
78 
79  //Pass it to the CDAP module
80  else if (dynamic_cast<CDAP_M_Create*>(msg) || dynamic_cast<CDAP_M_Create_R*>(msg) ||
81  dynamic_cast<CDAP_M_Delete*>(msg) || dynamic_cast<CDAP_M_Delete_R*>(msg) ||
82  dynamic_cast<CDAP_M_Start*>(msg) || dynamic_cast<CDAP_M_Start_R*>(msg) ||
83  dynamic_cast<CDAP_M_Stop*>(msg) || dynamic_cast<CDAP_M_Stop_R*>(msg) ||
84  dynamic_cast<CDAP_M_Write*>(msg) || dynamic_cast<CDAP_M_Write_R*>(msg) ||
85  dynamic_cast<CDAP_M_Read*>(msg) || dynamic_cast<CDAP_M_Read_R*>(msg) ||
86  dynamic_cast<CDAP_M_CancelRead*>(msg) || dynamic_cast<CDAP_M_CancelRead_R*>(msg) )
87  {
88  //EV <<"XXXXXXXX "<< msg->getArrivalGate()->getFullName() << "-" << msg->getArrivalGate()->getIndex() << endl;
89  out = gateHalf(GATE_CDAPIO, cGate::OUTPUT);
90  }
91 
92  }
93  //Received from north gates
94  else if (strstr(msg->getArrivalGate()->getName(), GATE_SOUTHIO) == NULL) {
95  MsgLog->insert(check_and_cast<CDAPMessage*>(msg), true);
96 
97  out = gateHalf(GATE_SOUTHIO, cGate::OUTPUT);
98  }
99 
100 
101  //Forward message
102  send(msg, out);
103 }
const char * MOD_CDAPMSGLOG
Definition: ExternConsts.cc:30
void insert(CDAPMessage *cdapmsg, bool srflag)
Definition: CDAPMsgLog.cc:37
virtual int32_t getOpCode() const
CDAPMsgLogEntry * findRequestByInvId(CDAPMessage *cdapmsg)
Definition: CDAPMsgLog.cc:54
const char * GATE_SOUTHIO
const char * GATE_CDAPIO
virtual void initialize()
Definition: CDAPSplitter.cc:27
virtual void handleMessage(cMessage *msg)
Definition: CDAPSplitter.cc:42
Define_Module(CDAPSplitter)
CDAPMsgLog * MsgLog
Definition: CDAPSplitter.h:39
virtual ~CDAPSplitter()
Definition: CDAPSplitter.cc:38