RINASim  October 2016
Documentation of framework for OMNeT++
LatencySingle1Entry.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 
17 #include "APN.h"
18 
19 
20 
22 
24 
25 using namespace std;
26 using namespace common_GraphCL;
27 
28 
29 portMetric::portMetric(RMTPort* p, unsigned short m) :
30  port(p), metric(m){}
31 
32 bool portMetric::operator < (const portMetric &other) const {
33  return port < other.port;
34 }
35 
36 // A new flow has been inserted/or removed
37 void LatencySingle1Entry::insertedFlow(const Address &addr, const QoSCube &qos, RMTPort * port){
38  string dst = addr.getIpcAddress().getName();
39 
40  mType metric = qos.getDelay()/par("redLinkCost").longValue();
41 
42  if(metric < par("minLinkCost").longValue()) {
43  metric = par("minLinkCost").longValue();
44  } else if(metric > par("maxLinkCost").longValue()) {
45  metric = par("maxLinkCost").longValue();
46  }
47 
48  if(qos.getQosId() == qos.MANAGEMENT.getQosId() || qos.getQosId() == VAL_UNDEF_QOSID) {
49  metric = par("maxLinkCost").longValue();
50  }
51 
52  neighbours[dst].insert(portMetric(port, metric));
53  if(neighbours[dst].size() == 1){
54  rt->insertFlow(addr, dst, "", metric);
55  routingUpdated();
56  } else {
57  bool lower = true;
58  for(portMetric mt : neighbours[dst]) {
59  if(metric >= mt.metric && port != mt.port) { lower = false; }
60  }
61  if(lower) {
62  rt->insertFlow(addr, dst, "", metric);
63  routingUpdated();
64  }
65  }
66 }
67 void LatencySingle1Entry::removedFlow(const Address &addr, const QoSCube& qos, RMTPort * port){
68  std::string dst = addr.getIpcAddress().getName();
69  neighbours[dst].erase(portMetric(port, 0));
70  if(neighbours[dst].size() <= 0){
71  rt->removeFlow(addr, dst, "");
72  neighbours.erase(dst);
73  routingUpdated();
74  } else {
75  unsigned short min = par("maxLinkCost").longValue();
76  for(portMetric mt : neighbours[dst]) {
77  if(min >= mt.metric) { min = mt.metric; }
78  }
79  rt->insertFlow(addr, dst, "", min);
80  routingUpdated();
81  }
82 }
83 
84 //Routing has processes a routing update
85 void LatencySingle1Entry::routingUpdated(){
86  map<string, map<string, nhLMetric<mType> > > changes = rt->getChanges();
87 
88  for(const auto & entry : changes[""]){
89  std::string nextHop = "";
90  if(!entry.second.nh.empty()){
91  nextHop = *(entry.second.nh.begin());
92  }
93  RMTPort * p = NULL;
94  if(nextHop != "") {
95  auto n = neighbours.find(nextHop);
96  if(n != neighbours.end()){
97  if(!n->second.empty()) {
98  p = n->second.begin()->port;
99  }
100  }
101  }
102  if(p == NULL) {
103  fwd->remove(entry.first);
104  } else {
105  fwd->insert(entry.first, p);
106  }
107  }
108 }
109 
110 // Called after initialize
111 void LatencySingle1Entry::onPolicyInit(){
112  //Set Forwarding policy
113  fwd = getRINAModule<IntMiniForwarding *>(this, 2, {MOD_RELAYANDMUX, MOD_POL_RMT_PDUFWD});
114  rt = getRINAModule<IntTSimpleRouting<mType> *>(this, 2, {MOD_RELAYANDMUX, MOD_POL_ROUTING});
115 
116  difA = getRINAModule<DA *>(this, 3, {MOD_DIFALLOC, MOD_DA});
117 
118  mType infMetric = par("infinite");
119  rt->setInfinite(infMetric);
120 }
121 
122 }
static const QoSCube MANAGEMENT
Definition: QoSCube.h:201
const char * MOD_POL_ROUTING
Definition: ExternConsts.cc:77
const char * MOD_DIFALLOC
Definition: ExternConsts.cc:34
const APN & getIpcAddress() const
Getter of IPC Process address which should be unambiguous within DIF.
Definition: Address.cc:83
Register_Class(LatencySingle1Entry)
RMTPort * port
const std::string VAL_UNDEF_QOSID
Definition: QoSCube.cc:36
bool operator<(const portMetric &other) const
portMetric(RMTPort *p, mType m)
const char * MOD_RELAYANDMUX
Definition: ExternConsts.cc:57
unsigned short mType
Class representing QoSCube with all its properties that is primarily used by FA, RMT and RA Specifica...
Definition: QoSCube.h:57
std::string getQosId() const
Gets QoSCube identifier.
Definition: QoSCube.cc:364
const char * MOD_DA
Definition: ExternConsts.cc:33
int getDelay() const
Gets Delay parameter.
Definition: QoSCube.cc:284
const std::string & getName() const
Gets APN string name representation.
Definition: APN.cc:40
const char * MOD_POL_RMT_PDUFWD
Definition: ExternConsts.cc:73
Address class holds IPC Process identification.
Definition: Address.h:42