RINASim  October 2016
Documentation of framework for OMNeT++
FlowListener.cc
Go to the documentation of this file.
1 //
2 // This program is free software: you can redistribute it and/or modify
3 // it under the terms of the GNU Lesser General Public License as published by
4 // the Free Software Foundation, either version 3 of the License, or
5 // (at your option) any later version.
6 //
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 // GNU Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public License
13 // along with this program. If not, see http://www.gnu.org/licenses/.
14 //
15 
16 #include "FlowListener.h"
17 
19 
20 
21 FlowContainer::FlowContainer(Flow * _f, RA * _ra):f(_f), ra(_ra){}
23  if(f < o.f) { return true; }
24  if(f > o.f) { return false; }
25  if(ra < o.ra) { return true; }
26  return false;
27 }
28 
30  return (f == o.f && ra == o.ra);
31 }
32 
34  getParentModule()->subscribe(SIG_RA_CreateFlowPositive, this);
35  killTime = par("killTime").doubleValue();
36  killCount = par("killCount");
37 
38  if(killCount > 0 && killTime > simTime().dbl()) {
39  scheduleAt(killTime, new cMessage("Kill flows"));
40  }
41 }
42 
43 void FlowListener::handleMessage(cMessage *msg) {
44  Enter_Method_Silent();
45  for(int i = 0; i < killCount; i++) {
46  if(flows.empty()) {
47  cerr << "All flows removed, requested to remove "<<(killCount-i) << " more flows" << endl;
48  break;
49  }
50 
51  int r = intuniform(0, flows.size()-1);
52  auto f = flows[r];
53  if(r == (int)flows.size()-1) {
54  flows[r] = flows.back();
55  flows.pop_back();
56  }
57  f.ra->sleepFlow(f.f, -1);
58  }
59  delete msg;
60 }
61 
62 void FlowListener::receiveSignal(cComponent *source, simsignal_t signalID, cObject *obj) {
63  Enter_Method_Silent();
64  if(killCount > 0 && killTime > simTime().dbl()) {
65  Flow * f = dynamic_cast<Flow*>(obj);
66  RA * ra = dynamic_cast<RA*>(source);
67  flows.push_back(FlowContainer(f, ra));
68  }
69 }
Class representing flow object with attributes from specs.
Definition: Flow.h:45
FlowContainer(Flow *_f, RA *_ra)
Definition: FlowListener.cc:21
Define_Module(FlowListener)
double killTime
Definition: FlowListener.h:31
void receiveSignal(cComponent *source, simsignal_t signalID, cObject *obj)
Definition: FlowListener.cc:62
bool operator==(const FlowContainer &o) const
Definition: FlowListener.cc:29
bool operator<(const FlowContainer &o) const
Definition: FlowListener.cc:22
vector< FlowContainer > flows
Definition: FlowListener.h:30
Definition: RA.h:61
void initialize()
Definition: FlowListener.cc:33
const char * SIG_RA_CreateFlowPositive
Definition: RINASignals.cc:116
void handleMessage(cMessage *msg)
Definition: FlowListener.cc:43