Download this file

SimpleLS.h    185 lines (147 with data), 4.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
 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
//
// 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/.
//
#ifndef SimpleLS_H_
#define SimpleLS_H_
#include <IntSimpleRouting.h>
#include <vector>
#include <map>
namespace SimpleLS {
struct linksU{
unsigned int sId;
std::map<std::string, unsigned short> links;
linksU(){
sId = 0;
}
linksU(const unsigned int &_sId){
sId = _sId;
}
};
typedef std::map<std::string, linksU> linksSt;
typedef std::pair<std::string, linksU> linksStEntry;
typedef std::map<unsigned short, linksSt> linksStCol;
typedef std::pair<unsigned short, linksSt> linksStColEntry;
typedef std::map<std::string, unsigned short>::iterator linksIt;
typedef linksSt::iterator linksStIt;
typedef linksStCol::iterator linksStColIt;
typedef std::map<Address, unsigned short> neighMetric;
typedef std::map<unsigned short, neighMetric> qosNeighMetric;
typedef neighMetric::iterator neighMetricIt;
typedef qosNeighMetric::iterator qosNeighMetricIt;
typedef std::set<unsigned short> qosSet;
typedef std::set<std::string> addrSet;
typedef std::vector<std::string> addrList;
typedef std::map<unsigned short, addrSet> qos2addrSet;
typedef std::pair<unsigned short, addrSet> qos2addrSetEntry;
typedef qosSet::iterator qosSetIt;
typedef addrSet::iterator addrSetIt;
typedef qos2addrSet::iterator qos2addrSetIt;
struct TreeNode {
std::string addr;
unsigned short metric;
std::set<TreeNode*> chl;
TreeNode(){
addr = "";
metric = UINT16_MAX;
}
TreeNode(const std::string &_addr, const unsigned short &_metric){
addr = _addr;
metric = _metric;
}
bool operator == (const TreeNode &b) const
{
return addr == b.addr;
}
bool operator < (const TreeNode &b) const
{
return addr < b.addr;
}
~TreeNode(){
for(std::set<TreeNode *>::iterator it = chl.begin(); it != chl.end(); it++){
TreeNode * c = *it;
delete c;
}
}
};
typedef std::set<TreeNode *>::iterator TreeNodeIt;
struct psT {
TreeNode* p;
unsigned short metric;
psT(){
p = NULL;
metric = UINT16_MAX;
}
psT(TreeNode* _p, const unsigned short _metric){
p = _p;
metric = _metric;
}
bool operator == (const psT &b) const
{
return p == b.p;
}
bool operator < (const psT &b) const
{
return p < b.p;
}
};
typedef std::map<std::string, psT > wMap;
typedef std::map<std::string, unsigned short > aMap;
typedef wMap::iterator wMapIt;
typedef aMap::iterator aMapIt;
typedef std::vector<wMapIt> mList;
typedef mList::iterator mListIt;
class RoutingUpdate : public IntRoutingUpdate {
public:
RoutingUpdate(const Address &_addr, const unsigned short &_qos);
unsigned short getQoS();
void addEntry(const std::string &, linksU);
void setEntries(linksSt);
linksStIt entriesBegin();
linksStIt entriesEnd();
protected:
unsigned short qos;
linksSt entries;
};
class SimpleLS: public IntSimpleRouting {
public:
//Process a Routing Update, return true => inform FWDG of the update
bool processUpdate(IntRoutingUpdate * update);
//Flow inserted/removed
void insertFlow(const Address &addr, const std::string &dst, const unsigned short &qos, const unsigned short &metric);
void removeFlow(const Address &addr, const std::string &dst, const unsigned short &qos);
//Get Changes
entries2Next getChanges();
entries2Next getAll();
void handleMessage(cMessage *msg);
void finish();
protected:
// Called after initialize
void onPolicyInit();
private:
unsigned short infMetric;
std::string myAddr;
qosNeighMetric neig;
linksStCol netState;
qos2addrSet lastChanges;
unsigned int secId;
linksSt getChangedEntries (const unsigned short &qos);
TreeNode constructTree(linksSt &ls);
void addRecursive(entries2Next &ret, const unsigned short &qos, const std::string &next, TreeNode * t);
bool scheduledUpdate;
void scheduleUpdate();
entries2Next table;
void printTreeNode(TreeNode *t, const std::string &next);
};
}
#endif /* SimpleLS_H_ */