RINASim  October 2016
Documentation of framework for OMNeT++
ScoreComparer.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 
24 #include <ScoreComparer.h>
25 
27 
28 short ScoreComparer::countFeasibilityScore(const QoSReq& requirements, const QoSCube& cube) const {
29  short score = 0;
30 
31  if (requirements.getAvgBand() != VAL_QOSPARDONOTCARE)
32  (requirements.getAvgBand() <= cube.getAvgBand()) ? score++ : score--;
33 
34  if (requirements.getAvgSduBand() != VAL_QOSPARDONOTCARE)
35  (requirements.getAvgSduBand() <= cube.getAvgSduBand()) ? score++ : score--;
36 
37  if (requirements.getPeakBandDuration() != VAL_QOSPARDONOTCARE)
38  (requirements.getPeakBandDuration() <= cube.getPeakBandDuration()) ? score++ : score--;
39 
40  if (requirements.getPeakSduBandDuration() != VAL_QOSPARDONOTCARE)
41  (requirements.getPeakSduBandDuration() <= cube.getPeakSduBandDuration()) ? score++ : score--;
42 
43  if (requirements.getBurstPeriod() != VAL_QOSPARDONOTCARE)
44  (requirements.getBurstPeriod() <= cube.getBurstPeriod()) ? score++ : score--;
45 
46  if (requirements.getBurstDuration() != VAL_QOSPARDONOTCARE)
47  (requirements.getBurstDuration() <= cube.getBurstDuration()) ? score++ : score--;
48 
49  if (requirements.getUndetectedBitErr() != VAL_QOSPARDONOTCARE)
50  (requirements.getUndetectedBitErr() <= cube.getUndetectedBitErr()) ? score++ : score--;
51 
52  if (requirements.getPduDropProbability() != VAL_QOSPARDONOTCARE)
53  (requirements.getPduDropProbability() <= cube.getPduDropProbability()) ? score++ : score--;
54 
55  if (requirements.getMaxSduSize() != VAL_QOSPARDONOTCARE)
56  (requirements.getMaxSduSize() <= cube.getMaxSduSize()) ? score++ : score--;
57 
58  (requirements.isPartialDelivery() == cube.isPartialDelivery()) ? score++ : score--;
59 
60  (requirements.isIncompleteDelivery() == cube.isIncompleteDelivery()) ? score++ : score--;
61 
62  (requirements.isForceOrder() == cube.isForceOrder()) ? score++ : score--;
63 
64  if (requirements.getMaxAllowGap() != VAL_QOSPARDONOTCARE)
65  (requirements.getMaxAllowGap() <= cube.getMaxAllowGap()) ? score++ : score--;
66 
67  if (requirements.getDelay() != VAL_QOSPARDONOTCARE)
68  (requirements.getDelay() <= cube.getDelay()) ? score++ : score--;
69 
70  if (requirements.getJitter() != VAL_QOSPARDONOTCARE)
71  (requirements.getJitter() <= cube.getJitter()) ? score++ : score--;
72 
73  if (requirements.getCostTime() != VAL_QOSPARDONOTCARE)
74  (requirements.getCostTime() <= cube.getCostTime()) ? score++ : score--;
75 
76  if (requirements.getCostBits() != VAL_QOSPARDONOTCARE)
77  (requirements.getCostBits() <= cube.getCostBits()) ? score++ : score--;
78 
79  return score;
80 }
81 
82 bool ScoreComparer::run(Flow& flow) {
83  Enter_Method("invokeNewFlowRequestPolicy()");
84  //Is flow policy acceptable
85  std::string apname = flow.getSrcApni().getApn().getName();
86 
87  //FIXME: Vesely - Simulate error and DTCP flag better
88  if ( apname.find("Err") != std::string::npos) {
89  return false;
90  }
91 
92  //EV << flow.getQosRequirements().getAvgBand() << endl;
93 
94  //Always translate management traffic to appropriate management QoSCube
95  if (flow.isManagementFlow()) {
98  return true;
99  }
100 
101  //TODO: Compare QoS Parameters with available QoS cubes
103  //EV << ResourceAllocator->getQoSCubes();
104 
105  std::string qosid = VAL_UNDEF_QOSID;
106  short score = 0;
107  QoSCube qs;
108 
109  for (QCubeCItem it = cubes.begin(); it != cubes.end(); ++it) {
110  short tmpscore = countFeasibilityScore(flow.getQosRequirements(), *it);
111  if (score < tmpscore) {
112  score = tmpscore;
113  qosid = it->getQosId();
114  qs = *it;
115  }
116  }
117  flow.getConnectionId().setQoSId(qosid);
118  flow.setQosCube(qs);
119  return qosid.compare(VAL_UNDEF_QOSID) ? true : false;
120 }
121 
double getUndetectedBitErr() const
Gets Undetected Bit Error Rate parameter.
Definition: QoSReq.cc:325
static const QoSCube MANAGEMENT
Definition: QoSCube.h:201
Class representing flow object with attributes from specs.
Definition: Flow.h:45
const APNamingInfo & getSrcApni() const
Gets read-only source APNamingInfo.
Definition: Flow.cc:134
int getBurstPeriod() const
Gets Burst Period parameter.
Definition: QoSCube.cc:276
int getBurstDuration() const
Gets Burst Duration parameter.
Definition: QoSCube.cc:268
int getAvgBand() const
Gets Average Bandwidth parameter.
Definition: QoSCube.cc:252
ConnectionId & getConnectionId()
Gets Flow's ConnectionId.
Definition: Flow.cc:209
double getPduDropProbability() const
Gets PDU Dropping Probability parameter.
Definition: QoSCube.cc:400
virtual bool run(Flow &flow)
int getPeakBandDuration() const
Gets Peak Band Duration parameter.
Definition: QoSCube.cc:340
int getJitter() const
Gets Jitter parameter.
Definition: QoSCube.cc:308
double getCostBits() const
Gets Cost-bits parameter.
Definition: QoSCube.cc:368
const std::string VAL_MGMTQOSID
Definition: QoSCube.cc:37
bool isForceOrder() const
Gets in-order delivery flag.
Definition: QoSReq.cc:261
int getMaxSduSize() const
Gets Maximum SDU Size parameter.
Definition: QoSCube.cc:324
double getUndetectedBitErr() const
Gets Undetected Bit Error Rate parameter.
Definition: QoSCube.cc:356
double getPduDropProbability() const
Gets PDU Dropping Probability parameter.
Definition: QoSReq.cc:472
const QoSCubeSet & getQoSCubes() const
Definition: RABase.cc:35
const APN & getApn() const
Getter of APN.
Definition: APNamingInfo.h:142
const std::string VAL_UNDEF_QOSID
Definition: QoSCube.cc:36
int getMaxSduSize() const
Gets Maximum SDU Size parameter.
Definition: QoSReq.cc:293
const QoSReq & getQosRequirements() const
Gets QoS parameters wanted by flow initiator.
Definition: Flow.cc:176
bool isIncompleteDelivery() const
Gets incomplete delivery flag.
Definition: QoSCube.cc:300
bool isManagementFlow() const
Definition: Flow.cc:366
short countFeasibilityScore(const QoSReq &requirements, const QoSCube &cube) const
Define_Module(ScoreComparer)
const int VAL_QOSPARDONOTCARE
int getPeakSduBandDuration() const
Gets Peak SDU Duration parameter.
Definition: QoSReq.cc:317
QoSCubeSet::const_iterator QCubeCItem
Definition: RABase.h:34
std::list< QoSCube > QoSCubeSet
Definition: RABase.h:33
int getMaxAllowGap() const
Gets Maximum Allowable Gap in SDUs parameter.
Definition: QoSReq.cc:285
int getDelay() const
Gets Delay parameter.
Definition: QoSReq.cc:253
bool isPartialDelivery() const
Gets partial delivery flag.
Definition: QoSReq.cc:301
Class representing QoSCube with all its properties that is primarily used by FA, RMT and RA Specifica...
Definition: QoSCube.h:57
int getJitter() const
Gets Jitter parameter.
Definition: QoSReq.cc:277
double getCostTime() const
Gets Cost-time parameter.
Definition: QoSCube.cc:376
bool isPartialDelivery() const
Gets partial delivery flag.
Definition: QoSCube.cc:332
bool isForceOrder() const
Gets in-order delivery flag.
Definition: QoSCube.cc:292
void setQoSId(std::string qoSId)
Setter of selected QoS-cube identifier.
Definition: ConnectionId.cc:49
double getCostTime() const
Gets Cost-time parameter.
Definition: QoSReq.cc:341
Class representing QoSReq with all its properties that is primarily used by FA, RMT and RA Specificat...
Definition: QoSReq.h:44
int getPeakBandDuration() const
Gets Peak Band Duration parameter.
Definition: QoSReq.cc:309
double getCostBits() const
Gets Cost-bits parameter.
Definition: QoSReq.cc:333
int getAvgBand() const
Gets Average Bandwidth parameter.
Definition: QoSReq.cc:221
int getDelay() const
Gets Delay parameter.
Definition: QoSCube.cc:284
const std::string & getName() const
Gets APN string name representation.
Definition: APN.cc:40
int getBurstDuration() const
Gets Burst Duration parameter.
Definition: QoSReq.cc:237
int getPeakSduBandDuration() const
Gets Peak SDU Duration parameter.
Definition: QoSCube.cc:348
void setQosCube(const QoSCube &qosCube)
Definition: Flow.cc:167
int getAvgSduBand() const
Gets Average SDU Bandwidth parameter.
Definition: QoSCube.cc:260
int getAvgSduBand() const
Gets Average SDU Bandwidth parameter.
Definition: QoSReq.cc:229
int getBurstPeriod() const
Gets Burst Period parameter.
Definition: QoSReq.cc:245
int getMaxAllowGap() const
Gets Maximum Allowable Gap in SDUs parameter.
Definition: QoSCube.cc:316
bool isIncompleteDelivery() const
Gets incomplete delivery flag.
Definition: QoSReq.cc:269