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