aboutsummaryrefslogtreecommitdiffstats
path: root/hicn-plugin/src/strategies
diff options
context:
space:
mode:
Diffstat (limited to 'hicn-plugin/src/strategies')
-rwxr-xr-xhicn-plugin/src/strategies/dpo_mw.c305
-rwxr-xr-xhicn-plugin/src/strategies/dpo_mw.h131
-rwxr-xr-xhicn-plugin/src/strategies/strategy_mw.c171
-rwxr-xr-xhicn-plugin/src/strategies/strategy_mw.h31
-rwxr-xr-xhicn-plugin/src/strategies/strategy_mw_cli.c148
5 files changed, 786 insertions, 0 deletions
diff --git a/hicn-plugin/src/strategies/dpo_mw.c b/hicn-plugin/src/strategies/dpo_mw.c
new file mode 100755
index 000000000..882368e6e
--- /dev/null
+++ b/hicn-plugin/src/strategies/dpo_mw.c
@@ -0,0 +1,305 @@
+/*
+ * Copyright (c) 2017-2019 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 "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,
+};
+
+/**
+ * @brief DPO type value for the mw_strategy
+ */
+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
+};
+
+int
+hicn_dpo_is_type_strategy_mw (const dpo_id_t * dpo)
+{
+ return dpo->dpoi_type == hicn_dpo_type_mw;
+}
+
+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_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)
+{
+ return hicn_dpo_type_mw;
+}
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
+
+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);
+ hicn_strategy_mw_ctx->default_ctx.locks++;
+}
+
+void
+hicn_strategy_mw_ctx_unlock (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);
+ 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);
+ }
+}
+
+u8 *
+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;
+ 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);
+
+ s = format (s, "hicn-mw");
+ for (i = 0; i < HICN_PARAM_FIB_ENTRY_NHOPS_MAX; i++)
+ {
+ next_hop = &dpo->default_ctx.next_hops[i];
+ face_vft = hicn_face_get_vft (next_hop->dpoi_type);
+ if (face_vft != NULL)
+ {
+ s = format (s, "\n");
+ s =
+ format (s, "%U ", face_vft->format_face, next_hop->dpoi_index,
+ indent);
+ s = format (s, "weight %u", dpo->weight[i]);
+ }
+ }
+
+ 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
+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;
+ dpo_id_t invalid = NEXT_HOP_INVALID;
+
+ /* Allocate a hicn_dpo_ctx on the vpp pool and initialize it */
+ pool_get (hicn_strategy_mw_ctx_pool, hicn_strategy_mw_ctx);
+
+ *dpo_idx = hicn_strategy_mw_ctx_get_index (hicn_strategy_mw_ctx);
+ for (int i = 0; i < HICN_PARAM_FIB_ENTRY_NHOPS_MAX; i++)
+ {
+ hicn_strategy_mw_ctx->default_ctx.next_hops[i] = invalid;
+ }
+
+ hicn_strategy_mw_ctx->default_ctx.entry_count = 0;
+ hicn_strategy_mw_ctx->default_ctx.locks = 0;
+
+ 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++;
+ }
+
+ 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_strategy_mw_ctx->default_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);
+
+ if (hicn_strategy_mw_ctx != NULL)
+ {
+
+ 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;
+ }
+ if (PREDICT_FALSE (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++;
+
+ return HICN_ERROR_NONE;
+ }
+ return HICN_ERROR_DPO_CTX_NOT_FOUND;
+}
+
+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_t *hicn_strategy_mw_ctx =
+ (hicn_strategy_mw_ctx_t *) hicn_strategy_mw_ctx_get (dpo_idx);
+ int ret = HICN_ERROR_NONE;
+ int nh_id = ~0;
+ dpo_id_t invalid = NEXT_HOP_INVALID;
+
+ if (hicn_strategy_mw_ctx != NULL)
+ {
+ 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)
+ {
+ nh_id = i;
+ hicn_face_unlock (&hicn_strategy_mw_ctx->default_ctx.
+ next_hops[i]);
+ hicn_strategy_mw_ctx->default_ctx.next_hops[i] = invalid;
+ hicn_strategy_mw_ctx->default_ctx.entry_count--;
+ }
+ }
+
+ if (0 == hicn_strategy_mw_ctx->default_ctx.entry_count)
+ {
+ fib_table_entry_special_remove (HICN_FIB_TABLE, fib_pfx,
+ FIB_SOURCE_PLUGIN_HI);
+ }
+ }
+ else
+ {
+ ret = HICN_ERROR_DPO_CTX_NOT_FOUND;
+ }
+
+ /*
+ * Remove any possible hole in the arrays of dpos
+ */
+ if (hicn_strategy_mw_ctx->default_ctx.entry_count > 0 && nh_id != ~0
+ && nh_id < hicn_strategy_mw_ctx->default_ctx.entry_count - 1)
+ {
+ int i;
+ for (i = nh_id; i < hicn_strategy_mw_ctx->default_ctx.entry_count; i++)
+ {
+ clib_memcpy (&hicn_strategy_mw_ctx->default_ctx.next_hops[i],
+ &hicn_strategy_mw_ctx->default_ctx.next_hops[i + 1],
+ sizeof (dpo_id_t));
+ }
+ /* Set as invalid the last dpo */
+ hicn_strategy_mw_ctx->default_ctx.next_hops[i] = invalid;
+ }
+ return ret;
+}
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/hicn-plugin/src/strategies/dpo_mw.h b/hicn-plugin/src/strategies/dpo_mw.h
new file mode 100755
index 000000000..a8c0a3b43
--- /dev/null
+++ b/hicn-plugin/src/strategies/dpo_mw.h
@@ -0,0 +1,131 @@
+/*
+ * Copyright (c) 2017-2019 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.
+ */
+
+#ifndef __HICN_DPO_MW_H__
+#define __HICN_DPO_MW_H__
+
+#include <vnet/dpo/dpo.h>
+#include "../strategy_dpo_ctx.h"
+
+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
+ * @param ap List of parameters for the formatting
+ *
+ * @result The string with the formatted dpo ctx
+ */
+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_format = format_hicn_strategy_mw_ctx,
+};
+
+/**
+ * @brief Retrieve an hicn_strategy_mw_ctx object
+ *
+ * @param indext Index of the hicn_dpo_ctx to retrieve
+ * @return The hicn_dpo_ctx object or NULL
+ */
+hicn_dpo_ctx_t *hicn_strategy_mw_ctx_get (index_t index);
+
+/**
+ * @brief Create a new mw ctx
+ *
+ * @param proto The protocol to which the dpo is meant for (see vpp docs)
+ * @param next_hop A list of next hops to be inserted in the dpo ctx
+ * @param nh_len Size of the list
+ * @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
+hicn_strategy_mw_ctx_create (dpo_proto_t proto, const dpo_id_t * next_hop,
+ int nh_len, index_t * dpo_idx);
+
+/**
+ * @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_idx Index of the dpo ctx to update with the new or updated next
+ * hop
+ * @return HICN_ERROR_NONE if the update or insert was fine,
+ * otherwise HICN_ERROR_DPO_CTX_NOT_FOUND
+ */
+int hicn_strategy_mw_ctx_add_nh (const dpo_id_t * nh, index_t dpo_idx);
+
+/**
+ * @brief Delete a next hop in the dpo ctx.
+ *
+ * @param face_id Face identifier of the next hop
+ * @param dpo_idx Index of the dpo ctx to update with the new or updated next
+ * hop
+ * @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);
+
+/**
+ * @brief Prefetch a dpo
+ *
+ * @param dpo_idx Index of the dpo ctx to prefetch
+ */
+void hicn_strategy_mw_ctx_prefetch (index_t dpo_idx);
+
+int hicn_dpo_is_type_strategy_mw (const dpo_id_t * dpo);
+
+void hicn_dpo_strategy_mw_module_init (void);
+
+dpo_type_t hicn_dpo_strategy_mw_get_type (void);
+
+u8 *format_hicn_dpo_strategy_mw (u8 * s, va_list * ap);
+
+
+#endif // __HICN_DPO_MW_H__
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/hicn-plugin/src/strategies/strategy_mw.c b/hicn-plugin/src/strategies/strategy_mw.c
new file mode 100755
index 000000000..144dd145e
--- /dev/null
+++ b/hicn-plugin/src/strategies/strategy_mw.c
@@ -0,0 +1,171 @@
+/*
+ * Copyright (c) 2017-2019 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 <vlib/vlib.h>
+#include <vnet/vnet.h>
+
+#include "../strategy.h"
+#include "../strategy_dpo_ctx.h"
+#include "dpo_mw.h"
+#include "../faces/face.h"
+#include "../route.h"
+#include "../pcs.h"
+#include "../strategy_dpo_manager.h"
+
+/* Simple strategy that chooses the next hop with the maximum weight */
+/* It does not require to exend the hicn_dpo */
+void hicn_receive_data_mw (index_t dpo_idx, int nh_idx);
+void hicn_add_interest_mw (index_t dpo_idx, hicn_hash_entry_t * pit_entry);
+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);
+
+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 _
+};
+
+/*
+ * Return the vft of the strategy.
+ */
+hicn_strategy_vft_t *
+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);
+
+ u8 next_hop_index = 0;
+ for (int i = 0; i < HICN_PARAM_FIB_ENTRY_NHOPS_MAX; i++)
+ {
+ if (dpo_id_is_valid (&hicn_strategy_mw_ctx->default_ctx.next_hops[i]))
+ {
+ if (hicn_strategy_mw_ctx->weight[next_hop_index] <
+ hicn_strategy_mw_ctx->weight[i])
+ {
+ next_hop_index = i;
+ }
+ }
+ }
+
+ if (!dpo_id_is_valid
+ (&hicn_strategy_mw_ctx->default_ctx.next_hops[next_hop_index]))
+ return HICN_ERROR_MW_STRATEGY_NH_NOT_FOUND;
+
+ *outface =
+ (dpo_id_t *) & hicn_strategy_mw_ctx->default_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_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);
+ hash_entry->vft_id = hicn_dpo_get_vft_id (&hicn_dpo_id);
+}
+
+void
+hicn_on_interest_timeout_mw (index_t dpo_idx)
+{
+ /* Nothign to do in the mw strategy when we receive an interest */
+}
+
+void
+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)
+{
+ 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) =
+{
+ .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_ERROR_DROP] = "error-drop",
+ },
+};
+/* *INDENT-ON* */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/hicn-plugin/src/strategies/strategy_mw.h b/hicn-plugin/src/strategies/strategy_mw.h
new file mode 100755
index 000000000..10b08c05f
--- /dev/null
+++ b/hicn-plugin/src/strategies/strategy_mw.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2017-2019 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.
+ */
+
+#ifndef __HICN_STRATEGY_MW_H__
+#define __HICN_STRATEGY_MW_H__
+
+#include "../strategy.h"
+
+hicn_strategy_vft_t *hicn_mw_strategy_get_vft (void);
+
+#endif // __HICN_STRATEGY_MW_H__
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/hicn-plugin/src/strategies/strategy_mw_cli.c b/hicn-plugin/src/strategies/strategy_mw_cli.c
new file mode 100755
index 000000000..ff4125258
--- /dev/null
+++ b/hicn-plugin/src/strategies/strategy_mw_cli.c
@@ -0,0 +1,148 @@
+/*
+ * Copyright (c) 2017-2019 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 <vnet/vnet.h>
+#include <vnet/dpo/dpo.h>
+#include <vlib/vlib.h>
+#include <vnet/fib/fib_entry.h>
+#include <vnet/fib/fib_table.h>
+
+#include "../strategy_dpo_manager.h"
+#include "../faces/face.h"
+#include "../error.h"
+#include "../route.h"
+#include "dpo_mw.h"
+
+static clib_error_t *
+hicn_mw_strategy_cli_set_weight_command_fn (vlib_main_t * vm,
+ unformat_input_t * main_input,
+ vlib_cli_command_t * cmd)
+{
+ clib_error_t *cl_err = 0;
+ int ret = HICN_ERROR_NONE;
+ ip46_address_t prefix;
+ hicn_face_id_t faceid = HICN_FACE_NULL;
+ u32 fib_index;
+ u32 weight = HICN_PARAM_FIB_ENTRY_NHOP_WGHT_DFLT;
+ u32 plen = 0;
+ 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;
+ if (unformat_user (main_input, unformat_line_input, line_input))
+ {
+ while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (line_input, "prefix %U/%u", unformat_ip46_address,
+ &prefix, IP46_TYPE_ANY, &plen))
+ ;
+ else if (unformat (line_input, "face %u", &faceid))
+ ;
+ else if (unformat (line_input, "weight %u", &weight))
+ ;
+ else
+ {
+ return clib_error_return (0, "%s",
+ get_error_string
+ (HICN_ERROR_CLI_INVAL));
+ }
+
+ }
+ }
+
+ if (((weight < 0) || (weight > HICN_PARAM_FIB_ENTRY_NHOP_WGHT_MAX)))
+ {
+ cl_err = clib_error_return (0,
+ "Next-hop weight must be between 0 and %d",
+ (int) HICN_PARAM_FIB_ENTRY_NHOP_WGHT_MAX);
+ goto done;
+ }
+
+ if (((ip46_address_is_zero (&prefix)) || faceid == HICN_FACE_NULL))
+ {
+ cl_err =
+ clib_error_return (0, "Please specify prefix and a valid faceid...");
+ goto done;
+ }
+
+ fib_prefix_t fib_pfx;
+ fib_prefix_from_ip46_addr (&prefix, &fib_pfx);
+ fib_pfx.fp_len = plen;
+
+ ret = hicn_route_get_dpo (&prefix, plen, &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);
+
+ if (hicn_dpo_ctx == NULL
+ || hicn_dpo_id->dpoi_type != hicn_dpo_strategy_mw_get_type ())
+ {
+ cl_err = clib_error_return (0, get_error_string (ret));
+ goto done;
+ }
+
+ hicn_strategy_mw_ctx_t *mw_dpo =
+ (hicn_strategy_mw_ctx_t *) hicn_dpo_ctx;
+ int idx = ~0;
+ for (int i = 0; i < hicn_dpo_ctx->entry_count; i++)
+ if (hicn_dpo_ctx->next_hops[i].dpoi_index == (index_t) faceid)
+ idx = i;
+
+ if (idx == ~0)
+ {
+ cl_err =
+ clib_error_return (0,
+ get_error_string
+ (HICN_ERROR_MW_STRATEGY_NH_NOT_FOUND));
+ goto done;
+ }
+
+ mw_dpo->weight[idx] = weight;
+ }
+ else
+ {
+ cl_err = clib_error_return (0, get_error_string (ret));
+
+ }
+
+done:
+
+ return (cl_err);
+
+}
+
+/* cli declaration for 'strategy mw' */
+/* *INDENT-OFF* */
+VLIB_CLI_COMMAND(hicn_mw_strategy_cli_set_weight_command, static)=
+{
+ .path = "hicn strategy mw set",
+ .short_help = "hicn strategy mw set prefix <prefix> face <face_id> weight <weight>",
+ .function = hicn_mw_strategy_cli_set_weight_command_fn,
+};
+/* *INDENT-ON* */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */