Calculate rxcost
This commit is contained in:
parent
afffa65f90
commit
af79e547f8
2 changed files with 17 additions and 7 deletions
22
ffd/ffd.c
22
ffd/ffd.c
|
@ -167,15 +167,12 @@ static inline ffd_neigh_t* get_neigh(const ffd_iface_t *iface, const eth_addr_t
|
||||||
static ffd_neigh_t* get_neigh_create(ffd_iface_t *iface, const eth_addr_t *addr) {
|
static ffd_neigh_t* get_neigh_create(ffd_iface_t *iface, const eth_addr_t *addr) {
|
||||||
ffd_neigh_t *neigh = get_neigh(iface, addr);
|
ffd_neigh_t *neigh = get_neigh(iface, addr);
|
||||||
if (!neigh) {
|
if (!neigh) {
|
||||||
neigh = malloc(sizeof(ffd_neigh_t));
|
neigh = calloc(1, sizeof(ffd_neigh_t));
|
||||||
neigh->next = iface->neigh_list;
|
neigh->next = iface->neigh_list;
|
||||||
iface->neigh_list = neigh;
|
iface->neigh_list = neigh;
|
||||||
|
|
||||||
neigh->addr = *addr;
|
neigh->addr = *addr;
|
||||||
neigh->hello_log = 0;
|
|
||||||
neigh->hello_interval = 0;
|
neigh->txcost = 0xffff;
|
||||||
neigh->last_seqno = 0;
|
|
||||||
neigh->last_hello = (struct timespec){};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return neigh;
|
return neigh;
|
||||||
|
@ -189,6 +186,17 @@ static void free_neighs(ffd_neigh_t *neigh) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint16_t neigh_get_rxcost(ffd_neigh_t *neigh) {
|
||||||
|
int timediff = timespec_diff(&now, &neigh->last_hello)/10;
|
||||||
|
int shift = (timediff - neigh->hello_interval/2)/neigh->hello_interval;
|
||||||
|
int received = __builtin_popcount(neigh->hello_log << shift);
|
||||||
|
|
||||||
|
if (received == 0)
|
||||||
|
return 0xffff;
|
||||||
|
else
|
||||||
|
return (0x1000/received);
|
||||||
|
}
|
||||||
|
|
||||||
static void update_netifs() {
|
static void update_netifs() {
|
||||||
ffd_iface_t *iface, **cur;
|
ffd_iface_t *iface, **cur;
|
||||||
|
|
||||||
|
@ -308,7 +316,7 @@ static void handle_tlv_hello(const ffd_tlv_hello_t *tlv_hello, size_t len, const
|
||||||
neigh->last_seqno = seqno;
|
neigh->last_seqno = seqno;
|
||||||
neigh->last_hello = now;
|
neigh->last_hello = now;
|
||||||
|
|
||||||
fprintf(stderr, "debug: accepted hello, log %04x.\n", neigh->hello_log);
|
fprintf(stderr, "debug: accepted hello, log %04x, rxcost is %u now.\n", neigh->hello_log, neigh_get_rxcost(neigh));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_tlv(ffd_tlv_type_t type, const void *data, size_t len, void *arg) {
|
static void handle_tlv(ffd_tlv_type_t type, const void *data, size_t len, void *arg) {
|
||||||
|
|
|
@ -50,6 +50,8 @@ typedef struct _ffd_neigh_t {
|
||||||
uint16_t hello_interval;
|
uint16_t hello_interval;
|
||||||
uint16_t last_seqno;
|
uint16_t last_seqno;
|
||||||
struct timespec last_hello;
|
struct timespec last_hello;
|
||||||
|
|
||||||
|
uint16_t txcost;
|
||||||
} ffd_neigh_t;
|
} ffd_neigh_t;
|
||||||
|
|
||||||
typedef struct _ffd_iface_t {
|
typedef struct _ffd_iface_t {
|
||||||
|
|
Reference in a new issue