Commit 3513e223 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

First implementation of channel diversity with memory.

parent 939c5b34
...@@ -289,6 +289,16 @@ route_expired(struct route *route) ...@@ -289,6 +289,16 @@ route_expired(struct route *route)
return route->time < now.tv_sec - route->hold_time; return route->time < now.tv_sec - route->hold_time;
} }
static int
channels_interfere(unsigned char ch1, unsigned char ch2)
{
if(ch1 == NET_CHANNEL_NONINTERFERING || ch2 == NET_CHANNEL_NONINTERFERING)
return 0;
if(ch1 == NET_CHANNEL_INTERFERING || ch2 == NET_CHANNEL_INTERFERING)
return 1;
return ch1 == ch2;
}
int int
route_interferes(struct route *route, struct network *net) route_interferes(struct route *route, struct network *net)
{ {
...@@ -298,14 +308,21 @@ route_interferes(struct route *route, struct network *net) ...@@ -298,14 +308,21 @@ route_interferes(struct route *route, struct network *net)
case DIVERSITY_INTERFACE_1: case DIVERSITY_INTERFACE_1:
return route->neigh->network == net; return route->neigh->network == net;
case DIVERSITY_CHANNEL_1: case DIVERSITY_CHANNEL_1:
if(route->neigh->network->channel == NET_CHANNEL_NONINTERFERING || case DIVERSITY_CHANNEL:
net->channel == NET_CHANNEL_NONINTERFERING) if(route->neigh->network == net)
return 0; return 1;
else if(route->neigh->network->channel == NET_CHANNEL_INTERFERING || if(channels_interfere(net->channel, route->neigh->network->channel))
net->channel == NET_CHANNEL_INTERFERING)
return 1; return 1;
else if(diversity_kind == DIVERSITY_CHANNEL) {
return route->neigh->network->channel == net->channel; int i;
for(i = 0; i < DIVERSITY_HOPS; i++) {
if(route->channels[i] == 0)
break;
if(channels_interfere(net->channel, route->channels[i]))
return 1;
}
}
return 0;
default: default:
fprintf(stderr, "Unknown kind of diversity.\n"); fprintf(stderr, "Unknown kind of diversity.\n");
return 1; return 1;
...@@ -510,6 +527,7 @@ update_route(const unsigned char *a, const unsigned char *p, unsigned char plen, ...@@ -510,6 +527,7 @@ update_route(const unsigned char *a, const unsigned char *p, unsigned char plen,
route->time = now.tv_sec; route->time = now.tv_sec;
route->hold_time = hold_time; route->hold_time = hold_time;
route->installed = 0; route->installed = 0;
memset(&route->channels, 0, sizeof(route->channels));
numroutes++; numroutes++;
local_notify_route(route, LOCAL_ADD); local_notify_route(route, LOCAL_ADD);
consider_route(route); consider_route(route);
......
...@@ -20,6 +20,13 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN ...@@ -20,6 +20,13 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. THE SOFTWARE.
*/ */
#define DIVERSITY_NONE 0
#define DIVERSITY_INTERFACE_1 1
#define DIVERSITY_CHANNEL_1 2
#define DIVERSITY_CHANNEL 3
#define DIVERSITY_HOPS 8
struct route { struct route {
struct source *src; struct source *src;
unsigned short refmetric; unsigned short refmetric;
...@@ -31,6 +38,7 @@ struct route { ...@@ -31,6 +38,7 @@ struct route {
time_t time; time_t time;
unsigned short hold_time; /* in seconds */ unsigned short hold_time; /* in seconds */
short installed; short installed;
unsigned char channels[DIVERSITY_HOPS];
}; };
static inline int static inline int
...@@ -40,11 +48,6 @@ route_metric(const struct route *route) ...@@ -40,11 +48,6 @@ route_metric(const struct route *route)
return MIN(m, INFINITY); return MIN(m, INFINITY);
} }
#define DIVERSITY_NONE 0
#define DIVERSITY_INTERFACE_1 1
#define DIVERSITY_CHANNEL_1 2
#define DIVERSITY_CHANNEL 3
extern struct route *routes; extern struct route *routes;
extern int numroutes, maxroutes; extern int numroutes, maxroutes;
extern int kernel_metric, allow_duplicates; extern int kernel_metric, allow_duplicates;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment