diff options
author | Alberto Compagno <acompagn+fdio@cisco.com> | 2020-04-07 11:43:39 +0200 |
---|---|---|
committer | Alberto Compagno <acompagn+fdio@cisco.com> | 2020-05-04 11:16:59 +0200 |
commit | c61e2e149421b849888bea0239c50607edce35ac (patch) | |
tree | f1191d338c9e27c77484c0d8bed6118c6d4612b6 | |
parent | dee66271e7f84cb756dae31d154982d5b6bb9807 (diff) |
[HICN-590] Removed andjacency type specific face implementation
Changes in the new implementation are:
- the adjacency index is replaced with a dpo that allows the single face node
to dispatch the packet to the right vlib node.
- local and remote address in the face are replaced with a single nat address
which is used to perform the nat operation when rewriting an interest or a
data (in case of tunnels the nat address will be equal to 0)
- the list of next hop in the load balance is no longer a list of dpos but
a list of face id (this makes the code easier and increases the number of
next hop we supports)
Signed-off-by: Alberto Compagno <acompagn+fdio@cisco.com>
Change-Id: I4ac2b4eb09425bfe1b3ca9f82d7d0ff564297b0d
65 files changed, 2021 insertions, 7077 deletions
diff --git a/ctrl/libhicnctrl/src/hicn_plugin_api.c b/ctrl/libhicnctrl/src/hicn_plugin_api.c index 406f43404..63509312a 100644 --- a/ctrl/libhicnctrl/src/hicn_plugin_api.c +++ b/ctrl/libhicnctrl/src/hicn_plugin_api.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: @@ -94,10 +94,6 @@ struct hc_sock_s { _(hicn_api_node_params_set_reply) \ _(hicn_api_node_params_get_reply) \ _(hicn_api_node_stats_get_reply) \ - _(hicn_api_face_add) \ - _(hicn_api_face_add_reply) \ - _(hicn_api_face_del) \ - _(hicn_api_face_del_reply) \ _(hicn_api_face_get) \ _(hicn_api_faces_details) \ _(hicn_api_face_stats_details) \ @@ -115,6 +111,7 @@ struct hc_sock_s { _(hicn_api_strategy_get) \ _(hicn_api_strategy_get_reply) + typedef vapi_type_msg_header2_t hc_msg_header_t; typedef union { @@ -881,277 +878,282 @@ int hc_connection_to_local_listener(const hc_connection_t *connection, } /* FACE CREATE */ -vapi_error_e parse_face_create( vapi_ctx_t ctx, - void *callback_ctx, - vapi_error_e rv, - bool is_last, - vapi_payload_hicn_api_face_add_reply *reply) { +// vapi_error_e parse_face_create( vapi_ctx_t ctx, +// void *callback_ctx, +// vapi_error_e rv, +// bool is_last, +// vapi_payload_hicn_api_face_add_reply *reply) { - if (reply == NULL || rv != VAPI_OK) - return rv; +// if (reply == NULL || rv != VAPI_OK) +// return rv; - if (reply->retval != VAPI_OK) - return reply->retval; +// if (reply->retval != VAPI_OK) +// return reply->retval; - hc_data_t *data = (hc_data_t *)callback_ctx; +// hc_data_t *data = (hc_data_t *)callback_ctx; - hc_face_t *output = (hc_face_t *)data->buffer; +// hc_face_t *output = (hc_face_t *)data->buffer; - output->id = reply->faceid; - return reply->retval; -} +// output->id = reply->faceid; +// return reply->retval; +// } int hc_face_create(hc_sock_t *s, hc_face_t *face) { - vapi_lock(); - vapi_msg_hicn_api_face_add *hicnp_msg; - hicnp_msg = vapi_alloc_hicn_api_face_add(s->g_vapi_ctx_instance); - - int retval = VAPI_OK; - if (!hicnp_msg) { - retval = VAPI_ENOMEM; - goto END; - } - - switch(face->face.type) { - case FACE_TYPE_HICN: - { - u8 check = ip46_address_is_ip4((ip46_address_t *)&(face->face.local_addr)) == ip46_address_is_ip4((ip46_address_t *)&(face->face.remote_addr)); - if (!check) { - retval = -1; - goto END; - } - - hicnp_msg->payload.type = IP_FACE; - if (ip46_address_is_ip4((ip46_address_t *)&(face->face.local_addr))) - { - memcpy(hicnp_msg->payload.face.ip.local_addr.un.ip4, face->face.local_addr.v4.as_u8, 4); - memcpy(hicnp_msg->payload.face.ip.remote_addr.un.ip4, face->face.remote_addr.v4.as_u8, 4); - hicnp_msg->payload.face.ip.local_addr.af = ADDRESS_IP4; - hicnp_msg->payload.face.ip.remote_addr.af = ADDRESS_IP4; - } - else - { - memcpy(hicnp_msg->payload.face.ip.local_addr.un.ip6, face->face.local_addr.v6.as_u8, 16); - memcpy(hicnp_msg->payload.face.ip.remote_addr.un.ip6, face->face.remote_addr.v6.as_u8, 16); - hicnp_msg->payload.face.ip.local_addr.af = ADDRESS_IP6; - hicnp_msg->payload.face.ip.remote_addr.af = ADDRESS_IP6; - } - hicnp_msg->payload.face.ip.swif = face->face.netdevice.index; - memcpy(hicnp_msg->payload.face.ip.if_name, face->face.netdevice.name, IFNAMSIZ); - break; - } - case FACE_TYPE_UDP: - { - u8 check = ip46_address_is_ip4((ip46_address_t *)&(face->face.local_addr)) == ip46_address_is_ip4((ip46_address_t *)&(face->face.remote_addr)); - if (!check) { - retval = -1; - goto END; - } - - hicnp_msg->payload.type = UDP_FACE; - if (ip46_address_is_ip4((ip46_address_t *)&(face->face.local_addr))) - { - memcpy(hicnp_msg->payload.face.udp.local_addr.un.ip4, face->face.local_addr.v4.as_u8, 4); - memcpy(hicnp_msg->payload.face.udp.remote_addr.un.ip4, face->face.remote_addr.v4.as_u8, 4); - hicnp_msg->payload.face.udp.local_addr.af = ADDRESS_IP4; - hicnp_msg->payload.face.udp.remote_addr.af = ADDRESS_IP4; - } - else - { - memcpy(hicnp_msg->payload.face.udp.local_addr.un.ip6, face->face.local_addr.v6.as_u8, 16); - memcpy(hicnp_msg->payload.face.udp.remote_addr.un.ip6, face->face.remote_addr.v6.as_u8, 16); - hicnp_msg->payload.face.udp.local_addr.af = ADDRESS_IP6; - hicnp_msg->payload.face.udp.remote_addr.af = ADDRESS_IP6; - } - hicnp_msg->payload.face.udp.lport = face->face.local_port; - hicnp_msg->payload.face.udp.rport = face->face.remote_port; - hicnp_msg->payload.face.udp.swif = face->face.netdevice.index; - memcpy(hicnp_msg->payload.face.udp.if_name, face->face.netdevice.name, IFNAMSIZ); - break; - } - default: - { - retval = -1; - goto END; - } - } - - hc_data_t *data = hc_data_create(0, sizeof(hc_face_t),NULL); - - if (!data) { - retval = -1; - goto END; - } - - data->buffer = malloc(sizeof(hc_face_t)); - data->out_element_size = sizeof(hc_face_t); - - if (!data->buffer) { - free (data); - retval = -1; - goto END; - } - - retval = vapi_hicn_api_face_add(s->g_vapi_ctx_instance, hicnp_msg, parse_face_create, data); - - if (retval != VAPI_OK) - goto END; - - face->id = ((hc_face_t *)data->buffer)->id; - - END: - vapi_unlock(); - return retval; + // vapi_lock(); + // vapi_msg_hicn_api_face_add *hicnp_msg; + // hicnp_msg = vapi_alloc_hicn_api_face_add(s->g_vapi_ctx_instance); + + // int retval = VAPI_OK; +// if (!hicnp_msg) { +// retval = VAPI_ENOMEM; +// goto END; +// } + +// switch(face->face.type) { +// case FACE_TYPE_HICN: +// { +// u8 check = ip46_address_is_ip4((ip46_address_t *)&(face->face.local_addr)) == ip46_address_is_ip4((ip46_address_t *)&(face->face.remote_addr)); +// if (!check) { +// retval = -1; +// goto END; +// } + +// hicnp_msg->payload.type = IP_FACE; +// if (ip46_address_is_ip4((ip46_address_t *)&(face->face.local_addr))) +// { +// memcpy(hicnp_msg->payload.face.ip.local_addr.un.ip4, face->face.local_addr.v4.as_u8, 4); +// memcpy(hicnp_msg->payload.face.ip.remote_addr.un.ip4, face->face.remote_addr.v4.as_u8, 4); +// hicnp_msg->payload.face.ip.local_addr.af = ADDRESS_IP4; +// hicnp_msg->payload.face.ip.remote_addr.af = ADDRESS_IP4; +// } +// else +// { +// memcpy(hicnp_msg->payload.face.ip.local_addr.un.ip6, face->face.local_addr.v6.as_u8, 16); +// memcpy(hicnp_msg->payload.face.ip.remote_addr.un.ip6, face->face.remote_addr.v6.as_u8, 16); +// hicnp_msg->payload.face.ip.local_addr.af = ADDRESS_IP6; +// hicnp_msg->payload.face.ip.remote_addr.af = ADDRESS_IP6; +// } +// hicnp_msg->payload.face.ip.swif = face->face.netdevice.index; +// memcpy(hicnp_msg->payload.face.ip.if_name, face->face.netdevice.name, IFNAMSIZ); +// break; +// } +// case FACE_TYPE_UDP: +// { +// u8 check = ip46_address_is_ip4((ip46_address_t *)&(face->face.local_addr)) == ip46_address_is_ip4((ip46_address_t *)&(face->face.remote_addr)); +// if (!check) { +// retval = -1; +// goto END; +// } + +// hicnp_msg->payload.type = UDP_FACE; +// if (ip46_address_is_ip4((ip46_address_t *)&(face->face.local_addr))) +// { +// memcpy(hicnp_msg->payload.face.udp.local_addr.un.ip4, face->face.local_addr.v4.as_u8, 4); +// memcpy(hicnp_msg->payload.face.udp.remote_addr.un.ip4, face->face.remote_addr.v4.as_u8, 4); +// hicnp_msg->payload.face.udp.local_addr.af = ADDRESS_IP4; +// hicnp_msg->payload.face.udp.remote_addr.af = ADDRESS_IP4; +// } +// else +// { +// memcpy(hicnp_msg->payload.face.udp.local_addr.un.ip6, face->face.local_addr.v6.as_u8, 16); +// memcpy(hicnp_msg->payload.face.udp.remote_addr.un.ip6, face->face.remote_addr.v6.as_u8, 16); +// hicnp_msg->payload.face.udp.local_addr.af = ADDRESS_IP6; +// hicnp_msg->payload.face.udp.remote_addr.af = ADDRESS_IP6; +// } +// hicnp_msg->payload.face.udp.lport = face->face.local_port; +// hicnp_msg->payload.face.udp.rport = face->face.remote_port; +// hicnp_msg->payload.face.udp.swif = face->face.netdevice.index; +// memcpy(hicnp_msg->payload.face.udp.if_name, face->face.netdevice.name, IFNAMSIZ); +// break; +// } +// default: +// { +// retval = -1; +// goto END; +// } +// } + +// hc_data_t *data = hc_data_create(0, sizeof(hc_face_t),NULL); + +// if (!data) { +// retval = -1; +// goto END; +// } + +// data->buffer = malloc(sizeof(hc_face_t)); +// data->out_element_size = sizeof(hc_face_t); + +// if (!data->buffer) { +// free (data); +// retval = -1; +// goto END; +// } + +// retval = vapi_hicn_api_face_add(s->g_vapi_ctx_instance, hicnp_msg, parse_face_create, data); + +// if (retval != VAPI_OK) +// goto END; + +// face->id = ((hc_face_t *)data->buffer)->id; + +// END: +// vapi_unlock(); + ERROR("hc_punting_snprintf not (yet) implemented."); + return -1; } -vapi_error_e parse_face_delete( vapi_ctx_t ctx, - void *callback_ctx, - vapi_error_e rv, - bool is_last, - vapi_payload_hicn_api_face_del_reply *reply) { +// vapi_error_e parse_face_delete( vapi_ctx_t ctx, +// void *callback_ctx, +// vapi_error_e rv, +// bool is_last, +// vapi_payload_hicn_api_face_del_reply *reply) { - if (reply == NULL || rv != VAPI_OK) - return rv; +// if (reply == NULL || rv != VAPI_OK) +// return rv; - return reply->retval; -} +// return reply->retval; +// } int hc_face_delete(hc_sock_t *s, hc_face_t *face) { - vapi_msg_hicn_api_face_del *hicnp_msg; - vapi_lock(); - hicnp_msg = vapi_alloc_hicn_api_face_del(s->g_vapi_ctx_instance); + // vapi_msg_hicn_api_face_del *hicnp_msg; + // vapi_lock(); + // hicnp_msg = vapi_alloc_hicn_api_face_del(s->g_vapi_ctx_instance); - if (!hicnp_msg) return VAPI_ENOMEM; + // if (!hicnp_msg) return VAPI_ENOMEM; - hicnp_msg->payload.faceid = face->id; + // hicnp_msg->payload.faceid = face->id; - int retval = vapi_hicn_api_face_del(s->g_vapi_ctx_instance, hicnp_msg, parse_face_delete, NULL); - vapi_unlock(); - return retval; + // int retval = vapi_hicn_api_face_del(s->g_vapi_ctx_instance, hicnp_msg, parse_face_delete, NULL); + // vapi_unlock(); + // return retval; + ERROR("hc_punting_snprintf not (yet) implemented."); + return -1; } /* FACE LIST */ -vapi_error_e parse_face_list( vapi_ctx_t ctx, - void *callback_ctx, - vapi_error_e rv, - bool is_last, - vapi_payload_hicn_api_faces_details *reply) { - - if (reply == NULL || rv != VAPI_OK) - return rv; - - if (reply->retval != VAPI_OK) - return reply->retval; - - hc_data_t *data = (hc_data_t *)callback_ctx; - - if (data->size == data->current) { - int new_size = data->size *2; - data->buffer = realloc(data->buffer, sizeof(hc_face_t) * (new_size)); - if (!data->buffer) - return VAPI_ENOMEM; - - data->size =new_size; - } - - int retval = VAPI_OK; - - hc_face_t * face = &((hc_face_t *)(data->buffer))[data->current]; - switch(reply->type) - { - case IP_FACE: - { - if (reply->face.ip.local_addr.af == ADDRESS_IP4) - { - memcpy(face->face.local_addr.v4.as_u8, reply->face.ip.local_addr.un.ip4, IPV4_ADDR_LEN); - memcpy(face->face.remote_addr.v4.as_u8, reply->face.ip.remote_addr.un.ip4, IPV4_ADDR_LEN); - } - else - { - memcpy(face->face.local_addr.v6.as_u8, reply->face.ip.local_addr.un.ip6, IPV6_ADDR_LEN); - memcpy(face->face.remote_addr.v6.as_u8, reply->face.ip.remote_addr.un.ip6, IPV6_ADDR_LEN); - } - face->face.type = FACE_TYPE_HICN; - face->id = reply->faceid; - face->face.netdevice.index = reply->face.ip.swif; - memcpy(face->face.netdevice.name, reply->face.ip.if_name, IFNAMSIZ); - break; - } - case UDP_FACE: - { - if (reply->face.ip.local_addr.af == ADDRESS_IP4) - { - memcpy(face->face.local_addr.v4.as_u8, reply->face.udp.local_addr.un.ip4, IPV4_ADDR_LEN); - memcpy(face->face.remote_addr.v4.as_u8, reply->face.udp.remote_addr.un.ip4, IPV4_ADDR_LEN); - } - else - { - memcpy(face->face.local_addr.v6.as_u8, reply->face.udp.local_addr.un.ip6, IPV6_ADDR_LEN); - memcpy(face->face.remote_addr.v6.as_u8, reply->face.udp.remote_addr.un.ip6, IPV6_ADDR_LEN); - } - face->face.local_port = reply->face.udp.lport; - face->face.remote_port = reply->face.udp.rport; - face->face.type = FACE_TYPE_UDP; - face->id = reply->faceid; - face->face.netdevice.index = reply->face.udp.swif; - memcpy(face->face.netdevice.name, reply->face.udp.if_name, IFNAMSIZ); - break; - } - default: - retval = -1; - } - if (!retval) - data->current++; - - return reply->retval; -} +// vapi_error_e parse_face_list( vapi_ctx_t ctx, +// void *callback_ctx, +// vapi_error_e rv, +// bool is_last, +// vapi_payload_hicn_api_faces_details *reply) { + +// if (reply == NULL || rv != VAPI_OK) +// return rv; + +// if (reply->retval != VAPI_OK) +// return reply->retval; + +// hc_data_t *data = (hc_data_t *)callback_ctx; + +// if (data->size == data->current) { +// int new_size = data->size *2; +// data->buffer = realloc(data->buffer, sizeof(hc_face_t) * (new_size)); +// if (!data->buffer) +// return VAPI_ENOMEM; + +// data->size =new_size; +// } + +// int retval = VAPI_OK; + +// hc_face_t * face = &((hc_face_t *)(data->buffer))[data->current]; +// switch(reply->type) +// { +// case IP_FACE: +// { +// if (reply->face.ip.local_addr.af == ADDRESS_IP4) +// { +// memcpy(face->face.local_addr.v4.as_u8, reply->face.ip.local_addr.un.ip4, IPV4_ADDR_LEN); +// memcpy(face->face.remote_addr.v4.as_u8, reply->face.ip.remote_addr.un.ip4, IPV4_ADDR_LEN); +// } +// else +// { +// memcpy(face->face.local_addr.v6.as_u8, reply->face.ip.local_addr.un.ip6, IPV6_ADDR_LEN); +// memcpy(face->face.remote_addr.v6.as_u8, reply->face.ip.remote_addr.un.ip6, IPV6_ADDR_LEN); +// } +// face->face.type = FACE_TYPE_HICN; +// face->id = reply->faceid; +// face->face.netdevice.index = reply->face.ip.swif; +// memcpy(face->face.netdevice.name, reply->face.ip.if_name, IFNAMSIZ); +// break; +// } +// case UDP_FACE: +// { +// if (reply->face.ip.local_addr.af == ADDRESS_IP4) +// { +// memcpy(face->face.local_addr.v4.as_u8, reply->face.udp.local_addr.un.ip4, IPV4_ADDR_LEN); +// memcpy(face->face.remote_addr.v4.as_u8, reply->face.udp.remote_addr.un.ip4, IPV4_ADDR_LEN); +// } +// else +// { +// memcpy(face->face.local_addr.v6.as_u8, reply->face.udp.local_addr.un.ip6, IPV6_ADDR_LEN); +// memcpy(face->face.remote_addr.v6.as_u8, reply->face.udp.remote_addr.un.ip6, IPV6_ADDR_LEN); +// } +// face->face.local_port = reply->face.udp.lport; +// face->face.remote_port = reply->face.udp.rport; +// face->face.type = FACE_TYPE_UDP; +// face->id = reply->faceid; +// face->face.netdevice.index = reply->face.udp.swif; +// memcpy(face->face.netdevice.name, reply->face.udp.if_name, IFNAMSIZ); +// break; +// } +// default: +// retval = -1; +// } +// if (!retval) +// data->current++; + +// return reply->retval; +// } int hc_face_list(hc_sock_t *s, hc_data_t **pdata) { - vapi_lock(); - vapi_msg_hicn_api_faces_dump *hicnp_msg; - hicnp_msg = vapi_alloc_hicn_api_faces_dump(s->g_vapi_ctx_instance); - - int retval = 0; - if (!hicnp_msg) { - retval = VAPI_ENOMEM; - goto END; - } - - hc_data_t *data = hc_data_create(0, sizeof(hc_face_t),NULL); - - if (!data) { - retval = -1; - goto END; - } - - data->buffer = malloc(sizeof(hc_face_t)); - data->size = 1; - - if (!data->buffer) { - free (data); - retval = -1; - goto err; - } - - - retval = vapi_hicn_api_faces_dump(s->g_vapi_ctx_instance, hicnp_msg, parse_face_list, data); - *pdata = data; - - if (retval != VAPI_OK) - goto err; - - data->size = data->current; - vapi_unlock(); - return retval; - - err: - free(data); - END: - vapi_unlock(); - return retval; +// vapi_lock(); +// vapi_msg_hicn_api_faces_dump *hicnp_msg; +// hicnp_msg = vapi_alloc_hicn_api_faces_dump(s->g_vapi_ctx_instance); + +// int retval = 0; +// if (!hicnp_msg) { +// retval = VAPI_ENOMEM; +// goto END; +// } + +// hc_data_t *data = hc_data_create(0, sizeof(hc_face_t),NULL); + +// if (!data) { +// retval = -1; +// goto END; +// } + +// data->buffer = malloc(sizeof(hc_face_t)); +// data->size = 1; + +// if (!data->buffer) { +// free (data); +// retval = -1; +// goto err; +// } + + +// retval = vapi_hicn_api_faces_dump(s->g_vapi_ctx_instance, hicnp_msg, parse_face_list, data); +// *pdata = data; + +// if (retval != VAPI_OK) +// goto err; + +// data->size = data->current; +// vapi_unlock(); +// return retval; + +// err: +// free(data); +// END: +// vapi_unlock(); +// return retval; +ERROR("hc_punting_snprintf not (yet) implemented."); +return -1; } int hc_connection_parse_to_face(void *in, hc_face_t *face) { return 0; } diff --git a/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/hicn_model.c b/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/hicn_model.c index 2a486f599..0e0a9104b 100644 --- a/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/hicn_model.c +++ b/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/hicn_model.c @@ -162,11 +162,11 @@ if(!reply->retval){ return VAPI_EUSER; } -static vapi_error_e call_hicn_api_face_ip_params_get(struct vapi_ctx_s *ctx, +static vapi_error_e call_hicn_api_face_params_get(struct vapi_ctx_s *ctx, void *callback_ctx, vapi_error_e rv, bool is_last, - vapi_payload_hicn_api_face_ip_params_get_reply *reply){ + vapi_payload_hicn_api_face_params_get_reply *reply){ if(!reply->retval){ if (callback_ctx!=NULL){ struct hicn_faces_s * tmp; @@ -190,32 +190,6 @@ if(!reply->retval){ return VAPI_EUSER; } -static vapi_error_e call_hicn_api_face_ip_del(struct vapi_ctx_s *ctx, - void *callback_ctx, - vapi_error_e rv, - bool is_last, - vapi_payload_hicn_api_face_ip_del_reply *reply){ -if(!reply->retval){ - SRP_LOG_DBGMSG("Successfully done"); - return VAPI_OK; - }else - return VAPI_EUSER; -} - - -static vapi_error_e call_hicn_api_face_ip_add(struct vapi_ctx_s *ctx, - void *callback_ctx, - vapi_error_e rv, - bool is_last, - vapi_payload_hicn_api_face_ip_add_reply *reply){ -if(!reply->retval){ - SRP_LOG_DBGMSG("Successfully done"); - return VAPI_OK; - }else - return VAPI_EUSER; - -} - static vapi_error_e call_vapi_hicn_api_node_stats_get(struct vapi_ctx_s *ctx, void *callback_ctx, vapi_error_e rv, @@ -411,13 +385,13 @@ static inline int faces_update(sr_val_t * vals, uint32_t nleaves, struct lyd_no for(int count=0; count<nleaves; count++){ - vapi_msg_hicn_api_face_ip_params_get *msg; - msg = vapi_alloc_hicn_api_face_ip_params_get(g_vapi_ctx_instance); + vapi_msg_hicn_api_face_params_get *msg; + msg = vapi_alloc_hicn_api_face_params_get(g_vapi_ctx_instance); msg->payload.faceid = temp->face.faceid; - if(vapi_hicn_api_face_ip_params_get(g_vapi_ctx_instance,msg,call_hicn_api_face_ip_params_get, (void *)temp)!=VAPI_OK){ + if(vapi_hicn_api_face_params_get(g_vapi_ctx_instance,msg,call_hicn_api_face_params_get, (void *)temp)!=VAPI_OK){ SRP_LOG_DBGMSG("Operation failed"); return SR_ERR_OPERATION_FAILED; } @@ -711,17 +685,17 @@ if(vapi_hicn_api_route_del(g_vapi_ctx_instance,msg,call_hicn_api_route_del,NULL) return SR_ERR_OK; } -static int hicn_face_ip_params_get_cb(sr_session_ctx_t *session, const char *path, const sr_val_t *input, const size_t input_cnt, +static int hicn_face_params_get_cb(sr_session_ctx_t *session, const char *path, const sr_val_t *input, const size_t input_cnt, sr_event_t event, uint32_t request_id, sr_val_t **output, size_t *output_cnt, void *private_data) { SRP_LOG_DBGMSG("hicn face ip params get received successfully"); - vapi_msg_hicn_api_face_ip_params_get *msg; + vapi_msg_hicn_api_face_params_get *msg; - msg = vapi_alloc_hicn_api_face_ip_params_get(g_vapi_ctx_instance); + msg = vapi_alloc_hicn_api_face_params_get(g_vapi_ctx_instance); msg->payload.faceid = input[0].data.uint32_val; -if (vapi_hicn_api_face_ip_params_get(g_vapi_ctx_instance,msg,call_hicn_api_face_ip_params_get,NULL)!=VAPI_OK){ +if (vapi_hicn_api_face_params_get(g_vapi_ctx_instance,msg,call_hicn_api_face_params_get,NULL)!=VAPI_OK){ SRP_LOG_DBGMSG("Operation failed"); return SR_ERR_OPERATION_FAILED; } @@ -773,86 +747,6 @@ if (vapi_hicn_api_route_nhop_del(g_vapi_ctx_instance, msg, call_hicn_api_route_n return SR_ERR_OK; } -static int hicn_face_ip_del_cb(sr_session_ctx_t *session, const char *path, const sr_val_t *input, const size_t input_cnt, - sr_event_t event, uint32_t request_id, sr_val_t **output, size_t *output_cnt, void *private_data) { - - SRP_LOG_DBGMSG("hicn face ip del received successfully"); - // allocate memory msg - vapi_msg_hicn_api_face_ip_del *msg; - - msg = vapi_alloc_hicn_api_face_ip_del(g_vapi_ctx_instance); - msg->payload.faceid = input[0].data.uint32_val; - - -if(vapi_hicn_api_face_ip_del(g_vapi_ctx_instance,msg, call_hicn_api_face_ip_del,NULL)!=VAPI_OK){ - SRP_LOG_DBGMSG("Operation failed"); - return SR_ERR_OPERATION_FAILED; -} -return SR_ERR_OK; -} - - -static int hicn_face_ip_add_cb(sr_session_ctx_t *session, const char *path, const sr_val_t *input, const size_t input_cnt, - sr_event_t event, uint32_t request_id, sr_val_t **output, size_t *output_cnt, void *private_data) { - - SRP_LOG_DBGMSG("hicn face ip add received successfully"); - - - vapi_msg_hicn_api_face_ip_add *msg; - - msg = vapi_alloc_hicn_api_face_ip_add(g_vapi_ctx_instance); - if(strcmp(input[0].data.string_val,"-1")){ - struct sockaddr_in sa; - inet_pton(AF_INET, input[0].data.string_val, &(sa.sin_addr)); - unsigned char * tmp = (unsigned char *) &sa.sin_addr.s_addr; - memcpy(&msg->payload.face.local_addr.un.ip4[0],tmp,B32); - msg->payload.face.local_addr.af = ADDRESS_IP4; - - }else if(strcmp(input[1].data.string_val,"-1")){ - - void *dst = malloc(sizeof(struct in6_addr)); - inet_pton(AF_INET6, input[1].data.string_val, dst); - unsigned char * tmp = (unsigned char *) ((struct in6_addr *)dst)->s6_addr; - memcpy(&msg->payload.face.local_addr.un.ip6[0],tmp,B128); - msg->payload.face.local_addr.af = ADDRESS_IP6; - - }else{ - SRP_LOG_DBGMSG("Invalid local IP address"); - return SR_ERR_OPERATION_FAILED; - } - - if(strcmp(input[2].data.string_val,"-1")){ - - struct sockaddr_in sa; - inet_pton(AF_INET, input[2].data.string_val, &(sa.sin_addr)); - unsigned char * tmp = (unsigned char *)&sa.sin_addr.s_addr; - memcpy(&msg->payload.face.remote_addr.un.ip4[0],tmp,B32); - msg->payload.face.remote_addr.af = ADDRESS_IP4; - - - }else if(strcmp(input[3].data.string_val,"-1")){ - - void *dst = malloc(sizeof(struct in6_addr)); - inet_pton(AF_INET6, input[3].data.string_val, dst); - unsigned char * tmp =(unsigned char *) ((struct in6_addr *)dst)->s6_addr; - memcpy(&msg->payload.face.remote_addr.un.ip6[0],tmp,B128); - msg->payload.face.remote_addr.af = ADDRESS_IP6; - - }else{ - SRP_LOG_DBGMSG("Invalid local IP address"); - return SR_ERR_OPERATION_FAILED; - } - - msg->payload.face.swif = input[4].data.uint32_val; // This is the idx number of interface - - -if(vapi_hicn_api_face_ip_add(g_vapi_ctx_instance,msg,call_hicn_api_face_ip_add,NULL)!=VAPI_OK){ - SRP_LOG_DBGMSG("Operation failed"); - return SR_ERR_OPERATION_FAILED; -} -return SR_ERR_OK; -} - static vapi_error_e hicn_api_routes_dump_cb(struct vapi_ctx_s *ctx, void *callback_ctx, vapi_error_e rv, bool is_last, @@ -1073,28 +967,13 @@ int hicn_subscribe_events(sr_session_ctx_t *session, // face ip subscriptions - rc = sr_rpc_subscribe(session, "/hicn:face-ip-params-get", - hicn_face_ip_params_get_cb, session, 93,SR_SUBSCR_CTX_REUSE, subscription); + rc = sr_rpc_subscribe(session, "/hicn:face-params-get", + hicn_face_params_get_cb, session, 93,SR_SUBSCR_CTX_REUSE, subscription); if (rc != SR_ERR_OK) { SRP_LOG_DBGMSG("Problem in subscription face-ip-params-get\n"); goto error; } - - rc = sr_rpc_subscribe(session, "/hicn:face-ip-add", hicn_face_ip_add_cb, - session, 92,SR_SUBSCR_CTX_REUSE, subscription); - if (rc != SR_ERR_OK) { - SRP_LOG_DBGMSG("Problem in subscription face-ip-add\n"); - goto error; - } - - rc = sr_rpc_subscribe(session, "/hicn:face-ip-del", hicn_face_ip_del_cb, - session, 91,SR_SUBSCR_CTX_REUSE, subscription); - if (rc != SR_ERR_OK) { - SRP_LOG_DBGMSG("Problem in subscription face-ip-del\n"); - goto error; - } - // subscribe as hicn state data provider rc = sr_oper_get_items_subscribe(session, "hicn","/hicn:hicn-state/states", diff --git a/hicn-plugin/src/CMakeLists.txt b/hicn-plugin/src/CMakeLists.txt index 71980765d..2d8a2c385 100644 --- a/hicn-plugin/src/CMakeLists.txt +++ b/hicn-plugin/src/CMakeLists.txt @@ -1,4 +1,4 @@ -# 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: @@ -79,16 +79,9 @@ set(HICN_PLUGIN_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/error.c ${CMAKE_CURRENT_SOURCE_DIR}/faces/face_cli.c ${CMAKE_CURRENT_SOURCE_DIR}/faces/face.c - ${CMAKE_CURRENT_SOURCE_DIR}/faces/ip/face_ip.c - ${CMAKE_CURRENT_SOURCE_DIR}/faces/ip/face_ip_cli.c - ${CMAKE_CURRENT_SOURCE_DIR}/faces/ip/face_ip_node.c - ${CMAKE_CURRENT_SOURCE_DIR}/faces/ip/iface_ip_node.c - ${CMAKE_CURRENT_SOURCE_DIR}/faces/ip/dpo_ip.c - ${CMAKE_CURRENT_SOURCE_DIR}/faces/udp/face_udp.c - ${CMAKE_CURRENT_SOURCE_DIR}/faces/udp/face_udp_cli.c - ${CMAKE_CURRENT_SOURCE_DIR}/faces/udp/face_udp_node.c - ${CMAKE_CURRENT_SOURCE_DIR}/faces/udp/iface_udp_node.c - ${CMAKE_CURRENT_SOURCE_DIR}/faces/udp/dpo_udp.c + ${CMAKE_CURRENT_SOURCE_DIR}/faces/face_node.c + ${CMAKE_CURRENT_SOURCE_DIR}/faces/iface_node.c + ${CMAKE_CURRENT_SOURCE_DIR}/faces/dpo_face.h ${CMAKE_CURRENT_SOURCE_DIR}/faces/app/address_mgr.c ${CMAKE_CURRENT_SOURCE_DIR}/faces/app/face_cons.c ${CMAKE_CURRENT_SOURCE_DIR}/faces/app/face_prod.c @@ -101,9 +94,9 @@ set(HICN_PLUGIN_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/strategies/dpo_rr.c ${CMAKE_CURRENT_SOURCE_DIR}/strategies/strategy_rr.c ${CMAKE_CURRENT_SOURCE_DIR}/cache_policies/cs_lru.c - ${CMAKE_CURRENT_SOURCE_DIR}/mapme_ack_node.c - ${CMAKE_CURRENT_SOURCE_DIR}/mapme_ctrl_node.c - ${CMAKE_CURRENT_SOURCE_DIR}/mapme_eventmgr.c +# ${CMAKE_CURRENT_SOURCE_DIR}/mapme_ack_node.c +# ${CMAKE_CURRENT_SOURCE_DIR}/mapme_ctrl_node.c +# ${CMAKE_CURRENT_SOURCE_DIR}/mapme_eventmgr.c ) set(HICN_PLUGIN_HEADER_FILES @@ -130,14 +123,9 @@ set(HICN_PLUGIN_HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/error.h ${CMAKE_CURRENT_SOURCE_DIR}/face_db.h ${CMAKE_CURRENT_SOURCE_DIR}/faces/face.h - ${CMAKE_CURRENT_SOURCE_DIR}/faces/ip/face_ip.h - ${CMAKE_CURRENT_SOURCE_DIR}/faces/ip/face_ip_node.h - ${CMAKE_CURRENT_SOURCE_DIR}/faces/ip/iface_ip_node.h - ${CMAKE_CURRENT_SOURCE_DIR}/faces/ip/dpo_ip.h - ${CMAKE_CURRENT_SOURCE_DIR}/faces/udp/face_udp.h - ${CMAKE_CURRENT_SOURCE_DIR}/faces/udp/face_udp_node.h - ${CMAKE_CURRENT_SOURCE_DIR}/faces/udp/iface_udp_node.h - ${CMAKE_CURRENT_SOURCE_DIR}/faces/udp/dpo_udp.h + ${CMAKE_CURRENT_SOURCE_DIR}/faces/face_node.h + ${CMAKE_CURRENT_SOURCE_DIR}/faces/iface_node.h + ${CMAKE_CURRENT_SOURCE_DIR}/faces/face_dpo.h ${CMAKE_CURRENT_SOURCE_DIR}/faces/app/address_mgr.h ${CMAKE_CURRENT_SOURCE_DIR}/faces/app/face_cons.h ${CMAKE_CURRENT_SOURCE_DIR}/faces/app/face_prod.h @@ -148,10 +136,10 @@ set(HICN_PLUGIN_HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/strategies/strategy_rr.h ${CMAKE_CURRENT_SOURCE_DIR}/cache_policies/cs_policy.h ${CMAKE_CURRENT_SOURCE_DIR}/cache_policies/cs_lru.h - ${CMAKE_CURRENT_SOURCE_DIR}/mapme.h - ${CMAKE_CURRENT_SOURCE_DIR}/mapme_ack.h - ${CMAKE_CURRENT_SOURCE_DIR}/mapme_ctrl.h - ${CMAKE_CURRENT_SOURCE_DIR}/mapme_eventmgr.h + # ${CMAKE_CURRENT_SOURCE_DIR}/mapme.h + # ${CMAKE_CURRENT_SOURCE_DIR}/mapme_ack.h + # ${CMAKE_CURRENT_SOURCE_DIR}/mapme_ctrl.h + # ${CMAKE_CURRENT_SOURCE_DIR}/mapme_eventmgr.h ) set(HICN_API_TEST_SOURCE_FILES diff --git a/hicn-plugin/src/cli.c b/hicn-plugin/src/cli.c index 15ea90c96..9d9a6d949 100644 --- a/hicn-plugin/src/cli.c +++ b/hicn-plugin/src/cli.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: @@ -39,7 +39,6 @@ static vl_api_hicn_api_node_params_set_t node_ctl_params = { .pit_max_size = -1, .pit_max_lifetime_sec = -1.0f, .cs_max_size = -1, - .cs_reserved_app = -1, }; typedef enum @@ -62,8 +61,7 @@ hicn_cli_node_ctl_start_set_command_fn (vlib_main_t * vm, node_ctl_params.pit_max_size, node_ctl_params. pit_max_lifetime_sec, - node_ctl_params.cs_max_size, - node_ctl_params.cs_reserved_app); + node_ctl_params.cs_max_size); vlib_cli_output (vm, "hicn: fwdr initialize => %s\n", get_error_string (ret)); @@ -106,8 +104,7 @@ hicn_cli_node_ctl_stop_set_command_fn (vlib_main_t * vm, node_ctl_params.pit_max_size, node_ctl_params. pit_max_lifetime_sec, - node_ctl_params.cs_max_size, - node_ctl_params.cs_reserved_app); + node_ctl_params.cs_max_size); return (ret == HICN_ERROR_NONE) ? 0 : clib_error_return (0, get_error_string @@ -135,7 +132,6 @@ hicn_cli_node_ctl_param_set_command_fn (vlib_main_t * vm, int table_size; f64 lifetime; - int cs_reserved_app; if (hicn_main.is_enabled) { @@ -193,15 +189,6 @@ hicn_cli_node_ctl_param_set_command_fn (vlib_main_t * vm, } node_ctl_params.cs_max_size = table_size; } - else if (unformat (line_input, "app %d", &cs_reserved_app)) - { - if (!DFLTD_RANGE_OK (cs_reserved_app, 0, 100)) - { - rv = HICN_ERROR_CS_CONFIG_SIZE_OOB; - break; - } - node_ctl_params.cs_reserved_app = cs_reserved_app; - } else { rv = HICN_ERROR_CLI_INVAL; @@ -278,8 +265,7 @@ hicn_cli_show_command_fn (vlib_main_t * vm, unformat_input_t * main_input, { if (node_ctl_params.pit_max_size == -1 && node_ctl_params.pit_max_lifetime_sec == -1 && - node_ctl_params.cs_max_size == -1 && - node_ctl_params.cs_reserved_app == -1) + node_ctl_params.cs_max_size == -1) { ret = HICN_ERROR_FWD_NOT_ENABLED; goto done; @@ -302,11 +288,6 @@ hicn_cli_show_command_fn (vlib_main_t * vm, unformat_input_t * main_input, vlib_cli_output (vm, " CS:: max entries:%d\n", node_ctl_params.cs_max_size); } - if (node_ctl_params.cs_reserved_app != -1) - { - vlib_cli_output (vm, " CS:: reserved to app:%d\n", - node_ctl_params.cs_reserved_app); - } goto done; } /* Globals */ @@ -314,16 +295,11 @@ hicn_cli_show_command_fn (vlib_main_t * vm, unformat_input_t * main_input, "Forwarder: %sabled\n" " PIT:: max entries:%d," " lifetime default: max:%05.3f\n" - " CS:: max entries:%d, network entries:%d, app entries:%d (allocated %d, free %d)\n", + " CS:: max entries:%d\n", hicn_main.is_enabled ? "en" : "dis", hicn_infra_pit_size, ((f64) hicn_main.pit_lifetime_max_ms) / SEC_MS, - hicn_infra_cs_size, - hicn_infra_cs_size - hicn_main.pitcs.pcs_app_max, - hicn_main.pitcs.pcs_app_max, - hicn_main.pitcs.pcs_app_count, - hicn_main.pitcs.pcs_app_max - - hicn_main.pitcs.pcs_app_count); + hicn_infra_cs_size); vl_api_hicn_api_node_stats_get_reply_t rm = { 0, } , *rmp = &rm; diff --git a/hicn-plugin/src/data_fwd.h b/hicn-plugin/src/data_fwd.h index 55434a024..ad41e7e39 100644 --- a/hicn-plugin/src/data_fwd.h +++ b/hicn-plugin/src/data_fwd.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: @@ -34,6 +34,8 @@ typedef enum HICN_DATA_FWD_NEXT_V4_LOOKUP, HICN_DATA_FWD_NEXT_V6_LOOKUP, HICN_DATA_FWD_NEXT_PUSH, + HICN_DATA_FWD_NEXT_IFACE4_OUT, + HICN_DATA_FWD_NEXT_IFACE6_OUT, HICN_DATA_FWD_NEXT_ERROR_DROP, HICN_DATA_FWD_N_NEXT, } hicn_data_fwd_next_t; diff --git a/hicn-plugin/src/data_fwd_node.c b/hicn-plugin/src/data_fwd_node.c index 1bb064fcf..2737d1d62 100644 --- a/hicn-plugin/src/data_fwd_node.c +++ b/hicn-plugin/src/data_fwd_node.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: @@ -434,7 +434,7 @@ hicn_satisfy_faces (vlib_main_t * vm, u32 bi0, { vlib_buffer_t *h0, *h1; u32 hi0, hi1; - dpo_id_t *face0, *face1; + hicn_face_id_t face0, face1; /* Prefetch for next iteration. */ { @@ -458,10 +458,13 @@ hicn_satisfy_faces (vlib_main_t * vm, u32 bi0, n_left_from -= 2; clones += 2; - next0 = face0->dpoi_next_node; - next1 = face1->dpoi_next_node; - vnet_buffer (h0)->ip.adj_index[VLIB_TX] = face0->dpoi_index; - vnet_buffer (h1)->ip.adj_index[VLIB_TX] = face1->dpoi_index; + next0 = isv6 ? HICN_DATA_FWD_NEXT_IFACE6_OUT : + HICN_DATA_FWD_NEXT_IFACE4_OUT; + next1 = isv6 ? HICN_DATA_FWD_NEXT_IFACE6_OUT : + HICN_DATA_FWD_NEXT_IFACE4_OUT; + + vnet_buffer (h0)->ip.adj_index[VLIB_TX] = face0; + vnet_buffer (h1)->ip.adj_index[VLIB_TX] = face1; stats->pkts_data_count += 2; @@ -499,7 +502,7 @@ hicn_satisfy_faces (vlib_main_t * vm, u32 bi0, { vlib_buffer_t *h0; u32 hi0; - dpo_id_t *face0; + hicn_face_id_t face0; face0 = hicn_face_db_get_dpo_face (i++, &pitp->u.pit.faces); @@ -511,8 +514,9 @@ hicn_satisfy_faces (vlib_main_t * vm, u32 bi0, n_left_from -= 1; clones += 1; - next0 = face0->dpoi_next_node; - vnet_buffer (h0)->ip.adj_index[VLIB_TX] = face0->dpoi_index; + next0 = isv6 ? HICN_DATA_FWD_NEXT_IFACE6_OUT : + HICN_DATA_FWD_NEXT_IFACE4_OUT; + vnet_buffer (h0)->ip.adj_index[VLIB_TX] = face0; stats->pkts_data_count++; @@ -584,7 +588,7 @@ clone_data_to_cs (vlib_main_t * vm, hicn_pit_cs_t * pitcs, */ hicn_buffer_t *hicnb0 = hicn_get_buffer (b0); hicn_pit_to_cs (vm, pitcs, pitp, hash_entry, nodep, dpo_vft, hicn_dpo_id, - &hicnb->face_dpo_id, + hicnb->face_id, hicnb0->flags & HICN_BUFFER_FLAGS_FACE_IS_APP); pitp->shared.create_time = tnow; @@ -636,6 +640,8 @@ VLIB_REGISTER_NODE(hicn_data_fwd_node) = [HICN_DATA_FWD_NEXT_V4_LOOKUP] = "ip4-lookup", [HICN_DATA_FWD_NEXT_V6_LOOKUP] = "ip6-lookup", [HICN_DATA_FWD_NEXT_PUSH] = "hicn-data-push", + [HICN_DATA_FWD_NEXT_IFACE4_OUT] = "hicn4-iface-output", + [HICN_DATA_FWD_NEXT_IFACE6_OUT] = "hicn6-iface-output", [HICN_DATA_FWD_NEXT_ERROR_DROP] = "error-drop", }, }; diff --git a/hicn-plugin/src/data_push_node.c b/hicn-plugin/src/data_push_node.c index fc19362f9..18c4690b1 100644 --- a/hicn-plugin/src/data_push_node.c +++ b/hicn-plugin/src/data_push_node.c @@ -150,7 +150,7 @@ hicn_new_data (vlib_main_t * vm, hicn_data_push_runtime_t * rt, hicn_pcs_cs_insert_update (vm, rt->pitcs, pitp, nodep, &hash_entry, hicnb0->name_hash, &node_id0, &dpo_ctx_id0, &vft_id0, &is_cs0, &hash_entry_id, &bucket_id, - &bucket_is_overflow, &(hicnb0->face_dpo_id)); + &bucket_is_overflow, hicnb0->face_id); if (ret != HICN_ERROR_NONE) { diff --git a/hicn-plugin/src/face_db.h b/hicn-plugin/src/face_db.h index 17c28959a..9423c59d6 100644 --- a/hicn-plugin/src/face_db.h +++ b/hicn-plugin/src/face_db.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: @@ -28,7 +28,7 @@ */ /* Must be power of two */ -#define HICN_FACE_DB_INLINE_FACES 4 +#define HICN_FACE_DB_INLINE_FACES 8 #define HICN_PIT_BITMAP_SIZE_BYTE HICN_PARAM_FACES_MAX/8 #define HICN_PIT_N_HOP_BITMAP_SIZE HICN_PARAM_FACES_MAX @@ -38,7 +38,7 @@ typedef struct hicn_face_bucket_s { /* Array of indexes of virtual faces */ - dpo_id_t faces[HICN_PIT_N_HOP_BUCKET]; + hicn_face_id_t faces[HICN_PIT_N_HOP_BUCKET]; /* Used to check if interests are retransmission */ u8 bitmap[HICN_PIT_BITMAP_SIZE_BYTE]; @@ -60,7 +60,7 @@ typedef struct __attribute__ ((packed)) hicn_face_db_s /* 24B + 32B (8*4) = 56B */ /* Array of indexes of virtual faces */ - dpo_id_t inline_faces[HICN_FACE_DB_INLINE_FACES]; + hicn_face_id_t inline_faces[HICN_FACE_DB_INLINE_FACES]; /* 56B + 4B = 60B */ u32 next_bucket; @@ -71,13 +71,13 @@ typedef struct __attribute__ ((packed)) hicn_face_db_s } hicn_face_db_t; -always_inline dpo_id_t * +always_inline hicn_face_id_t hicn_face_db_get_dpo_face (u32 index, hicn_face_db_t * face_db) { ASSERT (index < face_db->n_faces); - return index < HICN_FACE_DB_INLINE_FACES ? &(face_db->inline_faces[index]) : - &(pool_elt_at_index (hicn_face_bucket_pool, face_db->next_bucket)->faces + return index < HICN_FACE_DB_INLINE_FACES ? (face_db->inline_faces[index]) : + (pool_elt_at_index (hicn_face_bucket_pool, face_db->next_bucket)->faces [(index - HICN_FACE_DB_INLINE_FACES) & (HICN_PIT_N_HOP_BUCKET - 1)]); } @@ -94,23 +94,23 @@ hicn_face_db_get_bucket (u32 bucket_index) } always_inline void -hicn_face_db_add_face_dpo (dpo_id_t * dpo, hicn_face_db_t * face_db) +hicn_face_db_add_face (hicn_face_id_t face_id, hicn_face_db_t * face_db) { - ASSERT (dpo->dpoi_index != ~0); + //ASSERT (dpo->dpoi_index != ~0); hicn_face_bucket_t *faces_bkt = pool_elt_at_index (hicn_face_bucket_pool, face_db->next_bucket); - dpo_id_t *face = + hicn_face_id_t *element = face_db->n_faces < HICN_FACE_DB_INLINE_FACES ? &(face_db->inline_faces[face_db->n_faces]) : &(faces_bkt->faces [(face_db->n_faces - HICN_FACE_DB_INLINE_FACES) & (HICN_PIT_N_HOP_BUCKET - 1)]); - clib_memcpy (face, dpo, sizeof (dpo_id_t)); + *element = face_id; - u32 bitmap_index = dpo->dpoi_index % HICN_PIT_N_HOP_BITMAP_SIZE; + u32 bitmap_index = face_id % HICN_PIT_N_HOP_BITMAP_SIZE; u32 position_array = bitmap_index / 8; u8 bit_index = (u8) (bitmap_index - position_array * 8); @@ -119,11 +119,11 @@ hicn_face_db_add_face_dpo (dpo_id_t * dpo, hicn_face_db_t * face_db) } always_inline u8 -hicn_face_search (dpo_id_t * dpo, hicn_face_db_t * face_db) +hicn_face_search (hicn_face_id_t index, hicn_face_db_t * face_db) { hicn_face_bucket_t *faces_bkt = pool_elt_at_index (hicn_face_bucket_pool, face_db->next_bucket); - u32 bitmap_index = dpo->dpoi_index % HICN_PIT_N_HOP_BITMAP_SIZE; + u32 bitmap_index = index % HICN_PIT_N_HOP_BITMAP_SIZE; u32 position_array = bitmap_index / 8; u8 bit_index = bitmap_index - position_array * 8; diff --git a/hicn-plugin/src/faces/app/address_mgr.c b/hicn-plugin/src/faces/app/address_mgr.c index 1674379c4..2d5894ab8 100644 --- a/hicn-plugin/src/faces/app/address_mgr.c +++ b/hicn-plugin/src/faces/app/address_mgr.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: @@ -36,7 +36,6 @@ #include "../../infra.h" #include "../../error.h" #include "../face.h" -#include "../ip/face_ip.h" #include "../../strategy_dpo_ctx.h" #include "../../route.h" @@ -134,26 +133,25 @@ get_two_ip6_addresses (ip6_address_t * appif_addr, ip6_address_t * nh_addr) fib_pfx.fp_proto = FIB_PROTOCOL_IP6; fib_pfx.fp_len = ADDR_MGR_IP6_LEN; + + fib_index = fib_table_find (fib_pfx.fp_proto, 0); + /* At this point the face exists in the face table */ do { /* Check if the route already exist in the fib */ fib_pfx.fp_addr = to_ip46 ( /* is_v6 */ 1, appif_addr->as_u8); - fib_index = fib_table_find_or_create_and_lock (fib_pfx.fp_proto, - HICN_FIB_TABLE, - FIB_SOURCE_PRIORITY_HI); + fib_entry_index = fib_table_lookup_exact_match (fib_index, &fib_pfx); - fib_table_unlock (fib_index, fib_pfx.fp_proto, FIB_SOURCE_PRIORITY_HI); + //fib_table_unlock (fib_index, fib_pfx.fp_proto, FIB_SOURCE_PRIORITY_HI); if (fib_entry_index != FIB_NODE_INDEX_INVALID) { fib_pfx.fp_addr = to_ip46 ( /* is_v6 */ 0, nh_addr->as_u8); - fib_index = fib_table_find_or_create_and_lock (fib_pfx.fp_proto, - HICN_FIB_TABLE, - FIB_SOURCE_PRIORITY_HI); + fib_entry_index = fib_table_lookup_exact_match (fib_index, &fib_pfx); - fib_table_unlock (fib_index, fib_pfx.fp_proto, - FIB_SOURCE_PRIORITY_HI); + // fib_table_unlock (fib_index, fib_pfx.fp_proto, + // FIB_SOURCE_PRIORITY_HI); } if (fib_entry_index != FIB_NODE_INDEX_INVALID) { diff --git a/hicn-plugin/src/faces/app/face_app_cli.c b/hicn-plugin/src/faces/app/face_app_cli.c index 1e8eb6a5b..1aa27adc7 100644 --- a/hicn-plugin/src/faces/app/face_app_cli.c +++ b/hicn-plugin/src/faces/app/face_app_cli.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: @@ -18,8 +18,7 @@ #include <vlib/vlib.h> #include <vnet/ip/ip6_packet.h> -#include "../ip/face_ip.h" -#include "../ip/dpo_ip.h" +//#include "../face_dpo.h" #include "../face.h" #include "face_prod.h" #include "face_cons.h" @@ -164,7 +163,7 @@ hicn_face_app_cli_set_command_fn (vlib_main_t * vm, { hicn_face_t *face = hicn_dpoi_get_from_idx (face_id1); - if (face->shared.flags & HICN_FACE_FLAGS_APPFACE_CONS) + if (face->flags & HICN_FACE_FLAGS_APPFACE_CONS) rv = hicn_face_cons_del (face_id1); else rv = hicn_face_prod_del (face_id1); diff --git a/hicn-plugin/src/faces/app/face_cons.c b/hicn-plugin/src/faces/app/face_cons.c index e51201c21..3cd3da78c 100644 --- a/hicn-plugin/src/faces/app/face_cons.c +++ b/hicn-plugin/src/faces/app/face_cons.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: @@ -57,10 +57,10 @@ hicn_face_cons_add (ip4_address_t * nh_addr4, ip6_address_t * nh_addr6, ip46_address_t nh_addr = to_ip46 (0, (u8 *) nh_addr4); - hicn_iface_ip_add (&if_ip, &nh_addr, swif, faceid1); + hicn_iface_add (&nh_addr, swif, faceid1, DPO_PROTO_IP4); hicn_face_t *face = hicn_dpoi_get_from_idx (*faceid1); - face->shared.flags |= HICN_FACE_FLAGS_APPFACE_CONS; + face->flags |= HICN_FACE_FLAGS_APPFACE_CONS; get_two_ip6_addresses (&(if_ip.ip6), nh_addr6); ip6_add_del_interface_address (vm, @@ -68,10 +68,10 @@ hicn_face_cons_add (ip4_address_t * nh_addr4, ip6_address_t * nh_addr6, &(if_ip.ip6), ADDR_MGR_IP6_CONS_LEN, 0 /* is_del */ ); - hicn_iface_ip_add (&if_ip, (ip46_address_t *) nh_addr6, swif, faceid2); + hicn_iface_add ((ip46_address_t *) nh_addr6, swif, faceid2, DPO_PROTO_IP6); face = hicn_dpoi_get_from_idx (*faceid2); - face->shared.flags |= HICN_FACE_FLAGS_APPFACE_CONS; + face->flags |= HICN_FACE_FLAGS_APPFACE_CONS; return HICN_ERROR_NONE; } @@ -84,9 +84,9 @@ hicn_face_cons_del (hicn_face_id_t face_id) hicn_face_t *face = hicn_dpoi_get_from_idx (face_id); - if (face->shared.flags & HICN_FACE_FLAGS_APPFACE_CONS) + if (face->flags & HICN_FACE_FLAGS_APPFACE_CONS) { - return hicn_face_ip_del (face_id); + return hicn_face_del (face_id); } else { diff --git a/hicn-plugin/src/faces/app/face_prod.c b/hicn-plugin/src/faces/app/face_prod.c index ae59719ce..5aed8c11e 100644 --- a/hicn-plugin/src/faces/app/face_prod.c +++ b/hicn-plugin/src/faces/app/face_prod.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: @@ -98,10 +98,11 @@ hicn_app_state_del (u32 swif) ); /* *INDENT-ON* */ - prefix = &(face_state_vec[swif].prefix); if (!found) return HICN_ERROR_APPFACE_NOT_FOUND; + prefix = &(face_state_vec[swif].prefix); + int ret = HICN_ERROR_NONE; if (ip46_address_is_ip4 (&prefix->fp_addr)) { @@ -132,7 +133,7 @@ hicn_face_prod_add (fib_prefix_t * prefix, u32 sw_if, u32 * cs_reserved, hicn_main_t *hm = &hicn_main; ip46_address_t local_app_ip; - ip46_address_t remote_app_ip; + CLIB_UNUSED(ip46_address_t remote_app_ip); u32 if_flags = 0; if (!hm->is_enabled) @@ -164,24 +165,12 @@ hicn_face_prod_add (fib_prefix_t * prefix, u32 sw_if, u32 * cs_reserved, * Check if a producer face is already existing for the same prefix * and sw_if */ - if (ip46_address_is_ip4 (&prefix->fp_addr)) - { - face = - hicn_face_ip4_get (&(prefix->fp_addr.ip4), sw_if, - &hicn_face_ip_remote_hashtb); - } - else - { - face = - hicn_face_ip6_get (&(prefix->fp_addr.ip6), sw_if, - &hicn_face_ip_remote_hashtb); - if (face != NULL) - return HICN_ERROR_FACE_ALREADY_CREATED; - } + face = hicn_face_get (&(prefix->fp_addr), sw_if, + &hicn_face_hashtb); if (face != NULL) { - if (!(face->shared.flags & HICN_FACE_FLAGS_DELETED)) + if (!(face->flags & HICN_FACE_FLAGS_DELETED)) return HICN_ERROR_FACE_ALREADY_CREATED; /* @@ -189,19 +178,17 @@ hicn_face_prod_add (fib_prefix_t * prefix, u32 sw_if, u32 * cs_reserved, * producer's prefix. */ /* It should never happens, this is a safety check. */ - if (face->shared.flags & HICN_FACE_FLAGS_APPFACE_CONS) + if (face->flags & HICN_FACE_FLAGS_APPFACE_CONS) return HICN_ERROR_FACE_ALREADY_CREATED; /* If the face exists but is marked as deleted, undelete it */ - if (face->shared.flags & HICN_FACE_FLAGS_DELETED) + if (face->flags & HICN_FACE_FLAGS_DELETED) { /* * remove the deleted flag and retrieve the face * local addr */ - face->shared.flags &= HICN_FACE_FLAGS_DELETED; - hicn_face_prod_t *prod_face = (hicn_face_prod_t *) face->data; - local_app_ip = prod_face->ip_face.local_addr; + face->flags &= HICN_FACE_FLAGS_DELETED; } } else @@ -221,10 +208,6 @@ hicn_face_prod_add (fib_prefix_t * prefix, u32 sw_if, u32 * cs_reserved, &local_app_ip4, 31, 0 /* is_del */ ); local_app_ip = to_ip46 ( /* isv6 */ 0, local_app_ip4.as_u8); remote_app_ip = to_ip46 ( /* isv6 */ 0, remote_app_ip4.as_u8); - - ret = - hicn_face_ip_add (&local_app_ip, &remote_app_ip, sw_if, faceid, - HICN_FACE_FLAGS_APPFACE_PROD); } else { @@ -242,41 +225,29 @@ hicn_face_prod_add (fib_prefix_t * prefix, u32 sw_if, u32 * cs_reserved, 0 /* is_del */ ); local_app_ip = to_ip46 ( /* isv6 */ 1, local_app_ip6.as_u8); remote_app_ip = to_ip46 ( /* isv6 */ 1, remote_app_ip6.as_u8); - - ret = - hicn_face_ip_add (&local_app_ip, &remote_app_ip, sw_if, faceid, - HICN_FACE_FLAGS_APPFACE_PROD); } - - face = hicn_dpoi_get_from_idx (*faceid); - - face->shared.flags |= HICN_FACE_FLAGS_APPFACE_PROD; - - hicn_face_prod_t *prod_face = (hicn_face_prod_t *) face->data; - - /* - * For the moment we keep them here although it would be good - * to create a different face for appface - */ - prod_face->policy_vft.hicn_cs_insert = hicn_cs_lru.hicn_cs_insert; - prod_face->policy_vft.hicn_cs_update = hicn_cs_lru.hicn_cs_update; - prod_face->policy_vft.hicn_cs_dequeue = hicn_cs_lru.hicn_cs_dequeue; - prod_face->policy_vft.hicn_cs_delete_get = - hicn_cs_lru.hicn_cs_delete_get; - prod_face->policy_vft.hicn_cs_trim = hicn_cs_lru.hicn_cs_trim; - prod_face->policy_vft.hicn_cs_flush = hicn_cs_lru.hicn_cs_flush; - } - if (ret == HICN_ERROR_NONE - && hicn_face_prod_set_lru_max (*faceid, cs_reserved) == HICN_ERROR_NONE) + if (ret == HICN_ERROR_NONE) + // && hicn_face_prod_set_lru_max (*faceid, cs_reserved) == HICN_ERROR_NONE) { + fib_route_path_t rpath = {0}; + fib_route_path_t * rpaths = NULL; + if (ip46_address_is_ip4(&(prefix->fp_addr))) { ip4_address_t mask; ip4_preflen_to_mask (prefix->fp_len, &mask); prefix->fp_addr.ip4.as_u32 = prefix->fp_addr.ip4.as_u32 & mask.as_u32; prefix->fp_proto = FIB_PROTOCOL_IP4; + + rpath.frp_weight = 1; + rpath.frp_sw_if_index = ~0; + rpath.frp_addr.ip4.as_u32 = remote_app_ip.ip4.as_u32; + rpath.frp_sw_if_index = sw_if; + rpath.frp_proto = DPO_PROTO_IP4; + + vec_add1 (rpaths, rpath); } else { @@ -287,21 +258,40 @@ hicn_face_prod_add (fib_prefix_t * prefix, u32 sw_if, u32 * cs_reserved, prefix->fp_addr.ip6.as_u64[1] = prefix->fp_addr.ip6.as_u64[1] & mask.as_u64[1]; prefix->fp_proto = FIB_PROTOCOL_IP6; + + rpath.frp_weight = 1; + rpath.frp_sw_if_index = ~0; + rpath.frp_addr.ip6.as_u64[0] = remote_app_ip.ip6.as_u64[0]; + rpath.frp_addr.ip6.as_u64[1] = remote_app_ip.ip6.as_u64[1]; + rpath.frp_sw_if_index = sw_if; + rpath.frp_proto = DPO_PROTO_IP6; + + vec_add1 (rpaths, rpath); } + u32 fib_index = fib_table_find (prefix->fp_proto, 0); + fib_table_entry_path_add2 (fib_index, + prefix, + FIB_SOURCE_CLI, + FIB_ENTRY_FLAG_NONE, rpaths); + hicn_app_state_create (sw_if, prefix); - ret = hicn_route_add (faceid, 1, prefix); } + face = hicn_face_get(&local_app_ip, sw_if, &hicn_face_hashtb);//HICN_FACE_FLAGS_APPFACE_PROD); + + *faceid = hicn_dpoi_get_index (face); + + face->flags |= HICN_FACE_FLAGS_APPFACE_PROD; + + hicn_face_unlock_with_id(*faceid); + *prod_addr = local_app_ip; /* Cleanup in case of something went wrong. */ if (ret) { hicn_app_state_del (sw_if); - - if (*faceid != HICN_FACE_NULL) - hicn_face_ip_del (*faceid); } return ret; } @@ -314,88 +304,32 @@ hicn_face_prod_del (hicn_face_id_t face_id) hicn_face_t *face = hicn_dpoi_get_from_idx (face_id); - if (face->shared.flags & HICN_FACE_FLAGS_APPFACE_PROD) + if (face->flags & HICN_FACE_FLAGS_APPFACE_PROD) { - hicn_face_prod_t *prod_face = (hicn_face_prod_t *) face->data; - /* Free the CS reserved for the face */ - hicn_main.pitcs.pcs_app_count -= prod_face->policy.max; - prod_face->policy.max = 0; - /* Remove the face from the fib */ - hicn_route_del_nhop (&(face_state_vec[face->shared.sw_if].prefix), - face_id); + //hicn_route_del_nhop (&(face_state_vec[face->sw_if].prefix), + // face_id); - /* - * Delete the content in the CS before deleting the face. - * Mandatory to prevent hitting the CS and not having the lru list - * due to a early deletion of the face. - */ - vlib_main_t *vm = vlib_get_main (); - prod_face->policy_vft.hicn_cs_flush (vm, &(hicn_main.pitcs), - &(prod_face->policy)); - - int ret = hicn_face_ip_del (face_id); - return ret == - HICN_ERROR_NONE ? hicn_app_state_del (face->shared.sw_if) : ret; + //int ret = hicn_face_del (face_id); + return hicn_app_state_del (face->sw_if); + //ret == HICN_ERROR_NONE ? hicn_app_state_del (face->sw_if) : ret; } else { return HICN_ERROR_APPFACE_NOT_FOUND; } -} -int -hicn_face_prod_set_lru_max (hicn_face_id_t face_id, u32 * requested_size) -{ - int ret = HICN_ERROR_NONE; - vlib_main_t *vm = vlib_get_main (); - hicn_face_t *face; - hicn_face_prod_t *face_prod; - - if (!hicn_infra_fwdr_initialized) - { - ret = HICN_ERROR_FWD_NOT_ENABLED; - vlib_cli_output (vm, "hicn: %s\n", get_error_string (ret)); - return ret; - } - face = hicn_dpoi_get_from_idx (face_id); - face_prod = (hicn_face_prod_t *) face->data; - - if (face == NULL) - return HICN_ERROR_FACE_NOT_FOUND; - - if (*requested_size > HICN_PARAM_FACE_MAX_CS_RESERVED) - *requested_size = HICN_PARAM_FACE_MAX_CS_RESERVED; - - uint32_t available = - hicn_main.pitcs.pcs_app_max - hicn_main.pitcs.pcs_app_count; - - if (*requested_size > available) - *requested_size = available; - - face_prod->policy.max = *requested_size; - face_prod->policy.count = 0; - face_prod->policy.head = face_prod->policy.tail = 0; - - hicn_main.pitcs.pcs_app_count += *requested_size; - - return ret; + return HICN_ERROR_NONE; } u8 * format_hicn_face_prod (u8 * s, va_list * args) { - index_t index = va_arg (*args, index_t); + CLIB_UNUSED (index_t index) = va_arg (*args, index_t); CLIB_UNUSED (u32 indent) = va_arg (*args, u32); - hicn_face_t *face; - hicn_face_prod_t *prod_face; - - face = hicn_dpoi_get_from_idx (index); - prod_face = (hicn_face_prod_t *) face->data; s = - format (s, " (producer face: CS size %d, data cached %d)", - prod_face->policy.max, prod_face->policy.count); + format (s, " (producer)"); return s; } diff --git a/hicn-plugin/src/faces/app/face_prod.h b/hicn-plugin/src/faces/app/face_prod.h index 33e2a4199..4cb2e3fbf 100644 --- a/hicn-plugin/src/faces/app/face_prod.h +++ b/hicn-plugin/src/faces/app/face_prod.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: @@ -17,7 +17,7 @@ #define _FACE_PRODUCER_H_ #include "../../cache_policies/cs_policy.h" -#include "../ip/face_ip.h" +#include "../face.h" /** * @file @@ -56,15 +56,6 @@ extern hicn_face_prod_state_t *face_state_vec; #define DEFAULT_PROBING_PORT 3784 -typedef struct __attribute__ ((packed)) hicn_face_prod_t_ -{ - hicn_face_ip_t ip_face; - - hicn_cs_policy_t policy; - hicn_cs_policy_vft_t policy_vft; - -} hicn_face_prod_t; - /** * @brief Add a new producer application face * diff --git a/hicn-plugin/src/faces/app/face_prod_node.c b/hicn-plugin/src/faces/app/face_prod_node.c index 0ef25fe94..80c3e124c 100644 --- a/hicn-plugin/src/faces/app/face_prod_node.c +++ b/hicn-plugin/src/faces/app/face_prod_node.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: @@ -300,8 +300,8 @@ VLIB_REGISTER_NODE(hicn_face_prod_input_node) = .n_next_nodes = HICN_FACE_PROD_N_NEXT, .next_nodes = { - [HICN_FACE_PROD_NEXT_DATA_IP4] = "hicn-face-ip4-input", - [HICN_FACE_PROD_NEXT_DATA_IP6] = "hicn-face-ip6-input", + [HICN_FACE_PROD_NEXT_DATA_IP4] = "hicn4-face-input", + [HICN_FACE_PROD_NEXT_DATA_IP6] = "hicn6-face-input", [HICN_FACE_PROD_NEXT_ERROR_DROP] = "error-drop", }, }; diff --git a/hicn-plugin/src/faces/ip/dpo_ip.h b/hicn-plugin/src/faces/dpo_face.h index c893c8be4..736c5c926 100644 --- a/hicn-plugin/src/faces/ip/dpo_ip.h +++ b/hicn-plugin/src/faces/dpo_face.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: @@ -13,19 +13,20 @@ * limitations under the License. */ -#ifndef __HICN_DPO_IP_H__ -#define __HICN_DPO_IP_H__ +#ifndef __HICN_DPO_H__ +#define __HICN_DPO_H__ #include <vnet/vnet.h> #include <vnet/ip/ip4_packet.h> +#include <vnet/adj/adj_midchain.h> -#include "face_ip.h" -#include "../face.h" +#include "face.h" +#include "../error.h" /** * @brief Initialize the internal structures of the dpo ip face module. */ -void hicn_dpo_ip_module_init (void); +//void hicn_dpo_ip_module_init (void); /** @@ -34,23 +35,21 @@ void hicn_dpo_ip_module_init (void); * @param vec: Result of the lookup. If no face exists for the local address vec = NULL * @param hicnb_flags: Flags that indicate whether the face is an application * face or not - * @param local_addr: Ip v4 local address of the face + * @param local_addr: Ip v4 nat address of the face * @param sw_if: software interface id of the face * * @result HICN_ERROR_FACE_NOT_FOUND if the face does not exist, otherwise HICN_ERROR_NONE. */ always_inline int -hicn_dpo_ip4_lock_from_local (dpo_id_t * dpo, - u32 * in_faces_vec_id, - u8 * hicnb_flags, - const ip4_address_t * local_addr, u32 sw_if) +hicn_dpo_face_ip4_lock (hicn_face_id_t * face_id, + u32 * in_faces_vec_id, + u8 * hicnb_flags, + const ip4_address_t * nat_addr) { - dpo->dpoi_type = DPO_FIRST; - dpo->dpoi_proto = DPO_PROTO_NONE; - dpo->dpoi_index = INDEX_INVALID; - dpo->dpoi_next_node = 0; - hicn_face_ip_input_faces_t *in_faces_vec = - hicn_face_ip4_get_vec (local_addr, sw_if, &hicn_face_ip_local_hashtb); + ip46_address_t ip_address = {0}; + ip46_address_set_ip4(&ip_address, nat_addr); + hicn_face_input_faces_t *in_faces_vec = + hicn_face_get_vec (&ip_address, &hicn_face_vec_hashtb); if (PREDICT_FALSE (in_faces_vec == NULL)) return HICN_ERROR_FACE_NOT_FOUND; @@ -60,12 +59,10 @@ hicn_dpo_ip4_lock_from_local (dpo_id_t * dpo, *hicnb_flags = HICN_BUFFER_FLAGS_DEFAULT; *hicnb_flags |= - (face->shared.flags & HICN_FACE_FLAGS_APPFACE_PROD) >> + (face->flags & HICN_FACE_FLAGS_APPFACE_PROD) >> HICN_FACE_FLAGS_APPFACE_PROD_BIT; - dpo_set (dpo, hicn_face_ip_type, DPO_PROTO_IP4, in_faces_vec->face_id); - dpo->dpoi_next_node = ~0; - dpo_unlock (dpo); + *face_id = in_faces_vec->face_id; return HICN_ERROR_NONE; } @@ -77,23 +74,19 @@ hicn_dpo_ip4_lock_from_local (dpo_id_t * dpo, * @param dpo: Result of the lookup. If the face doesn't exist dpo = NULL * @param hicnb_flags: Flags that indicate whether the face is an application * face or not - * @param local_addr: Ip v6 local address of the face + * @param nat_addr: Ip v6 nat address of the face * @param sw_if: software interface id of the face * * @result HICN_ERROR_FACE_NOT_FOUND if the face does not exist, otherwise HICN_ERROR_NONE. */ always_inline int -hicn_dpo_ip6_lock_from_local (dpo_id_t * dpo, - u32 * in_faces_vec_id, - u8 * hicnb_flags, - const ip6_address_t * local_addr, u32 sw_if) +hicn_dpo_face_ip6_lock (hicn_face_id_t * face_id, + u32 * in_faces_vec_id, + u8 * hicnb_flags, + const ip6_address_t * nat_addr) { - dpo->dpoi_type = DPO_FIRST; - dpo->dpoi_proto = DPO_PROTO_NONE; - dpo->dpoi_index = INDEX_INVALID; - dpo->dpoi_next_node = 0; - hicn_face_ip_input_faces_t *in_faces_vec = - hicn_face_ip6_get_vec (local_addr, sw_if, &hicn_face_ip_local_hashtb); + hicn_face_input_faces_t *in_faces_vec = + hicn_face_get_vec ((ip46_address_t *)nat_addr, &hicn_face_vec_hashtb); if (PREDICT_FALSE (in_faces_vec == NULL)) return HICN_ERROR_FACE_NOT_FOUND; @@ -103,16 +96,29 @@ hicn_dpo_ip6_lock_from_local (dpo_id_t * dpo, *hicnb_flags = HICN_BUFFER_FLAGS_DEFAULT; *hicnb_flags |= - (face->shared.flags & HICN_FACE_FLAGS_APPFACE_PROD) >> + (face->flags & HICN_FACE_FLAGS_APPFACE_PROD) >> HICN_FACE_FLAGS_APPFACE_PROD_BIT; - dpo_set (dpo, hicn_face_ip_type, DPO_PROTO_IP6, in_faces_vec->face_id); - dpo->dpoi_next_node = ~0; - dpo_unlock (dpo); + *face_id = in_faces_vec->face_id; return HICN_ERROR_NONE; } +/** + * @brief Call back to get the adj of the tunnel + */ +static adj_walk_rc_t +hicn4_iface_adj_walk_cb (adj_index_t ai, + void *ctx) +{ + + hicn_face_t *face = (hicn_face_t *)ctx; + + dpo_set(&face->dpo, DPO_ADJACENCY_MIDCHAIN, DPO_PROTO_IP4, ai); + adj_nbr_midchain_stack(ai, &face->dpo); + + return (ADJ_WALK_RC_CONTINUE); +} /** * @brief Retrieve, or create if it doesn't exist, a face from the ip6 local @@ -121,105 +127,152 @@ hicn_dpo_ip6_lock_from_local (dpo_id_t * dpo, * @param dpo: Result of the lookup * @param hicnb_flags: Flags that indicate whether the face is an application * face or not - * @param local_addr: Ip v4 local address of the face - * @param remote_addr: Ip v4 remote address of the face + * @param nat_addr: Ip v4 remote address of the face * @param sw_if: software interface id of the face * @param node_index: vlib edge index to use in the packet processing */ always_inline void -hicn_dpo_ip4_add_and_lock_from_remote (dpo_id_t * dpo, - u8 * hicnb_flags, - const ip4_address_t * local_addr, - const ip4_address_t * remote_addr, - u32 sw_if, u32 node_index) +hicn_dpo_iface_ip4_add_and_lock (hicn_face_id_t * index, + u8 * hicnb_flags, + const ip4_address_t * nat_addr, + u32 sw_if, u32 node_index) { - dpo->dpoi_type = DPO_FIRST; - dpo->dpoi_proto = DPO_PROTO_NONE; - dpo->dpoi_index = INDEX_INVALID; - dpo->dpoi_next_node = 0; /*All (complete) faces are indexed by remote addess as well */ + + ip46_address_t ip_address = {0}; + ip46_address_set_ip4(&ip_address, nat_addr); + + /* if the face exists, it adds a lock */ hicn_face_t *face = - hicn_face_ip4_get (remote_addr, sw_if, &hicn_face_ip_remote_hashtb); + hicn_face_get (&ip_address, sw_if, &hicn_face_hashtb); if (face == NULL) { - hicn_face_id_t dpoi_index; - ip46_address_t local_addr46 = to_ip46 (0, (u8 *) local_addr); - ip46_address_t remote_addr46 = to_ip46 (0, (u8 *) remote_addr); - hicn_iface_ip_add (&local_addr46, &remote_addr46, sw_if, &dpoi_index); + hicn_face_id_t idx; + hicn_iface_add (&ip_address, sw_if, &idx, DPO_PROTO_IP4); + + face = hicn_dpoi_get_from_idx(idx); + + if (nat_addr->as_u32 == 0) + { + adj_nbr_walk(face->sw_if, + FIB_PROTOCOL_IP4, + hicn4_iface_adj_walk_cb, + face); + } + else + { + face->dpo.dpoi_type = DPO_FIRST; + face->dpo.dpoi_proto = DPO_PROTO_IP4; + face->dpo.dpoi_index = ~0; + face->dpo.dpoi_next_node = node_index; + } *hicnb_flags = HICN_BUFFER_FLAGS_DEFAULT; - dpo_set (dpo, hicn_face_ip_type, DPO_PROTO_IP4, dpoi_index); - dpo->dpoi_next_node = node_index; - dpo_unlock (dpo); - + *index = idx; return; } + else + { + /* unlock the face. We don't take a lock on each interest we receive */ + hicn_face_id_t face_id = hicn_dpoi_get_index(face); + hicn_face_unlock_with_id(face_id); + } /* Code replicated on purpose */ *hicnb_flags = HICN_BUFFER_FLAGS_DEFAULT; *hicnb_flags |= - (face->shared.flags & HICN_FACE_FLAGS_APPFACE_PROD) >> + (face->flags & HICN_FACE_FLAGS_APPFACE_PROD) >> HICN_FACE_FLAGS_APPFACE_PROD_BIT; - hicn_face_id_t dpoi_index = hicn_dpoi_get_index (face); - dpo_set (dpo, hicn_face_ip_type, DPO_PROTO_IP4, dpoi_index); - dpo->dpoi_next_node = node_index; - dpo_unlock (dpo); + *index = hicn_dpoi_get_index (face); } /** + * @brief Call back to get the adj of the tunnel + */ +static adj_walk_rc_t +hicn6_iface_adj_walk_cb (adj_index_t ai, + void *ctx) +{ + + hicn_face_t *face = (hicn_face_t *)ctx; + + ip_adjacency_t *adj = adj_get(ai); + if ((adj->lookup_next_index == IP_LOOKUP_NEXT_MIDCHAIN) || + (adj->lookup_next_index == IP_LOOKUP_NEXT_MCAST_MIDCHAIN)) + { + dpo_set(&face->dpo, DPO_ADJACENCY_MIDCHAIN, adj->ia_nh_proto, ai); + adj_nbr_midchain_stack(ai, &face->dpo); + } + + return (ADJ_WALK_RC_CONTINUE); +} + + +/** * @brief Retrieve, or create if it doesn't exist, a face from the ip6 local * address and returns its dpo. This method adds a lock on the face state. * * @param dpo: Result of the lookup * @param hicnb_flags: Flags that indicate whether the face is an application * face or not - * @param local_addr: Ip v6 local address of the face - * @param remote_addr: Ip v6 remote address of the face + * @param nat_addr: Ip v6 remote address of the face * @param sw_if: software interface id of the face * @param node_index: vlib edge index to use in the packet processing */ always_inline void -hicn_dpo_ip6_add_and_lock_from_remote (dpo_id_t * dpo, - u8 * hicnb_flags, - const ip6_address_t * local_addr, - const ip6_address_t * remote_addr, - u32 sw_if, u32 node_index) +hicn_dpo_iface_ip6_add_and_lock (hicn_face_id_t * index, + u8 * hicnb_flags, + const ip6_address_t * nat_addr, + u32 sw_if, u32 node_index) { - dpo->dpoi_type = DPO_FIRST; - dpo->dpoi_proto = DPO_PROTO_NONE; - dpo->dpoi_index = INDEX_INVALID; - dpo->dpoi_next_node = 0; /*All (complete) faces are indexed by remote addess as well */ + /* if the face exists, it adds a lock */ hicn_face_t *face = - hicn_face_ip6_get (remote_addr, sw_if, &hicn_face_ip_remote_hashtb); + hicn_face_get ((ip46_address_t *)nat_addr, sw_if, &hicn_face_hashtb); if (face == NULL) { - hicn_face_id_t dpoi_index; - hicn_iface_ip_add ((ip46_address_t *) local_addr, - (ip46_address_t *) remote_addr, sw_if, &dpoi_index); + hicn_face_id_t idx; + hicn_iface_add ((ip46_address_t *) nat_addr, sw_if, &idx, DPO_PROTO_IP6); + + face = hicn_dpoi_get_from_idx(idx); + + face->dpo.dpoi_type = DPO_FIRST; + face->dpo.dpoi_proto = DPO_PROTO_IP6; + face->dpo.dpoi_index = ~0; + face->dpo.dpoi_next_node = node_index; + + //if (ip46_address_is_zero((ip46_address_t *)nat_addr)) + // { + adj_nbr_walk(face->sw_if, + FIB_PROTOCOL_IP6, + hicn6_iface_adj_walk_cb, + face); + // } *hicnb_flags = HICN_BUFFER_FLAGS_DEFAULT; - dpo_set (dpo, hicn_face_ip_type, DPO_PROTO_IP4, dpoi_index); - dpo->dpoi_next_node = node_index; - dpo_unlock (dpo); + *index = idx; return; } + else + { + /* unlock the face. We don't take a lock on each interest we receive */ + hicn_face_id_t face_id = hicn_dpoi_get_index(face); + hicn_face_unlock_with_id(face_id); + } + /* Code replicated on purpose */ *hicnb_flags = HICN_BUFFER_FLAGS_DEFAULT; *hicnb_flags |= - (face->shared.flags & HICN_FACE_FLAGS_APPFACE_PROD) >> + (face->flags & HICN_FACE_FLAGS_APPFACE_PROD) >> HICN_FACE_FLAGS_APPFACE_PROD_BIT; - index_t dpoi_index = hicn_dpoi_get_index (face); - dpo_set (dpo, hicn_face_ip_type, DPO_PROTO_IP6, dpoi_index); - dpo->dpoi_next_node = node_index; - dpo_unlock (dpo); + *index = hicn_dpoi_get_index (face); } @@ -267,16 +320,6 @@ hicn_dpo_ip6_add_and_lock_from_remote (dpo_id_t * dpo, /* u32 node_index, */ /* hicn_face_flags_t flags, hicn_face_id_t * face_id); */ -/** - * @brief Create a dpo from an ip face - * - * @param face Face from which to create the dpo - * @param dpoi_next_node Edge index that connects a node to the iface or face nodes - * @return the dpo - */ -void hicn_dpo_ip_create_from_face (hicn_face_t * face, dpo_id_t * dpo, - u16 dpoi_next_node); - #endif // __HICN_DPO_IP_H__ /* diff --git a/hicn-plugin/src/faces/face.c b/hicn-plugin/src/faces/face.c index f2dcdd151..f8ea61819 100644 --- a/hicn-plugin/src/faces/face.c +++ b/hicn-plugin/src/faces/face.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: @@ -14,14 +14,11 @@ */ #include "face.h" -#include "ip/face_ip.h" -#include "ip/face_ip_node.h" -#include "ip/iface_ip_node.h" -#include "ip/dpo_ip.h" -#include "udp/face_udp.h" -#include "udp/face_udp_node.h" -#include "udp/iface_udp_node.h" -#include "udp/dpo_udp.h" +#include "../hicn.h" +#include "../params.h" +#include "../error.h" +/* #include "../mapme.h" */ +/* #include "../mapme_eventmgr.h" */ dpo_id_t *face_dpo_vec; hicn_face_vft_t *face_vft_vec; @@ -33,6 +30,8 @@ dpo_type_t first_type = DPO_FIRST; vlib_combined_counter_main_t *counters; +dpo_type_t hicn_face_type; + const char *HICN_FACE_CTRX_STRING[] = { #define _(a,b,c) c, foreach_hicn_face_counter @@ -56,24 +55,58 @@ face_show (u8 * s, int face_id, u32 indent) } -void -register_face_type (hicn_face_type_t face_type, hicn_face_vft_t * vft, - char *name) +/* void */ +/* register_face_type (hicn_face_type_t face_type, hicn_face_vft_t * vft, */ +/* char *name) */ +/* { */ +/* if (first_type == DPO_FIRST) */ +/* first_type = face_type; */ + +/* int idx = face_type - first_type; */ +/* ASSERT (idx >= 0); */ +/* vec_validate (face_vft_vec, idx); */ +/* vec_validate (face_type_names_vec, idx); */ + +/* /\* Copy the null char as well *\/ */ +/* char *name_str = (char *) malloc ((strlen (name) + 1) * sizeof (char)); */ +/* strcpy (name_str, name); */ +/* face_vft_vec[idx] = *vft; */ +/* face_type_names_vec[idx] = name_str; */ +/* } */ + +mhash_t hicn_face_vec_hashtb; +mhash_t hicn_face_hashtb; + +hicn_face_vec_t * hicn_vec_pool; + +const static char *const hicn_face6_nodes[] = + { + "hicn6-face-output", // this is the name you give your node in VLIB_REGISTER_NODE + "hicn6-iface-output", // this is the name you give your node in VLIB_REGISTER_NODE + NULL, +}; + +const static char *const hicn_face4_nodes[] = + { + "hicn4-face-output", // this is the name you give your node in VLIB_REGISTER_NODE + "hicn4-iface-output", // this is the name you give your node in VLIB_REGISTER_NODE + NULL, +}; + + +const static char *const *const hicn_ip_nodes[DPO_PROTO_NUM] = { - if (first_type == DPO_FIRST) - first_type = face_type; - - int idx = face_type - first_type; - ASSERT (idx >= 0); - vec_validate (face_vft_vec, idx); - vec_validate (face_type_names_vec, idx); - - /* Copy the null char as well */ - char *name_str = (char *) malloc ((strlen (name) + 1) * sizeof (char)); - strcpy (name_str, name); - face_vft_vec[idx] = *vft; - face_type_names_vec[idx] = name_str; -} + [DPO_PROTO_IP4] = hicn_face4_nodes, + [DPO_PROTO_IP6] = hicn_face6_nodes +}; + +const static dpo_vft_t hicn_face_ip_vft = +{ + .dv_lock = hicn_face_lock, + .dv_unlock = hicn_face_unlock, + .dv_format = format_hicn_face, +}; + // Make this more flexible for future types face void @@ -81,15 +114,77 @@ hicn_face_module_init (vlib_main_t * vm) { pool_validate (hicn_dpoi_face_pool); pool_alloc (hicn_dpoi_face_pool, 1024); - hicn_face_ip_init (vm); - hicn_iface_ip_init (vm); - hicn_face_udp_init (vm); - hicn_iface_udp_init (vm); counters = vec_new (vlib_combined_counter_main_t, HICN_PARAM_FACES_MAX * HICN_N_COUNTER); + + mhash_init (&hicn_face_vec_hashtb, + sizeof (hicn_face_input_faces_t) /* value */ , + sizeof (hicn_face_key_t) /* key */ ); + mhash_init (&hicn_face_hashtb, + sizeof (hicn_face_id_t) /* value */ , + sizeof (hicn_face_key_t) /* key */ ); + + pool_alloc(hicn_vec_pool, 100); + + /* + * How much useful is the following registration? + * So far it seems that we need it only for setting the dpo_type. + */ + hicn_face_type = + dpo_register_new_type (&hicn_face_ip_vft, hicn_ip_nodes); +} + +u8 * +format_hicn_face (u8 * s, va_list * args) +{ + index_t index = va_arg (*args, index_t); + u32 indent = va_arg (*args, u32); + hicn_face_t *face; + + face = hicn_dpoi_get_from_idx (index); + + if (face->flags & HICN_FACE_FLAGS_FACE) + { + hicn_face_id_t face_id = hicn_dpoi_get_index (face); + s = format (s, "%U Face %d: ", format_white_space, indent, face_id); + s = format (s, "nat address %U locks %u, path_label %u", + format_ip46_address, &face->nat_addr, IP46_TYPE_ANY, + face->locks, face->pl_id); + + if ((face->flags & HICN_FACE_FLAGS_APPFACE_PROD)) + s = format (s, " (producer)"); + else if ((face->flags & HICN_FACE_FLAGS_APPFACE_CONS)) + s = format (s, " (consumer)"); + + if ((face->flags & HICN_FACE_FLAGS_DELETED)) + s = format (s, " (deleted)"); + + s = format (s, "\n%U%U", + format_white_space, indent + 2, + format_dpo_id, &face->dpo, indent + 3); + } + else + { + hicn_face_id_t face_id = hicn_dpoi_get_index (face); + s = format (s, "%U iFace %d: ", format_white_space, indent, face_id); + s = format (s, "nat address %U locks %u, path_label %u", + format_ip46_address, &face->nat_addr, IP46_TYPE_ANY, + face->locks, face->pl_id); + + if ((face->flags & HICN_FACE_FLAGS_APPFACE_PROD)) + s = format (s, " (producer)"); + else if ((face->flags & HICN_FACE_FLAGS_APPFACE_CONS)) + s = format (s, " (consumer)"); + + if ((face->flags & HICN_FACE_FLAGS_DELETED)) + s = format (s, " (deleted)"); + } + + return s; } + u8 * format_hicn_face_all (u8 * s, int n, ...) { @@ -104,46 +199,238 @@ format_hicn_face_all (u8 * s, int n, ...) /* *INDENT-OFF* */ pool_foreach ( face, hicn_dpoi_face_pool, { - hicn_face_vft_t * vft = hicn_face_get_vft(face->shared.face_type); - hicn_face_id_t face_id = hicn_dpoi_get_index(face); - s = format(s, "%U\n", vft->format_face, face_id, indent); + s = format(s, "%U\n", format_hicn_face, hicn_dpoi_get_index(face), indent); }); /* *INDENT-ON* */ return s; } -hicn_face_vft_t * -hicn_face_get_vft (hicn_face_type_t face_type) -{ - int idx = face_type - first_type; - if (idx >= 0) - return &face_vft_vec[idx]; - else - return NULL; +/* hicn_face_vft_t * */ +/* hicn_face_get_vft (hicn_face_type_t face_type) */ +/* { */ +/* int idx = face_type - first_type; */ +/* if (idx >= 0) */ +/* return &face_vft_vec[idx]; */ +/* else */ +/* return NULL; */ -} +/* } */ + +/* FACE IP CODE */ int hicn_face_del (hicn_face_id_t face_id) { + hicn_face_t *face = hicn_dpoi_get_from_idx (face_id); + hicn_face_key_t key; + hicn_face_key_t old_key; + hicn_face_key_t old_key2; + + hicn_face_get_key (&(face->nat_addr), face->sw_if, &(face->dpo), + &key); + hicn_face_input_faces_t *in_faces_vec = + hicn_face_get_vec (&(face->nat_addr), + &hicn_face_vec_hashtb); + if (in_faces_vec != NULL) + { + hicn_face_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_vec_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]; + } + } + + mhash_unset (&hicn_face_hashtb, &key, + (uword *) & old_key2); + } + int ret = HICN_ERROR_NONE; if (hicn_dpoi_idx_is_valid (face_id)) { hicn_face_t *face = hicn_dpoi_get_from_idx (face_id); - face->shared.locks--; - if (face->shared.locks == 0) + face->locks--; + if (face->locks == 0) pool_put_index (hicn_dpoi_face_pool, face_id); else - face->shared.flags |= HICN_FACE_FLAGS_DELETED; + face->flags |= HICN_FACE_FLAGS_DELETED; } else ret = HICN_ERROR_FACE_NOT_FOUND; + return ret; } +static void +hicn_iface_to_face(hicn_face_t *face, const dpo_id_t * dpo) +{ + dpo_stack(hicn_face_type, dpo->dpoi_proto, &face->dpo, dpo); + + face->flags &= ~HICN_FACE_FLAGS_IFACE; + face->flags |= HICN_FACE_FLAGS_FACE; +} + +/* + * Utility that adds a new face cache entry. For the moment we assume that + * the ip_adjacency has already been set up. + */ +int +hicn_face_add (const dpo_id_t * dpo_nh, ip46_address_t * nat_address, + int sw_if, hicn_face_id_t * pfaceid, u8 is_app_prod) +{ + // dpo_proto_t dpo_proto; + + hicn_face_flags_t flags = (hicn_face_flags_t) 0; + flags |= HICN_FACE_FLAGS_FACE; + + hicn_face_t *face; + + face = + hicn_face_get_with_dpo (nat_address, sw_if, dpo_nh, + &hicn_face_hashtb); + + if (face != NULL) + { + *pfaceid = hicn_dpoi_get_index (face); + return HICN_ERROR_FACE_ALREADY_CREATED; + } + + face = + hicn_face_get (nat_address, sw_if, + &hicn_face_hashtb); + + dpo_id_t temp_dpo = DPO_INVALID; + hicn_face_key_t key; + hicn_face_get_key (nat_address, sw_if, dpo_nh, &key); + + if (face == NULL) + { + + hicn_iface_add (nat_address, sw_if, pfaceid, dpo_nh->dpoi_proto); + face = hicn_dpoi_get_from_idx (*pfaceid); + + mhash_set_mem (&hicn_face_hashtb, &key, (uword *) pfaceid, + 0); + + hicn_face_get_key (nat_address, sw_if, &temp_dpo, &key); + mhash_set_mem (&hicn_face_hashtb, &key, (uword *) pfaceid, + 0); + } + else + { + /* *We found an iface and we convert it to a face */ + *pfaceid = hicn_dpoi_get_index (face); + mhash_set_mem (&hicn_face_hashtb, &key, (uword *) pfaceid, + 0); + } + + hicn_iface_to_face(face, dpo_nh); + + + hicn_face_input_faces_t *in_faces = + hicn_face_get_vec (nat_address, &hicn_face_vec_hashtb); + + if (in_faces == NULL) + { + hicn_face_input_faces_t in_faces_temp; + hicn_face_vec_t *vec; + pool_get (hicn_vec_pool, vec); + *vec = vec_new (hicn_face_vec_t, 0); + u32 index = vec - hicn_vec_pool; + in_faces_temp.vec_id = index; + vec_add1 (*vec, *pfaceid); + + + // dpo_proto = DPO_PROTO_IP4; + + in_faces_temp.face_id = *pfaceid; + + hicn_face_get_key (nat_address, 0, &temp_dpo, &key); + + mhash_set_mem (&hicn_face_vec_hashtb, &key, + (uword *) & in_faces_temp, 0); + } + else + { + hicn_face_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; + + vec_add1 (*vec, *pfaceid); + + hicn_iface_to_face(face, dpo_nh); + + // dpo_proto = DPO_PROTO_IP4; + + hicn_face_get_key (nat_address, 0, &temp_dpo, &key); + + mhash_set_mem (&hicn_face_vec_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_EVENT_FACE_ADD, 1, */ + /* sizeof (retx_t)); */ + + /* /\* *INDENT-OFF* *\/ */ + /* *retx = (retx_t) */ + /* { */ + /* .prefix = 0, */ + /* .dpo = (dpo_id_t) */ + /* { */ + /* .dpoi_type = 0, */ + /* .dpoi_proto = dpo_proto, */ + /* .dpoi_next_node = 0, */ + /* .dpoi_index = *pfaceid, */ + /* } */ + /* }; */ + /* /\* *INDENT-ON* *\/ */ + + return HICN_ERROR_NONE; +} + +/* void */ +/* hicn_face_get_dpo (hicn_face_t * face, dpo_id_t * dpo) */ +/* { */ + +/* hicn_face_ip_t *face_ip = (hicn_face_ip_t *) face->data; */ +/* return hicn_dpo_ip_create_from_face (face, dpo, */ +/* ip46_address_is_ip4 */ +/* (&face_ip->remote_addr) ? */ +/* strategy_face_ip4_vlib_edge : */ +/* strategy_face_ip6_vlib_edge); */ +/* } */ + + + /* * fd.io coding-style-patch-verification: ON * diff --git a/hicn-plugin/src/faces/face.h b/hicn-plugin/src/faces/face.h index b758ece06..1c829d2c2 100644 --- a/hicn-plugin/src/faces/face.h +++ b/hicn-plugin/src/faces/face.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,13 +18,14 @@ #include <vnet/vnet.h> #include <vlib/vlib.h> +#include <vnet/ip/ip46_address.h> #include <vnet/dpo/dpo.h> #include <vnet/adj/adj_types.h> -#include "../hicn.h" +#include <vppinfra/bihash_8_8.h> typedef u8 hicn_face_flags_t; typedef index_t hicn_face_id_t; -typedef dpo_type_t hicn_face_type_t; +//typedef dpo_type_t hicn_face_type_t; /** * @file @@ -42,9 +43,11 @@ typedef dpo_type_t hicn_face_type_t; */ /** - * @brief Fields shared among all the different types of faces + * @brief Structure holding the face state. It containes the fields shared among + * all the types of faces as well it leaves some space for storing additional + * information specific to each type. */ -typedef struct __attribute__ ((packed)) hicn_face_shared_s +typedef struct __attribute__ ((packed)) hicn_face_s { /* Flags to idenfity if the face is incomplete (iface), complete (face) */ /* And a network or application face (1B) */ @@ -59,38 +62,28 @@ typedef struct __attribute__ ((packed)) hicn_face_shared_s /* Number of dpo holding a reference to the dpoi (4B) */ u32 locks; - /* Adjacency for the neighbor (4B) */ - adj_index_t adj; + /* Dpo for the adjacency (8B) */ + union { + dpo_id_t dpo; + u64 align_dpo; + }; + + /* Local address of the interface sw_if */ + ip46_address_t nat_addr; /* local interface for the local ip address */ u32 sw_if; - /* Face id corresponding to the global face pool (4B) */ - union - { - hicn_face_type_t face_type; - u32 int_face_type; //To force the face_type_t to be 4B - }; - -} hicn_face_shared_t; + /* To align a face to 8 bytes */ + u32 padding; -/** - * @brief Structure holding the face state. It containes the fields shared among - * all the types of faces as well it leaves some space for storing additional - * information specific to each type. - */ -typedef struct __attribute__ ((packed)) hicn_face_s -{ - /* Additional space to fill with face_type specific information */ - u8 data[2 * CLIB_CACHE_LINE_BYTES - sizeof (hicn_face_shared_t)]; - hicn_face_shared_t shared; -} - -hicn_face_t; +} hicn_face_t; /* Pool of faces */ extern hicn_face_t *hicn_dpoi_face_pool; +//extern dpo_type_t hicn_face_type; + /* Flags */ /* A face is complete and it stores all the information. A iface lacks of the adj index, therefore sending a packet through a iface require a lookup in @@ -107,6 +100,10 @@ extern hicn_face_t *hicn_dpoi_face_pool; #define HICN_FACE_FLAGS_APPFACE_PROD_BIT 2 #define HICN_FACE_FLAGS_APPFACE_CONS_BIT 3 + +#define HICN_BUFFER_FLAGS_DEFAULT 0x00 +#define HICN_BUFFER_FLAGS_FACE_IS_APP 0x01 + STATIC_ASSERT ((1 << HICN_FACE_FLAGS_APPFACE_PROD_BIT) == HICN_FACE_FLAGS_APPFACE_PROD, "HICN_FACE_FLAGS_APPFACE_PROD_BIT and HICN_FACE_FLAGS_APPFACE_PROD must correspond"); @@ -155,6 +152,8 @@ typedef enum HICN_N_COUNTER } hicn_face_counters_t; +extern mhash_t hicn_face_hashtb; + extern const char *HICN_FACE_CTRX_STRING[]; #define get_face_counter_string(ctrxno) (char *)(HICN_FACE_CTRX_STRING[ctrxno]) @@ -192,6 +191,21 @@ hicn_dpoi_get_index (hicn_face_t * face_dpoi) * @return Pointer to the face */ always_inline hicn_face_t * +hicn_dpoi_get_from_idx_safe (hicn_face_id_t dpoi_index) +{ + if (!pool_is_free_index(hicn_dpoi_face_pool, dpoi_index)) + return (hicn_face_t *) pool_elt_at_index (hicn_dpoi_face_pool, dpoi_index); + else + return NULL; +} + +/** + * @brief Return the face from the face id. Face id must be valid. + * + * @param dpoi_index Face identifier + * @return Pointer to the face + */ +always_inline hicn_face_t * hicn_dpoi_get_from_idx (hicn_face_id_t dpoi_index) { return (hicn_face_t *) pool_elt_at_index (hicn_dpoi_face_pool, dpoi_index); @@ -207,17 +221,18 @@ hicn_dpoi_idx_is_valid (hicn_face_id_t face_id) && !pool_is_free_index (hicn_dpoi_face_pool, face_id); } + /** * @brief Add a lock to the face dpo * * @param dpo Pointer to the face dpo */ always_inline void -hicn_face_lock (dpo_id_t * dpo) +hicn_face_lock_with_id (hicn_face_id_t face_id) { hicn_face_t *face; - face = hicn_dpoi_get_from_idx (dpo->dpoi_index); - face->shared.locks++; + face = hicn_dpoi_get_from_idx (face_id); + face->locks++; } /** @@ -226,13 +241,36 @@ hicn_face_lock (dpo_id_t * dpo) * @param dpo Pointer to the face dpo */ always_inline void -hicn_face_unlock (dpo_id_t * dpo) +hicn_face_unlock_with_id (hicn_face_id_t face_id) { hicn_face_t *face; - face = hicn_dpoi_get_from_idx (dpo->dpoi_index); - face->shared.locks--; + face = hicn_dpoi_get_from_idx (face_id); + face->locks--; +} + +/** + * @brief Add a lock to the face dpo + * + * @param dpo Pointer to the face dpo + */ +always_inline void +hicn_face_lock (dpo_id_t * dpo) +{ + hicn_face_lock_with_id(dpo->dpoi_index); +} + +/** + * @brief Remove a lock to the face dpo. Deallocate the face id locks == 0 + * + * @param dpo Pointer to the face dpo + */ +always_inline void +hicn_face_unlock (dpo_id_t * dpo) +{ + hicn_face_unlock_with_id (dpo->dpoi_index); } + /** * @brief Init the internal structures of the face module * @@ -240,6 +278,9 @@ hicn_face_unlock (dpo_id_t * dpo) */ void hicn_face_module_init (vlib_main_t * vm); +u8 * format_hicn_face (u8 * s, va_list * args); + + /** * @brief Format all the existing faces * @@ -258,22 +299,205 @@ u8 *format_hicn_face_all (u8 * s, int n, ...); */ int hicn_face_del (hicn_face_id_t face_id); +/* FACE IP CODE */ + +/** + * @bried vector of faces used to collect faces having the same local address + * + */ +typedef hicn_face_id_t *hicn_face_vec_t; + +typedef struct hicn_input_faces_s_ +{ + /* Vector of all possible input faces */ + u32 vec_id; + + /* Preferred face. If an prod_app face is in the vector it will be the preferred one. */ + /* It's not possible to have multiple prod_app face in the same vector, they would have */ + /* the same local address. Every prod_app face is a point-to-point face between the forwarder */ + /* and the application. */ + hicn_face_id_t face_id; + +} hicn_face_input_faces_t; + +/** + * Pool containing the vector of possible incoming faces. + */ +extern hicn_face_vec_t *hicn_vec_pool; + /** - * @brief Return the virtual function table corresponding to the face type + * Hash tables that indexes a face by remote address. For fast lookup when an + * interest arrives. + */ +extern mhash_t hicn_face_vec_hashtb; + + +/** + * Key definition for the mhash table. An ip face is uniquely identified by ip + * address and the interface id. The ip address can correspond to the remote ip + * address of the next hicn hop, or to the local address of the receiving + * interface. The former is used to retrieve the incoming face when an interest + * is received, the latter when the arring packet is a data. + */ +typedef struct hicn_face_key_s +{ + ip46_address_t addr; + union { + dpo_id_t dpo; + u64 align_dpo; + }; + u32 sw_if; +} hicn_face_key_t; + +/** + * @brief Create the key object for the mhash. Fill in the key object with the + * expected values. * - * @param face_type Type of the face - * @return NULL if the face type does not exist + * @param addr nat address of the face + * @param sw_if interface associated to the face + * @param key Pointer to an allocated hicn_face_ip_key_t object */ -hicn_face_vft_t *hicn_face_get_vft (hicn_face_type_t face_type); +always_inline void +hicn_face_get_key (const ip46_address_t * addr, + u32 sw_if, const dpo_id_t * dpo, hicn_face_key_t * key) +{ + key->dpo = *dpo; + key->addr = *addr; + key->sw_if = sw_if; +} /** - * @brief Register a new face type + * @brief Get the dpoi from the nat address. Does not add any lock. + * + * @param addr Ip v4 address used to create the key for the hash table. + * @param sw_if Software interface id used to create the key for the hash table. + * @param hashtb Hash table (remote or local) where to perform the lookup. * - * @param face_type Type of the face - * @param vft Virtual Function table for the new face type + * @result Pointer to the face. */ -void register_face_type (hicn_face_type_t face_type, hicn_face_vft_t * vft, - char *name); +always_inline hicn_face_t * +hicn_face_get (const ip46_address_t * addr, u32 sw_if, mhash_t * hashtb) +{ + hicn_face_key_t key; + + dpo_id_t dpo = DPO_INVALID; + + hicn_face_get_key (addr, sw_if, &dpo, &key); + + hicn_face_id_t *dpoi_index = (hicn_face_id_t *) mhash_get (hashtb, + &key); + + if ( dpoi_index != NULL) + { + hicn_face_lock_with_id(*dpoi_index); + return hicn_dpoi_get_from_idx (*dpoi_index); + } + + return NULL; +} + +always_inline hicn_face_t * +hicn_face_get_with_dpo (const ip46_address_t * addr, u32 sw_if, const dpo_id_t * dpo, mhash_t * hashtb) +{ + hicn_face_key_t key; + + hicn_face_get_key (addr, sw_if, dpo, &key); + + hicn_face_id_t *dpoi_index = (hicn_face_id_t *) mhash_get (hashtb, + &key); + + if ( dpoi_index != NULL) + { + hicn_face_lock_with_id(*dpoi_index); + return hicn_dpoi_get_from_idx (*dpoi_index); + } + + return NULL; +} + +/** + * @brief Get the vector of faces from the ip v4 address. Does not add any lock. + * + * @param addr Ip v4 address used to create the key for the hash table. + * @param sw_if Software interface id used to create the key for the hash table. + * @param hashtb Hash table (remote or local) where to perform the lookup. + * + * @result Pointer to the face. + */ +always_inline hicn_face_input_faces_t * +hicn_face_get_vec (const ip46_address_t * addr, + mhash_t * hashtb) +{ + hicn_face_key_t key; + + dpo_id_t dpo = DPO_INVALID; + + hicn_face_get_key (addr, 0, &dpo, &key); + return (hicn_face_input_faces_t *) mhash_get (hashtb, &key); +} + +/** + * @brief Create a new face ip. API for other modules (e.g., routing) + * + * @param local_addr Local ip v4 or v6 address of the face + * @param remote_addr Remote ip v4 or v6 address of the face + * @param sw_if interface associated to the face + * @param is_app_face Boolean to set the face as an application face + * @param pfaceid Pointer to return the face id + * @param is_app_prod if HICN_FACE_FLAGS_APPFACE_PROD the face is a local application face, all other values are ignored + * @return HICN_ERROR_FACE_NO_GLOBAL_IP if the face does not have a globally + * reachable ip address, otherwise HICN_ERROR_NONE + */ +int hicn_face_add (const dpo_id_t * dpo_nh, + ip46_address_t * nat_address, + int sw_if, + hicn_face_id_t * pfaceid, + u8 is_app_prod); + +/** + * @brief Create a new incomplete face ip. (Meant to be used by the data plane) + * + * @param local_addr Local ip v4 or v6 address of the face + * @param remote_addr Remote ip v4 or 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_add (ip46_address_t * nat_address, int sw_if, + hicn_face_id_t * pfaceid, dpo_proto_t proto) +{ + hicn_face_t *face; + pool_get (hicn_dpoi_face_pool, face); + + clib_memcpy (&(face->nat_addr), nat_address, + sizeof (ip46_address_t)); + face->sw_if = sw_if; + + face->dpo.dpoi_type = DPO_FIRST; + face->dpo.dpoi_proto = DPO_PROTO_NONE; + face->dpo.dpoi_index = INDEX_INVALID; + face->dpo.dpoi_next_node = 0; + face->pl_id = (u16) 0; + face->flags = HICN_FACE_FLAGS_IFACE; + face->locks = 1; + + hicn_face_key_t key; + hicn_face_get_key (nat_address, sw_if, &face->dpo, &key); + *pfaceid = hicn_dpoi_get_index (face); + + mhash_set_mem (&hicn_face_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); + } +} + + #endif // __HICN_FACE_H__ /* diff --git a/hicn-plugin/src/faces/face_cli.c b/hicn-plugin/src/faces/face_cli.c index b0ed7ddae..e9e516cc6 100644 --- a/hicn-plugin/src/faces/face_cli.c +++ b/hicn-plugin/src/faces/face_cli.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: @@ -74,8 +74,7 @@ hicn_face_cli_show_command_fn (vlib_main_t * vm, (HICN_ERROR_FACE_NOT_FOUND)); hicn_face_t *face = hicn_dpoi_get_from_idx (face_id); - hicn_face_vft_t *vft = hicn_face_get_vft (face->shared.face_type); - vlib_cli_output (vm, "%U\n", vft->format_face, face_id, 0 /*indent */ ); + vlib_cli_output (vm, "%U\n", format_hicn_face, face_id, 0 /*indent */ ); u32 indent = 3; @@ -107,16 +106,14 @@ hicn_face_cli_show_command_fn (vlib_main_t * vm, if (found != ~0) { hicn_face_t *face; - dpo_type_t type = (dpo_type_t) (found + first_type); - hicn_face_vft_t *vft = hicn_face_get_vft (type); /* *INDENT-OFF* */ pool_foreach(face, hicn_dpoi_face_pool, { - if (!((face->shared.flags & HICN_FACE_FLAGS_DELETED) && !deleted)) + if (!((face->flags & HICN_FACE_FLAGS_DELETED) && !deleted)) { - if ((face->shared.face_type == type) && (face->shared.flags)) + if (face->flags) { - vlib_cli_output(vm, "%U\n", vft->format_face, hicn_dpoi_get_index(face), 0); + vlib_cli_output(vm, "%U\n", format_hicn_face, hicn_dpoi_get_index(face), 0); u8 * s = 0; u32 indent = 3; @@ -147,10 +144,9 @@ hicn_face_cli_show_command_fn (vlib_main_t * vm, /* *INDENT-OFF* */ pool_foreach(face, hicn_dpoi_face_pool, { - if (!((face->shared.flags & HICN_FACE_FLAGS_DELETED) && !deleted)) + if (!((face->flags & HICN_FACE_FLAGS_DELETED) && !deleted)) { - hicn_face_vft_t * vft = hicn_face_get_vft(face->shared.face_type); - vlib_cli_output(vm, "%U\n", vft->format_face, hicn_dpoi_get_index(face), 0); + vlib_cli_output(vm, "%U\n", format_hicn_face, hicn_dpoi_get_index(face), 0); u32 indent = 3; u8 * s = 0; @@ -184,7 +180,7 @@ hicn_face_cli_show_command_fn (vlib_main_t * vm, VLIB_CLI_COMMAND (hicn_face_cli_show_command, static) = { .path = "hicn face show", - .short_help = "hicn face show [<face_id>| type <ip/udp>]", + .short_help = "hicn face show [<face_id>]", .function = hicn_face_cli_show_command_fn, }; /* *INDENT-ON* */ diff --git a/hicn-plugin/src/faces/ip/face_ip_node.c b/hicn-plugin/src/faces/face_node.c index 0eeeab6fb..b146e3a6f 100644 --- a/hicn-plugin/src/faces/ip/face_ip_node.c +++ b/hicn-plugin/src/faces/face_node.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 Cisco and/or its affiliates. + * 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: @@ -15,15 +15,15 @@ #include <vnet/adj/adj.h> -#include "face_ip.h" -#include "face_ip_node.h" -#include "dpo_ip.h" -#include "../app/face_prod.h" -#include "../../strategy_dpo_manager.h" -#include "../face.h" -#include "../../cache_policies/cs_lru.h" -#include "../../infra.h" -#include "../../hicn.h" +#include "face.h" +#include "face_node.h" +#include "dpo_face.h" +//#include "app/face_prod.h" +#include "../strategy_dpo_manager.h" +#include "face.h" +#include "../cache_policies/cs_lru.h" +#include "../infra.h" +#include "../hicn.h" /** * @File @@ -31,21 +31,21 @@ * Definition of the nodes for ip incomplete faces. */ -vlib_node_registration_t hicn_face_ip4_input_node; -vlib_node_registration_t hicn_face_ip4_output_node; -vlib_node_registration_t hicn_face_ip6_input_node; -vlib_node_registration_t hicn_face_ip6_output_node; +vlib_node_registration_t hicn4_face_input_node; +vlib_node_registration_t hicn4_face_output_node; +vlib_node_registration_t hicn6_face_input_node; +vlib_node_registration_t hicn6_face_output_node; #define ip_v4 4 #define ip_v6 6 -static char *hicn_face_ip4_input_error_strings[] = { +static char *hicn4_face_input_error_strings[] = { #define _(sym, string) string, foreach_hicnfwd_error #undef _ }; -static char *hicn_face_ip6_input_error_strings[] = { +static char *hicn6_face_input_error_strings[] = { #define _(sym, string) string, foreach_hicnfwd_error #undef _ @@ -59,15 +59,15 @@ typedef struct u8 pkt_type; u8 packet_data[60]; } -hicn_face_ip4_input_trace_t; +hicn4_face_input_trace_t; typedef enum { - HICN_FACE_IP4_INPUT_NEXT_DATA, - HICN_FACE_IP4_INPUT_NEXT_MAPME, - HICN_FACE_IP4_INPUT_NEXT_ERROR_DROP, - HICN_FACE_IP4_INPUT_N_NEXT, -} hicn_face_ip4_input_next_t; + HICN4_FACE_INPUT_NEXT_DATA, + //HICN4_FACE_INPUT_NEXT_MAPME, + HICN4_FACE_INPUT_NEXT_ERROR_DROP, + HICN4_FACE_INPUT_N_NEXT, +} hicn4_face_input_next_t; /* Trace context struct */ typedef struct @@ -77,35 +77,35 @@ typedef struct u8 pkt_type; u8 packet_data[60]; } -hicn_face_ip6_input_trace_t; +hicn6_face_input_trace_t; typedef enum { - HICN_FACE_IP6_INPUT_NEXT_DATA, - HICN_FACE_IP6_INPUT_NEXT_MAPME, - HICN_FACE_IP6_INPUT_NEXT_ERROR_DROP, - HICN_FACE_IP6_INPUT_N_NEXT, -} hicn_face_ip6_input_next_t; + HICN6_FACE_INPUT_NEXT_DATA, + //HICN6_FACE_INPUT_NEXT_MAPME, + HICN6_FACE_INPUT_NEXT_ERROR_DROP, + HICN6_FACE_INPUT_N_NEXT, +} hicn6_face_input_next_t; -#define NEXT_MAPME_IP4 HICN_FACE_IP4_INPUT_NEXT_MAPME -#define NEXT_MAPME_IP6 HICN_FACE_IP6_INPUT_NEXT_MAPME -#define NEXT_DATA_IP4 HICN_FACE_IP4_INPUT_NEXT_DATA -#define NEXT_DATA_IP6 HICN_FACE_IP6_INPUT_NEXT_DATA +#define NEXT_MAPME_IP4 HICN4_FACE_INPUT_NEXT_ERROR_DROP//HICN4_FACE_INPUT_NEXT_MAPME +#define NEXT_MAPME_IP6 HICN6_FACE_INPUT_NEXT_ERROR_DROP//HICN6_FACE_INPUT_NEXT_MAPME +#define NEXT_DATA_IP4 HICN4_FACE_INPUT_NEXT_DATA +#define NEXT_DATA_IP6 HICN6_FACE_INPUT_NEXT_DATA -#define NEXT_ERROR_DROP_IP4 HICN_FACE_IP4_INPUT_NEXT_ERROR_DROP -#define NEXT_ERROR_DROP_IP6 HICN_FACE_IP6_INPUT_NEXT_ERROR_DROP +#define NEXT_ERROR_DROP_IP4 HICN4_FACE_INPUT_NEXT_ERROR_DROP +#define NEXT_ERROR_DROP_IP6 HICN6_FACE_INPUT_NEXT_ERROR_DROP #define IP_HEADER_4 ip4_header_t #define IP_HEADER_6 ip6_header_t -#define LOCK_FROM_LOCAL_IP4 hicn_dpo_ip4_lock_from_local -#define LOCK_FROM_LOCAL_IP6 hicn_dpo_ip6_lock_from_local +#define LOCK_DPO_FACE_IP4 hicn_dpo_face_ip4_lock +#define LOCK_DPO_FACE_IP6 hicn_dpo_face_ip6_lock -#define TRACE_INPUT_PKT_IP4 hicn_face_ip4_input_trace_t -#define TRACE_INPUT_PKT_IP6 hicn_face_ip6_input_trace_t +#define TRACE_INPUT_PKT_IP4 hicn4_face_input_trace_t +#define TRACE_INPUT_PKT_IP6 hicn6_face_input_trace_t /* - * NOTE: Both hicn_face_ip4_input_node_fn and hicn_face_ip6_input_node_fn + * NOTE: Both hicn4_face_input_node_fn and hicn6_face_input_node_fn * present a similar codebase. Macro are hard to debug, although the * followind code is pretty straighforward and most of the complexity is in * functions that can be easily debug. @@ -143,19 +143,18 @@ typedef enum next0 = is_icmp*NEXT_MAPME_IP##ipv + \ (1-is_icmp)*NEXT_DATA_IP##ipv; \ \ - ret = LOCK_FROM_LOCAL_IP##ipv \ - (&(hicnb0->face_dpo_id), \ + ret = LOCK_DPO_FACE_IP##ipv \ + (&(hicnb0->face_id), \ &(hicnb0->in_faces_vec_id), \ &hicnb0->flags, \ - &(ip_hdr->dst_address), \ - vnet_buffer (b0)->sw_if_index[VLIB_RX]); \ + &(ip_hdr->dst_address)); \ \ if ( PREDICT_FALSE(ret != HICN_ERROR_NONE) ) \ next0 = NEXT_ERROR_DROP_IP##ipv; \ else \ { \ vlib_increment_combined_counter ( \ - &counters[hicnb0->face_dpo_id.dpoi_index \ + &counters[hicnb0->face_id \ * HICN_N_COUNTER], thread_index, \ HICN_FACE_COUNTERS_DATA_RX, \ 1, \ @@ -232,26 +231,24 @@ typedef enum (1-is_icmp1)*NEXT_DATA_IP##ipv; \ \ \ - ret0 = LOCK_FROM_LOCAL_IP##ipv \ - (&(hicnb0->face_dpo_id), \ + ret0 = LOCK_DPO_FACE_IP##ipv \ + (&(hicnb0->face_id), \ &(hicnb0->in_faces_vec_id), \ &hicnb0->flags, \ - &(ip_hdr0->dst_address), \ - vnet_buffer (b0)->sw_if_index[VLIB_RX]); \ + &(ip_hdr0->dst_address)); \ \ - ret1 = LOCK_FROM_LOCAL_IP##ipv \ - (&(hicnb1->face_dpo_id), \ + ret1 = LOCK_DPO_FACE_IP##ipv \ + (&(hicnb1->face_id), \ &(hicnb1->in_faces_vec_id), \ &hicnb1->flags, \ - &(ip_hdr1->dst_address), \ - vnet_buffer (b1)->sw_if_index[VLIB_RX]); \ + &(ip_hdr1->dst_address)); \ \ if ( PREDICT_FALSE(ret0 != HICN_ERROR_NONE) ) \ next0 = NEXT_ERROR_DROP_IP##ipv; \ else \ { \ vlib_increment_combined_counter ( \ - &counters[hicnb0->face_dpo_id.dpoi_index \ + &counters[hicnb0->face_id \ * HICN_N_COUNTER], thread_index, \ HICN_FACE_COUNTERS_DATA_RX, \ 1, \ @@ -264,7 +261,7 @@ typedef enum else \ { \ vlib_increment_combined_counter ( \ - &counters[hicnb1->face_dpo_id.dpoi_index \ + &counters[hicnb1->face_id \ * HICN_N_COUNTER], thread_index,\ HICN_FACE_COUNTERS_DATA_RX, \ 1, \ @@ -307,8 +304,8 @@ typedef enum static uword -hicn_face_ip4_input_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, - vlib_frame_t * frame) +hicn4_face_input_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, + vlib_frame_t * frame) { u32 n_left_from, *from, *to_next, next_index; @@ -345,12 +342,12 @@ hicn_face_ip4_input_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, /* packet trace format function */ static u8 * -hicn_face_ip4_input_format_trace (u8 * s, va_list * args) +hicn4_face_input_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_face_ip4_input_trace_t *t = - va_arg (*args, hicn_face_ip4_input_trace_t *); + hicn4_face_input_trace_t *t = + va_arg (*args, hicn4_face_input_trace_t *); s = format (s, "FACE_IP4_INPUT: pkt: %d, sw_if_index %d, next index %d\n%U", (int) t->pkt_type, t->sw_if_index, t->next_index, @@ -363,32 +360,32 @@ hicn_face_ip4_input_format_trace (u8 * s, va_list * args) * Node registration for the interest forwarder node */ /* *INDENT-OFF* */ -VLIB_REGISTER_NODE(hicn_face_ip4_input_node) = +VLIB_REGISTER_NODE(hicn4_face_input_node) = { - .function = hicn_face_ip4_input_node_fn, - .name = "hicn-face-ip4-input", + .function = hicn4_face_input_node_fn, + .name = "hicn4-face-input", .vector_size = sizeof(u32), - .format_trace = hicn_face_ip4_input_format_trace, + .format_trace = hicn4_face_input_format_trace, .type = VLIB_NODE_TYPE_INTERNAL, - .n_errors = ARRAY_LEN(hicn_face_ip4_input_error_strings), - .error_strings = hicn_face_ip4_input_error_strings, - .n_next_nodes = HICN_FACE_IP4_INPUT_N_NEXT, + .n_errors = ARRAY_LEN(hicn4_face_input_error_strings), + .error_strings = hicn4_face_input_error_strings, + .n_next_nodes = HICN4_FACE_INPUT_N_NEXT, /* edit / add dispositions here */ .next_nodes = { - [HICN_FACE_IP4_INPUT_NEXT_DATA] = "hicn-data-pcslookup", - [HICN_FACE_IP4_INPUT_NEXT_MAPME] = "hicn-mapme-ack", - [HICN_FACE_IP4_INPUT_NEXT_ERROR_DROP] = "error-drop", + [HICN4_FACE_INPUT_NEXT_DATA] = "hicn-data-pcslookup", + //[HICN4_FACE_INPUT_NEXT_MAPME] = "hicn-mapme-ack", + [HICN4_FACE_INPUT_NEXT_ERROR_DROP] = "error-drop", }, }; /* *INDENT-ON* */ /** * @brief IPv6 face input node function - * @see hicn_face_ip4_input_node_fn + * @see hicn6_face_input_node_fn */ static uword -hicn_face_ip6_input_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, +hicn6_face_input_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) { u32 n_left_from, *from, *to_next, next_index; @@ -426,12 +423,12 @@ hicn_face_ip6_input_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, /* packet trace format function */ static u8 * -hicn_face_ip6_input_format_trace (u8 * s, va_list * args) +hicn6_face_input_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_face_ip6_input_trace_t *t = - va_arg (*args, hicn_face_ip6_input_trace_t *); + hicn6_face_input_trace_t *t = + va_arg (*args, hicn6_face_input_trace_t *); s = format (s, "FACE_IP6_INPUT: pkt: %d, sw_if_index %d, next index %d\n%U", (int) t->pkt_type, t->sw_if_index, t->next_index, @@ -443,22 +440,22 @@ hicn_face_ip6_input_format_trace (u8 * s, va_list * args) * Node registration for the interest forwarder node */ /* *INDENT-OFF* */ -VLIB_REGISTER_NODE(hicn_face_ip6_input_node) = +VLIB_REGISTER_NODE(hicn6_face_input_node) = { - .function = hicn_face_ip6_input_node_fn, - .name = "hicn-face-ip6-input", + .function = hicn6_face_input_node_fn, + .name = "hicn6-face-input", .vector_size = sizeof(u32), - .format_trace = hicn_face_ip6_input_format_trace, + .format_trace = hicn6_face_input_format_trace, .type = VLIB_NODE_TYPE_INTERNAL, - .n_errors = ARRAY_LEN(hicn_face_ip6_input_error_strings), - .error_strings = hicn_face_ip6_input_error_strings, - .n_next_nodes = HICN_FACE_IP6_INPUT_N_NEXT, + .n_errors = ARRAY_LEN(hicn6_face_input_error_strings), + .error_strings = hicn6_face_input_error_strings, + .n_next_nodes = HICN6_FACE_INPUT_N_NEXT, /* edit / add dispositions here */ .next_nodes = { - [HICN_FACE_IP6_INPUT_NEXT_DATA] = "hicn-data-pcslookup", - [HICN_FACE_IP6_INPUT_NEXT_MAPME] = "hicn-mapme-ack", - [HICN_FACE_IP6_INPUT_NEXT_ERROR_DROP] = "error-drop", + [HICN6_FACE_INPUT_NEXT_DATA] = "hicn-data-pcslookup", + //[HICN6_FACE_INPUT_NEXT_MAPME] = "hicn-mapme-ack", + [HICN6_FACE_INPUT_NEXT_ERROR_DROP] = "error-drop", }, }; /* *INDENT-ON* */ @@ -467,87 +464,87 @@ VLIB_REGISTER_NODE(hicn_face_ip6_input_node) = typedef enum { - HICN_FACE_IP4_NEXT_ECHO_REPLY = IP4_LOOKUP_N_NEXT, - HICN_FACE_IP4_N_NEXT, -} hicn_face_ip4_next_t; + HICN4_FACE_OUTPUT_NEXT_ECHO_REPLY, + HICN4_FACE_OUTPUT_N_NEXT, +} hicn4_face_output_next_t; typedef enum { - HICN_FACE_IP6_NEXT_ECHO_REPLY = IP6_LOOKUP_N_NEXT, - HICN_FACE_IP6_N_NEXT, -} hicn_face_ip6_next_t; - -static_always_inline void -hicn_reply_probe_v4 (vlib_buffer_t * b, hicn_face_t * face) -{ - hicn_header_t *h0 = vlib_buffer_get_current (b); - hicn_face_ip_t * face_ip = (hicn_face_ip_t *)(&face->data); - h0->v4.ip.saddr = h0->v4.ip.daddr; - h0->v4.ip.daddr = face_ip->local_addr.ip4; - vnet_buffer (b)->sw_if_index[VLIB_RX] = face->shared.sw_if; - - u16 * dst_port_ptr = (u16 *)(((u8*)h0) + sizeof(ip4_header_t) + sizeof(u16)); - u16 dst_port = *dst_port_ptr; - u16 * src_port_ptr = (u16 *)(((u8*)h0) + sizeof(ip4_header_t)); - - *dst_port_ptr = *src_port_ptr; - *src_port_ptr = dst_port; - - hicn_type_t type = hicn_get_buffer (b)->type; - hicn_ops_vft[type.l1]->set_lifetime (type, &h0->protocol, 0); -} - -static_always_inline void -hicn_reply_probe_v6 (vlib_buffer_t * b, hicn_face_t * face) -{ - hicn_header_t *h0 = vlib_buffer_get_current (b); - hicn_face_ip_t * face_ip = (hicn_face_ip_t *)(&face->data); - h0->v6.ip.saddr = h0->v6.ip.daddr; - h0->v6.ip.daddr = face_ip->local_addr.ip6; - vnet_buffer (b)->sw_if_index[VLIB_RX] = face->shared.sw_if; - - u16 * dst_port_ptr = (u16 *)(((u8*)h0) + sizeof(ip6_header_t) + sizeof(u16)); - u16 dst_port = *dst_port_ptr; - u16 * src_port_ptr = (u16 *)(((u8*)h0) + sizeof(ip6_header_t)); - - *dst_port_ptr = *src_port_ptr; - *src_port_ptr = dst_port; - - hicn_type_t type = hicn_get_buffer (b)->type; - hicn_ops_vft[type.l1]->set_lifetime (type, &h0->protocol, 0); - -} - -static_always_inline u32 -hicn_face_match_probe (vlib_buffer_t * b, hicn_face_t * face, u32 * next) -{ - - u8 *ptr = vlib_buffer_get_current (b); - u8 v = *ptr & 0xf0; - u8 res = 0; - - if ( v == 0x40 ) - { - u16 * dst_port = (u16 *)(ptr + sizeof(ip4_header_t) + sizeof(u16)); - if (*dst_port == clib_net_to_host_u16(DEFAULT_PROBING_PORT)) - { - hicn_reply_probe_v6(b, face); - *next = HICN_FACE_IP4_NEXT_ECHO_REPLY; - res = 1; - } - } - else if ( v == 0x60 ) - { - u16 * dst_port = (u16 *)(ptr + sizeof(ip6_header_t) + sizeof(u16)); - if (*dst_port == clib_net_to_host_u16(DEFAULT_PROBING_PORT)) - { - hicn_reply_probe_v6(b, face); - *next = HICN_FACE_IP6_NEXT_ECHO_REPLY; - res = 1; - } - } - return res; -} + HICN6_FACE_OUTPUT_NEXT_ECHO_REPLY, + HICN6_FACE_OUTPUT_N_NEXT, +} hicn6_face_output_next_t; + +/* static_always_inline void */ +/* hicn_reply_probe_v4 (vlib_buffer_t * b, hicn_face_t * face) */ +/* { */ +/* hicn_header_t *h0 = vlib_buffer_get_current (b); */ +/* hicn_face_ip_t * face_ip = (hicn_face_ip_t *)(&face->data); */ +/* h0->v4.ip.saddr = h0->v4.ip.daddr; */ +/* h0->v4.ip.daddr = face_ip->local_addr.ip4; */ +/* vnet_buffer (b)->sw_if_index[VLIB_RX] = face->shared.sw_if; */ + +/* u16 * dst_port_ptr = (u16 *)(((u8*)h0) + sizeof(ip4_header_t) + sizeof(u16)); */ +/* u16 dst_port = *dst_port_ptr; */ +/* u16 * src_port_ptr = (u16 *)(((u8*)h0) + sizeof(ip4_header_t)); */ + +/* *dst_port_ptr = *src_port_ptr; */ +/* *src_port_ptr = dst_port; */ + +/* hicn_type_t type = hicn_get_buffer (b)->type; */ +/* hicn_ops_vft[type.l1]->set_lifetime (type, &h0->protocol, 0); */ +/* } */ + +/* static_always_inline void */ +/* hicn_reply_probe_v6 (vlib_buffer_t * b, hicn_face_t * face) */ +/* { */ +/* hicn_header_t *h0 = vlib_buffer_get_current (b); */ +/* hicn_face_ip_t * face_ip = (hicn_face_ip_t *)(&face->data); */ +/* h0->v6.ip.saddr = h0->v6.ip.daddr; */ +/* h0->v6.ip.daddr = face_ip->local_addr.ip6; */ +/* vnet_buffer (b)->sw_if_index[VLIB_RX] = face->shared.sw_if; */ + +/* u16 * dst_port_ptr = (u16 *)(((u8*)h0) + sizeof(ip6_header_t) + sizeof(u16)); */ +/* u16 dst_port = *dst_port_ptr; */ +/* u16 * src_port_ptr = (u16 *)(((u8*)h0) + sizeof(ip6_header_t)); */ + +/* *dst_port_ptr = *src_port_ptr; */ +/* *src_port_ptr = dst_port; */ + +/* hicn_type_t type = hicn_get_buffer (b)->type; */ +/* hicn_ops_vft[type.l1]->set_lifetime (type, &h0->protocol, 0); */ + +/* } */ + +/* static_always_inline u32 */ +/* hicn_face_match_probe (vlib_buffer_t * b, hicn_face_t * face, u32 * next) */ +/* { */ + +/* u8 *ptr = vlib_buffer_get_current (b); */ +/* u8 v = *ptr & 0xf0; */ +/* u8 res = 0; */ + +/* if ( v == 0x40 ) */ +/* { */ +/* u16 * dst_port = (u16 *)(ptr + sizeof(ip4_header_t) + sizeof(u16)); */ +/* if (*dst_port == clib_net_to_host_u16(DEFAULT_PROBING_PORT)) */ +/* { */ +/* hicn_reply_probe_v6(b, face); */ +/* *next = HICN4_FACE_NEXT_ECHO_REPLY; */ +/* res = 1; */ +/* } */ +/* } */ +/* else if ( v == 0x60 ) */ +/* { */ +/* u16 * dst_port = (u16 *)(ptr + sizeof(ip6_header_t) + sizeof(u16)); */ +/* if (*dst_port == clib_net_to_host_u16(DEFAULT_PROBING_PORT)) */ +/* { */ +/* hicn_reply_probe_v6(b, face); */ +/* *next = HICN6_FACE_NEXT_ECHO_REPLY; */ +/* res = 1; */ +/* } */ +/* } */ +/* return res; */ +/* } */ static inline void @@ -555,68 +552,37 @@ hicn_face_rewrite_interest (vlib_main_t * vm, vlib_buffer_t * b0, hicn_face_t * face, u32 * next) { - if ((face->shared.flags & HICN_FACE_FLAGS_APPFACE_PROD) && hicn_face_match_probe(b0, face, next)) - return; + /* if ((face->flags & HICN_FACE_FLAGS_APPFACE_PROD) && hicn_face_match_probe(b0, face, next)) */ + /* return; */ hicn_header_t *hicn = vlib_buffer_get_current (b0); - hicn_face_ip_t *ip_face = (hicn_face_ip_t *) face->data; + //hicn_face_ip_t *ip_face = (hicn_face_ip_t *) face->data; ip46_address_t temp_addr; ip46_address_reset (&temp_addr); hicn_type_t type = hicn_get_buffer (b0)->type; hicn_ops_vft[type.l1]->rewrite_interest (type, &hicn->protocol, - &ip_face->local_addr, &temp_addr); - - int is_iface = 0; - ip_adjacency_t *adj; - if (PREDICT_FALSE (face->shared.adj == ~0)) - is_iface = 1; - else - adj = adj_get (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 - (is_iface || 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 = ip46_address_is_ip4(&ip_face->remote_addr)? 32 : 128; - - u32 fib_index = fib_table_find_or_create_and_lock (fib_pfx.fp_proto, - HICN_FIB_TABLE, - FIB_SOURCE_PRIORITY_HI); - - fib_entry_index = fib_table_lookup (fib_index, &fib_pfx); + &face->nat_addr, &temp_addr); - face->shared.adj = fib_entry_get_adj (fib_entry_index); - face->shared.flags &= ~HICN_FACE_FLAGS_IFACE; - face->shared.flags |= HICN_FACE_FLAGS_FACE; - - adj = adj_get (face->shared.adj); - - hicn_ops_vft[type.l1]->rewrite_data (type, &hicn->protocol, - &ip_face->remote_addr, &temp_addr, - 0); - } + if (ip46_address_is_ip4(&face->nat_addr)) + b0->flags |= VNET_BUFFER_F_OFFLOAD_IP_CKSUM; - vnet_buffer (b0)->ip.adj_index[VLIB_TX] = face->shared.adj; - *next = adj->lookup_next_index; + b0->flags |= VNET_BUFFER_F_OFFLOAD_TCP_CKSUM; + ASSERT(face->flags & HICN_FACE_FLAGS_FACE); + vnet_buffer (b0)->ip.adj_index[VLIB_TX] = face->dpo.dpoi_index; + *next = face->dpo.dpoi_next_node; } -static char *hicn_face_ip4_output_error_strings[] = { +static char *hicn4_face_output_error_strings[] = { #define _(sym, string) string, foreach_hicnfwd_error #undef _ }; -static char *hicn_face_ip6_output_error_strings[] = { +static char *hicn6_face_output_error_strings[] = { #define _(sym, string) string, foreach_hicnfwd_error #undef _ @@ -631,7 +597,7 @@ typedef struct u8 pkt_type; u8 packet_data[60]; } -hicn_face_ip4_output_trace_t; +hicn4_face_output_trace_t; /* Trace context struct */ typedef struct @@ -641,10 +607,10 @@ typedef struct u8 pkt_type; u8 packet_data[60]; } -hicn_face_ip6_output_trace_t; +hicn6_face_output_trace_t; -#define TRACE_OUTPUT_PKT_IP4 hicn_face_ip4_output_trace_t -#define TRACE_OUTPUT_PKT_IP6 hicn_face_ip6_output_trace_t +#define TRACE_OUTPUT_PKT_IP4 hicn4_face_output_trace_t +#define TRACE_OUTPUT_PKT_IP6 hicn6_face_output_trace_t #define face_output_x1(ipv) \ do { \ @@ -807,7 +773,7 @@ hicn_face_ip6_output_trace_t; static uword -hicn_face_ip4_output_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, +hicn4_face_output_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) { u32 n_left_from, *from, *to_next, next_index; @@ -846,12 +812,12 @@ hicn_face_ip4_output_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, /* packet trace format function */ static u8 * -hicn_face_ip4_output_format_trace (u8 * s, va_list * args) +hicn4_face_output_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_face_ip4_output_trace_t *t = - va_arg (*args, hicn_face_ip4_output_trace_t *); + hicn4_face_output_trace_t *t = + va_arg (*args, hicn4_face_output_trace_t *); s = format (s, "FACE_IP4_OUTPUT: pkt: %d, sw_if_index %d, next index %d\n%U", @@ -864,38 +830,27 @@ hicn_face_ip4_output_format_trace (u8 * s, va_list * args) * Node registration for the interest forwarder node */ /* *INDENT-OFF* */ -VLIB_REGISTER_NODE(hicn_face_ip4_output_node) = +VLIB_REGISTER_NODE(hicn4_face_output_node) = { - .function = hicn_face_ip4_output_node_fn, - .name = "hicn-face-ip4-output", + .function = hicn4_face_output_node_fn, + .name = "hicn4-face-output", .vector_size = sizeof(u32), - .format_trace = hicn_face_ip4_output_format_trace, + .format_trace = hicn4_face_output_format_trace, .type = VLIB_NODE_TYPE_INTERNAL, - .n_errors = ARRAY_LEN(hicn_face_ip4_output_error_strings), - .error_strings = hicn_face_ip4_output_error_strings, - .n_next_nodes = HICN_FACE_IP4_N_NEXT, + .n_errors = ARRAY_LEN(hicn4_face_output_error_strings), + .error_strings = hicn4_face_output_error_strings, + .n_next_nodes = HICN4_FACE_OUTPUT_N_NEXT, /* Reusing the list of nodes from lookup to be compatible with arp */ .next_nodes = { - [IP_LOOKUP_NEXT_DROP] = "ip4-drop", - [IP_LOOKUP_NEXT_PUNT] = "ip4-punt", - [IP_LOOKUP_NEXT_LOCAL] = "ip4-local", - [IP_LOOKUP_NEXT_ARP] = "ip4-arp", - [IP_LOOKUP_NEXT_GLEAN] = "ip4-glean", - [IP_LOOKUP_NEXT_REWRITE] = "ip4-rewrite", - [IP_LOOKUP_NEXT_MCAST] = "ip4-rewrite-mcast", - [IP_LOOKUP_NEXT_BCAST] = "ip4-rewrite-bcast", - [IP_LOOKUP_NEXT_MIDCHAIN] = "ip4-midchain", - [IP_LOOKUP_NEXT_MCAST_MIDCHAIN] = "ip4-mcast-midchain", - [IP_LOOKUP_NEXT_ICMP_ERROR] = "ip4-icmp-error", - [HICN_FACE_IP4_NEXT_ECHO_REPLY] = "hicn-face-ip4-input", + [HICN4_FACE_OUTPUT_NEXT_ECHO_REPLY] = "hicn4-face-input", } }; /* *INDENT-ON* */ static uword -hicn_face_ip6_output_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, +hicn6_face_output_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) { u32 n_left_from, *from, *to_next, next_index; @@ -934,12 +889,12 @@ hicn_face_ip6_output_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, /* packet trace format function */ static u8 * -hicn_face_ip6_output_format_trace (u8 * s, va_list * args) +hicn6_face_output_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_face_ip6_output_trace_t *t = - va_arg (*args, hicn_face_ip6_output_trace_t *); + hicn6_face_output_trace_t *t = + va_arg (*args, hicn6_face_output_trace_t *); s = format (s, "FACE_IP6_OUTPUT: pkt: %d, sw_if_index %d, next index %d\n%U", @@ -952,34 +907,20 @@ hicn_face_ip6_output_format_trace (u8 * s, va_list * args) * Node registration for the interest forwarder node */ /* *INDENT-OFF* */ -VLIB_REGISTER_NODE(hicn_face_ip6_output_node) = +VLIB_REGISTER_NODE(hicn6_face_output_node) = { - .function = hicn_face_ip6_output_node_fn, - .name = "hicn-face-ip6-output", + .function = hicn6_face_output_node_fn, + .name = "hicn6-face-output", .vector_size = sizeof(u32), - .format_trace = hicn_face_ip6_output_format_trace, + .format_trace = hicn6_face_output_format_trace, .type = VLIB_NODE_TYPE_INTERNAL, - .n_errors = ARRAY_LEN(hicn_face_ip6_output_error_strings), - .error_strings = hicn_face_ip6_output_error_strings, - .n_next_nodes = HICN_FACE_IP6_N_NEXT, + .n_errors = ARRAY_LEN(hicn6_face_output_error_strings), + .error_strings = hicn6_face_output_error_strings, + .n_next_nodes = HICN6_FACE_OUTPUT_N_NEXT, /* Reusing the list of nodes from lookup to be compatible with neighbour discovery */ .next_nodes = { - [IP_LOOKUP_NEXT_DROP] = "ip6-drop", - [IP_LOOKUP_NEXT_PUNT] = "ip6-punt", - [IP_LOOKUP_NEXT_LOCAL] = "ip6-local", - [IP_LOOKUP_NEXT_ARP] = "ip6-discover-neighbor", - [IP_LOOKUP_NEXT_GLEAN] = "ip6-glean", - [IP_LOOKUP_NEXT_REWRITE] = "ip6-rewrite", - [IP_LOOKUP_NEXT_BCAST] = "ip6-rewrite-bcast", - [IP_LOOKUP_NEXT_MCAST] = "ip6-rewrite-mcast", - [IP_LOOKUP_NEXT_MIDCHAIN] = "ip6-midchain", - [IP_LOOKUP_NEXT_MCAST_MIDCHAIN] = "ip6-mcast-midchain", - [IP_LOOKUP_NEXT_ICMP_ERROR] = "ip6-icmp-error", - [IP6_LOOKUP_NEXT_HOP_BY_HOP] = "ip6-hop-by-hop", - [IP6_LOOKUP_NEXT_ADD_HOP_BY_HOP] = "ip6-add-hop-by-hop", - [IP6_LOOKUP_NEXT_POP_HOP_BY_HOP] = "ip6-pop-hop-by-hop", - [HICN_FACE_IP6_NEXT_ECHO_REPLY] = "hicn-face-ip6-input" + [HICN6_FACE_OUTPUT_NEXT_ECHO_REPLY] = "hicn6-face-input" } }; /* *INDENT-ON* */ diff --git a/hicn-plugin/src/faces/udp/face_udp_node.h b/hicn-plugin/src/faces/face_node.h index c759312c8..932ee40f5 100644 --- a/hicn-plugin/src/faces/udp/face_udp_node.h +++ b/hicn-plugin/src/faces/face_node.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 Cisco and/or its affiliates. + * 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: @@ -13,18 +13,18 @@ * limitations under the License. */ -#ifndef __HICN_FACE_UDP_NODE_H__ -#define __HICN_FACE_UDP_NODE_H__ +#ifndef __HICN_FACE_NODE_H__ +#define __HICN_FACE_NODE_H__ #include <vlib/vlib.h> #include <vnet/vnet.h> -extern vlib_node_registration_t hicn_face_udp4_input_node; -extern vlib_node_registration_t hicn_face_udp6_input_node; -extern vlib_node_registration_t hicn_face_udp4_output_node; -extern vlib_node_registration_t hicn_face_udp6_output_node; +extern vlib_node_registration_t hicn4_face_input_node; +extern vlib_node_registration_t hicn4_face_output_node; +extern vlib_node_registration_t hicn6_face_input_node; +extern vlib_node_registration_t hicn6_face_output_node; -#endif // __HICN_FACE_UDP_NODE_H__ +#endif // __HICN_FACE_NODE_H__ /* * fd.io coding-style-patch-verification: ON diff --git a/hicn-plugin/src/faces/ip/iface_ip_node.c b/hicn-plugin/src/faces/iface_node.c index 8adef50d9..5def03417 100644 --- a/hicn-plugin/src/faces/ip/iface_ip_node.c +++ b/hicn-plugin/src/faces/iface_node.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 Cisco and/or its affiliates. + * 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: @@ -13,13 +13,12 @@ * limitations under the License. */ -#include "face_ip.h" -#include "dpo_ip.h" -#include "../../strategy_dpo_manager.h" -#include "../face.h" -#include "../../hicn.h" -#include "../../infra.h" -#include "../../cache_policies/cs_lru.h" +#include "face.h" +#include "dpo_face.h" +#include "../strategy_dpo_manager.h" +#include "../hicn.h" +#include "../infra.h" +#include "../cache_policies/cs_lru.h" /** * @File @@ -27,10 +26,10 @@ * Definition of the nodes for ip incomplete faces. */ -vlib_node_registration_t hicn_iface_ip4_input_node; -vlib_node_registration_t hicn_iface_ip4_output_node; -vlib_node_registration_t hicn_iface_ip6_input_node; -vlib_node_registration_t hicn_iface_ip6_output_node; +vlib_node_registration_t hicn4_iface_input_node; +vlib_node_registration_t hicn4_iface_output_node; +vlib_node_registration_t hicn6_iface_input_node; +vlib_node_registration_t hicn6_iface_output_node; u32 data_fwd_iface_ip4_vlib_edge; u32 data_fwd_iface_ip6_vlib_edge; @@ -40,30 +39,30 @@ hicn_iface_ip_init (vlib_main_t * vm) { u32 temp_index4 = vlib_node_add_next (vm, hicn_interest_hitcs_node.index, - hicn_iface_ip4_output_node.index); + hicn4_iface_output_node.index); u32 temp_index6 = vlib_node_add_next (vm, hicn_interest_hitcs_node.index, - hicn_iface_ip6_output_node.index); + hicn6_iface_output_node.index); data_fwd_iface_ip4_vlib_edge = vlib_node_add_next (vm, hicn_data_fwd_node.index, - hicn_iface_ip4_output_node.index); + hicn4_iface_output_node.index); data_fwd_iface_ip6_vlib_edge = vlib_node_add_next (vm, hicn_data_fwd_node.index, - hicn_iface_ip6_output_node.index); + hicn6_iface_output_node.index); ASSERT (temp_index4 == data_fwd_iface_ip4_vlib_edge); ASSERT (temp_index6 == data_fwd_iface_ip6_vlib_edge); } -static char *hicn_iface_ip4_input_error_strings[] = { +static char *hicn4_iface_input_error_strings[] = { #define _(sym, string) string, foreach_hicnfwd_error #undef _ }; -static char *hicn_iface_ip6_input_error_strings[] = { +static char *hicn6_iface_input_error_strings[] = { #define _(sym, string) string, foreach_hicnfwd_error #undef _ @@ -76,15 +75,15 @@ typedef struct u32 sw_if_index; u8 pkt_type; u8 packet_data[60]; -} hicn_iface_ip4_input_trace_t; +} hicn4_iface_input_trace_t; typedef enum { - HICN_IFACE_IP4_INPUT_NEXT_INTEREST, - HICN_IFACE_IP4_INPUT_NEXT_MAPME, - HICN_IFACE_IP4_INPUT_NEXT_ERROR_DROP, - HICN_IFACE_IP4_INPUT_N_NEXT, -} hicn_iface_ip4_input_next_t; + HICN4_IFACE_INPUT_NEXT_INTEREST, + //HICN4_IFACE_INPUT_NEXT_MAPME, + HICN4_IFACE_INPUT_NEXT_ERROR_DROP, + HICN4_IFACE_INPUT_N_NEXT, +} hicn4_iface_input_next_t; /* Trace context struct */ typedef struct @@ -93,21 +92,21 @@ typedef struct u32 sw_if_index; u8 pkt_type; u8 packet_data[60]; -} hicn_iface_ip6_input_trace_t; +} hicn6_iface_input_trace_t; typedef enum { - HICN_IFACE_IP6_INPUT_NEXT_INTEREST, - HICN_IFACE_IP6_INPUT_NEXT_MAPME, - HICN_IFACE_IP6_INPUT_NEXT_ERROR_DROP, - HICN_IFACE_IP6_INPUT_N_NEXT, -} hicn_iface_ip6_input_next_t; + HICN6_IFACE_INPUT_NEXT_INTEREST, + //HICN6_IFACE_INPUT_NEXT_MAPME, + HICN6_IFACE_INPUT_NEXT_ERROR_DROP, + HICN6_IFACE_INPUT_N_NEXT, +} hicn6_iface_input_next_t; -#define NEXT_MAPME_IP4 HICN_IFACE_IP4_INPUT_NEXT_MAPME -#define NEXT_MAPME_IP6 HICN_IFACE_IP6_INPUT_NEXT_MAPME +#define NEXT_MAPME_IP4 HICN4_IFACE_INPUT_NEXT_ERROR_DROP//HICN4_IFACE_INPUT_NEXT_MAPME +#define NEXT_MAPME_IP6 HICN6_IFACE_INPUT_NEXT_ERROR_DROP//HICN6_IFACE_INPUT_NEXT_MAPME -#define NEXT_INTEREST_IP4 HICN_IFACE_IP6_INPUT_NEXT_INTEREST -#define NEXT_INTEREST_IP6 HICN_IFACE_IP6_INPUT_NEXT_INTEREST +#define NEXT_INTEREST_IP4 HICN4_IFACE_INPUT_NEXT_INTEREST +#define NEXT_INTEREST_IP6 HICN6_IFACE_INPUT_NEXT_INTEREST #define ADDRESS_IP4 ip_interface_address_t *ia = 0;ip4_address_t *local_address = ip4_interface_first_address(&ip4_main, swif, &ia) #define ADDRESS_IP6 ip6_address_t *local_address = ip6_interface_first_address(&ip6_main, swif) @@ -119,17 +118,76 @@ typedef enum #define ADDRESSX2_IP6 ip6_address_t *local_address0 = ip6_interface_first_address(&ip6_main, swif0); \ ip6_address_t *local_address1 = ip6_interface_first_address(&ip6_main, swif1); -#define DPO_ADD_LOCK_IP4 hicn_dpo_ip4_add_and_lock_from_remote -#define DPO_ADD_LOCK_IP6 hicn_dpo_ip6_add_and_lock_from_remote +#define DPO_ADD_LOCK_IFACE_IP4 hicn_dpo_iface_ip4_add_and_lock +#define DPO_ADD_LOCK_IFACE_IP6 hicn_dpo_iface_ip6_add_and_lock -#define VLIB_EDGE_IP4 data_fwd_iface_ip4_vlib_edge -#define VLIB_EDGE_IP6 data_fwd_iface_ip6_vlib_edge +//#define VLIB_EDGE_IP4 data_fwd_iface_ip4_vlib_edge +//#define VLIB_EDGE_IP6 data_fwd_iface_ip6_vlib_edge #define IP_HEADER_4 ip4_header_t #define IP_HEADER_6 ip6_header_t -#define TRACE_INPUT_PKT_IP4 hicn_iface_ip4_input_trace_t -#define TRACE_INPUT_PKT_IP6 hicn_iface_ip6_input_trace_t +#define TRACE_INPUT_PKT_IP4 hicn4_iface_input_trace_t +#define TRACE_INPUT_PKT_IP6 hicn6_iface_input_trace_t + +// NODE OUTPUT + +static char *hicn4_iface_output_error_strings[] = { +#define _(sym, string) string, + foreach_hicnfwd_error +#undef _ +}; + +static char *hicn6_iface_output_error_strings[] = { +#define _(sym, string) string, + foreach_hicnfwd_error +#undef _ +}; + + +/* Trace context struct */ +typedef struct +{ + u32 next_index; + u32 sw_if_index; + u8 pkt_type; + u8 packet_data[60]; +} hicn4_iface_output_trace_t; + +typedef enum +{ + HICN4_IFACE_OUTPUT_NEXT_LOOKUP, + HICN4_IFACE_OUTPUT_N_NEXT, +} hicn4_iface_output_next_t; + +/* Trace context struct */ +typedef struct +{ + u32 next_index; + u32 sw_if_index; + u8 pkt_type; + u8 packet_data[60]; +} hicn6_iface_output_trace_t; + +typedef enum +{ + HICN6_IFACE_OUTPUT_NEXT_LOOKUP, + HICN6_IFACE_OUTPUT_N_NEXT, +} hicn6_iface_output_next_t; + +//#define ERROR_OUTPUT_IP4 HICN4_IFACE_OUTPUT_NEXT_ERROR_DROP +//#define ERROR_OUTPUT_IP6 HICN6_IFACE_OUTPUT_NEXT_ERROR_DROP + +#define NEXT_DATA_LOOKUP_IP4 HICN4_IFACE_OUTPUT_NEXT_LOOKUP +#define NEXT_DATA_LOOKUP_IP6 HICN6_IFACE_OUTPUT_NEXT_LOOKUP + +#define HICN_REWRITE_DATA_IP4 hicn_rewrite_iface_data4 +#define HICN_REWRITE_DATA_IP6 hicn_rewrite_iface_data6 + +#define TRACE_OUTPUT_PKT_IP4 hicn4_iface_output_trace_t +#define TRACE_OUTPUT_PKT_IP6 hicn6_iface_output_trace_t + +// NODES IMPLEMENTATIONS #define iface_input_x1(ipv) \ do { \ @@ -137,7 +195,6 @@ typedef enum u32 bi0, next0; \ IP_HEADER_##ipv * ip_hdr = NULL; \ hicn_buffer_t * hicnb0; \ - u32 swif; \ /* Prefetch for next iteration. */ \ if (n_left_from > 1) \ { \ @@ -165,17 +222,13 @@ typedef enum next0 = is_icmp*NEXT_MAPME_IP##ipv + \ (1-is_icmp)*NEXT_INTEREST_IP##ipv; \ \ - swif = vnet_buffer (b0)->sw_if_index[VLIB_RX]; \ - \ - ADDRESS_IP##ipv; \ \ - DPO_ADD_LOCK_IP##ipv \ - (&(hicnb0->face_dpo_id), \ - &hicnb0->flags, \ - local_address, \ - &(ip_hdr->src_address), \ - vnet_buffer(b0)->sw_if_index[VLIB_RX], \ - VLIB_EDGE_IP##ipv); \ + DPO_ADD_LOCK_IFACE_IP##ipv \ + (&(hicnb0->face_id), \ + &hicnb0->flags, \ + &(ip_hdr->src_address), \ + vnet_buffer(b0)->sw_if_index[VLIB_RX], \ + NEXT_DATA_LOOKUP_IP##ipv); \ \ if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && \ (b0->flags & VLIB_BUFFER_IS_TRACED))) \ @@ -192,11 +245,11 @@ typedef enum } \ \ vlib_increment_combined_counter ( \ - &counters[hicnb0->face_dpo_id.dpoi_index \ - * HICN_N_COUNTER], thread_index, \ - HICN_FACE_COUNTERS_INTEREST_RX, \ - 1, \ - vlib_buffer_length_in_chain(vm, b0)); \ + &counters[hicnb0->face_id \ + * HICN_N_COUNTER], thread_index, \ + HICN_FACE_COUNTERS_INTEREST_RX, \ + 1, \ + vlib_buffer_length_in_chain(vm, b0)); \ \ /* Verify speculative enqueue, maybe switch current next frame */ \ vlib_validate_buffer_enqueue_x1 (vm, node, next_index, \ @@ -212,7 +265,6 @@ typedef enum IP_HEADER_##ipv * ip_hdr0 = NULL; \ IP_HEADER_##ipv * ip_hdr1 = NULL; \ hicn_buffer_t *hicnb0, *hicnb1; \ - u32 swif0, swif1; \ \ /* Prefetch for next iteration. */ \ vlib_buffer_t *b2, *b3; \ @@ -251,26 +303,20 @@ typedef enum next1 = is_icmp1*NEXT_MAPME_IP##ipv + \ (1-is_icmp1)*NEXT_INTEREST_IP##ipv; \ \ - swif0 = vnet_buffer (b0)->sw_if_index[VLIB_RX]; \ - swif1 = vnet_buffer (b1)->sw_if_index[VLIB_RX]; \ - \ - ADDRESSX2_IP##ipv; \ \ - DPO_ADD_LOCK_IP##ipv \ - (&(hicnb0->face_dpo_id), \ + DPO_ADD_LOCK_IFACE_IP##ipv \ + (&(hicnb0->face_id), \ &hicnb0->flags, \ - local_address0, \ &(ip_hdr0->src_address), \ vnet_buffer(b0)->sw_if_index[VLIB_RX], \ - VLIB_EDGE_IP##ipv); \ + NEXT_DATA_LOOKUP_IP##ipv); \ \ - DPO_ADD_LOCK_IP##ipv \ - (&(hicnb1->face_dpo_id), \ + DPO_ADD_LOCK_IFACE_IP##ipv \ + (&(hicnb1->face_id), \ &hicnb1->flags, \ - local_address1, \ &(ip_hdr1->src_address), \ vnet_buffer(b1)->sw_if_index[VLIB_RX], \ - VLIB_EDGE_IP##ipv); \ + NEXT_DATA_LOOKUP_IP##ipv); \ \ if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && \ (b0->flags & VLIB_BUFFER_IS_TRACED))) \ @@ -299,14 +345,14 @@ typedef enum } \ \ vlib_increment_combined_counter ( \ - &counters[hicnb0->face_dpo_id.dpoi_index \ + &counters[hicnb0->face_id \ * HICN_N_COUNTER], thread_index, \ HICN_FACE_COUNTERS_INTEREST_RX, \ 1, \ vlib_buffer_length_in_chain(vm, b0)); \ \ vlib_increment_combined_counter ( \ - &counters[hicnb1->face_dpo_id.dpoi_index \ + &counters[hicnb1->face_id \ * HICN_N_COUNTER], thread_index, \ HICN_FACE_COUNTERS_INTEREST_RX, \ 1, \ @@ -319,7 +365,7 @@ typedef enum }while(0) static uword -hicn_iface_ip4_input_node_fn (vlib_main_t * vm, +hicn4_iface_input_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) { @@ -359,12 +405,12 @@ hicn_iface_ip4_input_node_fn (vlib_main_t * vm, /* packet trace format function */ static u8 * -hicn_iface_ip4_input_format_trace (u8 * s, va_list * args) +hicn4_iface_input_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_iface_ip4_input_trace_t *t = - va_arg (*args, hicn_iface_ip4_input_trace_t *); + hicn4_iface_input_trace_t *t = + va_arg (*args, hicn4_iface_input_trace_t *); s = format (s, "IFACE_IP4_INPUT: pkt: %d, sw_if_index %d, next index %d\n%U", @@ -377,28 +423,28 @@ hicn_iface_ip4_input_format_trace (u8 * s, va_list * args) * Node registration for the interest forwarder node */ /* *INDENT-OFF* */ -VLIB_REGISTER_NODE (hicn_iface_ip4_input_node) = +VLIB_REGISTER_NODE (hicn4_iface_input_node) = { - .function = hicn_iface_ip4_input_node_fn, - .name = "hicn-iface-ip4-input", + .function = hicn4_iface_input_node_fn, + .name = "hicn4-iface-input", .vector_size = sizeof (u32), - .format_trace = hicn_iface_ip4_input_format_trace, + .format_trace = hicn4_iface_input_format_trace, .type = VLIB_NODE_TYPE_INTERNAL, - .n_errors = ARRAY_LEN (hicn_iface_ip4_input_error_strings), - .error_strings = hicn_iface_ip4_input_error_strings, - .n_next_nodes = HICN_IFACE_IP4_INPUT_N_NEXT, + .n_errors = ARRAY_LEN (hicn4_iface_input_error_strings), + .error_strings = hicn4_iface_input_error_strings, + .n_next_nodes = HICN4_IFACE_INPUT_N_NEXT, /* edit / add dispositions*/ .next_nodes = { - [HICN_IFACE_IP4_INPUT_NEXT_INTEREST] = "hicn-interest-pcslookup", - [HICN_IFACE_IP4_INPUT_NEXT_MAPME] = "hicn-mapme-ctrl", - [HICN_IFACE_IP4_INPUT_NEXT_ERROR_DROP] = "error-drop", + [HICN4_IFACE_INPUT_NEXT_INTEREST] = "hicn-interest-pcslookup", + //[HICN4_IFACE_INPUT_NEXT_MAPME] = "hicn-mapme-ctrl", + [HICN4_IFACE_INPUT_NEXT_ERROR_DROP] = "error-drop", }, }; /* *INDENT-ON* */ static uword -hicn_iface_ip6_input_node_fn (vlib_main_t * vm, +hicn6_iface_input_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) { @@ -439,12 +485,12 @@ hicn_iface_ip6_input_node_fn (vlib_main_t * vm, /* packet trace format function */ static u8 * -hicn_iface_ip6_input_format_trace (u8 * s, va_list * args) +hicn6_iface_input_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_iface_ip6_input_trace_t *t = - va_arg (*args, hicn_iface_ip6_input_trace_t *); + hicn6_iface_input_trace_t *t = + va_arg (*args, hicn6_iface_input_trace_t *); s = format (s, "IFACE_IP6_INPUT: pkt: %d, sw_if_index %d, next index %d\n%U", @@ -457,22 +503,22 @@ hicn_iface_ip6_input_format_trace (u8 * s, va_list * args) * Node registration for the interest forwarder node */ /* *INDENT-OFF* */ -VLIB_REGISTER_NODE (hicn_iface_ip6_input_node) = +VLIB_REGISTER_NODE (hicn6_iface_input_node) = { - .function = hicn_iface_ip6_input_node_fn, - .name = "hicn-iface-ip6-input", + .function = hicn6_iface_input_node_fn, + .name = "hicn6-iface-input", .vector_size = sizeof (u32), - .format_trace = hicn_iface_ip6_input_format_trace, + .format_trace = hicn6_iface_input_format_trace, .type = VLIB_NODE_TYPE_INTERNAL, - .n_errors = ARRAY_LEN (hicn_iface_ip6_input_error_strings), - .error_strings = hicn_iface_ip6_input_error_strings, - .n_next_nodes = HICN_IFACE_IP6_INPUT_N_NEXT, + .n_errors = ARRAY_LEN (hicn6_iface_input_error_strings), + .error_strings = hicn6_iface_input_error_strings, + .n_next_nodes = HICN6_IFACE_INPUT_N_NEXT, /* edit / add dispositions*/ .next_nodes = { - [HICN_IFACE_IP6_INPUT_NEXT_INTEREST] = "hicn-interest-pcslookup", - [HICN_IFACE_IP6_INPUT_NEXT_MAPME] = "hicn-mapme-ctrl", - [HICN_IFACE_IP6_INPUT_NEXT_ERROR_DROP] = "error-drop", + [HICN6_IFACE_INPUT_NEXT_INTEREST] = "hicn-interest-pcslookup", + //[HICN6_IFACE_INPUT_NEXT_MAPME] = "hicn-mapme-ctrl", + [HICN6_IFACE_INPUT_NEXT_ERROR_DROP] = "error-drop", }, }; /* *INDENT-ON* */ @@ -482,7 +528,7 @@ VLIB_REGISTER_NODE (hicn_iface_ip6_input_node) = static inline void hicn_rewrite_iface_data4 (vlib_main_t * vm, vlib_buffer_t * b0, - const hicn_face_t * iface) + const hicn_face_t * iface, u32 * next) { ip4_header_t *ip0; @@ -495,21 +541,21 @@ hicn_rewrite_iface_data4 (vlib_main_t * vm, vlib_buffer_t * b0, ip0->length = clib_host_to_net_u16 (sval); ip0->ttl = 254; // FIXME TTL - vnet_buffer (b0)->ip.adj_index[VLIB_TX] = ~0; + vnet_buffer (b0)->ip.adj_index[VLIB_TX] = iface->dpo.dpoi_index; + *next = iface->dpo.dpoi_next_node; hicn_header_t *hicn = vlib_buffer_get_current (b0); ip46_address_t temp_addr; ip46_address_reset (&temp_addr); - hicn_face_ip_t *iface_ip = (hicn_face_ip_t *) iface->data; hicn_type_t type = hicn_get_buffer (b0)->type; hicn_ops_vft[type.l1]->rewrite_data (type, &hicn->protocol, - &(iface_ip->remote_addr), &(temp_addr), - iface->shared.pl_id); + &(iface->nat_addr), &(temp_addr), + iface->pl_id); } static inline void hicn_rewrite_iface_data6 (vlib_main_t * vm, vlib_buffer_t * b0, - const hicn_face_t * iface) + const hicn_face_t * iface, u32 * next) { ip6_header_t *ip0; @@ -523,80 +569,24 @@ hicn_rewrite_iface_data6 (vlib_main_t * vm, vlib_buffer_t * b0, ip0->payload_length = clib_host_to_net_u16 (sval); ip0->hop_limit = HICN_IP6_HOP_LIMIT; - vnet_buffer (b0)->ip.adj_index[VLIB_TX] = ~0; + vnet_buffer (b0)->ip.adj_index[VLIB_TX] = iface->dpo.dpoi_index; + *next = iface->dpo.dpoi_next_node; + hicn_header_t *hicn = vlib_buffer_get_current (b0); ip46_address_t temp_addr; ip46_address_reset (&temp_addr); - hicn_face_ip_t *iface_ip = (hicn_face_ip_t *) iface->data; hicn_type_t type = hicn_get_buffer (b0)->type; hicn_ops_vft[type.l1]->rewrite_data (type, &hicn->protocol, - &(iface_ip->remote_addr), &(temp_addr), - iface->shared.pl_id); + &(iface->nat_addr), &(temp_addr), + iface->pl_id); } -static char *hicn_iface_ip4_output_error_strings[] = { -#define _(sym, string) string, - foreach_hicnfwd_error -#undef _ -}; - -static char *hicn_iface_ip6_output_error_strings[] = { -#define _(sym, string) string, - foreach_hicnfwd_error -#undef _ -}; - - -/* Trace context struct */ -typedef struct -{ - u32 next_index; - u32 sw_if_index; - u8 pkt_type; - u8 packet_data[60]; -} hicn_iface_ip4_output_trace_t; - -typedef enum -{ - HICN_IFACE_IP4_OUTPUT_NEXT_LOOKUP, - HICN_IFACE_IP4_OUTPUT_NEXT_ERROR_DROP, - HICN_IFACE_IP4_OUTPUT_N_NEXT, -} hicn_iface_ip4_output_next_t; - -/* Trace context struct */ -typedef struct -{ - u32 next_index; - u32 sw_if_index; - u8 pkt_type; - u8 packet_data[60]; -} hicn_iface_ip6_output_trace_t; - -typedef enum -{ - HICN_IFACE_IP6_OUTPUT_NEXT_LOOKUP, - HICN_IFACE_IP6_OUTPUT_NEXT_ERROR_DROP, - HICN_IFACE_IP6_OUTPUT_N_NEXT, -} hicn_iface_ip6_output_next_t; - -#define ERROR_OUTPUT_IP4 HICN_IFACE_IP4_OUTPUT_NEXT_ERROR_DROP -#define ERROR_OUTPUT_IP6 HICN_IFACE_IP6_OUTPUT_NEXT_ERROR_DROP - -#define NEXT_DATA_LOOKUP_IP4 HICN_IFACE_IP4_OUTPUT_NEXT_LOOKUP -#define NEXT_DATA_LOOKUP_IP6 HICN_IFACE_IP6_OUTPUT_NEXT_LOOKUP - -#define HICN_REWRITE_DATA_IP4 hicn_rewrite_iface_data4 -#define HICN_REWRITE_DATA_IP6 hicn_rewrite_iface_data6 - -#define TRACE_OUTPUT_PKT_IP4 hicn_iface_ip4_output_trace_t -#define TRACE_OUTPUT_PKT_IP6 hicn_iface_ip6_output_trace_t - #define iface_output_x1(ipv) \ do { \ vlib_buffer_t *b0; \ u32 bi0; \ - u32 next0 = ERROR_OUTPUT_IP##ipv; \ + u32 next0 = next_index; \ hicn_face_t * face; \ \ /* Prefetch for next iteration. */ \ @@ -624,8 +614,7 @@ typedef enum if (PREDICT_TRUE(face != NULL)) \ { \ HICN_REWRITE_DATA_IP##ipv \ - (vm, b0, face); \ - next0 = NEXT_DATA_LOOKUP_IP##ipv; \ + (vm, b0, face, &next0); \ stats.pkts_data_count += 1; \ vlib_increment_combined_counter ( \ &counters[face_id * HICN_N_COUNTER], \ @@ -660,8 +649,8 @@ typedef enum do { \ vlib_buffer_t *b0, *b1; \ u32 bi0, bi1; \ - u32 next0 = ERROR_OUTPUT_IP##ipv; \ - u32 next1 = ERROR_OUTPUT_IP##ipv; \ + u32 next0 = next_index; \ + u32 next1 = next_index; \ hicn_face_t *face0, *face1; \ \ /* Prefetch for next iteration. */ \ @@ -698,8 +687,7 @@ typedef enum if (PREDICT_TRUE(face0 != NULL)) \ { \ HICN_REWRITE_DATA_IP##ipv \ - (vm, b0, face0); \ - next0 = NEXT_DATA_LOOKUP_IP##ipv; \ + (vm, b0, face0, &next0); \ stats.pkts_data_count += 1; \ vlib_increment_combined_counter ( \ &counters[face_id0 * HICN_N_COUNTER], \ @@ -712,8 +700,7 @@ typedef enum if (PREDICT_TRUE(face1 != NULL)) \ { \ HICN_REWRITE_DATA_IP##ipv \ - (vm, b1, face1); \ - next1 = NEXT_DATA_LOOKUP_IP##ipv; \ + (vm, b1, face1, &next1); \ stats.pkts_data_count += 1; \ vlib_increment_combined_counter ( \ &counters[face_id1 * HICN_N_COUNTER], \ @@ -759,7 +746,7 @@ typedef enum static uword -hicn_iface_ip4_output_node_fn (vlib_main_t * vm, +hicn4_iface_output_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) { @@ -797,12 +784,12 @@ hicn_iface_ip4_output_node_fn (vlib_main_t * vm, /* packet trace format function */ static u8 * -hicn_iface_ip4_output_format_trace (u8 * s, va_list * args) +hicn4_iface_output_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_iface_ip4_output_trace_t *t = - va_arg (*args, hicn_iface_ip4_output_trace_t *); + hicn4_iface_output_trace_t *t = + va_arg (*args, hicn4_iface_output_trace_t *); s = format (s, "IFACE_IP4_OUTPUT: pkt: %d, sw_if_index %d, next index %d\n%U", @@ -815,28 +802,27 @@ hicn_iface_ip4_output_format_trace (u8 * s, va_list * args) * Node registration for the interest forwarder node */ /* *INDENT-OFF* */ -VLIB_REGISTER_NODE (hicn_iface_ip4_output_node) = +VLIB_REGISTER_NODE (hicn4_iface_output_node) = { - .function = hicn_iface_ip4_output_node_fn, - .name = "hicn-iface-ip4-output", + .function = hicn4_iface_output_node_fn, + .name = "hicn4-iface-output", .vector_size = sizeof (u32), - .format_trace = hicn_iface_ip4_output_format_trace, + .format_trace = hicn4_iface_output_format_trace, .type = VLIB_NODE_TYPE_INTERNAL, - .n_errors = ARRAY_LEN (hicn_iface_ip4_output_error_strings), - .error_strings = hicn_iface_ip4_output_error_strings, - .n_next_nodes = HICN_IFACE_IP4_OUTPUT_N_NEXT, + .n_errors = ARRAY_LEN (hicn4_iface_output_error_strings), + .error_strings = hicn4_iface_output_error_strings, + .n_next_nodes = HICN4_IFACE_OUTPUT_N_NEXT, /* edit / add dispositions here */ .next_nodes = { - [HICN_IFACE_IP4_OUTPUT_NEXT_LOOKUP] = "ip4-lookup", - [HICN_IFACE_IP4_OUTPUT_NEXT_ERROR_DROP] = "error-drop", + [HICN4_IFACE_OUTPUT_NEXT_LOOKUP] = "ip4-lookup", }, }; /* *INDENT-ON* */ static uword -hicn_iface_ip6_output_node_fn (vlib_main_t * vm, +hicn6_iface_output_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) { @@ -873,12 +859,12 @@ hicn_iface_ip6_output_node_fn (vlib_main_t * vm, /* packet trace format function */ static u8 * -hicn_iface_ip6_output_format_trace (u8 * s, va_list * args) +hicn6_iface_output_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_iface_ip6_output_trace_t *t = - va_arg (*args, hicn_iface_ip6_output_trace_t *); + hicn6_iface_output_trace_t *t = + va_arg (*args, hicn6_iface_output_trace_t *); s = format (s, "IFACE_IP6_OUTPUT: pkt: %d, sw_if_index %d, next index %d\n%U", @@ -891,21 +877,20 @@ hicn_iface_ip6_output_format_trace (u8 * s, va_list * args) * Node registration for the interest forwarder node */ /* *INDENT-OFF* */ -VLIB_REGISTER_NODE (hicn_iface_ip6_output_node) = +VLIB_REGISTER_NODE (hicn6_iface_output_node) = { - .function = hicn_iface_ip6_output_node_fn, - .name = "hicn-iface-ip6-output", + .function = hicn6_iface_output_node_fn, + .name = "hicn6-iface-output", .vector_size = sizeof (u32), - .format_trace = hicn_iface_ip6_output_format_trace, + .format_trace = hicn6_iface_output_format_trace, .type = VLIB_NODE_TYPE_INTERNAL, - .n_errors = ARRAY_LEN (hicn_iface_ip6_output_error_strings), - .error_strings = hicn_iface_ip6_output_error_strings, - .n_next_nodes = HICN_IFACE_IP6_OUTPUT_N_NEXT, + .n_errors = ARRAY_LEN (hicn6_iface_output_error_strings), + .error_strings = hicn6_iface_output_error_strings, + .n_next_nodes = HICN6_IFACE_OUTPUT_N_NEXT, /* edit / add dispositions here */ .next_nodes = { - [HICN_IFACE_IP6_OUTPUT_NEXT_LOOKUP] = "ip6-lookup", - [HICN_IFACE_IP6_OUTPUT_NEXT_ERROR_DROP] = "error-drop", + [HICN6_IFACE_OUTPUT_NEXT_LOOKUP] = "ip6-lookup", }, }; /* *INDENT-ON* */ diff --git a/hicn-plugin/src/faces/ip/iface_ip_node.h b/hicn-plugin/src/faces/iface_node.h index 36923f069..761721b2f 100644 --- a/hicn-plugin/src/faces/ip/iface_ip_node.h +++ b/hicn-plugin/src/faces/iface_node.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 Cisco and/or its affiliates. + * 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: diff --git a/hicn-plugin/src/faces/ip/dpo_ip.c b/hicn-plugin/src/faces/ip/dpo_ip.c deleted file mode 100644 index d05fec1a0..000000000 --- a/hicn-plugin/src/faces/ip/dpo_ip.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * 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 "dpo_ip.h" - -mhash_t hicn_face_ip_local_hashtb; -mhash_t hicn_face_ip_remote_hashtb; -dpo_type_t hicn_face_ip_type; - -hicn_face_ip_vec_t * hicn_vec_pool; - -const static char *const hicn_face_ip4dpoi_nodes[] = { - "hicn-face-ip4-input", - "hicn-face-ip4-output", - "hicn-iface-ip4-input", - "hicn-iface-ip4-output", - NULL, -}; - -const static char *const hicn_face_ip6dpoi_nodes[] = { - "hicn-face-ip6-input", - "hicn-face-ip6-output", - "hicn-iface-ip6-input", - "hicn-iface-ip6-output", - NULL, -}; - -const static char *const *const hicn_ip_nodes[DPO_PROTO_NUM] = { - [DPO_PROTO_IP4] = hicn_face_ip4dpoi_nodes, - [DPO_PROTO_IP6] = hicn_face_ip6dpoi_nodes -}; - -const static dpo_vft_t hicn_face_ip_vft = { - .dv_lock = hicn_face_lock, - .dv_unlock = hicn_face_unlock, - .dv_format = format_hicn_face_ip, -}; - -/* Must be executed after all the strategy nodes are created */ -void -hicn_dpo_ip_module_init (void) -{ - mhash_init (&hicn_face_ip_local_hashtb, - sizeof (hicn_face_ip_input_faces_t) /* value */ , - sizeof (hicn_face_ip_key_t) /* key */ ); - mhash_init (&hicn_face_ip_remote_hashtb, - sizeof (hicn_face_id_t) /* value */ , - sizeof (hicn_face_ip_key_t) /* key */ ); - - pool_alloc(hicn_vec_pool, 100); - - /* - * How much useful is the following registration? - * So far it seems that we need it only for setting the dpo_type. - */ - hicn_face_ip_type = - dpo_register_new_type (&hicn_face_ip_vft, hicn_ip_nodes); -} - -void -hicn_dpo_ip_create_from_face (hicn_face_t * face, dpo_id_t * dpo, - u16 dpoi_next_node) -{ - hicn_face_id_t face_dpoi_id = hicn_dpoi_get_index (face); - hicn_face_ip_t *ip_face = (hicn_face_ip_t *) face->data; - dpo_set (dpo, face->shared.face_type, - ip46_address_is_ip4 (&ip_face->local_addr) ? DPO_PROTO_IP4 : - DPO_PROTO_IP6, face_dpoi_id); - dpo->dpoi_next_node = dpoi_next_node; -} - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/hicn-plugin/src/faces/ip/face_ip.c b/hicn-plugin/src/faces/ip/face_ip.c deleted file mode 100644 index a2fe069ed..000000000 --- a/hicn-plugin/src/faces/ip/face_ip.c +++ /dev/null @@ -1,571 +0,0 @@ -/* - * 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/adj/adj_midchain.h> -#include <vnet/adj/adj.h> - -#include "face_ip.h" -#include "face_ip_node.h" -#include "dpo_ip.h" -#include "../../strategy_dpo_manager.h" -#include "../face.h" -#include "../../cache_policies/cs_lru.h" -#include "../../infra.h" -#include "../../hicn.h" -#include "../app/face_prod.h" -#include "../app/face_cons.h" - -#include "../../mapme.h" // HICN_MAPME_EVENT_* -#include "../../mapme_eventmgr.h" // hicn_mapme_eventmgr_process_node - -extern vlib_node_registration_t hicn_mapme_eventmgr_process_node; - -u32 strategy_face_ip4_vlib_edge; -u32 strategy_face_ip6_vlib_edge; - -void -hicn_face_ip_init (vlib_main_t * vm) -{ - int strategy_nodes_n = hicn_strategy_get_all_available (); - - /* Default Strategy has index 0 and it always exists */ - strategy_face_ip4_vlib_edge = vlib_node_add_next (vm, - hicn_strategy_node.index, - hicn_face_ip4_output_node.index); - - strategy_face_ip6_vlib_edge = vlib_node_add_next (vm, - hicn_strategy_node.index, - hicn_face_ip6_output_node.index); - /* - * Create and edge between al the other strategy nodes and the - * ip_encap nodes. - */ - for (int i = 1; i < strategy_nodes_n; i++) - { - u32 temp_index4 = vlib_node_add_next (vm, - hicn_strategy_node.index, - hicn_face_ip4_output_node.index); - u32 temp_index6 = vlib_node_add_next (vm, - 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); - } - - u32 temp_index4 = vlib_node_add_next (vm, - hicn_interest_hitpit_node.index, - hicn_face_ip4_output_node.index); - u32 temp_index6 = vlib_node_add_next (vm, - hicn_interest_hitpit_node.index, - hicn_face_ip6_output_node.index); - - ASSERT (temp_index4 == strategy_face_ip4_vlib_edge); - ASSERT (temp_index6 == strategy_face_ip6_vlib_edge); - - - hicn_dpo_ip_module_init (); - - register_face_type (hicn_face_ip_type, &ip_vft, "ip"); -} - -int -hicn_face_ip_del (hicn_face_id_t face_id) -{ - hicn_face_t *face = hicn_dpoi_get_from_idx (face_id); - hicn_face_ip_t *face_ip = (hicn_face_ip_t *) face->data; - hicn_face_ip_key_t key; - hicn_face_ip_key_t old_key; - hicn_face_ip_key_t old_key2; - - if (ip46_address_is_ip4 (&face_ip->local_addr)) - { - 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); - 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); - } - } - 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); - 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); - } - } - return hicn_face_del (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) -{ - vnet_buffer (b0)->sw_if_index[VLIB_TX] = 0; -}; - -/** - * @brief Build a rewrite string for the face. - */ -static u8 * -face_build_rewrite_i (void) -{ - /* - * passing the adj code a NULL rewrite means 'i don't have one cos - * t'other end is unresolved'. That's not the case here. For the mpls - * tunnel there are just no bytes of encap to apply in the adj. We'll impose - * the label stack once we choose a path. So return a zero length rewrite. - */ - u8 *rewrite = NULL; - - 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) -{ - 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); - - 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); - - 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; - - *adj = fib_entry_get_adj (fib_entry_index); - ip_adjacency_t *temp = NULL; - if (*adj != ~0) - 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; - } - 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); - } - } - - return HICN_ERROR_NONE; -} - -/* - * Utility that adds a new face cache entry. For the moment we assume that - * the ip_adjacency has already been set up. - */ -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) -{ - dpo_proto_t dpo_proto; - - /* Check if we found at least one ip address */ - if (ip46_address_is_zero (remote_addr)) - return HICN_ERROR_FACE_NO_GLOBAL_IP; - - hicn_face_flags_t flags = (hicn_face_flags_t) 0; - flags |= HICN_FACE_FLAGS_FACE; - - hicn_face_t *face; - if (ip46_address_is_ip4 (local_addr)) - { - face = - hicn_face_ip4_get (&(remote_addr->ip4), sw_if, - &hicn_face_ip_remote_hashtb); - - /* If remote matches the face we need to check if it is an incomplete face */ - if (face == NULL) - { - hicn_iface_ip_add (local_addr, remote_addr, sw_if, pfaceid); - face = hicn_dpoi_get_from_idx (*pfaceid); - } - else - { - *pfaceid = hicn_dpoi_get_index (face); - } - - if (!(face->shared.flags & HICN_FACE_FLAGS_IFACE)) - 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_ip4_get_vec (&(local_addr->ip4), sw_if, - &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); - } - 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; - } - } - } - else - { - face = - hicn_face_ip6_get (&(remote_addr->ip6), sw_if, - &hicn_face_ip_remote_hashtb); - - /* If remote matches the face is a iface */ - if (face == NULL) - { - hicn_iface_ip_add (local_addr, remote_addr, sw_if, pfaceid); - face = hicn_dpoi_get_from_idx (*pfaceid); - } - else - { - *pfaceid = hicn_dpoi_get_index (face); - } - - if (!(face->shared.flags & HICN_FACE_FLAGS_IFACE)) - 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_ip6_get_vec (&(local_addr->ip6), sw_if, - &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); - } - 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; - } - } - } - - retx_t *retx = vlib_process_signal_event_data (vlib_get_main (), - hicn_mapme_eventmgr_process_node.index, - HICN_MAPME_EVENT_FACE_ADD, 1, - sizeof (retx_t)); - - /* *INDENT-OFF* */ - *retx = (retx_t) - { - .prefix = 0, - .dpo = (dpo_id_t) - { - .dpoi_type = hicn_face_ip_type, - .dpoi_proto = dpo_proto, - .dpoi_next_node = 0, - .dpoi_index = *pfaceid, - } - }; - /* *INDENT-ON* */ - - return HICN_ERROR_NONE; -} - -u8 * -format_hicn_face_ip (u8 * s, va_list * args) -{ - index_t index = va_arg (*args, index_t); - CLIB_UNUSED (u32 indent) = va_arg (*args, u32); - hicn_face_t *face; - hicn_face_ip_t *ip_face; - ip_adjacency_t *adj; - vnet_main_t *vnm = vnet_get_main (); - - face = hicn_dpoi_get_from_idx (index); - ip_face = (hicn_face_ip_t *) face->data; - - if (face->shared.flags & HICN_FACE_FLAGS_FACE) - { - ASSERT (face->shared.adj != (adj_index_t) ~ 0); - adj = adj_get (face->shared.adj); - - hicn_face_id_t face_id = hicn_dpoi_get_index (face); - s = format (s, "%U Face %d: ", format_white_space, indent, face_id); - s = format (s, "type IP local %U ", - format_ip46_address, &ip_face->local_addr, IP46_TYPE_ANY); - s = - format (s, "remote %U ", format_ip46_address, &ip_face->remote_addr, - IP46_TYPE_ANY); - s = format (s, "%U", format_vnet_link, adj->ia_link); - - vnet_sw_interface_t *sw_int = - vnet_get_sw_interface_or_null (vnm, face->shared.sw_if); - if (sw_int != NULL) - s = format (s, " dev %U", format_vnet_sw_interface_name, vnm, sw_int); - - - if ((face->shared.flags & HICN_FACE_FLAGS_APPFACE_PROD)) - s = format (s, " %U", format_hicn_face_prod, face_id, 0); - else if ((face->shared.flags & HICN_FACE_FLAGS_APPFACE_CONS)) - s = format (s, " %U", format_hicn_face_cons, face_id, 0); - - if ((face->shared.flags & HICN_FACE_FLAGS_DELETED)) - s = format (s, " (deleted)"); - } - else - { - hicn_face_id_t face_id = hicn_dpoi_get_index (face); - s = format (s, "%U iFace %d: ", format_white_space, indent, face_id); - s = format (s, "type IP local %U remote %U", - format_ip46_address, &ip_face->local_addr, IP46_TYPE_ANY, - format_ip46_address, &ip_face->remote_addr, IP46_TYPE_ANY); - - vnet_sw_interface_t *sw_int = - vnet_get_sw_interface_or_null (vnm, face->shared.sw_if); - if (sw_int != NULL) - s = format (s, " dev %U", format_vnet_sw_interface_name, vnm, sw_int); - - if ((face->shared.flags & HICN_FACE_FLAGS_APPFACE_PROD)) - s = format (s, " %U", format_hicn_face_prod, face_id, 0); - else if ((face->shared.flags & HICN_FACE_FLAGS_APPFACE_CONS)) - s = format (s, " %U", format_hicn_face_cons, face_id, 0); - - if ((face->shared.flags & HICN_FACE_FLAGS_DELETED)) - s = format (s, " (deleted)"); - } - - return s; -} - -void -hicn_face_ip_get_dpo (hicn_face_t * face, dpo_id_t * dpo) -{ - - hicn_face_ip_t *face_ip = (hicn_face_ip_t *) face->data; - return hicn_dpo_ip_create_from_face (face, dpo, - ip46_address_is_ip4 - (&face_ip->remote_addr) ? - strategy_face_ip4_vlib_edge : - strategy_face_ip6_vlib_edge); -} - -hicn_face_vft_t ip_vft = { - .format_face = format_hicn_face_ip, - .hicn_face_del = hicn_face_ip_del, - .hicn_face_get_dpo = hicn_face_ip_get_dpo, -}; - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/hicn-plugin/src/faces/ip/face_ip.h b/hicn-plugin/src/faces/ip/face_ip.h deleted file mode 100644 index 74f3a83dc..000000000 --- a/hicn-plugin/src/faces/ip/face_ip.h +++ /dev/null @@ -1,310 +0,0 @@ -/* - * 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_FACE_IP_H__ -#define __HICN_FACE_IP_H__ - -#include <vlib/vlib.h> -#include <vnet/vnet.h> -#include "../face.h" -#include "../../cache_policies/cs_policy.h" - -/** - * @file - * - * @brief IP face - * - * A face is carried through nodes as a dpo. The face state is the object - * pointed by the dpoi_index in the dpo_id_t (see - * https://docs.fd.io/vpp/18.07/d0/d37/dpo_8h_source.html) - */ -typedef struct hicn_ip_face_t_ -{ - /** - * The headers to paint, in packet painting order - */ - /* Local address of the interface sw_if */ - ip46_address_t local_addr; - - /* Remote address of neighbor */ - ip46_address_t remote_addr; - -} hicn_face_ip_t; - -/** - * @bried vector of faces used to collect faces having the same local address - * - */ -typedef hicn_face_id_t *hicn_face_ip_vec_t; - -typedef struct hicn_ip_input_faces_s_ -{ - /* Vector of all possible input faces */ - u32 vec_id; - - /* Preferred face. If an prod_app face is in the vector it will be the preferred one. */ - /* It's not possible to have multiple prod_app face in the same vector, they would have */ - /* the same local address. Every prod_app face is a point-to-point face between the forwarder */ - /* and the application. */ - hicn_face_id_t face_id; - -} hicn_face_ip_input_faces_t; - -/** - * Hash tables that indexes a face by local address. For fast lookup when an - * data arrives. - */ -extern mhash_t hicn_face_ip_local_hashtb; - -/** - * Hash tables that indexes a face by remote address. For fast lookup when an - * interest arrives. - */ -extern mhash_t hicn_face_ip_remote_hashtb; - -/** - * Pool containing the vector of possible incoming faces. - */ -extern hicn_face_ip_vec_t *hicn_vec_pool; - -/** - * Key definition for the mhash table. An ip face is uniquely identified by ip - * address and the interface id. The ip address can correspond to the remote ip - * address of the next hicn hop, or to the local address of the receiving - * interface. The former is used to retrieve the incoming face when an interest - * is received, the latter when the arring packet is a data. - */ -typedef struct hicn_face_ip_key_s -{ - ip46_address_t addr; - u32 sw_if; -} hicn_face_ip_key_t; - - -extern hicn_face_type_t hicn_face_ip_type; -extern hicn_face_vft_t ip_vft; - -/** - * @brief Create the key object for the mhash. Fill in the key object with the - * expected values. - * - * @param addr Local or remote ip v6 address of the face - * @param sw_if interface associated to the face - * @param key Pointer to an allocated hicn_face_ip_key_t object - */ -always_inline void -hicn_face_ip6_get_key (const ip6_address_t * addr, - u32 sw_if, hicn_face_ip_key_t * key) -{ - key->addr.ip6 = *addr; - key->sw_if = sw_if; -} - - -/** - * @brief Create the key object for the mhash. Fill in the key object with the - * expected values. - * - * @param addr Local or remote ip v4 address of the face - * @param sw_if interface associated to the face - * @param key Pointer to an allocated hicn_face_ip_key_t object - */ -always_inline void -hicn_face_ip4_get_key (const ip4_address_t * addr, - u32 sw_if, hicn_face_ip_key_t * key) -{ - ip46_address_set_ip4 (&(key->addr), addr); - key->sw_if = sw_if; -} - -/** - * @brief Get the dpoi from the ip v4 address. Does not add any lock. - * - * @param addr Ip v4 address used to create the key for the hash table. - * @param sw_if Software interface id used to create the key for the hash table. - * @param hashtb Hash table (remote or local) where to perform the lookup. - * - * @result Pointer to the face. - */ -always_inline hicn_face_t * -hicn_face_ip4_get (const ip4_address_t * addr, u32 sw_if, mhash_t * hashtb) -{ - hicn_face_ip_key_t key; - - hicn_face_ip4_get_key (addr, sw_if, &key); - - hicn_face_id_t *dpoi_index = (hicn_face_id_t *) mhash_get (hashtb, - &key); - - return dpoi_index == NULL ? NULL : hicn_dpoi_get_from_idx (*dpoi_index); -} - -/** - * @brief Get the vector of faces from the ip v4 address. Does not add any lock. - * - * @param addr Ip v4 address used to create the key for the hash table. - * @param sw_if Software interface id used to create the key for the hash table. - * @param hashtb Hash table (remote or local) where to perform the lookup. - * - * @result Pointer to the face. - */ -always_inline hicn_face_ip_input_faces_t * -hicn_face_ip4_get_vec (const ip4_address_t * addr, u32 sw_if, - mhash_t * hashtb) -{ - hicn_face_ip_key_t key; - - hicn_face_ip4_get_key (addr, sw_if, &key); - return (hicn_face_ip_input_faces_t *) mhash_get (hashtb, &key); -} - -/** - * @brief Get the vector of faces from the ip v6 address. Does not add any lock. - * - * @param addr Ip v6 address used to create the key for the hash table. - * @param sw_if Software interface id used to create the key for the hash table. - * @param hashtb Hash table (remote or local) where to perform the lookup. - * - * @result Pointer to the face. - */ -always_inline hicn_face_ip_input_faces_t * -hicn_face_ip6_get_vec (const ip6_address_t * addr, u32 sw_if, - mhash_t * hashtb) -{ - hicn_face_ip_key_t key; - - hicn_face_ip6_get_key (addr, sw_if, &key); - return (hicn_face_ip_input_faces_t *) mhash_get (hashtb, &key); -} - -/** - * @brief Get the dpoi from the ip v6 address. Does not add any lock. - * - * @param addr Ip v6 address used to create the key for the hash table. - * @param sw_if Software interface id used to create the key for the hash table. - * @param hashtb Hash table (remote or local) where to perform the lookup. - * - * @result Pointer to the face. - */ -always_inline hicn_face_t * -hicn_face_ip6_get (const ip6_address_t * addr, u32 sw_if, mhash_t * hashtb) -{ - hicn_face_ip_key_t key; - - hicn_face_ip6_get_key (addr, sw_if, &key); - - hicn_face_id_t *dpoi_index = (hicn_face_id_t *) mhash_get (hashtb, - &key); - - return dpoi_index == NULL ? NULL : hicn_dpoi_get_from_idx (*dpoi_index); -} - -/** - * @brief Create a new face ip. API for other modules (e.g., routing) - * - * @param local_addr Local ip v4 or v6 address of the face - * @param remote_addr Remote ip v4 or v6 address of the face - * @param sw_if interface associated to the face - * @param is_app_face Boolean to set the face as an application face - * @param pfaceid Pointer to return the face id - * @param is_app_prod if HICN_FACE_FLAGS_APPFACE_PROD the face is a local application face, all other values are ignored - * @return HICN_ERROR_FACE_NO_GLOBAL_IP if the face does not have a globally - * reachable ip address, otherwise HICN_ERROR_NONE - */ -int hicn_face_ip_add (const ip46_address_t * local_addr, - const ip46_address_t * remote_addr, - int swif, hicn_face_id_t * pfaceid, u8 is_app_prod); - -/** - * @brief Create a new incomplete face ip. (Meant to be used by the data plane) - * - * @param local_addr Local ip v4 or v6 address of the face - * @param remote_addr Remote ip v4 or 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_ip_add (const ip46_address_t * local_addr, - const ip46_address_t * remote_addr, - int sw_if, hicn_face_id_t * pfaceid) -{ - hicn_face_t *face; - pool_get (hicn_dpoi_face_pool, face); - - hicn_face_ip_t *ip_face = (hicn_face_ip_t *) (face->data); - - clib_memcpy (&(ip_face->local_addr.ip6), local_addr, - sizeof (ip6_address_t)); - clib_memcpy (&(ip_face->remote_addr.ip6), remote_addr, - sizeof (ip6_address_t)); - face->shared.sw_if = sw_if; - - face->shared.adj = ADJ_INDEX_INVALID; - face->shared.pl_id = (u16) 0; - face->shared.face_type = hicn_face_ip_type; - face->shared.flags = HICN_FACE_FLAGS_IFACE; - face->shared.locks = 1; - - hicn_face_ip_key_t key; - hicn_face_ip6_get_key (&(remote_addr->ip6), sw_if, &key); - *pfaceid = hicn_dpoi_get_index (face); - - mhash_set_mem (&hicn_face_ip_remote_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 - * @return HICN_ERROR_FACE_NOT_FOUND if the face does not exist, otherwise - * HICN_ERROR_NONE - */ -int hicn_face_ip_del (hicn_face_id_t face_id); - -/** - * @brief Format a IP face - * - * @param s Pointer to a previous string. If null it will be initialize - * @param args Array storing input values. Expected u32 face_id and u32 indent - * @return String with the formatted face - */ -u8 *format_hicn_face_ip (u8 * s, va_list * args); - -/** - * @brief Create a dpo from an ip face - * - * @param face Face from which to create the dpo - * @return the dpo - */ -void hicn_face_ip_get_dpo (hicn_face_t * face, dpo_id_t * dpo); - -#endif // __HICN_FACE_IP_H__ - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/hicn-plugin/src/faces/ip/face_ip_cli.c b/hicn-plugin/src/faces/ip/face_ip_cli.c deleted file mode 100644 index 4c4986f97..000000000 --- a/hicn-plugin/src/faces/ip/face_ip_cli.c +++ /dev/null @@ -1,208 +0,0 @@ -/* - * 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 "face_ip.h" -#include "dpo_ip.h" -#include "../face.h" - -#define HICN_FACE_NONE 0 -#define HICN_FACE_DELETE 1 -#define HICN_FACE_ADD 2 - -static clib_error_t * -hicn_face_ip_cli_set_command_fn (vlib_main_t * vm, - unformat_input_t * main_input, - vlib_cli_command_t * cmd) -{ - vnet_main_t *vnm = vnet_get_main (); - ip46_address_t local_addr; - ip46_address_t remote_addr; - hicn_face_id_t face_id = HICN_FACE_NULL; - int ret = HICN_ERROR_NONE; - int sw_if; - int face_op = HICN_FACE_NONE; - - ip46_address_reset (&local_addr); - /* Get a line of input. */ - unformat_input_t _line_input, *line_input = &_line_input; - if (!unformat_user (main_input, unformat_line_input, line_input)) - { - return (0); - } - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "del")) - { - if (unformat (line_input, "id %d", &face_id)) - face_op = HICN_FACE_DELETE; - else - { - return clib_error_return (0, "missing face id"); - } - } - else if (unformat (line_input, "add")) - { - face_op = HICN_FACE_ADD; - if (unformat (line_input, "local %U", - unformat_ip46_address, &local_addr, IP46_TYPE_ANY)); - - if (unformat (line_input, "remote %U intfc %U", - unformat_ip46_address, &remote_addr, - IP46_TYPE_ANY, unformat_vnet_sw_interface, vnm, - &sw_if)); - else - { - return clib_error_return (0, "%s '%U'", - get_error_string - (HICN_ERROR_CLI_INVAL), - format_unformat_error, line_input); - } - } - else - { - return clib_error_return (0, "%s '%U'", - get_error_string (HICN_ERROR_CLI_INVAL), - format_unformat_error, line_input); - } - } - - if (face_id != HICN_FACE_NULL) - { - - if (!hicn_dpoi_idx_is_valid (face_id)) - { - return clib_error_return (0, "%s, face_id %d not valid", - get_error_string (ret), face_id); - } - } - - int rv; - switch (face_op) - { - case HICN_FACE_ADD: - - /* Check for presence of next hop address */ - if ((remote_addr.as_u64[0] == (u64) 0) - && (remote_addr.as_u64[1] == (u64) 0)) - { - return clib_error_return (0, "next hop address not specified"); - } - - if (ip46_address_is_zero (&local_addr)) - { - if (!vnet_sw_interface_is_valid (vnm, sw_if)) - return clib_error_return (0, "interface not valid"); - - if (ip46_address_is_ip4 (&remote_addr)) - { - ip_interface_address_t *interface_address; - ip4_address_t *addr = - ip4_interface_address_matching_destination (&ip4_main, - &remote_addr.ip4, - sw_if, - &interface_address); - - if (addr == NULL) - addr = ip4_interface_first_address (&ip4_main, - sw_if, - &interface_address); - - if (addr == NULL) - return clib_error_return (0, - "no valid ip address on interface %d", - sw_if); - - ip46_address_set_ip4 (&local_addr, addr); - } - else - { - ip_interface_address_t *interface_address; - ip6_interface_address_matching_destination (&ip6_main, - &remote_addr.ip6, - sw_if, - &interface_address); - - ip6_address_t *addr = NULL; - if (interface_address != NULL) - addr = - (ip6_address_t *) - ip_interface_address_get_address (&ip6_main.lookup_main, - interface_address); - - if (addr == NULL) - addr = ip6_interface_first_address (&ip6_main, sw_if); - - if (addr == NULL) - return clib_error_return (0, - "no valid ip address on interface %d", - sw_if); - - ip46_address_set_ip6 (&local_addr, addr); - } - } - - rv = hicn_face_ip_add (&local_addr, &remote_addr, sw_if, &face_id, 0); - - if (rv == HICN_ERROR_NONE) - { - vlib_cli_output (vm, "Face id: %d", face_id); - } - else - { - return clib_error_return (0, get_error_string (rv)); - } - break; - case HICN_FACE_DELETE: - rv = hicn_face_ip_del (face_id); - if (rv == HICN_ERROR_NONE) - { - vlib_cli_output (vm, "Face %d deleted", face_id); - } - else - { - return clib_error_return (0, get_error_string (rv)); - } - break; - default: - return clib_error_return (0, "Operation (%d) not implemented", face_op); - break; - } - return (rv == HICN_ERROR_NONE) ? 0 : clib_error_return (0, "%s\n", - get_error_string - (rv)); -} - -/* cli declaration for 'cfg face' */ -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (hicn_face_ip_cli_set_command, static) = -{ - .path = "hicn face ip", - .short_help = "hicn face ip {add [local <src_address>] remote <dst_address> intfc <sw_if>} | {del id <face_id>}", - .function = hicn_face_ip_cli_set_command_fn, -}; -/* *INDENT-ON* */ - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/hicn-plugin/src/faces/ip/face_ip_node.h b/hicn-plugin/src/faces/ip/face_ip_node.h deleted file mode 100644 index 000395a04..000000000 --- a/hicn-plugin/src/faces/ip/face_ip_node.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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_FACE_IP_NODE_H__ -#define __HICN_FACE_IP_NODE_H__ - -#include <vlib/vlib.h> -#include <vnet/vnet.h> - -extern vlib_node_registration_t hicn_face_ip4_input_node; -extern vlib_node_registration_t hicn_face_ip4_output_node; -extern vlib_node_registration_t hicn_face_ip6_input_node; -extern vlib_node_registration_t hicn_face_ip6_output_node; - -/** - * @brief Initialize the ip face module - */ -void hicn_face_ip_init (vlib_main_t * vm); - -#endif // __HICN_FACE_IP_NODE_H__ - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/hicn-plugin/src/faces/udp/dpo_udp.c b/hicn-plugin/src/faces/udp/dpo_udp.c deleted file mode 100644 index 987d52bb7..000000000 --- a/hicn-plugin/src/faces/udp/dpo_udp.c +++ /dev/null @@ -1,157 +0,0 @@ -/* - * 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 "dpo_udp.h" - -#include <vnet/ip/format.h> -#include <vnet/adj/adj.h> -#include <vnet/vnet.h> -#include <vlib/vlib.h> - -const static char *const hicn_face_ip4udp_nodes[] = { - "hicn-face-encap-udp4", - "hicn-face-decap-udp4", - "hicn-iface-decap-udp4", - "hicn-iface-encap-udp4", - NULL, -}; - -const static char *const hicn_face_ip6udp_nodes[] = { - "hicn-face-encap-udp6", - "hicn-face-decap-udp6", - "hicn-iface-decap-udp6", - "hicn-iface-encap-udp6", - NULL, -}; - -const static char *const *const hicn_ipudp_nodes[DPO_PROTO_NUM] = { - [DPO_PROTO_IP4] = hicn_face_ip4udp_nodes, - [DPO_PROTO_IP6] = hicn_face_ip6udp_nodes -}; - - -const static dpo_vft_t hicn_dpoi_udp_vft = { - .dv_lock = hicn_face_lock, - .dv_unlock = hicn_face_unlock, - .dv_format = format_hicn_face_udp, -}; - -/* Must be executed after all the strategy nodes are created */ -void -hicn_dpo_udp_module_init (void) -{ - mhash_init (&hicn_face_udp_hashtb, sizeof (hicn_face_id_t) /* value */ , - sizeof (hicn_face_udp_key_t) /* key */ ); - - /* - * How much useful is the following registration? - * So far it seems that we need it only for setting the dpo_type. - */ - hicn_face_udp_type = - dpo_register_new_type (&hicn_dpoi_udp_vft, hicn_ipudp_nodes); -} - - -/* Here udp ports are in host order, move them to network order to do the lookup */ -int -hicn_dpo_udp4_create (dpo_id_t * dpo, - const ip4_address_t * src_ip, - const ip4_address_t * dst_ip, - u16 src_port, u16 dst_port, - u32 sw_if, - adj_index_t ip_adj, - u32 node_index, - hicn_face_flags_t flags, hicn_face_id_t * face_id) -{ - u16 net_src_port = clib_host_to_net_u16 (src_port); - u16 net_dst_port = clib_host_to_net_u16 (dst_port); - hicn_face_t *face = - hicn_face_udp4_get (src_ip, dst_ip, net_src_port, net_dst_port); - - u8 hicnb_flags; - /* ip_csum_t sum0; */ - - if (face != NULL) - return HICN_ERROR_FACE_ALREADY_CREATED; - - hicn_dpo_udp4_add_and_lock (dpo, src_ip, dst_ip, net_src_port, net_dst_port, - node_index, &hicnb_flags, sw_if); - - face = hicn_dpoi_get_from_idx (dpo->dpoi_index); - - hicn_face_udp_t *udp_face = (hicn_face_udp_t *) face->data; - - udp_face->hdrs.ip4.ip.checksum = - ip4_header_checksum (&(udp_face->hdrs.ip4.ip)); - - face->shared.flags = flags; - face->shared.adj = ip_adj; - *face_id = hicn_dpoi_get_index (face); - - return HICN_ERROR_NONE; -} - - -int -hicn_dpo_udp6_create (dpo_id_t * dpo, - const ip6_address_t * src_ip, - const ip6_address_t * dst_ip, - u16 src_port, u16 dst_port, - u32 sw_if, - adj_index_t ip_adj, - u32 node_index, - hicn_face_flags_t flags, hicn_face_id_t * face_id) -{ - u16 net_src_port = clib_host_to_net_u16 (src_port); - u16 net_dst_port = clib_host_to_net_u16 (dst_port); - hicn_face_t *face = - hicn_face_udp6_get (src_ip, dst_ip, net_src_port, net_dst_port); - u8 hicnb_flags; - - if (face != NULL) - return HICN_ERROR_FACE_ALREADY_CREATED; - - hicn_dpo_udp6_add_and_lock (dpo, src_ip, dst_ip, net_src_port, net_dst_port, - node_index, &hicnb_flags, sw_if); - - face = hicn_dpoi_get_from_idx (dpo->dpoi_index); - - face->shared.flags = flags; - face->shared.adj = ip_adj; - *face_id = hicn_dpoi_get_index (face); - - return HICN_ERROR_NONE; -} - -void -hicn_dpo_udp_create_from_face (hicn_face_t * face, dpo_id_t * dpo, - u16 dpoi_next_node) -{ - hicn_face_id_t face_dpoi_id = hicn_dpoi_get_index (face); - hicn_face_udp_t *face_udp = (hicn_face_udp_t *) face->data; - u8 version = - (face_udp->hdrs.ip4.ip.ip_version_and_header_length & 0xf0) >> 4; - dpo_set (dpo, face->shared.face_type, - version == 4 ? DPO_PROTO_IP4 : DPO_PROTO_IP6, face_dpoi_id); - dpo->dpoi_next_node = dpoi_next_node; -} - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/hicn-plugin/src/faces/udp/dpo_udp.h b/hicn-plugin/src/faces/udp/dpo_udp.h deleted file mode 100644 index 98abf3d29..000000000 --- a/hicn-plugin/src/faces/udp/dpo_udp.h +++ /dev/null @@ -1,289 +0,0 @@ -/* - * 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_UDP_H__ -#define __HICN_DPO_UDP_H__ - -#include <vnet/adj/adj_types.h> -#include <vnet/ip/ip4_packet.h> -#include <vnet/ip/ip6_packet.h> - -#include "face_udp.h" -#include "../face.h" -#include "../../error.h" - -extern u32 strategy_face_udp4_vlib_edge; -extern u32 strategy_face_udp6_vlib_edge; - - -/** - * @brief Initialize the internal structures of the dpo udp face module. - */ -void hicn_dpo_udp_module_init (void); - -/** - * @brief Create a udp face and its corresponding dpo. Meant to be used for the - * control plane. - * - * @param dpo: Data plane object that point to the face created. - * @param local_addr: Local address of the UDP tunnel - * @param remote_addr: Remote address of the UDP tunnel - * @param local_port: Local port of the UDP tunnel - * @param remote_port: Remote port of the UDP tunnel - * @param adj: Ip adjacency corresponding to the remote address in the face - * @param node_index: vlib edge index to use in the packet processing - * @param flags: Flags of the face - * @param face_id: Identifier for the face (dpoi_index) - * @return HICN_ERROR_FACE_ALREADY_CREATED if the face exists, otherwise HICN_ERROR_NONE - */ -int -hicn_dpo_udp4_create (dpo_id_t * dpo, - const ip4_address_t * local_addr, - const ip4_address_t * remote_addr, - u16 local_port, u16 remote_port, - u32 sw_if, - adj_index_t adj, - u32 node_index, - hicn_face_flags_t flags, hicn_face_id_t * face_id); - -/** - * @brief Retrieve a face using the face identifier, i.e., the quadruplet (local_addr, remote_addr, - * local_port, remote_port). This method adds a lock on the face state. - * - * @param dpo: Result of the lookup. If the face doesn't exist dpo = NULL - * @param local_addr: Local address of the UDP tunnel - * @param remote_addr: Remote address of the UDP tunnel - * @param local_port: Local port of the UDP tunnel - * @param remote_port: Remote port of the UDP tunnel - * @param hicnb_flags: Flags that indicate whether the face is an application - * face or not in the hicn_buffer. (Currently only IP faces can be appface) - * - * @result HICN_ERROR_FACE_NOT_FOUND if the face does not exist, otherwise HICN_ERROR_NONE. - */ -always_inline int -hicn_dpo_udp4_lock (dpo_id_t * dpo, - const ip4_address_t * local_addr, - const ip4_address_t * remote_addr, - u16 local_port, u16 remote_port, u8 * hicnb_flags) -{ - dpo->dpoi_type = DPO_FIRST; - dpo->dpoi_proto = DPO_PROTO_NONE; - dpo->dpoi_index = INDEX_INVALID; - dpo->dpoi_next_node = 0; - - hicn_face_t *face = - hicn_face_udp4_get (local_addr, remote_addr, local_port, remote_port); - - if (PREDICT_FALSE (face == NULL)) - return HICN_ERROR_FACE_NOT_FOUND; - - index_t dpoi_index = hicn_dpoi_get_index (face); - dpo_set (dpo, hicn_face_udp_type, DPO_PROTO_IP4, dpoi_index); - dpo->dpoi_next_node = strategy_face_udp4_vlib_edge; - dpo_unlock (dpo); - - *hicnb_flags = HICN_BUFFER_FLAGS_DEFAULT; - - return HICN_ERROR_NONE; -} - -/** - * @brief Retrieve, or create if it doesn't exist, a face from the face - * identifier (local_addr, remote_addr, local_port, remote_port) and returns its - * dpo. This method adds a lock on the face state. - * - * @param dpo: Result of the lookup - * @param local_addr: Local address of the UDP tunnel - * @param remote_addr: Remote address of the UDP tunnel - * @param local_port: Local port of the UDP tunnel - * @param remote_port: Remote port of the UDP tunnel - * @param hicnb_flags: Flags that indicate whether the face is an application - * face or not. (Currently only IP faces can be appface) - * @param node_index: vlib edge index to use in the packet processing - */ -always_inline void -hicn_dpo_udp4_add_and_lock (dpo_id_t * dpo, - const ip4_address_t * local_addr, - const ip4_address_t * remote_addr, - u16 local_port, u16 remote_port, - u32 node_index, u8 * hicnb_flags, u32 sw_if) -{ - dpo->dpoi_type = DPO_FIRST; - dpo->dpoi_proto = DPO_PROTO_NONE; - dpo->dpoi_index = INDEX_INVALID; - dpo->dpoi_next_node = 0; - - hicn_face_t *face = - hicn_face_udp4_get (local_addr, remote_addr, local_port, remote_port); - - if (face == NULL) - { - - 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); - dpo->dpoi_next_node = node_index; - dpo_unlock (dpo); - - return; - } - - *hicnb_flags = HICN_BUFFER_FLAGS_DEFAULT; - - hicn_face_id_t dpoi_index = hicn_dpoi_get_index (face); - dpo_set (dpo, hicn_face_udp_type, DPO_PROTO_IP4, dpoi_index); - dpo->dpoi_next_node = node_index; - dpo_unlock (dpo); -} - -/** - * @brief Create a udp face and its corresponding dpo. Meant to be used for the - * control plane. - * - * @param dpo: Data plane object that point to the face created. - * @param local_addr: Local address of the UDP tunnel - * @param remote_addr: Remote address of the UDP tunnel - * @param local_port: Local port of the UDP tunnel - * @param remote_port: Remote port of the UDP tunnel - * @param adj: Ip adjacency corresponding to the remote address in the face - * @param node_index: vlib edge index to use in the packet processing - * @param flags: Flags of the face - * @param face_id: Identifier for the face (dpoi_index) - * @return HICN_ERROR_FACE_ALREADY_CREATED if the face exists, otherwise HICN_ERROR_NONE - */ -int -hicn_dpo_udp6_create (dpo_id_t * dpo, - const ip6_address_t * local_addr, - const ip6_address_t * remote_addr, - u16 local_port, u16 remote_port, - u32 sw_if, - adj_index_t adj, - u32 node_index, - hicn_face_flags_t flags, hicn_face_id_t * face_id); - - -/** - * @brief Retrieve a face using the face identifier, i.e., the quadruplet (local_addr, remote_addr, - * local_port, remote_port). This method adds a lock on the face state. - * - * @param dpo: Result of the lookup. If the face doesn't exist dpo = NULL - * @param local_addr: Local address of the UDP tunnel - * @param remote_addr: Remote address of the UDP tunnel - * @param local_port: Local port of the UDP tunnel - * @param remote_port: Remote port of the UDP tunnel - * @param hicnb_flags: Flags that indicate whether the face is an application - * face or not. (Currently only IP faces can be appface) - * - * @result HICN_ERROR_FACE_NOT_FOUND if the face does not exist, otherwise HICN_ERROR_NONE. - */ -always_inline int -hicn_dpo_udp6_lock (dpo_id_t * dpo, - const ip6_address_t * local_addr, - const ip6_address_t * remote_addr, - u16 local_port, u16 remote_port, u8 * hicnb_flags) -{ - dpo->dpoi_type = DPO_FIRST; - dpo->dpoi_proto = DPO_PROTO_NONE; - dpo->dpoi_index = INDEX_INVALID; - dpo->dpoi_next_node = 0; - - hicn_face_t *face = - hicn_face_udp6_get (local_addr, remote_addr, local_port, remote_port); - - - if (PREDICT_FALSE (face == NULL)) - 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_IP6, dpoi_index); - dpo->dpoi_next_node = strategy_face_udp6_vlib_edge; - dpo_unlock (dpo); - *hicnb_flags = HICN_BUFFER_FLAGS_DEFAULT; - - return HICN_ERROR_NONE; -} - -/** - * @brief Retrieve, or create if it doesn't exist, a face from the face - * identifier (local_addr, remote_addr, local_port, remote_port) and returns its - * dpo. This method adds a lock on the face state. - * - * @param dpo: Result of the lookup - * @param local_addr: Local address of the UDP tunnel - * @param remote_addr: Remote address of the UDP tunnel - * @param local_port: Local port of the UDP tunnel - * @param remote_port: Remote port of the UDP tunnel - * @param hicnb_flags: Flags that indicate whether the face is an application - * face or not. (Currently only IP faces can be appface) - * @param node_index: vlib edge index to use in the packet processing - */ -always_inline void -hicn_dpo_udp6_add_and_lock (dpo_id_t * dpo, - const ip6_address_t * local_addr, - const ip6_address_t * remote_addr, - u16 local_port, u16 remote_port, - u32 node_index, u8 * hicnb_flags, u32 sw_if) -{ - dpo->dpoi_type = DPO_FIRST; - dpo->dpoi_proto = DPO_PROTO_NONE; - dpo->dpoi_index = INDEX_INVALID; - dpo->dpoi_next_node = 0; - - hicn_face_t *face = - hicn_face_udp6_get (local_addr, remote_addr, local_port, remote_port); - - if (face == NULL) - { - 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); - dpo->dpoi_next_node = node_index; - dpo_unlock (dpo); - - return; - } - - *hicnb_flags = HICN_BUFFER_FLAGS_DEFAULT; - - hicn_face_id_t dpoi_index = hicn_dpoi_get_index (face); - dpo_set (dpo, hicn_face_udp_type, DPO_PROTO_IP6, dpoi_index); - dpo->dpoi_next_node = node_index; - dpo_unlock (dpo); -} - -/** - * @brief Create a dpo from a udp face - * - * @param face Face from which to create the dpo - * @return the dpo - */ -void hicn_dpo_udp_create_from_face (hicn_face_t * face, dpo_id_t * dpo, - u16 dpoi_next_node); - -#endif // __HICN_DPO_UDP_H__ - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/hicn-plugin/src/faces/udp/face_udp.c b/hicn-plugin/src/faces/udp/face_udp.c deleted file mode 100644 index f427505dd..000000000 --- a/hicn-plugin/src/faces/udp/face_udp.c +++ /dev/null @@ -1,456 +0,0 @@ -/* - * 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 <vnet/udp/udp.h> - -#include "face_udp.h" -#include "face_udp_node.h" -#include "iface_udp_node.h" -#include "dpo_udp.h" -#include "../face.h" -#include "../../infra.h" -#include "../../strategy.h" -#include "../../strategy_dpo_manager.h" -#include "../../hicn.h" - -#include "../../mapme.h" // HICN_MAPME_EVENT_* -#include "../../mapme_eventmgr.h" // hicn_mapme_eventmgr_process_node -extern vlib_node_registration_t hicn_mapme_eventmgr_process_node; - -mhash_t hicn_face_udp_hashtb; - -dpo_type_t hicn_face_udp_type; - -ip4_header_t ip4_header_skl = { - .ip_version_and_header_length = IP4_VERSION_AND_HEADER_LENGTH_NO_OPTIONS, - .tos = 0x00, - .length = (u16) 0, - .fragment_id = (u16) 0, - .flags_and_fragment_offset = (u16) 0, - .ttl = 254, - .protocol = IP_PROTOCOL_UDP, - .checksum = 0, - .src_address = {{0}}, - .dst_address = {{0}}, -}; - -ip6_header_t ip6_header_skl = { -#if CLIB_ARCH_IS_BIG_ENDIAN - .ip_version_traffic_class_and_flow_label = 0x60000000, -#else - .ip_version_traffic_class_and_flow_label = 0x00000060, -#endif - .payload_length = (u16) 0, - .protocol = IP_PROTOCOL_UDP, - .hop_limit = 254, - .src_address = {{0}}, - .dst_address = {{0}} -}; - -u32 strategy_face_udp4_vlib_edge; -u32 strategy_face_udp6_vlib_edge; - -/* - * Separated from the hicn_face_udp_init because it cannot be called by the - * init macro due to dependencies with other modules not yet initialied - */ -void -hicn_face_udp_init_internal () -{ - ip4_header_t *ip4_hdr = &ip4_header_skl; - ip4_header_skl.checksum = ip4_header_checksum (ip4_hdr); -} - -void -hicn_face_udp_init (vlib_main_t * vm) -{ - int strategy_nodes_n = hicn_strategy_get_all_available (); - - /* Default Strategy has index 0 and it always exists */ - strategy_face_udp4_vlib_edge = vlib_node_add_next (vm, - hicn_strategy_node.index, - hicn_face_udp4_output_node. - index); - strategy_face_udp6_vlib_edge = - vlib_node_add_next (vm, hicn_strategy_node.index, - hicn_face_udp6_output_node.index); - - /* - * Create and edge between al the other strategy nodes and the - * udp_output nodes. - */ - for (int i = 1; i < strategy_nodes_n; i++) - { - u32 temp_index4 = vlib_node_add_next (vm, - hicn_strategy_node.index, - hicn_face_udp4_output_node.index); - u32 temp_index6 = vlib_node_add_next (vm, - 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); - } - - u32 temp_index4 = vlib_node_add_next (vm, - hicn_interest_hitpit_node.index, - hicn_face_udp4_output_node.index); - u32 temp_index6 = vlib_node_add_next (vm, - hicn_interest_hitpit_node.index, - hicn_face_udp6_output_node.index); - - ASSERT (temp_index4 == strategy_face_udp4_vlib_edge); - ASSERT (temp_index6 == strategy_face_udp6_vlib_edge); - - hicn_dpo_udp_module_init (); - - register_face_type (hicn_face_udp_type, &udp_vft, "udp");; -} - -int -hicn_face_udp_add (const ip46_address_t * local_addr, - const ip46_address_t * remote_addr, u16 local_port, - u16 remote_port, u32 swif, hicn_face_id_t * pfaceid) -{ - adj_index_t ip_adj; - int ret = HICN_ERROR_NONE; - dpo_proto_t dpo_proto; - - hicn_face_flags_t flags = (hicn_face_flags_t) 0; - flags |= HICN_FACE_FLAGS_FACE; - vlib_main_t * vm = vlib_get_main(); - - if (ip46_address_is_ip4 (local_addr) && ip46_address_is_ip4 (remote_addr)) - { - 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; - - u32 fib_index = fib_table_find_or_create_and_lock (fib_pfx.fp_proto, - HICN_FIB_TABLE, - FIB_SOURCE_PRIORITY_HI); - fib_entry_index = fib_table_lookup (fib_index, &fib_pfx); - - ip_adj = fib_entry_get_adj (fib_entry_index); - - if (ip_adj == ~0) - return HICN_ERROR_FACE_IP_ADJ_NOT_FOUND; - - hicn_face_t *face = - hicn_face_udp4_get (&local_addr->ip4, &remote_addr->ip4, local_port, - remote_port); - - 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->ip4), - sizeof (ip4_address_t)); - clib_memcpy (&(udp_face->hdrs.ip4.ip.dst_address), &(remote_addr->ip4), - sizeof (ip4_address_t)); - - udp_face->hdrs.ip4.udp.src_port = local_port; - udp_face->hdrs.ip4.udp.dst_port = remote_port; - - ip_csum_t csum = udp_face->hdrs.ip4.ip.checksum; - csum = ip_csum_sub_even (csum, ip4_header_skl.src_address.as_u32); - csum = ip_csum_sub_even (csum, ip4_header_skl.dst_address.as_u32); - csum = - ip_csum_add_even (csum, udp_face->hdrs.ip4.ip.src_address.as_u32); - csum = - ip_csum_add_even (csum, udp_face->hdrs.ip4.ip.dst_address.as_u32); - udp_face->hdrs.ip4.ip.checksum = ip_csum_fold (csum); - - face->shared.adj = ip_adj; - face->shared.sw_if = swif; - face->shared.pl_id = (u16) 0; - face->shared.face_type = hicn_face_udp_type; - face->shared.flags = flags; - face->shared.locks = 0; - - hicn_face_udp_key_t key; - hicn_face_udp4_get_key (&local_addr->ip4, &remote_addr->ip4, 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); - - *pfaceid = hicn_dpoi_get_index (face); - dpo_proto = DPO_PROTO_IP4; - fib_table_unlock (fib_index, fib_pfx.fp_proto, FIB_SOURCE_PRIORITY_HI); - - udp_register_dst_port(vm, clib_net_to_host_u16(local_port), hicn_iface_udp4_input_node.index, 1); - } - else if (!ip46_address_is_ip4 (local_addr) - && !ip46_address_is_ip4 (remote_addr)) - { - 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; - - u32 fib_index = fib_table_find_or_create_and_lock (fib_pfx.fp_proto, - HICN_FIB_TABLE, - FIB_SOURCE_PRIORITY_HI); - fib_entry_index = fib_table_lookup (fib_index, &fib_pfx); - - ip_adj = fib_entry_get_adj (fib_entry_index); - - if (ip_adj == ~0) - return HICN_ERROR_FACE_IP_ADJ_NOT_FOUND; - - hicn_face_t *face = - hicn_face_udp6_get (&local_addr->ip6, &remote_addr->ip6, local_port, - remote_port); - - 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 = ip_adj; - face->shared.sw_if = swif; - face->shared.pl_id = (u16) 0; - face->shared.face_type = hicn_face_udp_type; - face->shared.flags = flags; - face->shared.locks = 0; - - hicn_face_udp_key_t key; - hicn_face_udp6_get_key (&local_addr->ip6, &remote_addr->ip6, 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); - - *pfaceid = hicn_dpoi_get_index (face); - dpo_proto = DPO_PROTO_IP6; - fib_table_unlock (fib_index, fib_pfx.fp_proto, FIB_SOURCE_PRIORITY_HI); - - udp_register_dst_port(vm, clib_net_to_host_u16(local_port), hicn_iface_udp6_input_node.index, 0); - } - else - { - return HICN_ERROR_IPS_ADDR_TYPE_NONUNIFORM; - } - - 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); - } - - retx_t *retx = vlib_process_signal_event_data (vlib_get_main (), - hicn_mapme_eventmgr_process_node. - index, - HICN_MAPME_EVENT_FACE_ADD, 1, - sizeof (retx_t)); - /* *INDENT-OFF* */ - *retx = (retx_t) - { - .prefix = 0, - .dpo = (dpo_id_t) - { - .dpoi_type = hicn_face_udp_type, - .dpoi_proto = dpo_proto, - .dpoi_next_node = 0, - .dpoi_index = *pfaceid, - } - }; - /* *INDENT-ON* */ - - //Take a lock on the face which will be removed when the face is deleted - hicn_face_lock (&(retx->dpo)); - - - return ret; -} - -int -hicn_face_udp_del (u32 faceid) -{ - hicn_face_t *face = hicn_dpoi_get_from_idx (faceid); - hicn_face_udp_t *face_udp = (hicn_face_udp_t *) face->data; - hicn_face_udp_key_t key; - hicn_face_udp_key_t old_key; - - if (face_udp->hdrs.ip4.ip.ip_version_and_header_length == - IP4_VERSION_AND_HEADER_LENGTH_NO_OPTIONS) - { - hicn_face_udp4_get_key (&face_udp->hdrs.ip4.ip.src_address, - &face_udp->hdrs.ip4.ip.dst_address, - face_udp->hdrs.ip4.udp.src_port, - face_udp->hdrs.ip4.udp.dst_port, &key); - mhash_unset (&hicn_face_udp_hashtb, &key, (uword *) & old_key); - } - else - { - hicn_face_udp6_get_key (&face_udp->hdrs.ip6.ip.src_address, - &face_udp->hdrs.ip6.ip.dst_address, - face_udp->hdrs.ip6.udp.src_port, - face_udp->hdrs.ip6.udp.dst_port, &key); - mhash_unset (&hicn_face_udp_hashtb, &key, (uword *) & old_key); - } - return hicn_face_del (faceid); -} - -u8 * -format_hicn_face_udp (u8 * s, va_list * args) -{ - hicn_face_id_t face_id = va_arg (*args, index_t); - CLIB_UNUSED (u32 indent) = va_arg (*args, u32); - hicn_face_t *face; - hicn_face_udp_t *udp_face; - ip_adjacency_t *adj; - u8 ipv = IP4_VERSION_AND_HEADER_LENGTH_NO_OPTIONS; - vnet_main_t *vnm = vnet_get_main (); - - - face = hicn_dpoi_get_from_idx (face_id); - udp_face = (hicn_face_udp_t *) (face->data); - - if (face->shared.flags & HICN_FACE_FLAGS_FACE) - { - ASSERT (face->shared.adj != (adj_index_t) ~ 0); - adj = adj_get (face->shared.adj); - - s = format (s, "%U Face %d: ", format_white_space, indent, face_id); - if (udp_face->hdrs.ip4.ip.ip_version_and_header_length == ipv) - { - s = format (s, "type UDP local %U|%u ", - format_ip4_address, &udp_face->hdrs.ip4.ip.src_address, - clib_net_to_host_u16 (udp_face->hdrs.ip4.udp.src_port)); - s = - format (s, "remote %U|%u ", format_ip4_address, - &udp_face->hdrs.ip4.ip.dst_address, - clib_net_to_host_u16 (udp_face->hdrs.ip4.udp.dst_port)); - s = format (s, "%U", format_vnet_link, adj->ia_link); - - vnet_sw_interface_t *sw_int = - vnet_get_sw_interface_or_null (vnm, face->shared.sw_if); - if (sw_int != NULL) - s = format (s, " dev %U", format_vnet_sw_interface_name, vnm, - sw_int); - - if ((face->shared.flags & HICN_FACE_FLAGS_DELETED)) - s = format (s, " (deleted)"); - } - else - { - s = format (s, "type UDP local %U|%u ", - format_ip6_address, &udp_face->hdrs.ip6.ip.src_address, - clib_net_to_host_u16 (udp_face->hdrs.ip6.udp.src_port)); - s = - format (s, "remote %U|%u ", format_ip6_address, - &udp_face->hdrs.ip6.ip.dst_address, - clib_net_to_host_u16 (udp_face->hdrs.ip6.udp.dst_port)); - s = format (s, "%U", format_vnet_link, adj->ia_link); - - vnet_sw_interface_t *sw_int = - vnet_get_sw_interface_or_null (vnm, face->shared.sw_if); - if (sw_int != NULL) - s = format (s, " dev %U", format_vnet_sw_interface_name, vnm, - sw_int); - - if ((face->shared.flags & HICN_FACE_FLAGS_DELETED)) - s = format (s, " (deleted)"); - } - } - else - { - s = format (s, "%U iFace %d: ", format_white_space, indent, face_id); - if (udp_face->hdrs.ip4.ip.ip_version_and_header_length == ipv) - { - s = format (s, "type UDP local %U|%u", - format_ip4_address, &udp_face->hdrs.ip4.ip.src_address, - clib_net_to_host_u16 (udp_face->hdrs.ip4.udp.src_port)); - s = - format (s, " local %U|%u", format_ip4_address, - &udp_face->hdrs.ip4.ip.dst_address, - clib_net_to_host_u16 (udp_face->hdrs.ip4.udp.dst_port)); - - vnet_sw_interface_t *sw_int = - vnet_get_sw_interface_or_null (vnm, face->shared.sw_if); - if (sw_int != NULL) - s = format (s, " dev %U", format_vnet_sw_interface_name, vnm, - sw_int); - - if ((face->shared.flags & HICN_FACE_FLAGS_DELETED)) - s = format (s, " (deleted)"); - } - else - { - s = format (s, "type UDP local %U|%u", - format_ip6_address, &udp_face->hdrs.ip6.ip.src_address, - clib_net_to_host_u16 (udp_face->hdrs.ip6.udp.src_port)); - s = - format (s, " remote %U|%u", format_ip6_address, - &udp_face->hdrs.ip6.ip.dst_address, - clib_net_to_host_u16 (udp_face->hdrs.ip6.udp.dst_port)); - - vnet_sw_interface_t *sw_int = - vnet_get_sw_interface_or_null (vnm, face->shared.sw_if); - if (sw_int != NULL) - s = format (s, " dev %U", format_vnet_sw_interface_name, vnm, - sw_int); - - if ((face->shared.flags & HICN_FACE_FLAGS_DELETED)) - s = format (s, " (deleted)"); - } - } - - return s; -} - -void -hicn_face_udp_get_dpo (hicn_face_t * face, dpo_id_t * dpo) -{ - hicn_face_udp_t *face_udp = (hicn_face_udp_t *) face->data; - u8 version = - (face_udp->hdrs.ip4.ip.ip_version_and_header_length & 0xf0) >> 4; - return hicn_dpo_udp_create_from_face (face, dpo, - version == - (u8) 4 ? strategy_face_udp4_vlib_edge - : strategy_face_udp6_vlib_edge); -} - -hicn_face_vft_t udp_vft = { - .format_face = format_hicn_face_udp, - .hicn_face_del = hicn_face_udp_del, - .hicn_face_get_dpo = hicn_face_udp_get_dpo, -}; - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/hicn-plugin/src/faces/udp/face_udp.h b/hicn-plugin/src/faces/udp/face_udp.h deleted file mode 100644 index 5dfc76e22..000000000 --- a/hicn-plugin/src/faces/udp/face_udp.h +++ /dev/null @@ -1,356 +0,0 @@ -/* - * 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_FACE_UDP_H__ -#define __HICN_FACE_UDP_H__ - -#include <vlib/vlib.h> -#include <vnet/vnet.h> -#include <vnet/ip/ip6_packet.h> -#include <vnet/udp/udp_packet.h> - -#include "../face.h" - -/** - * @file - * @brief UDP face - * - * This file containes the definition of UDP faces. - * UDP faces encap and decap an hicn packet into a UDP tunnel. - * Src and dst address in interest and data packets are not considered and - * should be set to 0 (not checked in the forwarder). - */ - -/* Pre-instantiated ip header to fast fill an newly encapsulated packet */ -extern ip4_header_t ip4_header_skl; -extern ip6_header_t ip6_header_skl; - -#define INVALID_UDP_DPO_INDEX ~0 - -/** - * @brief UDP face representation. The following is stored in the data field of - * an hicn_face_t object (see hicn_face.h). A UDP face is identifies by the - * quadruplet (src addr, dst addr, src port, dst port). - */ -typedef struct hicn_face_udp_t_ -{ - /** - * The headers to paint, in packet painting order - */ - union - { - struct - { - ip4_header_t ip; - udp_header_t udp; - } __attribute__ ((packed)) ip4; - struct - { - ip6_header_t ip; - udp_header_t udp; - } __attribute__ ((packed)) ip6; - } __attribute__ ((packed)) hdrs; -} hicn_face_udp_t; - -/* Hast table mapping the udp key with the face id (dpoi_index pointing to and - element in the face pool defined in hicn_face.h)*/ -extern mhash_t hicn_face_udp_hashtb; - -/** - * @brief Hash table key. - */ -typedef struct hicn_face_udp_key_s -{ - ip46_address_t local_addr; - ip46_address_t remote_addr; - u16 local_port; - u16 remote_port; -} hicn_face_udp_key_t; - -/* DPO type for the udp face */ -extern dpo_type_t hicn_face_udp_type; - -/* VFT table for the udp face. Mainly used to format the face in the right way */ -extern hicn_face_vft_t udp_vft; - -/** - * @brief Create the key object for the mhash. Fill in the key object with the - * expected values. - * - * @param local_addr Local address of the UDP tunnel - * @param remote_addr Remote address of the UDP tunnel - * @param local_port Local port of the UDP tunnel - * @param remote_port Remote port of the UDP tunnel - * @param key Pointer to an allocated hicn_face_udp_key_t object - */ -always_inline void -hicn_face_udp4_get_key (const ip4_address_t * local_addr, - const ip4_address_t * remote_addr, - u16 local_port, u16 remote_port, - hicn_face_udp_key_t * key) -{ - - ip46_address_set_ip4 (&(key->local_addr), local_addr); - ip46_address_set_ip4 (&(key->remote_addr), remote_addr); - key->local_port = local_port; - key->remote_port = remote_port; -} - -/** - * @brief Create the key object for the mhash. Fill in the key object with the - * expected values. - * - * @param local_addr Local address of the UDP tunnel - * @param remote_addr Remote address of the UDP tunnel - * @param local_port Local port of the UDP tunnel - * @param remote_port Remote port of the UDP tunnel - * @param key Pointer to an allocated hicn_face_udp_key_t object - */ -always_inline void -hicn_face_udp6_get_key (const ip6_address_t * local_addr, - const ip6_address_t * remote_addr, - u16 local_port, u16 remote_port, - hicn_face_udp_key_t * key) -{ - key->local_addr.ip6 = *local_addr; - key->remote_addr.ip6 = *remote_addr; - key->local_port = local_port; - key->remote_port = remote_port; -} - -/** - * @brief Get the dpoi from the quadruplet that identifies the face. Does not add any lock. - * - * @param local_addr Local address of the UDP tunnel - * @param remote_addr Remote address of the UDP tunnel - * @param local_port Local port of the UDP tunnel - * @param remote_port Remote port of the UDP tunnel - * - * @result Pointer to the face. - */ -always_inline hicn_face_t * -hicn_face_udp4_get (const ip4_address_t * local_addr, - const ip4_address_t * remote_addr, - u16 local_port, u16 remote_port) -{ - 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_face_id_t *) mhash_get (&hicn_face_udp_hashtb, - &key); - - return dpoi_index == NULL ? NULL : hicn_dpoi_get_from_idx (*dpoi_index); -} - -/** - * @brief Get the dpoi from the quadruplet that identifies the face. Does not add any lock. - * - * @param local_addr Local address of the UDP tunnel (network order) - * @param remote_addr Remote address of the UDP tunnel (network order) - * @param local_port Local port of the UDP tunnel (network order) - * @param remote_port Remote port of the UDP tunnel (network order) - * - * @result Pointer to the face. - */ -always_inline hicn_face_t * -hicn_face_udp6_get (const ip6_address_t * local_addr, - const ip6_address_t * remote_addr, - u16 local_port, u16 remote_port) -{ - 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_face_id_t *) mhash_get (&hicn_face_udp_hashtb, - &key); - - return dpoi_index == NULL ? NULL : hicn_dpoi_get_from_idx (*dpoi_index); -} - - -/** - * @brief Initialize the udp face module - */ -void hicn_face_udp_init (vlib_main_t * vm); - -/** - * @brief Create a new face ip. API for other modules (e.g., routing) - * - * @param local_addr Local ip v4 or v6 address of the face (network order) - * @param remote_addr Remote ip v4 or v6 address of the face (network order) - * @param local_port Local udp port of the face (network order) - * @param remote_port Remote udp port of the face (network order) - * @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 - */ -int hicn_face_udp_add (const ip46_address_t * local_addr, - const ip46_address_t * remote_addr, u16 local_port, - 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); - - hicn_face_id_t dpoi_index = hicn_dpoi_get_index (face); - - mhash_set_mem (&hicn_face_udp_hashtb, &key, (uword *) & dpoi_index, 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 = 1; - 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); - - hicn_face_id_t dpoi_index = hicn_dpoi_get_index (face); - - mhash_set_mem (&hicn_face_udp_hashtb, &key, (uword *) & dpoi_index, 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 - * @return HICN_ERROR_FACE_NOT_FOUND if the face does not exist, otherwise - * HICN_ERROR_NONE - */ -int hicn_face_udp_del (hicn_face_id_t faceid); - -/** - * @brief Format a UDP face - * - * @param s Pointer to a previous string. If null it will be initialize - * @param args Array storing input values. Expected u32 indent and u32 face_id - * @return String with the formatted face - */ -u8 *format_hicn_face_udp (u8 * s, va_list * args); - -/** - * @brief Create a dpo from a udp face - * - * @param face Face from which to create the dpo - * @return the dpo - */ -void hicn_face_udp_get_dpo (hicn_face_t * face, dpo_id_t * dpo); - -/** - * @brief Init some internal structures - */ -void hicn_face_udp_init_internal (void); - -#endif // __HICN_FACE_UDP_H__ - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/hicn-plugin/src/faces/udp/face_udp_cli.c b/hicn-plugin/src/faces/udp/face_udp_cli.c deleted file mode 100644 index 7bb172ce8..000000000 --- a/hicn-plugin/src/faces/udp/face_udp_cli.c +++ /dev/null @@ -1,164 +0,0 @@ -/* - * 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 "face_udp.h" -#include "dpo_udp.h" - -#include <vnet/vnet.h> -#include <vnet/dpo/dpo.h> -#include <vlib/vlib.h> -#include <vnet/ip/format.h> - -#define HICN_FACE_NONE 0 -#define HICN_FACE_DELETE 1 -#define HICN_FACE_ADD 2 - - -static clib_error_t * -hicn_face_udp_cli_set_command_fn (vlib_main_t * vm, - unformat_input_t * main_input, - vlib_cli_command_t * cmd) -{ - vnet_main_t *vnm = vnet_get_main (); - ip46_address_t src_addr; - u32 src_port = 0; - ip46_address_t dst_addr; - u32 dst_port = 0; - hicn_face_id_t face_id = HICN_FACE_NULL; - int ret = HICN_ERROR_NONE; - int sw_if; - int face_op = HICN_FACE_NONE; - - ip46_address_reset (&src_addr); - ip46_address_reset (&dst_addr); - /* Get a line of input. */ - unformat_input_t _line_input, *line_input = &_line_input; - if (!unformat_user (main_input, unformat_line_input, line_input)) - { - return (0); - } - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "del")) - { - if (unformat (line_input, "id %d", &face_id)) - face_op = HICN_FACE_DELETE; - else - { - return clib_error_return (0, "missing face id"); - } - } - else if (unformat (line_input, "add")) - { - face_op = HICN_FACE_ADD; - if (unformat - (line_input, "src_addr %U port %u dst_addr %U port %u intfc %U", - unformat_ip46_address, &src_addr, IP46_TYPE_ANY, &src_port, - unformat_ip46_address, &dst_addr, IP46_TYPE_ANY, &dst_port, - unformat_vnet_sw_interface, vnm, &sw_if)); - else - { - return clib_error_return (0, "%s '%U'", - get_error_string - (HICN_ERROR_CLI_INVAL), - format_unformat_error, line_input); - } - } - else - { - return clib_error_return (0, "%s '%U'", - get_error_string (HICN_ERROR_CLI_INVAL), - format_unformat_error, line_input); - } - } - - if (face_id != HICN_FACE_NULL) - { - if (!hicn_dpoi_idx_is_valid (face_id)) - { - return clib_error_return (0, "%s, face_id %d not valid", - get_error_string (ret), face_id); - } - } - - int rv; - switch (face_op) - { - case HICN_FACE_ADD: - - /* Check for presence of next hop address */ - if (((dst_addr.as_u64[0] == (u64) 0) && (dst_addr.as_u64[1] == (u64) 0)) - || dst_port == 0) - { - return clib_error_return (0, "dst address and port not specified"); - } - - if (((src_addr.as_u64[0] == (u64) 0) && (src_addr.as_u64[1] == (u64) 0)) - || src_port == 0) - { - return clib_error_return (0, "src address not specified"); - } - - rv = - hicn_face_udp_add (&src_addr, &dst_addr, - clib_host_to_net_u16 (src_port), - clib_host_to_net_u16 (dst_port), sw_if, &face_id); - if (rv == HICN_ERROR_NONE) - { - vlib_cli_output (vm, "Face id: %d", face_id); - } - else - { - return clib_error_return (0, get_error_string (rv)); - } - break; - case HICN_FACE_DELETE: - rv = hicn_face_udp_del (face_id); - if (rv == HICN_ERROR_NONE) - { - vlib_cli_output (vm, "Face %d deleted", face_id); - } - else - { - return clib_error_return (0, get_error_string (rv)); - } - break; - default: - return clib_error_return (0, "Operation (%d) not implemented", face_op); - break; - } - return (rv == HICN_ERROR_NONE) ? 0 : clib_error_return (0, "%s\n", - get_error_string - (rv)); -} - -/* cli declaration for 'cfg face' */ -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (hicn_face_udp_cli_set_command, static) = -{ - .path = "hicn face udp", - .short_help = "hicn face udp {add src_addr <src_address> port <src_port > dst_addr <dst_address> port <dst_port>} intfc <interface> | {del id <face_id>}", - .function = hicn_face_udp_cli_set_command_fn, -}; -/* *INDENT-ON* */ - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/hicn-plugin/src/faces/udp/face_udp_node.c b/hicn-plugin/src/faces/udp/face_udp_node.c deleted file mode 100644 index c82336659..000000000 --- a/hicn-plugin/src/faces/udp/face_udp_node.c +++ /dev/null @@ -1,1030 +0,0 @@ -/* - * 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 <vnet/ip/ip_packet.h> - -#include "face_udp.h" -#include "face_udp_node.h" -#include "dpo_udp.h" -#include "../face.h" -#include "../../strategy.h" -#include "../../strategy_dpo_manager.h" -#include "../../hicn.h" - -/** - * @File - * - * Definition of the nodes for udp faces. - */ - -vlib_node_registration_t hicn_face_udp4_input_node; -vlib_node_registration_t hicn_face_udp6_input_node; -vlib_node_registration_t hicn_face_udp4_output_node; -vlib_node_registration_t hicn_face_udp6_output_node; - -static char *hicn_face_udp4_input_error_strings[] = { -#define _(sym, string) string, - foreach_hicnfwd_error -#undef _ -}; - -static char *hicn_face_udp6_input_error_strings[] = { -#define _(sym, string) string, - foreach_hicnfwd_error -#undef _ -}; - -/* Trace context struct */ -typedef struct -{ - u32 next_index; - u32 sw_if_index; - u8 pkt_type; - u8 packet_data[60]; -} -hicn_face_udp4_input_trace_t; - -typedef enum -{ - HICN_FACE_UDP4_INPUT_NEXT_DATA, - HICN_FACE_UDP4_INPUT_NEXT_MAPME, - HICN_FACE_UDP4_INPUT_NEXT_ERROR_DROP, - HICN_FACE_UDP4_INPUT_N_NEXT, -} hicn_face_udp4_input_next_t; - -/* Trace context struct */ -typedef struct -{ - u32 next_index; - u32 sw_if_index; - u8 pkt_type; - u8 packet_data[60]; -} -hicn_face_udp6_input_trace_t; - -typedef enum -{ - HICN_FACE_UDP6_INPUT_NEXT_DATA, - HICN_FACE_UDP6_INPUT_NEXT_MAPME, - HICN_FACE_UDP6_INPUT_NEXT_ERROR_DROP, - HICN_FACE_UDP6_INPUT_N_NEXT, -} hicn_face_udp6_input_next_t; - -#define ERROR_INPUT_UDP4 HICN_FACE_UDP4_INPUT_NEXT_ERROR_DROP -#define ERROR_INPUT_UDP6 HICN_FACE_UDP6_INPUT_NEXT_ERROR_DROP - -#define NEXT_MAPME_UDP4 HICN_FACE_UDP4_INPUT_NEXT_MAPME -#define NEXT_MAPME_UDP6 HICN_FACE_UDP6_INPUT_NEXT_MAPME -#define NEXT_DATA_UDP4 HICN_FACE_UDP4_INPUT_NEXT_DATA -#define NEXT_DATA_UDP6 HICN_FACE_UDP6_INPUT_NEXT_DATA - -#define IP_HEADER_4 ip4_header_t -#define IP_HEADER_6 ip6_header_t - -#define HICN_DPO_UDP_LOCK_IP4 hicn_dpo_udp4_lock -#define HICN_DPO_UDP_LOCK_IP6 hicn_dpo_udp6_lock - -#define TRACE_INPUT_PKT_UDP4 hicn_face_udp4_input_trace_t -#define TRACE_INPUT_PKT_UDP6 hicn_face_udp6_input_trace_t - -#define SIZE_HICN_HEADER4 sizeof(ip4_header_t) + sizeof(udp_header_t) -#define SIZE_HICN_HEADER6 sizeof(ip6_header_t) + sizeof(udp_header_t) - - -#define face_input_x1(ipv) \ - do { \ - int ret; \ - vlib_buffer_t *b0; \ - u32 bi0; \ - u32 next0 = ERROR_INPUT_UDP##ipv; \ - IP_HEADER_##ipv * ip_hdr = NULL; \ - u8 * inner_ip_hdr = NULL; \ - udp_header_t * udp_hdr = NULL; \ - hicn_buffer_t * hicnb0; \ - /* Prefetch for next iteration. */ \ - if (n_left_from > 1) \ - { \ - vlib_buffer_t *b1; \ - b1 = vlib_get_buffer (vm, from[1]); \ - CLIB_PREFETCH (b1, CLIB_CACHE_LINE_BYTES, STORE); \ - CLIB_PREFETCH (b1->data, CLIB_CACHE_LINE_BYTES , LOAD); \ - } \ - /* Dequeue a packet buffer */ \ - bi0 = from[0]; \ - from += 1; \ - n_left_from -= 1; \ - to_next[0] = bi0; \ - to_next += 1; \ - n_left_to_next -= 1; \ - \ - b0 = vlib_get_buffer (vm, bi0); \ - ip_hdr = (IP_HEADER_##ipv *) vlib_buffer_get_current(b0); \ - udp_hdr = (udp_header_t *) (ip_hdr + 1); \ - hicnb0 = hicn_get_buffer(b0); \ - \ - inner_ip_hdr = (u8 *)(udp_hdr + 1); \ - u8 is_v6 = hicn_is_v6((hicn_header_t *)inner_ip_hdr); \ - u8 is_icmp = is_v6*(inner_ip_hdr[6] == IPPROTO_ICMPV6) + \ - (1 - is_v6)*(inner_ip_hdr[9] == IPPROTO_ICMPV4); \ - \ - ret = HICN_DPO_UDP_LOCK_IP##ipv \ - (&(hicnb0->face_dpo_id), \ - &(ip_hdr->dst_address), \ - &(ip_hdr->src_address), \ - (udp_hdr->dst_port), \ - (udp_hdr->src_port), \ - &hicnb0->flags); \ - \ - if ( PREDICT_FALSE(ret != HICN_ERROR_NONE) ) \ - { \ - next0 = ERROR_INPUT_UDP##ipv; \ - } \ - else \ - { \ - next0 = is_icmp*NEXT_MAPME_UDP##ipv + \ - (1-is_icmp)*NEXT_DATA_UDP##ipv; \ - stats.pkts_data_count += 1; \ - \ - vlib_buffer_advance(b0, sizeof(IP_HEADER_##ipv) + \ - sizeof(udp_header_t)); \ - vlib_increment_combined_counter ( \ - &counters[hicnb0->face_dpo_id.dpoi_index \ - * HICN_N_COUNTER], thread_index, \ - HICN_FACE_COUNTERS_DATA_RX, \ - 1, \ - vlib_buffer_length_in_chain(vm, b0)); \ - } \ - \ - if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && \ - (b0->flags & VLIB_BUFFER_IS_TRACED))) \ - { \ - TRACE_INPUT_PKT_UDP##ipv *t = \ - vlib_add_trace (vm, node, b0, sizeof (*t)); \ - t->pkt_type = HICN_PKT_TYPE_CONTENT; \ - t->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX]; \ - t->next_index = next0; \ - clib_memcpy_fast (t->packet_data, \ - vlib_buffer_get_current (b0), \ - sizeof (t->packet_data)); \ - } \ - \ - \ - /* Verify speculative enqueue, maybe switch current next frame */ \ - vlib_validate_buffer_enqueue_x1 (vm, node, next_index, \ - to_next, n_left_to_next, \ - bi0, next0); \ - }while(0) \ - -#define face_input_x2(ipv) \ - do { \ - int ret0, ret1; \ - vlib_buffer_t *b0, *b1; \ - u32 bi0, bi1; \ - u32 next0 = ERROR_INPUT_UDP##ipv; \ - u32 next1 = ERROR_INPUT_UDP##ipv; \ - IP_HEADER_##ipv * ip_hdr0 = NULL; \ - IP_HEADER_##ipv * ip_hdr1 = NULL; \ - u8 * inner_ip_hdr0 = NULL; \ - u8 * inner_ip_hdr1 = NULL; \ - udp_header_t * udp_hdr0 = NULL; \ - udp_header_t * udp_hdr1 = NULL; \ - hicn_buffer_t *hicnb0, *hicnb1; \ - \ - /* Prefetch for next iteration. */ \ - { \ - vlib_buffer_t *b2, *b3; \ - b2 = vlib_get_buffer (vm, from[2]); \ - b3 = vlib_get_buffer (vm, from[3]); \ - CLIB_PREFETCH (b2, CLIB_CACHE_LINE_BYTES, STORE); \ - CLIB_PREFETCH (b3, CLIB_CACHE_LINE_BYTES, STORE); \ - CLIB_PREFETCH (b2->data, CLIB_CACHE_LINE_BYTES , LOAD); \ - CLIB_PREFETCH (b3->data, CLIB_CACHE_LINE_BYTES , LOAD); \ - } \ - \ - /* Dequeue a packet buffer */ \ - bi0 = from[0]; \ - bi1 = from[1]; \ - from += 2; \ - n_left_from -= 2; \ - to_next[0] = bi0; \ - to_next[1] = bi1; \ - to_next += 2; \ - n_left_to_next -= 2; \ - \ - b0 = vlib_get_buffer (vm, bi0); \ - b1 = vlib_get_buffer (vm, bi1); \ - ip_hdr0 = (IP_HEADER_##ipv *) vlib_buffer_get_current(b0); \ - ip_hdr1 = (IP_HEADER_##ipv *) vlib_buffer_get_current(b1); \ - udp_hdr0 = (udp_header_t *) (ip_hdr0 + 1); \ - udp_hdr1 = (udp_header_t *) (ip_hdr1 + 1); \ - hicnb0 = hicn_get_buffer(b0); \ - hicnb1 = hicn_get_buffer(b1); \ - \ - inner_ip_hdr0 = (u8 *)(udp_hdr0 + 1); \ - u8 is_v6_0 = hicn_is_v6((hicn_header_t *)inner_ip_hdr0); \ - u8 is_icmp0 = is_v6_0*(inner_ip_hdr0[6] == IPPROTO_ICMPV6) + \ - (1 - is_v6_0)*(inner_ip_hdr0[9] == IPPROTO_ICMPV4); \ - \ - inner_ip_hdr1 = (u8 *)(udp_hdr1 + 1); \ - u8 is_v6_1 = hicn_is_v6((hicn_header_t *)inner_ip_hdr1); \ - u8 is_icmp1 = is_v6_1*(inner_ip_hdr1[6] == IPPROTO_ICMPV6) + \ - (1 - is_v6_1)*(inner_ip_hdr1[9] == IPPROTO_ICMPV4); \ - \ - ret0 = HICN_DPO_UDP_LOCK_IP##ipv \ - (&(hicnb0->face_dpo_id), \ - &(ip_hdr0->dst_address), \ - &(ip_hdr0->src_address), \ - (udp_hdr0->dst_port), \ - (udp_hdr0->src_port), \ - &hicnb0->flags); \ - \ - ret1 = HICN_DPO_UDP_LOCK_IP##ipv \ - (&(hicnb1->face_dpo_id), \ - &(ip_hdr1->dst_address), \ - &(ip_hdr1->src_address), \ - (udp_hdr1->dst_port), \ - (udp_hdr1->src_port), \ - &hicnb1->flags); \ - \ - if ( PREDICT_FALSE(ret0 != HICN_ERROR_NONE) ) \ - { \ - next0 = ERROR_INPUT_UDP##ipv; \ - } \ - else \ - { \ - stats.pkts_data_count += 1; \ - next0 = is_icmp0*NEXT_MAPME_UDP##ipv + \ - (1-is_icmp0)*NEXT_DATA_UDP##ipv; \ - \ - vlib_buffer_advance(b0, sizeof(IP_HEADER_##ipv) + \ - sizeof(udp_header_t)); \ - vlib_increment_combined_counter ( \ - &counters[hicnb0->face_dpo_id.dpoi_index \ - * HICN_N_COUNTER], thread_index, \ - HICN_FACE_COUNTERS_DATA_RX, \ - 1, \ - vlib_buffer_length_in_chain(vm, b0)); \ - } \ - \ - if ( PREDICT_FALSE(ret1 != HICN_ERROR_NONE) ) \ - { \ - next1 = ERROR_INPUT_UDP##ipv; \ - } \ - else \ - { \ - stats.pkts_data_count += 1; \ - next1 = is_icmp1*NEXT_MAPME_UDP##ipv + \ - (1-is_icmp1)*NEXT_DATA_UDP##ipv; \ - \ - vlib_buffer_advance(b1, sizeof(IP_HEADER_##ipv) + \ - sizeof(udp_header_t)); \ - vlib_increment_combined_counter ( \ - &counters[hicnb1->face_dpo_id.dpoi_index \ - * HICN_N_COUNTER], thread_index,\ - HICN_FACE_COUNTERS_DATA_RX, \ - 1, \ - vlib_buffer_length_in_chain(vm, b1)); \ - } \ - \ - if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && \ - (b0->flags & VLIB_BUFFER_IS_TRACED))) \ - { \ - TRACE_INPUT_PKT_UDP##ipv *t = \ - vlib_add_trace (vm, node, b0, sizeof (*t)); \ - t->pkt_type = HICN_PKT_TYPE_CONTENT; \ - t->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX]; \ - t->next_index = next0; \ - clib_memcpy_fast (t->packet_data, \ - vlib_buffer_get_current (b0), \ - sizeof (t->packet_data)); \ - } \ - \ - if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && \ - (b1->flags & VLIB_BUFFER_IS_TRACED))) \ - { \ - TRACE_INPUT_PKT_UDP##ipv *t = \ - vlib_add_trace (vm, node, b1, sizeof (*t)); \ - t->pkt_type = HICN_PKT_TYPE_CONTENT; \ - t->sw_if_index = vnet_buffer (b1)->sw_if_index[VLIB_RX]; \ - t->next_index = next1; \ - clib_memcpy_fast (t->packet_data, \ - vlib_buffer_get_current (b1), \ - sizeof (t->packet_data)); \ - } \ - \ - \ - /* Verify speculative enqueue, maybe switch current next frame */ \ - vlib_validate_buffer_enqueue_x2 (vm, node, next_index, \ - to_next, n_left_to_next, \ - bi0, bi1, next0, next1); \ - }while(0) \ - -static uword -hicn_face_udp4_input_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, - vlib_frame_t * frame) -{ - u32 n_left_from, *from, *to_next, next_index; - - from = vlib_frame_vector_args (frame); - n_left_from = frame->n_vectors; - next_index = node->cached_next_index; - vl_api_hicn_api_node_stats_get_reply_t stats = { 0 }; - u32 thread_index = vm->thread_index; - - while (n_left_from > 0) - { - u32 n_left_to_next; - vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); - - /* Dual loop, X2 */ - while (n_left_from >= 4 && n_left_to_next >= 2) - { - face_input_x2 (4); - } - - /* Dual loop, X1 */ - while (n_left_from > 0 && n_left_to_next > 0) - { - face_input_x1 (4); - } - vlib_put_next_frame (vm, node, next_index, n_left_to_next); - } - - vlib_node_increment_counter (vm, node->node_index, - HICNFWD_ERROR_DATAS, stats.pkts_data_count); - - return (frame->n_vectors); -} - -/* packet trace format function */ -static u8 * -hicn_face_udp4_input_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_face_udp4_input_trace_t *t = - va_arg (*args, hicn_face_udp4_input_trace_t *); - - s = - format (s, "FACE_UDP4_INPUT: pkt: %d, sw_if_index %d, next index %d\n%U", - (int) t->pkt_type, t->sw_if_index, t->next_index, - (t->packet_data[0] & 0xf0) == - 0x40 ? format_ip4_header : format_ip6_header, t->packet_data, - sizeof (t->packet_data)); - return (s); -} - -/* - * Node registration for the interest forwarder node - */ -/* *INDENT-OFF* */ -VLIB_REGISTER_NODE (hicn_face_udp4_input_node) = -{ - .function = hicn_face_udp4_input_node_fn, - .name = "hicn-face-udp4-input", - .vector_size = sizeof (u32), - .format_trace = hicn_face_udp4_input_format_trace, - .type = VLIB_NODE_TYPE_INTERNAL, - .n_errors = ARRAY_LEN (hicn_face_udp4_input_error_strings), - .error_strings = hicn_face_udp4_input_error_strings, - .n_next_nodes = HICN_FACE_UDP4_INPUT_N_NEXT, - /* edit / add dispositions here */ - .next_nodes = - { - [HICN_FACE_UDP4_INPUT_NEXT_DATA] = "hicn-data-pcslookup", - [HICN_FACE_UDP4_INPUT_NEXT_MAPME] = "hicn-mapme-ack", - [HICN_FACE_UDP4_INPUT_NEXT_ERROR_DROP] = "error-drop", - }, -}; -/* *INDENT-ON* */ - - -static uword -hicn_face_udp6_input_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, - vlib_frame_t * frame) -{ - u32 n_left_from, *from, *to_next, next_index; - - from = vlib_frame_vector_args (frame); - n_left_from = frame->n_vectors; - next_index = node->cached_next_index; - vl_api_hicn_api_node_stats_get_reply_t stats = { 0 }; - u32 thread_index = vm->thread_index; - - while (n_left_from > 0) - { - u32 n_left_to_next; - vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); - - /* Dual loop, X2 */ - while (n_left_from >= 4 && n_left_to_next >= 2) - { - face_input_x2 (6); - } - - /* Dual loop, X1 */ - while (n_left_from > 0 && n_left_to_next > 0) - { - face_input_x1 (6); - } - vlib_put_next_frame (vm, node, next_index, n_left_to_next); - } - - vlib_node_increment_counter (vm, node->node_index, - HICNFWD_ERROR_PROCESSED, stats.pkts_processed); - - vlib_node_increment_counter (vm, node->node_index, - HICNFWD_ERROR_DATAS, stats.pkts_data_count); - - return (frame->n_vectors); -} - -/* packet trace format function */ -static u8 * -hicn_face_udp6_input_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_face_udp6_input_trace_t *t = - va_arg (*args, hicn_face_udp6_input_trace_t *); - - s = - format (s, "FACE_UDP6_INPUT: pkt: %d, sw_if_index %d, next index %d\n%U", - (int) t->pkt_type, t->sw_if_index, t->next_index, - (t->packet_data[0] & 0xf0) == - 0x40 ? format_ip4_header : format_ip6_header, t->packet_data, - sizeof (t->packet_data)); - return (s); -} - -/* - * Node registration for the interest forwarder node - */ -/* *INDENT-OFF* */ -VLIB_REGISTER_NODE (hicn_face_udp6_input_node) = -{ - .function = hicn_face_udp6_input_node_fn, - .name = "hicn-face-udp6-input", - .vector_size = sizeof (u32), - .format_trace = hicn_face_udp6_input_format_trace, - .type = VLIB_NODE_TYPE_INTERNAL, - .n_errors = ARRAY_LEN (hicn_face_udp6_input_error_strings), - .error_strings = hicn_face_udp6_input_error_strings, - .n_next_nodes = HICN_FACE_UDP6_INPUT_N_NEXT, - /* edit / add dispositions here */ - .next_nodes = - { - [HICN_FACE_UDP6_INPUT_NEXT_DATA] = "hicn-data-pcslookup", - [HICN_FACE_UDP6_INPUT_NEXT_MAPME] = "hicn-mapme-ack", - [HICN_FACE_UDP6_INPUT_NEXT_ERROR_DROP] = "error-drop", - }, -}; -/* *INDENT-ON* */ - -/******* Face Output *******/ - -always_inline void -hicn_face_udp4_encap (vlib_main_t * vm, - vlib_buffer_t * outer_b0, - hicn_face_t * face, u32 * next) -{ - u16 old_l0 = 0, new_l0; - ip_csum_t sum0; - ip4_header_t *ip0; - udp_header_t *udp0; - hicn_face_udp_t *face_udp = (hicn_face_udp_t *) face->data; - - /* ip */ - ip0 = vlib_buffer_get_current (outer_b0); - clib_memcpy (ip0, &(face_udp->hdrs.ip4.ip), sizeof (ip4_header_t) + - sizeof (udp_header_t)); - - /* Fix UDP length */ - udp0 = (udp_header_t *) (ip0 + 1); - - new_l0 = - clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, outer_b0) - - sizeof (*ip0)); - udp0->length = new_l0; - - old_l0 = ip0->length; - ip0->length = - clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, outer_b0)); - - sum0 = ip0->checksum; - - //old_l0 always 0, see the rewrite setup - new_l0 = ip0->length; - - sum0 = ip_csum_update (sum0, old_l0, new_l0, ip4_header_t, - length /* changed member */ ); - ip0->checksum = sum0; - - int is_iface = 0; - ip_adjacency_t *adj; - if (PREDICT_FALSE (face->shared.adj == ~0)) - is_iface = 1; - else - adj = adj_get (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 - (is_iface || 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_PRIORITY_HI); - - fib_entry_index = fib_table_lookup (fib_index, &fib_pfx); - - face->shared.adj = fib_entry_get_adj (fib_entry_index); - face->shared.flags &= ~HICN_FACE_FLAGS_IFACE; - face->shared.flags |= HICN_FACE_FLAGS_FACE; - - adj = adj_get (face->shared.adj); - } - - vnet_buffer (outer_b0)->ip.adj_index[VLIB_TX] = face->shared.adj; - *next = adj->lookup_next_index; -} - -always_inline void -hicn_face_udp6_encap (vlib_main_t * vm, - vlib_buffer_t * outer_b0, - hicn_face_t * face, u32 * next) -{ - int bogus0; - u16 new_l0; - ip6_header_t *ip0; - udp_header_t *udp0; - hicn_face_udp_t *face_udp = (hicn_face_udp_t *) face->data; - - /* ip */ - ip0 = vlib_buffer_get_current (outer_b0); - clib_memcpy (ip0, &(face_udp->hdrs.ip6.ip), sizeof (ip6_header_t) + - sizeof (udp_header_t)); - new_l0 = clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, outer_b0) - - sizeof (*ip0)); - ip0->payload_length = new_l0; - - /* Fix UDP length */ - udp0 = (udp_header_t *) (ip0 + 1); - udp0->length = new_l0; - - udp0->checksum = - ip6_tcp_udp_icmp_compute_checksum (vm, outer_b0, ip0, &bogus0); - - ASSERT (bogus0 == 0); - - if (udp0->checksum == 0) - udp0->checksum = 0xffff; - - int is_iface = 0; - ip_adjacency_t *adj; - if (PREDICT_FALSE (face->shared.adj == ~0)) - is_iface = 1; - else - adj = adj_get (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 (is_iface || 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_PRIORITY_HI); - - fib_entry_index = fib_table_lookup (fib_index, &fib_pfx); - - face->shared.adj = fib_entry_get_adj (fib_entry_index); - face->shared.flags &= ~HICN_FACE_FLAGS_IFACE; - face->shared.flags |= HICN_FACE_FLAGS_FACE; - - adj = adj_get (face->shared.adj); - } - - vnet_buffer (outer_b0)->ip.adj_index[VLIB_TX] = face->shared.adj; - - *next = adj->lookup_next_index; -} - -static char *hicn_face_udp4_output_error_strings[] = { -#define _(sym, string) string, - foreach_hicnfwd_error -#undef _ -}; - -static char *hicn_face_udp6_output_error_strings[] = { -#define _(sym, string) string, - foreach_hicnfwd_error -#undef _ -}; - - -/* Trace context struct */ -typedef struct -{ - u32 next_index; - u32 sw_if_index; - u8 pkt_type; - u8 packet_data[60]; -} -hicn_face_udp4_output_trace_t; - -/* Trace context struct */ -typedef struct -{ - u32 next_index; - u32 sw_if_index; - u8 pkt_type; - u8 packet_data[60]; -} -hicn_face_udp6_output_trace_t; - -#define HICN_FACE_UDP_ENCAP_IP4 hicn_face_udp4_encap -#define HICN_FACE_UDP_ENCAP_IP6 hicn_face_udp6_encap - -#define TRACE_OUTPUT_PKT_UDP4 hicn_face_udp4_output_trace_t -#define TRACE_OUTPUT_PKT_UDP6 hicn_face_udp6_output_trace_t - -#define IP_HEADER_4 ip4_header_t -#define IP_HEADER_6 ip6_header_t - -#define face_output_x1(ipv) \ - do { \ - vlib_buffer_t *b0; \ - u32 bi0; \ - u32 next0 = IP_LOOKUP_NEXT_DROP; \ - hicn_face_t * face; \ - \ - /* Prefetch for next iteration. */ \ - if (n_left_from > 1) \ - { \ - vlib_buffer_t *b1; \ - b1 = vlib_get_buffer (vm, from[1]); \ - CLIB_PREFETCH (b1, CLIB_CACHE_LINE_BYTES, STORE); \ - CLIB_PREFETCH (b1->data, CLIB_CACHE_LINE_BYTES , LOAD); \ - } \ - /* Dequeue a packet buffer */ \ - bi0 = from[0]; \ - from += 1; \ - n_left_from -= 1; \ - \ - b0 = vlib_get_buffer (vm, bi0); \ - hicn_face_id_t face_id = vnet_buffer (b0)->ip.adj_index[VLIB_TX]; \ - face = \ - hicn_dpoi_get_from_idx(face_id); \ - \ - if (PREDICT_TRUE(face != NULL)) \ - { \ - /* Adjust vlib buffer. Create space for the udp tunnel. */ \ - vlib_buffer_advance(b0, -(sizeof (IP_HEADER_##ipv) + \ - sizeof (udp_header_t))); \ - \ - \ - HICN_FACE_UDP_ENCAP_IP##ipv \ - (vm, b0, face, &next0); \ - stats.pkts_interest_count += 1; \ - vlib_increment_combined_counter ( \ - &counters[face_id * HICN_N_COUNTER], \ - thread_index, \ - HICN_FACE_COUNTERS_INTEREST_TX, \ - 1, \ - vlib_buffer_length_in_chain(vm, b0));\ - } \ - \ - \ - if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && \ - (b0->flags & VLIB_BUFFER_IS_TRACED))) \ - { \ - TRACE_OUTPUT_PKT_UDP##ipv *t = \ - vlib_add_trace (vm, node, b0, sizeof (*t)); \ - t->pkt_type = HICN_PKT_TYPE_INTEREST; \ - t->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX]; \ - t->next_index = next0; \ - clib_memcpy_fast (t->packet_data, \ - vlib_buffer_get_current (b0) + \ - SIZE_HICN_HEADER##ipv, \ - sizeof (t->packet_data)); \ - } \ - \ - to_next[0] = bi0; \ - to_next += 1; \ - n_left_to_next -= 1; \ - \ - \ - /* Verify speculative enqueue, maybe switch current next frame */ \ - vlib_validate_buffer_enqueue_x1 (vm, node, next_index, \ - to_next, n_left_to_next, \ - bi0, next0); \ - } while(0) \ - - -#define face_output_x2(ipv) \ - do { \ - vlib_buffer_t *b0, *b1; \ - u32 bi0, bi1; \ - u32 next0 = IP_LOOKUP_NEXT_DROP; \ - u32 next1 = IP_LOOKUP_NEXT_DROP; \ - hicn_face_t *face0, *face1; \ - \ - /* Prefetch for next iteration. */ \ - { \ - vlib_buffer_t *b2, *b3; \ - b2 = vlib_get_buffer (vm, from[2]); \ - b3 = vlib_get_buffer (vm, from[3]); \ - CLIB_PREFETCH (b2, CLIB_CACHE_LINE_BYTES, STORE); \ - CLIB_PREFETCH (b3, CLIB_CACHE_LINE_BYTES, STORE); \ - CLIB_PREFETCH (b2->data, CLIB_CACHE_LINE_BYTES , LOAD); \ - CLIB_PREFETCH (b3->data, CLIB_CACHE_LINE_BYTES , LOAD); \ - } \ - \ - /* Dequeue a packet buffer */ \ - bi0 = from[0]; \ - bi1 = from[1]; \ - from += 2; \ - n_left_from -= 2; \ - to_next[0] = bi0; \ - to_next[1] = bi1; \ - to_next += 2; \ - n_left_to_next -= 2; \ - \ - b0 = vlib_get_buffer (vm, bi0); \ - b1 = vlib_get_buffer (vm, bi1); \ - \ - hicn_face_id_t face_id0 = vnet_buffer (b0)->ip.adj_index[VLIB_TX]; \ - hicn_face_id_t face_id1 = vnet_buffer (b1)->ip.adj_index[VLIB_TX]; \ - face0 = \ - hicn_dpoi_get_from_idx(vnet_buffer (b0)->ip.adj_index[VLIB_TX]); \ - face1 = \ - hicn_dpoi_get_from_idx(vnet_buffer (b1)->ip.adj_index[VLIB_TX]); \ - \ - if (PREDICT_TRUE(face0 != NULL)) \ - { \ - /* Adjust vlib buffer. Create space for the udp tunnel. */ \ - vlib_buffer_advance(b0, -(sizeof (IP_HEADER_##ipv) + \ - sizeof (udp_header_t))); \ - \ - \ - HICN_FACE_UDP_ENCAP_IP##ipv \ - (vm, b0, face0, &next0); \ - stats.pkts_interest_count += 1; \ - vlib_increment_combined_counter ( \ - &counters[face_id0 * HICN_N_COUNTER], \ - thread_index, \ - HICN_FACE_COUNTERS_INTEREST_TX, \ - 1, \ - vlib_buffer_length_in_chain(vm, b0)); \ - } \ - \ - if (PREDICT_TRUE(face1 != NULL)) \ - { \ - /* Adjust vlib buffer. Create space for the udp tunnel. */ \ - vlib_buffer_advance(b1, -(sizeof (IP_HEADER_##ipv) + \ - sizeof (udp_header_t))); \ - \ - \ - HICN_FACE_UDP_ENCAP_IP##ipv \ - (vm, b1, face1, &next1); \ - stats.pkts_interest_count += 1; \ - vlib_increment_combined_counter ( \ - &counters[face_id1 * HICN_N_COUNTER], \ - thread_index, \ - HICN_FACE_COUNTERS_INTEREST_TX, \ - 1, \ - vlib_buffer_length_in_chain(vm, b1)); \ - } \ - \ - \ - if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && \ - (b0->flags & VLIB_BUFFER_IS_TRACED))) \ - { \ - TRACE_OUTPUT_PKT_UDP##ipv *t = \ - vlib_add_trace (vm, node, b0, sizeof (*t)); \ - t->pkt_type = HICN_PKT_TYPE_INTEREST; \ - t->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX]; \ - t->next_index = next0; \ - clib_memcpy_fast (t->packet_data, \ - vlib_buffer_get_current (b0) + \ - SIZE_HICN_HEADER##ipv, \ - sizeof (t->packet_data)); \ - } \ - \ - \ - if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && \ - (b1->flags & VLIB_BUFFER_IS_TRACED))) \ - { \ - TRACE_OUTPUT_PKT_UDP##ipv *t = \ - vlib_add_trace (vm, node, b0, sizeof (*t)); \ - t->pkt_type = HICN_PKT_TYPE_INTEREST; \ - t->sw_if_index = vnet_buffer (b1)->sw_if_index[VLIB_RX]; \ - t->next_index = next1; \ - clib_memcpy_fast (t->packet_data, \ - vlib_buffer_get_current (b1) + \ - SIZE_HICN_HEADER##ipv, \ - sizeof (t->packet_data)); \ - } \ - /* Verify speculative enqueue, maybe switch current next frame */ \ - vlib_validate_buffer_enqueue_x2 (vm, node, next_index, \ - to_next, n_left_to_next, \ - bi0, bi1, next0, next1); \ - } while(0) \ - - -static uword -hicn_face_udp4_output_node_fn (vlib_main_t * vm, - vlib_node_runtime_t * node, - vlib_frame_t * frame) -{ - u32 n_left_from, *from, *to_next, next_index; - vl_api_hicn_api_node_stats_get_reply_t stats = { 0 }; - u32 thread_index = vm->thread_index; - - from = vlib_frame_vector_args (frame); - n_left_from = frame->n_vectors; - next_index = node->cached_next_index; - - while (n_left_from > 0) - { - u32 n_left_to_next; - vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); - - /* Dual loop, X2 */ - while (n_left_from >= 4 && n_left_to_next >= 2) - { - face_output_x2 (4); - } - - /* Dual loop, X1 */ - while (n_left_from > 0 && n_left_to_next > 0) - { - face_output_x1 (4); - } - vlib_put_next_frame (vm, node, next_index, n_left_to_next); - } - - vlib_node_increment_counter (vm, node->node_index, - HICNFWD_ERROR_INTERESTS, - stats.pkts_interest_count); - - return (frame->n_vectors); -} - -/* packet trace format function */ -static u8 * -hicn_face_udp4_output_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_face_udp4_output_trace_t *t = - va_arg (*args, hicn_face_udp4_output_trace_t *); - - s = - format (s, "FACE_UDP4_OUTPUT: pkt: %d, sw_if_index %d, next index %d\n%U", - (int) t->pkt_type, t->sw_if_index, t->next_index, - (t->packet_data[0] & 0xf0) == - 0x40 ? format_ip4_header : format_ip6_header, t->packet_data, - sizeof (t->packet_data)); - return (s); -} - -/* *INDENT-OFF* */ -/* - * Node registration for the interest forwarder node - */ -/* *INDENT-OFF* */ -VLIB_REGISTER_NODE (hicn_face_udp4_output_node) = -{ - .function = hicn_face_udp4_output_node_fn, - .name = "hicn-face-udp4-output", - .vector_size = sizeof (u32), - .format_trace = hicn_face_udp4_output_format_trace, - .type = VLIB_NODE_TYPE_INTERNAL, - .n_errors = ARRAY_LEN (hicn_face_udp4_output_error_strings), - .error_strings = hicn_face_udp4_output_error_strings, - .n_next_nodes = IP4_LOOKUP_N_NEXT, - /* Reusing the list of nodes from lookup to be compatible with arp */ - .next_nodes = IP4_LOOKUP_NEXT_NODES, -}; -/* *INDENT-ON* */ - -/* *INDENT-ON* */ - -static uword -hicn_face_udp6_output_node_fn (vlib_main_t * vm, - vlib_node_runtime_t * node, - vlib_frame_t * frame) -{ - u32 n_left_from, *from, *to_next, next_index; - vl_api_hicn_api_node_stats_get_reply_t stats = { 0 }; - u32 thread_index = vm->thread_index; - - from = vlib_frame_vector_args (frame); - n_left_from = frame->n_vectors; - next_index = node->cached_next_index; - - while (n_left_from > 0) - { - u32 n_left_to_next; - vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); - - /* Dual loop, X2 */ - while (n_left_from >= 4 && n_left_to_next >= 2) - { - face_output_x2 (6); - } - - while (n_left_from > 0 && n_left_to_next > 0) - { - face_output_x1 (6); - } - vlib_put_next_frame (vm, node, next_index, n_left_to_next); - } - - vlib_node_increment_counter (vm, node->node_index, - HICNFWD_ERROR_INTERESTS, - stats.pkts_interest_count); - - return (frame->n_vectors); -} - -/* packet trace format function */ -static u8 * -hicn_face_udp6_output_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_face_udp6_output_trace_t *t = - va_arg (*args, hicn_face_udp6_output_trace_t *); - - s = - format (s, "FACE_UDP6_OUTPUT: pkt: %d, sw_if_index %d, next index %d\n%u", - (int) t->pkt_type, t->sw_if_index, t->next_index, - (t->packet_data[0] & 0xf0) == - 0x40 ? format_ip4_header : format_ip6_header, t->packet_data, - sizeof (t->packet_data)); - return (s); -} - -/* *INDENT-OFF* */ -/* - * Node registration for the interest forwarder node - */ -/* *INDENT-OFF* */ -VLIB_REGISTER_NODE (hicn_face_udp6_output_node) = -{ - .function = hicn_face_udp6_output_node_fn, - .name = "hicn-face-udp6-output", - .vector_size = sizeof (u32), - .format_trace = hicn_face_udp6_output_format_trace, - .type = VLIB_NODE_TYPE_INTERNAL, - .n_errors = ARRAY_LEN (hicn_face_udp6_output_error_strings), - .error_strings = hicn_face_udp6_output_error_strings, - .n_next_nodes = IP6_LOOKUP_N_NEXT, - /* Reusing the list of nodes from lookup to be compatible with neighbour discovery */ - .next_nodes = IP6_LOOKUP_NEXT_NODES, -}; -/* *INDENT-ON* */ - -/* *INDENT-ON* */ - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/hicn-plugin/src/faces/udp/iface_udp_node.c b/hicn-plugin/src/faces/udp/iface_udp_node.c deleted file mode 100644 index 1fdd68f0b..000000000 --- a/hicn-plugin/src/faces/udp/iface_udp_node.c +++ /dev/null @@ -1,987 +0,0 @@ -/* - * 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 "iface_udp_node.h" -#include "dpo_udp.h" -#include "../face.h" - -#include "../../infra.h" -#include "../../hicn.h" - -/** - * @File - * - * Definition of the nodes for udp incomplete faces. - */ - -vlib_node_registration_t hicn_iface_udp4_input_node; -vlib_node_registration_t hicn_iface_udp6_input_node; -vlib_node_registration_t hicn_iface_udp4_output_node; -vlib_node_registration_t hicn_iface_udp6_output_node; - -u32 data_fwd_face_udp4_vlib_edge; -u32 data_fwd_face_udp6_vlib_edge; - -void -hicn_iface_udp_init (vlib_main_t * vm) -{ - data_fwd_face_udp4_vlib_edge = vlib_node_add_next (vm, - hicn_data_fwd_node.index, - hicn_iface_udp4_output_node.index); - - data_fwd_face_udp6_vlib_edge = vlib_node_add_next (vm, - hicn_data_fwd_node.index, - hicn_iface_udp6_output_node.index); - - u32 temp_index4 = vlib_node_add_next (vm, - hicn_interest_hitcs_node.index, - hicn_iface_udp4_output_node.index); - u32 temp_index6 = vlib_node_add_next (vm, - hicn_interest_hitcs_node.index, - hicn_iface_udp6_output_node.index); - - ASSERT (temp_index4 == data_fwd_face_udp4_vlib_edge); - ASSERT (temp_index6 == data_fwd_face_udp6_vlib_edge); -} - -static char *hicn_iface_udp4_input_error_strings[] = { -#define _(sym, string) string, - foreach_hicnfwd_error -#undef _ -}; - -static char *hicn_iface_udp6_input_error_strings[] = { -#define _(sym, string) string, - foreach_hicnfwd_error -#undef _ -}; - -u32 -get_face_udp4_output_node (void) -{ - return data_fwd_face_udp4_vlib_edge; -} - -u32 -get_face_udp6_output_node (void) -{ - return data_fwd_face_udp6_vlib_edge; -} - -/* Trace context struct */ -typedef struct -{ - u32 next_index; - u32 sw_if_index; - u8 pkt_type; - u8 packet_data[60]; -} -hicn_iface_udp4_input_trace_t; - -typedef enum -{ - HICN_IFACE_UDP4_INPUT_NEXT_INTEREST, - HICN_IFACE_UDP4_INPUT_NEXT_MAPME, - HICN_IFACE_UDP4_INPUT_NEXT_ERROR_DROP, - HICN_IFACE_UDP4_INPUT_N_NEXT, -} hicn_iface_udp4_input_next_t; - -/* Trace context struct */ -typedef struct -{ - u32 next_index; - u32 sw_if_index; - u8 pkt_type; - u8 packet_data[60]; -} -hicn_iface_udp6_input_trace_t; - -typedef enum -{ - HICN_IFACE_UDP6_INPUT_NEXT_INTEREST, - HICN_IFACE_UDP6_INPUT_NEXT_MAPME, - HICN_IFACE_UDP6_INPUT_NEXT_ERROR_DROP, - HICN_IFACE_UDP6_INPUT_N_NEXT, -} hicn_iface_udp6_input_next_t; - -#define ERROR_INPUT_UDP4 HICN_IFACE_UDP4_INPUT_NEXT_ERROR_DROP -#define ERROR_INPUT_UDP6 HICN_IFACE_UDP6_INPUT_NEXT_ERROR_DROP - -#define IP_HEADER_4 ip4_header_t -#define IP_HEADER_6 ip6_header_t - -#define NEXT_MAPME_UDP4 HICN_IFACE_UDP4_INPUT_NEXT_MAPME -#define NEXT_MAPME_UDP6 HICN_IFACE_UDP6_INPUT_NEXT_MAPME - -#define NEXT_INTEREST_UDP4 HICN_IFACE_UDP4_INPUT_NEXT_INTEREST -#define NEXT_INTEREST_UDP6 HICN_IFACE_UDP6_INPUT_NEXT_INTEREST - -#define HICN_IFACE_UDP_ADD_LOCK_IP4 hicn_dpo_udp4_add_and_lock -#define HICN_IFACE_UDP_ADD_LOCK_IP6 hicn_dpo_udp6_add_and_lock - -#define GET_FACE_UDP4 get_face_udp4_output_node -#define GET_FACE_UDP6 get_face_udp6_output_node - -#define TRACE_INPUT_PKT_UDP4 hicn_iface_udp4_input_trace_t -#define TRACE_INPUT_PKT_UDP6 hicn_iface_udp6_input_trace_t - -#define iface_input_x1(ipv) \ - do { \ - vlib_buffer_t *b0; \ - u32 bi0; \ - u32 next0 = ERROR_INPUT_UDP##ipv; \ - IP_HEADER_##ipv * ip_hdr = NULL; \ - u8 * inner_ip_hdr = NULL; \ - udp_header_t * udp_hdr = NULL; \ - hicn_buffer_t * hicnb0; \ - /* Prefetch for next iteration. */ \ - if (n_left_from > 1) \ - { \ - vlib_buffer_t *b1; \ - b1 = vlib_get_buffer (vm, from[1]); \ - CLIB_PREFETCH (b1, CLIB_CACHE_LINE_BYTES, STORE); \ - CLIB_PREFETCH (b1->data, CLIB_CACHE_LINE_BYTES , LOAD); \ - } \ - /* Dequeue a packet buffer */ \ - bi0 = from[0]; \ - from += 1; \ - n_left_from -= 1; \ - to_next[0] = bi0; \ - to_next += 1; \ - n_left_to_next -= 1; \ - \ - b0 = vlib_get_buffer (vm, bi0); \ - ip_hdr = (IP_HEADER_##ipv *) vlib_buffer_get_current(b0); \ - udp_hdr = (udp_header_t *) (ip_hdr + 1); \ - hicnb0 = hicn_get_buffer(b0); \ - \ - stats.pkts_interest_count += 1; \ - \ - inner_ip_hdr = (u8 *)(udp_hdr + 1); \ - u8 is_v6 = hicn_is_v6((hicn_header_t *)inner_ip_hdr); \ - u8 is_icmp = is_v6*(inner_ip_hdr[6] == IPPROTO_ICMPV6) + \ - (1 - is_v6)*(inner_ip_hdr[9] == IPPROTO_ICMPV4); \ - \ - next0 = is_icmp*NEXT_MAPME_UDP##ipv + \ - (1-is_icmp)*NEXT_INTEREST_UDP##ipv; \ - \ - HICN_IFACE_UDP_ADD_LOCK_IP##ipv \ - (&(hicnb0->face_dpo_id), \ - &(ip_hdr->dst_address), \ - &(ip_hdr->src_address), \ - udp_hdr->dst_port, \ - udp_hdr->src_port, \ - GET_FACE_UDP##ipv \ - (), \ - &hicnb0->flags, \ - vnet_buffer(b0)->sw_if_index[VLIB_RX]); \ - \ - vlib_buffer_advance(b0, sizeof(IP_HEADER_##ipv) + \ - sizeof(udp_header_t)); \ - \ - if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && \ - (b0->flags & VLIB_BUFFER_IS_TRACED))) \ - { \ - TRACE_INPUT_PKT_UDP##ipv *t = \ - vlib_add_trace (vm, node, b0, sizeof (*t)); \ - t->pkt_type = HICN_PKT_TYPE_INTEREST; \ - t->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX]; \ - t->next_index = next0; \ - clib_memcpy_fast (t->packet_data, \ - vlib_buffer_get_current (b0), \ - sizeof (t->packet_data)); \ - } \ - \ - vlib_increment_combined_counter ( \ - &counters[hicnb0->face_dpo_id.dpoi_index \ - * HICN_N_COUNTER], thread_index,\ - HICN_FACE_COUNTERS_INTEREST_RX, \ - 1, \ - vlib_buffer_length_in_chain(vm, b0)); \ - \ - \ - /* Verify speculative enqueue, maybe switch current next frame */ \ - vlib_validate_buffer_enqueue_x1 (vm, node, next_index, \ - to_next, n_left_to_next, \ - bi0, next0); \ - }while(0) - - -#define iface_input_x2(ipv) \ - do { \ - vlib_buffer_t *b0, *b1; \ - u32 bi0, bi1; \ - u32 next0, next1 = ERROR_INPUT_UDP##ipv; \ - IP_HEADER_##ipv * ip_hdr0 = NULL, *ip_hdr1 = NULL; \ - u8 * inner_ip_hdr0 = NULL, *inner_ip_hdr1 = NULL; \ - udp_header_t * udp_hdr0 = NULL, *udp_hdr1 = NULL; \ - hicn_buffer_t * hicnb0, *hicnb1; \ - \ - /* Prefetch for next iteration. */ \ - { \ - vlib_buffer_t *b2, *b3; \ - b2 = vlib_get_buffer (vm, from[2]); \ - b3 = vlib_get_buffer (vm, from[3]); \ - CLIB_PREFETCH (b2, CLIB_CACHE_LINE_BYTES, STORE); \ - CLIB_PREFETCH (b3, CLIB_CACHE_LINE_BYTES, STORE); \ - CLIB_PREFETCH (b2->data, CLIB_CACHE_LINE_BYTES , LOAD); \ - CLIB_PREFETCH (b3->data, CLIB_CACHE_LINE_BYTES , LOAD); \ - } \ - \ - /* Dequeue a packet buffer */ \ - bi0 = from[0]; \ - bi1 = from[1]; \ - from += 2; \ - n_left_from -= 2; \ - to_next[0] = bi0; \ - to_next[1] = bi1; \ - to_next += 2; \ - n_left_to_next -= 2; \ - \ - b0 = vlib_get_buffer (vm, bi0); \ - b1 = vlib_get_buffer (vm, bi1); \ - ip_hdr0 = (IP_HEADER_##ipv *) vlib_buffer_get_current(b0); \ - ip_hdr1 = (IP_HEADER_##ipv *) vlib_buffer_get_current(b1); \ - udp_hdr0 = (udp_header_t *) (ip_hdr0 + 1); \ - udp_hdr1 = (udp_header_t *) (ip_hdr1 + 1); \ - hicnb0 = hicn_get_buffer(b0); \ - hicnb1 = hicn_get_buffer(b1); \ - \ - stats.pkts_interest_count += 2; \ - \ - inner_ip_hdr0 = (u8 *)(udp_hdr0 + 1); \ - inner_ip_hdr1 = (u8 *)(udp_hdr1 + 1); \ - u8 is_v6_0 = hicn_is_v6((hicn_header_t *)inner_ip_hdr0); \ - u8 is_v6_1 = hicn_is_v6((hicn_header_t *)inner_ip_hdr1); \ - u8 is_icmp0 = is_v6_0*(inner_ip_hdr0[6] == IPPROTO_ICMPV6) + \ - (1 - is_v6_0)*(inner_ip_hdr0[9] == IPPROTO_ICMPV4); \ - u8 is_icmp1 = is_v6_1*(inner_ip_hdr1[6] == IPPROTO_ICMPV6) + \ - (1 - is_v6_1)*(inner_ip_hdr1[9] == IPPROTO_ICMPV4); \ - \ - next0 = is_icmp0*NEXT_MAPME_UDP##ipv + \ - (1-is_icmp0)*NEXT_INTEREST_UDP##ipv; \ - next1 = is_icmp1*NEXT_MAPME_UDP##ipv + \ - (1-is_icmp1)*NEXT_INTEREST_UDP##ipv; \ - \ - HICN_IFACE_UDP_ADD_LOCK_IP##ipv \ - (&(hicnb0->face_dpo_id), \ - &(ip_hdr0->dst_address), \ - &(ip_hdr0->src_address), \ - udp_hdr0->dst_port, \ - udp_hdr0->src_port, \ - GET_FACE_UDP##ipv \ - (), \ - &hicnb0->flags, \ - vnet_buffer(b0)->sw_if_index[VLIB_RX]); \ - \ - \ - HICN_IFACE_UDP_ADD_LOCK_IP##ipv \ - (&(hicnb1->face_dpo_id), \ - &(ip_hdr1->dst_address), \ - &(ip_hdr1->src_address), \ - udp_hdr1->dst_port, \ - udp_hdr1->src_port, \ - GET_FACE_UDP##ipv \ - (), \ - &hicnb1->flags, \ - vnet_buffer(b1)->sw_if_index[VLIB_RX]); \ - \ - vlib_buffer_advance(b0, sizeof(IP_HEADER_##ipv) + \ - sizeof(udp_header_t)); \ - \ - vlib_buffer_advance(b1, sizeof(IP_HEADER_##ipv) + \ - sizeof(udp_header_t)); \ - \ - if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && \ - (b0->flags & VLIB_BUFFER_IS_TRACED))) \ - { \ - TRACE_INPUT_PKT_UDP##ipv *t = \ - vlib_add_trace (vm, node, b0, sizeof (*t)); \ - t->pkt_type = HICN_PKT_TYPE_INTEREST; \ - t->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX]; \ - t->next_index = next0; \ - clib_memcpy_fast (t->packet_data, \ - vlib_buffer_get_current (b0), \ - sizeof (t->packet_data)); \ - } \ - \ - \ - if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && \ - (b1->flags & VLIB_BUFFER_IS_TRACED))) \ - { \ - TRACE_INPUT_PKT_UDP##ipv *t = \ - vlib_add_trace (vm, node, b1, sizeof (*t)); \ - t->pkt_type = HICN_PKT_TYPE_INTEREST; \ - t->sw_if_index = vnet_buffer (b1)->sw_if_index[VLIB_RX]; \ - t->next_index = next1; \ - clib_memcpy_fast (t->packet_data, \ - vlib_buffer_get_current (b1), \ - sizeof (t->packet_data)); \ - } \ - \ - vlib_increment_combined_counter ( \ - &counters[hicnb0->face_dpo_id.dpoi_index \ - * HICN_N_COUNTER], thread_index,\ - HICN_FACE_COUNTERS_INTEREST_RX, \ - 1, \ - vlib_buffer_length_in_chain(vm, b0)); \ - \ - vlib_increment_combined_counter ( \ - &counters[hicnb1->face_dpo_id.dpoi_index \ - * HICN_N_COUNTER], thread_index,\ - HICN_FACE_COUNTERS_INTEREST_RX, \ - 1, \ - vlib_buffer_length_in_chain(vm, b1)); \ - \ - /* Verify speculative enqueue, maybe switch current next frame */ \ - vlib_validate_buffer_enqueue_x2 (vm, node, next_index, \ - to_next, n_left_to_next, \ - bi0, bi1, next0, next1); \ - }while(0) - - -static uword -hicn_iface_udp4_input_node_fn (vlib_main_t * vm, - vlib_node_runtime_t * node, - vlib_frame_t * frame) -{ - u32 n_left_from, *from, *to_next, next_index; - vl_api_hicn_api_node_stats_get_reply_t stats = { 0 }; - u32 thread_index = vm->thread_index; - - from = vlib_frame_vector_args (frame); - n_left_from = frame->n_vectors; - next_index = node->cached_next_index; - - while (n_left_from > 0) - { - u32 n_left_to_next; - vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); - - /* Dual loop, X2 */ - while (n_left_from >= 4 && n_left_to_next >= 2) - { - iface_input_x2 (4); - } - - /* Dual loop, X1 */ - while (n_left_from > 0 && n_left_to_next > 0) - { - iface_input_x1 (4); - } - vlib_put_next_frame (vm, node, next_index, n_left_to_next); - } - - vlib_node_increment_counter (vm, node->node_index, - HICNFWD_ERROR_INTERESTS, - stats.pkts_interest_count); - - return (frame->n_vectors); -} - -/* packet trace format function */ -static u8 * -hicn_iface_udp4_input_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_iface_udp4_input_trace_t *t = - va_arg (*args, hicn_iface_udp4_input_trace_t *); - - s = - format (s, "IFACE_UDP4_INPUT: pkt: %d, sw_if_index %d, next index %d\n%U", - (int) t->pkt_type, t->sw_if_index, t->next_index, - (t->packet_data[0] & 0xf0) == - 0x40 ? format_ip4_header : format_ip6_header, t->packet_data, - sizeof (t->packet_data)); - return (s); -} - -/* - * Node registration for the interest forwarder node - */ -/* *INDENT-OFF* */ -VLIB_REGISTER_NODE (hicn_iface_udp4_input_node) = - -{ - .function = hicn_iface_udp4_input_node_fn, - .name = "hicn-iface-udp4-input", - .vector_size = sizeof (u32), - .format_trace = hicn_iface_udp4_input_format_trace, - .type = VLIB_NODE_TYPE_INTERNAL, - .n_errors = ARRAY_LEN (hicn_iface_udp4_input_error_strings), - .error_strings = hicn_iface_udp4_input_error_strings, - .n_next_nodes = HICN_IFACE_UDP4_INPUT_N_NEXT, - .next_nodes = - { - [HICN_IFACE_UDP4_INPUT_NEXT_INTEREST] = "hicn-interest-pcslookup", - [HICN_IFACE_UDP4_INPUT_NEXT_MAPME] = "hicn-mapme-ctrl", - [HICN_IFACE_UDP4_INPUT_NEXT_ERROR_DROP] = "error-drop", - }, -}; -/* *INDENT-ON* */ - - -static uword -hicn_iface_udp6_input_node_fn (vlib_main_t * vm, - vlib_node_runtime_t * node, - vlib_frame_t * frame) -{ - u32 n_left_from, *from, *to_next, next_index; - vl_api_hicn_api_node_stats_get_reply_t stats = { 0 }; - u32 thread_index = vm->thread_index; - - from = vlib_frame_vector_args (frame); - n_left_from = frame->n_vectors; - next_index = node->cached_next_index; - - while (n_left_from > 0) - { - u32 n_left_to_next; - vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); - - /* Dual loop, X2 */ - while (n_left_from >= 4 && n_left_to_next >= 2) - { - iface_input_x2 (6); - } - - /* Dual loop, X1 */ - while (n_left_from > 0 && n_left_to_next > 0) - { - iface_input_x1 (6); - } - vlib_put_next_frame (vm, node, next_index, n_left_to_next); - } - - vlib_node_increment_counter (vm, node->node_index, - HICNFWD_ERROR_INTERESTS, - stats.pkts_interest_count); - - return (frame->n_vectors); -} - -/* packet trace format function */ -static u8 * -hicn_iface_udp6_input_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_iface_udp6_input_trace_t *t = - va_arg (*args, hicn_iface_udp6_input_trace_t *); - - s = - format (s, "IFACE_UDP6_INPUT: pkt: %d, sw_if_index %d, next index %d\n%U", - (int) t->pkt_type, t->sw_if_index, t->next_index, - (t->packet_data[0] & 0xf0) == - 0x40 ? format_ip4_header : format_ip6_header, t->packet_data, - sizeof (t->packet_data)); - return (s); -} - -/* - * Node registration for the interest forwarder node - */ -/* *INDENT-OFF* */ -VLIB_REGISTER_NODE (hicn_iface_udp6_input_node) = -{ - .function = hicn_iface_udp6_input_node_fn, - .name = "hicn-iface-udp6-input", - .vector_size = sizeof (u32), - .format_trace = hicn_iface_udp6_input_format_trace, - .type = VLIB_NODE_TYPE_INTERNAL, - .n_errors = ARRAY_LEN (hicn_iface_udp6_input_error_strings), - .error_strings = hicn_iface_udp6_input_error_strings, - .n_next_nodes = HICN_IFACE_UDP6_INPUT_N_NEXT, - .next_nodes = - { - [HICN_IFACE_UDP6_INPUT_NEXT_INTEREST] = "hicn-interest-pcslookup", - [HICN_IFACE_UDP6_INPUT_NEXT_MAPME] = "hicn-mapme-ctrl", - [HICN_IFACE_UDP6_INPUT_NEXT_ERROR_DROP] = "error-drop", - }, -}; -/* *INDENT-ON* */ - -/******* Iface Output *******/ - -always_inline void -hicn_iface_udp4_encap (vlib_main_t * vm, - vlib_buffer_t * b0, hicn_face_t * face) -{ - u16 new_l0 = 0; - ip4_header_t *ip0; - udp_header_t *udp0; - hicn_face_udp_t *face_udp = (hicn_face_udp_t *) face->data; - - /* Adjust vlib buffers */ - /* Set the right length on the header buffer */ - /* Move the next buffer current data pointer back to the ip+tcp header (hicn header) */ - word offset = sizeof (ip4_header_t) + sizeof (udp_header_t); - vlib_buffer_advance (b0, -offset); - - /* ip */ - ip0 = vlib_buffer_get_current (b0); - clib_memcpy (ip0, &(face_udp->hdrs.ip4.ip), sizeof (ip4_header_t) + - sizeof (udp_header_t)); - - /* Fix UDP length */ - udp0 = (udp_header_t *) (ip0 + 1); - - new_l0 = - clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b0) - - sizeof (*ip0)); - udp0->length = new_l0; - - ip0->length = clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b0)); - ip0->checksum = ip4_header_checksum (ip0); -} - -always_inline void -hicn_iface_udp6_encap (vlib_main_t * vm, - vlib_buffer_t * b0, hicn_face_t * face) -{ - int bogus0; - u16 new_l0; - ip6_header_t *ip0; - udp_header_t *udp0; - hicn_face_udp_t *face_udp = (hicn_face_udp_t *) face->data; - - /* Adjust vlib buffer */ - word offset = sizeof (ip6_header_t) + sizeof (udp_header_t); - vlib_buffer_advance (b0, -offset); - - /* ip */ - ip0 = vlib_buffer_get_current (b0); - clib_memcpy (ip0, &(face_udp->hdrs.ip6.ip), sizeof (ip6_header_t) + - sizeof (udp_header_t)); - - new_l0 = clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b0) - - sizeof (*ip0)); - - ip0->payload_length = new_l0; - - /* Fix UDP length */ - udp0 = (udp_header_t *) (ip0 + 1); - udp0->length = new_l0; - - udp0->checksum = ip6_tcp_udp_icmp_compute_checksum (vm, b0, ip0, &bogus0); - - ASSERT (bogus0 == 0); - - if (udp0->checksum == 0) - udp0->checksum = 0xffff; -} - -static char *hicn_iface_udp4_output_error_strings[] = { -#define _(sym, string) string, - foreach_hicnfwd_error -#undef _ -}; - -static char *hicn_iface_udp6_output_error_strings[] = { -#define _(sym, string) string, - foreach_hicnfwd_error -#undef _ -}; - -/* Trace context struct */ -typedef struct -{ - u32 next_index; - u32 sw_if_index; - u8 pkt_type; - u8 packet_data[60]; -} -hicn_iface_udp4_output_trace_t; - -typedef enum -{ - HICN_IFACE_UDP4_OUTPUT_NEXT_LOOKUP, - HICN_IFACE_UDP4_OUTPUT_NEXT_ERROR_DROP, - HICN_IFACE_UDP4_OUTPUT_N_NEXT, -} hicn_iface_udp4_output_next_t; - -/* Trace context struct */ -typedef struct -{ - u32 next_index; - u32 sw_if_index; - u8 pkt_type; - u8 packet_data[60]; -} -hicn_iface_udp6_output_trace_t; - -typedef enum -{ - HICN_IFACE_UDP6_OUTPUT_NEXT_LOOKUP, - HICN_IFACE_UDP6_OUTPUT_NEXT_ERROR_DROP, - HICN_IFACE_UDP6_OUTPUT_N_NEXT, -} hicn_iface_udp6_output_next_t; - -#define ERROR_OUTPUT_UDP4 HICN_IFACE_UDP4_OUTPUT_NEXT_ERROR_DROP -#define ERROR_OUTPUT_UDP6 HICN_IFACE_UDP6_OUTPUT_NEXT_ERROR_DROP - -#define IP_HEADER_4 ip4_header_t -#define IP_HEADER_6 ip6_header_t - -#define NEXT_LOOKUP_UDP4 HICN_IFACE_UDP4_OUTPUT_NEXT_LOOKUP -#define NEXT_LOOKUP_UDP6 HICN_IFACE_UDP6_OUTPUT_NEXT_LOOKUP - -#define HICN_IFACE_UDP_ADD_LOCK_IP4 hicn_dpo_udp4_add_and_lock -#define HICN_IFACE_UDP_ADD_LOCK_IP6 hicn_dpo_udp6_add_and_lock - -#define HICN_FACE_UDP_ENCAP_IP4 hicn_iface_udp4_encap -#define HICN_FACE_UDP_ENCAP_IP6 hicn_iface_udp6_encap - -#define TRACE_OUTPUT_PKT_UDP4 hicn_iface_udp4_output_trace_t -#define TRACE_OUTPUT_PKT_UDP6 hicn_iface_udp6_output_trace_t - -#define SIZE_HICN_HEADER4 sizeof(ip4_header_t) + sizeof(udp_header_t) -#define SIZE_HICN_HEADER6 sizeof(ip6_header_t) + sizeof(udp_header_t) - -#define iface_output_x1(ipv) \ - do { \ - vlib_buffer_t *b0; \ - u32 bi0; \ - u32 next0 = ERROR_OUTPUT_UDP##ipv; \ - hicn_face_t * face; \ - \ - /* Prefetch for next iteration. */ \ - if (n_left_from > 1) \ - { \ - vlib_buffer_t *b1; \ - b1 = vlib_get_buffer (vm, from[1]); \ - CLIB_PREFETCH (b1, CLIB_CACHE_LINE_BYTES, STORE); \ - CLIB_PREFETCH (b1->data, CLIB_CACHE_LINE_BYTES , LOAD); \ - } \ - /* Dequeue a packet buffer */ \ - bi0 = from[0]; \ - from += 1; \ - n_left_from -= 1; \ - to_next[0] = bi0; \ - to_next += 1; \ - n_left_to_next -= 1; \ - \ - b0 = vlib_get_buffer (vm, bi0); \ - \ - hicn_face_id_t face_id = vnet_buffer (b0)->ip.adj_index[VLIB_TX]; \ - face = \ - hicn_dpoi_get_from_idx(face_id); \ - \ - if (PREDICT_TRUE(face != NULL)) \ - { \ - HICN_FACE_UDP_ENCAP_IP##ipv \ - (vm, b0, face); \ - next0 = NEXT_LOOKUP_UDP##ipv; \ - stats.pkts_data_count += 1; \ - vlib_increment_combined_counter ( \ - &counters[face_id * HICN_N_COUNTER], \ - thread_index, \ - HICN_FACE_COUNTERS_DATA_TX, \ - 1, \ - vlib_buffer_length_in_chain(vm, b0)); \ - } \ - \ - if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && \ - (b0->flags & VLIB_BUFFER_IS_TRACED))) \ - { \ - TRACE_OUTPUT_PKT_UDP##ipv *t = \ - vlib_add_trace (vm, node, b0, sizeof (*t)); \ - t->pkt_type = HICN_PKT_TYPE_INTEREST; \ - t->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX]; \ - t->next_index = next0; \ - clib_memcpy_fast (t->packet_data, \ - vlib_buffer_get_current (b0) + \ - SIZE_HICN_HEADER##ipv, \ - sizeof (t->packet_data)); \ - } \ - \ - \ - /* Verify speculative enqueue, maybe switch current next frame */ \ - vlib_validate_buffer_enqueue_x1 (vm, node, next_index, \ - to_next, n_left_to_next, \ - bi0, next0); \ - } while(0) - -#define iface_output_x2(ipv) \ - do { \ - vlib_buffer_t *b0, *b1; \ - u32 bi0, bi1; \ - u32 next0 = ERROR_OUTPUT_UDP##ipv, next1 = ERROR_OUTPUT_UDP##ipv; \ - hicn_face_t *face0, *face1; \ - \ - /* Prefetch for next iteration. */ \ - { \ - vlib_buffer_t *b2, *b3; \ - b2 = vlib_get_buffer (vm, from[2]); \ - b3 = vlib_get_buffer (vm, from[3]); \ - CLIB_PREFETCH (b2, CLIB_CACHE_LINE_BYTES, STORE); \ - CLIB_PREFETCH (b3, CLIB_CACHE_LINE_BYTES, STORE); \ - CLIB_PREFETCH (b2->data, CLIB_CACHE_LINE_BYTES , LOAD); \ - CLIB_PREFETCH (b3->data, CLIB_CACHE_LINE_BYTES , LOAD); \ - } \ - \ - /* Dequeue packets buffers */ \ - bi0 = from[0]; \ - bi1 = from[1]; \ - from += 2; \ - n_left_from -= 2; \ - to_next[0] = bi0; \ - to_next[1] = bi1; \ - to_next += 2; \ - n_left_to_next -= 2; \ - \ - b0 = vlib_get_buffer (vm, bi0); \ - b1 = vlib_get_buffer (vm, bi1); \ - \ - hicn_face_id_t face_id0 = vnet_buffer (b0)->ip.adj_index[VLIB_TX]; \ - hicn_face_id_t face_id1 = vnet_buffer (b1)->ip.adj_index[VLIB_TX]; \ - face0 = \ - hicn_dpoi_get_from_idx(face_id0); \ - face1 = \ - hicn_dpoi_get_from_idx(face_id1); \ - \ - if (PREDICT_TRUE(face0 != NULL)) \ - { \ - HICN_FACE_UDP_ENCAP_IP##ipv \ - (vm, b0, face0); \ - next0 = NEXT_LOOKUP_UDP##ipv; \ - stats.pkts_data_count += 1; \ - vlib_increment_combined_counter ( \ - &counters[face_id0 * HICN_N_COUNTER], \ - thread_index, \ - HICN_FACE_COUNTERS_DATA_TX, \ - 1, \ - vlib_buffer_length_in_chain(vm, b0)); \ - } \ - \ - if (PREDICT_TRUE(face1 != NULL)) \ - { \ - HICN_FACE_UDP_ENCAP_IP##ipv \ - (vm, b1, face1); \ - next1 = NEXT_LOOKUP_UDP##ipv; \ - stats.pkts_data_count += 1; \ - vlib_increment_combined_counter ( \ - &counters[face_id1 * HICN_N_COUNTER], \ - thread_index, \ - HICN_FACE_COUNTERS_DATA_TX, \ - 1, \ - vlib_buffer_length_in_chain(vm, b1)); \ - } \ - \ - if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && \ - (b0->flags & VLIB_BUFFER_IS_TRACED))) \ - { \ - TRACE_OUTPUT_PKT_UDP##ipv *t = \ - vlib_add_trace (vm, node, b0, sizeof (*t)); \ - t->pkt_type = HICN_PKT_TYPE_INTEREST; \ - t->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX]; \ - t->next_index = next0; \ - clib_memcpy_fast (t->packet_data, \ - vlib_buffer_get_current (b0) + \ - SIZE_HICN_HEADER##ipv, \ - sizeof (t->packet_data)); \ - } \ - \ - if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && \ - (b1->flags & VLIB_BUFFER_IS_TRACED))) \ - { \ - TRACE_OUTPUT_PKT_UDP##ipv *t = \ - vlib_add_trace (vm, node, b1, sizeof (*t)); \ - t->pkt_type = HICN_PKT_TYPE_INTEREST; \ - t->sw_if_index = vnet_buffer (b1)->sw_if_index[VLIB_RX]; \ - t->next_index = next1; \ - clib_memcpy_fast (t->packet_data, \ - vlib_buffer_get_current (b1) + \ - SIZE_HICN_HEADER##ipv, \ - sizeof (t->packet_data)); \ - } \ - \ - \ - /* Verify speculative enqueue, maybe switch current next frame */ \ - vlib_validate_buffer_enqueue_x2 (vm, node, next_index, \ - to_next, n_left_to_next, \ - bi0, bi1, next0, next1); \ - } while(0) - - -static uword -hicn_iface_udp4_output_node_fn (vlib_main_t * vm, - vlib_node_runtime_t * node, - vlib_frame_t * frame) -{ - u32 n_left_from, *from, *to_next, next_index; - vl_api_hicn_api_node_stats_get_reply_t stats = { 0 }; - u32 thread_index = vm->thread_index; - - from = vlib_frame_vector_args (frame); - n_left_from = frame->n_vectors; - next_index = node->cached_next_index; - - while (n_left_from > 0) - { - u32 n_left_to_next; - vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); - - while (n_left_from >= 4 && n_left_to_next >= 2) - { - iface_output_x2 (4); - } - - while (n_left_from > 0 && n_left_to_next > 0) - { - iface_output_x1 (4); - } - - vlib_put_next_frame (vm, node, next_index, n_left_to_next); - } - - vlib_node_increment_counter (vm, node->node_index, - HICNFWD_ERROR_DATAS, stats.pkts_data_count); - - return (frame->n_vectors); -} - -/* packet trace format function */ -static u8 * -hicn_iface_udp4_output_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_iface_udp4_output_trace_t *t = - va_arg (*args, hicn_iface_udp4_output_trace_t *); - - s = - format (s, - "IFACE_UDP4_OUTPUT: pkt: %d, out face %d, next index %d\n%U", - (int) t->pkt_type, t->sw_if_index, t->next_index, - (t->packet_data[0] & 0xf0) == - 0x40 ? format_ip4_header : format_ip6_header, t->packet_data, - sizeof (t->packet_data)); - return (s); -} - - -/* - * Node registration for the interest forwarder node - */ -/* *INDENT-OFF* */ -VLIB_REGISTER_NODE (hicn_iface_udp4_output_node) = -{ - .function = hicn_iface_udp4_output_node_fn, - .name = "hicn-iface-udp4-output", - .vector_size = sizeof (u32), - .format_trace = hicn_iface_udp4_output_format_trace, - .type = VLIB_NODE_TYPE_INTERNAL, - .n_errors = ARRAY_LEN (hicn_iface_udp4_output_error_strings), - .error_strings = hicn_iface_udp4_output_error_strings, - .n_next_nodes = HICN_IFACE_UDP4_OUTPUT_N_NEXT, - /* edit / add dispositions here */ - .next_nodes = - { - [HICN_IFACE_UDP4_OUTPUT_NEXT_LOOKUP] = "ip4-lookup", - [HICN_IFACE_UDP4_OUTPUT_NEXT_ERROR_DROP] = "error-drop", - }, -}; -/* *INDENT-ON* */ - - -static uword -hicn_iface_udp6_output_node_fn (vlib_main_t * vm, - vlib_node_runtime_t * node, - vlib_frame_t * frame) -{ - u32 n_left_from, *from, *to_next, next_index; - vl_api_hicn_api_node_stats_get_reply_t stats = { 0 }; - u32 thread_index = vm->thread_index; - - from = vlib_frame_vector_args (frame); - n_left_from = frame->n_vectors; - next_index = node->cached_next_index; - - while (n_left_from > 0) - { - u32 n_left_to_next; - vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); - - while (n_left_from >= 4 && n_left_to_next >= 2) - { - iface_output_x2 (6); - } - - while (n_left_from > 0 && n_left_to_next > 0) - { - iface_output_x1 (6); - } - - vlib_put_next_frame (vm, node, next_index, n_left_to_next); - } - - vlib_node_increment_counter (vm, node->node_index, - HICNFWD_ERROR_DATAS, stats.pkts_data_count); - - return (frame->n_vectors); - -} - -/* packet trace format function */ -static u8 * -hicn_iface_udp6_output_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_iface_udp6_output_trace_t *t = - va_arg (*args, hicn_iface_udp6_output_trace_t *); - - s = - format (s, - "IFACE_UDP6_OUTPUT: pkt: %d, out face %d, next index %d\n%U", - (int) t->pkt_type, t->sw_if_index, t->next_index, - (t->packet_data[0] & 0xf0) == - 0x40 ? format_ip4_header : format_ip6_header, t->packet_data, - sizeof (t->packet_data)); - return (s); -} - -/* - * Node registration for the interest forwarder node - */ -/* *INDENT-OFF* */ -VLIB_REGISTER_NODE (hicn_iface_udp6_output_node) = -{ - .function = hicn_iface_udp6_output_node_fn, - .name = "hicn-iface-udp6-output", - .vector_size = sizeof (u32), - .format_trace = hicn_iface_udp6_output_format_trace, - .type = VLIB_NODE_TYPE_INTERNAL, - .n_errors = ARRAY_LEN (hicn_iface_udp6_output_error_strings), - .error_strings = hicn_iface_udp6_output_error_strings, - .n_next_nodes = HICN_IFACE_UDP6_OUTPUT_N_NEXT, - /* edit / add dispositions here */ - .next_nodes = - { - [HICN_IFACE_UDP6_OUTPUT_NEXT_LOOKUP] = "ip6-lookup", - [HICN_IFACE_UDP6_OUTPUT_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/faces/udp/iface_udp_node.h b/hicn-plugin/src/faces/udp/iface_udp_node.h deleted file mode 100644 index 957d19217..000000000 --- a/hicn-plugin/src/faces/udp/iface_udp_node.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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_IFACE_UDP_H__ -#define __HICN_IFACE_UDP_H__ - -#include <vlib/vlib.h> - -extern vlib_node_registration_t hicn_iface_udp4_input_node; -extern vlib_node_registration_t hicn_iface_udp6_input_node; -extern vlib_node_registration_t hicn_iface_udp4_output_node; -extern vlib_node_registration_t hicn_iface_udp6_output_node; - -void hicn_iface_udp_init (vlib_main_t * vm); - -#endif // __HICN_FACE_UDP_H__ - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/hicn-plugin/src/hicn.api b/hicn-plugin/src/hicn.api index 01e4da213..d8198d149 100644 --- a/hicn-plugin/src/hicn.api +++ b/hicn-plugin/src/hicn.api @@ -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: @@ -16,19 +16,10 @@ option version = "5.1.0"; import "vnet/ip/ip_types.api"; -enum hicn_face_type -{ - IP_FACE = 0, - UDP_FACE, -}; - -typedef hicn_face_ip +typedef hicn_face { /* IP local address */ - vl_api_address_t local_addr; - - /* IP remote address */ - vl_api_address_t remote_addr; + vl_api_address_t nat_addr; /* IPv4 local port number */ u32 swif; @@ -40,36 +31,6 @@ typedef hicn_face_ip u8 if_name[30]; }; -typedef hicn_face_udp -{ - /* IP local address */ - vl_api_address_t local_addr; - - /* IP remote address */ - vl_api_address_t remote_addr; - - /* Local port */ - u16 lport; - - /* Remote port */ - u16 rport; - - /* IPv4 local port number */ - u32 swif; - - /* Face flags */ - u32 flags; - - /* Name of the interface */ - u8 if_name[30]; -}; - -typedef hicn_face_union -{ - vl_api_hicn_face_ip_t ip; - vl_api_hicn_face_udp_t udp; -}; - define hicn_api_node_params_set { /* Client identifier, set from api_main.my_client_index */ @@ -87,9 +48,6 @@ define hicn_api_node_params_set /* CS maximum size, otherwise -1 to assign default value */ i32 cs_max_size; - /* Portion of CS reserved to application, otherwise -1 to assign default value */ - i32 cs_reserved_app; - /* Upper bound on PIT entry lifetime, otherwise -1 to assign default value */ f64 pit_max_lifetime_sec; }; @@ -205,51 +163,6 @@ define hicn_api_node_stats_get_reply u64 cs_entries_ntw_count; }; -define hicn_api_face_ip_add -{ - /* Client identifier, set from api_main.my_client_index */ - u32 client_index; - - /* Arbitrary context, so client can match reply to request */ - u32 context; - - /* IP local address */ - vl_api_hicn_face_ip_t face; -}; - -define hicn_api_face_ip_add_reply -{ - /* From the request */ - u32 context; - - /* Return value: new Face ID, ~0 means no Face was created */ - u32 faceid; - - /* Return value, zero means all OK */ - i32 retval; -}; - -define hicn_api_face_ip_del -{ - /* Client identifier, set from api_main.my_client_index */ - u32 client_index; - - /* Arbitrary context, so client can match reply to request */ - u32 context; - - /* A Face ID to be deleted */ - u32 faceid; -}; - -define hicn_api_face_ip_del_reply -{ - /* From the request */ - u32 context; - - /* Return value, zero means all OK */ - i32 retval; -}; - define hicn_api_face_stats_details { /* From the request */ @@ -291,7 +204,7 @@ define hicn_api_face_stats_dump u32 context; }; -define hicn_api_face_ip_params_get +define hicn_api_face_params_get { /* Client identifier, set from api_main.my_client_index */ u32 client_index; @@ -303,7 +216,7 @@ define hicn_api_face_ip_params_get u32 faceid; }; -define hicn_api_face_ip_params_get_reply +define hicn_api_face_params_get_reply { /* From the request */ u32 context; @@ -315,10 +228,7 @@ define hicn_api_face_ip_params_get_reply u32 faceid; /* IP local address */ - vl_api_address_t local_addr; - - /* IP remote address */ - vl_api_address_t remote_addr; + vl_api_address_t nat_addr; /* VPP interface (index) associated with the face */ u32 swif; @@ -327,54 +237,6 @@ define hicn_api_face_ip_params_get_reply u32 flags; }; -define hicn_api_face_add -{ - /* Client identifier, set from api_main.my_client_index */ - u32 client_index; - - /* Arbitrary context, so client can match reply to request */ - u32 context; - - /* Type of face to add */ - vl_api_hicn_face_type_t type; - - /* Face to add */ - vl_api_hicn_face_union_t face; -}; - -define hicn_api_face_add_reply -{ - /* From the request */ - u32 context; - - /* Return value: new Face ID, ~0 means no Face was created */ - u32 faceid; - - /* Return value, zero means all OK */ - i32 retval; -}; - -define hicn_api_face_del -{ - /* Client identifier, set from api_main.my_client_index */ - u32 client_index; - - /* Arbitrary context, so client can match reply to request */ - u32 context; - - /* A Face ID to be deleted */ - u32 faceid; -}; - -define hicn_api_face_del_reply -{ - /* From the request */ - u32 context; - - /* Return value, zero means all OK */ - i32 retval; -}; - define hicn_api_faces_details { /* From the request */ @@ -386,11 +248,8 @@ define hicn_api_faces_details /* Id of the face */ u32 faceid; - /* Type of face to add */ - vl_api_hicn_face_type_t type; - /* Face to add */ - vl_api_hicn_face_union_t face; + vl_api_hicn_face_t face; }; define hicn_api_faces_dump @@ -425,11 +284,8 @@ define hicn_api_face_get_reply /* Id of the face */ u32 faceid; - /* Type of face to add */ - vl_api_hicn_face_type_t type; - /* Face to add */ - vl_api_hicn_face_union_t face; + vl_api_hicn_face_t face; }; define hicn_api_route_nhops_add @@ -444,7 +300,7 @@ define hicn_api_route_nhops_add vl_api_prefix_t prefix; /* A Face ID to the next hop forwarder for the specified prefix */ - u32 face_ids[5]; + u32 face_ids[10]; /* Number of face to add */ u8 n_faces; diff --git a/hicn-plugin/src/hicn.c b/hicn-plugin/src/hicn.c index 7c2776869..e12d6d923 100644 --- a/hicn-plugin/src/hicn.c +++ b/hicn-plugin/src/hicn.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: @@ -25,7 +25,7 @@ #include "error.h" #include "faces/app/address_mgr.h" #include "face_db.h" -#include "faces/udp/face_udp.h" +//#include "faces/udp/face_udp.h" #include "route.h" hicn_main_t hicn_main; @@ -45,8 +45,7 @@ hicn_face_bucket_t *hicn_face_bucket_pool; * Init hicn forwarder with configurable PIT, CS sizes */ static int -hicn_infra_fwdr_init (uint32_t shard_pit_size, uint32_t shard_cs_size, - uint32_t cs_reserved) +hicn_infra_fwdr_init (uint32_t shard_pit_size, uint32_t shard_cs_size) { int ret = 0; @@ -64,12 +63,7 @@ hicn_infra_fwdr_init (uint32_t shard_pit_size, uint32_t shard_cs_size, hicn_infra_slow_timer = 1; ret = hicn_pit_create (&hicn_main.pitcs, hicn_infra_pit_size); - hicn_pit_set_lru_max (&hicn_main.pitcs, - hicn_infra_cs_size - - (hicn_infra_cs_size * cs_reserved / 100)); - hicn_pit_set_lru_app_max (&hicn_main.pitcs, - hicn_infra_cs_size * cs_reserved / 100); - + hicn_pit_set_lru_max (&hicn_main.pitcs, hicn_infra_cs_size); done: if ((ret == HICN_ERROR_NONE) && !hicn_infra_fwdr_initialized) { @@ -86,12 +80,12 @@ int hicn_infra_plugin_enable_disable (int enable_disable, int pit_size_req, f64 pit_max_lifetime_sec_req, - int cs_size_req, int cs_reserved_app) + int cs_size_req) { int ret = 0; hicn_main_t *sm = &hicn_main; - uint32_t pit_size, cs_size, cs_reserved; + uint32_t pit_size, cs_size; /* Notice if we're already enabled... */ if (sm->is_enabled) @@ -168,18 +162,7 @@ hicn_infra_plugin_enable_disable (int enable_disable, cs_size = (uint32_t) cs_size_req; } - if (cs_reserved_app < 0) - { - cs_reserved = HICN_PARAM_CS_RESERVED_APP; - } - else - { - if (cs_reserved_app >= 100) - ret = HICN_ERROR_CS_CONFIG_RESERVED_OOB; - cs_reserved = cs_reserved_app; - } - - ret = hicn_infra_fwdr_init (pit_size, cs_size, cs_reserved); + ret = hicn_infra_fwdr_init (pit_size, cs_size); hicn_face_db_init (pit_size); @@ -189,7 +172,7 @@ hicn_infra_plugin_enable_disable (int enable_disable, } sm->is_enabled = 1; - hicn_face_udp_init_internal (); + //hicn_face_udp_init_internal (); done: @@ -202,7 +185,6 @@ hicn_configure (vlib_main_t * vm, unformat_input_t * input) u32 pit_size = HICN_PARAM_PIT_ENTRIES_DFLT; u32 cs_size = HICN_PARAM_CS_ENTRIES_DFLT; u64 pit_lifetime_max_sec = HICN_PARAM_PIT_LIFETIME_DFLT_MAX_MS / SEC_MS; - int cs_reserved = HICN_PARAM_CS_RESERVED_APP; while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { @@ -212,19 +194,15 @@ hicn_configure (vlib_main_t * vm, unformat_input_t * input) ; else if (unformat (input, "pit-lifetime-max %u", &pit_lifetime_max_sec)) ; - else if (unformat (input, "cs-reserved-app %u", &cs_reserved)) - ; else break; -// clib_error_return (0, -// "hICN parameter unknown"); } unformat_free (input); hicn_infra_plugin_enable_disable (1, pit_size, pit_lifetime_max_sec, - cs_size, cs_reserved); + cs_size); return 0; diff --git a/hicn-plugin/src/hicn.h b/hicn-plugin/src/hicn.h index b469a7ed9..9e851ade1 100644 --- a/hicn-plugin/src/hicn.h +++ b/hicn-plugin/src/hicn.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: @@ -30,6 +30,8 @@ #undef ip_prefix_len #define ip_prefix_len(_a) (_a)->len +#include "faces/face.h" + #include <netinet/in.h> #include <vnet/ip/ip.h> #include <vnet/tcp/tcp_packet.h> @@ -54,8 +56,6 @@ typedef u8 weight_t; #define VLIB_BUFFER_MIN_CHAIN_SEG_SIZE (128) #endif -#define HICN_BUFFER_FLAGS_DEFAULT 0x00 -#define HICN_BUFFER_FLAGS_FACE_IS_APP 0x01 /* vlib_buffer cloning utilities impose that current_lentgh is more that 2*CLIB_CACHE_LINE_BYTES. */ /* This flag is used to mark packets whose lenght is less that 2*CLIB_CACHE_LINE_BYTES. */ #define HICN_BUFFER_FLAGS_PKT_LESS_TWO_CL 0x02 @@ -76,8 +76,7 @@ typedef struct u8 dpo_ctx_id; /* used for data path */ u8 vft_id; /* " */ - dpo_id_t face_dpo_id; /* ingress iface, sizeof(dpo_id_t) - * <= sizeof(u64) */ + hicn_face_id_t face_id; /* ingress iface, sizeof(u32) */ u32 in_faces_vec_id; /* vector of possible input face for a data packet */ hicn_type_t type; diff --git a/hicn-plugin/src/hicn_api.c b/hicn-plugin/src/hicn_api.c index 7a6babeb2..62fa55f47 100644 --- a/hicn-plugin/src/hicn_api.c +++ b/hicn-plugin/src/hicn_api.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: @@ -25,8 +25,8 @@ #include <vnet/ip/ip_types_api.h> #include <vnet/ip/ip_format_fns.h> -#include "faces/ip/face_ip.h" -#include "faces/udp/face_udp.h" +#include "faces/face.h" +//#include "faces/udp/face_udp.h" #include "infra.h" #include "parser.h" #include "mgmt.h" @@ -59,7 +59,7 @@ */ always_inline vnet_api_error_t hicn_face_api_entry_params_serialize (hicn_face_id_t faceid, - vl_api_hicn_api_face_ip_params_get_reply_t + vl_api_hicn_api_face_params_get_reply_t * reply); @@ -88,14 +88,10 @@ vl_api_hicn_api_node_params_set_t_handler (vl_api_hicn_api_node_params_set_t * int cs_max_size = clib_net_to_host_i32 (mp->cs_max_size); cs_max_size = cs_max_size == -1 ? HICN_PARAM_CS_ENTRIES_DFLT : cs_max_size; - int cs_reserved_app = clib_net_to_host_i32 (mp->cs_reserved_app); - cs_reserved_app = cs_reserved_app >= 0 - && cs_reserved_app < 100 ? cs_reserved_app : HICN_PARAM_CS_RESERVED_APP; - rv = hicn_infra_plugin_enable_disable ((int) (mp->enable_disable), pit_max_size, pit_max_lifetime_sec, - cs_max_size, cs_reserved_app); + cs_max_size); REPLY_MACRO (VL_API_HICN_API_NODE_PARAMS_SET_REPLY /* , rmp, mp, rv */ ); } @@ -142,118 +138,118 @@ vl_api_hicn_api_node_stats_get_t_handler (vl_api_hicn_api_node_stats_get_t * /****** FACE *******/ -static hicn_error_t -hicn_api_face_ip_add (vl_api_hicn_face_ip_t * mp, hicn_face_id_t * face_id) -{ - hicn_error_t rv = HICN_ERROR_NONE; - - vnet_main_t *vnm = vnet_get_main (); - - ip46_address_t local_addr; - ip46_address_t remote_addr; - ip_address_decode (&mp->local_addr, &local_addr); - ip_address_decode (&mp->remote_addr, &remote_addr); - - u32 sw_if = clib_net_to_host_u32 (mp->swif); - - if (ip46_address_is_zero (&local_addr)) - { - if (!vnet_sw_interface_is_valid (vnm, sw_if)) - { - rv = HICN_ERROR_UNSPECIFIED; - } - - if ((rv == HICN_ERROR_NONE) && ip46_address_is_ip4 (&remote_addr)) - { - ip_interface_address_t *interface_address; - ip4_address_t *addr = - ip4_interface_address_matching_destination (&ip4_main, - &remote_addr.ip4, - sw_if, - &interface_address); - if (addr == NULL) - addr = ip4_interface_first_address (&ip4_main, - sw_if, &interface_address); - - if (addr == NULL) - rv = HICN_ERROR_UNSPECIFIED; - else - ip46_address_set_ip4 (&local_addr, addr); - } - else - { - ip_interface_address_t *interface_address; - ip6_interface_address_matching_destination (&ip6_main, - &remote_addr.ip6, sw_if, - &interface_address); - ip6_address_t *addr = NULL; - if (rv == HICN_ERROR_NONE && interface_address != NULL) - { - addr = - (ip6_address_t *) - ip_interface_address_get_address (&ip6_main.lookup_main, - interface_address); - } - else - { - addr = ip6_interface_first_address (&ip6_main, sw_if); - } - - if (addr == NULL) - rv = HICN_ERROR_UNSPECIFIED; - else - ip46_address_set_ip6 (&local_addr, addr); - } - } - - if (rv == HICN_ERROR_NONE) - rv = hicn_face_ip_add (&local_addr, &remote_addr, sw_if, face_id, 0); - - return rv; -} - -static void -vl_api_hicn_api_face_ip_add_t_handler (vl_api_hicn_api_face_ip_add_t * mp) -{ - vl_api_hicn_api_face_ip_add_reply_t *rmp; - hicn_error_t rv = HICN_ERROR_NONE; - - hicn_main_t *sm = &hicn_main; - hicn_face_id_t face_id = HICN_FACE_NULL; - rv = hicn_api_face_ip_add (&(mp->face), &face_id); - - /* *INDENT-OFF* */ - REPLY_MACRO2 (VL_API_HICN_API_FACE_IP_ADD_REPLY /* , rmp, mp, rv */ ,( - { - rmp->faceid = clib_host_to_net_u32 ((u32) face_id); - rmp->retval = rv; - })); - /* *INDENT-ON* */ -} +/* static hicn_error_t */ +/* hicn_api_face_ip_add (vl_api_hicn_face_ip_t * mp, hicn_face_id_t * face_id) */ +/* { */ +/* hicn_error_t rv = HICN_ERROR_NONE; */ + +/* vnet_main_t *vnm = vnet_get_main (); */ + +/* ip46_address_t local_addr; */ +/* ip46_address_t remote_addr; */ +/* ip_address_decode (&mp->local_addr, &local_addr); */ +/* ip_address_decode (&mp->remote_addr, &remote_addr); */ + +/* u32 sw_if = clib_net_to_host_u32 (mp->swif); */ + +/* if (ip46_address_is_zero (&local_addr)) */ +/* { */ +/* if (!vnet_sw_interface_is_valid (vnm, sw_if)) */ +/* { */ +/* rv = HICN_ERROR_UNSPECIFIED; */ +/* } */ + +/* if ((rv == HICN_ERROR_NONE) && ip46_address_is_ip4 (&remote_addr)) */ +/* { */ +/* ip_interface_address_t *interface_address; */ +/* ip4_address_t *addr = */ +/* ip4_interface_address_matching_destination (&ip4_main, */ +/* &remote_addr.ip4, */ +/* sw_if, */ +/* &interface_address); */ +/* if (addr == NULL) */ +/* addr = ip4_interface_first_address (&ip4_main, */ +/* sw_if, &interface_address); */ + +/* if (addr == NULL) */ +/* rv = HICN_ERROR_UNSPECIFIED; */ +/* else */ +/* ip46_address_set_ip4 (&local_addr, addr); */ +/* } */ +/* else */ +/* { */ +/* ip_interface_address_t *interface_address; */ +/* ip6_interface_address_matching_destination (&ip6_main, */ +/* &remote_addr.ip6, sw_if, */ +/* &interface_address); */ +/* ip6_address_t *addr = NULL; */ +/* if (rv == HICN_ERROR_NONE && interface_address != NULL) */ +/* { */ +/* addr = */ +/* (ip6_address_t *) */ +/* ip_interface_address_get_address (&ip6_main.lookup_main, */ +/* interface_address); */ +/* } */ +/* else */ +/* { */ +/* addr = ip6_interface_first_address (&ip6_main, sw_if); */ +/* } */ + +/* if (addr == NULL) */ +/* rv = HICN_ERROR_UNSPECIFIED; */ +/* else */ +/* ip46_address_set_ip6 (&local_addr, addr); */ +/* } */ +/* } */ + +/* if (rv == HICN_ERROR_NONE) */ +/* rv = hicn_face_ip_add (&local_addr, &remote_addr, sw_if, face_id, 0); */ + +/* return rv; */ +/* } */ + +/* static void */ +/* vl_api_hicn_api_face_ip_add_t_handler (vl_api_hicn_api_face_ip_add_t * mp) */ +/* { */ +/* vl_api_hicn_api_face_ip_add_reply_t *rmp; */ +/* hicn_error_t rv = HICN_ERROR_NONE; */ + +/* hicn_main_t *sm = &hicn_main; */ +/* hicn_face_id_t face_id = HICN_FACE_NULL; */ +/* rv = hicn_api_face_ip_add (&(mp->face), &face_id); */ + +/* /\* *INDENT-OFF* *\/ */ +/* REPLY_MACRO2 (VL_API_HICN_API_FACE_IP_ADD_REPLY /\* , rmp, mp, rv *\/ ,( */ +/* { */ +/* rmp->faceid = clib_host_to_net_u32 ((u32) face_id); */ +/* rmp->retval = rv; */ +/* })); */ +/* /\* *INDENT-ON* *\/ */ +/* } */ + +/* static void */ +/* vl_api_hicn_api_face_ip_del_t_handler (vl_api_hicn_api_face_ip_del_t * mp) */ +/* { */ +/* vl_api_hicn_api_face_ip_del_reply_t *rmp; */ +/* int rv = HICN_ERROR_FACE_NOT_FOUND; */ + +/* hicn_main_t *sm = &hicn_main; */ + +/* hicn_face_id_t faceid = clib_net_to_host_u32 (mp->faceid); */ +/* if (hicn_dpoi_idx_is_valid (faceid)) */ +/* { */ +/* rv = hicn_face_ip_del (faceid); */ +/* } */ + +/* REPLY_MACRO (VL_API_HICN_API_FACE_IP_DEL_REPLY /\* , rmp, mp, rv *\/ ); */ + +/* } */ static void -vl_api_hicn_api_face_ip_del_t_handler (vl_api_hicn_api_face_ip_del_t * mp) + vl_api_hicn_api_face_params_get_t_handler + (vl_api_hicn_api_face_params_get_t * mp) { - vl_api_hicn_api_face_ip_del_reply_t *rmp; - int rv = HICN_ERROR_FACE_NOT_FOUND; - - hicn_main_t *sm = &hicn_main; - - hicn_face_id_t faceid = clib_net_to_host_u32 (mp->faceid); - if (hicn_dpoi_idx_is_valid (faceid)) - { - rv = hicn_face_ip_del (faceid); - } - - REPLY_MACRO (VL_API_HICN_API_FACE_IP_DEL_REPLY /* , rmp, mp, rv */ ); - -} - -static void - vl_api_hicn_api_face_ip_params_get_t_handler - (vl_api_hicn_api_face_ip_params_get_t * mp) -{ - vl_api_hicn_api_face_ip_params_get_reply_t *rmp; + vl_api_hicn_api_face_params_get_reply_t *rmp; int rv = 0; hicn_main_t *sm = &hicn_main; @@ -261,7 +257,7 @@ static void hicn_face_id_t faceid = clib_net_to_host_u32 (mp->faceid); /* *INDENT-OFF* */ - REPLY_MACRO2 (VL_API_HICN_API_FACE_IP_PARAMS_GET_REPLY, ( + REPLY_MACRO2 (VL_API_HICN_API_FACE_PARAMS_GET_REPLY, ( { rv = hicn_face_api_entry_params_serialize(faceid, rmp); rmp->retval = clib_host_to_net_u32(rv); @@ -269,105 +265,103 @@ static void /* *INDENT-ON* */ } -static hicn_error_t -hicn_api_face_udp_add (vl_api_hicn_face_udp_t * mp, hicn_face_id_t * face_id) -{ - hicn_error_t rv = HICN_ERROR_NONE; - - ip46_address_t local_addr = ip46_address_initializer; - ip46_address_t remote_addr = ip46_address_initializer; - u16 lport; - u16 rport; - u32 sw_if; - ip_address_decode (&mp->local_addr, &local_addr); - ip_address_decode (&mp->remote_addr, &remote_addr); - //Do not byteswap. We store ports in network order - lport = mp->lport; - rport = mp->rport; - sw_if = clib_net_to_host_u32 (mp->swif); - - int input_is_ok = !ip46_address_is_zero (&local_addr) - && !ip46_address_is_zero (&remote_addr) - && - ((ip46_address_is_ip4 (&local_addr) && ip46_address_is_ip4 (&remote_addr)) - || (!ip46_address_is_ip4 (&local_addr) - && !ip46_address_is_ip4 (&remote_addr))) && lport != 0 && rport != 0; - - if (!input_is_ok) - { - rv = HICN_ERROR_UNSPECIFIED; - } - else - { - rv = hicn_face_udp_add (&local_addr, - &remote_addr, lport, rport, sw_if, face_id); - } - return rv; -} - -static void -vl_api_hicn_api_face_add_t_handler (vl_api_hicn_api_face_add_t * mp) -{ - vl_api_hicn_api_face_add_reply_t *rmp; - hicn_error_t rv = HICN_ERROR_NONE; - - 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); - - switch (face_type) - { - case IP_FACE: - rv = hicn_api_face_ip_add (&(mp->face.ip), &face_id); - break; - case UDP_FACE: - rv = hicn_api_face_udp_add (&(mp->face.udp), &face_id); - break; - default: - rv = HICN_ERROR_UNSPECIFIED; - break; - } - - /* *INDENT-OFF* */ - REPLY_MACRO2 (VL_API_HICN_API_FACE_ADD_REPLY /* , rmp, mp, rv */ ,( - { - rmp->faceid = clib_host_to_net_u32 ((u32) face_id); - rmp->retval = clib_host_to_net_u32 (rv); - })); - /* *INDENT-ON* */ -} - -static void -vl_api_hicn_api_face_del_t_handler (vl_api_hicn_api_face_del_t * mp) -{ - vl_api_hicn_api_face_del_reply_t *rmp; - int rv = HICN_ERROR_FACE_NOT_FOUND; - - hicn_main_t *sm = &hicn_main; - - hicn_face_id_t faceid = clib_net_to_host_u32 (mp->faceid); - if (hicn_dpoi_idx_is_valid (faceid)) - { - hicn_face_t *face = hicn_dpoi_get_from_idx (faceid); - hicn_face_vft_t *vft = hicn_face_get_vft (face->shared.face_type); - rv = vft->hicn_face_del (faceid); - } - - REPLY_MACRO (VL_API_HICN_API_FACE_DEL_REPLY /* , rmp, mp, rv */ ); -} +/* static hicn_error_t */ +/* hicn_api_face_udp_add (vl_api_hicn_face_udp_t * mp, hicn_face_id_t * face_id) */ +/* { */ +/* hicn_error_t rv = HICN_ERROR_NONE; */ + +/* ip46_address_t local_addr = ip46_address_initializer; */ +/* ip46_address_t remote_addr = ip46_address_initializer; */ +/* u16 lport; */ +/* u16 rport; */ +/* u32 sw_if; */ +/* ip_address_decode (&mp->local_addr, &local_addr); */ +/* ip_address_decode (&mp->remote_addr, &remote_addr); */ +/* //Do not byteswap. We store ports in network order */ +/* lport = mp->lport; */ +/* rport = mp->rport; */ +/* sw_if = clib_net_to_host_u32 (mp->swif); */ + +/* int input_is_ok = !ip46_address_is_zero (&local_addr) */ +/* && !ip46_address_is_zero (&remote_addr) */ +/* && */ +/* ((ip46_address_is_ip4 (&local_addr) && ip46_address_is_ip4 (&remote_addr)) */ +/* || (!ip46_address_is_ip4 (&local_addr) */ +/* && !ip46_address_is_ip4 (&remote_addr))) && lport != 0 && rport != 0; */ + +/* if (!input_is_ok) */ +/* { */ +/* rv = HICN_ERROR_UNSPECIFIED; */ +/* } */ +/* else */ +/* { */ +/* rv = hicn_face_udp_add (&local_addr, */ +/* &remote_addr, lport, rport, sw_if, face_id); */ +/* } */ +/* return rv; */ +/* } */ + +/* static void */ +/* vl_api_hicn_api_face_add_t_handler (vl_api_hicn_api_face_add_t * mp) */ +/* { */ +/* vl_api_hicn_api_face_add_reply_t *rmp; */ +/* hicn_error_t rv = HICN_ERROR_NONE; */ + +/* 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); */ + +/* switch (face_type) */ +/* { */ +/* case IP_FACE: */ +/* rv = hicn_api_face_ip_add (&(mp->face.ip), &face_id); */ +/* break; */ +/* case UDP_FACE: */ +/* rv = hicn_api_face_udp_add (&(mp->face.udp), &face_id); */ +/* break; */ +/* default: */ +/* rv = HICN_ERROR_UNSPECIFIED; */ +/* break; */ +/* } */ + +/* /\* *INDENT-OFF* *\/ */ +/* REPLY_MACRO2 (VL_API_HICN_API_FACE_ADD_REPLY /\* , rmp, mp, rv *\/ ,( */ +/* { */ +/* rmp->faceid = clib_host_to_net_u32 ((u32) face_id); */ +/* rmp->retval = clib_host_to_net_u32 (rv); */ +/* })); */ +/* /\* *INDENT-ON* *\/ */ +/* } */ + +/* static void */ +/* vl_api_hicn_api_face_del_t_handler (vl_api_hicn_api_face_del_t * mp) */ +/* { */ +/* vl_api_hicn_api_face_del_reply_t *rmp; */ +/* int rv = HICN_ERROR_FACE_NOT_FOUND; */ + +/* hicn_main_t *sm = &hicn_main; */ + +/* hicn_face_id_t faceid = clib_net_to_host_u32 (mp->faceid); */ +/* if (hicn_dpoi_idx_is_valid (faceid)) */ +/* { */ +/* hicn_face_t *face = hicn_dpoi_get_from_idx (faceid); */ +/* hicn_face_vft_t *vft = hicn_face_get_vft (face->shared.face_type); */ +/* rv = vft->hicn_face_del (faceid); */ +/* } */ + +/* REPLY_MACRO (VL_API_HICN_API_FACE_DEL_REPLY /\* , rmp, mp, rv *\/ ); */ +/* } */ static void -send_face_ip_details (hicn_face_t * face, vl_api_hicn_face_ip_t * mp) +send_face_details (hicn_face_t * face, vl_api_hicn_face_t * mp) { vnet_main_t *vnm = vnet_get_main (); - hicn_face_ip_t *face_ip = (hicn_face_ip_t *) face->data; - ip_address_encode (&face_ip->local_addr, IP46_TYPE_ANY, &mp->local_addr); - ip_address_encode (&face_ip->remote_addr, IP46_TYPE_ANY, &mp->remote_addr); - mp->flags = clib_host_to_net_u32 (face->shared.flags); - mp->swif = clib_net_to_host_u32 (face->shared.sw_if); + ip_address_encode (&face->nat_addr, IP46_TYPE_ANY, &mp->nat_addr); + mp->flags = clib_host_to_net_u32 (face->flags); + mp->swif = clib_net_to_host_u32 (face->sw_if); vnet_sw_interface_t *sw_interface = - vnet_get_sw_interface_or_null (vnm, face->shared.sw_if); + vnet_get_sw_interface_or_null (vnm, face->sw_if); u8 *sbuf = 0; if (sw_interface != NULL) { @@ -377,49 +371,49 @@ send_face_ip_details (hicn_face_t * face, vl_api_hicn_face_ip_t * mp) } } -static void -send_face_udp_details (hicn_face_t * face, vl_api_hicn_face_udp_t * mp) -{ - vnet_main_t *vnm = vnet_get_main (); - hicn_face_udp_t *face_udp = (hicn_face_udp_t *) face->data; - if (face_udp->hdrs.ip4.ip.ip_version_and_header_length == 0x45) - { - ip46_address_t src_addr = { 0 }; - ip46_address_t dst_addr = { 0 }; - ip46_address_set_ip4 (&src_addr, &(face_udp->hdrs.ip4.ip.src_address)); - ip46_address_set_ip4 (&dst_addr, &(face_udp->hdrs.ip4.ip.dst_address)); - - ip_address_encode (&src_addr, IP46_TYPE_ANY, &(mp->local_addr)); - ip_address_encode (&dst_addr, IP46_TYPE_ANY, &(mp->remote_addr)); - //Do not swap, they are already in network order - mp->lport = face_udp->hdrs.ip4.udp.src_port; - mp->rport = face_udp->hdrs.ip4.udp.dst_port; - } - else - { - ip46_address_t src_addr = { 0 }; - ip46_address_t dst_addr = { 0 }; - ip46_address_set_ip6 (&src_addr, &(face_udp->hdrs.ip6.ip.src_address)); - ip46_address_set_ip6 (&dst_addr, &(face_udp->hdrs.ip6.ip.dst_address)); - - ip_address_encode (&src_addr, IP46_TYPE_ANY, &(mp->local_addr)); - ip_address_encode (&dst_addr, IP46_TYPE_ANY, &(mp->remote_addr)); - //Do not swap, they are already in network order - mp->lport = face_udp->hdrs.ip6.udp.src_port; - mp->rport = face_udp->hdrs.ip6.udp.dst_port; - } - mp->flags = clib_host_to_net_u32 (face->shared.flags); - mp->swif = clib_net_to_host_u32 (face->shared.sw_if); - vnet_sw_interface_t *sw_interface = - vnet_get_sw_interface_or_null (vnm, face->shared.sw_if); - u8 *sbuf = 0; - if (sw_interface != NULL) - { - sbuf = - format (0, "%U", format_vnet_sw_interface_name, vnm, sw_interface); - strcpy ((char *) (mp->if_name), (char *) sbuf); - } -} +/* static void */ +/* send_face_udp_details (hicn_face_t * face, vl_api_hicn_face_udp_t * mp) */ +/* { */ +/* vnet_main_t *vnm = vnet_get_main (); */ +/* hicn_face_udp_t *face_udp = (hicn_face_udp_t *) face->data; */ +/* if (face_udp->hdrs.ip4.ip.ip_version_and_header_length == 0x45) */ +/* { */ +/* ip46_address_t src_addr = { 0 }; */ +/* ip46_address_t dst_addr = { 0 }; */ +/* ip46_address_set_ip4 (&src_addr, &(face_udp->hdrs.ip4.ip.src_address)); */ +/* ip46_address_set_ip4 (&dst_addr, &(face_udp->hdrs.ip4.ip.dst_address)); */ + +/* ip_address_encode (&src_addr, IP46_TYPE_ANY, &(mp->local_addr)); */ +/* ip_address_encode (&dst_addr, IP46_TYPE_ANY, &(mp->remote_addr)); */ +/* //Do not swap, they are already in network order */ +/* mp->lport = face_udp->hdrs.ip4.udp.src_port; */ +/* mp->rport = face_udp->hdrs.ip4.udp.dst_port; */ +/* } */ +/* else */ +/* { */ +/* ip46_address_t src_addr = { 0 }; */ +/* ip46_address_t dst_addr = { 0 }; */ +/* ip46_address_set_ip6 (&src_addr, &(face_udp->hdrs.ip6.ip.src_address)); */ +/* ip46_address_set_ip6 (&dst_addr, &(face_udp->hdrs.ip6.ip.dst_address)); */ + +/* ip_address_encode (&src_addr, IP46_TYPE_ANY, &(mp->local_addr)); */ +/* ip_address_encode (&dst_addr, IP46_TYPE_ANY, &(mp->remote_addr)); */ +/* //Do not swap, they are already in network order */ +/* mp->lport = face_udp->hdrs.ip6.udp.src_port; */ +/* mp->rport = face_udp->hdrs.ip6.udp.dst_port; */ +/* } */ +/* mp->flags = clib_host_to_net_u32 (face->shared.flags); */ +/* mp->swif = clib_net_to_host_u32 (face->shared.sw_if); */ +/* vnet_sw_interface_t *sw_interface = */ +/* vnet_get_sw_interface_or_null (vnm, face->shared.sw_if); */ +/* u8 *sbuf = 0; */ +/* if (sw_interface != NULL) */ +/* { */ +/* sbuf = */ +/* format (0, "%U", format_vnet_sw_interface_name, vnm, sw_interface); */ +/* strcpy ((char *) (mp->if_name), (char *) sbuf); */ +/* } */ +/* } */ static void send_faces_details (vl_api_registration_t * reg, @@ -433,17 +427,7 @@ send_faces_details (vl_api_registration_t * reg, mp->_vl_msg_id = htons (VL_API_HICN_API_FACES_DETAILS + hm->msg_id_base); mp->context = context; - if (face->shared.face_type == hicn_face_ip_type) - { - 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); - send_face_udp_details (face, &(mp->face.udp)); - } - + send_face_details (face, &(mp->face)); vl_api_send_msg (reg, (u8 *) mp); } @@ -483,16 +467,7 @@ vl_api_hicn_api_face_get_t_handler (vl_api_hicn_api_face_get_t * mp) if (rv) { hicn_face_t * face = hicn_dpoi_get_from_idx(faceid); - if (face->shared.face_type == hicn_face_ip_type) - { - rmp->type = IP_FACE; - send_face_ip_details(face, &(rmp->face.ip)); - } - else if (face->shared.face_type == hicn_face_udp_type) - { - rmp->type = UDP_FACE; - send_face_udp_details(face, &(rmp->face.udp)); - } + send_face_details(face, &(rmp->face)); rv = HICN_ERROR_NONE; } else @@ -663,9 +638,7 @@ static void vl_api_hicn_api_route_get_t_handler 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])) - { - rmp->faceids[i] =((dpo_id_t *) &hicn_dpo_ctx->next_hops[i])->dpoi_index;} + rmp->faceids[i] = hicn_dpo_ctx->next_hops[i]; } rmp->strategy_id = clib_host_to_net_u32(hicn_dpo_get_vft_id(hicn_dpo_id));} })); @@ -699,14 +672,10 @@ send_route_details (vl_api_registration_t * reg, 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); + mp->faceids[i] = + clib_host_to_net_u32 (hicn_dpo_ctx-> + next_hops[i]); mp->nfaces++; - } } mp->strategy_id = clib_host_to_net_u32 (hicn_dpo_get_vft_id (hicn_dpo_id)); @@ -955,7 +924,7 @@ hicn_api_plugin_hookup (vlib_main_t * vm) */ vnet_api_error_t hicn_face_api_entry_params_serialize (hicn_face_id_t faceid, - vl_api_hicn_api_face_ip_params_get_reply_t + vl_api_hicn_api_face_params_get_reply_t * reply) { int rv = HICN_ERROR_NONE; @@ -967,15 +936,13 @@ hicn_face_api_entry_params_serialize (hicn_face_id_t faceid, } hicn_face_t *face = hicn_dpoi_get_from_idx (faceid); - if (face != NULL && face->shared.face_type == hicn_face_ip_type) + if (face != NULL) { - hicn_face_ip_t *face_ip = (hicn_face_ip_t *) face->data; - ip_address_encode (&face_ip->local_addr, IP46_TYPE_ANY, - &reply->local_addr); - ip_address_encode (&face_ip->remote_addr, IP46_TYPE_ANY, - &reply->remote_addr); - reply->swif = clib_host_to_net_u32 (face->shared.sw_if); - reply->flags = clib_host_to_net_u32 (face->shared.flags); + ip_address_encode (&face->nat_addr, IP46_TYPE_ANY, + &reply->nat_addr); + + reply->swif = clib_host_to_net_u32 (face->sw_if); + reply->flags = clib_host_to_net_u32 (face->flags); reply->faceid = clib_host_to_net_u32 (faceid); } else diff --git a/hicn-plugin/src/hicn_api_test.c b/hicn-plugin/src/hicn_api_test.c index 08a579914..af0f8af94 100644 --- a/hicn-plugin/src/hicn_api_test.c +++ b/hicn-plugin/src/hicn_api_test.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: @@ -222,8 +222,6 @@ hicn_test_main_t hicn_test_main; #define foreach_standard_reply_retval_handler \ _(hicn_api_node_params_set_reply) \ -_(hicn_api_face_ip_del_reply) \ -_(hicn_api_face_del_reply) \ _(hicn_api_route_nhops_add_reply) \ _(hicn_api_route_del_reply) \ _(hicn_api_route_nhop_del_reply) @@ -253,26 +251,17 @@ foreach_standard_reply_retval_handler; _(HICN_API_NODE_PARAMS_SET_REPLY, hicn_api_node_params_set_reply) \ _(HICN_API_NODE_PARAMS_GET_REPLY, hicn_api_node_params_get_reply) \ _(HICN_API_NODE_STATS_GET_REPLY, hicn_api_node_stats_get_reply) \ -_(HICN_API_FACE_IP_DEL_REPLY, hicn_api_face_ip_del_reply) \ -_(HICN_API_FACE_IP_ADD_REPLY, hicn_api_face_ip_add_reply) \ -_(HICN_API_FACE_ADD_REPLY, hicn_api_face_add_reply) \ -_(HICN_API_FACE_DEL_REPLY, hicn_api_face_del_reply) \ _(HICN_API_FACE_GET_REPLY, hicn_api_face_get_reply) \ _(HICN_API_FACES_DETAILS, hicn_api_faces_details) \ _(HICN_API_FACE_STATS_DETAILS, hicn_api_face_stats_details) \ _(HICN_API_ROUTE_NHOPS_ADD_REPLY, hicn_api_route_nhops_add_reply) \ -_(HICN_API_FACE_IP_PARAMS_GET_REPLY, hicn_api_face_ip_params_get_reply) \ +_(HICN_API_FACE_PARAMS_GET_REPLY, hicn_api_face_params_get_reply) \ _(HICN_API_ROUTE_GET_REPLY, hicn_api_route_get_reply) \ _(HICN_API_ROUTES_DETAILS, hicn_api_routes_details) \ _(HICN_API_ROUTE_DEL_REPLY, hicn_api_route_del_reply) \ _(HICN_API_ROUTE_NHOP_DEL_REPLY, hicn_api_route_nhop_del_reply) \ _(HICN_API_STRATEGIES_GET_REPLY, hicn_api_strategies_get_reply) \ -_(HICN_API_STRATEGY_GET_REPLY, hicn_api_strategy_get_reply) \ -_(HICN_API_REGISTER_PROD_APP_REPLY, hicn_api_register_prod_app_reply) \ -_(HICN_API_FACE_PROD_DEL_REPLY, hicn_api_face_prod_del_reply) \ -_(HICN_API_REGISTER_CONS_APP_REPLY, hicn_api_register_cons_app_reply) \ -_(HICN_API_FACE_CONS_DEL_REPLY, hicn_api_face_cons_del_reply) - +_(HICN_API_STRATEGY_GET_REPLY, hicn_api_strategy_get_reply) static int api_hicn_api_node_params_set (vat_main_t * vam) @@ -451,263 +440,10 @@ static void } static int -api_hicn_api_face_ip_add (vat_main_t * vam) -{ - unformat_input_t *input = vam->input; - ip46_address_t local_addr = { 0 }; - ip46_address_t remote_addr = { 0 }; - int ret = HICN_ERROR_NONE; - int sw_if = 0; - vl_api_hicn_api_face_add_t *mp; - - /* Parse args required to build the message */ - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) - { - if (unformat - (input, "local %U", unformat_ip46_address, &local_addr, - IP46_TYPE_ANY)); - else - if (unformat - (input, "remote %U", unformat_ip46_address, &remote_addr, - IP46_TYPE_ANY)); - else if (unformat (input, "intfc %d", &sw_if)); - else - { - break; - } - } - - /* Check for presence of both addresses */ - if (ip46_address_is_zero (&remote_addr)) - { - clib_warning ("Incomplete IP face. Please specify remote address"); - return (1); - } - /* Construct the API message */ - M (HICN_API_FACE_ADD, mp); - mp->type = clib_host_to_net_u32 (IP_FACE); - ip_address_encode (&local_addr, IP46_TYPE_ANY, &mp->face.ip.local_addr); - ip_address_encode (&remote_addr, IP46_TYPE_ANY, &mp->face.ip.remote_addr); - mp->face.ip.swif = clib_host_to_net_u32 (sw_if); - - /* send it... */ - S (mp); - - /* Wait for a reply... */ - W (ret); - - return ret; -} - -static void - vl_api_hicn_api_face_ip_add_reply_t_handler - (vl_api_hicn_api_face_ip_add_reply_t * rmp) -{ - vat_main_t *vam = hicn_test_main.vat_main; - i32 retval = ntohl (rmp->retval); - - if (vam->async_mode) - { - vam->async_errors += (retval < 0); - return; - } - vam->retval = retval; - vam->result_ready = 1; - - if (vam->retval < 0) - { - //vpp_api_test infra will also print out string form of error - fformat (vam->ofp, " (API call error: %d)\n", vam->retval); - return; - } - fformat (vam->ofp, "New Face ID: %d\n", ntohl (rmp->faceid)); -} - -static int -api_hicn_api_face_udp_add (vat_main_t * vam) -{ - unformat_input_t *input = vam->input; - ip46_address_t local_addr = ip46_address_initializer; - ip46_address_t remote_addr = ip46_address_initializer; - u32 sport = 0; - u32 dport = 0; - int ret = HICN_ERROR_NONE; - int sw_if = ~0; - vl_api_hicn_api_face_add_t *mp; - - /* Parse args required to build the message */ - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) - { - if (unformat - (input, "local %U port %u", unformat_ip46_address, &local_addr, - IP46_TYPE_ANY, &sport)); - else - if (unformat - (input, "remote %U port %u", unformat_ip46_address, &remote_addr, - IP46_TYPE_ANY, &dport)); - else if (unformat (input, "intfc %d", &sw_if)); - else - { - break; - } - } - - /* Check for presence of both addresses */ - if (ip46_address_is_zero (&remote_addr) - || ip46_address_is_zero (&local_addr) || sport == 0 || dport == 0) - { - clib_warning - ("Incomplete UDP face. Please specify local and remote address and port"); - return (1); - } - /* Construct the API message */ - M (HICN_API_FACE_ADD, mp); - mp->type = clib_host_to_net_u32 (UDP_FACE); - ip_address_encode (&local_addr, IP46_TYPE_ANY, &mp->face.udp.local_addr); - ip_address_encode (&remote_addr, IP46_TYPE_ANY, &mp->face.udp.remote_addr); - mp->face.udp.lport = clib_host_to_net_u16 (sport); - mp->face.udp.rport = clib_host_to_net_u16 (dport); - mp->face.udp.swif = clib_host_to_net_u32 (sw_if); - - /* send it... */ - S (mp); - - /* Wait for a reply... */ - W (ret); - - return ret; -} - -static int -api_hicn_api_face_add (vat_main_t * vam) +api_hicn_api_face_params_get (vat_main_t * vam) { unformat_input_t *input = vam->input; - int ret = HICN_ERROR_NONE; - u32 type = ~0; - - /* Parse args required to build the message */ - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (input, "type %d", &type)); - else - { - break; - } - } - - vam->input = input; - - if (type == IP_FACE) - ret = api_hicn_api_face_ip_add (vam); - else if (type == UDP_FACE) - ret = api_hicn_api_face_udp_add (vam); - - return ret; -} - -static void - vl_api_hicn_api_face_add_reply_t_handler - (vl_api_hicn_api_face_add_reply_t * rmp) -{ - vat_main_t *vam = hicn_test_main.vat_main; - i32 retval = ntohl (rmp->retval); - - if (vam->async_mode) - { - vam->async_errors += (retval < 0); - return; - } - vam->retval = retval; - vam->result_ready = 1; - - if (vam->retval < 0) - { - //vpp_api_test infra will also print out string form of error - fformat (vam->ofp, " (API call error: %d)\n", vam->retval); - return; - } - fformat (vam->ofp, "New Face ID: %d\n", ntohl (rmp->faceid)); -} - -static int -api_hicn_api_face_ip_del (vat_main_t * vam) -{ - unformat_input_t *input = vam->input; - vl_api_hicn_api_face_ip_del_t *mp; - u32 faceid = 0, ret; - - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (input, "face %d", &faceid)) - {; - } - else - { - break; - } - } - - //Check for presence of face ID - if (faceid == ~0) - { - clib_warning ("Please specify face ID"); - return 1; - } - //Construct the API message - M (HICN_API_FACE_IP_DEL, mp); - mp->faceid = clib_host_to_net_u32 (faceid); - - //send it... - S (mp); - - //Wait for a reply... - W (ret); - - return ret; -} - -static int -api_hicn_api_face_del (vat_main_t * vam) -{ - unformat_input_t *input = vam->input; - vl_api_hicn_api_face_del_t *mp; - u32 faceid = 0, ret; - - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (input, "face %d", &faceid)) - {; - } - else - { - break; - } - } - - //Check for presence of face ID - if (faceid == ~0) - { - clib_warning ("Please specify face ID"); - return 1; - } - //Construct the API message - M (HICN_API_FACE_DEL, mp); - mp->faceid = clib_host_to_net_u32 (faceid); - - //send it... - S (mp); - - //Wait for a reply... - W (ret); - - return ret; -} - -static int -api_hicn_api_face_ip_params_get (vat_main_t * vam) -{ - unformat_input_t *input = vam->input; - vl_api_hicn_api_face_ip_params_get_t *mp; + vl_api_hicn_api_face_params_get_t *mp; u32 faceid = HICN_FACE_NULL, ret; while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) @@ -728,7 +464,7 @@ api_hicn_api_face_ip_params_get (vat_main_t * vam) return 1; } //Construct the API message - M (HICN_API_FACE_IP_PARAMS_GET, mp); + M (HICN_API_FACE_PARAMS_GET, mp); mp->faceid = clib_host_to_net_u32 (faceid); //send it... @@ -741,14 +477,13 @@ api_hicn_api_face_ip_params_get (vat_main_t * vam) } static void - vl_api_hicn_api_face_ip_params_get_reply_t_handler - (vl_api_hicn_api_face_ip_params_get_reply_t * rmp) + vl_api_hicn_api_face_params_get_reply_t_handler + (vl_api_hicn_api_face_params_get_reply_t * rmp) { vat_main_t *vam = hicn_test_main.vat_main; i32 retval = ntohl (rmp->retval); u8 *sbuf = 0; - ip46_address_t remote_addr; - ip46_address_t local_addr; + ip46_address_t nat_addr; if (vam->async_mode) { @@ -765,12 +500,10 @@ static void return; } vec_reset_length (sbuf); - ip_address_decode (&rmp->local_addr, &local_addr); - ip_address_decode (&rmp->remote_addr, &remote_addr); + ip_address_decode (&rmp->nat_addr, &nat_addr); sbuf = - format (0, "local_addr %U remote_addr %U", format_ip46_address, - &local_addr, 0 /*IP46_ANY_TYPE */ , format_ip46_address, - &remote_addr, 0 /*IP46_ANY_TYPE */ ); + format (0, "nat_addr %U", format_ip46_address, + &nat_addr, 0 /*IP46_ANY_TYPE */); fformat (vam->ofp, "%s swif %d flags %d\n", sbuf, @@ -779,48 +512,23 @@ static void } static void -format_ip_face (vl_api_hicn_face_ip_t * rmp) +format_face (vl_api_hicn_face_t * rmp) { vat_main_t *vam = hicn_test_main.vat_main; u8 *sbuf = 0; - ip46_address_t remote_addr; + ip46_address_t nat_addr; ip46_address_t local_addr; vec_reset_length (sbuf); - ip_address_decode (&rmp->local_addr, &local_addr); - ip_address_decode (&rmp->remote_addr, &remote_addr); - sbuf = - format (0, "local_addr %U remote_addr %U", format_ip46_address, - &local_addr, 0 /*IP46_ANY_TYPE */ , format_ip46_address, - &remote_addr, 0 /*IP46_ANY_TYPE */ ); + ip_address_decode (&rmp->nat_addr, &nat_addr); - fformat (vam->ofp, "%s swif %d flags %d name %s\n", - sbuf, - clib_net_to_host_u32 (rmp->swif), - clib_net_to_host_i32 (rmp->flags), rmp->if_name); -} - -static void -format_udp_face (vl_api_hicn_face_udp_t * rmp) -{ - vat_main_t *vam = hicn_test_main.vat_main; - u8 *sbuf = 0; - ip46_address_t remote_addr; - ip46_address_t local_addr; - - vec_reset_length (sbuf); - ip_address_decode (&rmp->local_addr, &local_addr); - ip_address_decode (&rmp->remote_addr, &remote_addr); - u16 lport = clib_net_to_host_u16 (rmp->lport); - u16 rport = clib_net_to_host_u16 (rmp->rport);; sbuf = - format (0, "local_addr %U port %u remote_addr %U port %u", - format_ip46_address, &local_addr, 0 /*IP46_ANY_TYPE */ , lport, - format_ip46_address, &remote_addr, 0 /*IP46_ANY_TYPE */ , rport); + format (0, "nat_addr %U", format_ip46_address, + &local_addr, 0 /*IP46_ANY_TYPE */); fformat (vam->ofp, "%s swif %d flags %d name %s\n", sbuf, - clib_net_to_host_u16 (rmp->swif), + clib_net_to_host_u32 (rmp->swif), clib_net_to_host_i32 (rmp->flags), rmp->if_name); } @@ -859,14 +567,7 @@ static void vl_api_hicn_api_faces_details_t_handler (vl_api_hicn_api_faces_details_t * mp) { - if (mp->type == IP_FACE) - { - format_ip_face (&(mp->face.ip)); - } - else - { - format_udp_face (&(mp->face.udp)); - } + format_face (&(mp->face)); } static int @@ -929,15 +630,7 @@ static void fformat (vam->ofp, " (API call error: %d)\n", vam->retval); return; } - - if (rmp->type == IP_FACE) - { - format_ip_face (&(rmp->face.ip)); - } - else - { - format_udp_face (&(rmp->face.udp)); - } + format_face (&(rmp->face)); } @@ -1613,6 +1306,7 @@ static void format_ip46_address, IP46_TYPE_ANY, &src_addr6); } + #include <hicn/hicn.api_test.c> /* diff --git a/hicn-plugin/src/infra.h b/hicn-plugin/src/infra.h index b859b8e46..fa493e7e9 100644 --- a/hicn-plugin/src/infra.h +++ b/hicn-plugin/src/infra.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: @@ -67,7 +67,7 @@ int hicn_infra_plugin_enable_disable (int enable_disable, int pit_max_size, f64 pit_max_lifetime_sec_req, - int cs_max_size, int cs_reserved_app); + int cs_max_size); /* vlib nodes that compose the hICN forwarder */ diff --git a/hicn-plugin/src/interest_hitcs.h b/hicn-plugin/src/interest_hitcs.h index c69564452..4164887d0 100644 --- a/hicn-plugin/src/interest_hitcs.h +++ b/hicn-plugin/src/interest_hitcs.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: @@ -43,7 +43,8 @@ typedef enum HICN_INTEREST_HITCS_NEXT_STRATEGY, HICN_INTEREST_HITCS_NEXT_PUSH, HICN_INTEREST_HITCS_NEXT_ERROR_DROP, - HICN_INTEREST_HITCS_NEXT_EMPTY, + HICN_INTEREST_HITCS_NEXT_IFACE4_OUT, + HICN_INTEREST_HITCS_NEXT_IFACE6_OUT, 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 d10f15afa..f569fa897 100644 --- a/hicn-plugin/src/interest_hitcs_node.c +++ b/hicn-plugin/src/interest_hitcs_node.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: @@ -184,9 +184,9 @@ hicn_interest_hitcs_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, * Retrieve the incoming iface and forward * the data through it */ - next0 = hicnb0->face_dpo_id.dpoi_next_node; - vnet_buffer (b0)->ip.adj_index[VLIB_TX] = - hicnb0->face_dpo_id.dpoi_index; + next0 = isv6 ? HICN_INTEREST_HITCS_NEXT_IFACE6_OUT : + HICN_INTEREST_HITCS_NEXT_IFACE4_OUT; + vnet_buffer (b0)->ip.adj_index[VLIB_TX] = hicnb0->face_id; clone_from_cs (vm, &pitp->u.cs.cs_pkt_buf, b0, isv6); @@ -277,9 +277,9 @@ VLIB_REGISTER_NODE(hicn_interest_hitcs_node) = .next_nodes = { [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" + [HICN_INTEREST_HITCS_NEXT_IFACE4_OUT] = "hicn4-iface-output", + [HICN_INTEREST_HITCS_NEXT_IFACE6_OUT] = "hicn6-iface-output", + [HICN_INTEREST_HITCS_NEXT_ERROR_DROP] = "error-drop" }, }; /* *INDENT-ON* */ diff --git a/hicn-plugin/src/interest_hitpit.h b/hicn-plugin/src/interest_hitpit.h index fc4cfc3ea..f26a25afa 100644 --- a/hicn-plugin/src/interest_hitpit.h +++ b/hicn-plugin/src/interest_hitpit.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: @@ -42,6 +42,8 @@ typedef enum { HICN_INTEREST_HITPIT_NEXT_INTEREST_HITCS, HICN_INTEREST_HITPIT_NEXT_STRATEGY, + HICN_INTEREST_HITPIT_NEXT_FACE4_OUTPUT, + HICN_INTEREST_HITPIT_NEXT_FACE6_OUTPUT, 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 a346dcc7e..25a25248c 100644 --- a/hicn-plugin/src/interest_hitpit_node.c +++ b/hicn-plugin/src/interest_hitpit_node.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: @@ -88,7 +88,7 @@ hicn_interest_hitpit_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, u8 dpo_ctx_id0; u8 found = 0; int nh_idx; - dpo_id_t *outface; + hicn_face_id_t outface; hicn_hash_entry_t *hash_entry0; hicn_buffer_t *hicnb0; int ret; @@ -166,7 +166,7 @@ hicn_interest_hitpit_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, */ found = - hicn_face_search (&(hicnb0->face_dpo_id), + hicn_face_search (hicnb0->face_id, &(pitp->u.pit.faces)); if (found) @@ -178,9 +178,10 @@ hicn_interest_hitpit_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, * Prepare the packet for the * forwarding */ - next0 = outface->dpoi_next_node; + next0 = isv6 ? HICN_INTEREST_HITPIT_NEXT_FACE6_OUTPUT : + HICN_INTEREST_HITPIT_NEXT_FACE4_OUTPUT; vnet_buffer (b0)->ip.adj_index[VLIB_TX] = - outface->dpoi_index; + outface; /* * Update the egress face in @@ -191,8 +192,8 @@ hicn_interest_hitpit_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, } else { - hicn_face_db_add_face_dpo (&hicnb0->face_dpo_id, - &pitp->u.pit.faces); + hicn_face_db_add_face (hicnb0->face_id, + &pitp->u.pit.faces); /* Aggregation */ drop_packet (&next0); @@ -293,6 +294,8 @@ VLIB_REGISTER_NODE(hicn_interest_hitpit_node) = { [HICN_INTEREST_HITPIT_NEXT_INTEREST_HITCS] = "hicn-interest-hitcs", [HICN_INTEREST_HITPIT_NEXT_STRATEGY] = "hicn-strategy", + [HICN_INTEREST_HITPIT_NEXT_STRATEGY] = "hicn4-face-output", + [HICN_INTEREST_HITPIT_NEXT_STRATEGY] = "hicn6-face-output", [HICN_INTEREST_HITPIT_NEXT_ERROR_DROP] = "error-drop", }, }; diff --git a/hicn-plugin/src/mapme.h b/hicn-plugin/src/mapme.h index 071590ede..7ed0af88b 100644 --- a/hicn-plugin/src/mapme.h +++ b/hicn-plugin/src/mapme.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: @@ -34,6 +34,9 @@ #define INVALID_SEQ 0 +STATIC_ASSERT (sizeof(u32) == sizeof(seq_t), + "seq_t is not 4 bytes"); + typedef struct hicn_mapme_conf_s { hicn_mapme_conf_t conf; @@ -86,12 +89,12 @@ hicn_mapme_nh_set (hicn_mapme_tfib_t * tfib, dpo_id_t * face_id) * @brief Add a next hop iif it is not already a next hops */ static_always_inline int -hicn_mapme_nh_add (hicn_mapme_tfib_t * tfib, dpo_id_t * face_id) +hicn_mapme_nh_add (hicn_mapme_tfib_t * tfib, hicn_face_id_t face_id) { for (u8 pos = 0; pos < tfib->entry_count; pos++) - if (dpo_cmp (&tfib->next_hops[pos], face_id) == 0) + if (tfib->next_hops[pos] == face_id) return 0; - tfib->next_hops[tfib->entry_count++] = *face_id; + tfib->next_hops[tfib->entry_count++] = face_id; return 0; } @@ -133,7 +136,7 @@ hicn_mapme_tfib_clear (hicn_mapme_tfib_t * tfib) u8 pos = ~0; for (pos = start_pos; pos < HICN_PARAM_FIB_ENTRY_NHOPS_MAX; pos++) { - hicn_face_unlock (&tfib->next_hops[pos]); + hicn_face_unlock_with_id (&tfib->next_hops[pos]); tfib->next_hops[pos] = invalid; break; } @@ -144,9 +147,9 @@ hicn_mapme_tfib_clear (hicn_mapme_tfib_t * tfib) } static_always_inline int -hicn_mapme_tfib_del (hicn_mapme_tfib_t * tfib, dpo_id_t * face_id) +hicn_mapme_tfib_del (hicn_mapme_tfib_t * tfib, hicn_face_id_t face_id) { - dpo_id_t invalid = NEXT_HOP_INVALID; + hicn_face_id_t invalid = NEXT_HOP_INVALID; /* * We need to do a linear scan of TFIB entries to find the one to * remove @@ -154,9 +157,9 @@ hicn_mapme_tfib_del (hicn_mapme_tfib_t * tfib, dpo_id_t * face_id) u8 start_pos = HICN_PARAM_FIB_ENTRY_NHOPS_MAX - tfib->tfib_entry_count; u8 pos = ~0; for (pos = start_pos; pos < HICN_PARAM_FIB_ENTRY_NHOPS_MAX; pos++) - if (dpo_cmp (&tfib->next_hops[pos], face_id) == 0) + if (tfib->next_hops[pos] == face_id) { - hicn_face_unlock (&tfib->next_hops[pos]); + hicn_face_unlock_with_id (&tfib->next_hops[pos]); tfib->next_hops[pos] = invalid; break; } @@ -169,7 +172,7 @@ hicn_mapme_tfib_del (hicn_mapme_tfib_t * tfib, dpo_id_t * face_id) /* Likely we won't receive a new IU twice from the same face */ if (PREDICT_TRUE (pos > start_pos)) memmove (tfib->next_hops + start_pos, tfib->next_hops + start_pos + 1, - (pos - start_pos) * sizeof (dpo_id_t)); + (pos - start_pos) * sizeof (hicn_face_id_t)); return 0; } diff --git a/hicn-plugin/src/mapme_ctrl.h b/hicn-plugin/src/mapme_ctrl.h index e7c1cdf64..732a74b30 100644 --- a/hicn-plugin/src/mapme_ctrl.h +++ b/hicn-plugin/src/mapme_ctrl.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: @@ -51,34 +51,17 @@ typedef enum * @brief Returns the next hop node on which we can send an ACK packet */ always_inline hicn_mapme_ctrl_next_t -hicn_mapme_get_dpo_iface_node (dpo_id_t * dpo) +hicn_mapme_get_dpo_iface_node (hicn_face_id_t face_id) { - if (dpo->dpoi_type == hicn_face_ip_type) - { - switch (dpo->dpoi_proto) - { - case DPO_PROTO_IP4: - return HICN_MAPME_CTRL_NEXT_IP4_OUTPUT; - case DPO_PROTO_IP6: - return HICN_MAPME_CTRL_NEXT_IP6_OUTPUT; - default: - return HICN_MAPME_CTRL_NEXT_ERROR_DROP; - } - } - else if (dpo->dpoi_type == hicn_face_udp_type) - { - switch (dpo->dpoi_proto) - { - case DPO_PROTO_IP4: - return HICN_MAPME_CTRL_NEXT_UDP46_OUTPUT; - case DPO_PROTO_IP6: - return HICN_MAPME_CTRL_NEXT_UDP66_OUTPUT; - default: - return HICN_MAPME_CTRL_NEXT_ERROR_DROP; - } - } - else + hicn_face_t * face = hicn_dpoi_get_from_idx(face_id); + + switch (dpo->dpoi_proto) { + case DPO_PROTO_IP4: + return HICN_MAPME_CTRL_NEXT_IP4_OUTPUT; + case DPO_PROTO_IP6: + return HICN_MAPME_CTRL_NEXT_IP6_OUTPUT; + default: return HICN_MAPME_CTRL_NEXT_ERROR_DROP; } } diff --git a/hicn-plugin/src/mapme_ctrl_node.c b/hicn-plugin/src/mapme_ctrl_node.c index ed25a31b0..1708f2b2d 100644 --- a/hicn-plugin/src/mapme_ctrl_node.c +++ b/hicn-plugin/src/mapme_ctrl_node.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: @@ -74,7 +74,7 @@ preprocess_in_face (hicn_type_t type, dpo_id_t * in, dpo_id_t * out) */ static_always_inline bool hicn_mapme_process_ctrl (vlib_main_t * vm, vlib_buffer_t * b, - dpo_id_t * in_face) + hicn_face_id_t in_face) { seq_t fib_seq; const dpo_id_t *dpo; @@ -158,19 +158,21 @@ hicn_mapme_process_ctrl (vlib_main_t * vm, vlib_buffer_t * b, /* Move next hops to TFIB... but in_face... */ for (u8 pos = 0; pos < tfib->entry_count; pos++) { - if (dpo_cmp (&tfib->next_hops[pos], in_face) == 0) + if (tfib->next_hops[pos] == in_face) { 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); - hicn_mapme_tfib_add (tfib, &tfib->next_hops[pos]); + in_face, tfib->next_hops[pos]); + hicn_mapme_tfib_add (tfib, tfib->next_hops[pos]); } /* ... and set ingress face as next_hop */ in_face->dpoi_next_node = hicn_mapme_get_dpo_vlib_edge (in_face); + + /* Convert possible iFate into a face TODO!!!*/ hicn_mapme_nh_set (tfib, in_face); /* We transmit both the prefix and the full dpo (type will be needed to pick the right transmit node */ @@ -273,7 +275,7 @@ hicn_mapme_ctrl_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, hb = hicn_get_buffer (b0); /* This determines the next node on which the ack will be sent back */ - u32 next0 = hicn_mapme_get_dpo_iface_node (&hb->face_dpo_id); + u32 next0 = hicn_mapme_get_dpo_iface_node (&hb->face_id); /* Preprocessing is needed to precompute in the dpo the next node * that will have to be followed by regular interests when being diff --git a/hicn-plugin/src/mapme_eventmgr.h b/hicn-plugin/src/mapme_eventmgr.h index 338915d63..8414861b4 100644 --- a/hicn-plugin/src/mapme_eventmgr.h +++ b/hicn-plugin/src/mapme_eventmgr.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: @@ -15,6 +15,7 @@ #include <vlib/vlib.h> // vlib_node_registration_t (vlib/node.h) +#include <hicn/name.h> /* * Structure carrying all necessary information for managing Special Interest * (re)transmissions. diff --git a/hicn-plugin/src/params.h b/hicn-plugin/src/params.h index 606d42992..d8e4dc247 100644 --- a/hicn-plugin/src/params.h +++ b/hicn-plugin/src/params.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: @@ -37,7 +37,7 @@ STATIC_ASSERT ((HICN_PARAM_FACES_MAX & (HICN_PARAM_FACES_MAX - 1)) == 0, #define HICN_PARAM_HICN_NAME_LEN_MAX 20 //bytes // Max next - hops supported in a FIB entry -#define HICN_PARAM_FIB_ENTRY_NHOPS_MAX 5 +#define HICN_PARAM_FIB_ENTRY_NHOPS_MAX 10 // Default and limit on weight, whatever weight means #define HICN_PARAM_FIB_ENTRY_NHOP_WGHT_DFLT 0x10 diff --git a/hicn-plugin/src/pcs.c b/hicn-plugin/src/pcs.c index 4355aaeb0..6c44b9d83 100644 --- a/hicn-plugin/src/pcs.c +++ b/hicn-plugin/src/pcs.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: @@ -34,7 +34,6 @@ hicn_pit_create (hicn_pit_cs_t * p, u32 num_elems) (HICN_PARAM_CS_LRU_DEFAULT * HICN_PARAM_CS_RESERVED_APP / 100); p->policy_state.count = 0; p->policy_state.head = p->policy_state.tail = 0; - p->pcs_app_max = HICN_PARAM_CS_LRU_DEFAULT - p->policy_state.max; p->policy_vft.hicn_cs_insert = hicn_cs_lru.hicn_cs_insert; p->policy_vft.hicn_cs_update = hicn_cs_lru.hicn_cs_update; diff --git a/hicn-plugin/src/pcs.h b/hicn-plugin/src/pcs.h index fc63bd0a6..1d99136a2 100644 --- a/hicn-plugin/src/pcs.h +++ b/hicn-plugin/src/pcs.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,8 +22,8 @@ #include "error.h" #include "cache_policies/cs_policy.h" #include "faces/face.h" -#include "faces/ip/dpo_ip.h" -#include "faces/app/face_prod.h" +#include "faces/dpo_face.h" +//#include "faces/app/face_prod.h" /* The PIT and CS are stored as a union */ #define HICN_PIT_NULL_TYPE 0 @@ -84,36 +84,37 @@ typedef struct __attribute__ ((packed)) hicn_pit_entry_s } hicn_pit_entry_t; -#define HICN_CS_ENTRY_OPAQUE_SIZE HICN_HASH_NODE_APP_DATA_SIZE - 40 +#define HICN_CS_ENTRY_OPAQUE_SIZE HICN_HASH_NODE_APP_DATA_SIZE - 36 /* * CS entry, unioned with a PIT entry below */ typedef struct __attribute__ ((packed)) hicn_cs_entry_s { - /* 22B + 2B = 24B */ + /* 18B + 2B = 20B */ u16 align; /* Packet buffer, if held */ - /* 18B + 4B = 22B */ + /* 20B + 4B = 24B */ u32 cs_pkt_buf; /* Ingress face */ - /* 24B + 8B = 32B */ - //Fix alignment issues - union - { - dpo_id_t cs_rxface; - u64 cs_rxface_u64; - }; + /* 24B + 4B = 28B */ + hicn_face_id_t cs_rxface; + /* //Fix alignment issues */ + /* union */ + /* { */ + /* dpo_id_t cs_rxface; */ + /* u64 cs_rxface_u64; */ + /* }; */ /* Linkage for LRU, in the form of hashtable node indexes */ - /* 32B + 8B = 40B */ + /* 28B + 8B = 36B */ u32 cs_lru_prev; u32 cs_lru_next; /* Reserved for implementing cache policy different than LRU */ - /* 40B + (64 - 40)B = 64B */ + /* 36B + (64 - 36)B = 64B */ u8 opaque[HICN_CS_ENTRY_OPAQUE_SIZE]; @@ -154,10 +155,6 @@ typedef struct hicn_pit_cs_s /* Total size of PCS */ u32 pcs_size; - /* Memory reserved for appfaces */ - u32 pcs_app_max; - u32 pcs_app_count; - hicn_cs_policy_t policy_state; hicn_cs_policy_vft_t policy_vft; @@ -170,7 +167,7 @@ always_inline void hicn_pit_to_cs (vlib_main_t * vm, hicn_pit_cs_t * pitcs, hicn_pcs_entry_t * pcs_entry, hicn_hash_entry_t * hash_entry, hicn_hash_node_t * node, const hicn_dpo_vft_t * dpo_vft, - dpo_id_t * hicn_dpo_id, dpo_id_t * inface_id, u8 is_appface); + dpo_id_t * hicn_dpo_id, hicn_face_id_t inface_id, u8 is_appface); always_inline void hicn_pcs_cs_update (vlib_main_t * vm, hicn_pit_cs_t * pitcs, @@ -197,7 +194,7 @@ hicn_pcs_cs_insert_update (vlib_main_t * vm, hicn_pit_cs_t * pitcs, hicn_hash_entry_t ** hash_entry, 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, dpo_id_t * inface); + u8 * bucket_is_overflow, hicn_face_id_t inface); always_inline int hicn_pcs_pit_insert (hicn_pit_cs_t * pitcs, hicn_pcs_entry_t * entry, @@ -285,16 +282,6 @@ hicn_pit_set_lru_max (hicn_pit_cs_t * p, u32 limit) } /* - * Configure CS LRU limit. Zero is accepted, means 'no limit', probably not a - * good choice. - */ -static inline void -hicn_pit_set_lru_app_max (hicn_pit_cs_t * p, u32 limit) -{ - p->pcs_app_max = limit; -} - -/* * Accessor for PIT interest counter. */ static inline u32 @@ -385,7 +372,7 @@ always_inline void hicn_pit_to_cs (vlib_main_t * vm, hicn_pit_cs_t * pitcs, hicn_pcs_entry_t * pcs_entry, hicn_hash_entry_t * hash_entry, hicn_hash_node_t * node, const hicn_dpo_vft_t * dpo_vft, - dpo_id_t * hicn_dpo_id, dpo_id_t * inface_id, u8 is_appface) + dpo_id_t * hicn_dpo_id, hicn_face_id_t inface_id, u8 is_appface) { /* @@ -401,25 +388,14 @@ hicn_pit_to_cs (vlib_main_t * vm, hicn_pit_cs_t * pitcs, node->hn_flags |= HICN_HASH_NODE_CS_FLAGS; pcs_entry->shared.entry_flags |= HICN_PCS_ENTRY_CS_FLAG; - pcs_entry->u.cs.cs_rxface = *inface_id; + pcs_entry->u.cs.cs_rxface = inface_id; /* Update the CS according to the policy */ hicn_cs_policy_t *policy_state; hicn_cs_policy_vft_t *policy_vft; - if (is_appface) - { - dpo_id_t *face_dpo = (dpo_id_t *) & (pcs_entry->u.cs.cs_rxface); - hicn_face_t *face = hicn_dpoi_get_from_idx (face_dpo->dpoi_index); - hicn_face_prod_t *prod_face = (hicn_face_prod_t *) face->data; - policy_state = &prod_face->policy; - policy_vft = &prod_face->policy_vft; - } - else - { - policy_state = &pitcs->policy_state; - policy_vft = &pitcs->policy_vft; - } + policy_state = &pitcs->policy_state; + policy_vft = &pitcs->policy_vft; policy_vft->hicn_cs_insert (pitcs, node, pcs_entry, policy_state); pitcs->pcs_cs_count++; @@ -456,42 +432,18 @@ hicn_pcs_cs_update (vlib_main_t * vm, hicn_pit_cs_t * pitcs, hicn_cs_policy_t *policy_state; hicn_cs_policy_vft_t *policy_vft; - dpo_id_t *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; - } - } - - if (dpo_cmp (&entry->u.cs.cs_rxface, &old_entry->u.cs.cs_rxface) != 0) + if (entry->u.cs.cs_rxface != old_entry->u.cs.cs_rxface) { /* Dequeue content from the old queue */ policy_vft->hicn_cs_dequeue (pitcs, node, old_entry, policy_state); - dpo_copy (&old_entry->u.cs.cs_rxface, &entry->u.cs.cs_rxface); - face_dpo = (dpo_id_t *) & (old_entry->u.cs.cs_rxface); + old_entry->u.cs.cs_rxface = 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; - } - } - policy_vft->hicn_cs_insert (pitcs, node, old_entry, policy_state); if (policy_state->count > policy_state->max) @@ -530,20 +482,9 @@ hicn_pcs_cs_delete (vlib_main_t * vm, hicn_pit_cs_t * pitcs, hicn_cs_policy_t *policy_state; hicn_cs_policy_vft_t *policy_vft; - dpo_id_t *face_dpo = (dpo_id_t *) & ((*pcs_entryp)->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; - } - } policy_vft->hicn_cs_dequeue (pitcs, (*nodep), (*pcs_entryp), policy_state); @@ -589,20 +530,9 @@ hicn_pcs_cs_insert (vlib_main_t * vm, hicn_pit_cs_t * pitcs, hicn_cs_policy_t *policy_state; hicn_cs_policy_vft_t *policy_vft; - dpo_id_t *face_dpo = (dpo_id_t *) & (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; - } - } policy_vft->hicn_cs_insert (pitcs, node, entry, policy_state); pitcs->pcs_cs_count++; @@ -639,13 +569,13 @@ hicn_pcs_cs_insert_update (vlib_main_t * vm, hicn_pit_cs_t * pitcs, hicn_hash_entry_t ** hash_entry, 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, dpo_id_t * inface) + u8 * bucket_is_overflow, hicn_face_id_t inface) { int ret; ASSERT (entry == hicn_hashtb_node_data (node)); - entry->u.cs.cs_rxface = *inface; + entry->u.cs.cs_rxface = inface; ret = hicn_pcs_cs_insert (vm, pitcs, entry, node, hash_entry, hashval, node_id, dpo_ctx_id, vft_id, is_cs, hash_entry_id, bucket_id, diff --git a/hicn-plugin/src/route.c b/hicn-plugin/src/route.c index c208dd4c1..263bf8c56 100644 --- a/hicn-plugin/src/route.c +++ b/hicn-plugin/src/route.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: @@ -96,12 +96,11 @@ hicn_route_add_nhops (hicn_face_id_t * face_id, u32 len, { const dpo_id_t *hicn_dpo_id; int ret = HICN_ERROR_NONE; - dpo_id_t faces_dpo_tmp[HICN_PARAM_FIB_ENTRY_NHOPS_MAX]; - int n_face_dpo = 0; + hicn_face_id_t faces_id_tmp[HICN_PARAM_FIB_ENTRY_NHOPS_MAX]; + int n_face_id = 0; const hicn_dpo_vft_t *dpo_vft; u32 fib_index; vlib_main_t *vm = vlib_get_main (); - hicn_face_vft_t *face_vft = NULL; if (face_id == NULL) { @@ -114,19 +113,16 @@ hicn_route_add_nhops (hicn_face_id_t * face_id, u32 len, */ for (int i = 0; i < clib_min (HICN_PARAM_FIB_ENTRY_NHOPS_MAX, len); i++) { - hicn_face_t *face = hicn_dpoi_get_from_idx (face_id[i]); - face_vft = hicn_face_get_vft (face->shared.face_type); - dpo_id_t face_dpo = DPO_INVALID; - face_vft->hicn_face_get_dpo (face, &face_dpo); + hicn_face_t *face = hicn_dpoi_get_from_idx_safe (face_id[i]); - if (!dpo_id_is_valid (&face_dpo)) + if (face == NULL) { vlib_cli_output (vm, "Face %d not found, skip...\n", face_id[i]); return ret; } else { - faces_dpo_tmp[n_face_dpo++] = face_dpo; + faces_id_tmp[n_face_id++] = face_id[i]; } } @@ -134,22 +130,22 @@ hicn_route_add_nhops (hicn_face_id_t * face_id, u32 len, if (ret == HICN_ERROR_NONE) { - for (int i = 0; i < n_face_dpo && (ret == HICN_ERROR_NONE); i++) + for (int i = 0; i < n_face_id && (ret == HICN_ERROR_NONE); i++) { u32 vft_id = hicn_dpo_get_vft_id (hicn_dpo_id); dpo_vft = hicn_dpo_get_vft (vft_id); hicn_face_t *face = - hicn_dpoi_get_from_idx (faces_dpo_tmp[i].dpoi_index); + hicn_dpoi_get_from_idx (faces_id_tmp[i]); //Disable feature on the interface if (prefix->fp_proto == FIB_PROTOCOL_IP4) vnet_feature_enable_disable ("ip4-local", "hicn-data-input-ip4", - face->shared.sw_if, 1, 0, 0); + face->sw_if, 1, 0, 0); else if (prefix->fp_proto == FIB_PROTOCOL_IP6) vnet_feature_enable_disable ("ip6-local", "hicn-data-input-ip6", - face->shared.sw_if, 1, 0, 0); + face->sw_if, 1, 0, 0); - ret = dpo_vft->hicn_dpo_add_update_nh (&faces_dpo_tmp[i], + ret = dpo_vft->hicn_dpo_add_update_nh (faces_id_tmp[i], hicn_dpo_id->dpoi_index); } } @@ -164,12 +160,11 @@ hicn_route_add (hicn_face_id_t * face_id, u32 len, dpo_id_t dpo = DPO_INVALID; const dpo_id_t *hicn_dpo_id; int ret = HICN_ERROR_NONE; - dpo_id_t face_dpo_tmp[HICN_PARAM_FIB_ENTRY_NHOPS_MAX]; - int n_face_dpo = 0; + hicn_face_id_t face_id_tmp[HICN_PARAM_FIB_ENTRY_NHOPS_MAX]; + int n_face_id = 0; index_t dpo_idx; u32 fib_index; vlib_main_t *vm = vlib_get_main (); - hicn_face_vft_t *face_vft = NULL; if (face_id == NULL || !hicn_dpoi_idx_is_valid (*face_id)) { @@ -183,18 +178,15 @@ hicn_route_add (hicn_face_id_t * face_id, u32 len, for (int i = 0; i < clib_min (HICN_PARAM_FIB_ENTRY_NHOPS_MAX, len); i++) { hicn_face_t *face = hicn_dpoi_get_from_idx (face_id[i]); - face_vft = hicn_face_get_vft (face->shared.face_type); - dpo_id_t face_dpo = DPO_INVALID; - face_vft->hicn_face_get_dpo (face, &face_dpo); - if (!dpo_id_is_valid (&face_dpo)) + if (face == NULL) { vlib_cli_output (vm, "Face %d not found, skip...\n", face_id[i]); return ret; } else { - face_dpo_tmp[n_face_dpo++] = face_dpo; + face_id_tmp[n_face_id++] = face_id[i]; } } @@ -202,22 +194,22 @@ hicn_route_add (hicn_face_id_t * face_id, u32 len, if (ret == HICN_ERROR_ROUTE_NOT_FOUND) { - dpo_id_t nhops[HICN_PARAM_FIB_ENTRY_NHOPS_MAX]; - for (int i = 0; i < n_face_dpo; i++) + hicn_face_id_t nhops[HICN_PARAM_FIB_ENTRY_NHOPS_MAX]; + for (int i = 0; i < n_face_id; i++) { - clib_memcpy (&nhops[i], &face_dpo_tmp[i], sizeof (dpo_id_t)); + nhops[i] = face_id_tmp[i]; hicn_face_t *face = - hicn_dpoi_get_from_idx (face_dpo_tmp[i].dpoi_index); + hicn_dpoi_get_from_idx (face_id_tmp[i]); //Disable feature on the interface if (prefix->fp_proto == FIB_PROTOCOL_IP4) vnet_feature_enable_disable ("ip4-local", "hicn-data-input-ip4", - face->shared.sw_if, 1, 0, 0); + face->sw_if, 1, 0, 0); else if (prefix->fp_proto == FIB_PROTOCOL_IP6) vnet_feature_enable_disable ("ip6-local", "hicn-data-input-ip6", - face->shared.sw_if, 1, 0, 0); + face->sw_if, 1, 0, 0); } - default_dpo.hicn_dpo_create (prefix->fp_proto, nhops, n_face_dpo, + default_dpo.hicn_dpo_create (prefix->fp_proto, nhops, n_face_id, &dpo_idx); /* the value we got when we registered */ @@ -312,10 +304,10 @@ hicn_route_del_nhop (fib_prefix_t * prefix, hicn_face_id_t face_id) //Disable feature on the interface if (prefix->fp_proto == FIB_PROTOCOL_IP4) vnet_feature_enable_disable ("ip4-local", "hicn-data-input-ip4", - face->shared.sw_if, 0, 0, 0); + face->sw_if, 0, 0, 0); else if (prefix->fp_proto == FIB_PROTOCOL_IP6) vnet_feature_enable_disable ("ip6-local", "hicn-data-input-ip6", - face->shared.sw_if, 0, 0, 0); + face->sw_if, 0, 0, 0); ret = dpo_vft->hicn_dpo_del_nh (face_id, hicn_dpo_id->dpoi_index); diff --git a/hicn-plugin/src/strategies/dpo_mw.c b/hicn-plugin/src/strategies/dpo_mw.c index eebb572c4..2ec699e06 100644 --- a/hicn-plugin/src/strategies/dpo_mw.c +++ b/hicn-plugin/src/strategies/dpo_mw.c @@ -76,8 +76,6 @@ format_hicn_strategy_mw_ctx (u8 * s, va_list * ap) index_t index = va_arg (*ap, index_t); 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_ctx = hicn_strategy_dpo_ctx_get (index); @@ -97,24 +95,20 @@ format_hicn_strategy_mw_ctx (u8 * s, va_list * ap) buf = format (NULL, "TFIB"); else continue; - next_hop = &dpo_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", mw_dpo_ctx->weight[i]); - s = format (s, " %s", buf); - } + + s = format (s, "\n"); + 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); } return (s); } void -hicn_strategy_mw_ctx_create (dpo_proto_t proto, const dpo_id_t * next_hop, +hicn_strategy_mw_ctx_create (dpo_proto_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; @@ -132,7 +126,7 @@ hicn_strategy_mw_ctx_create (dpo_proto_t proto, const dpo_id_t * next_hop, } int -hicn_strategy_mw_ctx_add_nh (const dpo_id_t * nh, index_t dpo_idx) +hicn_strategy_mw_ctx_add_nh (hicn_face_id_t nh, index_t dpo_idx) { hicn_dpo_ctx_t *hicn_strategy_dpo_ctx = hicn_strategy_dpo_ctx_get (dpo_idx); u8 pos = 0; diff --git a/hicn-plugin/src/strategies/dpo_mw.h b/hicn-plugin/src/strategies/dpo_mw.h index ccc8d044f..45a3f3384 100644 --- a/hicn-plugin/src/strategies/dpo_mw.h +++ b/hicn-plugin/src/strategies/dpo_mw.h @@ -60,7 +60,7 @@ hicn_dpo_ctx_t *hicn_strategy_mw_ctx_get (index_t index); * @return HICN_ERROR_NONE if the creation was fine, otherwise EINVAL */ void -hicn_strategy_mw_ctx_create (dpo_proto_t proto, const dpo_id_t * next_hop, +hicn_strategy_mw_ctx_create (dpo_proto_t proto, const hicn_face_id_t * next_hop, int nh_len, index_t * dpo_idx); /** @@ -75,7 +75,7 @@ hicn_strategy_mw_ctx_create (dpo_proto_t proto, const dpo_id_t * 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); +int hicn_strategy_mw_ctx_add_nh (hicn_face_id_t nh, index_t dpo_idx); /** * @brief Delete a next hop in the dpo ctx. diff --git a/hicn-plugin/src/strategies/dpo_rr.c b/hicn-plugin/src/strategies/dpo_rr.c index a67b06acb..40620bb51 100644 --- a/hicn-plugin/src/strategies/dpo_rr.c +++ b/hicn-plugin/src/strategies/dpo_rr.c @@ -76,8 +76,6 @@ format_hicn_strategy_rr_ctx (u8 * s, va_list * ap) index_t index = va_arg (*ap, index_t); 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); dpo_ctx = hicn_strategy_dpo_ctx_get (index); @@ -88,7 +86,7 @@ format_hicn_strategy_rr_ctx (u8 * s, va_list * ap) s = format (s, "hicn-rr, next hop Face %d", - dpo_ctx->next_hops[rr_dpo_ctx->current_nhop].dpoi_index); + dpo_ctx->next_hops[rr_dpo_ctx->current_nhop]); for (i = 0; i < HICN_PARAM_FIB_ENTRY_NHOPS_MAX; i++) { @@ -101,23 +99,18 @@ format_hicn_strategy_rr_ctx (u8 * s, va_list * ap) else continue; - next_hop = &dpo_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, " %s", buf); - } + s = format (s, "\n"); + s = + format (s, "%U ", format_hicn_face, dpo_ctx->next_hops[i], + indent); + s = format (s, " %s", buf); } return (s); } void -hicn_strategy_rr_ctx_create (dpo_proto_t proto, const dpo_id_t * next_hop, +hicn_strategy_rr_ctx_create (dpo_proto_t proto, const hicn_face_id_t * next_hop, int nh_len, index_t * dpo_idx) { hicn_strategy_rr_ctx_t *hicn_strategy_rr_ctx; @@ -135,7 +128,7 @@ hicn_strategy_rr_ctx_create (dpo_proto_t proto, const dpo_id_t * next_hop, } int -hicn_strategy_rr_ctx_add_nh (const dpo_id_t * nh, index_t dpo_idx) +hicn_strategy_rr_ctx_add_nh (hicn_face_id_t nh, index_t dpo_idx) { hicn_dpo_ctx_t *hicn_strategy_dpo_ctx = hicn_strategy_dpo_ctx_get (dpo_idx); u8 pos = 0; diff --git a/hicn-plugin/src/strategies/dpo_rr.h b/hicn-plugin/src/strategies/dpo_rr.h index 8afd0dabc..cb6e693e3 100644 --- a/hicn-plugin/src/strategies/dpo_rr.h +++ b/hicn-plugin/src/strategies/dpo_rr.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: @@ -62,7 +62,7 @@ hicn_dpo_ctx_t *hicn_strategy_rr_ctx_get (index_t index); * @return HICN_ERROR_NONE if the creation was fine, otherwise EINVAL */ void -hicn_strategy_rr_ctx_create (dpo_proto_t proto, const dpo_id_t * next_hop, +hicn_strategy_rr_ctx_create (dpo_proto_t proto, const hicn_face_id_t * next_hop, int nh_len, index_t * dpo_idx); /** @@ -77,7 +77,7 @@ hicn_strategy_rr_ctx_create (dpo_proto_t proto, const dpo_id_t * 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); +int hicn_strategy_rr_ctx_add_nh (hicn_face_id_t nh, index_t dpo_idx); /** * @brief Delete a next hop in the dpo ctx. diff --git a/hicn-plugin/src/strategies/strategy_mw.c b/hicn-plugin/src/strategies/strategy_mw.c index 2422d4fed..fe4d5896a 100644 --- a/hicn-plugin/src/strategies/strategy_mw.c +++ b/hicn-plugin/src/strategies/strategy_mw.c @@ -25,7 +25,7 @@ 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); + hicn_face_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); @@ -51,7 +51,7 @@ hicn_mw_strategy_get_vft (void) /* 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_select_next_hop_mw (index_t dpo_idx, int *nh_idx, hicn_face_id_t* outface) { hicn_dpo_ctx_t *dpo_ctx = hicn_strategy_dpo_ctx_get (dpo_idx); @@ -64,20 +64,14 @@ hicn_select_next_hop_mw (index_t dpo_idx, int *nh_idx, dpo_id_t ** outface) u8 next_hop_index = 0; for (int i = 0; i < dpo_ctx->entry_count; 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]) - { - next_hop_index = 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 (&dpo_ctx->next_hops[next_hop_index])) - return HICN_ERROR_STRATEGY_NH_NOT_FOUND; - - *outface = (dpo_id_t *) & dpo_ctx->next_hops[next_hop_index]; + *outface = dpo_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 701f96fa7..636d7effa 100644 --- a/hicn-plugin/src/strategies/strategy_mw_cli.c +++ b/hicn-plugin/src/strategies/strategy_mw_cli.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: @@ -97,7 +97,7 @@ hicn_mw_strategy_cli_set_weight_command_fn (vlib_main_t * vm, (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) + if (hicn_dpo_ctx->next_hops[i] == faceid) idx = i; if (idx == ~0) diff --git a/hicn-plugin/src/strategies/strategy_rr.c b/hicn-plugin/src/strategies/strategy_rr.c index cdcca7f2a..4c65ce52a 100644 --- a/hicn-plugin/src/strategies/strategy_rr.c +++ b/hicn-plugin/src/strategies/strategy_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: @@ -26,7 +26,7 @@ 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); + hicn_face_id_t* outface); u8 *hicn_strategy_format_trace_rr (u8 * s, hicn_strategy_trace_t * t); u8 *hicn_strategy_format_rr (u8 * s, va_list * ap); @@ -51,7 +51,7 @@ hicn_rr_strategy_get_vft (void) /* 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_select_next_hop_rr (index_t dpo_idx, int *nh_idx, hicn_face_id_t* outface) { hicn_dpo_ctx_t *dpo_ctx = hicn_strategy_dpo_ctx_get (dpo_idx); @@ -61,15 +61,8 @@ 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 *) dpo_ctx->data; - if (dpo_id_is_valid - (&dpo_ctx->next_hops[hicn_strategy_rr_ctx->current_nhop])) - { - *outface = - (dpo_id_t *) & dpo_ctx->next_hops[hicn_strategy_rr_ctx->current_nhop]; - - } - else - return HICN_ERROR_STRATEGY_NH_NOT_FOUND; + *outface = + dpo_ctx->next_hops[hicn_strategy_rr_ctx->current_nhop]; hicn_strategy_rr_ctx->current_nhop = (hicn_strategy_rr_ctx->current_nhop + 1) % dpo_ctx->entry_count; diff --git a/hicn-plugin/src/strategy.h b/hicn-plugin/src/strategy.h index c18ae4eea..a63db84d4 100644 --- a/hicn-plugin/src/strategy.h +++ b/hicn-plugin/src/strategy.h @@ -54,7 +54,7 @@ typedef struct hicn_strategy_vft_s void (*hicn_on_interest_timeout) (index_t dpo_idx); 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); + hicn_face_id_t* outface); u8 *(*hicn_format_strategy_trace) (u8 *, hicn_strategy_trace_t *); u8 *(*hicn_format_strategy) (u8 * s, va_list * ap); /**< Format an hICN dpo*/ @@ -64,6 +64,8 @@ typedef enum { HICN_STRATEGY_NEXT_INTEREST_HITPIT, HICN_STRATEGY_NEXT_INTEREST_HITCS, + HICN_STRATEGY_NEXT_INTEREST_FACE4, + HICN_STRATEGY_NEXT_INTEREST_FACE6, HICN_STRATEGY_NEXT_ERROR_DROP, HICN_STRATEGY_N_NEXT, } hicn_strategy_next_t; diff --git a/hicn-plugin/src/strategy_dpo_ctx.c b/hicn-plugin/src/strategy_dpo_ctx.c index 6ec1407fb..342c78bb5 100644 --- a/hicn-plugin/src/strategy_dpo_ctx.c +++ b/hicn-plugin/src/strategy_dpo_ctx.c @@ -97,7 +97,7 @@ hicn_strategy_dpo_ctx_alloc () } int -hicn_strategy_dpo_ctx_add_nh (const dpo_id_t * nh, hicn_dpo_ctx_t * dpo_ctx, +hicn_strategy_dpo_ctx_add_nh (hicn_face_id_t nh, hicn_dpo_ctx_t * dpo_ctx, u8 * pos) { @@ -106,12 +106,12 @@ hicn_strategy_dpo_ctx_add_nh (const dpo_id_t * nh, hicn_dpo_ctx_t * dpo_ctx, /* 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 (nh == dpo_ctx->next_hops[i]) { /* 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) + hicn_dpoi_get_from_idx (dpo_ctx->next_hops[i]); + if (face->flags & HICN_FACE_FLAGS_DELETED) { continue; } @@ -125,7 +125,8 @@ hicn_strategy_dpo_ctx_add_nh (const dpo_id_t * nh, hicn_dpo_ctx_t * dpo_ctx, return HICN_ERROR_DPO_CTX_NHOPS_NS; } - clib_memcpy (&dpo_ctx->next_hops[empty], nh, sizeof (dpo_id_t)); + dpo_ctx->next_hops[empty] = nh; + hicn_face_lock_with_id (nh); dpo_ctx->entry_count++; *pos = empty; @@ -137,13 +138,13 @@ 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; + hicn_face_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) + if (dpo_ctx->next_hops[i] == face_id) { - hicn_face_unlock (&dpo_ctx->next_hops[i]); + hicn_face_unlock_with_id (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; diff --git a/hicn-plugin/src/strategy_dpo_ctx.h b/hicn-plugin/src/strategy_dpo_ctx.h index 737071766..2a534c4dc 100644 --- a/hicn-plugin/src/strategy_dpo_ctx.h +++ b/hicn-plugin/src/strategy_dpo_ctx.h @@ -25,7 +25,7 @@ //FIB table for hicn. 0 is the default one used by ip #define HICN_FIB_TABLE 0 -#define NEXT_HOP_INVALID DPO_INVALID +#define NEXT_HOP_INVALID ~0 #define INIT_SEQ 0 @@ -41,8 +41,8 @@ typedef struct __attribute__ ((packed)) hicn_dpo_ctx_s { CLIB_CACHE_LINE_ALIGN_MARK (cacheline0); - /* 8B*5 = 40B */ - dpo_id_t next_hops[HICN_PARAM_FIB_ENTRY_NHOPS_MAX]; + /* 4B*10 = 40B */ + hicn_face_id_t next_hops[HICN_PARAM_FIB_ENTRY_NHOPS_MAX]; /* 40B + 4B = 44B */ u32 locks; /* 44B + 1B = 45B */ @@ -55,7 +55,7 @@ typedef struct __attribute__ ((packed)) hicn_dpo_ctx_s u16 padding; /* To align to 8B */ /* 48 + 4B = 52; last sequence number */ - seq_t seq; + u32 seq; /* 48 + 1B = 53; last sequence number */ dpo_type_t dpo_type; @@ -76,10 +76,10 @@ extern hicn_dpo_ctx_t *hicn_strategy_dpo_ctx_pool; * @param dpo_type Type of dpo. It identifies the strategy. */ always_inline void -init_dpo_ctx (hicn_dpo_ctx_t * dpo_ctx, const dpo_id_t * next_hop, +init_dpo_ctx (hicn_dpo_ctx_t * dpo_ctx, const hicn_face_id_t * next_hop, int nh_len, dpo_type_t dpo_type) { - dpo_id_t invalid = NEXT_HOP_INVALID; + hicn_face_id_t invalid = NEXT_HOP_INVALID; dpo_ctx->entry_count = 0; dpo_ctx->locks = 0; @@ -91,7 +91,7 @@ init_dpo_ctx (hicn_dpo_ctx_t * dpo_ctx, const dpo_id_t * next_hop, 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->next_hops[i] = next_hop[i]; dpo_ctx->entry_count++; } @@ -151,7 +151,7 @@ void hicn_strategy_dpo_ctx_unlock (dpo_id_t * dpo); * 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, +hicn_strategy_dpo_ctx_add_nh (hicn_face_id_t nh, hicn_dpo_ctx_t * dpo_ctx, u8 * pos); /** diff --git a/hicn-plugin/src/strategy_dpo_manager.h b/hicn-plugin/src/strategy_dpo_manager.h index 63fcb930b..8c274d06d 100644 --- a/hicn-plugin/src/strategy_dpo_manager.h +++ b/hicn-plugin/src/strategy_dpo_manager.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: @@ -35,8 +35,8 @@ typedef struct hicn_dpo_vft_s 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 */ - 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 */ + void (*hicn_dpo_create) (dpo_proto_t proto, const hicn_face_id_t * nh, int nh_len, index_t * dpo_idx); /**< Create the context of the hICN dpo */ + int (*hicn_dpo_add_update_nh) (hicn_face_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); u8 *(*hicn_dpo_format) (u8 * s, int, ...); /**< Format an hICN dpo*/ diff --git a/hicn-plugin/src/strategy_node.c b/hicn-plugin/src/strategy_node.c index 27d1e2a03..578ba2c4f 100644 --- a/hicn-plugin/src/strategy_node.c +++ b/hicn-plugin/src/strategy_node.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: @@ -64,7 +64,7 @@ hicn_strategy_format_trace (u8 * s, va_list * args) 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, + u16 namelen, hicn_face_id_t outface, int nh_idx, 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) @@ -123,14 +123,12 @@ hicn_new_interest (hicn_strategy_runtime_t * rt, vlib_buffer_t * b0, hash_entry); /* Add face */ - hicn_face_db_add_face_dpo (&hicnb0->face_dpo_id, &(pitp->u.pit.faces)); + hicn_face_db_add_face (hicnb0->face_id, &(pitp->u.pit.faces)); - /* Remove lock on the dpo stored in the vlib_buffer */ - //dpo_unlock (&hicnb0->face_dpo_id); + *next = isv6 ? HICN_STRATEGY_NEXT_INTEREST_FACE6 : + HICN_STRATEGY_NEXT_INTEREST_FACE4; - *next = outface->dpoi_next_node; - - vnet_buffer (b0)->ip.adj_index[VLIB_TX] = outface->dpoi_index; + vnet_buffer (b0)->ip.adj_index[VLIB_TX] = outface; stats->pkts_interest_count++; } else @@ -197,7 +195,7 @@ hicn_strategy_fn (vlib_main_t * vm, hicn_header_t *hicn0; vlib_buffer_t *b0; u32 bi0; - dpo_id_t *outface = NULL; + hicn_face_id_t outface; int nh_idx; u32 next0 = next_index; int ret; @@ -310,6 +308,8 @@ VLIB_REGISTER_NODE (hicn_strategy_node) = { [HICN_STRATEGY_NEXT_INTEREST_HITPIT] = "hicn-interest-hitpit", [HICN_STRATEGY_NEXT_INTEREST_HITCS] = "hicn-interest-hitcs", + [HICN_STRATEGY_NEXT_INTEREST_FACE4] = "hicn4-face-output", + [HICN_STRATEGY_NEXT_INTEREST_FACE6] = "hicn6-face-output", [HICN_STRATEGY_NEXT_ERROR_DROP] = "error-drop", }, }; |