From: Antonio Quartulli <antonio@meshcoding.com>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org,
Antonio Quartulli <antonio@open-mesh.com>,
Marek Lindner <lindner_marek@yahoo.de>
Subject: [PATCH 05/16] batman-adv: add bat_neigh_is_equiv_or_better API function
Date: Wed, 23 Oct 2013 18:04:52 +0200 [thread overview]
Message-ID: <1382544303-2694-6-git-send-email-antonio@meshcoding.com> (raw)
In-Reply-To: <1382544303-2694-1-git-send-email-antonio@meshcoding.com>
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 their "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>
Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
---
net/batman-adv/bat_iv_ogm.c | 18 ++++++++++++++++++
net/batman-adv/main.c | 3 ++-
net/batman-adv/main.h | 6 ++++++
net/batman-adv/types.h | 4 ++++
4 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index b288d90..4376fe7 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -1494,6 +1494,23 @@ static int batadv_iv_ogm_neigh_cmp(struct batadv_neigh_node *neigh1,
return tq1 - tq2;
}
+/**
+ * batadv_iv_ogm_neigh_is_eob - check if neigh1 is equally good or better than
+ * neigh2 from the metric prospective
+ * @neigh1: the first neighbor object of the comparison
+ * @neigh2: the second neighbor object of the comparison
+ *
+ * Returns true if the metric via neigh1 is equally good or better than the
+ * metric via neigh2, false otherwise.
+ */
+static bool batadv_iv_ogm_neigh_is_eob(struct batadv_neigh_node *neigh1,
+ struct batadv_neigh_node *neigh2)
+{
+ int diff = batadv_iv_ogm_neigh_cmp(neigh1, neigh2);
+
+ return diff > -BATADV_TQ_SIMILARITY_THRESHOLD;
+}
+
static struct batadv_algo_ops batadv_batman_iv __read_mostly = {
.name = "BATMAN_IV",
.bat_iface_enable = batadv_iv_ogm_iface_enable,
@@ -1503,6 +1520,7 @@ static struct batadv_algo_ops batadv_batman_iv __read_mostly = {
.bat_ogm_schedule = batadv_iv_ogm_schedule,
.bat_ogm_emit = batadv_iv_ogm_emit,
.bat_neigh_cmp = batadv_iv_ogm_neigh_cmp,
+ .bat_neigh_is_equiv_or_better = batadv_iv_ogm_neigh_is_eob,
.bat_orig_print = batadv_iv_ogm_orig_print,
};
diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c
index 1f2f1ac..c51a5e5 100644
--- a/net/batman-adv/main.c
+++ b/net/batman-adv/main.c
@@ -502,7 +502,8 @@ int batadv_algo_register(struct batadv_algo_ops *bat_algo_ops)
!bat_algo_ops->bat_primary_iface_set ||
!bat_algo_ops->bat_ogm_schedule ||
!bat_algo_ops->bat_ogm_emit ||
- !bat_algo_ops->bat_neigh_cmp) {
+ !bat_algo_ops->bat_neigh_cmp ||
+ !bat_algo_ops->bat_neigh_is_equiv_or_better) {
pr_info("Routing algo '%s' does not implement required ops\n",
bat_algo_ops->name);
ret = -EINVAL;
diff --git a/net/batman-adv/main.h b/net/batman-adv/main.h
index d7dfafe..773301a 100644
--- a/net/batman-adv/main.h
+++ b/net/batman-adv/main.h
@@ -86,6 +86,12 @@
/* numbers of originator to contact for any PUT/GET DHT operation */
#define BATADV_DAT_CANDIDATES_NUM 3
+/**
+ * BATADV_TQ_SIMILARITY_THRESHOLD - TQ points that a secondary metric can differ
+ * at most from the primary one in order to be still considered acceptable
+ */
+#define BATADV_TQ_SIMILARITY_THRESHOLD 50
+
/* how much worse secondary interfaces may be to be considered as bonding
* candidates
*/
diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
index 7a00932..d0e64d2 100644
--- a/net/batman-adv/types.h
+++ b/net/batman-adv/types.h
@@ -993,6 +993,8 @@ struct batadv_forw_packet {
* @bat_ogm_schedule: prepare a new outgoing OGM for the send queue
* @bat_ogm_emit: send scheduled OGM
* @bat_neigh_cmp: compare the metrics of two neighbors
+ * @bat_neigh_is_equiv_or_better: check if neigh1 is equally good or
+ * better than neigh2 from the metric prospective
* @bat_orig_print: print the originator table (optional)
*/
struct batadv_algo_ops {
@@ -1006,6 +1008,8 @@ struct batadv_algo_ops {
void (*bat_ogm_emit)(struct batadv_forw_packet *forw_packet);
int (*bat_neigh_cmp)(struct batadv_neigh_node *neigh1,
struct batadv_neigh_node *neigh2);
+ bool (*bat_neigh_is_equiv_or_better)(struct batadv_neigh_node *neigh1,
+ struct batadv_neigh_node *neigh2);
/* orig_node handling API */
void (*bat_orig_print)(struct batadv_priv *priv, struct seq_file *seq);
};
--
1.8.4
next prev parent reply other threads:[~2013-10-23 16:05 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-23 16:04 pull request: batman-adv 2013-10-23 Antonio Quartulli
[not found] ` <1382544303-2694-1-git-send-email-antonio-x4xJYDvStAgysxA8WJXlww@public.gmane.org>
2013-10-23 16:04 ` [PATCH 01/16] batman-adv: make struct batadv_neigh_node algorithm agnostic Antonio Quartulli
2013-10-23 16:05 ` [PATCH 13/16] batman-adv: improve the TT component to support runtime flag changes Antonio Quartulli
2013-10-23 16:04 ` [PATCH 02/16] batman-adv: make struct batadv_orig_node algorithm agnostic Antonio Quartulli
2013-10-23 16:04 ` [PATCH 03/16] batman-adv: add bat_orig_print API function Antonio Quartulli
2013-10-23 17:00 ` Joe Perches
2013-10-23 17:18 ` Antonio Quartulli
[not found] ` <20131023171810.GB2651-rVWd3aGhH2zPj3vggD0kEA@public.gmane.org>
2013-10-23 17:27 ` Joe Perches
2013-10-23 17:37 ` Antonio Quartulli
2013-10-23 16:04 ` [PATCH 04/16] batman-adv: add bat_neigh_cmp " Antonio Quartulli
2013-10-23 16:04 ` Antonio Quartulli [this message]
2013-10-23 16:04 ` [PATCH 06/16] batman-adv: adapt bonding to use the new API functions Antonio Quartulli
2013-10-23 16:04 ` [PATCH 07/16] batman-adv: adapt the neighbor purging routine " Antonio Quartulli
2013-10-23 16:04 ` [PATCH 08/16] batman-adv: provide orig_node routing API Antonio Quartulli
2013-10-23 16:04 ` [PATCH 09/16] batman-adv: adapt the TT component to use the new API functions Antonio Quartulli
2013-10-23 16:04 ` [PATCH 10/16] batman-adv: limit local translation table max size Antonio Quartulli
2013-10-23 16:04 ` [PATCH 11/16] batman-adv: send GW_DEL event in case of soft-iface destruction Antonio Quartulli
2013-10-23 16:04 ` [PATCH 12/16] batman-adv: invoke dev_get_by_index() outside of is_wifi_iface() Antonio Quartulli
2013-10-23 16:05 ` [PATCH 14/16] batman-adv: include the sync-flags when compute the global/local table CRC Antonio Quartulli
2013-10-23 16:05 ` [PATCH 15/16] batman-adv: Start new development cycle Antonio Quartulli
2013-10-23 16:05 ` [PATCH 16/16] batman-adv: generalize batman-adv icmp packet handling Antonio Quartulli
2013-10-23 21:13 ` pull request: batman-adv 2013-10-23 David Miller
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=1382544303-2694-6-git-send-email-antonio@meshcoding.com \
--to=antonio@meshcoding.com \
--cc=antonio@open-mesh.com \
--cc=b.a.t.m.a.n@lists.open-mesh.org \
--cc=davem@davemloft.net \
--cc=lindner_marek@yahoo.de \
--cc=netdev@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).