[HICN-216] Fixed dpo initializatino 36/20036/1
authorAlberto Compagno <acompagn+fdio@cisco.com>
Fri, 7 Jun 2019 18:20:08 +0000 (20:20 +0200)
committerAlberto Compagno <acompagn+fdio@cisco.com>
Fri, 7 Jun 2019 18:20:08 +0000 (20:20 +0200)
Change-Id: I45104ab815cf93969d1f25a77ea7e79ef295acdc
Signed-off-by: Alberto Compagno <acompagn+fdio@cisco.com>
hicn-plugin/src/mapme.h
hicn-plugin/src/strategies/dpo_mw.c
hicn-plugin/src/strategies/dpo_rr.c
hicn-plugin/src/strategy_dpo_ctx.h

index 41134cd..d5e77f6 100644 (file)
@@ -33,7 +33,6 @@
 #define TIMER_NO_REPEAT false
 
 #define INVALID_SEQ 0
-#define INIT_SEQ 0
 
 typedef struct hicn_mapme_conf_s
 {
@@ -135,9 +134,9 @@ hicn_mapme_tfib_del (hicn_mapme_tfib_t * tfib, dpo_id_t * face_id)
   for (pos = start_pos; pos < HICN_PARAM_FIB_ENTRY_NHOPS_MAX; pos++)
     if (dpo_cmp (&tfib->next_hops[pos], face_id) == 0)
       {
-        hicn_face_unlock (&tfib->next_hops[pos]);
-        tfib->next_hops[pos] = invalid;
-        break;
+       hicn_face_unlock (&tfib->next_hops[pos]);
+       tfib->next_hops[pos] = invalid;
+       break;
       }
   if (pos == HICN_PARAM_FIB_ENTRY_NHOPS_MAX)
     /* Not found */
index 80cbcf2..0014c2b 100644 (file)
@@ -161,19 +161,13 @@ hicn_strategy_mw_ctx_create (dpo_proto_t proto, const dpo_id_t * next_hop,
 {
   hicn_strategy_mw_ctx_t *hicn_strategy_mw_ctx;
   int ret = HICN_ERROR_NONE, i;
-  dpo_id_t invalid = NEXT_HOP_INVALID;
 
   /* Allocate a hicn_dpo_ctx on the vpp pool and initialize it */
   pool_get (hicn_strategy_mw_ctx_pool, hicn_strategy_mw_ctx);
 
   *dpo_idx = hicn_strategy_mw_ctx_get_index (hicn_strategy_mw_ctx);
-  for (int i = 0; i < HICN_PARAM_FIB_ENTRY_NHOPS_MAX; i++)
-    {
-      hicn_strategy_mw_ctx->default_ctx.next_hops[i] = invalid;
-    }
 
-  hicn_strategy_mw_ctx->default_ctx.entry_count = 0;
-  hicn_strategy_mw_ctx->default_ctx.locks = 0;
+  init_dpo_ctx (&(hicn_strategy_mw_ctx->default_ctx));
 
   for (i = 0; i < HICN_PARAM_FIB_ENTRY_NHOPS_MAX && i < nh_len; i++)
     {
@@ -219,8 +213,8 @@ hicn_strategy_mw_ctx_add_nh (const dpo_id_t * nh, index_t dpo_idx)
            {
              /* If face is marked as deleted, ignore it */
              hicn_face_t *face =
-               hicn_dpoi_get_from_idx (hicn_strategy_mw_ctx->default_ctx.
-                                       next_hops[i].dpoi_index);
+               hicn_dpoi_get_from_idx (hicn_strategy_mw_ctx->
+                                       default_ctx.next_hops[i].dpoi_index);
              if (face->shared.flags & HICN_FACE_FLAGS_DELETED)
                {
                  continue;
@@ -265,8 +259,8 @@ hicn_strategy_mw_ctx_del_nh (hicn_face_id_t face_id, index_t dpo_idx,
              face_id)
            {
              nh_id = i;
-             hicn_face_unlock (&hicn_strategy_mw_ctx->
-                               default_ctx.next_hops[i]);
+             hicn_face_unlock (&hicn_strategy_mw_ctx->default_ctx.
+                               next_hops[i]);
              hicn_strategy_mw_ctx->default_ctx.next_hops[i] = invalid;
              hicn_strategy_mw_ctx->default_ctx.entry_count--;
            }
index c9ec504..027087f 100644 (file)
@@ -162,19 +162,13 @@ hicn_strategy_rr_ctx_create (dpo_proto_t proto, const dpo_id_t * next_hop,
 {
   hicn_strategy_rr_ctx_t *hicn_strategy_rr_ctx;
   int ret = HICN_ERROR_NONE, i;
-  dpo_id_t invalid = NEXT_HOP_INVALID;
 
   /* Allocate a hicn_dpo_ctx on the vpp pool and initialize it */
   pool_get (hicn_strategy_rr_ctx_pool, hicn_strategy_rr_ctx);
 
   *dpo_idx = hicn_strategy_rr_ctx_get_index (hicn_strategy_rr_ctx);
-  for (int i = 0; i < HICN_PARAM_FIB_ENTRY_NHOPS_MAX; i++)
-    {
-      hicn_strategy_rr_ctx->default_ctx.next_hops[i] = invalid;
-    }
 
-  hicn_strategy_rr_ctx->default_ctx.entry_count = 0;
-  hicn_strategy_rr_ctx->default_ctx.locks = 0;
+  init_dpo_ctx (&(hicn_strategy_rr_ctx->default_ctx));
 
   for (i = 0; i < HICN_PARAM_FIB_ENTRY_NHOPS_MAX && i < nh_len; i++)
     {
@@ -220,8 +214,8 @@ hicn_strategy_rr_ctx_add_nh (const dpo_id_t * nh, index_t dpo_idx)
            {
              /* If face is marked as deleted, ignore it */
              hicn_face_t *face =
-               hicn_dpoi_get_from_idx (hicn_strategy_rr_ctx->
-                                       default_ctx.next_hops[i].dpoi_index);
+               hicn_dpoi_get_from_idx (hicn_strategy_rr_ctx->default_ctx.
+                                       next_hops[i].dpoi_index);
              if (face->shared.flags & HICN_FACE_FLAGS_DELETED)
                {
                  continue;
@@ -266,8 +260,8 @@ hicn_strategy_rr_ctx_del_nh (hicn_face_id_t face_id, index_t dpo_idx,
              face_id)
            {
              nh_id = i;
-             hicn_face_unlock (&hicn_strategy_rr_ctx->default_ctx.
-                               next_hops[i]);
+             hicn_face_unlock (&hicn_strategy_rr_ctx->
+                               default_ctx.next_hops[i]);
              hicn_strategy_rr_ctx->default_ctx.next_hops[i] = invalid;
              hicn_strategy_rr_ctx->default_ctx.entry_count--;
            }
index 5d2dbc4..c6de6b7 100644 (file)
@@ -29,6 +29,7 @@
 
 #define NEXT_HOP_INVALID DPO_INVALID
 
+#define INIT_SEQ 0
 /*
  * An hicn dpo is a list of next hops (face + weight).
  */
@@ -57,6 +58,28 @@ typedef struct __attribute__ ((packed)) hicn_dpo_ctx_s
 
 } hicn_dpo_ctx_t;
 
+always_inline void
+init_dpo_ctx (hicn_dpo_ctx_t * dpo_ctx)
+{
+  dpo_id_t invalid = NEXT_HOP_INVALID;
+
+  for (int i = 0; i < HICN_PARAM_FIB_ENTRY_NHOPS_MAX; i++)
+    {
+      dpo_ctx->next_hops[i] = invalid;
+    }
+
+  dpo_ctx->entry_count = 0;
+  dpo_ctx->locks = 0;
+
+  dpo_ctx->tfib_entry_count = 0;
+
+#ifdef HICN_MAPME_NOTIFICATIONS
+  last_iu_ack = 0;
+#endif
+
+  dpo_ctx->seq = INIT_SEQ;
+}
+
 STATIC_ASSERT (sizeof (hicn_dpo_ctx_t) <= CLIB_CACHE_LINE_BYTES,
               "sizeof hicn_dpo_ctx_t is greater than 64B");