diff options
author | 2019-11-18 10:51:08 +0000 | |
---|---|---|
committer | 2019-11-18 10:51:08 +0000 | |
commit | f1590834352d863d238d38c5a58d5a31ab042e3f (patch) | |
tree | 23dd849a19f44300004f5d4a6f68d728faadaf19 /hicn-plugin/src/hicn_api_test.c | |
parent | 7a8ed38fac8f0c42e214e3f648be855609afcc43 (diff) | |
parent | fb81ea88640de69820f2b2d24e29e5743e4f301b (diff) |
Merge "[HICN-225] Added generic binary api for handling faces"
Diffstat (limited to 'hicn-plugin/src/hicn_api_test.c')
-rw-r--r-- | hicn-plugin/src/hicn_api_test.c | 510 |
1 files changed, 411 insertions, 99 deletions
diff --git a/hicn-plugin/src/hicn_api_test.c b/hicn-plugin/src/hicn_api_test.c index c29aa4a21..fa0e075f8 100644 --- a/hicn-plugin/src/hicn_api_test.c +++ b/hicn-plugin/src/hicn_api_test.c @@ -84,69 +84,94 @@ unformat_ip46_address (unformat_input_t * input, va_list * args) return 0; } -/* static ip46_type_t */ -/* ip_address_union_decode (const vl_api_address_union_t *in, */ -/* vl_api_address_family_t af, */ -/* ip46_address_t *out) */ -/* { */ -/* ip46_type_t type; */ - -/* switch (clib_net_to_host_u32 (af)) */ -/* { */ -/* case ADDRESS_IP4: */ -/* clib_memset (out, 0, sizeof (*out)); */ -/* clib_memcpy (&out->ip4, &in->ip4, sizeof (out->ip4)); */ -/* type = IP46_TYPE_IP4; */ -/* break; */ -/* case ADDRESS_IP6: */ -/* clib_memcpy (&out->ip6, &in->ip6, sizeof (out->ip6)); */ -/* type = IP46_TYPE_IP6; */ -/* break; */ -/* default: */ -/* ASSERT (!"Unkown address family in API address type"); */ -/* type = IP46_TYPE_ANY; */ -/* break; */ -/* } */ - -/* return type; */ -/* } */ - -/* static void */ -/* ip_address_union_encode (const ip46_address_t * in, */ -/* vl_api_address_family_t af, */ -/* vl_api_address_union_t * out) */ -/* { */ -/* if (ADDRESS_IP6 == clib_net_to_host_u32 (af)) */ -/* memcpy (out->ip6.address, &in->ip6, sizeof (out->ip6)); */ -/* else */ -/* memcpy (out->ip4.address, &in->ip4, sizeof (out->ip4)); */ -/* } */ - -/* ip46_type_t ip_address_decode (const vl_api_address_t *in, ip46_address_t *out) */ -/* { */ -/* return (ip_address_union_decode (&in->un, in->af, out)); */ -/* } */ - -/* void ip_address_encode (const ip46_address_t *in, ip46_type_t type, */ -/* vl_api_address_t *out) */ -/* { */ -/* switch (type) */ -/* { */ -/* case IP46_TYPE_IP4: */ -/* out->af = clib_net_to_host_u32 (ADDRESS_IP4); */ -/* break; */ -/* case IP46_TYPE_IP6: */ -/* out->af = clib_net_to_host_u32 (ADDRESS_IP6); */ -/* break; */ -/* case IP46_TYPE_ANY: */ -/* if (ip46_address_is_ip4 (in)) */ -/* out->af = clib_net_to_host_u32 (ADDRESS_IP4); */ -/* else */ -/* out->af = clib_net_to_host_u32 (ADDRESS_IP6); */ -/* break; */ -/* } */ -/* ip_address_union_encode (in, out->af, &out->un); */ -/* } */ +static ip46_type_t +ip_address_union_decode (const vl_api_address_union_t * in, + vl_api_address_family_t af, ip46_address_t * out) +{ + ip46_type_t type; + + switch (clib_net_to_host_u32 (af)) + { + case ADDRESS_IP4: + clib_memset (out, 0, sizeof (*out)); + clib_memcpy (&out->ip4, &in->ip4, sizeof (out->ip4)); + type = IP46_TYPE_IP4; + break; + case ADDRESS_IP6: + clib_memcpy (&out->ip6, &in->ip6, sizeof (out->ip6)); + type = IP46_TYPE_IP6; + break; + default: + ASSERT (!"Unkown address family in API address type"); + type = IP46_TYPE_ANY; + break; + } + + return type; +} + +void +ip6_address_encode (const ip6_address_t * in, vl_api_ip6_address_t out) +{ + clib_memcpy (out, in, sizeof (*in)); +} + +void +ip6_address_decode (const vl_api_ip6_address_t in, ip6_address_t * out) +{ + clib_memcpy (out, in, sizeof (*out)); +} + +void +ip4_address_encode (const ip4_address_t * in, vl_api_ip4_address_t out) +{ + clib_memcpy (out, in, sizeof (*in)); +} + +void +ip4_address_decode (const vl_api_ip4_address_t in, ip4_address_t * out) +{ + clib_memcpy (out, in, sizeof (*out)); +} + +static void +ip_address_union_encode (const ip46_address_t * in, + vl_api_address_family_t af, + vl_api_address_union_t * out) +{ + if (ADDRESS_IP6 == clib_net_to_host_u32 (af)) + ip6_address_encode (&in->ip6, out->ip6); + else + ip4_address_encode (&in->ip4, out->ip4); +} + +ip46_type_t +ip_address_decode (const vl_api_address_t * in, ip46_address_t * out) +{ + return (ip_address_union_decode (&in->un, in->af, out)); +} + +void +ip_address_encode (const ip46_address_t * in, ip46_type_t type, + vl_api_address_t * out) +{ + switch (type) + { + case IP46_TYPE_IP4: + out->af = clib_net_to_host_u32 (ADDRESS_IP4); + break; + case IP46_TYPE_IP6: + out->af = clib_net_to_host_u32 (ADDRESS_IP6); + break; + case IP46_TYPE_ANY: + if (ip46_address_is_ip4 (in)) + out->af = clib_net_to_host_u32 (ADDRESS_IP4); + else + out->af = clib_net_to_host_u32 (ADDRESS_IP6); + break; + } + ip_address_union_encode (in, out->af, &out->un); +} ///////////////////////////////////////////////////// @@ -165,6 +190,7 @@ 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) @@ -196,6 +222,10 @@ _(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) \ @@ -393,22 +423,18 @@ api_hicn_api_face_ip_add (vat_main_t * vam) ip46_address_t remote_addr = { 0 }; int ret = HICN_ERROR_NONE; int sw_if = 0; - vl_api_hicn_api_face_ip_add_t *mp; + 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_ip4_address, &local_addr.ip4)); - else - if (unformat - (input, "local %U", unformat_ip6_address, &local_addr.ip6)); - else - if (unformat - (input, "remote %U", unformat_ip4_address, &remote_addr.ip4)); + (input, "local %U", unformat_ip46_address, &local_addr, + IP46_TYPE_ANY)); else if (unformat - (input, "remote %U", unformat_ip6_address, &remote_addr.ip6)); + (input, "remote %U", unformat_ip46_address, &remote_addr, + IP46_TYPE_ANY)); else if (unformat (input, "intfc %d", &sw_if)); else { @@ -423,10 +449,11 @@ api_hicn_api_face_ip_add (vat_main_t * vam) return (1); } /* Construct the API message */ - M (HICN_API_FACE_IP_ADD, mp); - ip_address_decode (&mp->local_addr, &local_addr); - ip_address_decode (&mp->remote_addr, &remote_addr); - mp->swif = clib_host_to_net_u32 (sw_if); + M (HICN_API_FACE_ADD, mp); + mp->type = 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); @@ -462,6 +489,85 @@ static void } 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 = 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 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; @@ -499,11 +605,48 @@ api_hicn_api_face_ip_del (vat_main_t * vam) } 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; - u32 faceid = 0, ret; + u32 faceid = HICN_FACE_NULL, ret; while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { @@ -517,7 +660,7 @@ api_hicn_api_face_ip_params_get (vat_main_t * vam) } //Check for presence of face ID - if (faceid == 0) + if (faceid == HICN_FACE_NULL) { clib_warning ("Please specify face ID"); return 1; @@ -560,8 +703,8 @@ 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->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, @@ -569,11 +712,173 @@ static void fformat (vam->ofp, "%s swif %d flags %d\n", sbuf, - clib_net_to_host_u16 (rmp->swif), + clib_net_to_host_u32 (rmp->swif), clib_net_to_host_i32 (rmp->flags)); } -/* memif-dump API */ +static void format_ip_face (vl_api_hicn_face_ip_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); + 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 */ ); + + 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); + + fformat (vam->ofp, "%s swif %d flags %d name %s\n", + sbuf, + clib_net_to_host_u16 (rmp->swif), + clib_net_to_host_i32 (rmp->flags), rmp->if_name); +} + +static int +api_hicn_api_faces_dump (vat_main_t * vam) +{ + hicn_test_main_t *hm = &hicn_test_main; + vl_api_hicn_api_faces_dump_t *mp; + vl_api_control_ping_t *mp_ping; + int ret; + + if (vam->json_output) + { + clib_warning ("JSON output not supported for faces_dump"); + return -99; + } + + M (HICN_API_FACES_DUMP, mp); + S (mp); + + /* Use a control ping for synchronization */ + mp_ping = vl_msg_api_alloc_as_if_client (sizeof (*mp_ping)); + mp_ping->_vl_msg_id = htons (hm->ping_id); + mp_ping->client_index = vam->my_client_index; + + fformat (vam->ofp, "Sending ping id=%d\n", hm->ping_id); + + vam->result_ready = 0; + S (mp_ping); + + W (ret); + return ret; +} + +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)); + } +} + +static int +api_hicn_api_face_get (vat_main_t * vam) +{ + unformat_input_t *input = vam->input; + vl_api_hicn_api_face_get_t *mp; + u32 faceid = HICN_FACE_NULL, 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 == HICN_FACE_NULL) + { + clib_warning ("Please specify face ID"); + return 1; + } + //Construct the API message + M (HICN_API_FACE_GET, mp); + mp->faceid = clib_host_to_net_u32 (faceid); + + //send it... + S (mp); + + //Wait for a reply... + W (ret); + + return ret; +} + + +static void + vl_api_hicn_api_face_get_reply_t_handler + (vl_api_hicn_api_face_get_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; + } + + if (rmp->type == IP_FACE) + { + format_ip_face (&(rmp->face.ip)); + } + else + { + format_udp_face (&(rmp->face.udp)); + } +} + + + static int api_hicn_api_face_stats_dump (vat_main_t * vam) { @@ -632,7 +937,6 @@ static void clib_host_to_net_u64 (mp->dtx_bytes)); } - static int api_hicn_api_route_get (vat_main_t * vam) { @@ -655,14 +959,15 @@ api_hicn_api_route_get (vat_main_t * vam) } /* Check parse */ - if (((prefix.fp_addr.as_u64[0] == 0) && (prefix.fp_addr.as_u64[1] == 0)) || (prefix.fp_len == 0)) + if (((prefix.fp_addr.as_u64[0] == 0) && (prefix.fp_addr.as_u64[1] == 0)) + || (prefix.fp_len == 0)) { clib_warning ("Please specify a valid prefix..."); return 1; } //Construct the API message M (HICN_API_ROUTE_GET, mp); - ip_prefix_encode(&prefix, &mp->prefix); + ip_prefix_encode (&prefix, &mp->prefix); //send it... S (mp); @@ -764,7 +1069,7 @@ static void u8 *sbuf = 0; vec_reset_length (sbuf); - ip_prefix_decode(&mp->prefix, &prefix); + ip_prefix_decode (&mp->prefix, &prefix); sbuf = format (sbuf, "Prefix: %U/%u\n", format_ip46_address, &prefix.fp_addr, 0, prefix.fp_len); @@ -807,15 +1112,15 @@ api_hicn_api_route_nhops_add (vat_main_t * vam) } /* Check parse */ - if (((prefix.fp_addr.as_u64[0] == 0) && (prefix.fp_addr.as_u64[1] == 0)) || (prefix.fp_len == 0) - || (faceid == 0)) + if (((prefix.fp_addr.as_u64[0] == 0) && (prefix.fp_addr.as_u64[1] == 0)) + || (prefix.fp_len == 0) || (faceid == 0)) { clib_warning ("Please specify prefix and faceid..."); return 1; } /* Construct the API message */ M (HICN_API_ROUTE_NHOPS_ADD, mp); - ip_prefix_encode(&prefix, &mp->prefix); + ip_prefix_encode (&prefix, &mp->prefix); mp->face_ids[0] = clib_host_to_net_u32 (faceid); mp->n_faces = 1; @@ -851,14 +1156,15 @@ api_hicn_api_route_del (vat_main_t * vam) } /* Check parse */ - if (((prefix.fp_addr.as_u64[0] == 0) && (prefix.fp_addr.as_u64[1] == 0)) || (prefix.fp_len == 0)) + if (((prefix.fp_addr.as_u64[0] == 0) && (prefix.fp_addr.as_u64[1] == 0)) + || (prefix.fp_len == 0)) { clib_warning ("Please specify prefix..."); return 1; } /* Construct the API message */ M (HICN_API_ROUTE_DEL, mp); - ip_prefix_encode(&prefix, &mp->prefix); + ip_prefix_encode (&prefix, &mp->prefix); /* send it... */ S (mp); @@ -895,15 +1201,15 @@ api_hicn_api_route_nhop_del (vat_main_t * vam) } /* Check parse */ - if (((prefix.fp_addr.as_u64[0] == 0) && (prefix.fp_addr.as_u64[1] == 0)) || (prefix.fp_len == 0) - || (faceid == HICN_FACE_NULL)) + if (((prefix.fp_addr.as_u64[0] == 0) && (prefix.fp_addr.as_u64[1] == 0)) + || (prefix.fp_len == 0) || (faceid == HICN_FACE_NULL)) { clib_warning ("Please specify prefix and faceid..."); return 1; } /* Construct the API message */ M (HICN_API_ROUTE_NHOP_DEL, mp); - ip_prefix_encode(&prefix, &mp->prefix); + ip_prefix_encode (&prefix, &mp->prefix); mp->faceid = clib_host_to_net_u32 (faceid); @@ -1059,14 +1365,15 @@ api_hicn_api_register_prod_app (vat_main_t * vam) } /* Check parse */ - if (((prefix.fp_addr.as_u64[0] == 0) && (prefix.fp_addr.as_u64[1] == 0)) || (prefix.fp_len == 0)) + if (((prefix.fp_addr.as_u64[0] == 0) && (prefix.fp_addr.as_u64[1] == 0)) + || (prefix.fp_len == 0)) { clib_warning ("Please specify prefix..."); return 1; } /* Construct the API message */ M (HICN_API_REGISTER_PROD_APP, mp); - ip_prefix_encode(&prefix, &mp->prefix); + ip_prefix_encode (&prefix, &mp->prefix); mp->swif = clib_host_to_net_u32 (swif); @@ -1143,14 +1450,15 @@ static void } ip46_address_t src_addr4 = ip46_address_initializer; ip46_address_t src_addr6 = ip46_address_initializer; - ip_address_decode(&mp->src_addr4, &src_addr4); - ip_address_decode(&mp->src_addr6, &src_addr6); + ip_address_decode (&mp->src_addr4, &src_addr4); + ip_address_decode (&mp->src_addr6, &src_addr6); fformat (vam->ofp, "ip4 address %U\n" "ip6 address :%U\n" "appif id :%d\n", - format_ip46_address, IP46_TYPE_ANY, &src_addr4, format_ip46_address, IP46_TYPE_ANY, &src_addr6); + format_ip46_address, IP46_TYPE_ANY, &src_addr4, + format_ip46_address, IP46_TYPE_ANY, &src_addr6); } /* @@ -1164,6 +1472,10 @@ _(hicn_api_node_params_get, "") \ _(hicn_api_node_stats_get, "") \ _(hicn_api_face_ip_del, "face <faceID>") \ _(hicn_api_face_ip_add, "local <address> remote <address> intfc <swif>")\ +_(hicn_api_face_udp_add, "local <address> port <port> remote <address> port <port> intfc <swif>") \ +_(hicn_api_face_del, "face <faceID>") \ +_(hicn_api_faces_dump, "") \ +_(hicn_api_face_get, "face <faceID>") \ _(hicn_api_face_stats_dump, "") \ _(hicn_api_route_nhops_add, "add prefix <IP4/IP6>/<subnet> face <faceID> weight <weight>") \ _(hicn_api_face_ip_params_get, "face <faceID>") \ |