Download this file

SimpleGenerator.cc    88 lines (75 with data), 2.8 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
//
// 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 <SimpleGenerator/SimpleGenerator.h>
#include "APN.h"
namespace SimpleGenerator {
Register_Class(SimpleGenerator);
using namespace std;
// A new flow has been inserted/or removed
void SimpleGenerator::insertedFlow(const Address &addr, const unsigned short &qos, RMTPort * port){
std::string dst = addr.getIpcAddress().getName();
neighbours[dst][qos].insert(port);
if(neighbours[dst][qos].size() == 1){
rt->insertFlow(addr, dst, qos, 1);
routingUpdated();
}
}
void SimpleGenerator::removedFlow(const Address &addr, const unsigned short &qos, RMTPort * port){
std::string dst = addr.getIpcAddress().getName();
neighbours[dst][qos].erase(port);
if(neighbours[dst][qos].size() <= 0){
neighbours[dst].erase(qos);
rt->removeFlow(addr, dst, qos);
if(neighbours[dst].size() <= 0){
neighbours.erase(dst);
}
routingUpdated();
}
}
//Routing has processes a routing update
void SimpleGenerator::routingUpdated(){
entries2Next changes = rt->getChanges();
for(entries2NextIt it = changes.begin(); it!= changes.end(); it++){
qosPaddr dst = it->first;
std::string nextHop = it->second;
RMTPort * p = NULL;
if(nextHop != "") {
NTableIt n = neighbours.find(nextHop);
if(n != neighbours.end()){
NentriesIt pit = n->second.find(dst.first);
if(pit != n->second.end()){
if(pit->second.size()>0){
p = *(pit->second.begin());
}
}
}
}
if(p == NULL) {
fwd->remove(dst.second, dst.first);
} else {
fwd->insert(dst.second, dst.first, p);
}
}
}
// Called after initialize
void SimpleGenerator::onPolicyInit(){
//Set Forwarding policy
fwd = check_and_cast<SimpleTable::SimpleTable *>
(getModuleByPath("^.^.relayAndMux.pduForwardingPolicy"));
rt = check_and_cast<IntSimpleRouting *>
(getModuleByPath("^.^.routingPolicy"));
difA = check_and_cast<DA *>(getModuleByPath("^.^.^.difAllocator.da"));
}
}