Commit 31efc5c8 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Simplify computation of neighbour cost.

parent f0e3e486
...@@ -235,27 +235,26 @@ neighbour_rxcost(struct neighbour *neigh) ...@@ -235,27 +235,26 @@ neighbour_rxcost(struct neighbour *neigh)
int int
neighbour_cost(struct neighbour *neigh) neighbour_cost(struct neighbour *neigh)
{ {
int c; int a, b;
if(neigh->txcost >= INFINITY) a = neigh->txcost;
if(a >= INFINITY)
return INFINITY; return INFINITY;
c = neighbour_rxcost(neigh); b = neighbour_rxcost(neigh);
if(c >= INFINITY) if(b >= INFINITY)
return INFINITY; return INFINITY;
if(neigh->network->wired) { if(a <= 256 && b <= 256) {
/* On a wired interface, only the txcost is significant. return MAX(a, b);
However, a low txcost with a large rxcost probably indicates
a malfunctioning interface, so penalise it. This doesn't
matter much, as we usually don't perform link quality estimation
on wired interfaces. */
return MIN(INFINITY, MAX(neigh->txcost, c / 4));
} else { } else {
a = MAX(a, 256);
b = MAX(b, 256);
/* (1/(alpha * beta) + 1/beta) / 2, which is half the expected /* (1/(alpha * beta) + 1/beta) / 2, which is half the expected
number of transmissions, in both directions. number of transmissions, in both directions.
ETX uses 1/(alpha * beta), which is the expected number of ETX uses 1/(alpha * beta), which is the expected number of
transmissions in the forward direction. */ transmissions in the forward direction. */
return (c + ((c * neigh->txcost + 128) >> 8) + 1) / 2; return (((a * b + 128) >> 8) + b + 1) >> 1;
} }
} }
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