From ae4505db19ae5c13b2c9367fc0fe586df515025b Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 29 Sep 2012 21:55:38 +0200 Subject: Add cost computation --- ffd/ffd.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/ffd/ffd.c b/ffd/ffd.c index 807a59a..b1668b0 100644 --- a/ffd/ffd.c +++ b/ffd/ffd.c @@ -47,7 +47,7 @@ static const eth_addr_t ffd_addr = {{0x03, 0x00, 0x00, 0x00, 0x0f, 0xfd}}; -#define HELLO_INTERVAL 1000 +#define HELLO_INTERVAL 400 #define IHU_INTERVAL (3*HELLO_INTERVAL) #define PACKET_MAX 1000 @@ -199,6 +199,19 @@ static uint16_t get_neigh_rxcost(const ffd_neigh_t *neigh) { return (0x1000/received); } +static uint16_t get_neigh_cost(const ffd_neigh_t *neigh) { + uint16_t txcost = neigh->txcost; + if (txcost < 256) + txcost = 256; + + uint32_t cost = (txcost * get_neigh_rxcost(neigh)) >> 8; + + if (cost > 0xffff) + return 0xffff; + else + return cost; +} + static void update_netifs() { ffd_iface_t *iface, **cur; @@ -339,7 +352,7 @@ static void handle_tlv_hello(const ffd_tlv_hello_t *tlv_hello, size_t len, const neigh->last_seqno = seqno; neigh->last_hello = now; - fprintf(stderr, "debug: accepted hello, log %04x, rxcost is %u now.\n", neigh->hello_log, get_neigh_rxcost(neigh)); + fprintf(stderr, "debug: accepted hello, log %04x, rxcost is %u, cost is %u now.\n", neigh->hello_log, get_neigh_rxcost(neigh), get_neigh_cost(neigh)); } static void handle_tlv_ihu(const ffd_tlv_ihu_t *tlv_ihu, size_t len, const eth_addr_t *addr, ffd_iface_t *iface) { @@ -365,7 +378,7 @@ static void handle_tlv_ihu(const ffd_tlv_ihu_t *tlv_ihu, size_t len, const eth_a neigh->last_ihu = now; neigh->txcost = ntohs(tlv_ihu->rxcost); - fprintf(stderr, "debug: accepted IHU, txcost is %u now.\n", neigh->txcost); + fprintf(stderr, "debug: accepted IHU, txcost is %u, cost is %u now.\n", neigh->txcost, get_neigh_cost(neigh)); } static void handle_tlv(ffd_tlv_type_t type, const void *data, size_t len, void *arg) { -- cgit v1.2.3