diff options
Diffstat (limited to 'hicn-plugin')
-rw-r--r-- | hicn-plugin/CMakeLists.txt | 6 | ||||
-rw-r--r-- | hicn-plugin/README.md | 2 | ||||
-rw-r--r-- | hicn-plugin/cmake/Modules/Packaging.cmake | 2 | ||||
-rw-r--r-- | hicn-plugin/src/data_fwd.h | 46 | ||||
-rw-r--r-- | hicn-plugin/src/data_fwd_node.c | 13 | ||||
-rw-r--r-- | hicn-plugin/src/error.h | 2 | ||||
-rw-r--r-- | hicn-plugin/src/faces/ip/face_ip_node.c | 37 | ||||
-rw-r--r-- | hicn-plugin/src/faces/udp/dpo_udp.h | 61 | ||||
-rw-r--r-- | hicn-plugin/src/faces/udp/face_udp.h | 104 | ||||
-rw-r--r-- | hicn-plugin/src/faces/udp/face_udp_node.c | 49 | ||||
-rw-r--r-- | hicn-plugin/src/interest_hitcs_node.c | 4 | ||||
-rw-r--r-- | hicn-plugin/src/pg.c | 8 | ||||
-rw-r--r-- | hicn-plugin/src/strategies/dpo_rr.c | 312 | ||||
-rw-r--r-- | hicn-plugin/src/strategies/dpo_rr.h | 135 | ||||
-rw-r--r-- | hicn-plugin/src/strategies/strategy_mw.c | 6 | ||||
-rw-r--r-- | hicn-plugin/src/strategies/strategy_mw_cli.c | 2 | ||||
-rw-r--r-- | hicn-plugin/src/strategies/strategy_rr.c | 169 | ||||
-rw-r--r-- | hicn-plugin/src/strategies/strategy_rr.h | 31 | ||||
-rw-r--r-- | hicn-plugin/src/strategy_dpo_manager.c | 2 |
19 files changed, 873 insertions, 118 deletions
diff --git a/hicn-plugin/CMakeLists.txt b/hicn-plugin/CMakeLists.txt index 1cd6f0411..be71b36a3 100644 --- a/hicn-plugin/CMakeLists.txt +++ b/hicn-plugin/CMakeLists.txt @@ -113,6 +113,8 @@ set(HICN_PLUGIN_SOURCE_FILES src/strategies/dpo_mw.c src/strategies/strategy_mw.c src/strategies/strategy_mw_cli.c + src/strategies/dpo_rr.c + src/strategies/strategy_rr.c src/cache_policies/cs_lru.c src/mapme_ack_node.c src/mapme_ctrl_node.c @@ -158,6 +160,8 @@ set(HICN_PLUGIN_HEADER_FILES src/pg.h src/strategies/dpo_mw.h src/strategies/strategy_mw.h + src/strategies/dpo_rr.h + src/strategies/strategy_rr.h src/cache_policies/cs_policy.h src/cache_policies/cs_lru.h src/mapme.h @@ -275,4 +279,4 @@ install(FILES ${HICN_API_TEST_HEADER_FILES} ${HICN_API_GENERATED_FILES} install(FILES ${HICN_VAPI_GENERATED_FILES} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/vapi - COMPONENT ${HICN_PLUGIN})
\ No newline at end of file + COMPONENT ${HICN_PLUGIN}) diff --git a/hicn-plugin/README.md b/hicn-plugin/README.md index e0e0580de..22e38a015 100644 --- a/hicn-plugin/README.md +++ b/hicn-plugin/README.md @@ -65,7 +65,7 @@ hICN-plugin has been tested in: Build dependencies: -- VPP 19.01 +- VPP 19.04 - DEB packages: - vpp - vpp-lib diff --git a/hicn-plugin/cmake/Modules/Packaging.cmake b/hicn-plugin/cmake/Modules/Packaging.cmake index 00ac3422f..8cace744b 100644 --- a/hicn-plugin/cmake/Modules/Packaging.cmake +++ b/hicn-plugin/cmake/Modules/Packaging.cmake @@ -21,7 +21,7 @@ set(${HICN_PLUGIN}_DESCRIPTION ) set(${HICN_PLUGIN}_DEB_DEPENDENCIES - "vpp (>= stable_version-release), vpp (<< next_version-release), vpp-plugins (>= stable_version-release), vpp-plugins (<< next_version-release)" + "vpp (>= stable_version-release), vpp (<< next_version-release), vpp-plugin-core (>= stable_version-release), vpp-plugin-core (<< next_version-release)" CACHE STRING "Dependencies for deb/rpm package." ) diff --git a/hicn-plugin/src/data_fwd.h b/hicn-plugin/src/data_fwd.h index 4e37e6087..c001e5af5 100644 --- a/hicn-plugin/src/data_fwd.h +++ b/hicn-plugin/src/data_fwd.h @@ -20,17 +20,6 @@ #include "pcs.h" -/* - * Node context data; we think this is per-thread/instance - */ -typedef struct hicn_data_fwd_runtime_s -{ - vlib_combined_counter_main_t repm_counters; - - /* per-cpu vector of cloned packets */ - u32 **clones; -} hicn_data_fwd_runtime_t; - /* Trace context struct */ typedef struct { @@ -86,9 +75,8 @@ vlib_buffer_clone_256_2 (vlib_main_t * vm, u32 src_buffer, u32 * buffers, } return n_buffers; } - n_buffers = vlib_buffer_alloc_from_free_list (vm, buffers, n_buffers, - vlib_buffer_get_free_list_index - (s)); + n_buffers = vlib_buffer_alloc_from_pool (vm, buffers, n_buffers, + s->buffer_pool_index); for (i = 0; i < n_buffers; i++) { @@ -96,8 +84,6 @@ vlib_buffer_clone_256_2 (vlib_main_t * vm, u32 src_buffer, u32 * buffers, d->current_data = s->current_data; d->current_length = head_end_offset; d->trace_index = s->trace_index; - vlib_buffer_set_free_list_index (d, - vlib_buffer_get_free_list_index (s)); d->total_length_not_including_first_buffer = s->current_length - head_end_offset; @@ -109,18 +95,18 @@ vlib_buffer_clone_256_2 (vlib_main_t * vm, u32 src_buffer, u32 * buffers, d->flags = s->flags | VLIB_BUFFER_NEXT_PRESENT; d->flags &= ~VLIB_BUFFER_EXT_HDR_VALID; d->trace_index = s->trace_index; - clib_memcpy (d->opaque, s->opaque, sizeof (s->opaque)); - clib_memcpy (d->opaque2, s->opaque2, sizeof (s->opaque2)); - clib_memcpy (vlib_buffer_get_current (d), vlib_buffer_get_current (s), - head_end_offset); + clib_memcpy_fast (d->opaque, s->opaque, sizeof (s->opaque)); + clib_memcpy_fast (d->opaque2, s->opaque2, sizeof (s->opaque2)); + clib_memcpy_fast (vlib_buffer_get_current (d), + vlib_buffer_get_current (s), head_end_offset); d->next_buffer = src_buffer; } vlib_buffer_advance (s, head_end_offset); - s->n_add_refs = n_buffers - 1; + s->ref_count = n_buffers; while (s->flags & VLIB_BUFFER_NEXT_PRESENT) { s = vlib_get_buffer (vm, s->next_buffer); - s->n_add_refs = n_buffers - 1; + s->ref_count = n_buffers; } return n_buffers; @@ -129,7 +115,7 @@ vlib_buffer_clone_256_2 (vlib_main_t * vm, u32 src_buffer, u32 * buffers, /** * @brief Create multiple clones of buffer and store them * in the supplied array. Unlike the function in the vlib library, - * we allow src_buffer to have n_add_refs != 0. + * we allow src_buffer to have ref_count != 0. * * @param vm - (vlib_main_t *) vlib main data structure pointer * @param src_buffer - (u32) source buffer index @@ -154,13 +140,13 @@ vlib_buffer_clone2 (vlib_main_t * vm, u32 src_buffer, u32 * buffers, s->total_length_not_including_first_buffer = 0; u16 n_cloned = 0; - u8 n_clone_src = 255 - s->n_add_refs; + u8 n_clone_src = 255 - s->ref_count; /* * We need to copy src for all the clones that cannot be chained in * the src_buffer */ - /* MAX(n_add_refs) = 256 */ + /* MAX(ref_count) = 256 */ if (n_buffers > n_clone_src) { vlib_buffer_t *copy; @@ -174,25 +160,25 @@ vlib_buffer_clone2 (vlib_main_t * vm, u32 src_buffer, u32 * buffers, n_buffers -= n_cloned; } /* - * vlib_buffer_clone_256 check if n_add_refs is 0. We force it to be + * vlib_buffer_clone_256 check if ref_count is 0. We force it to be * 0 before calling the function and we retore it to the right value * after the function has been called */ - u8 tmp_n_add_refs = s->n_add_refs; + u8 tmp_ref_count = s->ref_count; - s->n_add_refs = 0; + s->ref_count = 1; /* * The regular vlib_buffer_clone_256 does copy if we need to clone * only one packet. While this is not a problem per se, it adds * complexity to the code, especially because we need to add 1 to - * n_add_refs when the packet is cloned. + * ref_count when the packet is cloned. */ n_cloned += vlib_buffer_clone_256_2 (vm, src_buffer, (buffers + n_cloned), n_buffers, head_end_offset); - s->n_add_refs += tmp_n_add_refs; + s->ref_count += (tmp_ref_count - 1); return n_cloned; } diff --git a/hicn-plugin/src/data_fwd_node.c b/hicn-plugin/src/data_fwd_node.c index efb98164d..fe4155958 100644 --- a/hicn-plugin/src/data_fwd_node.c +++ b/hicn-plugin/src/data_fwd_node.c @@ -271,7 +271,7 @@ hicn_data_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, * longer in any frame. The vlib_buffer will be freed when * all its cloned vlib_buffer will be freed. */ - b0->n_add_refs--; + b0->ref_count--; } /* Delete the PIT entry */ @@ -294,7 +294,7 @@ hicn_data_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, * longer in any frame. The vlib_buffer will be freed when * all its cloned vlib_buffer will be freed. */ - b0->n_add_refs--; + b0->ref_count--; } /* Delete the PIT entry */ @@ -389,6 +389,7 @@ hicn_satisfy_faces (vlib_main_t * vm, u32 bi0, vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0); hicn_buffer_t *hicnb = hicn_get_buffer (b0); + /* * Mark the buffer as smaller than TWO_CL. It will be stored as is in the CS, without excluding * the hicn_header. Cloning is not possible, it will be copied. @@ -403,12 +404,12 @@ hicn_satisfy_faces (vlib_main_t * vm, u32 bi0, else { /* Add one reference to maintain the buffer in the CS. - * b0->n_add_refs == 0 has two meaning: it has 1 buffer or no buffer chained to it. + * b0->ref_count == 0 has two meaning: it has 1 buffer or no buffer chained to it. * vlib_buffer_clone2 add a number of reference equalt to pitp->u.pit.faces.n_faces - 1 * as vlib_buffer_clone does. So after all the packet are forwarded the buffer stored in - * the CS will have n_add_refs == 0; + * the CS will have ref_count == 0; */ - b0->n_add_refs++; + b0->ref_count++; } found = n_left_from = @@ -546,7 +547,6 @@ hicn_satisfy_faces (vlib_main_t * vm, u32 bi0, } } - vec_free (header); if (PREDICT_FALSE (!found)) @@ -621,7 +621,6 @@ VLIB_REGISTER_NODE(hicn_data_fwd_node) = .function = hicn_data_node_fn, .name = "hicn-data-fwd", .vector_size = sizeof(u32), - .runtime_data_bytes = sizeof(hicn_data_fwd_runtime_t), .format_trace = hicn_data_fwd_format_trace, .type = VLIB_NODE_TYPE_INTERNAL, .n_errors = ARRAY_LEN(hicn_data_fwd_error_strings), diff --git a/hicn-plugin/src/error.h b/hicn-plugin/src/error.h index 978c7f2ca..0abcce96c 100644 --- a/hicn-plugin/src/error.h +++ b/hicn-plugin/src/error.h @@ -74,7 +74,7 @@ _(APPFACE_FEATURE, -181, "Error while enabling app face feature") \ _(APPFACE_NOT_FOUND, -182, "Application face not found") \ _(APPFACE_PROD_PREFIX_NULL, -183, "Prefix must not be null for producer face") \ - _(MW_STRATEGY_NH_NOT_FOUND, -184, "Next hop not found") \ + _(STRATEGY_NH_NOT_FOUND, -184, "Next hop not found") \ _(MW_STRATEGY_SET, -185, "Error while setting weight for next hop") \ _(STRATEGY_NOT_FOUND, -186, "Strategy not found") diff --git a/hicn-plugin/src/faces/ip/face_ip_node.c b/hicn-plugin/src/faces/ip/face_ip_node.c index 8d0820604..109750de8 100644 --- a/hicn-plugin/src/faces/ip/face_ip_node.c +++ b/hicn-plugin/src/faces/ip/face_ip_node.c @@ -463,12 +463,10 @@ VLIB_REGISTER_NODE(hicn_face_ip6_input_node) = static inline void hicn_face_rewrite_interest (vlib_main_t * vm, vlib_buffer_t * b0, - const hicn_face_t * face, u32 * next) + hicn_face_t * face, u32 * next) { ip_adjacency_t *adj = adj_get (face->shared.adj); - /* We assume the ip adjacency has already the MAC/link layer address */ - vnet_buffer (b0)->ip.adj_index[VLIB_TX] = face->shared.adj; hicn_header_t *hicn = vlib_buffer_get_current (b0); hicn_face_ip_t *ip_face = (hicn_face_ip_t *) face->data; @@ -479,14 +477,33 @@ hicn_face_rewrite_interest (vlib_main_t * vm, vlib_buffer_t * b0, hicn_ops_vft[type.l1]->rewrite_interest (type, &hicn->protocol, &ip_face->local_addr, &temp_addr); - /* We rewrite the dst address to send an arp/neighbour discovert request */ - if (PREDICT_FALSE - (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP - || adj->lookup_next_index == IP_LOOKUP_NEXT_GLEAN)) - hicn_ops_vft[type.l1]->rewrite_data (type, &hicn->protocol, - &ip_face->remote_addr, &temp_addr, - 0); + /* In case the adj is not complete, we look if a better one exists, otherwise we send an arp request + * This is necessary to account for the case in which when we create a face, there isn't a /128(/32) adjacency and we match with a more general route which is in glean state + * In this case in fact, the general route will not be update upone receiving of a arp or neighbour responde, but a new /128(/32) will be created + */ + if (PREDICT_FALSE (adj->lookup_next_index < IP_LOOKUP_NEXT_REWRITE)) + { + fib_prefix_t fib_pfx; + fib_node_index_t fib_entry_index; + fib_prefix_from_ip46_addr (&ip_face->remote_addr, &fib_pfx); + fib_pfx.fp_len = 128; + + u32 fib_index = fib_table_find_or_create_and_lock (fib_pfx.fp_proto, + HICN_FIB_TABLE, + FIB_SOURCE_PLUGIN_HI); + + fib_entry_index = fib_table_lookup (fib_index, &fib_pfx); + + face->shared.adj = fib_entry_get_adj (fib_entry_index); + adj = adj_get (face->shared.adj); + + hicn_ops_vft[type.l1]->rewrite_data (type, &hicn->protocol, + &ip_face->remote_addr, &temp_addr, + 0); + } + + vnet_buffer (b0)->ip.adj_index[VLIB_TX] = face->shared.adj; *next = adj->lookup_next_index; } diff --git a/hicn-plugin/src/faces/udp/dpo_udp.h b/hicn-plugin/src/faces/udp/dpo_udp.h index 3d74a1884..42b9864df 100644 --- a/hicn-plugin/src/faces/udp/dpo_udp.h +++ b/hicn-plugin/src/faces/udp/dpo_udp.h @@ -127,33 +127,10 @@ hicn_dpo_udp4_add_and_lock (dpo_id_t * dpo, if (face == NULL) { - pool_get (hicn_dpoi_face_pool, face); - hicn_face_udp_t *udp_face = (hicn_face_udp_t *) face->data; - - clib_memcpy (&(udp_face->hdrs.ip4.ip), &ip4_header_skl, - sizeof (ip4_header_t)); - clib_memcpy (&(udp_face->hdrs.ip4.ip.src_address), local_addr, - sizeof (ip4_address_t)); - clib_memcpy (&(udp_face->hdrs.ip4.ip.dst_address), remote_addr, - sizeof (ip4_address_t)); - - udp_face->hdrs.ip4.udp.src_port = local_port; - udp_face->hdrs.ip4.udp.dst_port = remote_port; - - face->shared.adj = ADJ_INDEX_INVALID; - face->shared.pl_id = (u16) 0; - face->shared.face_type = hicn_face_udp_type; - face->shared.flags = HICN_FACE_FLAGS_IFACE; - face->shared.locks = 0; - face->shared.sw_if = sw_if; - - hicn_face_udp_key_t key; - hicn_face_udp4_get_key (local_addr, remote_addr, local_port, - remote_port, &key); - hicn_face_id_t dpoi_index = hicn_dpoi_get_index (face); - - mhash_set_mem (&hicn_face_udp_hashtb, &key, (uword *) & dpoi_index, 0); + hicn_face_id_t dpoi_index; + hicn_iface_udp4_add (local_addr, remote_addr, local_port, remote_port, + sw_if, &dpoi_index); *hicnb_flags = HICN_BUFFER_FLAGS_DEFAULT; dpo_set (dpo, hicn_face_udp_type, DPO_PROTO_IP4, dpoi_index); @@ -230,7 +207,7 @@ hicn_dpo_udp6_lock (dpo_id_t * dpo, return HICN_ERROR_FACE_NOT_FOUND; hicn_face_id_t dpoi_index = hicn_dpoi_get_index (face); - dpo_set (dpo, hicn_face_udp_type, DPO_PROTO_IP4, dpoi_index); + dpo_set (dpo, hicn_face_udp_type, DPO_PROTO_IP6, dpoi_index); dpo->dpoi_next_node = ~0; dpo_lock (dpo); *hicnb_flags = HICN_BUFFER_FLAGS_DEFAULT; @@ -269,33 +246,9 @@ hicn_dpo_udp6_add_and_lock (dpo_id_t * dpo, if (face == NULL) { - pool_get (hicn_dpoi_face_pool, face); - - hicn_face_udp_t *udp_face = (hicn_face_udp_t *) face->data; - - clib_memcpy (&(udp_face->hdrs.ip6.ip), &ip6_header_skl, - sizeof (ip6_header_t)); - clib_memcpy (&(udp_face->hdrs.ip6.ip.src_address), local_addr, - sizeof (ip6_address_t)); - clib_memcpy (&(udp_face->hdrs.ip6.ip.dst_address), remote_addr, - sizeof (ip6_address_t)); - - udp_face->hdrs.ip6.udp.src_port = local_port; - udp_face->hdrs.ip6.udp.dst_port = remote_port; - - face->shared.adj = ADJ_INDEX_INVALID; - face->shared.pl_id = (u16) 0; - face->shared.face_type = hicn_face_udp_type; - face->shared.flags = HICN_FACE_FLAGS_IFACE; - face->shared.locks = 0; - face->shared.sw_if = sw_if; - - hicn_face_udp_key_t key; - hicn_face_udp6_get_key (local_addr, remote_addr, local_port, - remote_port, &key); - hicn_face_id_t dpoi_index = hicn_dpoi_get_index (face); - - mhash_set_mem (&hicn_face_udp_hashtb, &key, (uword *) & dpoi_index, 0); + hicn_face_id_t dpoi_index; + hicn_iface_udp6_add (local_addr, remote_addr, local_port, remote_port, + sw_if, &dpoi_index); *hicnb_flags = HICN_BUFFER_FLAGS_DEFAULT; dpo_set (dpo, hicn_face_udp_type, DPO_PROTO_IP6, dpoi_index); diff --git a/hicn-plugin/src/faces/udp/face_udp.h b/hicn-plugin/src/faces/udp/face_udp.h index 8694bad5c..2bd420b55 100644 --- a/hicn-plugin/src/faces/udp/face_udp.h +++ b/hicn-plugin/src/faces/udp/face_udp.h @@ -207,6 +207,110 @@ int hicn_face_udp_add (const ip46_address_t * local_addr, u16 remote_port, u32 swif, hicn_face_id_t * pfaceid); /** + * @brief Create a new incomplete face udp. (Meant to be used by the data plane) + * + * @param local_addr Local ip v6 address of the face + * @param remote_addr Remote ip v6 address of the face + * @param sw_if interface associated to the face + * @param pfaceid Pointer to return the face id + * @return HICN_ERROR_FACE_NO_GLOBAL_IP if the face does not have a globally + * reachable ip address, otherwise HICN_ERROR_NONE + */ +always_inline void +hicn_iface_udp6_add (const ip6_address_t * local_addr, + const ip6_address_t * remote_addr, u16 local_port, + u16 remote_port, int sw_if, hicn_face_id_t * pfaceid) +{ + hicn_face_t *face; + pool_get (hicn_dpoi_face_pool, face); + + hicn_face_udp_t *udp_face = (hicn_face_udp_t *) face->data; + + clib_memcpy (&(udp_face->hdrs.ip6.ip), &ip6_header_skl, + sizeof (ip6_header_t)); + clib_memcpy (&(udp_face->hdrs.ip6.ip.src_address), local_addr, + sizeof (ip6_address_t)); + clib_memcpy (&(udp_face->hdrs.ip6.ip.dst_address), remote_addr, + sizeof (ip6_address_t)); + + udp_face->hdrs.ip6.udp.src_port = local_port; + udp_face->hdrs.ip6.udp.dst_port = remote_port; + + face->shared.adj = ADJ_INDEX_INVALID; + face->shared.pl_id = (u16) 0; + face->shared.face_type = hicn_face_udp_type; + face->shared.flags = HICN_FACE_FLAGS_IFACE; + face->shared.locks = 0; + face->shared.sw_if = sw_if; + + hicn_face_udp_key_t key; + hicn_face_udp6_get_key (local_addr, remote_addr, local_port, + remote_port, &key); + *pfaceid = hicn_dpoi_get_index (face); + + mhash_set_mem (&hicn_face_udp_hashtb, &key, (uword *) & pfaceid, 0); + + for (int i = 0; i < HICN_N_COUNTER; i++) + { + vlib_validate_combined_counter (&counters[(*pfaceid) * HICN_N_COUNTER], + i); + vlib_zero_combined_counter (&counters[(*pfaceid) * HICN_N_COUNTER], i); + } +} + +/** + * @brief Create a new incomplete face udp. (Meant to be used by the data plane) + * + * @param local_addr Local ip v4 address of the face + * @param remote_addr Remote ip v4 address of the face + * @param sw_if interface associated to the face + * @param pfaceid Pointer to return the face id + * @return HICN_ERROR_FACE_NO_GLOBAL_IP if the face does not have a globally + * reachable ip address, otherwise HICN_ERROR_NONE + */ +always_inline void +hicn_iface_udp4_add (const ip4_address_t * local_addr, + const ip4_address_t * remote_addr, u16 local_port, + u16 remote_port, int sw_if, hicn_face_id_t * pfaceid) +{ + hicn_face_t *face; + pool_get (hicn_dpoi_face_pool, face); + + hicn_face_udp_t *udp_face = (hicn_face_udp_t *) face->data; + + clib_memcpy (&(udp_face->hdrs.ip4.ip), &ip4_header_skl, + sizeof (ip4_header_t)); + clib_memcpy (&(udp_face->hdrs.ip4.ip.src_address), local_addr, + sizeof (ip4_address_t)); + clib_memcpy (&(udp_face->hdrs.ip4.ip.dst_address), remote_addr, + sizeof (ip4_address_t)); + + udp_face->hdrs.ip4.udp.src_port = local_port; + udp_face->hdrs.ip4.udp.dst_port = remote_port; + + face->shared.adj = ADJ_INDEX_INVALID; + face->shared.pl_id = (u16) 0; + face->shared.face_type = hicn_face_udp_type; + face->shared.flags = HICN_FACE_FLAGS_IFACE; + face->shared.locks = 0; + face->shared.sw_if = sw_if; + + hicn_face_udp_key_t key; + hicn_face_udp4_get_key (local_addr, remote_addr, local_port, + remote_port, &key); + *pfaceid = hicn_dpoi_get_index (face); + + mhash_set_mem (&hicn_face_udp_hashtb, &key, (uword *) & pfaceid, 0); + + for (int i = 0; i < HICN_N_COUNTER; i++) + { + vlib_validate_combined_counter (&counters[(*pfaceid) * HICN_N_COUNTER], + i); + vlib_zero_combined_counter (&counters[(*pfaceid) * HICN_N_COUNTER], i); + } +} + +/** * @brief Delete an ip face * * @param face_id Id of the face to delete diff --git a/hicn-plugin/src/faces/udp/face_udp_node.c b/hicn-plugin/src/faces/udp/face_udp_node.c index df24c477f..184fea679 100644 --- a/hicn-plugin/src/faces/udp/face_udp_node.c +++ b/hicn-plugin/src/faces/udp/face_udp_node.c @@ -535,8 +535,31 @@ hicn_face_udp4_encap (vlib_main_t * vm, length /* changed member */ ); ip0->checksum = sum0; - vnet_buffer (outer_b0)->ip.adj_index[VLIB_TX] = face->shared.adj; + /* In case the adj is not complete, we look if a better one exists, otherwise we send an arp request + * This is necessary to account for the case in which when we create a face, there isn't a /128(/32) adjacency and we match with a more general route which is in glean state + * In this case in fact, the general route will not be update upone receiving of a arp or neighbour responde, but a new /128(/32) will be created + */ + if (PREDICT_FALSE (adj->lookup_next_index < IP_LOOKUP_NEXT_REWRITE)) + { + fib_prefix_t fib_pfx; + fib_node_index_t fib_entry_index; + ip46_address_t ip46 = + to_ip46 (0, (u8 *) & (face_udp->hdrs.ip4.ip.dst_address)); + fib_prefix_from_ip46_addr (&ip46, &fib_pfx); + fib_pfx.fp_len = 32; + + u32 fib_index = fib_table_find_or_create_and_lock (fib_pfx.fp_proto, + HICN_FIB_TABLE, + FIB_SOURCE_PLUGIN_HI); + + fib_entry_index = fib_table_lookup (fib_index, &fib_pfx); + face->shared.adj = fib_entry_get_adj (fib_entry_index); + + adj = adj_get (face->shared.adj); + } + + vnet_buffer (outer_b0)->ip.adj_index[VLIB_TX] = face->shared.adj; *next = adj->lookup_next_index; } @@ -572,6 +595,30 @@ hicn_face_udp6_encap (vlib_main_t * vm, if (udp0->checksum == 0) udp0->checksum = 0xffff; + /* In case the adj is not complete, we look if a better one exists, otherwise we send an arp request + * This is necessary to account for the case in which when we create a face, there isn't a /128(/32) adjacency and we match with a more general route which is in glean state + * In this case in fact, the general route will not be update upone receiving of a arp or neighbour responde, but a new /128(/32) will be created + */ + if (PREDICT_FALSE (adj->lookup_next_index < IP_LOOKUP_NEXT_REWRITE)) + { + fib_prefix_t fib_pfx; + fib_node_index_t fib_entry_index; + ip46_address_t ip46 = + to_ip46 (1, (u8 *) & (face_udp->hdrs.ip6.ip.dst_address)); + fib_prefix_from_ip46_addr (&ip46, &fib_pfx); + fib_pfx.fp_len = 128; + + u32 fib_index = fib_table_find_or_create_and_lock (fib_pfx.fp_proto, + HICN_FIB_TABLE, + FIB_SOURCE_PLUGIN_HI); + + fib_entry_index = fib_table_lookup (fib_index, &fib_pfx); + + face->shared.adj = fib_entry_get_adj (fib_entry_index); + + adj = adj_get (face->shared.adj); + } + vnet_buffer (outer_b0)->ip.adj_index[VLIB_TX] = face->shared.adj; *next = adj->lookup_next_index; diff --git a/hicn-plugin/src/interest_hitcs_node.c b/hicn-plugin/src/interest_hitcs_node.c index 8ddd4f59e..aad7ed74e 100644 --- a/hicn-plugin/src/interest_hitcs_node.c +++ b/hicn-plugin/src/interest_hitcs_node.c @@ -60,12 +60,12 @@ clone_from_cs (vlib_main_t * vm, u32 * bi0_cs, vlib_buffer_t * dest, u8 isv6) else { vlib_buffer_advance (cs_buf, -buffer_advance); - if (PREDICT_FALSE (cs_buf->n_add_refs == 255)) + if (PREDICT_FALSE (cs_buf->ref_count == 255)) { vlib_buffer_t *cs_buf2 = vlib_buffer_copy (vm, cs_buf); vlib_buffer_advance (cs_buf, buffer_advance); *bi0_cs = vlib_get_buffer_index (vm, cs_buf2); - cs_buf->n_add_refs--; + cs_buf->ref_count--; cs_buf = cs_buf2; } diff --git a/hicn-plugin/src/pg.c b/hicn-plugin/src/pg.c index 643aff2be..8181d865e 100644 --- a/hicn-plugin/src/pg.c +++ b/hicn-plugin/src/pg.c @@ -1056,9 +1056,7 @@ convert_interest_to_data_v4 (vlib_main_t * vm, vlib_buffer_t * b0, bytes_to_copy = 1500 - pkt_len; } /* Add content to the data packet */ - vlib_buffer_add_data (vm, - VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX, &bi0, - rb->data, bytes_to_copy); + vlib_buffer_add_data (vm, &bi0, rb->data, bytes_to_copy); b0 = vlib_get_buffer (vm, bi0); @@ -1094,9 +1092,7 @@ convert_interest_to_data_v6 (vlib_main_t * vm, vlib_buffer_t * b0, bytes_to_copy = 1500 - pkt_len; } /* Add content to the data packet */ - vlib_buffer_add_data (vm, - VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX, &bi0, - rb->data, bytes_to_copy); + vlib_buffer_add_data (vm, &bi0, rb->data, bytes_to_copy); b0 = vlib_get_buffer (vm, bi0); diff --git a/hicn-plugin/src/strategies/dpo_rr.c b/hicn-plugin/src/strategies/dpo_rr.c new file mode 100644 index 000000000..c9ec50445 --- /dev/null +++ b/hicn-plugin/src/strategies/dpo_rr.c @@ -0,0 +1,312 @@ +/* + * 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_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, +}; + +/** + * @brief DPO type value for the rr_strategy + */ +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 +}; + +int +hicn_dpo_is_type_strategy_rr (const dpo_id_t * dpo) +{ + return dpo->dpoi_type == hicn_dpo_type_rr; +} + +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_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) +{ + return hicn_dpo_type_rr; +} + +////////////////////////////////////////////////////////////////////////////////////////////////// + +void +hicn_strategy_rr_ctx_lock (dpo_id_t * dpo) +{ + if (dpo->dpoi_index != 0) + { + hicn_strategy_rr_ctx_t *hicn_strategy_rr_ctx = + (hicn_strategy_rr_ctx_t *) hicn_strategy_rr_ctx_get (dpo->dpoi_index); + hicn_strategy_rr_ctx->default_ctx.locks++; + } +} + +void +hicn_strategy_rr_ctx_unlock (dpo_id_t * dpo) +{ + if (dpo->dpoi_index != 0) + { + hicn_strategy_rr_ctx_t *hicn_strategy_rr_ctx = + (hicn_strategy_rr_ctx_t *) hicn_strategy_rr_ctx_get (dpo->dpoi_index); + 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); + } + } +} + +u8 * +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; + dpo_id_t *next_hop = NULL; + hicn_face_vft_t *face_vft = NULL; + u32 indent = va_arg (*ap, u32);; + + dpo = (hicn_strategy_rr_ctx_t *) hicn_strategy_rr_ctx_get (index); + + s = + format (s, "hicn-rr, next hop Face %d", + dpo->default_ctx.next_hops[dpo->current_nhop].dpoi_index); + 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); + } + } + + 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 +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; + dpo_id_t invalid = NEXT_HOP_INVALID; + + /* Allocate a hicn_dpo_ctx on the vpp pool and initialize it */ + pool_get (hicn_strategy_rr_ctx_pool, hicn_strategy_rr_ctx); + + *dpo_idx = hicn_strategy_rr_ctx_get_index (hicn_strategy_rr_ctx); + for (int i = 0; i < HICN_PARAM_FIB_ENTRY_NHOPS_MAX; i++) + { + hicn_strategy_rr_ctx->default_ctx.next_hops[i] = invalid; + } + + hicn_strategy_rr_ctx->default_ctx.entry_count = 0; + hicn_strategy_rr_ctx->default_ctx.locks = 0; + + 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++; + } + + 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_strategy_rr_ctx->default_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); + + if (hicn_strategy_rr_ctx != NULL) + { + + 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; + } + if (PREDICT_FALSE (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++; + + return HICN_ERROR_NONE; + } + return HICN_ERROR_DPO_CTX_NOT_FOUND; +} + +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_t *hicn_strategy_rr_ctx = + (hicn_strategy_rr_ctx_t *) hicn_strategy_rr_ctx_get (dpo_idx); + int ret = HICN_ERROR_NONE; + int nh_id = ~0; + dpo_id_t invalid = NEXT_HOP_INVALID; + + if (hicn_strategy_rr_ctx != NULL) + { + 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) + { + nh_id = i; + hicn_face_unlock (&hicn_strategy_rr_ctx->default_ctx. + next_hops[i]); + hicn_strategy_rr_ctx->default_ctx.next_hops[i] = invalid; + hicn_strategy_rr_ctx->default_ctx.entry_count--; + } + } + + if (0 == hicn_strategy_rr_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_rr_ctx->default_ctx.entry_count > 0 && nh_id != ~0 + && nh_id < hicn_strategy_rr_ctx->default_ctx.entry_count - 1) + { + int i; + for (i = nh_id; i < hicn_strategy_rr_ctx->default_ctx.entry_count; i++) + { + clib_memcpy (&hicn_strategy_rr_ctx->default_ctx.next_hops[i], + &hicn_strategy_rr_ctx->default_ctx.next_hops[i + 1], + sizeof (dpo_id_t)); + } + /* Set as invalid the last dpo */ + hicn_strategy_rr_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_rr.h b/hicn-plugin/src/strategies/dpo_rr.h new file mode 100644 index 000000000..a12183653 --- /dev/null +++ b/hicn-plugin/src/strategies/dpo_rr.h @@ -0,0 +1,135 @@ +/* + * 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_RR_H__ +#define __HICN_DPO_RR_H__ + +#include <vnet/dpo/dpo.h> +#include "../strategy_dpo_ctx.h" + +/** + * Context for the Round Robin strategy + */ + +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 + * @param ap List of parameters for the formatting + * + * @result The string with the formatted dpo ctx + */ +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_format = format_hicn_strategy_rr_ctx, +}; + +/** + * @brief Retrieve an hicn_strategy_rr_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_rr_ctx_get (index_t index); + +/** + * @brief Create a new round robin 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_rr_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_rr_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_rr_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_rr_ctx_prefetch (index_t dpo_idx); + +int hicn_dpo_is_type_strategy_rr (const dpo_id_t * dpo); + +void hicn_dpo_strategy_rr_module_init (void); + +dpo_type_t hicn_dpo_strategy_rr_get_type (void); + +u8 *format_hicn_dpo_strategy_rr (u8 * s, va_list * ap); + + +#endif // __HICN_DPO_RR_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 index 77a7d16a8..3efddc0ce 100644 --- a/hicn-plugin/src/strategies/strategy_mw.c +++ b/hicn-plugin/src/strategies/strategy_mw.c @@ -88,11 +88,11 @@ 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])) - return HICN_ERROR_MW_STRATEGY_NH_NOT_FOUND; + return HICN_ERROR_STRATEGY_NH_NOT_FOUND; *outface = - (dpo_id_t *) & hicn_strategy_mw_ctx-> - default_ctx.next_hops[next_hop_index]; + (dpo_id_t *) & hicn_strategy_mw_ctx->default_ctx. + next_hops[next_hop_index]; return HICN_ERROR_NONE; } diff --git a/hicn-plugin/src/strategies/strategy_mw_cli.c b/hicn-plugin/src/strategies/strategy_mw_cli.c index ff4125258..689bce470 100644 --- a/hicn-plugin/src/strategies/strategy_mw_cli.c +++ b/hicn-plugin/src/strategies/strategy_mw_cli.c @@ -111,7 +111,7 @@ hicn_mw_strategy_cli_set_weight_command_fn (vlib_main_t * vm, cl_err = clib_error_return (0, get_error_string - (HICN_ERROR_MW_STRATEGY_NH_NOT_FOUND)); + (HICN_ERROR_STRATEGY_NH_NOT_FOUND)); goto done; } diff --git a/hicn-plugin/src/strategies/strategy_rr.c b/hicn-plugin/src/strategies/strategy_rr.c new file mode 100644 index 000000000..53b9b688f --- /dev/null +++ b/hicn-plugin/src/strategies/strategy_rr.c @@ -0,0 +1,169 @@ +/* + * 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_rr.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_rr (index_t dpo_idx, int nh_idx); +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); + +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 _ +}; + +/* + * Return the vft of the strategy. + */ +hicn_strategy_vft_t * +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_strategy_rr_ctx_t *hicn_strategy_rr_ctx = + (hicn_strategy_rr_ctx_t *) hicn_strategy_rr_ctx_get (dpo_idx); + + if (dpo_id_is_valid + (&hicn_strategy_rr_ctx->default_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]; + + } + 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; + + 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); + 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 */ +} + +void +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) +{ + 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) = +{ + .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* */ + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/hicn-plugin/src/strategies/strategy_rr.h b/hicn-plugin/src/strategies/strategy_rr.h new file mode 100644 index 000000000..84149c36f --- /dev/null +++ b/hicn-plugin/src/strategies/strategy_rr.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_RR_H__ +#define __HICN_STRATEGY_RR_H__ + +#include "../strategy.h" + +hicn_strategy_vft_t *hicn_rr_strategy_get_vft (void); + +#endif // __HICN_STRATEGY_RR_H__ + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/hicn-plugin/src/strategy_dpo_manager.c b/hicn-plugin/src/strategy_dpo_manager.c index c1723eccc..470d8d185 100644 --- a/hicn-plugin/src/strategy_dpo_manager.c +++ b/hicn-plugin/src/strategy_dpo_manager.c @@ -17,6 +17,7 @@ #include "strategy_dpo_manager.h" #include "strategies/dpo_mw.h" +#include "strategies/dpo_rr.h" #include "strategy.h" #include "faces/face.h" @@ -94,6 +95,7 @@ void hicn_dpos_init (void) { 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; |