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)
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
route_interferes(struct route *route, struct network *net)
{
......@@ -298,14 +308,21 @@ route_interferes(struct route *route, struct network *net)
case DIVERSITY_INTERFACE_1:
return route->neigh->network == net;
case DIVERSITY_CHANNEL_1:
if(route->neigh->network->channel == NET_CHANNEL_NONINTERFERING ||
net->channel == NET_CHANNEL_NONINTERFERING)
return 0;
else if(route->neigh->network->channel == NET_CHANNEL_INTERFERING ||
net->channel == NET_CHANNEL_INTERFERING)
case DIVERSITY_CHANNEL:
if(route->neigh->network == net)
return 1;
else
return route->neigh->network->channel == net->channel;
if(channels_interfere(net->channel, route->neigh->network->channel))
return 1;
if(diversity_kind == DIVERSITY_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:
fprintf(stderr, "Unknown kind of diversity.\n");
return 1;
......@@ -510,6 +527,7 @@ update_route(const unsigned char *a, const unsigned char *p, unsigned char plen,
route->time = now.tv_sec;
route->hold_time = hold_time;
route->installed = 0;
memset(&route->channels, 0, sizeof(route->channels));
numroutes++;
local_notify_route(route, LOCAL_ADD);
consider_route(route);
......
......@@ -20,6 +20,13 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
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 source *src;
unsigned short refmetric;
......@@ -31,6 +38,7 @@ struct route {
time_t time;
unsigned short hold_time; /* in seconds */
short installed;
unsigned char channels[DIVERSITY_HOPS];
};
static inline int
......@@ -40,11 +48,6 @@ route_metric(const struct route *route)
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 int numroutes, maxroutes;
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