RINASim  October 2016
Documentation of framework for OMNeT++
QoSAwareMEntries.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 
21 namespace QoSAwareMEntries {
22 
24 
25 using namespace std;
26 using namespace common_GraphCL;
27 
28 // A new flow has been inserted/or removed
29 void QoSAwareMEntries::insertedFlow(const Address &addr, const QoSCube &qos, RMTPort * port){
30 
31  string dst = addr.getIpcAddress().getName();
32  string qosId = qos.getQosId();
33  portQoS[port] = qosId;
34  neighbours[qosId][dst].insert(port);
35  int lat = dstLat[dst];
36  if(lat <= 0) {
37  lat = maxLat;
38  dstLat[dst] = maxLat;
39  }
40 
41  if(neighbours[qosId][dst].size() == 1){
42  if(urgentQoS.find(qosId) != urgentQoS.end()) {
43  rt->insertFlow(addr, dst, qosId, lat);
44  } else {
45  rt->insertFlow(addr, dst, qosId, 1);
46  }
47  routingUpdated();
48  }
49 
50  qosId = "*";
51  neighbours[qosId][dst].insert(port);
52  if(neighbours[qosId][dst].size() == 1){
53  if(urgentQoS.find(qosId) != urgentQoS.end()) {
54  rt->insertFlow(addr, dst, qosId, lat);
55  } else {
56  rt->insertFlow(addr, dst, qosId, 1);
57  }
58  routingUpdated();
59  }
60 }
61 void QoSAwareMEntries::removedFlow(const Address &addr, const QoSCube& qos, RMTPort * port){
62  std::string dst = addr.getIpcAddress().getName();
63  string qosId = portQoS[port];
64  neighbours[qosId][dst].erase(port);
65  if(neighbours[qosId][dst].size() <= 0){
66  rt->removeFlow(addr, dst, qosId);
67  neighbours[qosId].erase(dst);
68  if(neighbours[qosId].size()<=0) {
69  neighbours.erase(qosId);
70  }
71  routingUpdated();
72  }
73 
74  qosId = "*";
75  neighbours[qosId][dst].erase(port);
76  if(neighbours[qosId][dst].size() <= 0){
77  rt->removeFlow(addr, dst, qosId);
78  neighbours[qosId].erase(dst);
79  if(neighbours[qosId].size()<=0) {
80  neighbours.erase(qosId);
81  }
82  routingUpdated();
83  }
84 
85  portQoS.erase(port);
86 }
87 
88 //Routing has processes a routing update
90  map<string, map<string, nhLMetric<mType> > > changes = rt->getChanges();
91 
92  for(const auto & qosEntries : changes){
93  string qosId = qosEntries.first;
94  for(const auto & entry : qosEntries.second){
95  std::vector< RMTPort * > ps;
96  for(string nextHop : entry.second.nh){
97  RMTPort * p = NULL;
98  if(nextHop != "") {
99  auto n = neighbours[qosId].find(nextHop);
100  if(n != neighbours[qosId].end()){
101  if(!n->second.empty()) {
102  p = *(n->second.begin());
103  }
104  }
105  }
106  if(p != NULL) {
107  ps.push_back(p);
108  }
109  fwd->addReplace(entry.first, qosId, ps);
110  }
111  }
112  }
113 }
114 
115 // Called after initialize
117  //Set Forwarding policy
118  fwd = check_and_cast<IntQoSMForwarding *>
119  (getModuleByPath("^.^.relayAndMux.pduForwardingPolicy"));
120  rt = check_and_cast<IntTSimpleRouting<mType> *>
121  (getModuleByPath("^.^.routingPolicy"));
122 
123  difA = check_and_cast<DA *>(getModuleByPath("^.^.^.difAllocator.da"));
124 
125  mType infMetric = par("infinite");
126  rt->setInfinite(infMetric);
127 
128  maxLat = par("maxLat").longValue();
129 
130  string myAddr = getModuleByPath("^.^")->par("ipcAddress").stringValue();
131 
132 
133  cXMLElement* Xml = NULL;
134  if (par("data").xmlValue() != NULL && par("data").xmlValue()->hasChildren()){
135  Xml = par("data").xmlValue();
136  } else { return; }
137 
138 
139  cXMLElementList QoSs = Xml->getChildrenByTagName("Qos");
140  for(auto qos : QoSs){
141  if (!qos->getAttribute("id")) { error("Error. ID is missing!"); }
142  std::string id = qos->getAttribute("id");
143  if (id=="") { error("Error. ID cannot be empty!"); }
144 
145  if (!qos->getAttribute("urgent")) { continue; }
146  urgentQoS.insert(id);
147  }
148 
149  double latMultip = par("latMultip").doubleValue();
150 
151  cXMLElementList Links = Xml->getChildrenByTagName("Link");
152  for(auto link : Links){
153  if (!link->getAttribute("src")) { error("Error. Addr is missing!"); }
154  std::string src = link->getAttribute("src");
155  if (src=="") { error("Error. Addr cannot be empty!"); }
156 
157  if (!link->getAttribute("dst")) { error("Error. Addr is missing!"); }
158  std::string dst = link->getAttribute("dst");
159  if (dst=="") { error("Error. Addr cannot be empty!"); }
160 
161 
162  if (!link->getAttribute("l")) { error("Error. Latency is missing!"); }
163  double l = atof(link->getAttribute("l"));
164  if (l < 0.0) { error("Error. Latency cannot be < 0"); }
165  int lat = l*latMultip;
166  if (lat > maxLat) { lat = maxLat; }
167 
168  if(src == myAddr) { dstLat[dst] = lat; }
169  else if(dst == myAddr) { dstLat[src] = lat; }
170  }
171 }
172 
173 }
const APN & getIpcAddress() const
Getter of IPC Process address which should be unambiguous within DIF.
Definition: Address.cc:83
unsigned short mType
virtual void removedFlow(const Address &addr, const QoSCube &qos, RMTPort *port)
Definition: DA.h:43
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 std::string & getName() const
Gets APN string name representation.
Definition: APN.cc:40
virtual void insertedFlow(const Address &addr, const QoSCube &qos, RMTPort *port)
Address class holds IPC Process identification.
Definition: Address.h:42
Register_Class(QoSAwareMEntries)