aboutsummaryrefslogtreecommitdiffstats
path: root/hicn-plugin/src/strategies/dpo_mw.c
diff options
context:
space:
mode:
Diffstat (limited to 'hicn-plugin/src/strategies/dpo_mw.c')
-rw-r--r--hicn-plugin/src/strategies/dpo_mw.c74
1 files changed, 38 insertions, 36 deletions
diff --git a/hicn-plugin/src/strategies/dpo_mw.c b/hicn-plugin/src/strategies/dpo_mw.c
index 12c77bce8..9283f6a43 100644
--- a/hicn-plugin/src/strategies/dpo_mw.c
+++ b/hicn-plugin/src/strategies/dpo_mw.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2020 Cisco and/or its affiliates.
+ * Copyright (c) 2021 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:
@@ -28,13 +28,20 @@ static const hicn_dpo_vft_t hicn_dpo_mw_vft = {
.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_update_type = &hicn_strategy_mw_update_ctx_type,
.hicn_dpo_add_update_nh = &hicn_strategy_mw_ctx_add_nh,
.hicn_dpo_del_nh = &hicn_strategy_mw_ctx_del_nh,
- .hicn_dpo_format = &hicn_strategy_mw_format_ctx
+ .hicn_dpo_format = &hicn_dpo_strategy_mw_format
+};
+
+const static dpo_vft_t dpo_strategy_mw_ctx_vft = {
+ .dv_lock = &hicn_strategy_dpo_ctx_lock,
+ .dv_unlock = &hicn_strategy_dpo_ctx_unlock,
+ .dv_format = &hicn_strategy_dpo_format
};
int
-hicn_dpo_is_type_strategy_mw (const dpo_id_t * dpo)
+hicn_dpo_is_type_strategy_mw (const dpo_id_t *dpo)
{
return dpo->dpoi_type == hicn_dpo_type_mw;
}
@@ -45,10 +52,9 @@ hicn_dpo_strategy_mw_module_init (void)
/*
* Register our type of dpo
*/
- hicn_dpo_type_mw =
- hicn_dpo_register_new_type (hicn_nodes_strategy, &hicn_dpo_mw_vft,
- hicn_mw_strategy_get_vft (),
- &dpo_strategy_mw_ctx_vft);
+ hicn_dpo_type_mw = hicn_dpo_register_new_type (
+ hicn_nodes_strategy, &hicn_dpo_mw_vft, hicn_mw_strategy_get_vft (),
+ &dpo_strategy_mw_ctx_vft);
}
dpo_type_t
@@ -59,28 +65,11 @@ hicn_dpo_strategy_mw_get_type (void)
//////////////////////////////////////////////////////////////////////////////////////////////////
-
-u8 *
-hicn_strategy_mw_format_ctx (u8 * s, int n, ...)
-{
- va_list args;
- va_start (args, n);
- s = format_hicn_strategy_mw_ctx (s, &args);
- return s;
-}
-
u8 *
-format_hicn_strategy_mw_ctx (u8 * s, va_list * ap)
+hicn_dpo_strategy_mw_format (u8 *s, hicn_dpo_ctx_t *dpo_ctx, u32 indent)
{
- int i = 0;
- index_t index = va_arg (*ap, index_t);
- hicn_dpo_ctx_t *dpo_ctx = NULL;
hicn_strategy_mw_ctx_t *mw_dpo_ctx = NULL;
- u32 indent = va_arg (*ap, u32);;
-
- dpo_ctx = hicn_strategy_dpo_ctx_get (index);
- if (dpo_ctx == NULL)
- return s;
+ int i = 0;
mw_dpo_ctx = (hicn_strategy_mw_ctx_t *) dpo_ctx->data;
@@ -90,16 +79,13 @@ format_hicn_strategy_mw_ctx (u8 * s, va_list * ap)
u8 *buf = NULL;
if (i < dpo_ctx->entry_count)
buf = format (NULL, "FIB");
- else if (i >=
- HICN_PARAM_FIB_ENTRY_NHOPS_MAX - dpo_ctx->tfib_entry_count)
+ else if (i >= HICN_PARAM_FIB_ENTRY_NHOPS_MAX - dpo_ctx->tfib_entry_count)
buf = format (NULL, "TFIB");
else
continue;
s = format (s, "\n");
- s =
- format (s, "%U ", format_hicn_face, dpo_ctx->next_hops[i],
- indent);
+ s = format (s, "%U ", format_hicn_face, dpo_ctx->next_hops[i], indent);
s = format (s, "weight %u", mw_dpo_ctx->weight[i]);
s = format (s, " %s", buf);
}
@@ -108,8 +94,9 @@ format_hicn_strategy_mw_ctx (u8 * s, va_list * ap)
}
void
-hicn_strategy_mw_ctx_create (fib_protocol_t proto, const hicn_face_id_t * next_hop,
- int nh_len, index_t * dpo_idx)
+hicn_strategy_mw_ctx_create (fib_protocol_t proto,
+ const hicn_face_id_t *next_hop, int nh_len,
+ index_t *dpo_idx)
{
hicn_strategy_mw_ctx_t *hicn_strategy_mw_ctx;
hicn_dpo_ctx_t *hicn_strategy_ctx;
@@ -120,8 +107,22 @@ hicn_strategy_mw_ctx_create (fib_protocol_t proto, const hicn_face_id_t * next_h
*dpo_idx = hicn_strategy_dpo_ctx_get_index (hicn_strategy_ctx);
- init_dpo_ctx (hicn_strategy_ctx, next_hop, nh_len, hicn_dpo_type_mw, proto);
+ HICN_DEBUG ("Successful hicn_strategy_dpo_ctx_alloc with index %d",
+ *dpo_idx);
+
+ init_dpo_ctx (hicn_strategy_ctx, next_hop, nh_len, hicn_dpo_type_mw,
+ (dpo_proto_t) proto);
+
+ memset (hicn_strategy_mw_ctx->weight, 0, HICN_PARAM_FIB_ENTRY_NHOPS_MAX);
+}
+
+void
+hicn_strategy_mw_update_ctx_type (hicn_dpo_ctx_t *hicn_strategy_ctx)
+{
+ hicn_strategy_mw_ctx_t *hicn_strategy_mw_ctx;
+ hicn_strategy_mw_ctx = (hicn_strategy_mw_ctx_t *) hicn_strategy_ctx->data;
+ hicn_strategy_ctx->dpo_type = hicn_dpo_type_mw;
memset (hicn_strategy_mw_ctx->weight, 0, HICN_PARAM_FIB_ENTRY_NHOPS_MAX);
}
@@ -138,7 +139,7 @@ hicn_strategy_mw_ctx_add_nh (hicn_face_id_t nh, index_t dpo_idx)
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_t *) &hicn_strategy_dpo_ctx->data;
hicn_strategy_mw_ctx->weight[pos] = DEFAULT_WEIGHT;
return HICN_ERROR_NONE;
@@ -148,7 +149,8 @@ int
hicn_strategy_mw_ctx_del_nh (hicn_face_id_t face_id, index_t dpo_idx)
{
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;
+ // 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);
}