All of lore.kernel.org
 help / color / mirror / Atom feed
From: Antonio Quartulli <ordex@autistici.org>
To: b.a.t.m.a.n@lists.open-mesh.org
Cc: Antonio Quartulli <antonio@open-mesh.com>
Subject: [B.A.T.M.A.N.] [RFC 06/10] batman-adv: add bat_metric_compare API function
Date: Wed, 29 May 2013 00:20:46 +0200	[thread overview]
Message-ID: <1369779649-2537-8-git-send-email-ordex@autistici.org> (raw)
In-Reply-To: <1369779649-2537-1-git-send-email-ordex@autistici.org>

From: Antonio Quartulli <antonio@open-mesh.com>

Add an API function to allow the routing protocol to
implement its own metric sorting logic.

In this way each routing protocol can play with its metric
semantic without exposing any detail to the rest of the
code.

Signed-off-by: Antonio Quartulli <antonio@open-mesh.com>
---
 bat_iv_ogm.c | 14 ++++++++++++++
 main.c       |  3 ++-
 types.h      |  2 ++
 3 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/bat_iv_ogm.c b/bat_iv_ogm.c
index 18c9ae8..97aa2fe 100644
--- a/bat_iv_ogm.c
+++ b/bat_iv_ogm.c
@@ -1447,6 +1447,19 @@ static bool batadv_iv_ogm_metric_is_similar(uint32_t metric,
 	return (metric - new_metric < BATADV_TQ_SIMILARITY_THRESHOLD);
 }
 
+/**
+ * batadv_iv_ogm_metric_compare - implement the bat_metric_compare API
+ * @metric1: the first metric to compare
+ * @metric2: the second metric to compare
+ *
+ * Return a value smaller, equal or greater than zero if metric1 is respectively
+ * smaller, equal or greater than metric2
+ */
+static int batadv_iv_ogm_metric_compare(uint32_t metric1, uint32_t metric2)
+{
+	return metric1 - metric2;
+}
+
 static struct batadv_algo_ops batadv_batman_iv __read_mostly = {
 	.name = "BATMAN_IV",
 	.bat_iface_enable = batadv_iv_ogm_iface_enable,
@@ -1457,6 +1470,7 @@ static struct batadv_algo_ops batadv_batman_iv __read_mostly = {
 	.bat_ogm_emit = batadv_iv_ogm_emit,
 	.bat_metric_get = batadv_iv_ogm_metric_get,
 	.bat_metric_is_similar = batadv_iv_ogm_metric_is_similar,
+	.bat_metric_compare = batadv_iv_ogm_metric_compare,
 	.bat_orig_print = batadv_iv_ogm_orig_print,
 };
 
diff --git a/main.c b/main.c
index d81f6d6..a5de41e 100644
--- a/main.c
+++ b/main.c
@@ -446,7 +446,8 @@ int batadv_algo_register(struct batadv_algo_ops *bat_algo_ops)
 	    !bat_algo_ops->bat_ogm_schedule ||
 	    !bat_algo_ops->bat_ogm_emit ||
 	    !bat_algo_ops->bat_metric_get ||
-	    !bat_algo_ops->bat_metric_is_similar) {
+	    !bat_algo_ops->bat_metric_is_similar ||
+	    !bat_algo_ops->bat_metric_compare) {
 		pr_info("Routing algo '%s' does not implement required ops\n",
 			bat_algo_ops->name);
 		ret = -EINVAL;
diff --git a/types.h b/types.h
index a2492a4..e2b2aaa 100644
--- a/types.h
+++ b/types.h
@@ -984,6 +984,7 @@ struct batadv_forw_packet {
  * @bat_ogm_emit: send scheduled OGM
  * @bat_metric_is_similar: check if new_metric is good enough to be comparable
  *  with metric
+ * @bat_metric_compare: compare two metric values
  * @bat_orig_print: print the originator table
  */
 struct batadv_algo_ops {
@@ -997,6 +998,7 @@ struct batadv_algo_ops {
 	void (*bat_ogm_emit)(struct batadv_forw_packet *forw_packet);
 	uint32_t (*bat_metric_get)(struct batadv_neigh_node *neigh_node);
 	bool (*bat_metric_is_similar)(uint32_t metric, uint32_t new_metric);
+	int (*bat_metric_compare)(uint32_t metric, uint32_t new_metric);
 	/* orig_node handling API */
 	void (*bat_orig_print)(struct batadv_priv *priv, struct seq_file *seq);
 };
-- 
1.8.1.5


  parent reply	other threads:[~2013-05-28 22:20 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-28 22:20 [B.A.T.M.A.N.] [RFC 00/10] Improving the routing protocol abstraction Antonio Quartulli
2013-05-28 22:20 ` [B.A.T.M.A.N.] [RFC 01/10] batman-adv: make struct batadv_neigh_node algorithm agnostic Antonio Quartulli
2013-05-28 22:20 ` [B.A.T.M.A.N.] [RFC 02/10] batman-adv: make struct batadv_orig_node " Antonio Quartulli
2013-05-29 14:09   ` Simon Wunderlich
2013-05-29 14:12     ` Antonio Quartulli
2013-05-28 22:20 ` [B.A.T.M.A.N.] [RFC 03/10] batman-adv: add bat_orig_print function API Antonio Quartulli
2013-05-28 22:20 ` [B.A.T.M.A.N.] [RFC 04/10] batman-adv: add bat_get_metric API function Antonio Quartulli
2013-05-29 14:17   ` Simon Wunderlich
2013-05-29 14:29     ` Antonio Quartulli
2013-05-28 22:20 ` [B.A.T.M.A.N.] [RFC 04/10] batman-adv: add bat_metric_get " Antonio Quartulli
2013-05-28 22:20 ` [B.A.T.M.A.N.] [RFC 05/10] batman-adv: add bat_metric_is_similar " Antonio Quartulli
2013-05-29 14:16   ` Simon Wunderlich
2013-05-29 14:28     ` Antonio Quartulli
2013-05-29 14:55       ` Simon Wunderlich
2013-05-29 14:57         ` Antonio Quartulli
2013-06-26  8:59           ` Antonio Quartulli
2013-05-28 22:20 ` Antonio Quartulli [this message]
2013-05-28 22:20 ` [B.A.T.M.A.N.] [RFC 07/10] batman-adv: adapt bonding to use the new API functions Antonio Quartulli
2013-05-28 22:20 ` [B.A.T.M.A.N.] [RFC 08/10] batman-adv: adapt the gateway feature " Antonio Quartulli
2013-05-29 14:32   ` Simon Wunderlich
2013-05-29 14:48     ` Antonio Quartulli
2013-05-30 11:29       ` Antonio Quartulli
2013-05-28 22:20 ` [B.A.T.M.A.N.] [RFC 09/10] batman-adv: adapt the neighbor purging routine " Antonio Quartulli
2013-05-28 22:23 ` [B.A.T.M.A.N.] [RFC 00/10] Improving the routing protocol abstraction Antonio Quartulli
2013-05-28 23:19 ` [B.A.T.M.A.N.] [RFC 10/10] batman-adv: provide orig_node routing API Antonio Quartulli
2013-05-29  6:20 ` [B.A.T.M.A.N.] [RFC 00/10] Improving the routing protocol abstraction Martin Hundebøll
2013-05-29  7:08   ` Antonio Quartulli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1369779649-2537-8-git-send-email-ordex@autistici.org \
    --to=ordex@autistici.org \
    --cc=antonio@open-mesh.com \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.