RINASim  October 2016
Documentation of framework for OMNeT++
ModularMonitor.cc
Go to the documentation of this file.
1 //
2 // Copyright © 2014 - 2015 PRISTINE Consortium (http://ict-pristine.eu)
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Lesser General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public License
15 // along with this program. If not, see http://www.gnu.org/licenses/.
16 //
17 
18 #include <ModularMonitor.h>
19 #include "ModularMonitorSignals.h"
20 #include "AEConstantMsgs.h"
21 #include "UserDataField.h"
22 #include "PDUData.h"
23 #include "InfectionSignals.h"
24 
25 namespace ModularMonitor {
26 
28 
29 void ModularMonitor::onPolicyInit(){
30  inOutModule = check_and_cast<Int_MM_Out_Module*> (getSubmodule("inputOutSubModule"));
31  inDropModule = check_and_cast<Int_MM_Drop_Module*> (getSubmodule("inputDropSubModule"));
32  outOutModule = check_and_cast<Int_MM_Out_Module*> (getSubmodule("outputOutSubModule"));
33  outDropModule = check_and_cast<Int_MM_Drop_Module*> (getSubmodule("outputDropSubModule"));
34 
35  emitSignals = par("signal").boolValue();
36  if(emitSignals) {
37  signal = registerSignal("ModularSignal");
38  }
39 }
40 
41 void ModularMonitor::postPDUInsertion(RMTQueue* queue) {
42  RMTPort* port = rmtAllocator->getQueueToPortMapping(queue);
43  switch(queue->getType()){
44  case RMTQueue::INPUT:
45  inOutModule->pduInsertered(queue, port);
46  inDropModule->pduInsertered(queue, port);
47  break;
48  case RMTQueue::OUTPUT:
49  outOutModule->pduInsertered(queue, port);
50  outDropModule->pduInsertered(queue, port);
51 
52  if(emitSignals) {
53  const cPacket * pdu = queue->getLastPDU();
54  if(inTime.find(pdu) == inTime.end()) {
55  inTime[pdu] = simTime();
56  }
57 
58  if(inPos.find(pdu) == inPos.end()) {
59  inPos[pdu] = portServed[port];
60  }
61 
62  if(const PDU * p = dynamic_cast<const PDU*>(pdu)) {
63  emit(signal, new HopRcvMsg(p->getConnId().getQoSId(), this));
64  }
65  }
66  break;
67  }
68 }
69 
70 void ModularMonitor::onMessageDrop(RMTQueue* queue, const cPacket* pdu) {
71  RMTPort* port = rmtAllocator->getQueueToPortMapping(queue);
72  switch(queue->getType()){
73  case RMTQueue::INPUT:
74  inOutModule->pduDropped(queue, pdu, port);
75  inDropModule->pduDropped(queue, pdu, port);
76  break;
77  case RMTQueue::OUTPUT:
78  outOutModule->pduDropped(queue, pdu, port);
79  outDropModule->pduDropped(queue, pdu, port);
80 
81  if(emitSignals) {
82  if(const PDU * p = dynamic_cast<const PDU*>(pdu)) {
83  emit(signal, new HopLossMsg(p->getConnId().getQoSId(), this));
84  }
85  inTime.erase(pdu);
86  inPos.erase(pdu);
87  }
88 
89  break;
90  }
91 }
92 
93 void ModularMonitor::prePDURelease(RMTQueue* queue) {
94  RMTPort* port = rmtAllocator->getQueueToPortMapping(queue);
95  switch(queue->getType()){
96  case RMTQueue::INPUT:
97  inOutModule->pduReleased(queue, port);
98  inDropModule->pduReleased(queue, port);
99  break;
100  case RMTQueue::OUTPUT:
101  outOutModule->pduReleased(queue, port);
102  outDropModule->pduReleased(queue, port);
103 
104  if(const PDU * pdu = dynamic_cast<const PDU*>(queue->getFirstPDU())) {
105  if(inTime.find(pdu) != inTime.end()) {
106  int hdel = portServed[port]-inPos[pdu];
107  std::string qos = pdu->getConnId().getQoSId();
108  inTime.erase(pdu);
109  inPos.erase(pdu);
110  emit(signal, new HopDelayMsg(qos, hdel, this));
111  if(InfectedDataTransferPDU * idt =
112  dynamic_cast<InfectedDataTransferPDU * >(
113  const_cast<PDU*>(pdu))) {
114  idt->addPSTdelay(hdel);
115  idt->setHopCount(idt->getHopCount()+1);
116  }
117  }
118  }
119  portServed[port]++;
120  break;
121  }
122 }
123 
124 void ModularMonitor::postQueueCreation(RMTQueue* queue){
125  RMTPort* port = rmtAllocator->getQueueToPortMapping(queue);
126  switch(queue->getType()){
127  case RMTQueue::INPUT:
128  inOutModule->queueCreated(queue, port);
129  inDropModule->queueCreated(queue, port);
130  break;
131  case RMTQueue::OUTPUT:
132  outOutModule->queueCreated(queue, port);
133  outDropModule->queueCreated(queue, port);
134  break;
135  }
136 }
137 
138 
139 double ModularMonitor::getInDropProb(RMTQueue * queue) {
140  RMTPort* port = rmtAllocator->getQueueToPortMapping(queue);
141  return inDropModule->getDropProbability(queue, port);
142 }
143 
144 double ModularMonitor::getOutDropProb(RMTQueue * queue) {
145  RMTPort* port = rmtAllocator->getQueueToPortMapping(queue);
146  return outDropModule->getDropProbability(queue, port);
147 }
148 
149 
150 RMTQueue* ModularMonitor::getNextInput(RMTPort* port){
151  return inOutModule->getnextQueue(port);
152 }
153 
154 RMTQueue* ModularMonitor::getNextOutput(RMTPort* port){
155  return outOutModule->getnextQueue(port);
156 }
157 
158 
159 simtime_t ModularMonitor::getInNextTime(RMTPort* port){
160  return inOutModule->getnextTime(port);
161 }
162 
163 simtime_t ModularMonitor::getOutNextTime(RMTPort* port){
164  return outOutModule->getnextTime(port);
165 }
166 
167 
168 }
queueType getType() const
Definition: RMTQueue.cc:241
const cPacket * getFirstPDU() const
Definition: RMTQueue.cc:271
Definition: PDU.h:42
const cPacket * getLastPDU() const
Definition: RMTQueue.cc:276
Define_Module(ModularMonitor)