RINASim  October 2016
Documentation of framework for OMNeT++
BEMonitor.cc
Go to the documentation of this file.
1 //
2 // The MIT License (MIT)
3 //
4 // Copyright (c) 2014-2016 Brno University of Technology, PRISTINE project
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to deal
8 // in the Software without restriction, including without limitation the rights
9 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 // copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 // THE SOFTWARE.
23 
24 #include <BEMonitor.h>
25 
26 namespace BEMonitor {
27 
29 
30 void BEMonitor::onPolicyInit(){}
31 
32 void BEMonitor::postPDUInsertion(RMTQueue* queue) {
33  RMTPort* port = rmtAllocator->getQueueToPortMapping(queue);
34  if(port != NULL){
35  if(queue->getType() == RMTQueue::INPUT){
36  inC[port] ++;
37  inQ[port].push_back(queue);
38  }
39  if(queue->getType() == RMTQueue::OUTPUT){
40  outC[port] ++;
41  outQ[port].push_back(queue);
42  }
43  }
44 }
45 
46 void BEMonitor::onMessageDrop(RMTQueue* queue, const cPacket* pdu) {
47  RMTPort* port = rmtAllocator->getQueueToPortMapping(queue);
48  if(port != NULL){
49  if(queue->getType() == RMTQueue::INPUT){
50  inC[port] --;
51  inQ[port].pop_back();
52  } else {
53  outC[port] --;
54  outQ[port].pop_back();
55  }
56  }
57 }
58 
59 RMTQueue* BEMonitor::getNextInput(RMTPort* port){
60  RMTQueue* q = NULL;
61 
62  QueuesList* ql = &(inQ[port]);
63  if(!ql->empty()) {
64  q = ql->front();
65  ql->pop_front();
66  }
67 
68  if(q != NULL){
69  inC[port]--;
70  }
71 
72  return q;
73 }
74 
75 RMTQueue* BEMonitor::getNextOutput(RMTPort* port){
76  RMTQueue* q = NULL;
77 
78  QueuesList* ql = &(outQ[port]);
79  if(!ql->empty()) {
80  q = ql->front();
81  ql->pop_front();
82  }
83 
84  if(q != NULL){
85  outC[port]--;
86  }
87 
88  return q;
89 }
90 
91 double BEMonitor::getInDropProb(RMTQueue * queue) {
92  RMTPort* port = rmtAllocator->getQueueToPortMapping(queue);
93  if(port == NULL){ error("RMTPort for RMTQueue not found."); }
94 
95  return ( (int)inC[port] < queue->getMaxLength() )? 0 : 1;
96 }
97 
98 double BEMonitor::getOutDropProb(RMTQueue * queue) {
99  RMTPort* port = rmtAllocator->getQueueToPortMapping(queue);
100  if(port == NULL){ error("RMTPort for RMTQueue not found."); }
101 
102  return ( (int)outC[port] < queue->getMaxLength() )? 0 : 1;
103 }
104 
105 
106 }
queueType getType() const
Definition: RMTQueue.cc:241
int getMaxLength() const
Definition: RMTQueue.cc:215
Define_Module(BEMonitor)
list< RMTQueue * > QueuesList
Definition: BEMonitor.h:38