RINASim  October 2016
Documentation of framework for OMNeT++
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BiDomainGenerator.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 #include <Utils.h>
26 
27 
28 
29 namespace BiDomainGenerator {
30 
32 
33 using namespace std;
34 
35 // A new flow has been inserted/or removed
36 void BiDomainGenerator::insertedFlow(const Address &addr, const QoSCube &qos, RMTPort * port){
37 
38  std::string dst = addr.getIpcAddress().getName();
39  neighbours[dst].insert(port);
40  if(neighbours[dst].size() == 1){
41  pAddr parsedA = parseAddr(dst);
42  if(parsedA.domain != ""){
43  rt->addFlow(addr, "", parsedA.domain, 1);
44  rt->addFlow(addr, parsedA.domain, parsedA.addr,1);
45  } else {
46  rt->addFlow(addr, parsedA.domain, parsedA.addr,1);
47  }
48 
49  routingUpdated();
50  }
51 }
52 void BiDomainGenerator::removedFlow(const Address &addr, const QoSCube& qos, RMTPort * port){
53  std::string dst = addr.getIpcAddress().getName();
54  neighbours[dst].erase(port);
55  if(neighbours[dst].size() <= 0){
56  pAddr parsedA = parseAddr(dst);
57 
58  if(parsedA.domain != ""){
59  rt->removeFlow(addr, "", parsedA.domain);
60  rt->removeFlow(addr, parsedA.domain, parsedA.addr);
61  } else {
62  rt->removeFlow(addr, parsedA.domain, parsedA.addr);
63  }
64 
65  neighbours.erase(dst);
66 
67  routingUpdated();
68  }
69 }
70 
71 //Routing has processes a routing update
73  DMRnms::dmUpdateM changes = rt->getChanges();
74  for(DMRnms::dmUpdateMIt it = changes.begin(); it!= changes.end(); it++){
75  for(DMRnms::s2AIt eIt = it->entries.begin(); eIt != it->entries.end(); eIt++){
76 
77  std::string dst = eIt->first;
78  std::string nextHop = eIt->second.getIpcAddress().getName();
79 
80  EV << "Entry ::: \""<< it->domain << "\"/\""<< dst << "\" -> " << nextHop << " ("<< eIt->second<<")" <<endl;
81  RMTPort * p = NULL;
82 
83  NTableIt n = neighbours.find(nextHop);
84  if(nextHop != "" && n != neighbours.end()){
85  p = *(n->second.begin());
86  }
87 
88  if(p == NULL) {
89  fwd->remove(it->domain, dst);
90  } else {
91  fwd->insert(it->domain, dst, p);
92  }
93 
94  }
95  }
96 }
97 
98 // Called after initialize
100  //Set Forwarding policy
101  fwd = getRINAModule<DomainTable::DomainTable *>(this, 2, {MOD_RELAYANDMUX, MOD_POL_RMT_PDUFWD});
102 
103  rt = getRINAModule<DMRnms::Routing *>(this, 2, {MOD_POL_ROUTING});
104 
105  string myAddr = getModuleByPath("^.^")->par("ipcAddress").stringValue();
106 
107  vector<string> parsStr = split(myAddr, '.');
108  if(parsStr.size() != 2) {
109  error("BiDomainGenerator own address must be on the form A.B");
110  }
111  myPrefix = parsStr[0];
112  mySufix = parsStr[1];
113 
114  string alg0 = par("alg0").stdstringValue();
115  string alg1 = par("alg1").stdstringValue();
116 
117  fwd->addDomain(myPrefix);
118  fwd->addDomain("");
119 
120  if(alg0 == "LS"){
121  rt->addDomain("", myPrefix, DMRnms::LS);
122  } else {
123  rt->addDomain("", myPrefix, DMRnms::DV);
124  }
125 
126  if(alg1 == "LS"){
127  rt->addDomain(myPrefix, mySufix, DMRnms::LS);
128  } else {
129  rt->addDomain(myPrefix, mySufix, DMRnms::DV);
130  }
131 
132 
133  difA = getRINAModule<DA *>(this, 3, {MOD_DIFALLOC, MOD_DA});
134 }
135 
137  vector<string> sep = split(addr, '.');
138  if(isPrefix(myPrefix, addr)){
139  if(sep.size()>=2) {
140  return pAddr(myPrefix, sep[1]);
141  } else {
142  return pAddr(myPrefix, "");
143  }
144  } else {
145  return pAddr("", sep[0]);
146  }
147 }
148 
149 }
const char * MOD_POL_ROUTING
Definition: ExternConsts.cc:77
const char * MOD_DIFALLOC
Definition: ExternConsts.cc:34
s2A::iterator s2AIt
Definition: rModule.h:54
virtual void removedFlow(const Address &addr, const QoSCube &qos, RMTPort *port)
const APN & getIpcAddress() const
Getter of IPC Process address which should be unambiguous within DIF.
Definition: Address.cc:83
bool isPrefix(std::string prefix, std::string s)
Definition: Utils.cc:62
std::vector< std::string > & split(const std::string &s, char delim, std::vector< std::string > &elems)
Definition: Utils.cc:33
Register_Class(BiDomainGenerator)
virtual void insertedFlow(const Address &addr, const QoSCube &qos, RMTPort *port)
pAddr parseAddr(const std::string &addr)
NTable::iterator NTableIt
const char * MOD_RELAYANDMUX
Definition: ExternConsts.cc:57
dmUpdateM::iterator dmUpdateMIt
Definition: rModule.h:56
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
std::vector< dmNxt > dmUpdateM
Definition: rModule.h:52
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