Re: [B.A.T.M.A.N.] [RFC 05/10] batman-adv: add bat_metric_is_similar API function

Simon Wunderlich
2013-05-29T14:16:57Z

[-- Attachment #1: Type: text/plain, Size: 1245 bytes --]

On Wed, May 29, 2013 at 12:20:45AM +0200, Antonio Quartulli wrote:
> From: Antonio Quartulli <antonio@open-mesh.com>
>
> Each routing protocol has its own metric semantic and
> therefore is the protocol itself the only component able to
> compare two metrics to check similarity similarity.
>
> This new API allows each routing protocol to implement its
> own logic and make the external code protocol agnostic.
>
> Signed-off-by: Antonio Quartulli <antonio@open-mesh.com>
> ---
> bat_iv_ogm.c | 7 +++++++
> main.c | 3 ++-
> main.h | 6 ++++++
> types.h | 3 +++
> 4 files changed, 18 insertions(+), 1 deletion(-)
>
> diff --git a/bat_iv_ogm.c b/bat_iv_ogm.c
> index abf4cd3..18c9ae8 100644
> --- a/bat_iv_ogm.c
> +++ b/bat_iv_ogm.c
> @@ -1441,6 +1441,12 @@ static uint32_t batadv_iv_ogm_metric_get(struct batadv_neigh_node *neigh_node)
> return neigh_node->bat_iv.tq_avg;
> }
>
> +static bool batadv_iv_ogm_metric_is_similar(uint32_t metric,
> + uint32_t new_metric)
> +{
> + return (metric - new_metric < BATADV_TQ_SIMILARITY_THRESHOLD);

You might want to use abs(metric - new_metric) here, otherwise is_similar(a, b) output
might differ from is_similar(b, a).
> +}
> +

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]