RINASim  October 2016
Documentation of framework for OMNeT++
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
QoSDomainGenerator.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 
24 #include "APN.h"
25 
26 #include <stdio.h>
27 #include <stdlib.h>
28 
29 
30 
31 namespace QoSDomainGenerator {
32 
34 
35 using namespace std;
36 
37 void QoSDomainGenerator::insertedFlow(const Address& addr, const QoSCube & qos, RMTPort* port) {
38  std::string dst = addr.getIpcAddress().getName();
39 
40  //Iterate through all QoS cubes and check if qos is a valid
41  for(QoSCube qosI : cubes) {
42  if(comparer->isValid(qosI, qos)) {
43  neighbours[qosI.getQosId()][dst].insert(port);
44  if (neighbours[qosI.getQosId()][dst].size() == 1) {
45  rt->addFlow(addr, qosI.getQosId(), dst, 1);
46  routingUpdated();
47  }
48  }
49  }
50 }
51 
52 void QoSDomainGenerator::removedFlow(const Address &addr, const QoSCube& qos, RMTPort * port){
53  std::string dst = addr.getIpcAddress().getName();
54 
55  //Iterate through all QoS cubes and remove is inserted
56  for(QoSCube qosI : cubes) {
57  if(neighbours[qosI.getQosId()].find(dst) != neighbours[qosI.getQosId()].end()){
58  neighbours[qosI.getQosId()][dst].erase(port);
59  if(neighbours[qosI.getQosId()][dst].size() <= 0){
60  rt->removeFlow(addr,qosI.getQosId(), dst);
61  neighbours[qosI.getQosId()].erase(dst);
62  routingUpdated();
63  }
64  }
65  }
66 }
67 
68 //Routing has processes a routing update
70  DMRnms::dmUpdateM changes = rt->getChanges();
71  for(DMRnms::dmUpdateMIt it = changes.begin(); it!= changes.end(); it++){
72  for(DMRnms::s2AIt eIt = it->entries.begin(); eIt != it->entries.end(); eIt++){
73  std::string dst = eIt->first;
74  std::string nextHop = eIt->second.getIpcAddress().getName();
75 
76  EV << "Entry ::: "<< dst << " -> " << nextHop << " ("<< eIt->second<<")" <<endl;
77  RMTPort * p = NULL;
78 
79  NTableIt n = neighbours[it->domain].find(nextHop);
80  if(n != neighbours[it->domain].end()){
81  p = *(n->second.begin());
82  }
83 
84  if(p == NULL) {
85  fwd->remove(dst, it->domain);
86  } else {
87  fwd->insert(dst, it->domain, p);
88  }
89  }
90  }
91 }
92 
93 // Called after initialize
95  //Set Forwarding policy
96  fwd = getRINAModule<QoSTable::QoSTable *>(this, 2, {MOD_RELAYANDMUX, MOD_POL_RMT_PDUFWD});
97 
98  rt = getRINAModule<DMRnms::Routing *>(this, 2, {MOD_POL_ROUTING});
99 
100  std::string alg = par("alg").stdstringValue();
101 
102  RABase* ResourceAllocator = getRINAModule<RABase*>(this, 2, {MOD_RESALLOC, MOD_RA});
103 
104  cubes = ResourceAllocator->getQoSCubes();
105 
106  if(alg == "LS"){
107  for (QCubeCItem it = cubes.begin(); it != cubes.end(); ++it) {
108  rt->addDomain(it->getQosId(), getModuleByPath("^.^")->par("ipcAddress").stringValue(), DMRnms::LS);
109  }
110  } else {
111  for (QCubeCItem it = cubes.begin(); it != cubes.end(); ++it) {
112  rt->addDomain(it->getQosId(), getModuleByPath("^.^")->par("ipcAddress").stringValue(), DMRnms::DV);
113  }
114  }
115 
116  difA = getRINAModule<DA *>(this, 3, {MOD_DIFALLOC, MOD_DA});
117 
118 
119  comparer = getRINAModule<MultilevelQoS *>(this, 2, {MOD_FLOWALLOC, MOD_POL_RA_QOSCOMPARER});
120 }
121 
122 }
const char * MOD_RESALLOC
Definition: ExternConsts.cc:58
const char * MOD_POL_ROUTING
Definition: ExternConsts.cc:77
const char * MOD_DIFALLOC
Definition: ExternConsts.cc:34
s2A::iterator s2AIt
Definition: rModule.h:54
const APN & getIpcAddress() const
Getter of IPC Process address which should be unambiguous within DIF.
Definition: Address.cc:83
const QoSCubeSet & getQoSCubes() const
Definition: RABase.cc:35
const char * MOD_RELAYANDMUX
Definition: ExternConsts.cc:57
dmUpdateM::iterator dmUpdateMIt
Definition: rModule.h:56
const char * MOD_FLOWALLOC
Definition: ExternConsts.cc:47
QoSCubeSet::const_iterator QCubeCItem
Definition: RABase.h:34
Definition: RABase.h:36
const char * MOD_POL_RA_QOSCOMPARER
Definition: ExternConsts.cc:70
Class representing QoSCube with all its properties that is primarily used by FA, RMT and RA Specifica...
Definition: QoSCube.h:57
const char * MOD_RA
Definition: ExternConsts.cc:55
const char * MOD_DA
Definition: ExternConsts.cc:33
Register_Class(QoSDomainGenerator)
std::vector< dmNxt > dmUpdateM
Definition: rModule.h:52
const std::string & getName() const
Gets APN string name representation.
Definition: APN.cc:40
virtual void removedFlow(const Address &addr, const QoSCube &qos, RMTPort *port)
const char * MOD_POL_RMT_PDUFWD
Definition: ExternConsts.cc:73
Address class holds IPC Process identification.
Definition: Address.h:42
virtual void insertedFlow(const Address &addr, const QoSCube &qos, RMTPort *port)
NTable::iterator NTableIt