forked from wujingbang/aodv-Android
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroute_alg.c
More file actions
executable file
·106 lines (83 loc) · 3.06 KB
/
route_alg.c
File metadata and controls
executable file
·106 lines (83 loc) · 3.06 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
/***************************************************************************
Created by Miguel Catalan Cid - miguel.catcid@gmail.com - Version: Mon Jan 1 2010
***************************************************************************/
#include "route_alg.h"
extern aodv_dev* g_mesh_dev;
extern aodv_neigh *aodv_neigh_list;
extern aodv_neigh_2h *aodv_neigh_list_2h;
int ett_metric(aodv_neigh *tmp_neigh, rreq *tmp_rreq) {
if (tmp_neigh->recv_rate == 0 || tmp_neigh->send_rate == 0 || tmp_neigh->etx_metric == 0)
return 1;
tmp_rreq->path_metric +=(PROBE_PACKET*1000)/(tmp_neigh->recv_rate*tmp_neigh->etx_metric); //ETT in microseconds
return 0;
}
u_int8_t compute_coef(u_int16_t size, u_int16_t rate) {
u_int32_t other_delays = 122*100; //122 usecs (DIFS, SIFS, ACK)
u_int32_t headers = 470*1000; //470 bits
u_int32_t nominal_delay = size*8000;
u_int32_t coef = nominal_delay + headers;
u_int32_t u_rate = rate;
if (size == 0 || rate == 0)
return 0;
nominal_delay = nominal_delay/u_rate;
coef= coef/u_rate;
coef += other_delays;
coef = (nominal_delay*100)/coef;
return (u_int8_t)coef;
}
int wcim_metric(aodv_neigh *tmp_neigh, rreq *tmp_rreq) {
int i, alpha;
u_int8_t coef_recv;
u_int8_t load;
u_int16_t recv_bw;
flow_type *flow;
aodv_neigh *load_neigh;
aodv_neigh_2h *load_neigh_2h;
if (tmp_neigh->recv_rate == 0 || tmp_neigh->send_rate == 0 || tmp_neigh->etx_metric == 0)
return 1;
flow = find_flow_type(tmp_rreq->tos);
coef_recv = compute_coef(flow->avg_size, tmp_neigh->recv_rate);
recv_bw = (tmp_neigh->recv_rate*tmp_neigh->etx_metric*coef_recv)/100; //in Kbps
load = g_mesh_dev->load; //my own load
load_neigh = aodv_neigh_list;
while (load_neigh != NULL){ //my one-hop neighbors
if (load_neigh->ip == tmp_neigh->ip)
load += tmp_neigh->load_metric.load;//load of my neighbor
else{
alpha = 2; //hidden node?
for (i=0; i< NEIGH_TABLESIZE; i++) {
if (tmp_neigh->load_metric.neigh_tx[i] != 0) {
if (tmp_neigh->load_metric.neigh_tx[i] == load_neigh->ip) { //it's also a neighbor of the transmitter
alpha = 1;
break;
}
}
}
//alpha = 1 if neigbor of the transmitter (break)
//alpha = 2 if hidden node (not found in load_metric.neigh_tx[i])
load+=load_neigh->load_metric.load*alpha;
}
load_neigh = load_neigh->next;
}
load_neigh_2h = aodv_neigh_list_2h;
while (load_neigh_2h != NULL){ //my two-hop neighbors
alpha = 1; //two-hops neigbhor?
for (i=0; i< NEIGH_TABLESIZE; i++) {
if (tmp_neigh->load_metric.neigh_tx[i] != 0) {
if (tmp_neigh->load_metric.neigh_tx[i] == load_neigh_2h->ip) { //it's also a neighbor of the transmitter
alpha = 2;
break;
}
}
}
//alpha = 1/2 if a two-hops neighbor of the receiver
//alpha = 1 if a one-hop neighbor of the receiver
load+=(load_neigh_2h->load*alpha)/2;
load_neigh_2h = load_neigh_2h->next;
}
recv_bw = (recv_bw*(100-load))/100;
if (recv_bw <= flow->avg_rate) //not enough bw for the new flow
return 1;
tmp_rreq->path_metric +=(flow->avg_size*8000)/recv_bw; //in microseconds
return 0;
}