RINASim  October 2016
Documentation of framework for OMNeT++
PortsLoadMonitor.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 // NOTE:The procedures are sorted by name.
19 
20 #define RATESMONITOR_SELFMSG "RMT_MonitorPolicy_PortsLoad"
21 
22 #include <stdio.h>
23 #include <PortsLoadMonitor.h>
24 
26 
27 #ifdef PORTSLOADMONITOR_ENHANCED_DEBUG
28 void PortsLoadMonitor::enhancedDebug()
29 {
30  if(ev.isGUI())
31  {
32  cModule * ipcm = check_and_cast<cModule *>(getModuleByPath("^.^.^"));
33  cDisplayString & cs = ipcm->getDisplayString();
34  std::ostringstream str;
35 
36  for(PMIter i = rates.begin(); i != rates.end(); ++i)
37  {
38  str << i->first->info() << ", " << i->second << "\n";
39  }
40 
41  cs.setTagArg("t", 1, "l");
42  cs.setTagArg("t", 0, str.str().c_str());
43  }
44 }
45 #endif
46 
48 {
49  PMIter i = rates.find(port);
50 
51  // Be sure that the key exists.
52  if(i != rates.end())
53  {
54  return i->second;
55  }
56 
57  // Error value.
58  return 0;
59 }
60 
62 {
63  // Only consider messages which you send to yourself.
64  if(msg->isSelfMessage())
65  {
66  // Save the current rate and reset every entry in the accumulation map.
67  for(PMIter i = acc.begin(); i != acc.end(); ++i)
68  {
69  //EV << "New rate computed: " << i->first->info() << " have " << i->second << endl;
70  rates[i->first] = i->second;
71  i->second = 0;
72  }
73 
74 #ifdef PORTSLOADMONITOR_ENHANCED_DEBUG
75  enhancedDebug();
76 #endif
77 
78  // Renew the rate scheduling.
79  scheduleAt(simTime() + 1, new cMessage(RATESMONITOR_SELFMSG));
80  }
81 }
82 
84 {
85  // Get the arrived message.
86  const cPacket * pdu = queue->getLastPDU();
87  RMTPort * port = 0;
88 
89  if(!rmtA)
90  {
91  EV << "[Rate monitor policy] ERROR: "
92  "No RMT allocator detected.";
93 
94  return; // Exit before crashing all.
95  }
96 
97  port = rmtA->getQueueToPortMapping(queue);
98 
99  if(!port)
100  {
101  EV << "[Rate monitor policy] ERROR: "
102  "Could not resolve the queue.";
103 
104  return; // Exit before crashing all.
105  }
106 
107  // Accumulates the bytes. Input and output usage is accumulated
108  // together.
109  acc[port] += pdu->getByteLength();
110 
111 #ifdef PORTSLOADMONITOR_ENHANCED_DEBUG
112  enhancedDebug();
113 #endif
114 }
115 
117 {
118  // Get the departing message.
119  const cPacket * pdu = queue->getFirstPDU();
120  RMTPort * port = 0;
121 
122  if(!rmtA)
123  {
124  EV << "[Rate monitor policy] ERROR: "
125  "No RMT allocator detected.";
126 
127  return; // Exit before crashing all.
128  }
129 
130  port = rmtA->getQueueToPortMapping(queue);
131 
132  if(!port)
133  {
134  EV << "[Rate monitor policy] ERROR: "
135  "Could not resolve the queue.";
136 
137  return; // Exit before crashing all.
138  }
139 
140  // Accumulates the bytes. Input and output usage is accumulated
141  // together.
142  acc[port] += pdu->getByteLength();
143 
144 #ifdef PORTSLOADMONITOR_ENHANCED_DEBUG
145  enhancedDebug();
146 #endif
147 }
148 
150 {
151  // Get a pointer to the allocator.
152  rmtA = check_and_cast<RMTModuleAllocator *>(
153  getModuleByPath("^.allocator"));
154 
155  // Just activate the rate scheduling.
156  scheduleAt(simTime() + 1, new cMessage(RATESMONITOR_SELFMSG));
157 }
const cPacket * getFirstPDU() const
Definition: RMTQueue.cc:271
virtual void onPolicyInit()
PortsMap::iterator PMIter
Define_Module(PortsLoadMonitor)
RMTPort * getQueueToPortMapping(RMTQueue *queue)
virtual void postPDUInsertion(RMTQueue *queue)
#define RATESMONITOR_SELFMSG
RMTModuleAllocator * rmtA
const cPacket * getLastPDU() const
Definition: RMTQueue.cc:276
virtual void prePDURelease(RMTQueue *queue)
int64_t getByteRate(RMTPort *port)
virtual void handleMessage(cMessage *msg)