summaryrefslogtreecommitdiffstats
path: root/hicn-plugin/src/hicn_api_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'hicn-plugin/src/hicn_api_test.c')
-rw-r--r--hicn-plugin/src/hicn_api_test.c212
1 files changed, 211 insertions, 1 deletions
diff --git a/hicn-plugin/src/hicn_api_test.c b/hicn-plugin/src/hicn_api_test.c
index fa0e075f8..1dc8158d4 100644
--- a/hicn-plugin/src/hicn_api_test.c
+++ b/hicn-plugin/src/hicn_api_test.c
@@ -173,6 +173,65 @@ ip_address_encode (const ip46_address_t * in, ip46_type_t type,
ip_address_union_encode (in, out->af, &out->un);
}
+fib_protocol_t
+fib_proto_from_ip46 (ip46_type_t iproto)
+{
+ switch (iproto)
+ {
+ case IP46_TYPE_IP4:
+ return FIB_PROTOCOL_IP4;
+ case IP46_TYPE_IP6:
+ return FIB_PROTOCOL_IP6;
+ case IP46_TYPE_ANY:
+ ASSERT(0);
+ return FIB_PROTOCOL_IP4;
+ }
+
+ ASSERT(0);
+ return FIB_PROTOCOL_IP4;
+}
+
+ip46_type_t
+fib_proto_to_ip46 (fib_protocol_t fproto)
+{
+ switch (fproto)
+ {
+ case FIB_PROTOCOL_IP4:
+ return (IP46_TYPE_IP4);
+ case FIB_PROTOCOL_IP6:
+ return (IP46_TYPE_IP6);
+ case FIB_PROTOCOL_MPLS:
+ return (IP46_TYPE_ANY);
+ }
+ ASSERT(0);
+ return (IP46_TYPE_ANY);
+}
+
+void
+ip_prefix_decode (const vl_api_prefix_t * in, fib_prefix_t * out)
+{
+ switch (clib_net_to_host_u32 (in->address.af))
+ {
+ case ADDRESS_IP4:
+ out->fp_proto = FIB_PROTOCOL_IP4;
+ break;
+ case ADDRESS_IP6:
+ out->fp_proto = FIB_PROTOCOL_IP6;
+ break;
+ }
+ out->fp_len = in->len;
+ out->___fp___pad = 0;
+ ip_address_decode (&in->address, &out->fp_addr);
+}
+
+void
+ip_prefix_encode (const fib_prefix_t * in, vl_api_prefix_t * out)
+{
+ out->len = in->fp_len;
+ ip_address_encode (&in->fp_addr,
+ fib_proto_to_ip46 (in->fp_proto), &out->address);
+}
+
/////////////////////////////////////////////////////
#define HICN_FACE_NULL ~0
@@ -193,7 +252,8 @@ _(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)
+_(hicn_api_route_nhop_del_reply) \
+_(hicn_api_punting_add_reply)
#define _(n) \
static void vl_api_##n##_t_handler \
@@ -235,6 +295,7 @@ _(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_PUNTING_ADD_REPLY, hicn_api_punting_add_reply) \
_(HICN_API_REGISTER_PROD_APP_REPLY, hicn_api_register_prod_app_reply) \
_(HICN_API_REGISTER_CONS_APP_REPLY, hicn_api_register_cons_app_reply)
@@ -967,6 +1028,8 @@ api_hicn_api_route_get (vat_main_t * vam)
}
//Construct the API message
M (HICN_API_ROUTE_GET, mp);
+ if (!ip46_address_is_ip4(&(prefix.fp_addr)))
+ prefix.fp_proto = fib_proto_from_ip46(IP46_TYPE_IP6);
ip_prefix_encode (&prefix, &mp->prefix);
//send it...
@@ -1122,6 +1185,9 @@ api_hicn_api_route_nhops_add (vat_main_t * vam)
M (HICN_API_ROUTE_NHOPS_ADD, mp);
ip_prefix_encode (&prefix, &mp->prefix);
+ if (!ip46_address_is_ip4(&(prefix.fp_addr)))
+ prefix.fp_proto = fib_proto_from_ip46(IP46_TYPE_IP6);
+
mp->face_ids[0] = clib_host_to_net_u32 (faceid);
mp->n_faces = 1;
@@ -1166,6 +1232,9 @@ api_hicn_api_route_del (vat_main_t * vam)
M (HICN_API_ROUTE_DEL, mp);
ip_prefix_encode (&prefix, &mp->prefix);
+ if (!ip46_address_is_ip4(&(prefix.fp_addr)))
+ prefix.fp_proto = fib_proto_from_ip46(IP46_TYPE_IP6);
+
/* send it... */
S (mp);
@@ -1211,6 +1280,9 @@ api_hicn_api_route_nhop_del (vat_main_t * vam)
M (HICN_API_ROUTE_NHOP_DEL, mp);
ip_prefix_encode (&prefix, &mp->prefix);
+ if (!ip46_address_is_ip4(&(prefix.fp_addr)))
+ prefix.fp_proto = fib_proto_from_ip46(IP46_TYPE_IP6);
+
mp->faceid = clib_host_to_net_u32 (faceid);
/* send it... */
@@ -1339,6 +1411,142 @@ static void
}
fformat (vam->ofp, "%s", mp->description);
}
+static int
+api_hicn_api_ip_punting_add(vat_main_t * vam)
+{
+ unformat_input_t *input = vam->input;
+ vl_api_hicn_api_punting_add_t *mp;
+ fib_prefix_t prefix;
+ u32 swif = ~0;
+ int ret;
+
+ while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (input, "prefix %U/%d", unformat_ip46_address,
+ &prefix.fp_addr, IP46_TYPE_ANY, &prefix.fp_len))
+ {;
+ }
+ else if (unformat (input, "intfc %d", &swif))
+ {;
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ /* Check parse */
+ 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;
+ }
+
+ if (swif == ~0)
+ {
+ clib_warning ("Please specify interface...");
+ return 1;
+ }
+ /* Construct the API message */
+ M (HICN_API_PUNTING_ADD, mp);
+ mp->type = IP_PUNT;
+ if (!ip46_address_is_ip4(&(prefix.fp_addr)))
+ {
+ prefix.fp_proto = fib_proto_from_ip46(IP46_TYPE_IP6);
+ }
+ ip_prefix_encode (&prefix, &mp->rule.ip.prefix);
+
+ mp->rule.ip.swif = clib_host_to_net_u32 (swif);
+
+ /* send it... */
+ S (mp);
+
+ /* Wait for a reply... */
+ W (ret);
+
+ return ret;
+}
+
+static int
+api_hicn_api_udp_punting_add(vat_main_t * vam)
+{
+ unformat_input_t *input = vam->input;
+ vl_api_hicn_api_punting_add_t *mp;
+ fib_prefix_t prefix;
+ u32 swif = ~0;
+ u16 sport = 0;
+ u16 dport = 0;
+ vl_api_address_family_t ip_version = ~0;
+ int ret;
+
+ while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (input, "prefix %U/%d", unformat_ip46_address,
+ &prefix.fp_addr, IP46_TYPE_ANY, &prefix.fp_len))
+ {;
+ }
+ else if (unformat (input, "sport %u", &sport));
+ else if (unformat (input, "dport %u", &dport));
+ else if (unformat (input, "ip4"))
+ {
+ ip_version = ADDRESS_IP4;
+ }
+ else if (unformat (input, "ip6"))
+ {
+ ip_version = ADDRESS_IP6;
+ }
+ else if (unformat (input, "intfc %d", &swif))
+ {;
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ /* Check parse */
+ 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;
+ }
+
+ if (swif == ~0)
+ {
+ clib_warning ("Please specify interface...");
+ return 1;
+ }
+ if (ip_version == ~0)
+ {
+ clib_warning ("Please specify ip version of the udp tunnel...");
+ return 1;
+ }
+ /* Construct the API message */
+ M (HICN_API_PUNTING_ADD, mp);
+ mp->type = UDP_PUNT;
+ if (!ip46_address_is_ip4(&(prefix.fp_addr)))
+ {
+ prefix.fp_proto = fib_proto_from_ip46(IP46_TYPE_IP6);
+ }
+ ip_prefix_encode (&prefix, &mp->rule.ip.prefix);
+
+ mp->rule.udp.ip_version = ip_version;
+
+ mp->rule.udp.swif = clib_host_to_net_u32 (swif);
+ mp->rule.udp.sport = clib_host_to_net_u16 (sport);
+ mp->rule.udp.sport = clib_host_to_net_u16 (dport);
+
+ /* send it... */
+ S (mp);
+
+ /* Wait for a reply... */
+ W (ret);
+
+ return ret;
+}
+
static int
api_hicn_api_register_prod_app (vat_main_t * vam)
@@ -1485,6 +1693,8 @@ _(hicn_api_route_del, "prefix <IP4/IP6>/<subnet>") \
_(hicn_api_route_nhop_del, "del prefix <IP4/IP6>/<subnet> face <faceID>") \
_(hicn_api_strategies_get, "") \
_(hicn_api_strategy_get, "strategy <id>") \
+_(hicn_api_ip_punting_add, "prefix <IP4/IP6>/<subnet> intfc <swif>") \
+_(hicn_api_udp_punting_add, "prefix <IP4/IP6>/<subnet> intfc <swif> sport <port> dport <port> ip4/ip6") \
_(hicn_api_register_prod_app, "prefix <IP4/IP6>/<subnet> id <appif_id>") \
_(hicn_api_register_cons_app, "")