forked from Mirror/frr
babeld: changes for code maintainability
these changes are for improving the code maintainability and readability Signed-off-by: sri-mohan1 <sri.mohan@samsung.com>
This commit is contained in:
parent
21b7f32a2c
commit
c8287d97db
|
@ -34,15 +34,13 @@ find_neighbour_nocreate(const unsigned char *address, struct interface *ifp)
|
|||
{
|
||||
struct neighbour *neigh;
|
||||
FOR_ALL_NEIGHBOURS(neigh) {
|
||||
if(memcmp(address, neigh->address, 16) == 0 &&
|
||||
neigh->ifp == ifp)
|
||||
if(memcmp(address, neigh->address, 16) == 0 && neigh->ifp == ifp)
|
||||
return neigh;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
flush_neighbour(struct neighbour *neigh)
|
||||
void flush_neighbour(struct neighbour *neigh)
|
||||
{
|
||||
debugf(BABEL_DEBUG_COMMON,"Flushing neighbour %s (reach 0x%04x)",
|
||||
format_address(neigh->address), neigh->reach);
|
||||
|
@ -102,8 +100,7 @@ find_neighbour(const unsigned char *address, struct interface *ifp)
|
|||
}
|
||||
|
||||
/* Recompute a neighbour's rxcost. Return true if anything changed. */
|
||||
int
|
||||
update_neighbour(struct neighbour *neigh, int hello, int hello_interval)
|
||||
int update_neighbour(struct neighbour *neigh, int hello, int hello_interval)
|
||||
{
|
||||
int missed_hellos;
|
||||
int rc = 0;
|
||||
|
@ -160,26 +157,26 @@ update_neighbour(struct neighbour *neigh, int hello, int hello_interval)
|
|||
if(hello >= 0) {
|
||||
neigh->hello_seqno = hello;
|
||||
neigh->reach >>= 1;
|
||||
neigh->reach |= 0x8000;
|
||||
if((neigh->reach & 0xFC00) != 0xFC00)
|
||||
SET_FLAG(neigh->reach, 0x8000);
|
||||
if(CHECK_FLAG(neigh->reach, 0xFC00) != 0xFC00)
|
||||
rc = 1;
|
||||
}
|
||||
|
||||
/* Make sure to give neighbours some feedback early after association */
|
||||
if((neigh->reach & 0xBF00) == 0x8000) {
|
||||
if(CHECK_FLAG(neigh->reach, 0xBF00) == 0x8000) {
|
||||
/* A new neighbour */
|
||||
send_hello(neigh->ifp);
|
||||
} else {
|
||||
/* Don't send hellos, in order to avoid a positive feedback loop. */
|
||||
int a = (neigh->reach & 0xC000);
|
||||
int b = (neigh->reach & 0x3000);
|
||||
int a = CHECK_FLAG(neigh->reach, 0xC000);
|
||||
int b = CHECK_FLAG(neigh->reach, 0x3000);
|
||||
if((a == 0xC000 && b == 0) || (a == 0 && b == 0x3000)) {
|
||||
/* Reachability is either 1100 or 0011 */
|
||||
send_self_update(neigh->ifp);
|
||||
}
|
||||
}
|
||||
|
||||
if((neigh->reach & 0xFC00) == 0xC000) {
|
||||
if(CHECK_FLAG(neigh->reach, 0xFC00) == 0xC000) {
|
||||
/* This is a newish neighbour, let's request a full route dump.
|
||||
We ought to avoid this when the network is dense */
|
||||
send_unicast_request(neigh, NULL, 0);
|
||||
|
@ -188,8 +185,7 @@ update_neighbour(struct neighbour *neigh, int hello, int hello_interval)
|
|||
return rc;
|
||||
}
|
||||
|
||||
static int
|
||||
reset_txcost(struct neighbour *neigh)
|
||||
static int reset_txcost(struct neighbour *neigh)
|
||||
{
|
||||
unsigned delay;
|
||||
|
||||
|
@ -199,9 +195,8 @@ reset_txcost(struct neighbour *neigh)
|
|||
return 0;
|
||||
|
||||
/* If we're losing a lot of packets, we probably lost an IHU too */
|
||||
if(delay >= 180000 || (neigh->reach & 0xFFF0) == 0 ||
|
||||
(neigh->ihu_interval > 0 &&
|
||||
delay >= neigh->ihu_interval * 10U * 10U)) {
|
||||
if (delay >= 180000 || CHECK_FLAG(neigh->reach, 0xFFF0) == 0 ||
|
||||
(neigh->ihu_interval > 0 && delay >= neigh->ihu_interval * 10U * 10U)) {
|
||||
neigh->txcost = INFINITY;
|
||||
neigh->ihu_time = babel_now;
|
||||
return 1;
|
||||
|
@ -210,14 +205,12 @@ reset_txcost(struct neighbour *neigh)
|
|||
return 0;
|
||||
}
|
||||
|
||||
unsigned
|
||||
neighbour_txcost(struct neighbour *neigh)
|
||||
unsigned neighbour_txcost(struct neighbour *neigh)
|
||||
{
|
||||
return neigh->txcost;
|
||||
}
|
||||
|
||||
unsigned
|
||||
check_neighbours(void)
|
||||
unsigned check_neighbours(void)
|
||||
{
|
||||
struct neighbour *neigh;
|
||||
int changed, rc;
|
||||
|
@ -253,21 +246,20 @@ check_neighbours(void)
|
|||
return msecs;
|
||||
}
|
||||
|
||||
unsigned
|
||||
neighbour_rxcost(struct neighbour *neigh)
|
||||
unsigned neighbour_rxcost(struct neighbour *neigh)
|
||||
{
|
||||
unsigned delay;
|
||||
unsigned short reach = neigh->reach;
|
||||
|
||||
delay = timeval_minus_msec(&babel_now, &neigh->hello_time);
|
||||
|
||||
if((reach & 0xFFF0) == 0 || delay >= 180000) {
|
||||
if(CHECK_FLAG(reach, 0xFFF0) == 0 || delay >= 180000) {
|
||||
return INFINITY;
|
||||
} else if(babel_get_if_nfo(neigh->ifp)->flags & BABEL_IF_LQ) {
|
||||
} else if (CHECK_FLAG(babel_get_if_nfo(neigh->ifp)->flags, BABEL_IF_LQ)) {
|
||||
int sreach =
|
||||
((reach & 0x8000) >> 2) +
|
||||
((reach & 0x4000) >> 1) +
|
||||
(reach & 0x3FFF);
|
||||
(CHECK_FLAG(reach, 0x8000) >> 2) +
|
||||
(CHECK_FLAG(reach, 0x4000) >> 1) +
|
||||
CHECK_FLAG(reach, 0x3FFF);
|
||||
/* 0 <= sreach <= 0x7FFF */
|
||||
int cost = (0x8000 * babel_get_if_nfo(neigh->ifp)->cost) / (sreach + 1);
|
||||
/* cost >= interface->cost */
|
||||
|
@ -276,19 +268,18 @@ neighbour_rxcost(struct neighbour *neigh)
|
|||
return MIN(cost, INFINITY);
|
||||
} else {
|
||||
/* To lose one hello is a misfortune, to lose two is carelessness. */
|
||||
if((reach & 0xC000) == 0xC000)
|
||||
if (CHECK_FLAG(reach, 0xC000) == 0xC000)
|
||||
return babel_get_if_nfo(neigh->ifp)->cost;
|
||||
else if((reach & 0xC000) == 0)
|
||||
else if (CHECK_FLAG(reach, 0xC000) == 0)
|
||||
return INFINITY;
|
||||
else if((reach & 0x2000))
|
||||
else if (CHECK_FLAG(reach, 0x2000))
|
||||
return babel_get_if_nfo(neigh->ifp)->cost;
|
||||
else
|
||||
return INFINITY;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned
|
||||
neighbour_rttcost(struct neighbour *neigh)
|
||||
unsigned neighbour_rttcost(struct neighbour *neigh)
|
||||
{
|
||||
struct interface *ifp = neigh->ifp;
|
||||
babel_interface_nfo *babel_ifp = babel_get_if_nfo(ifp);
|
||||
|
@ -304,15 +295,14 @@ neighbour_rttcost(struct neighbour *neigh)
|
|||
(unsigned long long)babel_ifp->max_rtt_penalty *
|
||||
(neigh->rtt - babel_ifp->rtt_min) /
|
||||
(babel_ifp->rtt_max - babel_ifp->rtt_min);
|
||||
assert((tmp & 0x7FFFFFFF) == tmp);
|
||||
assert(CHECK_FLAG(tmp, 0x7FFFFFFF) == tmp);
|
||||
return tmp;
|
||||
} else {
|
||||
return babel_ifp->max_rtt_penalty;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned
|
||||
neighbour_cost(struct neighbour *neigh)
|
||||
unsigned neighbour_cost(struct neighbour *neigh)
|
||||
{
|
||||
unsigned a, b, cost;
|
||||
|
||||
|
@ -328,7 +318,7 @@ neighbour_cost(struct neighbour *neigh)
|
|||
if(b >= INFINITY)
|
||||
return INFINITY;
|
||||
|
||||
if(!(babel_get_if_nfo(neigh->ifp)->flags & BABEL_IF_LQ)
|
||||
if (!CHECK_FLAG(babel_get_if_nfo(neigh->ifp)->flags, BABEL_IF_LQ)
|
||||
|| (a < 256 && b < 256)) {
|
||||
cost = a;
|
||||
} else {
|
||||
|
@ -347,8 +337,7 @@ neighbour_cost(struct neighbour *neigh)
|
|||
return MIN(cost, INFINITY);
|
||||
}
|
||||
|
||||
int
|
||||
valid_rtt(struct neighbour *neigh)
|
||||
int valid_rtt(struct neighbour *neigh)
|
||||
{
|
||||
return (timeval_minus_msec(&babel_now, &neigh->rtt_time) < 180000) ? 1 : 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue