summaryrefslogtreecommitdiffstats
path: root/hicn-plugin/src
diff options
context:
space:
mode:
authorLuca Muscariello <muscariello@ieee.org>2020-03-23 06:43:34 +0000
committerGerrit Code Review <gerrit@fd.io>2020-03-23 06:43:34 +0000
commite0db9608e092c5b1381f1bc8df68ef17f9f7ec87 (patch)
treea8345430e8773e21567b9a18b4eeb48ae9a7cb71 /hicn-plugin/src
parentd0ebc1438a58b108f8d1509356bfabeaf95000fa (diff)
parente6a120973cca65ca464d1323a6f7f4308dcb4717 (diff)
Merge "[HICN-547] Removing punting through acl for interests"
Diffstat (limited to 'hicn-plugin/src')
-rw-r--r--hicn-plugin/src/CMakeLists.txt5
-rw-r--r--hicn-plugin/src/data_pcslookup_node.c6
-rw-r--r--hicn-plugin/src/data_push_node.c2
-rw-r--r--hicn-plugin/src/faces/app/face_cons.c22
-rw-r--r--hicn-plugin/src/faces/face.c4
-rw-r--r--hicn-plugin/src/faces/ip/face_ip.c466
-rw-r--r--hicn-plugin/src/faces/udp/face_udp.c22
-rw-r--r--hicn-plugin/src/hashtb.c10
-rw-r--r--hicn-plugin/src/hashtb.h19
-rw-r--r--hicn-plugin/src/hicn_api.c38
-rw-r--r--hicn-plugin/src/interest_hitcs.h4
-rw-r--r--hicn-plugin/src/interest_hitcs_node.c8
-rw-r--r--hicn-plugin/src/interest_hitpit.h3
-rw-r--r--hicn-plugin/src/interest_hitpit_node.c7
-rw-r--r--hicn-plugin/src/interest_pcslookup.h3
-rw-r--r--hicn-plugin/src/interest_pcslookup_node.c9
-rw-r--r--hicn-plugin/src/mapme_ack_node.c14
-rw-r--r--hicn-plugin/src/mapme_ctrl_node.c21
-rw-r--r--hicn-plugin/src/mapme_eventmgr.c30
-rw-r--r--hicn-plugin/src/pcs.h119
-rw-r--r--hicn-plugin/src/route.c22
-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
-rw-r--r--hicn-plugin/src/strategy.h50
-rw-r--r--hicn-plugin/src/strategy_dpo_ctx.c163
-rw-r--r--hicn-plugin/src/strategy_dpo_ctx.h132
-rw-r--r--hicn-plugin/src/strategy_dpo_manager.c13
-rw-r--r--hicn-plugin/src/strategy_dpo_manager.h26
-rw-r--r--hicn-plugin/src/strategy_node.c (renamed from hicn-plugin/src/strategy.c)82
36 files changed, 1007 insertions, 1035 deletions
diff --git a/hicn-plugin/src/CMakeLists.txt b/hicn-plugin/src/CMakeLists.txt
index 68c583e0b..db8fcef4c 100644
--- a/hicn-plugin/src/CMakeLists.txt
+++ b/hicn-plugin/src/CMakeLists.txt
@@ -66,8 +66,9 @@ set(HICN_PLUGIN_SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/mgmt.c
${CMAKE_CURRENT_SOURCE_DIR}/pcs.c
${CMAKE_CURRENT_SOURCE_DIR}/route.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/strategy_dpo_ctx.c
${CMAKE_CURRENT_SOURCE_DIR}/strategy_dpo_manager.c
- ${CMAKE_CURRENT_SOURCE_DIR}/strategy.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/strategy_node.c
${CMAKE_CURRENT_SOURCE_DIR}/interest_pcslookup_node.c
${CMAKE_CURRENT_SOURCE_DIR}/interest_hitpit_node.c
${CMAKE_CURRENT_SOURCE_DIR}/interest_hitcs_node.c
@@ -298,4 +299,4 @@ set(HICNPLUGIN_INCLUDE_DIRS
${CMAKE_CURRENT_BINARY_DIR}/vpp_plugins
${VPP_INCLUDE_DIRS}
CACHE INTERNAL "" FORCE)
-set(HICNPLUGIN_LIBRARIES ${VPP_LIBRARIES} CACHE INTERNAL "" FORCE) \ No newline at end of file
+set(HICNPLUGIN_LIBRARIES ${VPP_LIBRARIES} CACHE INTERNAL "" FORCE)
diff --git a/hicn-plugin/src/data_pcslookup_node.c b/hicn-plugin/src/data_pcslookup_node.c
index 1ae36202f..cbea07871 100644
--- a/hicn-plugin/src/data_pcslookup_node.c
+++ b/hicn-plugin/src/data_pcslookup_node.c
@@ -73,7 +73,7 @@ hicn_data_pcslookup_node_fn (vlib_main_t * vm,
hicn_name_t name;
hicn_header_t *hicn0 = NULL;
u32 node_id0 = 0;
- u8 dpo_ctx_id0 = 0;
+ index_t dpo_ctx_id0 = 0;
int ret0;
u8 vft_id0;
u8 is_cs0;
@@ -117,7 +117,9 @@ hicn_data_pcslookup_node_fn (vlib_main_t * vm,
int res =
hicn_hashtb_lookup_node (rt->pitcs->pcs_table, nameptr,
namelen, name_hash,
- 1 /*is_data. Do not take lock if hit CS */ ,
+ 1
+ /*is_data. Do not take lock if hit CS */
+ ,
&node_id0, &dpo_ctx_id0, &vft_id0,
&is_cs0, &hash_entry_id, &bucket_id,
&bucket_is_overflown);
diff --git a/hicn-plugin/src/data_push_node.c b/hicn-plugin/src/data_push_node.c
index 21ebae16f..fc19362f9 100644
--- a/hicn-plugin/src/data_push_node.c
+++ b/hicn-plugin/src/data_push_node.c
@@ -99,7 +99,7 @@ hicn_new_data (vlib_main_t * vm, hicn_data_push_runtime_t * rt,
hicn_header_t *hicn0 = vlib_buffer_get_current (b0);
hicn_buffer_t *hicnb0 = hicn_get_buffer (b0);
u32 node_id0 = 0;
- u8 dpo_ctx_id0 = ~0;
+ index_t dpo_ctx_id0 = ~0;
u8 vft_id0 = default_dpo.hicn_dpo_get_type ();
u8 is_cs0 = 1;
u8 hash_entry_id = 0;
diff --git a/hicn-plugin/src/faces/app/face_cons.c b/hicn-plugin/src/faces/app/face_cons.c
index f258da787..e51201c21 100644
--- a/hicn-plugin/src/faces/app/face_cons.c
+++ b/hicn-plugin/src/faces/app/face_cons.c
@@ -73,10 +73,7 @@ hicn_face_cons_add (ip4_address_t * nh_addr4, ip6_address_t * nh_addr6,
face = hicn_dpoi_get_from_idx (*faceid2);
face->shared.flags |= HICN_FACE_FLAGS_APPFACE_CONS;
- return vnet_feature_enable_disable ("ip6-unicast",
- "hicn-iface-ip6-input", swif, 1, 0,
- 0) ==
- 0 ? HICN_ERROR_NONE : HICN_ERROR_APPFACE_FEATURE;
+ return HICN_ERROR_NONE;
}
int
@@ -89,13 +86,7 @@ hicn_face_cons_del (hicn_face_id_t face_id)
if (face->shared.flags & HICN_FACE_FLAGS_APPFACE_CONS)
{
- int ret = hicn_face_ip_del (face_id);
-
- return ret ==
- HICN_ERROR_NONE
- ? (vnet_feature_enable_disable
- ("ip6-unicast", "hicn-iface-ip6-input", face->shared.sw_if, 0,
- 0, 0) == 0 ? HICN_ERROR_NONE : HICN_ERROR_APPFACE_FEATURE) : ret;
+ return hicn_face_ip_del (face_id);
}
else
{
@@ -114,15 +105,6 @@ format_hicn_face_cons (u8 * s, va_list * args)
return s;
}
-/* *INDENT-OFF* */
-VNET_FEATURE_INIT(hicn_cons_app, static)=
-{
- .arc_name = "ip6-unicast",
- .node_name = "hicn-iface-ip6-input",
- .runs_before = VNET_FEATURES("ip6-inacl"),
-};
-/* *INDENT-ON* */
-
/*
* fd.io coding-style-patch-verification: ON
*
diff --git a/hicn-plugin/src/faces/face.c b/hicn-plugin/src/faces/face.c
index fa9d0d203..f2dcdd151 100644
--- a/hicn-plugin/src/faces/face.c
+++ b/hicn-plugin/src/faces/face.c
@@ -42,7 +42,7 @@ const char *HICN_FACE_CTRX_STRING[] = {
u8 *
face_show (u8 * s, int face_id, u32 indent)
{
- s = format (s, "Faces:\n", indent);
+ s = format (s, "%U Faces:\n", format_white_space, indent);
indent += 4;
int i;
vec_foreach_index (i, face_dpo_vec)
@@ -97,7 +97,7 @@ format_hicn_face_all (u8 * s, int n, ...)
va_start (ap, n);
u32 indent = va_arg (ap, u32);
- s = format (s, "Faces: %d\n", indent);
+ s = format (s, "%U Faces:\n", format_white_space, indent);
hicn_face_t *face;
diff --git a/hicn-plugin/src/faces/ip/face_ip.c b/hicn-plugin/src/faces/ip/face_ip.c
index f4ae5429d..a2fe069ed 100644
--- a/hicn-plugin/src/faces/ip/face_ip.c
+++ b/hicn-plugin/src/faces/ip/face_ip.c
@@ -41,22 +41,12 @@ hicn_face_ip_init (vlib_main_t * vm)
/* Default Strategy has index 0 and it always exists */
strategy_face_ip4_vlib_edge = vlib_node_add_next (vm,
- hicn_dpo_get_strategy_vft
- (default_dpo.
- hicn_dpo_get_type ())->
- get_strategy_node_index
- (),
- hicn_face_ip4_output_node.
- index);
+ hicn_strategy_node.index,
+ hicn_face_ip4_output_node.index);
strategy_face_ip6_vlib_edge = vlib_node_add_next (vm,
- hicn_dpo_get_strategy_vft
- (default_dpo.
- hicn_dpo_get_type ())->
- get_strategy_node_index
- (),
- hicn_face_ip6_output_node.
- index);
+ hicn_strategy_node.index,
+ hicn_face_ip6_output_node.index);
/*
* Create and edge between al the other strategy nodes and the
* ip_encap nodes.
@@ -64,12 +54,10 @@ hicn_face_ip_init (vlib_main_t * vm)
for (int i = 1; i < strategy_nodes_n; i++)
{
u32 temp_index4 = vlib_node_add_next (vm,
- hicn_dpo_get_strategy_vft_from_id
- (i)->get_strategy_node_index (),
+ hicn_strategy_node.index,
hicn_face_ip4_output_node.index);
u32 temp_index6 = vlib_node_add_next (vm,
- hicn_dpo_get_strategy_vft_from_id
- (i)->get_strategy_node_index (),
+ hicn_strategy_node.index,
hicn_face_ip6_output_node.index);
ASSERT (temp_index4 == strategy_face_ip4_vlib_edge);
ASSERT (temp_index6 == strategy_face_ip6_vlib_edge);
@@ -104,66 +92,74 @@ hicn_face_ip_del (hicn_face_id_t face_id)
{
hicn_face_ip4_get_key (&(face_ip->local_addr.ip4), face->shared.sw_if,
&key);
- hicn_face_ip_input_faces_t * in_faces_vec = hicn_face_ip4_get_vec(&(face_ip->local_addr.ip4), face->shared.sw_if,
- &hicn_face_ip_local_hashtb);
+ hicn_face_ip_input_faces_t *in_faces_vec =
+ hicn_face_ip4_get_vec (&(face_ip->local_addr.ip4), face->shared.sw_if,
+ &hicn_face_ip_local_hashtb);
if (in_faces_vec != NULL)
- {
- hicn_face_ip_vec_t * vec = pool_elt_at_index (hicn_vec_pool, in_faces_vec->vec_id);
- u32 index_face = vec_search(*vec, face_id);
- vec_del1(*vec, index_face);
-
- if (vec_len(*vec) == 0)
- {
- pool_put_index(hicn_vec_pool, in_faces_vec->vec_id);
- mhash_unset (&hicn_face_ip_local_hashtb, &key, (uword *) & old_key);
- vec_free(*vec);
- }
- else
- {
- /* Check if the face we are deleting is the preferred one. */
- /* If so, repleace with another. */
- if (in_faces_vec->face_id == face_id)
- {
- in_faces_vec->face_id = (*vec)[0];
- }
- }
- hicn_face_ip4_get_key (&(face_ip->remote_addr.ip4), face->shared.sw_if,
- &key);
- mhash_unset (&hicn_face_ip_remote_hashtb, &key, (uword *) & old_key2);
- }
+ {
+ hicn_face_ip_vec_t *vec =
+ pool_elt_at_index (hicn_vec_pool, in_faces_vec->vec_id);
+ u32 index_face = vec_search (*vec, face_id);
+ vec_del1 (*vec, index_face);
+
+ if (vec_len (*vec) == 0)
+ {
+ pool_put_index (hicn_vec_pool, in_faces_vec->vec_id);
+ mhash_unset (&hicn_face_ip_local_hashtb, &key,
+ (uword *) & old_key);
+ vec_free (*vec);
+ }
+ else
+ {
+ /* Check if the face we are deleting is the preferred one. */
+ /* If so, repleace with another. */
+ if (in_faces_vec->face_id == face_id)
+ {
+ in_faces_vec->face_id = (*vec)[0];
+ }
+ }
+ hicn_face_ip4_get_key (&(face_ip->remote_addr.ip4),
+ face->shared.sw_if, &key);
+ mhash_unset (&hicn_face_ip_remote_hashtb, &key,
+ (uword *) & old_key2);
+ }
}
else
{
hicn_face_ip6_get_key (&(face_ip->local_addr.ip6), face->shared.sw_if,
&key);
- hicn_face_ip_input_faces_t * in_faces_vec = hicn_face_ip6_get_vec(&(face_ip->local_addr.ip6), face->shared.sw_if,
- &hicn_face_ip_local_hashtb);
+ hicn_face_ip_input_faces_t *in_faces_vec =
+ hicn_face_ip6_get_vec (&(face_ip->local_addr.ip6), face->shared.sw_if,
+ &hicn_face_ip_local_hashtb);
if (in_faces_vec != NULL)
- {
- hicn_face_ip_vec_t * vec = pool_elt_at_index (hicn_vec_pool, in_faces_vec->vec_id);
- u32 index_face = vec_search(*vec, face_id);
- vec_del1(*vec, index_face);
-
- if (vec_len(*vec) == 0)
- {
- pool_put(hicn_vec_pool, vec);
- mhash_unset (&hicn_face_ip_local_hashtb, &key, (uword *) & old_key);
- vec_free(*vec);
- }
- else
- {
- /* Check if the face we are deleting is the preferred one. */
- /* If so, repleace with another. */
- if (in_faces_vec->face_id == face_id)
- {
- in_faces_vec->face_id = (*vec)[0];
- }
- }
- hicn_face_ip6_get_key (&(face_ip->remote_addr.ip6), face->shared.sw_if,
- &key);
- mhash_unset (&hicn_face_ip_remote_hashtb, &key, (uword *) & old_key);
- }
+ {
+ hicn_face_ip_vec_t *vec =
+ pool_elt_at_index (hicn_vec_pool, in_faces_vec->vec_id);
+ u32 index_face = vec_search (*vec, face_id);
+ vec_del1 (*vec, index_face);
+
+ if (vec_len (*vec) == 0)
+ {
+ pool_put (hicn_vec_pool, vec);
+ mhash_unset (&hicn_face_ip_local_hashtb, &key,
+ (uword *) & old_key);
+ vec_free (*vec);
+ }
+ else
+ {
+ /* Check if the face we are deleting is the preferred one. */
+ /* If so, repleace with another. */
+ if (in_faces_vec->face_id == face_id)
+ {
+ in_faces_vec->face_id = (*vec)[0];
+ }
+ }
+ hicn_face_ip6_get_key (&(face_ip->remote_addr.ip6),
+ face->shared.sw_if, &key);
+ mhash_unset (&hicn_face_ip_remote_hashtb, &key,
+ (uword *) & old_key);
+ }
}
return hicn_face_del (face_id);
}
@@ -171,17 +167,18 @@ hicn_face_ip_del (hicn_face_id_t face_id)
/**
* @brief Helper for handling midchain adjacencies
*/
-void face_midchain_fixup_t (vlib_main_t * vm,
- const struct ip_adjacency_t_ * adj,
- vlib_buffer_t * b0,
- const void *data) {
+void
+face_midchain_fixup_t (vlib_main_t * vm,
+ const struct ip_adjacency_t_ *adj,
+ vlib_buffer_t * b0, const void *data)
+{
vnet_buffer (b0)->sw_if_index[VLIB_TX] = 0;
};
/**
* @brief Build a rewrite string for the face.
*/
-static u8*
+static u8 *
face_build_rewrite_i (void)
{
/*
@@ -192,51 +189,56 @@ face_build_rewrite_i (void)
*/
u8 *rewrite = NULL;
- vec_validate(rewrite, 0);
- vec_reset_length(rewrite);
+ vec_validate (rewrite, 0);
+ vec_reset_length (rewrite);
return (rewrite);
}
always_inline int
hicn_face_ip_find_adj (const ip46_address_t * remote_addr,
- int sw_if, adj_index_t * adj)
+ int sw_if, adj_index_t * adj)
{
fib_prefix_t fib_pfx;
fib_node_index_t fib_entry_index;
fib_prefix_from_ip46_addr (remote_addr, &fib_pfx);
- fib_pfx.fp_len = ip46_address_is_ip4(remote_addr)? 32 : 128;
- vnet_link_t link_type = ip46_address_is_ip4(&fib_pfx.fp_addr)? VNET_LINK_IP4 : VNET_LINK_IP6;
- *adj = adj_nbr_find(fib_pfx.fp_proto, link_type, &fib_pfx.fp_addr, sw_if);
+ fib_pfx.fp_len = ip46_address_is_ip4 (remote_addr) ? 32 : 128;
+ vnet_link_t link_type =
+ ip46_address_is_ip4 (&fib_pfx.fp_addr) ? VNET_LINK_IP4 : VNET_LINK_IP6;
+ *adj = adj_nbr_find (fib_pfx.fp_proto, link_type, &fib_pfx.fp_addr, sw_if);
if (*adj == ADJ_INDEX_INVALID)
{
u32 fib_index = fib_table_find_or_create_and_lock (fib_pfx.fp_proto,
- HICN_FIB_TABLE,
- FIB_SOURCE_PRIORITY_HI);
+ HICN_FIB_TABLE,
+ FIB_SOURCE_PRIORITY_HI);
fib_entry_index = fib_table_lookup (fib_index, &fib_pfx);
if (fib_entry_index == (FIB_NODE_INDEX_INVALID))
- return HICN_ERROR_FACE_IP_ADJ_NOT_FOUND;
+ return HICN_ERROR_FACE_IP_ADJ_NOT_FOUND;
*adj = fib_entry_get_adj (fib_entry_index);
- ip_adjacency_t * temp = NULL;
+ ip_adjacency_t *temp = NULL;
if (*adj != ~0)
- temp = adj_get(*adj);
+ temp = adj_get (*adj);
if (temp == NULL || temp->lookup_next_index <= IP_LOOKUP_NEXT_MIDCHAIN)
- {
- if(sw_if != ~0)
- *adj = adj_nbr_add_or_lock(fib_pfx.fp_proto, link_type, remote_addr, sw_if);
- else
- return HICN_ERROR_FACE_IP_ADJ_NOT_FOUND;
- }
+ {
+ if (sw_if != ~0)
+ *adj =
+ adj_nbr_add_or_lock (fib_pfx.fp_proto, link_type, remote_addr,
+ sw_if);
+ else
+ return HICN_ERROR_FACE_IP_ADJ_NOT_FOUND;
+ }
else
- {
- adj_nbr_midchain_update_rewrite(*adj, &face_midchain_fixup_t, NULL, ADJ_FLAG_NONE, face_build_rewrite_i());
- adj_midchain_delegate_stack(*adj, fib_index, &fib_pfx);
- }
+ {
+ adj_nbr_midchain_update_rewrite (*adj, &face_midchain_fixup_t, NULL,
+ ADJ_FLAG_NONE,
+ face_build_rewrite_i ());
+ adj_midchain_delegate_stack (*adj, fib_index, &fib_pfx);
+ }
}
return HICN_ERROR_NONE;
@@ -249,8 +251,7 @@ hicn_face_ip_find_adj (const ip46_address_t * remote_addr,
int
hicn_face_ip_add (const ip46_address_t * local_addr,
const ip46_address_t * remote_addr,
- int sw_if, hicn_face_id_t * pfaceid,
- u8 is_app_prod)
+ int sw_if, hicn_face_id_t * pfaceid, u8 is_app_prod)
{
dpo_proto_t dpo_proto;
@@ -280,78 +281,83 @@ hicn_face_ip_add (const ip46_address_t * local_addr,
}
if (!(face->shared.flags & HICN_FACE_FLAGS_IFACE))
- return HICN_ERROR_FACE_ALREADY_CREATED;
+ return HICN_ERROR_FACE_ALREADY_CREATED;
hicn_face_ip_key_t key;
hicn_face_ip4_get_key (&(local_addr->ip4), sw_if, &key);
- hicn_face_ip_input_faces_t * in_faces =
+ hicn_face_ip_input_faces_t *in_faces =
hicn_face_ip4_get_vec (&(local_addr->ip4), sw_if,
- &hicn_face_ip_local_hashtb);
+ &hicn_face_ip_local_hashtb);
if (in_faces == NULL)
- {
- adj_index_t adj;
- int ret = hicn_face_ip_find_adj(remote_addr, sw_if, &adj);
- if (ret != HICN_ERROR_NONE)
- return ret;
-
- hicn_face_ip_input_faces_t in_faces_temp;
- hicn_face_ip_vec_t *vec;
- pool_get(hicn_vec_pool, vec);
- *vec = vec_new(hicn_face_ip_vec_t, 0);
- u32 index = vec - hicn_vec_pool;
- in_faces_temp.vec_id = index;
- vec_add1(*vec, *pfaceid);
-
- hicn_face_ip_t *ip_face = (hicn_face_ip_t *) face->data;
- clib_memcpy (&ip_face->local_addr, local_addr, sizeof (ip4_address_t));
- clib_memcpy (&ip_face->remote_addr, remote_addr,
- sizeof (ip4_address_t));
- face->shared.sw_if = sw_if;
- face->shared.flags = flags;
- face->shared.adj = adj;
-
- dpo_proto = DPO_PROTO_IP4;
-
- in_faces_temp.face_id = *pfaceid;
-
- mhash_set_mem (&hicn_face_ip_local_hashtb, &key, (uword *) &in_faces_temp, 0);
- }
+ {
+ adj_index_t adj;
+ int ret = hicn_face_ip_find_adj (remote_addr, sw_if, &adj);
+ if (ret != HICN_ERROR_NONE)
+ return ret;
+
+ hicn_face_ip_input_faces_t in_faces_temp;
+ hicn_face_ip_vec_t *vec;
+ pool_get (hicn_vec_pool, vec);
+ *vec = vec_new (hicn_face_ip_vec_t, 0);
+ u32 index = vec - hicn_vec_pool;
+ in_faces_temp.vec_id = index;
+ vec_add1 (*vec, *pfaceid);
+
+ hicn_face_ip_t *ip_face = (hicn_face_ip_t *) face->data;
+ clib_memcpy (&ip_face->local_addr, local_addr,
+ sizeof (ip4_address_t));
+ clib_memcpy (&ip_face->remote_addr, remote_addr,
+ sizeof (ip4_address_t));
+ face->shared.sw_if = sw_if;
+ face->shared.flags = flags;
+ face->shared.adj = adj;
+
+ dpo_proto = DPO_PROTO_IP4;
+
+ in_faces_temp.face_id = *pfaceid;
+
+ mhash_set_mem (&hicn_face_ip_local_hashtb, &key,
+ (uword *) & in_faces_temp, 0);
+ }
else
- {
- hicn_face_ip_vec_t * vec = pool_elt_at_index(hicn_vec_pool, in_faces->vec_id);
-
- /* */
- if (vec_search(*vec, *pfaceid) != ~0)
- return HICN_ERROR_FACE_ALREADY_CREATED;
-
- adj_index_t adj;
- int ret = hicn_face_ip_find_adj(remote_addr, sw_if, &adj);
- if (ret != HICN_ERROR_NONE)
- return ret;
-
- vec_add1(*vec, *pfaceid);
-
- hicn_face_ip_t *ip_face = (hicn_face_ip_t *) face->data;
- clib_memcpy (&ip_face->local_addr, local_addr, sizeof (ip4_address_t));
- clib_memcpy (&ip_face->remote_addr, remote_addr,
- sizeof (ip4_address_t));
- face->shared.sw_if = sw_if;
- face->shared.flags = flags;
- face->shared.adj = adj;
-
- dpo_proto = DPO_PROTO_IP4;
-
- mhash_set_mem (&hicn_face_ip_local_hashtb, &key, (uword *) in_faces, 0);
-
- /* If the face is an application producer face, we set it as the preferred incoming face. */
- /* This is required to handle the CS separation, and the push api in a lightway*/
- if (is_app_prod)
- {
- in_faces->face_id = *pfaceid;
- }
- }
+ {
+ hicn_face_ip_vec_t *vec =
+ pool_elt_at_index (hicn_vec_pool, in_faces->vec_id);
+
+ /* */
+ if (vec_search (*vec, *pfaceid) != ~0)
+ return HICN_ERROR_FACE_ALREADY_CREATED;
+
+ adj_index_t adj;
+ int ret = hicn_face_ip_find_adj (remote_addr, sw_if, &adj);
+ if (ret != HICN_ERROR_NONE)
+ return ret;
+
+ vec_add1 (*vec, *pfaceid);
+
+ hicn_face_ip_t *ip_face = (hicn_face_ip_t *) face->data;
+ clib_memcpy (&ip_face->local_addr, local_addr,
+ sizeof (ip4_address_t));
+ clib_memcpy (&ip_face->remote_addr, remote_addr,
+ sizeof (ip4_address_t));
+ face->shared.sw_if = sw_if;
+ face->shared.flags = flags;
+ face->shared.adj = adj;
+
+ dpo_proto = DPO_PROTO_IP4;
+
+ mhash_set_mem (&hicn_face_ip_local_hashtb, &key, (uword *) in_faces,
+ 0);
+
+ /* If the face is an application producer face, we set it as the preferred incoming face. */
+ /* This is required to handle the CS separation, and the push api in a lightway */
+ if (is_app_prod)
+ {
+ in_faces->face_id = *pfaceid;
+ }
+ }
}
else
{
@@ -371,83 +377,87 @@ hicn_face_ip_add (const ip46_address_t * local_addr,
}
if (!(face->shared.flags & HICN_FACE_FLAGS_IFACE))
- return HICN_ERROR_FACE_ALREADY_CREATED;
+ return HICN_ERROR_FACE_ALREADY_CREATED;
hicn_face_ip_key_t key;
hicn_face_ip6_get_key (&(local_addr->ip6), sw_if, &key);
- hicn_face_ip_input_faces_t * in_faces =
+ hicn_face_ip_input_faces_t *in_faces =
hicn_face_ip6_get_vec (&(local_addr->ip6), sw_if,
- &hicn_face_ip_local_hashtb);
+ &hicn_face_ip_local_hashtb);
if (in_faces == NULL)
- {
- adj_index_t adj;
- int ret = hicn_face_ip_find_adj(remote_addr, sw_if, &adj);
- if (ret != HICN_ERROR_NONE)
- return ret;
-
- hicn_face_ip_input_faces_t in_faces_temp;
- hicn_face_ip_vec_t *vec;
- pool_get(hicn_vec_pool, vec);
- vec_alloc(*vec, 1);
- u32 index = vec - hicn_vec_pool;
- in_faces_temp.vec_id = index;
- vec_add1(*vec, *pfaceid);
-
- hicn_face_ip_t *ip_face = (hicn_face_ip_t *) face->data;
- clib_memcpy (&ip_face->local_addr, local_addr, sizeof (ip6_address_t));
- clib_memcpy (&ip_face->remote_addr, remote_addr,
- sizeof (ip6_address_t));
- face->shared.sw_if = sw_if;
- face->shared.flags = flags;
- face->shared.adj = adj;
-
- dpo_proto = DPO_PROTO_IP6;
-
- in_faces_temp.face_id = *pfaceid;
-
- mhash_set_mem (&hicn_face_ip_local_hashtb, &key, (uword *) &in_faces_temp, 0);
- }
+ {
+ adj_index_t adj;
+ int ret = hicn_face_ip_find_adj (remote_addr, sw_if, &adj);
+ if (ret != HICN_ERROR_NONE)
+ return ret;
+
+ hicn_face_ip_input_faces_t in_faces_temp;
+ hicn_face_ip_vec_t *vec;
+ pool_get (hicn_vec_pool, vec);
+ vec_alloc (*vec, 1);
+ u32 index = vec - hicn_vec_pool;
+ in_faces_temp.vec_id = index;
+ vec_add1 (*vec, *pfaceid);
+
+ hicn_face_ip_t *ip_face = (hicn_face_ip_t *) face->data;
+ clib_memcpy (&ip_face->local_addr, local_addr,
+ sizeof (ip6_address_t));
+ clib_memcpy (&ip_face->remote_addr, remote_addr,
+ sizeof (ip6_address_t));
+ face->shared.sw_if = sw_if;
+ face->shared.flags = flags;
+ face->shared.adj = adj;
+
+ dpo_proto = DPO_PROTO_IP6;
+
+ in_faces_temp.face_id = *pfaceid;
+
+ mhash_set_mem (&hicn_face_ip_local_hashtb, &key,
+ (uword *) & in_faces_temp, 0);
+ }
else
- {
- hicn_face_ip_vec_t *vec = pool_elt_at_index(hicn_vec_pool, in_faces->vec_id);
-
- /* */
- if (vec_search(*vec, *pfaceid) != ~0)
- return HICN_ERROR_FACE_ALREADY_CREATED;
-
- adj_index_t adj;
- int ret = hicn_face_ip_find_adj(remote_addr, sw_if, &adj);
- if (ret != HICN_ERROR_NONE)
- return ret;
-
- vec_add1(*vec, *pfaceid);
-
- hicn_face_ip_t *ip_face = (hicn_face_ip_t *) face->data;
- clib_memcpy (&ip_face->local_addr, local_addr, sizeof (ip6_address_t));
- clib_memcpy (&ip_face->remote_addr, remote_addr,
- sizeof (ip6_address_t));
- face->shared.sw_if = sw_if;
- face->shared.flags = flags;
- face->shared.adj = adj;
-
- dpo_proto = DPO_PROTO_IP6;
-
- mhash_set_mem (&hicn_face_ip_local_hashtb, &key, (uword *) in_faces, 0);
-
- /* If the face is an application producer face, we set it as the preferred incoming face. */
- /* This is required to handle the CS separation, and the push api in a lightway*/
- if (is_app_prod)
- {
- in_faces->face_id = *pfaceid;
- }
- }
+ {
+ hicn_face_ip_vec_t *vec =
+ pool_elt_at_index (hicn_vec_pool, in_faces->vec_id);
+
+ /* */
+ if (vec_search (*vec, *pfaceid) != ~0)
+ return HICN_ERROR_FACE_ALREADY_CREATED;
+
+ adj_index_t adj;
+ int ret = hicn_face_ip_find_adj (remote_addr, sw_if, &adj);
+ if (ret != HICN_ERROR_NONE)
+ return ret;
+
+ vec_add1 (*vec, *pfaceid);
+
+ hicn_face_ip_t *ip_face = (hicn_face_ip_t *) face->data;
+ clib_memcpy (&ip_face->local_addr, local_addr,
+ sizeof (ip6_address_t));
+ clib_memcpy (&ip_face->remote_addr, remote_addr,
+ sizeof (ip6_address_t));
+ face->shared.sw_if = sw_if;
+ face->shared.flags = flags;
+ face->shared.adj = adj;
+
+ dpo_proto = DPO_PROTO_IP6;
+
+ mhash_set_mem (&hicn_face_ip_local_hashtb, &key, (uword *) in_faces,
+ 0);
+
+ /* If the face is an application producer face, we set it as the preferred incoming face. */
+ /* This is required to handle the CS separation, and the push api in a lightway */
+ if (is_app_prod)
+ {
+ in_faces->face_id = *pfaceid;
+ }
+ }
}
retx_t *retx = vlib_process_signal_event_data (vlib_get_main (),
- hicn_mapme_eventmgr_process_node.
- index,
+ hicn_mapme_eventmgr_process_node.index,
HICN_MAPME_EVENT_FACE_ADD, 1,
sizeof (retx_t));
diff --git a/hicn-plugin/src/faces/udp/face_udp.c b/hicn-plugin/src/faces/udp/face_udp.c
index e2fa3227b..e610cbd14 100644
--- a/hicn-plugin/src/faces/udp/face_udp.c
+++ b/hicn-plugin/src/faces/udp/face_udp.c
@@ -80,16 +80,11 @@ hicn_face_udp_init (vlib_main_t * vm)
/* Default Strategy has index 0 and it always exists */
strategy_face_udp4_vlib_edge = vlib_node_add_next (vm,
- hicn_dpo_get_strategy_vft
- (default_dpo.hicn_dpo_get_type
- ())->get_strategy_node_index
- (),
- hicn_face_udp4_output_node.index);
+ hicn_strategy_node.index,
+ hicn_face_udp4_output_node.
+ index);
strategy_face_udp6_vlib_edge =
- vlib_node_add_next (vm,
- hicn_dpo_get_strategy_vft
- (default_dpo.hicn_dpo_get_type
- ())->get_strategy_node_index (),
+ vlib_node_add_next (vm, hicn_strategy_node.index,
hicn_face_udp6_output_node.index);
/*
@@ -99,12 +94,10 @@ hicn_face_udp_init (vlib_main_t * vm)
for (int i = 1; i < strategy_nodes_n; i++)
{
u32 temp_index4 = vlib_node_add_next (vm,
- hicn_dpo_get_strategy_vft_from_id
- (i)->get_strategy_node_index (),
+ hicn_strategy_node.index,
hicn_face_udp4_output_node.index);
u32 temp_index6 = vlib_node_add_next (vm,
- hicn_dpo_get_strategy_vft_from_id
- (i)->get_strategy_node_index (),
+ hicn_strategy_node.index,
hicn_face_udp6_output_node.index);
ASSERT (temp_index4 == strategy_face_udp4_vlib_edge);
ASSERT (temp_index6 == strategy_face_udp6_vlib_edge);
@@ -269,7 +262,8 @@ hicn_face_udp_add (const ip46_address_t * local_addr,
}
retx_t *retx = vlib_process_signal_event_data (vlib_get_main (),
- hicn_mapme_eventmgr_process_node.index,
+ hicn_mapme_eventmgr_process_node.
+ index,
HICN_MAPME_EVENT_FACE_ADD, 1,
sizeof (retx_t));
/* *INDENT-OFF* */
diff --git a/hicn-plugin/src/hashtb.c b/hicn-plugin/src/hashtb.c
index 5d41b7aa9..6deddbd84 100644
--- a/hicn-plugin/src/hashtb.c
+++ b/hicn-plugin/src/hashtb.c
@@ -270,7 +270,7 @@ hicn_hashtb_free (hicn_hashtb_h * ph)
int
hicn_hashtb_lookup_node (hicn_hashtb_h h, const u8 * key,
u32 keylen, u64 hashval, u8 is_data,
- u32 * node_id, u8 * dpo_ctx_id, u8 * vft_id,
+ u32 * node_id, index_t * dpo_ctx_id, u8 * vft_id,
u8 * is_cs, u8 * hash_entry_id, u32 * bucket_id,
u8 * bucket_is_overflow)
{
@@ -295,7 +295,7 @@ int
hicn_hashtb_lookup_node_ex (hicn_hashtb_h h, const u8 * key,
u32 keylen, u64 hashval, u8 is_data,
int include_deleted_p, u32 * node_id,
- u8 * dpo_ctx_id, u8 * vft_id, u8 * is_cs,
+ index_t * dpo_ctx_id, u8 * vft_id, u8 * is_cs,
u8 * hash_entry_id, u32 * bucket_id,
u8 * bucket_is_overflow)
{
@@ -423,7 +423,7 @@ int
hicn_hashtb_insert (hicn_hashtb_h h, hicn_hash_node_t * node,
hicn_hash_entry_t ** hash_entry, u64 hash,
u32 * node_id,
- u8 * dpo_ctx_id, u8 * vft_id, u8 * is_cs,
+ index_t * dpo_ctx_id, u8 * vft_id, u8 * is_cs,
u8 * hash_entry_id, u32 * bucket_id,
u8 * bucket_is_overflow)
{
@@ -485,8 +485,8 @@ loop_buckets:
* If we are doing lookup for a data, do not take a
* lock in case of a hit with a CS entry
*/
- if (!(*is_cs))
- bucket->hb_entries[i].locks++;
+ if (!(*is_cs))
+ bucket->hb_entries[i].locks++;
*bucket_is_overflow = is_overflow;
ret = HICN_ERROR_HASHTB_EXIST;
goto done;
diff --git a/hicn-plugin/src/hashtb.h b/hicn-plugin/src/hashtb.h
index b74e972b2..756f247b7 100644
--- a/hicn-plugin/src/hashtb.h
+++ b/hicn-plugin/src/hashtb.h
@@ -189,6 +189,9 @@ typedef struct __attribute__ ((packed)) hicn_hash_entry_s
*/
u32 locks;
+ /* Index of dpo (4B) */
+ index_t dpo_ctx_id;
+
/* A few flags, including 'this points to a chain of buckets' */
u8 he_flags;
@@ -198,10 +201,10 @@ typedef struct __attribute__ ((packed)) hicn_hash_entry_s
*/
u8 vft_id;
- /* Index of dpo */
- u8 dpo_ctx_id;
+} hicn_hash_entry_t; //size 22B
+
+STATIC_ASSERT (sizeof (index_t) <= 4, "sizeof index_t is greater than 4B");
-} hicn_hash_entry_t;
#define HICN_HASH_ENTRY_FLAGS_DEFAULT 0x00
@@ -231,13 +234,13 @@ typedef struct __attribute__ ((packed)) hicn_hash_entry_s
* Overflow bucket ratio as a fraction of the fixed/configured count; a pool
* of hash buckets used if a row in the fixed table overflows.
*/
-#define HICN_HASHTB_BUCKET_ENTRIES 6
+#define HICN_HASHTB_BUCKET_ENTRIES 5
typedef struct __attribute__ ((packed))
{
hicn_hash_entry_t hb_entries[HICN_HASHTB_BUCKET_ENTRIES];
u64 align1;
- u32 align2;
+ u64 align2;
u16 align3;
} hicn_hash_bucket_t;
@@ -400,7 +403,7 @@ int
hicn_hashtb_insert (hicn_hashtb_h h, hicn_hash_node_t * node,
hicn_hash_entry_t ** hash_entry, u64 hash,
u32 * node_id,
- u8 * dpo_ctx_id, u8 * vft_id, u8 * is_cs,
+ index_t * dpo_ctx_id, u8 * vft_id, u8 * is_cs,
u8 * hash_entry_id, u32 * bucket_id,
u8 * bucket_is_overflow);
@@ -414,7 +417,7 @@ hicn_hashtb_insert (hicn_hashtb_h h, hicn_hash_node_t * node,
int
hicn_hashtb_lookup_node (hicn_hashtb_h h, const u8 * key,
u32 keylen, u64 hashval, u8 is_data,
- u32 * node_id, u8 * dpo_ctx_id, u8 * vft_id,
+ u32 * node_id, index_t * dpo_ctx_id, u8 * vft_id,
u8 * is_cs, u8 * hash_entry_id, u32 * bucket_id,
u8 * bucket_is_overflow);
@@ -432,7 +435,7 @@ int
hicn_hashtb_lookup_node_ex (hicn_hashtb_h h, const u8 * key,
u32 keylen, u64 hashval, u8 is_data,
int include_deleted_p, u32 * node_id,
- u8 * dpo_ctx_id, u8 * vft_id, u8 * is_cs,
+ index_t * dpo_ctx_id, u8 * vft_id, u8 * is_cs,
u8 * hash_entry_id, u32 * bucket_id,
u8 * bucket_is_overflow);
diff --git a/hicn-plugin/src/hicn_api.c b/hicn-plugin/src/hicn_api.c
index 4601ae316..5bdab4408 100644
--- a/hicn-plugin/src/hicn_api.c
+++ b/hicn-plugin/src/hicn_api.c
@@ -314,7 +314,7 @@ vl_api_hicn_api_face_add_t_handler (vl_api_hicn_api_face_add_t * mp)
hicn_main_t *sm = &hicn_main;
hicn_face_id_t face_id;
- vl_api_hicn_face_type_t face_type = clib_net_to_host_u32(mp->type);
+ vl_api_hicn_face_type_t face_type = clib_net_to_host_u32 (mp->type);
switch (face_type)
{
@@ -436,12 +436,12 @@ send_faces_details (vl_api_registration_t * reg,
if (face->shared.face_type == hicn_face_ip_type)
{
- mp->type = clib_host_to_net_u32(IP_FACE);
+ mp->type = clib_host_to_net_u32 (IP_FACE);
send_face_ip_details (face, &(mp->face.ip));
}
else if (face->shared.face_type == hicn_face_udp_type)
{
- mp->type = clib_host_to_net_u32(UDP_FACE);
+ mp->type = clib_host_to_net_u32 (UDP_FACE);
send_face_udp_details (face, &(mp->face.udp));
}
@@ -651,7 +651,6 @@ static void vl_api_hicn_api_route_get_t_handler
fib_prefix_t prefix;
ip_prefix_decode (&mp->prefix, &prefix);
const dpo_id_t *hicn_dpo_id;
- const hicn_dpo_vft_t *hicn_dpo_vft;
hicn_dpo_ctx_t *hicn_dpo_ctx;
u32 fib_index;
@@ -662,8 +661,7 @@ static void vl_api_hicn_api_route_get_t_handler
{
if (rv == HICN_ERROR_NONE)
{
- hicn_dpo_vft = hicn_dpo_get_vft(hicn_dpo_id->dpoi_type);
- hicn_dpo_ctx = hicn_dpo_vft->hicn_dpo_get_ctx(hicn_dpo_id->dpoi_index);
+ hicn_dpo_ctx = hicn_strategy_dpo_ctx_get(hicn_dpo_id->dpoi_index);
for (int i = 0; hicn_dpo_ctx != NULL && i < hicn_dpo_ctx->entry_count; i++)
{
if (dpo_id_is_valid(&hicn_dpo_ctx->next_hops[i]))
@@ -687,11 +685,10 @@ send_route_details (vl_api_registration_t * reg,
mp->_vl_msg_id = htons (VL_API_HICN_API_ROUTES_DETAILS + hm->msg_id_base);
mp->context = context;
- ip_prefix_encode(pfx, &mp->prefix);
+ ip_prefix_encode (pfx, &mp->prefix);
mp->nfaces = 0;
const dpo_id_t *hicn_dpo_id;
- const hicn_dpo_vft_t *hicn_dpo_vft;
hicn_dpo_ctx_t *hicn_dpo_ctx;
u32 fib_index;
@@ -699,16 +696,16 @@ send_route_details (vl_api_registration_t * reg,
if (rv == HICN_ERROR_NONE)
{
- hicn_dpo_vft = hicn_dpo_get_vft (hicn_dpo_id->dpoi_type);
- hicn_dpo_ctx = hicn_dpo_vft->hicn_dpo_get_ctx (hicn_dpo_id->dpoi_index);
- for (int i = 0; hicn_dpo_ctx != NULL && i < hicn_dpo_ctx->entry_count; i++)
+ hicn_dpo_ctx = hicn_strategy_dpo_ctx_get (hicn_dpo_id->dpoi_index);
+ for (int i = 0; hicn_dpo_ctx != NULL && i < hicn_dpo_ctx->entry_count;
+ i++)
{
if (dpo_id_is_valid (&hicn_dpo_ctx->next_hops[i]))
{
mp->faceids[i] =
clib_host_to_net_u32 (((dpo_id_t *) &
- hicn_dpo_ctx->
- next_hops[i])->dpoi_index);
+ hicn_dpo_ctx->next_hops[i])->
+ dpoi_index);
mp->nfaces++;
}
}
@@ -757,8 +754,7 @@ vl_api_hicn_api_route_dump_walk (fib_node_index_t fei, void *arg)
}
static void
- vl_api_hicn_api_routes_dump_t_handler
- (vl_api_hicn_api_routes_dump_t * mp)
+ vl_api_hicn_api_routes_dump_t_handler (vl_api_hicn_api_routes_dump_t * mp)
{
vl_api_registration_t *reg;
fib_table_t *fib_table;
@@ -779,7 +775,8 @@ static void
fib_table_walk (fib_table->ft_index,
FIB_PROTOCOL_IP4,
vl_api_hicn_api_route_dump_walk,
- &ctx);}
+ &ctx);
+ }
));
pool_foreach (fib_table, im6->fibs, (
@@ -787,7 +784,8 @@ static void
fib_table_walk (fib_table->ft_index,
FIB_PROTOCOL_IP6,
vl_api_hicn_api_route_dump_walk,
- &ctx);}
+ &ctx);
+ }
));
vec_foreach (lfeip, ctx.feis)
@@ -841,9 +839,9 @@ static void vl_api_hicn_api_strategy_get_t_handler
{
if (rv == HICN_ERROR_NONE)
{
- const hicn_dpo_vft_t * hicn_dpo_vft =
- hicn_dpo_get_vft (strategy_id);
- hicn_dpo_vft->format_hicn_dpo (rmp->description, 0);}
+ const hicn_strategy_vft_t * hicn_strategy_vft =
+ hicn_dpo_get_strategy_vft (strategy_id);
+ hicn_strategy_vft->hicn_format_strategy (rmp->description, 0);}
}));
/* *INDENT-ON* */
}
diff --git a/hicn-plugin/src/interest_hitcs.h b/hicn-plugin/src/interest_hitcs.h
index 3588d4e08..c69564452 100644
--- a/hicn-plugin/src/interest_hitcs.h
+++ b/hicn-plugin/src/interest_hitcs.h
@@ -40,10 +40,10 @@ typedef struct
typedef enum
{
- HICN_INTEREST_HITCS_NEXT_V4_LOOKUP,
- HICN_INTEREST_HITCS_NEXT_V6_LOOKUP,
+ HICN_INTEREST_HITCS_NEXT_STRATEGY,
HICN_INTEREST_HITCS_NEXT_PUSH,
HICN_INTEREST_HITCS_NEXT_ERROR_DROP,
+ HICN_INTEREST_HITCS_NEXT_EMPTY,
HICN_INTEREST_HITCS_N_NEXT,
} hicn_interest_hitcs_next_t;
diff --git a/hicn-plugin/src/interest_hitcs_node.c b/hicn-plugin/src/interest_hitcs_node.c
index 14f512897..d10f15afa 100644
--- a/hicn-plugin/src/interest_hitcs_node.c
+++ b/hicn-plugin/src/interest_hitcs_node.c
@@ -172,9 +172,7 @@ hicn_interest_hitcs_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
dpo_vft0, &hicn_dpo_id0);
stats.cs_expired_count++;
/* Forward interest to the strategy node */
- next0 =
- isv6 ? HICN_INTEREST_HITCS_NEXT_V6_LOOKUP :
- HICN_INTEREST_HITCS_NEXT_V4_LOOKUP;
+ next0 = HICN_INTEREST_HITCS_NEXT_STRATEGY;
}
else
{
@@ -278,10 +276,10 @@ VLIB_REGISTER_NODE(hicn_interest_hitcs_node) =
/* edit / add dispositions here */
.next_nodes =
{
- [HICN_INTEREST_HITCS_NEXT_V4_LOOKUP] = "ip4-lookup",
- [HICN_INTEREST_HITCS_NEXT_V6_LOOKUP] = "ip6-lookup",
+ [HICN_INTEREST_HITCS_NEXT_STRATEGY] = "hicn-strategy",
[HICN_INTEREST_HITCS_NEXT_PUSH] = "hicn-data-push",
[HICN_INTEREST_HITCS_NEXT_ERROR_DROP] = "error-drop",
+ [HICN_INTEREST_HITCS_NEXT_EMPTY] = "ip6-lookup"
},
};
/* *INDENT-ON* */
diff --git a/hicn-plugin/src/interest_hitpit.h b/hicn-plugin/src/interest_hitpit.h
index 28427d342..fc4cfc3ea 100644
--- a/hicn-plugin/src/interest_hitpit.h
+++ b/hicn-plugin/src/interest_hitpit.h
@@ -41,8 +41,7 @@ typedef struct
typedef enum
{
HICN_INTEREST_HITPIT_NEXT_INTEREST_HITCS,
- HICN_INTEREST_HITPIT_NEXT_IP4_LOOKUP,
- HICN_INTEREST_HITPIT_NEXT_IP6_LOOKUP,
+ HICN_INTEREST_HITPIT_NEXT_STRATEGY,
HICN_INTEREST_HITPIT_NEXT_ERROR_DROP,
HICN_INTEREST_HITPIT_N_NEXT,
} hicn_interest_hitpit_next_t;
diff --git a/hicn-plugin/src/interest_hitpit_node.c b/hicn-plugin/src/interest_hitpit_node.c
index d5eeb20dd..a346dcc7e 100644
--- a/hicn-plugin/src/interest_hitpit_node.c
+++ b/hicn-plugin/src/interest_hitpit_node.c
@@ -150,9 +150,7 @@ hicn_interest_hitpit_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
hicn_pcs_delete (rt->pitcs, &pitp, &node0, vm, hash_entry0,
dpo_vft0, &hicn_dpo_id0);
stats.pit_expired_count++;
- next0 =
- isv6 ? HICN_INTEREST_HITPIT_NEXT_IP6_LOOKUP :
- HICN_INTEREST_HITPIT_NEXT_IP4_LOOKUP;
+ next0 = HICN_INTEREST_HITPIT_NEXT_STRATEGY;
}
else
{
@@ -294,8 +292,7 @@ VLIB_REGISTER_NODE(hicn_interest_hitpit_node) =
.next_nodes =
{
[HICN_INTEREST_HITPIT_NEXT_INTEREST_HITCS] = "hicn-interest-hitcs",
- [HICN_INTEREST_HITPIT_NEXT_IP4_LOOKUP] = "ip4-lookup",
- [HICN_INTEREST_HITPIT_NEXT_IP6_LOOKUP] = "ip6-lookup",
+ [HICN_INTEREST_HITPIT_NEXT_STRATEGY] = "hicn-strategy",
[HICN_INTEREST_HITPIT_NEXT_ERROR_DROP] = "error-drop",
},
};
diff --git a/hicn-plugin/src/interest_pcslookup.h b/hicn-plugin/src/interest_pcslookup.h
index e27673a9e..5a5a6a7a8 100644
--- a/hicn-plugin/src/interest_pcslookup.h
+++ b/hicn-plugin/src/interest_pcslookup.h
@@ -40,8 +40,7 @@ typedef struct
typedef enum
{
- HICN_INTEREST_PCSLOOKUP_NEXT_V4_LOOKUP,
- HICN_INTEREST_PCSLOOKUP_NEXT_V6_LOOKUP,
+ HICN_INTEREST_PCSLOOKUP_NEXT_STRATEGY,
HICN_INTEREST_PCSLOOKUP_NEXT_INTEREST_HITPIT,
HICN_INTEREST_PCSLOOKUP_NEXT_INTEREST_HITCS,
HICN_INTEREST_PCSLOOKUP_NEXT_ERROR_DROP,
diff --git a/hicn-plugin/src/interest_pcslookup_node.c b/hicn-plugin/src/interest_pcslookup_node.c
index 40d62510b..6ac2aa3a0 100644
--- a/hicn-plugin/src/interest_pcslookup_node.c
+++ b/hicn-plugin/src/interest_pcslookup_node.c
@@ -85,7 +85,7 @@ hicn_interest_pcslookup_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
hicn_name_t name;
hicn_header_t *hicn0;
u32 node_id0 = 0;
- u8 dpo_ctx_id0 = 0;
+ index_t dpo_ctx_id0 = 0;
u8 vft_id0 = 0;
u8 is_cs0 = 0;
u8 hash_entry_id = 0;
@@ -113,9 +113,7 @@ hicn_interest_pcslookup_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
if (PREDICT_TRUE (ret == HICN_ERROR_NONE))
{
- next0 =
- isv6 ? HICN_INTEREST_PCSLOOKUP_NEXT_V6_LOOKUP :
- HICN_INTEREST_PCSLOOKUP_NEXT_V4_LOOKUP;
+ next0 = HICN_INTEREST_PCSLOOKUP_NEXT_STRATEGY;
}
nameptr = (u8 *) (&name);
stats.pkts_processed++;
@@ -224,8 +222,7 @@ VLIB_REGISTER_NODE(hicn_interest_pcslookup_node) =
.n_next_nodes = HICN_INTEREST_PCSLOOKUP_N_NEXT,
.next_nodes =
{
- [HICN_INTEREST_PCSLOOKUP_NEXT_V4_LOOKUP] = "ip4-lookup",
- [HICN_INTEREST_PCSLOOKUP_NEXT_V6_LOOKUP] = "ip6-lookup",
+ [HICN_INTEREST_PCSLOOKUP_NEXT_STRATEGY] = "hicn-strategy",
[HICN_INTEREST_PCSLOOKUP_NEXT_INTEREST_HITPIT] = "hicn-interest-hitpit",
[HICN_INTEREST_PCSLOOKUP_NEXT_INTEREST_HITCS] = "hicn-interest-hitcs",
[HICN_INTEREST_PCSLOOKUP_NEXT_ERROR_DROP] = "error-drop",
diff --git a/hicn-plugin/src/mapme_ack_node.c b/hicn-plugin/src/mapme_ack_node.c
index ebb12a124..557fb0ad7 100644
--- a/hicn-plugin/src/mapme_ack_node.c
+++ b/hicn-plugin/src/mapme_ack_node.c
@@ -79,9 +79,8 @@ hicn_mapme_process_ack (vlib_main_t * vm, vlib_buffer_t * b,
/* We are only expecting ACKs for hICN DPOs */
ASSERT (dpo_is_hicn (dpo));
- const hicn_dpo_vft_t *dpo_vft = hicn_dpo_get_vft (dpo->dpoi_type);
hicn_mapme_tfib_t *tfib =
- TFIB (dpo_vft->hicn_dpo_get_ctx (dpo->dpoi_index));
+ TFIB (hicn_strategy_dpo_ctx_get (dpo->dpoi_index));
if (tfib == NULL)
{
@@ -107,11 +106,12 @@ hicn_mapme_process_ack (vlib_main_t * vm, vlib_buffer_t * b,
* Is the ingress face in TFIB ? if so, remove it, otherwise it might be a
* duplicate
*/
- retx_t *retx =
- vlib_process_signal_event_data (vm,
- hicn_mapme_eventmgr_process_node.index,
- HICN_MAPME_EVENT_FACE_PH_DEL, 1,
- sizeof (retx_t));
+ retx_t *retx = vlib_process_signal_event_data (vm,
+ hicn_mapme_eventmgr_process_node.
+ index,
+ HICN_MAPME_EVENT_FACE_PH_DEL,
+ 1,
+ sizeof (retx_t));
*retx = (retx_t)
{
.prefix = prefix,.dpo = *dpo};
diff --git a/hicn-plugin/src/mapme_ctrl_node.c b/hicn-plugin/src/mapme_ctrl_node.c
index cef3d0944..ed25a31b0 100644
--- a/hicn-plugin/src/mapme_ctrl_node.c
+++ b/hicn-plugin/src/mapme_ctrl_node.c
@@ -27,6 +27,7 @@
#include "parser.h"
#include "infra.h"
#include "strategy_dpo_manager.h"
+#include "strategy_dpo_ctx.h"
#include "error.h"
#include "state.h"
@@ -93,7 +94,7 @@ hicn_mapme_process_ctrl (vlib_main_t * vm, vlib_buffer_t * b,
/* if (params.seq == INVALID_SEQ) */
/* { */
/* vlib_log_warn (mapme_main.log_class, */
- /* "Invalid sequence number found in IU"); */
+ /* "Invalid sequence number found in IU"); */
/* return true; */
/* } */
@@ -129,9 +130,8 @@ hicn_mapme_process_ctrl (vlib_main_t * vm, vlib_buffer_t * b,
#endif
/* Process the hICN DPO */
- const hicn_dpo_vft_t *dpo_vft = hicn_dpo_get_vft (dpo->dpoi_type);
hicn_mapme_tfib_t *tfib =
- TFIB (dpo_vft->hicn_dpo_get_ctx (dpo->dpoi_index));
+ TFIB (hicn_strategy_dpo_ctx_get (dpo->dpoi_index));
if (tfib == NULL)
{
@@ -163,7 +163,9 @@ hicn_mapme_process_ctrl (vlib_main_t * vm, vlib_buffer_t * b,
tfib->entry_count = 0;
break;
}
- DEBUG ("Adding nexthop to the tfib, dpo index in_face %d, dpo index tfib %d", in_face->dpoi_index, tfib->next_hops[pos].dpoi_index);
+ DEBUG
+ ("Adding nexthop to the tfib, dpo index in_face %d, dpo index tfib %d",
+ in_face->dpoi_index, tfib->next_hops[pos].dpoi_index);
hicn_mapme_tfib_add (tfib, &tfib->next_hops[pos]);
}
@@ -173,7 +175,8 @@ hicn_mapme_process_ctrl (vlib_main_t * vm, vlib_buffer_t * b,
/* We transmit both the prefix and the full dpo (type will be needed to pick the right transmit node */
retx_t *retx = vlib_process_signal_event_data (vm,
- hicn_mapme_eventmgr_process_node.index,
+ hicn_mapme_eventmgr_process_node.
+ index,
HICN_MAPME_EVENT_FACE_NH_SET,
1,
sizeof (retx_t));
@@ -195,7 +198,8 @@ hicn_mapme_process_ctrl (vlib_main_t * vm, vlib_buffer_t * b,
/* Multipath, multihoming, multiple producers or duplicate interest */
retx_t *retx = vlib_process_signal_event_data (vm,
- hicn_mapme_eventmgr_process_node.index,
+ hicn_mapme_eventmgr_process_node.
+ index,
HICN_MAPME_EVENT_FACE_NH_ADD,
1,
sizeof (retx_t));
@@ -212,7 +216,8 @@ hicn_mapme_process_ctrl (vlib_main_t * vm, vlib_buffer_t * b,
hicn_mapme_tfib_add (tfib, in_face);
retx_t *retx = vlib_process_signal_event_data (vm,
- hicn_mapme_eventmgr_process_node.index,
+ hicn_mapme_eventmgr_process_node.
+ index,
HICN_MAPME_EVENT_FACE_PH_ADD,
1,
sizeof (retx_t));
@@ -277,7 +282,7 @@ hicn_mapme_ctrl_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
preprocess_in_face (hb->type, &hb->face_dpo_id, &in_face);
hicn_mapme_process_ctrl (vm, b0, &in_face);
- vnet_buffer (b0)->ip.adj_index[VLIB_TX] = in_face.dpoi_index;
+ vnet_buffer (b0)->ip.adj_index[VLIB_TX] = in_face.dpoi_index;
vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
n_left_to_next, bi0, next0);
diff --git a/hicn-plugin/src/mapme_eventmgr.c b/hicn-plugin/src/mapme_eventmgr.c
index ef73f9550..5a9e7967e 100644
--- a/hicn-plugin/src/mapme_eventmgr.c
+++ b/hicn-plugin/src/mapme_eventmgr.c
@@ -261,12 +261,11 @@ hicn_mapme_send_message (vlib_main_t * vm, const hicn_prefix_t * prefix,
vlib_node_t *node = vlib_get_node_by_name (vm, (u8 *) node_name);
u32 node_index = node->index;
- u8 *buffer =
- get_packet_buffer (vm, node_index, face->dpoi_index,
- (ip46_address_t *) prefix,
- (params->protocol ==
- IPPROTO_IPV6) ? HICN_TYPE_IPV6_ICMP :
- HICN_TYPE_IPV4_ICMP);
+ u8 *buffer = get_packet_buffer (vm, node_index, face->dpoi_index,
+ (ip46_address_t *) prefix,
+ (params->protocol ==
+ IPPROTO_IPV6) ? HICN_TYPE_IPV6_ICMP :
+ HICN_TYPE_IPV4_ICMP);
n = hicn_mapme_create_packet (buffer, prefix, params);
if (n <= 0)
{
@@ -281,8 +280,7 @@ static_always_inline void
hicn_mapme_send_updates (vlib_main_t * vm, hicn_prefix_t * prefix,
dpo_id_t dpo, bool send_all)
{
- const hicn_dpo_vft_t *dpo_vft = hicn_dpo_get_vft (dpo.dpoi_type);
- hicn_mapme_tfib_t *tfib = TFIB (dpo_vft->hicn_dpo_get_ctx (dpo.dpoi_index));
+ hicn_mapme_tfib_t *tfib = TFIB (hicn_strategy_dpo_ctx_get (dpo.dpoi_index));
if (!tfib)
{
DEBUG ("NULL TFIB entry id=%d", dpo.dpoi_index);
@@ -323,7 +321,7 @@ hicn_mapme_eventmgr_process (vlib_main_t * vm,
u8 idle = 0;
retx_t retx_array[NUM_RETX_SLOT][NUM_RETX_ENTRIES];
- memset(retx_array, 0, NUM_RETX_SLOT*NUM_RETX_ENTRIES);
+ memset (retx_array, 0, NUM_RETX_SLOT * NUM_RETX_ENTRIES);
u8 retx_len[NUM_RETX_SLOT] = { 0 };
u8 cur = 0; /* current slot */
@@ -500,10 +498,8 @@ hicn_mapme_eventmgr_process (vlib_main_t * vm,
if (retx->dpo.dpoi_index == ~0) /* deleted entry */
continue;
- const hicn_dpo_vft_t *dpo_vft =
- hicn_dpo_get_vft (retx->dpo.dpoi_type);
hicn_mapme_tfib_t *tfib =
- TFIB (dpo_vft->hicn_dpo_get_ctx (retx->dpo.dpoi_index));
+ TFIB (hicn_strategy_dpo_ctx_get (retx->dpo.dpoi_index));
if (!tfib)
{
DEBUG ("NULL TFIB entry for dpoi_index=%d",
@@ -517,16 +513,16 @@ hicn_mapme_eventmgr_process (vlib_main_t * vm,
// If we exceed the numver of retransmittion it means that all tfib entries have seens at least HICN_PARAM_RTX_MAX of retransmission
if (retx->rtx_count < HICN_PARAM_RTX_MAX)
{
- /*
- * We did some retransmissions, so let's reschedule a check in the
- * next slot
- */
+ /*
+ * We did some retransmissions, so let's reschedule a check in the
+ * next slot
+ */
NXT[NXTLEN++] = CUR[pos];
idle = 0;
}
else
{
- hicn_mapme_tfib_clear(tfib);
+ hicn_mapme_tfib_clear (tfib);
}
}
diff --git a/hicn-plugin/src/pcs.h b/hicn-plugin/src/pcs.h
index d9c48954e..fc63bd0a6 100644
--- a/hicn-plugin/src/pcs.h
+++ b/hicn-plugin/src/pcs.h
@@ -174,7 +174,8 @@ hicn_pit_to_cs (vlib_main_t * vm, hicn_pit_cs_t * pitcs,
always_inline void
hicn_pcs_cs_update (vlib_main_t * vm, hicn_pit_cs_t * pitcs,
- hicn_pcs_entry_t * old_entry, hicn_pcs_entry_t * entry, hicn_hash_node_t * node);
+ hicn_pcs_entry_t * old_entry, hicn_pcs_entry_t * entry,
+ hicn_hash_node_t * node);
always_inline void
hicn_pcs_cs_delete (vlib_main_t * vm, hicn_pit_cs_t * pitcs,
@@ -186,24 +187,24 @@ always_inline int
hicn_pcs_cs_insert (vlib_main_t * vm, hicn_pit_cs_t * pitcs,
hicn_pcs_entry_t * entry, hicn_hash_node_t * node,
hicn_hash_entry_t ** hash_entry, u64 hashval,
- u32 * node_id, u8 * dpo_ctx_id, u8 * vft_id, u8 * is_cs,
- u8 * hash_entry_id, u32 * bucket_id,
+ u32 * node_id, index_t * dpo_ctx_id, u8 * vft_id,
+ u8 * is_cs, u8 * hash_entry_id, u32 * bucket_id,
u8 * bucket_is_overflow);
always_inline int
hicn_pcs_cs_insert_update (vlib_main_t * vm, hicn_pit_cs_t * pitcs,
hicn_pcs_entry_t * entry, hicn_hash_node_t * node,
hicn_hash_entry_t ** hash_entry, u64 hashval,
- u32 * node_id, u8 * dpo_ctx_id, u8 * vft_id,
+ u32 * node_id, index_t * dpo_ctx_id, u8 * vft_id,
u8 * is_cs, u8 * hash_entry_id, u32 * bucket_id,
u8 * bucket_is_overflow, dpo_id_t * inface);
always_inline int
hicn_pcs_pit_insert (hicn_pit_cs_t * pitcs, hicn_pcs_entry_t * entry,
hicn_hash_node_t * node, hicn_hash_entry_t ** hash_entry,
- u64 hashval, u32 * node_id, u8 * dpo_ctx_id, u8 * vft_id,
- u8 * is_cs, u8 * hash_entry_id, u32 * bucket_id,
- u8 * bucket_is_overflow);
+ u64 hashval, u32 * node_id, index_t * dpo_ctx_id,
+ u8 * vft_id, u8 * is_cs, u8 * hash_entry_id,
+ u32 * bucket_id, u8 * bucket_is_overflow);
always_inline void
hicn_pcs_pit_delete (hicn_pit_cs_t * pitcs, hicn_pcs_entry_t ** pcs_entryp,
@@ -215,8 +216,9 @@ always_inline int
hicn_pcs_insert (vlib_main_t * vm, hicn_pit_cs_t * pitcs,
hicn_pcs_entry_t * entry, hicn_hash_node_t * node,
hicn_hash_entry_t ** hash_entry, u64 hashval, u32 * node_id,
- u8 * dpo_ctx_id, u8 * vft_id, u8 * is_cs, u8 * hash_entry_id,
- u32 * bucket_id, u8 * bucket_is_overflow);
+ index_t * dpo_ctx_id, u8 * vft_id, u8 * is_cs,
+ u8 * hash_entry_id, u32 * bucket_id,
+ u8 * bucket_is_overflow);
always_inline void
hicn_pcs_delete (hicn_pit_cs_t * pitcs, hicn_pcs_entry_t ** pcs_entryp,
@@ -365,7 +367,7 @@ hicn_pcs_delete_internal (hicn_pit_cs_t * pitcs,
else
{
pitcs->pcs_pit_dealloc++;
- dpo_vft->hicn_dpo_unlock_dpo_ctx (hicn_dpo_id);
+ hicn_strategy_dpo_ctx_unlock (hicn_dpo_id);
/* Flush faces */
hicn_faces_flush (&(pcs->u.pit.faces));
@@ -391,7 +393,7 @@ hicn_pit_to_cs (vlib_main_t * vm, hicn_pit_cs_t * pitcs,
* hash entry.
*/
pitcs->pcs_pit_count--;
- dpo_vft->hicn_dpo_unlock_dpo_ctx (hicn_dpo_id);
+ hicn_strategy_dpo_ctx_unlock (hicn_dpo_id);
/* Flush faces */
hicn_faces_flush (&(pcs_entry->u.pit.faces));
@@ -448,7 +450,8 @@ hicn_pit_to_cs (vlib_main_t * vm, hicn_pit_cs_t * pitcs,
always_inline void
hicn_pcs_cs_update (vlib_main_t * vm, hicn_pit_cs_t * pitcs,
- hicn_pcs_entry_t * old_entry, hicn_pcs_entry_t * entry, hicn_hash_node_t * node)
+ hicn_pcs_entry_t * old_entry, hicn_pcs_entry_t * entry,
+ hicn_hash_node_t * node)
{
hicn_cs_policy_t *policy_state;
hicn_cs_policy_vft_t *policy_vft;
@@ -468,48 +471,48 @@ hicn_pcs_cs_update (vlib_main_t * vm, hicn_pit_cs_t * pitcs,
}
}
- if (dpo_cmp(&entry->u.cs.cs_rxface, &old_entry->u.cs.cs_rxface) !=0)
+ if (dpo_cmp (&entry->u.cs.cs_rxface, &old_entry->u.cs.cs_rxface) != 0)
{
/* Dequeue content from the old queue */
- policy_vft->hicn_cs_dequeue(pitcs, node, old_entry, policy_state);
+ policy_vft->hicn_cs_dequeue (pitcs, node, old_entry, policy_state);
- dpo_copy(&old_entry->u.cs.cs_rxface, &entry->u.cs.cs_rxface);
+ dpo_copy (&old_entry->u.cs.cs_rxface, &entry->u.cs.cs_rxface);
face_dpo = (dpo_id_t *) & (old_entry->u.cs.cs_rxface);
policy_state = &pitcs->policy_state;
policy_vft = &pitcs->policy_vft;
if (face_dpo->dpoi_type == hicn_face_ip_type)
- {
- hicn_face_t *face = hicn_dpoi_get_from_idx (face_dpo->dpoi_index);
- if (face->shared.flags & HICN_FACE_FLAGS_APPFACE_PROD)
- {
- hicn_face_prod_t *prod_face = (hicn_face_prod_t *) face->data;
- policy_state = &prod_face->policy;
- policy_vft = &prod_face->policy_vft;
- }
- }
+ {
+ hicn_face_t *face = hicn_dpoi_get_from_idx (face_dpo->dpoi_index);
+ if (face->shared.flags & HICN_FACE_FLAGS_APPFACE_PROD)
+ {
+ hicn_face_prod_t *prod_face = (hicn_face_prod_t *) face->data;
+ policy_state = &prod_face->policy;
+ policy_vft = &prod_face->policy_vft;
+ }
+ }
policy_vft->hicn_cs_insert (pitcs, node, old_entry, policy_state);
if (policy_state->count > policy_state->max)
- {
- hicn_hash_node_t *node;
- hicn_pcs_entry_t *pcs_entry;
- hicn_hash_entry_t *hash_entry;
- policy_vft->hicn_cs_delete_get (pitcs, policy_state,
- &node, &pcs_entry, &hash_entry);
-
- /*
- * We don't have to decrease the lock (therefore we cannot
- * use hicn_pcs_cs_delete function)
- */
- policy_vft->hicn_cs_dequeue (pitcs, node, pcs_entry, policy_state);
-
- hicn_cs_delete_trimmed (pitcs, &pcs_entry, hash_entry, &node, vm);
-
- /* Update the global CS counter */
- pitcs->pcs_cs_count--;
- }
+ {
+ hicn_hash_node_t *node;
+ hicn_pcs_entry_t *pcs_entry;
+ hicn_hash_entry_t *hash_entry;
+ policy_vft->hicn_cs_delete_get (pitcs, policy_state,
+ &node, &pcs_entry, &hash_entry);
+
+ /*
+ * We don't have to decrease the lock (therefore we cannot
+ * use hicn_pcs_cs_delete function)
+ */
+ policy_vft->hicn_cs_dequeue (pitcs, node, pcs_entry, policy_state);
+
+ hicn_cs_delete_trimmed (pitcs, &pcs_entry, hash_entry, &node, vm);
+
+ /* Update the global CS counter */
+ pitcs->pcs_cs_count--;
+ }
}
else
/* Update the CS LRU, moving this item to the head */
@@ -565,8 +568,8 @@ always_inline int
hicn_pcs_cs_insert (vlib_main_t * vm, hicn_pit_cs_t * pitcs,
hicn_pcs_entry_t * entry, hicn_hash_node_t * node,
hicn_hash_entry_t ** hash_entry, u64 hashval,
- u32 * node_id, u8 * dpo_ctx_id, u8 * vft_id, u8 * is_cs,
- u8 * hash_entry_id, u32 * bucket_id,
+ u32 * node_id, index_t * dpo_ctx_id, u8 * vft_id,
+ u8 * is_cs, u8 * hash_entry_id, u32 * bucket_id,
u8 * bucket_is_overflow)
{
ASSERT (entry == hicn_hashtb_node_data (node));
@@ -611,16 +614,16 @@ hicn_pcs_cs_insert (vlib_main_t * vm, hicn_pit_cs_t * pitcs,
policy_vft->hicn_cs_delete_get (pitcs, policy_state,
&node, &pcs_entry, &hash_entry);
- /*
- * We don't have to decrease the lock (therefore we cannot
- * use hicn_pcs_cs_delete function)
- */
- policy_vft->hicn_cs_dequeue (pitcs, node, pcs_entry, policy_state);
+ /*
+ * We don't have to decrease the lock (therefore we cannot
+ * use hicn_pcs_cs_delete function)
+ */
+ policy_vft->hicn_cs_dequeue (pitcs, node, pcs_entry, policy_state);
- hicn_cs_delete_trimmed (pitcs, &pcs_entry, hash_entry, &node, vm);
+ hicn_cs_delete_trimmed (pitcs, &pcs_entry, hash_entry, &node, vm);
- /* Update the global CS counter */
- pitcs->pcs_cs_count--;
+ /* Update the global CS counter */
+ pitcs->pcs_cs_count--;
}
}
return ret;
@@ -634,7 +637,7 @@ always_inline int
hicn_pcs_cs_insert_update (vlib_main_t * vm, hicn_pit_cs_t * pitcs,
hicn_pcs_entry_t * entry, hicn_hash_node_t * node,
hicn_hash_entry_t ** hash_entry, u64 hashval,
- u32 * node_id, u8 * dpo_ctx_id, u8 * vft_id,
+ u32 * node_id, index_t * dpo_ctx_id, u8 * vft_id,
u8 * is_cs, u8 * hash_entry_id, u32 * bucket_id,
u8 * bucket_is_overflow, dpo_id_t * inface)
{
@@ -677,9 +680,9 @@ hicn_pcs_cs_insert_update (vlib_main_t * vm, hicn_pit_cs_t * pitcs,
always_inline int
hicn_pcs_pit_insert (hicn_pit_cs_t * pitcs, hicn_pcs_entry_t * entry,
hicn_hash_node_t * node, hicn_hash_entry_t ** hash_entry,
- u64 hashval, u32 * node_id, u8 * dpo_ctx_id, u8 * vft_id,
- u8 * is_cs, u8 * hash_entry_id, u32 * bucket_id,
- u8 * bucket_is_overflow)
+ u64 hashval, u32 * node_id, index_t * dpo_ctx_id,
+ u8 * vft_id, u8 * is_cs, u8 * hash_entry_id,
+ u32 * bucket_id, u8 * bucket_is_overflow)
{
ASSERT (entry == hicn_hashtb_node_data (node));
@@ -724,8 +727,8 @@ always_inline int
hicn_pcs_insert (vlib_main_t * vm, hicn_pit_cs_t * pitcs,
hicn_pcs_entry_t * entry, hicn_hash_node_t * node,
hicn_hash_entry_t ** hash_entry, u64 hashval, u32 * node_id,
- u8 * dpo_ctx_id, u8 * vft_id, u8 * is_cs, u8 * hash_entry_id,
- u32 * bucket_id, u8 * bucket_is_overflow)
+ index_t * dpo_ctx_id, u8 * vft_id, u8 * is_cs,
+ u8 * hash_entry_id, u32 * bucket_id, u8 * bucket_is_overflow)
{
int ret;
diff --git a/hicn-plugin/src/route.c b/hicn-plugin/src/route.c
index 85ad9f729..67dedaa88 100644
--- a/hicn-plugin/src/route.c
+++ b/hicn-plugin/src/route.c
@@ -197,14 +197,9 @@ hicn_route_add (hicn_face_id_t * face_id, u32 len,
clib_memcpy (&nhops[i], &face_dpo_tmp[i], sizeof (dpo_id_t));
}
- ret =
- default_dpo.hicn_dpo_create (prefix->fp_proto, nhops, n_face_dpo,
- &dpo_idx);
+ default_dpo.hicn_dpo_create (prefix->fp_proto, nhops, n_face_dpo,
+ &dpo_idx);
- if (ret)
- {
- return ret;
- }
/* the value we got when we registered */
/*
* This should be taken from the name?!? the index of the
@@ -291,11 +286,10 @@ hicn_route_del_nhop (fib_prefix_t * prefix, hicn_face_id_t face_id)
{
vft_id = hicn_dpo_get_vft_id (hicn_dpo_id);
dpo_vft = hicn_dpo_get_vft (vft_id);
- ret = dpo_vft->hicn_dpo_del_nh (face_id, hicn_dpo_id->dpoi_index,
- prefix);
+ ret = dpo_vft->hicn_dpo_del_nh (face_id, hicn_dpo_id->dpoi_index);
hicn_dpo_ctx_t *dpo_ctx =
- dpo_vft->hicn_dpo_get_ctx (hicn_dpo_id->dpoi_index);
+ hicn_strategy_dpo_ctx_get (hicn_dpo_id->dpoi_index);
if (ret == HICN_ERROR_NONE && !dpo_ctx->entry_count)
ret = hicn_route_del (prefix);
@@ -311,21 +305,15 @@ hicn_route_set_strategy (fib_prefix_t * prefix, u8 strategy_id)
dpo_id_t new_dpo_id = DPO_INVALID;
int ret;
hicn_dpo_ctx_t *old_hicn_dpo_ctx;
- const hicn_dpo_vft_t *old_dpo_vft;
const hicn_dpo_vft_t *new_dpo_vft;
index_t new_hicn_dpo_idx;
u32 fib_index;
- u32 old_vft_id;
-
ret = hicn_route_get_dpo (prefix, &hicn_dpo_id, &fib_index);
if (ret == HICN_ERROR_NONE)
{
- old_vft_id = hicn_dpo_get_vft_id (hicn_dpo_id);
- old_dpo_vft = hicn_dpo_get_vft (old_vft_id);
- old_hicn_dpo_ctx =
- old_dpo_vft->hicn_dpo_get_ctx (hicn_dpo_id->dpoi_index);
+ old_hicn_dpo_ctx = hicn_strategy_dpo_ctx_get (hicn_dpo_id->dpoi_index);
new_dpo_vft = hicn_dpo_get_vft_from_id (strategy_id);
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__
diff --git a/hicn-plugin/src/strategy.h b/hicn-plugin/src/strategy.h
index 19eee72c5..c18ae4eea 100644
--- a/hicn-plugin/src/strategy.h
+++ b/hicn-plugin/src/strategy.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:
@@ -24,10 +24,13 @@
/**
* @File
*
- * A strategy is defined as a vpp node and a set of function that will be called
- * during the packet processing. Having one vpp node per strategy allows to
- * easily process multiple interests in the same node (x2 or x4) and call the
- * same function for choosing the next hop.
+ * A strategy is defined as a dpo and a set of function (vft) that will be called
+ * during the packet processing. A strategy is associated to an entry in the fib by
+ * assigning the corresponding dpo to the fib entry. The dpo points to a hICN dpo
+ * context (ctx) which contains the information needed by the strategy to compute
+ * the next hop. Each strategy hash its own dpo type, which means that the dpo_type
+ * uniquely identify a strategy and its vft. The strategy node will use the dpo_type
+ * to retrieve the corresponding vft.
* Here we provide:
* - a template for the callbacks to implement in order to create a new strategy
* (hicn_fwd_strategy_t)
@@ -36,6 +39,15 @@
* interest and calling hicn_select_next_hop)
*/
+/* Trace context struct */
+typedef struct
+{
+ u32 next_index;
+ u32 sw_if_index;
+ u8 pkt_type;
+ dpo_type_t dpo_type;
+} hicn_strategy_trace_t;
+
typedef struct hicn_strategy_vft_s
{
void (*hicn_receive_data) (index_t dpo_idx, int nh_idx);
@@ -43,39 +55,21 @@ typedef struct hicn_strategy_vft_s
void (*hicn_add_interest) (index_t dpo_idx, hicn_hash_entry_t * pit_entry);
u32 (*hicn_select_next_hop) (index_t dpo_idx, int *nh_idx,
dpo_id_t ** outface);
- u32 (*get_strategy_node_index) (void);
- /**< Return the vlib node index implementing the strategy */
+ u8 *(*hicn_format_strategy_trace) (u8 *, hicn_strategy_trace_t *);
+ u8 *(*hicn_format_strategy) (u8 * s, va_list * ap);
+ /**< Format an hICN dpo*/
} hicn_strategy_vft_t;
-hicn_face_vft_t *hicn_strategy_get_face_vft (u16 index);
-
-/* Strategy node API */
-/* Basic interest processing function. To be called in all the strategy nodes */
-uword
-hicn_forward_interest_fn (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame,
- hicn_strategy_vft_t * strategy,
- dpo_type_t dpo_type,
- vlib_node_registration_t * hicn_strategy_node);
-
-/* Trace context struct */
-typedef struct
-{
- u32 next_index;
- u32 sw_if_index;
- u8 pkt_type;
-} hicn_strategy_trace_t;
-
typedef enum
{
HICN_STRATEGY_NEXT_INTEREST_HITPIT,
HICN_STRATEGY_NEXT_INTEREST_HITCS,
HICN_STRATEGY_NEXT_ERROR_DROP,
- HICN_STRATEGY_NEXT_EMPTY,
HICN_STRATEGY_N_NEXT,
} hicn_strategy_next_t;
+extern vlib_node_registration_t hicn_strategy_node;
+
#endif /* //__HICN_STRATEGY__ */
/*
diff --git a/hicn-plugin/src/strategy_dpo_ctx.c b/hicn-plugin/src/strategy_dpo_ctx.c
new file mode 100644
index 000000000..6ec1407fb
--- /dev/null
+++ b/hicn-plugin/src/strategy_dpo_ctx.c
@@ -0,0 +1,163 @@
+/*
+ * Copyright (c) 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:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "strategy_dpo_ctx.h"
+#include "strategy_dpo_manager.h"
+
+hicn_dpo_ctx_t *hicn_strategy_dpo_ctx_pool;
+
+void
+hicn_strategy_init_dpo_ctx_pool ()
+{
+ pool_init_fixed (hicn_strategy_dpo_ctx_pool, 256);
+
+}
+
+void
+hicn_strategy_dpo_ctx_lock (dpo_id_t * dpo)
+{
+ hicn_dpo_ctx_t *dpo_ctx = hicn_strategy_dpo_ctx_get (dpo->dpoi_index);
+
+ if (dpo_ctx != NULL)
+ {
+ dpo_ctx->locks++;
+ }
+}
+
+void
+hicn_strategy_dpo_ctx_unlock (dpo_id_t * dpo)
+{
+ hicn_dpo_ctx_t *hicn_strategy_dpo_ctx =
+ (hicn_dpo_ctx_t *) hicn_strategy_dpo_ctx_get (dpo->dpoi_index);
+
+ if (hicn_strategy_dpo_ctx != NULL)
+ {
+ hicn_strategy_dpo_ctx->locks--;
+
+ if (0 == hicn_strategy_dpo_ctx->locks)
+ {
+ pool_put (hicn_strategy_dpo_ctx_pool, hicn_strategy_dpo_ctx);
+ }
+ }
+}
+
+u8 *
+hicn_strategy_dpo_format_ctx (u8 * s, va_list * ap)
+{
+ index_t index = va_arg (*ap, index_t);
+ hicn_dpo_ctx_t *dpo = NULL;
+ u32 indent = va_arg (*ap, u32);
+
+ dpo = (hicn_dpo_ctx_t *) hicn_strategy_dpo_ctx_get (index);
+
+ const hicn_dpo_vft_t *dpo_vft = hicn_dpo_get_vft (dpo->dpo_type);
+
+ s = dpo_vft->hicn_dpo_format (s, 2, index, indent);
+
+ return (s);
+}
+
+index_t
+hicn_strategy_dpo_ctx_get_index (hicn_dpo_ctx_t * cd)
+{
+ return (cd - hicn_strategy_dpo_ctx_pool);
+}
+
+hicn_dpo_ctx_t *
+hicn_strategy_dpo_ctx_get (index_t index)
+{
+ hicn_dpo_ctx_t *hicn_strategy_dpo_ctx = NULL;
+ if (!pool_is_free_index (hicn_strategy_dpo_ctx_pool, index))
+ {
+ hicn_strategy_dpo_ctx =
+ (pool_elt_at_index (hicn_strategy_dpo_ctx_pool, index));
+ }
+
+ return hicn_strategy_dpo_ctx;
+}
+
+hicn_dpo_ctx_t *
+hicn_strategy_dpo_ctx_alloc ()
+{
+ hicn_dpo_ctx_t *dpo_ctx;
+ pool_get (hicn_strategy_dpo_ctx_pool, dpo_ctx);
+ return dpo_ctx;
+}
+
+int
+hicn_strategy_dpo_ctx_add_nh (const dpo_id_t * nh, hicn_dpo_ctx_t * dpo_ctx,
+ u8 * pos)
+{
+
+ int empty = dpo_ctx->entry_count;
+
+ /* Iterate through the list of faces to find if the face is already a next hop */
+ for (int i = 0; i < dpo_ctx->entry_count; i++)
+ {
+ if (!memcmp (nh, &dpo_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 (dpo_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 (&dpo_ctx->next_hops[empty], nh, sizeof (dpo_id_t));
+ dpo_ctx->entry_count++;
+ *pos = empty;
+
+ return HICN_ERROR_NONE;
+}
+
+int
+hicn_strategy_dpo_ctx_del_nh (hicn_face_id_t face_id,
+ hicn_dpo_ctx_t * dpo_ctx)
+{
+ int ret = HICN_ERROR_DPO_CTX_NOT_FOUND;
+ dpo_id_t invalid = NEXT_HOP_INVALID;
+
+ for (int i = 0; i < dpo_ctx->entry_count; i++)
+ {
+ if (dpo_ctx->next_hops[i].dpoi_index == face_id)
+ {
+ hicn_face_unlock (&dpo_ctx->next_hops[i]);
+ dpo_ctx->entry_count--;
+ dpo_ctx->next_hops[i] = dpo_ctx->next_hops[dpo_ctx->entry_count];
+ dpo_ctx->next_hops[dpo_ctx->entry_count] = invalid;
+ ret = HICN_ERROR_NONE;
+ break;
+ }
+ }
+
+ return ret;
+
+}
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables: eval: (c-set-style "gnu") End:
+ */
diff --git a/hicn-plugin/src/strategy_dpo_ctx.h b/hicn-plugin/src/strategy_dpo_ctx.h
index 00b11412b..737071766 100644
--- a/hicn-plugin/src/strategy_dpo_ctx.h
+++ b/hicn-plugin/src/strategy_dpo_ctx.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:
@@ -22,15 +22,21 @@
#include "params.h"
#include "faces/face.h"
+//FIB table for hicn. 0 is the default one used by ip
#define HICN_FIB_TABLE 0
-#define DATA_LEN 8
-
#define NEXT_HOP_INVALID DPO_INVALID
#define INIT_SEQ 0
-/*
- * An hicn dpo is a list of next hops (face + weight).
+
+/**
+ * @brief Definition of the general hICN DPO ctx (shared among all the strategies).
+ *
+ * An hICN DPO ctx contains the list of next hops, auxiliaries fields to maintain the dpo, map-me
+ * specifics (tfib_entry_count and seq), the dpo_type and 64B to let each strategy to store additional
+ * information. Each next hop is a dpo_id_t that refers to an hICN face. The dpo_type is used to
+ * identify the strategy and to retrieve the vft corresponding to the strategy (see strategy.h)
+ * and to the dpo ctx (see strategy_dpo_manager.h)
*/
typedef struct __attribute__ ((packed)) hicn_dpo_ctx_s
{
@@ -48,39 +54,121 @@ typedef struct __attribute__ ((packed)) hicn_dpo_ctx_s
/* 46B + 2B = 48B */
u16 padding; /* To align to 8B */
-#ifdef HICN_MAPME_NOTIFICATIONS
- /* (8B) last acked update for IU/IN heuristic on producer */
- f64 last_iu_ack;
-#endif
- /* (4B) last sequence number */
+ /* 48 + 4B = 52; last sequence number */
seq_t seq;
+ /* 48 + 1B = 53; last sequence number */
+ dpo_type_t dpo_type;
+
+ CLIB_CACHE_LINE_ALIGN_MARK (cacheline1);
+ u8 data[CLIB_CACHE_LINE_BYTES];
+
} hicn_dpo_ctx_t;
+extern hicn_dpo_ctx_t *hicn_strategy_dpo_ctx_pool;
+
+/**
+ * @brief Initialize the hICN dpo ctx
+ *
+ * @param dpo_ctx Pointer to the hICN dpo ctx to initialize
+ * @param next_hop List of netx hops to store in the dpo ctx
+ * @param nh_len Number of elements in the list of next hops
+ * @param dpo_type Type of dpo. It identifies the strategy.
+ */
always_inline void
-init_dpo_ctx (hicn_dpo_ctx_t * dpo_ctx)
+init_dpo_ctx (hicn_dpo_ctx_t * dpo_ctx, const dpo_id_t * next_hop,
+ int nh_len, dpo_type_t dpo_type)
{
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;
+ dpo_ctx->dpo_type = dpo_type;
+
+ for (int i = 0; i < HICN_PARAM_FIB_ENTRY_NHOPS_MAX && i < nh_len; i++)
+ {
+ clib_memcpy (&dpo_ctx->next_hops[i], &next_hop[i], sizeof (dpo_id_t));
+ dpo_ctx->entry_count++;
+ }
+
+
+ for (int i = nh_len; i < HICN_PARAM_FIB_ENTRY_NHOPS_MAX; i++)
+ {
+ dpo_ctx->next_hops[i] = invalid;
+ }
+
}
-STATIC_ASSERT (sizeof (hicn_dpo_ctx_t) <= CLIB_CACHE_LINE_BYTES,
- "sizeof hicn_dpo_ctx_t is greater than 64B");
+/**
+ * @brief Initialize the pool containing the hICN dpo ctx
+ *
+ */
+void hicn_strategy_init_dpo_ctx_pool (void);
+
+/**
+ * @brief Allocate a new hICN dpo ctx from the pool
+ */
+hicn_dpo_ctx_t *hicn_strategy_dpo_ctx_alloc ();
+
+/**
+ * @brief Retrieve an existing hICN dpo ctx from the pool
+ */
+hicn_dpo_ctx_t *hicn_strategy_dpo_ctx_get (index_t index);
+
+/**
+ * @brief Retrieve the index of the hICN dpo ctx
+ */
+index_t hicn_strategy_dpo_ctx_get_index (hicn_dpo_ctx_t * cd);
+
+/**
+ * @brief Lock the dpo of a strategy ctx
+ *
+ * @param dpo Identifier of the dpo of the strategy ctx
+ */
+void hicn_strategy_dpo_ctx_lock (dpo_id_t * dpo);
+
+/**
+ * @brief Unlock the dpo of a strategy ctx
+ *
+ * @param dpo Identifier of the dpo of the strategy ctx
+ */
+void hicn_strategy_dpo_ctx_unlock (dpo_id_t * dpo);
+
+/**
+ * @brief Add or update a next hop in the dpo ctx.
+ *
+ * This function is meant to be used in the control plane and not in the data plane,
+ * as it is not optimized for the latter.
+ *
+ * @param nh Next hop to insert in the dpo ctx
+ * @param dpo_ctx Dpo ctx to update with the new or updated next hop
+ * @param pos Return the position of the nh that has been added
+ * @return HICN_ERROR_NONE if the update or insert was fine,
+ * otherwise HICN_ERROR_DPO_CTX_NOT_FOUND
+ */
+int
+hicn_strategy_dpo_ctx_add_nh (const dpo_id_t * nh, hicn_dpo_ctx_t * dpo_ctx,
+ u8 * pos);
+
+/**
+ * @brief Delete a next hop in the dpo ctx.
+ *
+ * @param face_id Face identifier of the next hop
+ * @param dpo_ctx Dpo ctx to update by removing the face
+ * @return HICN_ERROR_NONE if the update or insert was fine,
+ * otherwise HICN_ERROR_DPO_CTS_NOT_FOUND
+ */
+int
+hicn_strategy_dpo_ctx_del_nh (hicn_face_id_t face_id,
+ hicn_dpo_ctx_t * dpo_ctx);
+
+
+STATIC_ASSERT (sizeof (hicn_dpo_ctx_t) <= 2 * CLIB_CACHE_LINE_BYTES,
+ "sizeof hicn_dpo_ctx_t is greater than 128B");
#endif /* // __HICN_STRATEGY_DPO_CTX_H__ */
diff --git a/hicn-plugin/src/strategy_dpo_manager.c b/hicn-plugin/src/strategy_dpo_manager.c
index 470d8d185..f8d41a372 100644
--- a/hicn-plugin/src/strategy_dpo_manager.c
+++ b/hicn-plugin/src/strategy_dpo_manager.c
@@ -16,6 +16,7 @@
#include <vnet/dpo/dpo.h>
#include "strategy_dpo_manager.h"
+#include "strategy_dpo_ctx.h"
#include "strategies/dpo_mw.h"
#include "strategies/dpo_rr.h"
#include "strategy.h"
@@ -94,19 +95,17 @@ hicn_dpo_get_strategy_vft_from_id (u8 vfts_id)
void
hicn_dpos_init (void)
{
+ hicn_strategy_init_dpo_ctx_pool ();
hicn_dpo_strategy_mw_module_init ();
hicn_dpo_strategy_rr_module_init ();
- default_dpo.hicn_dpo_get_ctx = &hicn_strategy_mw_ctx_get;
default_dpo.hicn_dpo_is_type = &hicn_dpo_is_type_strategy_mw;
default_dpo.hicn_dpo_get_type = &hicn_dpo_strategy_mw_get_type;
default_dpo.hicn_dpo_module_init = &hicn_dpo_strategy_mw_module_init;
default_dpo.hicn_dpo_create = &hicn_strategy_mw_ctx_create;
default_dpo.hicn_dpo_add_update_nh = &hicn_strategy_mw_ctx_add_nh;
default_dpo.hicn_dpo_del_nh = &hicn_strategy_mw_ctx_del_nh;
- default_dpo.hicn_dpo_lock_dpo_ctx = &hicn_strategy_mw_ctx_lock;
- default_dpo.hicn_dpo_unlock_dpo_ctx = hicn_strategy_mw_ctx_unlock;
- default_dpo.format_hicn_dpo = &format_hicn_strategy_mw_ctx;
+ default_dpo.hicn_dpo_format = &hicn_strategy_mw_format_ctx;
}
u8 *
@@ -117,13 +116,13 @@ format_hicn_strategy_list (u8 * s, int n, ...)
u32 indent = va_arg (ap, u32);
va_end (ap);
- s = format (s, "Strategies:\n", indent);
+ s = format (s, "%U Strategies:\n", format_white_space, indent);
indent += 4;
int i;
vec_foreach_index (i, strategies_id)
{
- s = format (s, "(%d) ", i, indent);
- s = hicn_dpo_vfts[strategies_id[i]]->format_hicn_dpo (s, &ap);
+ s = format (s, "%U (%d) ", format_white_space, indent, i);
+ s = hicn_strategy_vfts[strategies_id[i]]->hicn_format_strategy (s, &ap);
}
return (s);
diff --git a/hicn-plugin/src/strategy_dpo_manager.h b/hicn-plugin/src/strategy_dpo_manager.h
index 686c2f8c8..63fcb930b 100644
--- a/hicn-plugin/src/strategy_dpo_manager.h
+++ b/hicn-plugin/src/strategy_dpo_manager.h
@@ -29,21 +29,16 @@
*/
typedef struct hicn_dpo_vft_s
{
- hicn_dpo_ctx_t *(*hicn_dpo_get_ctx) (index_t dpo_idx); /**< Retrieve the dpo ctx*/
int (*hicn_dpo_is_type) (const dpo_id_t * dpo);
/**< Check if the type of the
hICN DPO is the expected */
dpo_type_t (*hicn_dpo_get_type) (void);
/**< Return the type of the hICN dpo */
void (*hicn_dpo_module_init) (void); /**< Initialize the hICN dpo */
- int (*hicn_dpo_create) (dpo_proto_t proto, const dpo_id_t * nh, int nh_len, index_t * dpo_idx); /**< Create the context of the hICN dpo */
+ void (*hicn_dpo_create) (dpo_proto_t proto, const dpo_id_t * nh, int nh_len, index_t * dpo_idx); /**< Create the context of the hICN dpo */
int (*hicn_dpo_add_update_nh) (const dpo_id_t * nh, index_t dpo_idx); /**< Add a next hop to the hICN dpo context */
- int (*hicn_dpo_del_nh) (hicn_face_id_t face_id, index_t dpo_idx,
- fib_prefix_t * fib_pfx);
- /**< Add a next hop to the hICN dpo context */
- void (*hicn_dpo_lock_dpo_ctx) (dpo_id_t * dpo);
- void (*hicn_dpo_unlock_dpo_ctx) (dpo_id_t * dpo);
- u8 *(*format_hicn_dpo) (u8 * s, va_list * ap);
+ int (*hicn_dpo_del_nh) (hicn_face_id_t face_id, index_t dpo_idx);
+ u8 *(*hicn_dpo_format) (u8 * s, int, ...);
/**< Format an hICN dpo*/
} hicn_dpo_vft_t;
@@ -53,6 +48,21 @@ typedef struct hicn_dpo_vft_s
*/
extern hicn_dpo_vft_t default_dpo;
+const static char *const hicn_ip6_nodes[] = {
+ "hicn-iface-ip6-input", // this is the name you give your node in VLIB_REGISTER_NODE
+ NULL,
+};
+
+const static char *const hicn_ip4_nodes[] = {
+ "hicn-iface-ip4-input", // this is the name you give your node in VLIB_REGISTER_NODE
+ NULL,
+};
+
+const static char *const *const hicn_nodes_strategy[DPO_PROTO_NUM] = {
+ [DPO_PROTO_IP6] = hicn_ip6_nodes,
+ [DPO_PROTO_IP4] = hicn_ip4_nodes,
+};
+
/**
* @brief Register a new hICN dpo to the manager.
*
diff --git a/hicn-plugin/src/strategy.c b/hicn-plugin/src/strategy_node.c
index 15c0dc720..27d1e2a03 100644
--- a/hicn-plugin/src/strategy.c
+++ b/hicn-plugin/src/strategy_node.c
@@ -25,6 +25,10 @@
#include "mgmt.h"
#include "pcs.h"
#include "state.h"
+#include "strategies/strategy_mw.h"
+
+/* Registration struct for a graph node */
+vlib_node_registration_t hicn_strategy_node;
/*
* Node context data (to be used in all the strategy nodes); we think this is
@@ -36,11 +40,32 @@ typedef struct hicn_strategy_runtime_s
hicn_pit_cs_t *pitcs;
} hicn_strategy_runtime_t;
+/* Stats string values */
+static char *hicn_strategy_error_strings[] = {
+#define _(sym, string) string,
+ foreach_hicnfwd_error
+#undef _
+};
+
+/* packet trace format function */
+u8 *
+hicn_strategy_format_trace (u8 * s, va_list * args)
+{
+ 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 *);
+
+ const hicn_strategy_vft_t *vft = hicn_dpo_get_strategy_vft (t->dpo_type);
+
+ return vft->hicn_format_strategy_trace (s, t);
+}
+
+
always_inline int
hicn_new_interest (hicn_strategy_runtime_t * rt, vlib_buffer_t * b0,
u32 * next, f64 tnow, u8 * nameptr,
u16 namelen, dpo_id_t * outface, int nh_idx,
- index_t hicn_dpo_idx, hicn_strategy_vft_t * strategy,
+ index_t dpo_ctx_id0, const hicn_strategy_vft_t * strategy,
dpo_type_t dpo_type, u8 isv6,
vl_api_hicn_api_node_stats_get_reply_t * stats)
{
@@ -51,7 +76,6 @@ hicn_new_interest (hicn_strategy_runtime_t * rt, vlib_buffer_t * b0,
hicn_main_t *sm = &hicn_main;
hicn_buffer_t *hicnb0 = hicn_get_buffer (b0);
u32 node_id0 = 0;
- u8 dpo_ctx_id0 = vnet_buffer (b0)->ip.adj_index[VLIB_TX];
u8 vft_id0 = dpo_type;
u8 is_cs0 = 0;
u8 hash_entry_id = 0;
@@ -142,24 +166,20 @@ hicn_new_interest (hicn_strategy_runtime_t * rt, vlib_buffer_t * b0,
* ipv6/tcp
*/
uword
-hicn_forward_interest_fn (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame,
- hicn_strategy_vft_t * strategy,
- dpo_type_t dpo_type,
- vlib_node_registration_t * hicn_strategy_node)
+hicn_strategy_fn (vlib_main_t * vm,
+ vlib_node_runtime_t * node, vlib_frame_t * frame)
{
u32 n_left_from, *from, *to_next, n_left_to_next;
hicn_strategy_next_t next_index;
- hicn_strategy_runtime_t *rt;
+ hicn_strategy_runtime_t *rt = NULL;
vl_api_hicn_api_node_stats_get_reply_t stats = { 0 };
f64 tnow;
from = vlib_frame_vector_args (frame);
n_left_from = frame->n_vectors;
next_index = (hicn_strategy_next_t) node->cached_next_index;
- rt = vlib_node_get_runtime_data (vm, hicn_strategy_node->index);
+ rt = vlib_node_get_runtime_data (vm, hicn_strategy_node.index);
rt->pitcs = &hicn_main.pitcs;
/* Capture time in vpp terms */
tnow = vlib_time_now (vm);
@@ -202,6 +222,12 @@ hicn_forward_interest_fn (vlib_main_t * vm,
b0 = vlib_get_buffer (vm, bi0);
next0 = HICN_STRATEGY_NEXT_ERROR_DROP;
+ hicn_dpo_ctx_t *dpo_ctx =
+ hicn_strategy_dpo_ctx_get (vnet_buffer (b0)->ip.
+ adj_index[VLIB_TX]);
+ const hicn_strategy_vft_t *strategy =
+ hicn_dpo_get_strategy_vft (dpo_ctx->dpo_type);
+
ret = hicn_interest_parse_pkt (b0, &name, &namelen, &hicn0, &isv6);
stats.pkts_processed++;
/* Select next hop */
@@ -212,8 +238,9 @@ hicn_forward_interest_fn (vlib_main_t * vm,
*/
if (PREDICT_TRUE
(ret == HICN_ERROR_NONE && HICN_IS_NAMEHASH_CACHED (b0)
- && strategy->hicn_select_next_hop (vnet_buffer (b0)->ip.
- adj_index[VLIB_TX], &nh_idx,
+ && strategy->hicn_select_next_hop (vnet_buffer (b0)->
+ ip.adj_index[VLIB_TX],
+ &nh_idx,
&outface) ==
HICN_ERROR_NONE))
{
@@ -226,7 +253,7 @@ hicn_forward_interest_fn (vlib_main_t * vm,
hicn_new_interest (rt, b0, &next0, tnow, nameptr, namelen,
outface, nh_idx,
vnet_buffer (b0)->ip.adj_index[VLIB_TX],
- strategy, dpo_type, isv6, &stats);
+ strategy, dpo_ctx->dpo_type, isv6, &stats);
}
/* Maybe trace */
if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) &&
@@ -237,6 +264,7 @@ hicn_forward_interest_fn (vlib_main_t * vm,
t->pkt_type = HICN_PKT_TYPE_CONTENT;
t->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX];
t->next_index = next0;
+ t->dpo_type = dpo_ctx->dpo_type;
}
/*
* Verify speculative enqueue, maybe switch current
@@ -254,9 +282,9 @@ hicn_forward_interest_fn (vlib_main_t * vm,
vlib_put_next_frame (vm, node, next_index, n_left_to_next);
}
- vlib_node_increment_counter (vm, hicn_strategy_node->index,
+ vlib_node_increment_counter (vm, hicn_strategy_node.index,
HICNFWD_ERROR_PROCESSED, stats.pkts_processed);
- vlib_node_increment_counter (vm, hicn_strategy_node->index,
+ vlib_node_increment_counter (vm, hicn_strategy_node.index,
HICNFWD_ERROR_INTERESTS,
stats.pkts_interest_count);
@@ -264,6 +292,30 @@ hicn_forward_interest_fn (vlib_main_t * vm,
}
/*
+ * Node registration for the forwarder node
+ */
+/* *INDENT-OFF* */
+VLIB_REGISTER_NODE (hicn_strategy_node) =
+ {
+ .name = "hicn-strategy",
+ .function = hicn_strategy_fn,
+ .vector_size = sizeof (u32),
+ .runtime_data_bytes = sizeof (int) + sizeof(hicn_pit_cs_t *),
+ .format_trace = hicn_strategy_format_trace,
+ .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",
+ },
+ };
+
+
+/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables: eval: (c-set-style "gnu") End: