aboutsummaryrefslogtreecommitdiffstats
path: root/hicn-plugin/src/strategies
diff options
context:
space:
mode:
Diffstat (limited to 'hicn-plugin/src/strategies')
-rw-r--r--hicn-plugin/src/strategies/dpo_mw.c205
-rw-r--r--hicn-plugin/src/strategies/dpo_mw.h56
-rw-r--r--hicn-plugin/src/strategies/dpo_rr.c208
-rw-r--r--hicn-plugin/src/strategies/dpo_rr.h52
-rw-r--r--hicn-plugin/src/strategies/strategy_mw.c103
-rw-r--r--hicn-plugin/src/strategies/strategy_mw.h5
-rw-r--r--hicn-plugin/src/strategies/strategy_mw_cli.c10
-rw-r--r--hicn-plugin/src/strategies/strategy_rr.c100
-rw-r--r--hicn-plugin/src/strategies/strategy_rr.h3
9 files changed, 218 insertions, 524 deletions
diff --git a/hicn-plugin/src/strategies/dpo_mw.c b/hicn-plugin/src/strategies/dpo_mw.c
index 3317d31e0..eebb572c4 100644
--- a/hicn-plugin/src/strategies/dpo_mw.c
+++ b/hicn-plugin/src/strategies/dpo_mw.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Copyright (c) 2017-2020 Cisco and/or its affiliates.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
@@ -13,27 +13,10 @@
* limitations under the License.
*/
-#include "../strategy_dpo_ctx.h"
#include "dpo_mw.h"
#include "strategy_mw.h"
#include "../strategy_dpo_manager.h"
-
-hicn_strategy_mw_ctx_t *hicn_strategy_mw_ctx_pool;
-
-const static char *const hicn_ip6_nodes[] = {
- "hicn-mw-strategy", // this is the name you give your node in VLIB_REGISTER_NODE
- NULL,
-};
-
-const static char *const hicn_ip4_nodes[] = {
- "hicn-mw-strategy", // this is the name you give your node in VLIB_REGISTER_NODE
- NULL,
-};
-
-const static char *const *const hicn_nodes_mw[DPO_PROTO_NUM] = {
- [DPO_PROTO_IP6] = hicn_ip6_nodes,
- [DPO_PROTO_IP4] = hicn_ip4_nodes,
-};
+#include "../strategy_dpo_ctx.h"
/**
* @brief DPO type value for the mw_strategy
@@ -41,16 +24,13 @@ const static char *const *const hicn_nodes_mw[DPO_PROTO_NUM] = {
static dpo_type_t hicn_dpo_type_mw;
static const hicn_dpo_vft_t hicn_dpo_mw_vft = {
- .hicn_dpo_get_ctx = &hicn_strategy_mw_ctx_get,
.hicn_dpo_is_type = &hicn_dpo_is_type_strategy_mw,
.hicn_dpo_get_type = &hicn_dpo_strategy_mw_get_type,
.hicn_dpo_module_init = &hicn_dpo_strategy_mw_module_init,
.hicn_dpo_create = &hicn_strategy_mw_ctx_create,
.hicn_dpo_add_update_nh = &hicn_strategy_mw_ctx_add_nh,
.hicn_dpo_del_nh = &hicn_strategy_mw_ctx_del_nh,
- .hicn_dpo_lock_dpo_ctx = &hicn_strategy_mw_ctx_lock,
- .hicn_dpo_unlock_dpo_ctx = hicn_strategy_mw_ctx_unlock,
- .format_hicn_dpo = &format_hicn_dpo_strategy_mw
+ .hicn_dpo_format = &hicn_strategy_mw_format_ctx
};
int
@@ -62,28 +42,15 @@ hicn_dpo_is_type_strategy_mw (const dpo_id_t * dpo)
void
hicn_dpo_strategy_mw_module_init (void)
{
- pool_validate_index (hicn_strategy_mw_ctx_pool, 0);
/*
* Register our type of dpo
*/
hicn_dpo_type_mw =
- hicn_dpo_register_new_type (hicn_nodes_mw, &hicn_dpo_mw_vft,
+ hicn_dpo_register_new_type (hicn_nodes_strategy, &hicn_dpo_mw_vft,
hicn_mw_strategy_get_vft (),
&dpo_strategy_mw_ctx_vft);
}
-u8 *
-format_hicn_dpo_strategy_mw (u8 * s, va_list * ap)
-{
-
- u32 indent = va_arg (*ap, u32);
- s =
- format (s,
- "Static Weights: weights are updated by the control plane, next hop is the one with the maximum weight.\n",
- indent);
- return (s);
-}
-
dpo_type_t
hicn_dpo_strategy_mw_get_type (void)
{
@@ -92,33 +59,14 @@ hicn_dpo_strategy_mw_get_type (void)
//////////////////////////////////////////////////////////////////////////////////////////////////
-void
-hicn_strategy_mw_ctx_lock (dpo_id_t * dpo)
-{
- hicn_strategy_mw_ctx_t *hicn_strategy_mw_ctx =
- (hicn_strategy_mw_ctx_t *) hicn_strategy_mw_ctx_get (dpo->dpoi_index);
-
- if (hicn_strategy_mw_ctx != NULL)
- {
- hicn_strategy_mw_ctx->default_ctx.locks++;
- }
-}
-void
-hicn_strategy_mw_ctx_unlock (dpo_id_t * dpo)
+u8 *
+hicn_strategy_mw_format_ctx (u8 * s, int n, ...)
{
- hicn_strategy_mw_ctx_t *hicn_strategy_mw_ctx =
- (hicn_strategy_mw_ctx_t *) hicn_strategy_mw_ctx_get (dpo->dpoi_index);
-
- if (hicn_strategy_mw_ctx != NULL)
- {
- hicn_strategy_mw_ctx->default_ctx.locks--;
-
- if (0 == hicn_strategy_mw_ctx->default_ctx.locks)
- {
- pool_put (hicn_strategy_mw_ctx_pool, hicn_strategy_mw_ctx);
- }
- }
+ va_list args;
+ va_start (args, n);
+ s = format_hicn_strategy_mw_ctx (s, &args);
+ return s;
}
u8 *
@@ -126,24 +74,30 @@ format_hicn_strategy_mw_ctx (u8 * s, va_list * ap)
{
int i = 0;
index_t index = va_arg (*ap, index_t);
- hicn_strategy_mw_ctx_t *dpo = NULL;
+ hicn_dpo_ctx_t *dpo_ctx = NULL;
+ hicn_strategy_mw_ctx_t *mw_dpo_ctx = NULL;
dpo_id_t *next_hop = NULL;
hicn_face_vft_t *face_vft = NULL;
u32 indent = va_arg (*ap, u32);;
- dpo = (hicn_strategy_mw_ctx_t *) hicn_strategy_mw_ctx_get (index);
+ dpo_ctx = hicn_strategy_dpo_ctx_get (index);
+ if (dpo_ctx == NULL)
+ return s;
+
+ mw_dpo_ctx = (hicn_strategy_mw_ctx_t *) dpo_ctx->data;
s = format (s, "hicn-mw");
- for (i = 0; i < HICN_PARAM_FIB_ENTRY_NHOPS_MAX && dpo != NULL; i++)
+ for (i = 0; i < HICN_PARAM_FIB_ENTRY_NHOPS_MAX; i++)
{
u8 *buf = NULL;
- if (i < dpo->default_ctx.entry_count)
- buf = format(NULL, "FIB");
- else if (i >= HICN_PARAM_FIB_ENTRY_NHOPS_MAX - dpo->default_ctx.tfib_entry_count)
- buf = format(NULL, "TFIB");
+ if (i < dpo_ctx->entry_count)
+ buf = format (NULL, "FIB");
+ else if (i >=
+ HICN_PARAM_FIB_ENTRY_NHOPS_MAX - dpo_ctx->tfib_entry_count)
+ buf = format (NULL, "TFIB");
else
continue;
- next_hop = &dpo->default_ctx.next_hops[i];
+ next_hop = &dpo_ctx->next_hops[i];
face_vft = hicn_face_get_vft (next_hop->dpoi_type);
if (face_vft != NULL)
{
@@ -151,7 +105,7 @@ format_hicn_strategy_mw_ctx (u8 * s, va_list * ap)
s =
format (s, "%U ", face_vft->format_face, next_hop->dpoi_index,
indent);
- s = format (s, "weight %u", dpo->weight[i]);
+ s = format (s, "weight %u", mw_dpo_ctx->weight[i]);
s = format (s, " %s", buf);
}
}
@@ -159,124 +113,49 @@ format_hicn_strategy_mw_ctx (u8 * s, va_list * ap)
return (s);
}
-static index_t
-hicn_strategy_mw_ctx_get_index (hicn_strategy_mw_ctx_t * cd)
-{
- return (cd - hicn_strategy_mw_ctx_pool);
-}
-
-int
+void
hicn_strategy_mw_ctx_create (dpo_proto_t proto, const dpo_id_t * next_hop,
int nh_len, index_t * dpo_idx)
{
hicn_strategy_mw_ctx_t *hicn_strategy_mw_ctx;
- int ret = HICN_ERROR_NONE, i;
+ hicn_dpo_ctx_t *hicn_strategy_ctx;
/* Allocate a hicn_dpo_ctx on the vpp pool and initialize it */
- pool_get (hicn_strategy_mw_ctx_pool, hicn_strategy_mw_ctx);
+ hicn_strategy_ctx = hicn_strategy_dpo_ctx_alloc ();
+ hicn_strategy_mw_ctx = (hicn_strategy_mw_ctx_t *) hicn_strategy_ctx->data;
- *dpo_idx = hicn_strategy_mw_ctx_get_index (hicn_strategy_mw_ctx);
+ *dpo_idx = hicn_strategy_dpo_ctx_get_index (hicn_strategy_ctx);
- init_dpo_ctx (&(hicn_strategy_mw_ctx->default_ctx));
-
- for (i = 0; i < HICN_PARAM_FIB_ENTRY_NHOPS_MAX && i < nh_len; i++)
- {
- clib_memcpy (&hicn_strategy_mw_ctx->default_ctx.next_hops[i],
- &next_hop[i], sizeof (dpo_id_t));
- hicn_strategy_mw_ctx->default_ctx.entry_count++;
- }
+ init_dpo_ctx (hicn_strategy_ctx, next_hop, nh_len, hicn_dpo_type_mw);
memset (hicn_strategy_mw_ctx->weight, 0, HICN_PARAM_FIB_ENTRY_NHOPS_MAX);
-
- return ret;
-}
-
-hicn_dpo_ctx_t *
-hicn_strategy_mw_ctx_get (index_t index)
-{
- hicn_strategy_mw_ctx_t *hicn_strategy_mw_ctx = NULL;
- if (!pool_is_free_index (hicn_strategy_mw_ctx_pool, index))
- {
- hicn_strategy_mw_ctx =
- (pool_elt_at_index (hicn_strategy_mw_ctx_pool, index));
- }
-
- return (hicn_dpo_ctx_t *)hicn_strategy_mw_ctx;
}
int
hicn_strategy_mw_ctx_add_nh (const dpo_id_t * nh, index_t dpo_idx)
{
- hicn_strategy_mw_ctx_t *hicn_strategy_mw_ctx =
- (hicn_strategy_mw_ctx_t *) hicn_strategy_mw_ctx_get (dpo_idx);
+ hicn_dpo_ctx_t *hicn_strategy_dpo_ctx = hicn_strategy_dpo_ctx_get (dpo_idx);
+ u8 pos = 0;
- if (hicn_strategy_mw_ctx == NULL)
+ if (hicn_strategy_dpo_ctx == NULL)
{
return HICN_ERROR_STRATEGY_NOT_FOUND;
}
- int empty = hicn_strategy_mw_ctx->default_ctx.entry_count;
-
- /* Iterate through the list of faces to add new faces */
- for (int i = 0; i < hicn_strategy_mw_ctx->default_ctx.entry_count; i++)
- {
- if (!memcmp
- (nh, &hicn_strategy_mw_ctx->default_ctx.next_hops[i],
- sizeof (dpo_id_t)))
- {
- /* 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);
- if (face->shared.flags & HICN_FACE_FLAGS_DELETED)
- {
- continue;
- }
- return HICN_ERROR_DPO_CTX_NHOPS_EXISTS;
- }
- }
-
- /* Get an empty place */
- if (empty > HICN_PARAM_FIB_ENTRY_NHOPS_MAX)
- {
- return HICN_ERROR_DPO_CTX_NHOPS_NS;
- }
-
- clib_memcpy (&hicn_strategy_mw_ctx->default_ctx.next_hops[empty], nh,
- sizeof (dpo_id_t));
- hicn_strategy_mw_ctx->default_ctx.entry_count++;
+ hicn_strategy_dpo_ctx_add_nh (nh, hicn_strategy_dpo_ctx, &pos);
+ hicn_strategy_mw_ctx_t *hicn_strategy_mw_ctx =
+ (hicn_strategy_mw_ctx_t *) & hicn_strategy_dpo_ctx->data;
+ hicn_strategy_mw_ctx->weight[pos] = DEFAULT_WEIGHT;
return HICN_ERROR_NONE;
}
int
-hicn_strategy_mw_ctx_del_nh (hicn_face_id_t face_id, index_t dpo_idx,
- fib_prefix_t * fib_pfx)
+hicn_strategy_mw_ctx_del_nh (hicn_face_id_t face_id, index_t dpo_idx)
{
- hicn_strategy_mw_ctx_t *hicn_strategy_mw_ctx =
- (hicn_strategy_mw_ctx_t *) hicn_strategy_mw_ctx_get (dpo_idx);
- int ret = HICN_ERROR_DPO_CTX_NOT_FOUND;
- dpo_id_t invalid = NEXT_HOP_INVALID;
-
- if (hicn_strategy_mw_ctx == NULL)
- return HICN_ERROR_STRATEGY_NOT_FOUND;
-
- for (int i = 0; i < hicn_strategy_mw_ctx->default_ctx.entry_count; i++)
- {
- if (hicn_strategy_mw_ctx->default_ctx.next_hops[i].dpoi_index ==
- face_id)
- {
- hicn_face_unlock (&hicn_strategy_mw_ctx->default_ctx.
- next_hops[i]);
- hicn_strategy_mw_ctx->default_ctx.entry_count--;
- hicn_strategy_mw_ctx->default_ctx.next_hops[i] = hicn_strategy_mw_ctx->default_ctx.next_hops[hicn_strategy_mw_ctx->default_ctx.entry_count];
- hicn_strategy_mw_ctx->default_ctx.next_hops[hicn_strategy_mw_ctx->default_ctx.entry_count] = invalid;
- ret = HICN_ERROR_NONE;
- break;
- }
- }
-
- return ret;
+ hicn_dpo_ctx_t *hicn_strategy_dpo_ctx = hicn_strategy_dpo_ctx_get (dpo_idx);
+ //No need to flush the weights, they are initialized when a dpo_ctx is created;
+ return hicn_strategy_dpo_ctx_del_nh (face_id, hicn_strategy_dpo_ctx);
}
/*
diff --git a/hicn-plugin/src/strategies/dpo_mw.h b/hicn-plugin/src/strategies/dpo_mw.h
index a8c0a3b43..ccc8d044f 100644
--- a/hicn-plugin/src/strategies/dpo_mw.h
+++ b/hicn-plugin/src/strategies/dpo_mw.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Copyright (c) 2017-2020 Cisco and/or its affiliates.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
@@ -19,28 +19,14 @@
#include <vnet/dpo/dpo.h>
#include "../strategy_dpo_ctx.h"
+#define DEFAULT_WEIGHT 0
+
typedef struct hicn_strategy_mw_ctx_s
{
- hicn_dpo_ctx_t default_ctx;
-
u8 weight[HICN_PARAM_FIB_ENTRY_NHOPS_MAX];
} hicn_strategy_mw_ctx_t;
/**
- * @brief Lock the mw ctx
- *
- * @param dpo Identifier of the dpo of the mw ctx
- */
-void hicn_strategy_mw_ctx_lock (dpo_id_t * dpo);
-
-/**
- * @brief Unlock the mw ctx
- *
- * @param dpo Identifier of the dpo of the mw ctx
- */
-void hicn_strategy_mw_ctx_unlock (dpo_id_t * dpo);
-
-/**
* @brief Format the dpo ctx for a human-readable string
*
* @param s String to which to append the formatted dpo ctx
@@ -51,8 +37,8 @@ void hicn_strategy_mw_ctx_unlock (dpo_id_t * dpo);
u8 *format_hicn_strategy_mw_ctx (u8 * s, va_list * ap);
const static dpo_vft_t dpo_strategy_mw_ctx_vft = {
- .dv_lock = hicn_strategy_mw_ctx_lock,
- .dv_unlock = hicn_strategy_mw_ctx_unlock,
+ .dv_lock = hicn_strategy_dpo_ctx_lock,
+ .dv_unlock = hicn_strategy_dpo_ctx_unlock,
.dv_format = format_hicn_strategy_mw_ctx,
};
@@ -73,7 +59,7 @@ hicn_dpo_ctx_t *hicn_strategy_mw_ctx_get (index_t index);
* @param dpo_idx index_t that will hold the index of the created dpo ctx
* @return HICN_ERROR_NONE if the creation was fine, otherwise EINVAL
*/
-int
+void
hicn_strategy_mw_ctx_create (dpo_proto_t proto, const dpo_id_t * next_hop,
int nh_len, index_t * dpo_idx);
@@ -100,9 +86,7 @@ int hicn_strategy_mw_ctx_add_nh (const dpo_id_t * nh, index_t dpo_idx);
* @return HICN_ERROR_NONE if the update or insert was fine,
* otherwise HICN_ERROR_DPO_CTS_NOT_FOUND
*/
-int
-hicn_strategy_mw_ctx_del_nh (hicn_face_id_t face_id, index_t dpo_idx,
- fib_prefix_t * fib_pfx);
+int hicn_strategy_mw_ctx_del_nh (hicn_face_id_t face_id, index_t dpo_idx);
/**
* @brief Prefetch a dpo
@@ -111,14 +95,40 @@ hicn_strategy_mw_ctx_del_nh (hicn_face_id_t face_id, index_t dpo_idx,
*/
void hicn_strategy_mw_ctx_prefetch (index_t dpo_idx);
+/**
+ * @brief Return true if the dpo is of type strategy mw
+ *
+ * @param dpo Dpo to check the type
+ */
int hicn_dpo_is_type_strategy_mw (const dpo_id_t * dpo);
+/**
+ * @brief Initialize the Maximum Weight strategy
+ */
void hicn_dpo_strategy_mw_module_init (void);
+/**
+ * @brief Return the dpo type for the Maximum Weight strategy
+ */
dpo_type_t hicn_dpo_strategy_mw_get_type (void);
+/**
+ * @brief Format the dpo ctx for the strategy Maximum Weight
+ *
+ * @param s String to append the formatted dpo ctx
+ * @param ap List of arguments to format
+ */
u8 *format_hicn_dpo_strategy_mw (u8 * s, va_list * ap);
+/**
+ * @brief Format the dpo ctx for the strategy Maximum Weight. To
+ * call from other functions
+ *
+ * @param s String to append the formatted dpo ctx
+ * @param ... List of arguments to format
+ */
+u8 *hicn_strategy_mw_format_ctx (u8 * s, int n, ...);
+
#endif // __HICN_DPO_MW_H__
diff --git a/hicn-plugin/src/strategies/dpo_rr.c b/hicn-plugin/src/strategies/dpo_rr.c
index dfdc83ff4..a67b06acb 100644
--- a/hicn-plugin/src/strategies/dpo_rr.c
+++ b/hicn-plugin/src/strategies/dpo_rr.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Copyright (c) 2017-2020 Cisco and/or its affiliates.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
@@ -13,27 +13,10 @@
* limitations under the License.
*/
-#include "../strategy_dpo_ctx.h"
#include "dpo_rr.h"
#include "strategy_rr.h"
#include "../strategy_dpo_manager.h"
-
-hicn_strategy_rr_ctx_t *hicn_strategy_rr_ctx_pool;
-
-const static char *const hicn_ip6_nodes[] = {
- "hicn-rr-strategy", // this is the name you give your node in VLIB_REGISTER_NODE
- NULL,
-};
-
-const static char *const hicn_ip4_nodes[] = {
- "hicn-rr-strategy", // this is the name you give your node in VLIB_REGISTER_NODE
- NULL,
-};
-
-const static char *const *const hicn_nodes_rr[DPO_PROTO_NUM] = {
- [DPO_PROTO_IP6] = hicn_ip6_nodes,
- [DPO_PROTO_IP4] = hicn_ip4_nodes,
-};
+#include "../strategy_dpo_ctx.h"
/**
* @brief DPO type value for the rr_strategy
@@ -41,16 +24,13 @@ const static char *const *const hicn_nodes_rr[DPO_PROTO_NUM] = {
static dpo_type_t hicn_dpo_type_rr;
static const hicn_dpo_vft_t hicn_dpo_rr_vft = {
- .hicn_dpo_get_ctx = &hicn_strategy_rr_ctx_get,
.hicn_dpo_is_type = &hicn_dpo_is_type_strategy_rr,
.hicn_dpo_get_type = &hicn_dpo_strategy_rr_get_type,
.hicn_dpo_module_init = &hicn_dpo_strategy_rr_module_init,
.hicn_dpo_create = &hicn_strategy_rr_ctx_create,
.hicn_dpo_add_update_nh = &hicn_strategy_rr_ctx_add_nh,
.hicn_dpo_del_nh = &hicn_strategy_rr_ctx_del_nh,
- .hicn_dpo_lock_dpo_ctx = &hicn_strategy_rr_ctx_lock,
- .hicn_dpo_unlock_dpo_ctx = hicn_strategy_rr_ctx_unlock,
- .format_hicn_dpo = &format_hicn_dpo_strategy_rr
+ .hicn_dpo_format = &hicn_strategy_rr_format_ctx
};
int
@@ -62,28 +42,15 @@ hicn_dpo_is_type_strategy_rr (const dpo_id_t * dpo)
void
hicn_dpo_strategy_rr_module_init (void)
{
- pool_validate_index (hicn_strategy_rr_ctx_pool, 0);
/*
* Register our type of dpo
*/
hicn_dpo_type_rr =
- hicn_dpo_register_new_type (hicn_nodes_rr, &hicn_dpo_rr_vft,
+ hicn_dpo_register_new_type (hicn_nodes_strategy, &hicn_dpo_rr_vft,
hicn_rr_strategy_get_vft (),
&dpo_strategy_rr_ctx_vft);
}
-u8 *
-format_hicn_dpo_strategy_rr (u8 * s, va_list * ap)
-{
-
- u32 indent = va_arg (*ap, u32);
- s =
- format (s,
- "Round Robin: next hop is chosen ciclying between all the available next hops, one after the other.\n",
- indent);
- return (s);
-}
-
dpo_type_t
hicn_dpo_strategy_rr_get_type (void)
{
@@ -92,32 +59,14 @@ hicn_dpo_strategy_rr_get_type (void)
//////////////////////////////////////////////////////////////////////////////////////////////////
-void
-hicn_strategy_rr_ctx_lock (dpo_id_t * dpo)
-{
- hicn_strategy_rr_ctx_t *hicn_strategy_rr_ctx =
- (hicn_strategy_rr_ctx_t *) hicn_strategy_rr_ctx_get (dpo->dpoi_index);
-
- if (hicn_strategy_rr_ctx != NULL)
- {
- hicn_strategy_rr_ctx->default_ctx.locks++;
- }
-}
-void
-hicn_strategy_rr_ctx_unlock (dpo_id_t * dpo)
+u8 *
+hicn_strategy_rr_format_ctx (u8 * s, int n, ...)
{
- hicn_strategy_rr_ctx_t *hicn_strategy_rr_ctx =
- (hicn_strategy_rr_ctx_t *) hicn_strategy_rr_ctx_get (dpo->dpoi_index);
- if (hicn_strategy_rr_ctx != NULL)
- {
- hicn_strategy_rr_ctx->default_ctx.locks--;
-
- if (0 == hicn_strategy_rr_ctx->default_ctx.locks)
- {
- pool_put (hicn_strategy_rr_ctx_pool, hicn_strategy_rr_ctx);
- }
- }
+ va_list args;
+ va_start (args, n);
+ s = format_hicn_strategy_rr_ctx (s, &args);
+ return s;
}
u8 *
@@ -125,28 +74,34 @@ format_hicn_strategy_rr_ctx (u8 * s, va_list * ap)
{
int i = 0;
index_t index = va_arg (*ap, index_t);
- hicn_strategy_rr_ctx_t *dpo = NULL;
+ hicn_dpo_ctx_t *dpo_ctx = NULL;
+ hicn_strategy_rr_ctx_t *rr_dpo_ctx = NULL;
dpo_id_t *next_hop = NULL;
hicn_face_vft_t *face_vft = NULL;
- u32 indent = va_arg (*ap, u32);;
+ u32 indent = va_arg (*ap, u32);
- dpo = (hicn_strategy_rr_ctx_t *) hicn_strategy_rr_ctx_get (index);
+ dpo_ctx = hicn_strategy_dpo_ctx_get (index);
+ if (dpo_ctx == NULL)
+ return s;
+
+ rr_dpo_ctx = (hicn_strategy_rr_ctx_t *) dpo_ctx->data;
s =
format (s, "hicn-rr, next hop Face %d",
- dpo->default_ctx.next_hops[dpo->current_nhop].dpoi_index);
+ dpo_ctx->next_hops[rr_dpo_ctx->current_nhop].dpoi_index);
- for (i = 0; i < HICN_PARAM_FIB_ENTRY_NHOPS_MAX && dpo != NULL; i++)
+ for (i = 0; i < HICN_PARAM_FIB_ENTRY_NHOPS_MAX; i++)
{
u8 *buf = NULL;
- if (i < dpo->default_ctx.entry_count)
- buf = format(NULL, "FIB");
- else if (i >= HICN_PARAM_FIB_ENTRY_NHOPS_MAX - dpo->default_ctx.tfib_entry_count)
- buf = format(NULL, "TFIB");
+ if (i < dpo_ctx->entry_count)
+ buf = format (NULL, "FIB");
+ else if (i >=
+ HICN_PARAM_FIB_ENTRY_NHOPS_MAX - dpo_ctx->tfib_entry_count)
+ buf = format (NULL, "TFIB");
else
continue;
- next_hop = &dpo->default_ctx.next_hops[i];
+ next_hop = &dpo_ctx->next_hops[i];
face_vft = hicn_face_get_vft (next_hop->dpoi_type);
if (face_vft != NULL)
{
@@ -154,132 +109,53 @@ format_hicn_strategy_rr_ctx (u8 * s, va_list * ap)
s =
format (s, "%U ", face_vft->format_face, next_hop->dpoi_index,
indent);
- s = format (s, " %s", buf);
+ s = format (s, " %s", buf);
}
}
return (s);
}
-static index_t
-hicn_strategy_rr_ctx_get_index (hicn_strategy_rr_ctx_t * cd)
-{
- return (cd - hicn_strategy_rr_ctx_pool);
-}
-
-int
+void
hicn_strategy_rr_ctx_create (dpo_proto_t proto, const dpo_id_t * next_hop,
int nh_len, index_t * dpo_idx)
{
hicn_strategy_rr_ctx_t *hicn_strategy_rr_ctx;
- int ret = HICN_ERROR_NONE, i;
+ hicn_dpo_ctx_t *hicn_strategy_ctx;
/* Allocate a hicn_dpo_ctx on the vpp pool and initialize it */
- pool_get (hicn_strategy_rr_ctx_pool, hicn_strategy_rr_ctx);
+ hicn_strategy_ctx = hicn_strategy_dpo_ctx_alloc ();
+ hicn_strategy_rr_ctx = (hicn_strategy_rr_ctx_t *) hicn_strategy_ctx->data;
- *dpo_idx = hicn_strategy_rr_ctx_get_index (hicn_strategy_rr_ctx);
+ *dpo_idx = hicn_strategy_dpo_ctx_get_index (hicn_strategy_ctx);
- init_dpo_ctx (&(hicn_strategy_rr_ctx->default_ctx));
-
- for (i = 0; i < HICN_PARAM_FIB_ENTRY_NHOPS_MAX && i < nh_len; i++)
- {
- clib_memcpy (&hicn_strategy_rr_ctx->default_ctx.next_hops[i],
- &next_hop[i], sizeof (dpo_id_t));
- hicn_strategy_rr_ctx->default_ctx.entry_count++;
- }
+ init_dpo_ctx (hicn_strategy_ctx, next_hop, nh_len, hicn_dpo_type_rr);
hicn_strategy_rr_ctx->current_nhop = 0;
-
- return ret;
-}
-
-hicn_dpo_ctx_t *
-hicn_strategy_rr_ctx_get (index_t index)
-{
- hicn_strategy_rr_ctx_t *hicn_strategy_rr_ctx = NULL;
- if (!pool_is_free_index (hicn_strategy_rr_ctx_pool, index))
- {
- hicn_strategy_rr_ctx =
- (pool_elt_at_index (hicn_strategy_rr_ctx_pool, index));
- }
- return (hicn_dpo_ctx_t *)hicn_strategy_rr_ctx;
}
int
hicn_strategy_rr_ctx_add_nh (const dpo_id_t * nh, index_t dpo_idx)
{
- hicn_strategy_rr_ctx_t *hicn_strategy_rr_ctx =
- (hicn_strategy_rr_ctx_t *) hicn_strategy_rr_ctx_get (dpo_idx);
+ hicn_dpo_ctx_t *hicn_strategy_dpo_ctx = hicn_strategy_dpo_ctx_get (dpo_idx);
+ u8 pos = 0;
- if (hicn_strategy_rr_ctx == NULL)
+ if (hicn_strategy_dpo_ctx == NULL)
{
return HICN_ERROR_STRATEGY_NOT_FOUND;
}
- int empty = hicn_strategy_rr_ctx->default_ctx.entry_count;
-
- /* Iterate through the list of faces to add new faces */
- for (int i = 0; i < hicn_strategy_rr_ctx->default_ctx.entry_count; i++)
- {
- if (!memcmp
- (nh, &hicn_strategy_rr_ctx->default_ctx.next_hops[i],
- sizeof (dpo_id_t)))
- {
- /* 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);
- if (face->shared.flags & HICN_FACE_FLAGS_DELETED)
- {
- continue;
- }
- return HICN_ERROR_DPO_CTX_NHOPS_EXISTS;
- }
- }
-
- /* Get an empty place */
- if (empty > HICN_PARAM_FIB_ENTRY_NHOPS_MAX)
- {
- return HICN_ERROR_DPO_CTX_NHOPS_NS;
- }
-
- clib_memcpy (&hicn_strategy_rr_ctx->default_ctx.next_hops[empty], nh,
- sizeof (dpo_id_t));
- hicn_strategy_rr_ctx->default_ctx.entry_count++;
-
+ hicn_strategy_dpo_ctx_add_nh (nh, hicn_strategy_dpo_ctx, &pos);
+ //nothing else to initialize in this strategy
return HICN_ERROR_NONE;
}
int
-hicn_strategy_rr_ctx_del_nh (hicn_face_id_t face_id, index_t dpo_idx,
- fib_prefix_t * fib_pfx)
+hicn_strategy_rr_ctx_del_nh (hicn_face_id_t face_id, index_t dpo_idx)
{
- hicn_strategy_rr_ctx_t *hicn_strategy_rr_ctx =
- (hicn_strategy_rr_ctx_t *) hicn_strategy_rr_ctx_get (dpo_idx);
- int ret = HICN_ERROR_DPO_CTX_NOT_FOUND;
- dpo_id_t invalid = NEXT_HOP_INVALID;
-
- if (hicn_strategy_rr_ctx == NULL)
- {
- return HICN_ERROR_STRATEGY_NOT_FOUND;
- }
-
- for (int i = 0; i < hicn_strategy_rr_ctx->default_ctx.entry_count; i++)
- {
- if (hicn_strategy_rr_ctx->default_ctx.next_hops[i].dpoi_index ==
- face_id)
- {
- hicn_face_unlock (&hicn_strategy_rr_ctx->
- default_ctx.next_hops[i]);
- hicn_strategy_rr_ctx->default_ctx.entry_count--;
- hicn_strategy_rr_ctx->default_ctx.next_hops[i] = hicn_strategy_rr_ctx->default_ctx.next_hops[hicn_strategy_rr_ctx->default_ctx.entry_count];
- hicn_strategy_rr_ctx->default_ctx.next_hops[hicn_strategy_rr_ctx->default_ctx.entry_count] = invalid;
- ret = HICN_ERROR_NONE;
- break;
- }
- }
-
- return ret;
+ hicn_dpo_ctx_t *hicn_strategy_dpo_ctx = hicn_strategy_dpo_ctx_get (dpo_idx);
+ //No need to change the current_nhop. It will be updated at the next selection.
+ return hicn_strategy_dpo_ctx_del_nh (face_id, hicn_strategy_dpo_ctx);
}
/*
diff --git a/hicn-plugin/src/strategies/dpo_rr.h b/hicn-plugin/src/strategies/dpo_rr.h
index a12183653..8afd0dabc 100644
--- a/hicn-plugin/src/strategies/dpo_rr.h
+++ b/hicn-plugin/src/strategies/dpo_rr.h
@@ -25,26 +25,10 @@
typedef struct hicn_strategy_rr_ctx_s
{
- hicn_dpo_ctx_t default_ctx;
-
u8 current_nhop;
} hicn_strategy_rr_ctx_t;
/**
- * @brief Lock the round robin ctx
- *
- * @param dpo Identifier of the dpo of the rr ctx
- */
-void hicn_strategy_rr_ctx_lock (dpo_id_t * dpo);
-
-/**
- * @brief Unlock the round robin ctx
- *
- * @param dpo Identifier of the dpo of the rr ctx
- */
-void hicn_strategy_rr_ctx_unlock (dpo_id_t * dpo);
-
-/**
* @brief Format the dpo ctx for a human-readable string
*
* @param s String to which to append the formatted dpo ctx
@@ -55,8 +39,8 @@ void hicn_strategy_rr_ctx_unlock (dpo_id_t * dpo);
u8 *format_hicn_strategy_rr_ctx (u8 * s, va_list * ap);
const static dpo_vft_t dpo_strategy_rr_ctx_vft = {
- .dv_lock = hicn_strategy_rr_ctx_lock,
- .dv_unlock = hicn_strategy_rr_ctx_unlock,
+ .dv_lock = hicn_strategy_dpo_ctx_lock,
+ .dv_unlock = hicn_strategy_dpo_ctx_unlock,
.dv_format = format_hicn_strategy_rr_ctx,
};
@@ -77,7 +61,7 @@ hicn_dpo_ctx_t *hicn_strategy_rr_ctx_get (index_t index);
* @param dpo_idx index_t that will hold the index of the created dpo ctx
* @return HICN_ERROR_NONE if the creation was fine, otherwise EINVAL
*/
-int
+void
hicn_strategy_rr_ctx_create (dpo_proto_t proto, const dpo_id_t * next_hop,
int nh_len, index_t * dpo_idx);
@@ -104,9 +88,7 @@ int hicn_strategy_rr_ctx_add_nh (const dpo_id_t * nh, index_t dpo_idx);
* @return HICN_ERROR_NONE if the update or insert was fine,
* otherwise HICN_ERROR_DPO_CTS_NOT_FOUND
*/
-int
-hicn_strategy_rr_ctx_del_nh (hicn_face_id_t face_id, index_t dpo_idx,
- fib_prefix_t * fib_pfx);
+int hicn_strategy_rr_ctx_del_nh (hicn_face_id_t face_id, index_t dpo_idx);
/**
* @brief Prefetch a dpo
@@ -115,14 +97,40 @@ hicn_strategy_rr_ctx_del_nh (hicn_face_id_t face_id, index_t dpo_idx,
*/
void hicn_strategy_rr_ctx_prefetch (index_t dpo_idx);
+/**
+ * @brief Return true if the dpo is of type strategy rr
+ *
+ * @param dpo Dpo to check the type
+ */
int hicn_dpo_is_type_strategy_rr (const dpo_id_t * dpo);
+/**
+ * @brief Initialize the Round Robin strategy
+ */
void hicn_dpo_strategy_rr_module_init (void);
+/**
+ * @brief Return the dpo type for the Round Robin strategy
+ */
dpo_type_t hicn_dpo_strategy_rr_get_type (void);
+/**
+ * @brief Format the dpo ctx for the strategy Round Robin
+ *
+ * @param s String to append the formatted dpo ctx
+ * @param ap List of arguments to format
+ */
u8 *format_hicn_dpo_strategy_rr (u8 * s, va_list * ap);
+/**
+ * @brief Format the dpo ctx for the strategy Round Robin. To
+ * call from other functions
+ *
+ * @param s String to append the formatted dpo ctx
+ * @param ... List of arguments to format
+ */
+u8 *hicn_strategy_rr_format_ctx (u8 * s, int n, ...);
+
#endif // __HICN_DPO_RR_H__
diff --git a/hicn-plugin/src/strategies/strategy_mw.c b/hicn-plugin/src/strategies/strategy_mw.c
index 40e062bd8..2422d4fed 100644
--- a/hicn-plugin/src/strategies/strategy_mw.c
+++ b/hicn-plugin/src/strategies/strategy_mw.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Copyright (c) 2017-2020 Cisco and/or its affiliates.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
@@ -12,16 +12,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-#include <vlib/vlib.h>
-#include <vnet/vnet.h>
-
+#include "dpo_mw.h"
#include "../strategy.h"
#include "../strategy_dpo_ctx.h"
-#include "dpo_mw.h"
#include "../faces/face.h"
-#include "../route.h"
-#include "../pcs.h"
+#include "../hashtb.h"
#include "../strategy_dpo_manager.h"
/* Simple strategy that chooses the next hop with the maximum weight */
@@ -32,20 +27,17 @@ void hicn_on_interest_timeout_mw (index_t dpo_idx);
u32 hicn_select_next_hop_mw (index_t dpo_idx, int *nh_idx,
dpo_id_t ** outface);
u32 get_strategy_node_index_mw (void);
+u8 *hicn_strategy_format_trace_mw (u8 * s, hicn_strategy_trace_t * t);
+u8 *hicn_strategy_format_mw (u8 * s, va_list * ap);
+
static hicn_strategy_vft_t hicn_strategy_mw_vft = {
.hicn_receive_data = &hicn_receive_data_mw,
.hicn_add_interest = &hicn_add_interest_mw,
.hicn_on_interest_timeout = &hicn_on_interest_timeout_mw,
.hicn_select_next_hop = &hicn_select_next_hop_mw,
- .get_strategy_node_index = get_strategy_node_index_mw
-};
-
-/* Stats string values */
-static char *hicn_strategy_error_strings[] = {
-#define _(sym, string) string,
- foreach_hicnfwd_error
-#undef _
+ .hicn_format_strategy_trace = hicn_strategy_format_trace_mw,
+ .hicn_format_strategy = &hicn_strategy_format_mw
};
/*
@@ -57,29 +49,22 @@ hicn_mw_strategy_get_vft (void)
return &hicn_strategy_mw_vft;
}
-/* Registration struct for a graph node */
-vlib_node_registration_t hicn_mw_strategy_node;
-
-u32
-get_strategy_node_index_mw (void)
-{
- return hicn_mw_strategy_node.index;
-}
-
/* DPO should be give in input as it containes all the information to calculate the next hops*/
u32
hicn_select_next_hop_mw (index_t dpo_idx, int *nh_idx, dpo_id_t ** outface)
{
- hicn_strategy_mw_ctx_t *hicn_strategy_mw_ctx =
- (hicn_strategy_mw_ctx_t *) hicn_strategy_mw_ctx_get (dpo_idx);
+ hicn_dpo_ctx_t *dpo_ctx = hicn_strategy_dpo_ctx_get (dpo_idx);
- if(hicn_strategy_mw_ctx == NULL)
+ if (dpo_ctx == NULL)
return HICN_ERROR_STRATEGY_NOT_FOUND;
+ hicn_strategy_mw_ctx_t *hicn_strategy_mw_ctx =
+ (hicn_strategy_mw_ctx_t *) dpo_ctx->data;
+
u8 next_hop_index = 0;
- for (int i = 0; i < hicn_strategy_mw_ctx->default_ctx.entry_count; i++)
+ for (int i = 0; i < dpo_ctx->entry_count; i++)
{
- if (dpo_id_is_valid (&hicn_strategy_mw_ctx->default_ctx.next_hops[i]))
+ if (dpo_id_is_valid (&dpo_ctx->next_hops[i]))
{
if (hicn_strategy_mw_ctx->weight[next_hop_index] <
hicn_strategy_mw_ctx->weight[i])
@@ -89,33 +74,21 @@ hicn_select_next_hop_mw (index_t dpo_idx, int *nh_idx, dpo_id_t ** outface)
}
}
- if (!dpo_id_is_valid
- (&hicn_strategy_mw_ctx->default_ctx.next_hops[next_hop_index]))
+ if (!dpo_id_is_valid (&dpo_ctx->next_hops[next_hop_index]))
return HICN_ERROR_STRATEGY_NH_NOT_FOUND;
- *outface =
- (dpo_id_t *) & hicn_strategy_mw_ctx->default_ctx.
- next_hops[next_hop_index];
+ *outface = (dpo_id_t *) & dpo_ctx->next_hops[next_hop_index];
return HICN_ERROR_NONE;
}
-uword
-hicn_mw_strategy_node_fn (vlib_main_t * vm,
- vlib_node_runtime_t * node, vlib_frame_t * frame)
-{
- return hicn_forward_interest_fn (vm, node, frame, &hicn_strategy_mw_vft,
- hicn_dpo_strategy_mw_get_type (),
- &hicn_mw_strategy_node);
-}
-
void
hicn_add_interest_mw (index_t dpo_ctx_idx, hicn_hash_entry_t * hash_entry)
{
hash_entry->dpo_ctx_id = dpo_ctx_idx;
dpo_id_t hicn_dpo_id =
{ hicn_dpo_strategy_mw_get_type (), 0, 0, dpo_ctx_idx };
- hicn_strategy_mw_ctx_lock (&hicn_dpo_id);
+ hicn_strategy_dpo_ctx_lock (&hicn_dpo_id);
hash_entry->vft_id = hicn_dpo_get_vft_id (&hicn_dpo_id);
}
@@ -132,41 +105,25 @@ hicn_receive_data_mw (index_t dpo_idx, int nh_idx)
/* packet trace format function */
-static u8 *
-hicn_strategy_format_trace_mw (u8 * s, va_list * args)
+u8 *
+hicn_strategy_format_trace_mw (u8 * s, hicn_strategy_trace_t * t)
{
- CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
- CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
- hicn_strategy_trace_t *t = va_arg (*args, hicn_strategy_trace_t *);
-
s = format (s, "Strategy_mw: pkt: %d, sw_if_index %d, next index %d",
(int) t->pkt_type, t->sw_if_index, t->next_index);
return (s);
}
-/*
- * Node registration for the forwarder node
- */
-/* *INDENT-OFF* */
-VLIB_REGISTER_NODE (hicn_mw_strategy_node) =
+u8 *
+hicn_strategy_format_mw (u8 * s, va_list * ap)
{
- .name = "hicn-mw-strategy",
- .function = hicn_mw_strategy_node_fn,
- .vector_size = sizeof (u32),
- .runtime_data_bytes = sizeof (int) + sizeof(hicn_pit_cs_t *),
- .format_trace = hicn_strategy_format_trace_mw,
- .type = VLIB_NODE_TYPE_INTERNAL,
- .n_errors = ARRAY_LEN (hicn_strategy_error_strings),
- .error_strings = hicn_strategy_error_strings,
- .n_next_nodes = HICN_STRATEGY_N_NEXT,
- .next_nodes = {
- [HICN_STRATEGY_NEXT_INTEREST_HITPIT] = "hicn-interest-hitpit",
- [HICN_STRATEGY_NEXT_INTEREST_HITCS] = "hicn-interest-hitcs",
- [HICN_STRATEGY_NEXT_ERROR_DROP] = "error-drop",
- [HICN_STRATEGY_NEXT_EMPTY] = "ip4-lookup",
- },
-};
-/* *INDENT-ON* */
+
+ u32 indent = va_arg (*ap, u32);
+ s =
+ format (s,
+ "Static Weights: weights are updated by the control plane, next hop is the one with the maximum weight.\n",
+ indent);
+ return (s);
+}
/*
* fd.io coding-style-patch-verification: ON
diff --git a/hicn-plugin/src/strategies/strategy_mw.h b/hicn-plugin/src/strategies/strategy_mw.h
index 10b08c05f..f64f1fdc7 100644
--- a/hicn-plugin/src/strategies/strategy_mw.h
+++ b/hicn-plugin/src/strategies/strategy_mw.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Copyright (c) 2017-2020 Cisco and/or its affiliates.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
@@ -18,6 +18,9 @@
#include "../strategy.h"
+/**
+ * @brief Return the vft for the Maximum Weight strategy
+ */
hicn_strategy_vft_t *hicn_mw_strategy_get_vft (void);
#endif // __HICN_STRATEGY_MW_H__
diff --git a/hicn-plugin/src/strategies/strategy_mw_cli.c b/hicn-plugin/src/strategies/strategy_mw_cli.c
index 50d4d21f0..701f96fa7 100644
--- a/hicn-plugin/src/strategies/strategy_mw_cli.c
+++ b/hicn-plugin/src/strategies/strategy_mw_cli.c
@@ -38,8 +38,6 @@ hicn_mw_strategy_cli_set_weight_command_fn (vlib_main_t * vm,
u32 weight = HICN_PARAM_FIB_ENTRY_NHOP_WGHT_DFLT;
hicn_dpo_ctx_t *hicn_dpo_ctx;
const dpo_id_t *hicn_dpo_id;
- u32 vft_id;
- const hicn_dpo_vft_t *dpo_vft;
/* Get a line of input. */
unformat_input_t _line_input, *line_input = &_line_input;
@@ -79,14 +77,14 @@ hicn_mw_strategy_cli_set_weight_command_fn (vlib_main_t * vm,
goto done;
}
- prefix.fp_proto = ip46_address_is_ip4(&prefix.fp_addr) ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
+ prefix.fp_proto =
+ ip46_address_is_ip4 (&prefix.
+ fp_addr) ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
ret = hicn_route_get_dpo (&prefix, &hicn_dpo_id, &fib_index);
if (ret == HICN_ERROR_NONE)
{
- vft_id = hicn_dpo_get_vft_id (hicn_dpo_id);
- dpo_vft = hicn_dpo_get_vft (vft_id);
- hicn_dpo_ctx = dpo_vft->hicn_dpo_get_ctx (hicn_dpo_id->dpoi_index);
+ hicn_dpo_ctx = hicn_strategy_dpo_ctx_get (hicn_dpo_id->dpoi_index);
if (hicn_dpo_ctx == NULL
|| hicn_dpo_id->dpoi_type != hicn_dpo_strategy_mw_get_type ())
diff --git a/hicn-plugin/src/strategies/strategy_rr.c b/hicn-plugin/src/strategies/strategy_rr.c
index 53b9b688f..cdcca7f2a 100644
--- a/hicn-plugin/src/strategies/strategy_rr.c
+++ b/hicn-plugin/src/strategies/strategy_rr.c
@@ -13,15 +13,11 @@
* limitations under the License.
*/
-#include <vlib/vlib.h>
-#include <vnet/vnet.h>
-
+#include "dpo_rr.h"
#include "../strategy.h"
#include "../strategy_dpo_ctx.h"
-#include "dpo_rr.h"
#include "../faces/face.h"
-#include "../route.h"
-#include "../pcs.h"
+#include "../hashtb.h"
#include "../strategy_dpo_manager.h"
/* Simple strategy that chooses the next hop with the maximum weight */
@@ -31,21 +27,17 @@ void hicn_add_interest_rr (index_t dpo_idx, hicn_hash_entry_t * pit_entry);
void hicn_on_interest_timeout_rr (index_t dpo_idx);
u32 hicn_select_next_hop_rr (index_t dpo_idx, int *nh_idx,
dpo_id_t ** outface);
-u32 get_strategy_node_index_rr (void);
+u8 *hicn_strategy_format_trace_rr (u8 * s, hicn_strategy_trace_t * t);
+u8 *hicn_strategy_format_rr (u8 * s, va_list * ap);
+
static hicn_strategy_vft_t hicn_strategy_rr_vft = {
.hicn_receive_data = &hicn_receive_data_rr,
.hicn_add_interest = &hicn_add_interest_rr,
.hicn_on_interest_timeout = &hicn_on_interest_timeout_rr,
.hicn_select_next_hop = &hicn_select_next_hop_rr,
- .get_strategy_node_index = get_strategy_node_index_rr
-};
-
-/* Stats string values */
-static char *hicn_strategy_error_strings[] = {
-#define _(sym, string) string,
- foreach_hicnfwd_error
-#undef _
+ .hicn_format_strategy_trace = &hicn_strategy_format_trace_rr,
+ .hicn_format_strategy = &hicn_strategy_format_rr
};
/*
@@ -57,64 +49,48 @@ hicn_rr_strategy_get_vft (void)
return &hicn_strategy_rr_vft;
}
-/* Registration struct for a graph node */
-vlib_node_registration_t hicn_rr_strategy_node;
-
-u32
-get_strategy_node_index_rr (void)
-{
- return hicn_rr_strategy_node.index;
-}
-
/* DPO should be give in input as it containes all the information to calculate the next hops*/
u32
hicn_select_next_hop_rr (index_t dpo_idx, int *nh_idx, dpo_id_t ** outface)
{
+ hicn_dpo_ctx_t *dpo_ctx = hicn_strategy_dpo_ctx_get (dpo_idx);
+
+ if (dpo_ctx == NULL)
+ return HICN_ERROR_STRATEGY_NOT_FOUND;
+
hicn_strategy_rr_ctx_t *hicn_strategy_rr_ctx =
- (hicn_strategy_rr_ctx_t *) hicn_strategy_rr_ctx_get (dpo_idx);
+ (hicn_strategy_rr_ctx_t *) dpo_ctx->data;
if (dpo_id_is_valid
- (&hicn_strategy_rr_ctx->default_ctx.
- next_hops[hicn_strategy_rr_ctx->current_nhop]))
+ (&dpo_ctx->next_hops[hicn_strategy_rr_ctx->current_nhop]))
{
*outface =
- (dpo_id_t *) & hicn_strategy_rr_ctx->default_ctx.
- next_hops[hicn_strategy_rr_ctx->current_nhop];
+ (dpo_id_t *) & dpo_ctx->next_hops[hicn_strategy_rr_ctx->current_nhop];
}
else
return HICN_ERROR_STRATEGY_NH_NOT_FOUND;
hicn_strategy_rr_ctx->current_nhop =
- (hicn_strategy_rr_ctx->current_nhop +
- 1) % hicn_strategy_rr_ctx->default_ctx.entry_count;
+ (hicn_strategy_rr_ctx->current_nhop + 1) % dpo_ctx->entry_count;
return HICN_ERROR_NONE;
}
-uword
-hicn_rr_strategy_node_fn (vlib_main_t * vm,
- vlib_node_runtime_t * node, vlib_frame_t * frame)
-{
- return hicn_forward_interest_fn (vm, node, frame, &hicn_strategy_rr_vft,
- hicn_dpo_strategy_rr_get_type (),
- &hicn_rr_strategy_node);
-}
-
void
hicn_add_interest_rr (index_t dpo_ctx_idx, hicn_hash_entry_t * hash_entry)
{
hash_entry->dpo_ctx_id = dpo_ctx_idx;
dpo_id_t hicn_dpo_id =
{ hicn_dpo_strategy_rr_get_type (), 0, 0, dpo_ctx_idx };
- hicn_strategy_rr_ctx_lock (&hicn_dpo_id);
+ hicn_strategy_dpo_ctx_lock (&hicn_dpo_id);
hash_entry->vft_id = hicn_dpo_get_vft_id (&hicn_dpo_id);
}
void
hicn_on_interest_timeout_rr (index_t dpo_idx)
{
- /* Nothign to do in the rr strategy when we receive an interest */
+ /* Nothing to do in the rr strategy when we receive an interest */
}
void
@@ -124,41 +100,25 @@ hicn_receive_data_rr (index_t dpo_idx, int nh_idx)
/* packet trace format function */
-static u8 *
-hicn_strategy_format_trace_rr (u8 * s, va_list * args)
+u8 *
+hicn_strategy_format_trace_rr (u8 * s, hicn_strategy_trace_t * t)
{
- CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
- CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
- hicn_strategy_trace_t *t = va_arg (*args, hicn_strategy_trace_t *);
-
s = format (s, "Strategy_rr: pkt: %d, sw_if_index %d, next index %d",
(int) t->pkt_type, t->sw_if_index, t->next_index);
return (s);
}
-/*
- * Node registration for the forwarder node
- */
-/* *INDENT-OFF* */
-VLIB_REGISTER_NODE (hicn_rr_strategy_node) =
+u8 *
+hicn_strategy_format_rr (u8 * s, va_list * ap)
{
- .name = "hicn-rr-strategy",
- .function = hicn_rr_strategy_node_fn,
- .vector_size = sizeof (u32),
- .runtime_data_bytes = sizeof (int) + sizeof(hicn_pit_cs_t *),
- .format_trace = hicn_strategy_format_trace_rr,
- .type = VLIB_NODE_TYPE_INTERNAL,
- .n_errors = ARRAY_LEN (hicn_strategy_error_strings),
- .error_strings = hicn_strategy_error_strings,
- .n_next_nodes = HICN_STRATEGY_N_NEXT,
- .next_nodes = {
- [HICN_STRATEGY_NEXT_INTEREST_HITPIT] = "hicn-interest-hitpit",
- [HICN_STRATEGY_NEXT_INTEREST_HITCS] = "hicn-interest-hitcs",
- [HICN_STRATEGY_NEXT_ERROR_DROP] = "error-drop",
- [HICN_STRATEGY_NEXT_EMPTY] = "ip4-lookup",
- },
-};
-/* *INDENT-ON* */
+
+ u32 indent = va_arg (*ap, u32);
+ s =
+ format (s,
+ "Round Robin: next hop is chosen ciclying between all the available next hops, one after the other.\n",
+ indent);
+ return (s);
+}
/*
* fd.io coding-style-patch-verification: ON
diff --git a/hicn-plugin/src/strategies/strategy_rr.h b/hicn-plugin/src/strategies/strategy_rr.h
index 84149c36f..3936845fe 100644
--- a/hicn-plugin/src/strategies/strategy_rr.h
+++ b/hicn-plugin/src/strategies/strategy_rr.h
@@ -18,6 +18,9 @@
#include "../strategy.h"
+/**
+ * @brief Return the vft for the Round Robin strategy
+ */
hicn_strategy_vft_t *hicn_rr_strategy_get_vft (void);
#endif // __HICN_STRATEGY_RR_H__