Download this file

LS.h    145 lines (104 with data), 3.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
142
143
144
/*
* LS.h
*
* Created on: Mar 23, 2015
* Author: gaixas1
*/
#ifndef LS_H_
#define LS_H_
#include <DomainRouting/rModule.h>
namespace DMRnmsLS {
using namespace DMRnms;
///////////////////////////////////////////////////////////////////////
// Data structures
typedef std::map<std::string, unsigned short> s2m;
typedef s2m::iterator s2mIt;
struct linksU{
unsigned int sId;
s2m links;
linksU()
:sId(0){}
linksU(const unsigned int &_sId)
:sId(_sId){}
};
typedef std::map<std::string, linksU> linksSt;
typedef linksSt::iterator linksStIt;
typedef std::map<Address, unsigned short> neighMetric;
typedef neighMetric::iterator neighMetricIt;
typedef std::set<std::string> sSet;
typedef sSet::iterator sSetIt;
typedef std::vector<std::string> sList;
typedef sList::iterator sListIt;
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 wMap::iterator wMapIt;
///////////////////////////////////////////////////////////////////////
// Update Message
class LSUpdate : public RoutingUpdate {
public:
LSUpdate(const Address &_addr, const std::string &_domain);
void addEntry(const std::string & _addr, linksU _neig);
void setEntries(linksSt _entries);
linksStIt entriesBegin();
linksStIt entriesEnd();
protected:
linksSt entries;
};
///////////////////////////////////////////////////////////////////////
// Routing Module
class LS: public rModule {
public:
LS(Routing * parent, const Address &_nAddr, const std::string &_domain, const std::string &_addr);
bool processUpdate(RoutingUpdate * update);
void addFlow(const Address &_nAddr, const std::string &_addr, const unsigned short &_metric);
void removeFlow(const Address &_nAddr, const std::string &_addr);
void addAddr(const std::string &_addr);
void removeAddr(const std::string &_addr);
void setInfMetric(const unsigned short &inf);
dmNxt getChanges();
dmNxt getAll();
void handleMessage(cMessage *msg);
protected:
sSet myAddrSet;
neighMetric nei;
unsigned short infMetric;
s2A neigTable;
linksSt netState;
unsigned int secId;
sSet changed;
linksSt getChangedEntries ();
s2A currentTable;
TreeNode constructTree();
void addRecursive(s2A &ret, const Address &next, TreeNode * t);
bool scheduledUpdate;
void scheduleUpdate();
};
} /* namespace DomainRoutingLS */
#endif /* LS_H_ */