RINASim  October 2016
Documentation of framework for OMNeT++
HopsQoSMEntries.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 HopsQoSMEntries {
22 
24 
25 using namespace std;
26 using namespace common_GraphCL;
27 
28 // A new flow has been inserted/or removed
29 void HopsQoSMEntries::insertedFlow(const Address &addr, const QoSCube &qos, RMTPort * port){
30  string dst = addr.getIpcAddress().getName();
31  string qosId = qos.getQosId();
32  portQoS[port] = qosId;
33  neighbours[qosId][dst].insert(port);
34  if(neighbours[qosId][dst].size() == 1){
35  rt->insertFlow(addr, dst, qosId, 1);
36  routingUpdated();
37  }
38 }
39 void HopsQoSMEntries::removedFlow(const Address &addr, const QoSCube& qos, RMTPort * port){
40  std::string dst = addr.getIpcAddress().getName();
41  string qosId = portQoS[port];
42  neighbours[qosId][dst].erase(port);
43  if(neighbours[qosId][dst].size() <= 0){
44  rt->removeFlow(addr, dst, qosId);
45  neighbours[qosId].erase(dst);
46  if(neighbours[qosId].size()<=0) {
47  neighbours.erase(qosId);
48  }
49  routingUpdated();
50  }
51  portQoS.erase(port);
52 }
53 
54 //Routing has processes a routing update
56  map<string, map<string, nhLMetric<mType> > > changes = rt->getChanges();
57 
58  for(const auto & qosEntries : changes){
59  string qosId = qosEntries.first;
60  for(const auto & entry : qosEntries.second){
61  std::vector< RMTPort * > ps;
62  for(string nextHop : entry.second.nh){
63  RMTPort * p = NULL;
64  if(nextHop != "") {
65  auto n = neighbours[qosId].find(nextHop);
66  if(n != neighbours[qosId].end()){
67  if(!n->second.empty()) {
68  p = *(n->second.begin());
69  }
70  }
71  }
72  if(p != NULL) {
73  ps.push_back(p);
74  }
75  fwd->addReplace(entry.first, qosId, ps);
76  }
77  }
78  }
79 }
80 
81 // Called after initialize
83  //Set Forwarding policy
84  fwd = check_and_cast<IntQoSMForwarding *>
85  (getModuleByPath("^.^.relayAndMux.pduForwardingPolicy"));
86  rt = check_and_cast<IntTSimpleRouting<mType> *>
87  (getModuleByPath("^.^.routingPolicy"));
88 
89  difA = check_and_cast<DA *>(getModuleByPath("^.^.^.difAllocator.da"));
90 
91  mType infMetric = par("infinite");
92  rt->setInfinite(infMetric);
93 }
94 
95 }
Register_Class(HopsQoSMEntries)
const APN & getIpcAddress() const
Getter of IPC Process address which should be unambiguous within DIF.
Definition: Address.cc:83
Definition: DA.h:43
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
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
virtual void insertedFlow(const Address &addr, const QoSCube &qos, RMTPort *port)
Address class holds IPC Process identification.
Definition: Address.h:42