Download this file

BiDomainGenerator.cc    142 lines (114 with data), 4.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see http://www.gnu.org/licenses/.
//
#include <BiDomainGenerator/BiDomainGenerator.h>
#include "APN.h"
#include <Utils.h>
namespace BiDomainGenerator {
Register_Class(BiDomainGenerator);
using namespace std;
// A new flow has been inserted/or removed
void BiDomainGenerator::insertedFlow(const Address &addr, const unsigned short &qos, RMTPort * port){
std::string dst = addr.getIpcAddress().getName();
neighbours[dst].insert(port);
if(neighbours[dst].size() == 1){
pAddr parsedA = parseAddr(dst);
if(parsedA.domain != ""){
rt->addFlow(addr, "", parsedA.domain, 1);
rt->addFlow(addr, parsedA.domain, parsedA.addr,1);
} else {
rt->addFlow(addr, parsedA.domain, parsedA.addr,1);
}
routingUpdated();
}
}
void BiDomainGenerator::removedFlow(const Address &addr, const unsigned short &qos, RMTPort * port){
std::string dst = addr.getIpcAddress().getName();
neighbours[dst].erase(port);
if(neighbours[dst].size() <= 0){
pAddr parsedA = parseAddr(dst);
if(parsedA.domain != ""){
rt->removeFlow(addr, "", parsedA.domain);
rt->removeFlow(addr, parsedA.domain, parsedA.addr);
} else {
rt->removeFlow(addr, parsedA.domain, parsedA.addr);
}
neighbours.erase(dst);
routingUpdated();
}
}
//Routing has processes a routing update
void BiDomainGenerator::routingUpdated(){
DMRnms::dmUpdateM changes = rt->getChanges();
for(DMRnms::dmUpdateMIt it = changes.begin(); it!= changes.end(); it++){
for(DMRnms::s2AIt eIt = it->entries.begin(); eIt != it->entries.end(); eIt++){
std::string dst = eIt->first;
std::string nextHop = eIt->second.getIpcAddress().getName();
EV << "Entry ::: \""<< it->domain << "\"/\""<< dst << "\" -> " << nextHop << " ("<< eIt->second<<")" <<endl;
RMTPort * p = NULL;
NTableIt n = neighbours.find(nextHop);
if(nextHop != "" && n != neighbours.end()){
p = *(n->second.begin());
}
if(p == NULL) {
fwd->remove(it->domain, dst);
} else {
fwd->insert(it->domain, dst, p);
}
}
}
}
// Called after initialize
void BiDomainGenerator::onPolicyInit(){
//Set Forwarding policy
fwd = check_and_cast<DomainTable::DomainTable *>
(getModuleByPath("^.^.relayAndMux.pduForwardingPolicy"));
rt = check_and_cast<DMRnms::Routing *>
(getModuleByPath("^.^.routingPolicy"));
string myAddr = getParentModule()->getParentModule()->par("ipcAddress").stringValue();
vector<string> parsStr = split(myAddr, '.');
if(parsStr.size() != 2) {
error("BiDomainGenerator own address must be on the form A.B");
}
myPrefix = parsStr[0];
mySufix = parsStr[1];
string alg0 = par("alg0").stdstringValue();
string alg1 = par("alg1").stdstringValue();
fwd->addDomain(myPrefix);
fwd->addDomain("");
if(alg0 == "LS"){
rt->addDomain("", myPrefix, DMRnms::LS);
} else {
rt->addDomain("", myPrefix, DMRnms::DV);
}
if(alg1 == "LS"){
rt->addDomain(myPrefix, mySufix, DMRnms::LS);
} else {
rt->addDomain(myPrefix, mySufix, DMRnms::DV);
}
difA = check_and_cast<DA *>(getModuleByPath("^.^.^.difAllocator.da"));
}
pAddr BiDomainGenerator::parseAddr(const string &addr){
vector<string> sep = split(addr, '.');
if(isPrefix(myPrefix, addr)){
if(sep.size()>=2) {
return pAddr(myPrefix, sep[1]);
} else {
return pAddr(myPrefix, "");
}
} else {
return pAddr("", sep[0]);
}
}
}