RINASim  October 2016
Documentation of framework for OMNeT++
HierarchicalGenerator.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 #include <Utils.h>
19 
20 #include <stdio.h>
21 #include <stdlib.h>
22 
23 
25 
27 
28 using namespace std;
29 
30 // A new flow has been inserted/or removed
31 void HierarchicalGenerator::insertedFlow(const Address &addr, const QoSCube &qos, RMTPort * port){
32  std::string dst = addr.getIpcAddress().getName();
33  pAddr parsedA = parseAddr(dst);
34 
35  domNeighbours[parsedA.domId][parsedA.addr].insert(port);
36 
37  if(domNeighbours[parsedA.domId][parsedA.addr].size() == 1){
38  rt->insertFlow(addr, parsedA.addr, parsedA.domId, 1);
39  routingUpdated();
40  }
41  fwd->setTmp(addr, port);
42 }
43 
44 void HierarchicalGenerator::removedFlow(const Address &addr, const QoSCube& qos, RMTPort * port){
45  std::string dst = addr.getIpcAddress().getName();
46  pAddr parsedA = parseAddr(dst);
47 
48  domNeighbours[parsedA.domId][parsedA.addr].insert(port);
49 
50  if(domNeighbours[parsedA.domId][parsedA.addr].size() <= 0){
51  rt->removeFlow(addr, parsedA.addr, parsedA.domId);
52  domNeighbours[parsedA.domId].erase(dst);
53  routingUpdated();
54  }
55  fwd->removeTmp(addr, port);
56 }
57 
58 //Routing has processes a routing update
60  map<string, map<string, nhLMetric<mType> > > changes = rt->getChanges();
61 
62  for(const auto & domain : changes){
63  for(const auto & entry : domain.second){
64  vector< RMTPort * > ps;
65  for(string nextHop : entry.second.nh){
66  RMTPort * p = NULL;
67  if(nextHop != "") {
68  auto n = domNeighbours[domain.first].find(nextHop);
69  if(n != domNeighbours[domain.first].end()){
70  if(!n->second.empty()) {
71  p = *(n->second.begin());
72  }
73  }
74  }
75  if(p != NULL) {
76  ps.push_back(p);
77  }
78  }
79  if(entry.first == "*") {
80  for(auto domain : domains){
81  fwd->addReplace(domain, "*", ps);
82  //fwd->addReplace("0", "", ps);
83  }
84  // fwd->addReplace(domain.first, "", ps);
85  } else {
86  fwd->addReplace(domain.first, entry.first, ps);
87  }
88  }
89  }
90 }
91 
92 // Called after initialize
94  //Set Forwarding policy
95  fwd = getRINAModule<HierarchicalTable::HierarchicalTable *>(this, 2, {MOD_RELAYANDMUX, MOD_POL_RMT_PDUFWD});
96  rt = getRINAModule<tDomain::TDomainRouting<mType> *>(this, 2, {MOD_POL_ROUTING});
97 
98  myAddr = getModuleByPath("^.^")->par("ipcAddress").stringValue();
99  parsStr = split(myAddr, '.');
100 
101  string alg = par("alg").stdstringValue();
102  tDomain::ModuleAlgs algT = (alg == "LS")? tDomain::LS : tDomain::DV;
103 
104  int k = 0;
105  for(string tAddr : parsStr){
106  string domId = to_string(k);
107  string pref = "";
108  if(k > 0) {
109  pref = join(parsStr, k, '.');
110  pref.append(".");
111  }
112  fwd->addDomain(domId,pref);
113  rt->addDomain(domId, tAddr, 32, algT);
114  domains.push_back(domId);
115  k++;
116  }
117  domains.pop_back();
118 
119  string domId = to_string(k);
120  string pref = join(parsStr, k, '.');
121  pref.append(".");
122  fwd->addDomain(domId,pref);
123  rt->addDomain(domId, "*", 32, algT);
124  k++;
125 
126  difA = getRINAModule<DA*>(this, 3, {MOD_DIFALLOC, MOD_DA});
127 }
128 
130  vector<string> sep = split(addr, '.');
131  int i = 0;
132  for(; i < (int)parsStr.size() && i < (int)sep.size(); i++){
133  if(parsStr[i] != sep[i]) {
134  return pAddr(to_string(i), sep[i]);
135  }
136  }
137  if(i < (int)sep.size()) {
138  return pAddr(to_string(i), sep[i]);
139  } else {
140  return pAddr(to_string(i), "*");
141  }
142 }
143 
144 }
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
std::vector< std::string > & split(const std::string &s, char delim, std::vector< std::string > &elems)
Definition: Utils.cc:33
std::string join(const std::vector< std::string > &elems, const unsigned int n, const char delim)
Definition: Utils.cc:48
virtual void insertedFlow(const Address &addr, const QoSCube &qos, RMTPort *port)
const char * MOD_RELAYANDMUX
Definition: ExternConsts.cc:57
Class representing QoSCube with all its properties that is primarily used by FA, RMT and RA Specifica...
Definition: QoSCube.h:57
const char * MOD_DA
Definition: ExternConsts.cc:33
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
const char * MOD_POL_RMT_PDUFWD
Definition: ExternConsts.cc:73
Address class holds IPC Process identification.
Definition: Address.h:42
Register_Class(HierarchicalGenerator)