FIB path preference
Paths are given a preference, lowest value is 'best'. Only paths that are up are up contribute to fprwarding - that's unchanged. What's new is that of the path's that re up only those that have the best preference contribute. A poor man's primary and backup. It's not true primary/backup function because the FIB must converge before the lower preference paths are used.
Change-Id: Ie4453c4a7b1094c6c2b51fe1594b8302103bb68e
Signed-off-by: Neale Ranns <nranns@cisco.com>
diff --git a/src/vnet/fib/fib_path.c b/src/vnet/fib/fib_path.c
index 274b0ef..a32baf2 100644
--- a/src/vnet/fib/fib_path.c
+++ b/src/vnet/fib/fib_path.c
@@ -196,9 +196,15 @@
fib_protocol_t fp_nh_proto;
/**
- * UCMP [unnormalised] weigt
+ * UCMP [unnormalised] weigth
*/
- u32 fp_weight;
+ u16 fp_weight;
+ /**
+ * A path preference. 0 is the best.
+ * Only paths of the best preference, that are 'up', are considered
+ * for forwarding.
+ */
+ u16 fp_preference;
/**
* per-type union of the data required to resolve the path
@@ -376,6 +382,7 @@
s = format (s, "pl-index:%d ", path->fp_pl_index);
s = format (s, "%U ", format_fib_protocol, path->fp_nh_proto);
s = format (s, "weight=%d ", path->fp_weight);
+ s = format (s, "pref=%d ", path->fp_preference);
s = format (s, "%s: ", fib_path_type_names[path->fp_type]);
if (FIB_PATH_OPER_FLAG_NONE != path->fp_oper_flags) {
s = format(s, " oper-flags:");
@@ -700,6 +707,14 @@
}
/*
+ * If this path is contributing a drop, then it's not resolved
+ */
+ if (dpo_is_drop(&via_dpo) || load_balance_is_drop(&via_dpo))
+ {
+ path->fp_oper_flags &= ~FIB_PATH_OPER_FLAG_RESOLVED;
+ }
+
+ /*
* update the path's contributed DPO
*/
dpo_copy(dpo, &via_dpo);
@@ -1071,6 +1086,7 @@
*/
path->fp_weight = 1;
}
+ path->fp_preference = rpath->frp_preference;
path->fp_cfg_flags = fib_path_route_flags_to_cfg_flags(rpath);
/*
@@ -1165,6 +1181,7 @@
path->fp_pl_index = pl_index;
path->fp_weight = 1;
+ path->fp_preference = 0;
path->fp_nh_proto = nh_proto;
path->fp_via_fib = FIB_NODE_INDEX_INVALID;
path->fp_cfg_flags = flags;
@@ -1275,7 +1292,7 @@
/*
* paths of different types and protocol are not equal.
- * different weights only are the same path.
+ * different weights and/or preference only are the same path.
*/
if (path1->fp_type != path2->fp_type)
{
@@ -1350,6 +1367,15 @@
path1 = fib_path_get(*pi1);
path2 = fib_path_get(*pi2);
+ /*
+ * when sorting paths we want the highest preference paths
+ * first, so that the choices set built is in prefernce order
+ */
+ if (path1->fp_preference != path2->fp_preference)
+ {
+ return (path1->fp_preference - path2->fp_preference);
+ }
+
return (fib_path_cmp_i(path1, path2));
}
@@ -1750,7 +1776,7 @@
return (ADJ_INDEX_INVALID);
}
-int
+u16
fib_path_get_weight (fib_node_index_t path_index)
{
fib_path_t *path;
@@ -1762,6 +1788,18 @@
return (path->fp_weight);
}
+u16
+fib_path_get_preference (fib_node_index_t path_index)
+{
+ fib_path_t *path;
+
+ path = fib_path_get(path_index);
+
+ ASSERT(path);
+
+ return (path->fp_preference);
+}
+
/**
* @brief Contribute the path's adjacency to the list passed.
* By calling this function over all paths, recursively, a child
@@ -2116,6 +2154,7 @@
return (FIB_PATH_LIST_WALK_CONTINUE);
vec_add2(*api_rpaths, api_rpath, 1);
api_rpath->rpath.frp_weight = path->fp_weight;
+ api_rpath->rpath.frp_preference = path->fp_preference;
api_rpath->rpath.frp_proto = path->fp_nh_proto;
api_rpath->rpath.frp_sw_if_index = ~0;
api_rpath->dpo = path->exclusive.fp_ex_dpo;