Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F120655509
utilrouting.hh
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Jul 6, 00:59
Size
8 KB
Mime Type
text/x-c
Expires
Tue, Jul 8, 00:59 (2 d)
Engine
blob
Format
Raw Data
Handle
27206925
Attached To
R6591 HyMAB
utilrouting.hh
View Options
#ifndef UTILROUTING_HH
#define UTILROUTING_HH
#include "util.hh"
#define MAX_NB_NEIGHBORS 10u
#define MAX_FREQ_LS_PACKET_SEC 10u
#define MIN_FREQ_LS_PACKET_SEC 30u
#define MAX_FREQ_CONT_LINKS 60u
#define FREQ_CONT_LINKS_PACKET 30u
#define DEFAULT_FREQ_PRINT 10u
#define MIN_TIME_WEIGHT_UPDATE 300u
#define MAX_SEQ_NB 256u // seq numbers between 0 and MAX_SEQ_NB-1
#define MAX_LOST_LS_PACKET 5u
#define THRES_WEIGHT_GOOD_NEI 30u
#define SCALE_WEIGHTS 524288u // 2^19
#define MAX_PATHS_METRIC 2
CLICK_DECLS
struct ShortNeighbor {
EtherAddress eth;
uint32_t weight;
};
struct MPR {
EtherAddress eth;
};
struct linkstate_header {
uint8_t _type;
#define LS_PACKET 1
bool _MPR_retr_bool; // true if only MPRs should retransmit
uint8_t _nb_retr; // number of retransmitters
MPR _retr[]; // retransmitters
};
struct linkstate_packet {
uint8_t _seq; // sequence number of the linkstate header
struct in_addr _src_ip_node; // indicates the transmitting node's IP address
EtherAddress _src_eth_int; // indicates the transmitting interface's Ethernet address
uint8_t _nb_neighbors; // indicates total number of neighbors
bool _has_invalid_routes;
bool _delete_interface;
bool _has_different_neighbors;
bool _is_reliable; // is not reliable at the beginning
bool _is_wifi; // if plc, is false
ShortNeighbor _neighbors[]; // indicates the neighbors
};
struct invalid_routes_packet {
uint8_t _nb_invalid_routes;
FormatedRoute _invalid_routes[];
};
struct VirtualNodeRouting {
// a virtual node is a type and an address
unsigned char type;
#define SRC_VN 1
#define DST_VN 2
#define ING_VN 3
#define EGR_VN 4
// address is ip if SRC_VN or DST_VN, is eth if ING_VN or EGR_VN
IPAddress ip;
EtherAddress eth;
VirtualNodeRouting() {
type = 0;
}
VirtualNodeRouting(unsigned char t, IPAddress addr) {
assert(t==SRC_VN || t==DST_VN);
type = t;
ip = addr;
}
VirtualNodeRouting(unsigned char t, EtherAddress addr) {
assert(t==ING_VN || t==EGR_VN);
type = t;
eth = addr;
}
uint32_t
hashcode() const {
switch (type) {
case 0: {
return type;
}
case SRC_VN: {
return (type+ip.hashcode());
}
case DST_VN: {
return (type+ip.hashcode());
}
case ING_VN: {
return (type+eth.hashcode());
}
case EGR_VN: {
return (type+eth.hashcode());
}
default:
return 0;
}
}
inline bool operator==(const VirtualNodeRouting a) const
{
switch (type) {
case 0: {
return (a.type == type);
}
case SRC_VN: {
return (a.type == type && a.ip == ip);
}
case DST_VN: {
return (a.type == type && a.ip == ip);
}
case ING_VN: {
return (a.type == type && a.eth == eth);
}
case EGR_VN: {
return (a.type == type && a.eth == eth);
}
default:
return false;
}
}
inline bool operator!=(const VirtualNodeRouting a) const
{
switch (type) {
case 0: {
return (a.type != type);
}
case SRC_VN: {
return (a.type != type || a.ip != ip);
}
case DST_VN: {
return (a.type != type || a.ip != ip);
}
case ING_VN: {
return (a.type != type || a.eth != eth);
}
case EGR_VN: {
return (a.type != type || a.eth != eth);
}
default:
return true;
}
}
String
unparse() const {
String s = "";
switch (type) {
case 0: {
s+="NULL ";
break;
}
case SRC_VN: {
s+="SRC_VN ";
s+=ip.unparse();
break;
}
case DST_VN: {
s+="DST_VN ";
s+=ip.unparse();
break;
}
case ING_VN: {
s+="ING_VN ";
s+=eth.unparse();
break;
}
case EGR_VN: {
s+="EGR_VN ";
s+=eth.unparse();
break;
}
}
return s;
}
};
struct VirtualNeighbor {
VirtualNodeRouting neighbor;
uint32_t weight;
VirtualNeighbor() {
neighbor = VirtualNodeRouting();
}
VirtualNeighbor(VirtualNodeRouting node, uint32_t w) {
neighbor = node;
weight = w;
}
inline bool operator==(const VirtualNeighbor a) const
{
return (a.neighbor == neighbor);
}
inline bool operator!=(const VirtualNeighbor a) const
{
return a.neighbor!=neighbor;
}
String
unparse() const {
String s = "(";
s+=neighbor.unparse();
s+=";";
s+=String(weight);
s+=")";
return s;
}
};
typedef HashTable<VirtualNodeRouting,Vector<VirtualNeighbor> > AdjacencyMatrix;
struct VirtualRoute {
Vector<VirtualNeighbor> route;
uint32_t weight;
VirtualRoute() {
route = Vector<VirtualNeighbor>();
weight = 0;
}
void add_node(VirtualNeighbor n) {
route.push_back(n);
weight += n.weight;
}
VirtualRoute concat_routes(VirtualRoute second, AdjacencyMatrix adj_mat) {
VirtualRoute totalRoute;
if(route.size() > 0) {
int ind = find_in_vector(adj_mat[route.back().neighbor], second.route[0]);
second.route[0].weight = adj_mat[route.back().neighbor][ind].weight;
second.weight += second.route[0].weight;
}
totalRoute.route = concat_vectors(route, second.route);
totalRoute.weight = weight + second.weight;
return totalRoute;
}
inline bool operator==(const VirtualRoute a) const
{
return equals_vector(route, a.route);
}
inline bool operator!=(const VirtualRoute a) const
{
return ~(equals_vector(route, a.route));
}
String unparse() {
String s = print_vector(route);
s+="; total weight ";
s+= String(weight);
return s;
}
};
struct SetNeighbor {
Vector<VirtualNeighbor> set;
void insert_neighbor(VirtualNeighbor n) {
if (!is_in_vector(set, n)) {
set.push_back(n);
}
}
void erase_neighbor(VirtualNeighbor n) {
Vector<VirtualNeighbor>::iterator to_delete=0;
int i=0;
for (Vector<VirtualNeighbor>::iterator it=set.begin();it!=set.end();it++) {
if (n==set[i]) {
to_delete = it;
break;
}
i++;
}
if(to_delete!=0) {
set.erase(to_delete);
}
}
bool empty() {
return set.empty();
}
VirtualNeighbor begin() {
return *set.begin();
}
};
template<typename T>
struct SortedVector {
// vector sorted in decreasing order
Vector<T> vector;
SortedVector() {
vector = Vector<T>();
}
void push(T a) {
// non optimal push
if(vector.size() == 0)
vector.push_back(a);
else {
int ind=0;
while(ind < vector.size() && vector[ind] > a) {
ind++;
}
if(ind == vector.size())
vector.push_back(a);
else
vector.insert(&vector[ind], a);
}
}
T back() {
if (vector.isempty()) {
return 0;
}
else {
return vector.back();
}
}
void pop_back() {
vector.pop_back();
}
void clear() {
vector.clear();
}
int length() {
return vector.size();
}
T operator[](int i) {
return vector[i];
}
};
struct MultiPathDemand {
IPAddress _dst;
int _N;
int _n;
MultiPathDemand(IPAddress dst, int N, int n) {
_dst = dst;
if (n == 1)
_N = 1;
else
_N = N;
_n = n;
}
inline bool operator==(const MultiPathDemand a) const
{
return (a._dst == _dst && a._N == _N && a._n == _n);
}
inline bool operator!=(const MultiPathDemand a) const
{
return !(a._dst == _dst && a._N == _N && a._n == _n);
}
inline uint32_t hashcode() const {
return (_dst.hashcode() + 10*_N + _n);
}
};
typedef HashTable<UndirectedLinkRouting, HashTable<UndirectedLinkRouting,bool> > ContLinksMatrix;
CLICK_ENDDECLS
#endif // UTILROUTING_HH
Event Timeline
Log In to Comment