|
a |
|
b/src/policies/DIF/RA/PDUFG/SingleDomainGenerator/SingleDomainGenerator.cc |
|
|
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 |
|
|
|
16 |
#include <SingleDomainGenerator/SingleDomainGenerator.h>
|
|
|
17 |
#include "APN.h"
|
|
|
18 |
|
|
|
19 |
|
|
|
20 |
|
|
|
21 |
namespace SingleDomainGenerator {
|
|
|
22 |
|
|
|
23 |
Register_Class(SingleDomainGenerator);
|
|
|
24 |
|
|
|
25 |
using namespace std;
|
|
|
26 |
|
|
|
27 |
// A new flow has been inserted/or removed
|
|
|
28 |
void SingleDomainGenerator::insertedFlow(const Address &addr, const unsigned short &qos, RMTPort * port){
|
|
|
29 |
std::string dst = addr.getIpcAddress().getName();
|
|
|
30 |
neighbours[dst].insert(port);
|
|
|
31 |
if(neighbours[dst].size() == 1){
|
|
|
32 |
rt->addFlow(addr, "", dst,1);
|
|
|
33 |
routingUpdated();
|
|
|
34 |
}
|
|
|
35 |
}
|
|
|
36 |
void SingleDomainGenerator::removedFlow(const Address &addr, const unsigned short &qos, RMTPort * port){
|
|
|
37 |
std::string dst = addr.getIpcAddress().getName();
|
|
|
38 |
neighbours[dst].erase(port);
|
|
|
39 |
if(neighbours[dst].size() <= 0){
|
|
|
40 |
rt->removeFlow(addr,"", dst);
|
|
|
41 |
neighbours.erase(dst);
|
|
|
42 |
routingUpdated();
|
|
|
43 |
}
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
//Routing has processes a routing update
|
|
|
47 |
void SingleDomainGenerator::routingUpdated(){
|
|
|
48 |
DMRnms::dmUpdateM changes = rt->getChanges();
|
|
|
49 |
for(DMRnms::dmUpdateMIt it = changes.begin(); it!= changes.end(); it++){
|
|
|
50 |
for(DMRnms::s2AIt eIt = it->entries.begin(); eIt != it->entries.end(); eIt++){
|
|
|
51 |
std::string dst = eIt->first;
|
|
|
52 |
std::string nextHop = eIt->second.getIpcAddress().getName();
|
|
|
53 |
|
|
|
54 |
EV << "Entry ::: "<< dst << " -> " << nextHop << " ("<< eIt->second<<")" <<endl;
|
|
|
55 |
RMTPort * p = NULL;
|
|
|
56 |
|
|
|
57 |
NTableIt n = neighbours.find(nextHop);
|
|
|
58 |
if(n != neighbours.end()){
|
|
|
59 |
p = *(n->second.begin());
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
if(p == NULL) {
|
|
|
63 |
fwd->remove(dst);
|
|
|
64 |
} else {
|
|
|
65 |
fwd->insert(dst, p);
|
|
|
66 |
}
|
|
|
67 |
}
|
|
|
68 |
}
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
// Called after initialize
|
|
|
72 |
void SingleDomainGenerator::onPolicyInit(){
|
|
|
73 |
//Set Forwarding policy
|
|
|
74 |
fwd = check_and_cast<MiniTable::MiniTable *>
|
|
|
75 |
(getModuleByPath("^.^.relayAndMux.pduForwardingPolicy"));
|
|
|
76 |
|
|
|
77 |
rt = check_and_cast<DMRnms::Routing *>
|
|
|
78 |
(getModuleByPath("^.^.routingPolicy"));
|
|
|
79 |
|
|
|
80 |
std::string alg = par("alg").stdstringValue();
|
|
|
81 |
|
|
|
82 |
if(alg == "LS"){
|
|
|
83 |
rt->addDomain("", getParentModule()->getParentModule()->par("ipcAddress").stringValue(), DMRnms::LS);
|
|
|
84 |
} else {
|
|
|
85 |
rt->addDomain("", getParentModule()->getParentModule()->par("ipcAddress").stringValue(), DMRnms::DV);
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
|
|
|
89 |
difA = check_and_cast<DA *>(getModuleByPath("^.^.^.difAllocator.da"));
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
}
|