LISP: add API handlers for set/get transport protocol

Change-Id: Ib675164c475edcdbe3013df7b847adf5e050c53f
Signed-off-by: Filip Tehlar <ftehlar@cisco.com>
diff --git a/src/vnet/lisp-cp/control.c b/src/vnet/lisp-cp/control.c
index 42b5b8b..0d6d453 100644
--- a/src/vnet/lisp-cp/control.c
+++ b/src/vnet/lisp-cp/control.c
@@ -4351,6 +4351,7 @@
   lcm->map_register_ttl = MAP_REGISTER_DEFAULT_TTL;
   lcm->max_expired_map_registers = MAX_EXPIRED_MAP_REGISTERS_DEFAULT;
   lcm->expired_map_registers = 0;
+  lcm->transport_protocol = LISP_TRANSPORT_PROTOCOL_UDP;
   return 0;
 }
 
@@ -4720,6 +4721,26 @@
 };
 /* *INDENT-ON* */
 
+u32
+vnet_lisp_set_transport_protocol (u8 protocol)
+{
+  lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
+
+  if (protocol < LISP_TRANSPORT_PROTOCOL_UDP ||
+      protocol > LISP_TRANSPORT_PROTOCOL_API)
+    return VNET_API_ERROR_INVALID_ARGUMENT;
+
+  lcm->transport_protocol = protocol;
+  return 0;
+}
+
+lisp_transport_protocol_t
+vnet_lisp_get_transport_protocol (void)
+{
+  lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
+  return lcm->transport_protocol;
+}
+
 VLIB_INIT_FUNCTION (lisp_cp_init);
 
 /*
diff --git a/src/vnet/lisp-cp/control.h b/src/vnet/lisp-cp/control.h
index 0df18f4..a6da818 100644
--- a/src/vnet/lisp-cp/control.h
+++ b/src/vnet/lisp-cp/control.h
@@ -140,6 +140,12 @@
   u32 bd;
 } lisp_l2_arp_key_t;
 
+typedef enum
+{
+  LISP_TRANSPORT_PROTOCOL_UDP = 1,
+  LISP_TRANSPORT_PROTOCOL_API
+} lisp_transport_protocol_t;
+
 typedef struct
 {
   u64 nonce;
@@ -271,6 +277,9 @@
   u32 max_expired_map_registers;
   u32 expired_map_registers;
 
+  /** either UDP based or binary API. Default is UDP */
+  lisp_transport_protocol_t transport_protocol;
+
   /* commodity */
   ip4_main_t *im4;
   ip6_main_t *im6;
@@ -404,6 +413,8 @@
 u32 vnet_lisp_map_register_fallback_threshold_get (void);
 u32 *vnet_lisp_ndp_bds_get (void);
 lisp_api_ndp_entry_t *vnet_lisp_ndp_entries_get_by_bd (u32 bd);
+u32 vnet_lisp_set_transport_protocol (u8 protocol);
+lisp_transport_protocol_t vnet_lisp_get_transport_protocol (void);
 
 map_records_arg_t *parse_map_reply (vlib_buffer_t * b);
 
diff --git a/src/vnet/lisp-cp/one_api.c b/src/vnet/lisp-cp/one_api.c
index ae52381..e3a2afe 100644
--- a/src/vnet/lisp-cp/one_api.c
+++ b/src/vnet/lisp-cp/one_api.c
@@ -133,6 +133,8 @@
 _(ONE_ADD_DEL_NDP_ENTRY, one_add_del_ndp_entry)                         \
 _(ONE_NDP_BD_GET, one_ndp_bd_get)                                       \
 _(ONE_NDP_ENTRIES_GET, one_ndp_entries_get)                             \
+_(ONE_SET_TRANSPORT_PROTOCOL, one_set_transport_protocol)               \
+_(ONE_GET_TRANSPORT_PROTOCOL, one_get_transport_protocol)
 
 static locator_t *
 unformat_one_locs (vl_api_one_remote_locator_t * rmt_locs, u32 rloc_num)
@@ -1698,6 +1700,34 @@
 }
 
 static void
+  vl_api_one_set_transport_protocol_t_handler
+  (vl_api_one_set_transport_protocol_t * mp)
+{
+  vl_api_one_set_transport_protocol_reply_t *rmp;
+  int rv = 0;
+
+  rv = vnet_lisp_set_transport_protocol (mp->protocol);
+
+  REPLY_MACRO (VL_API_ONE_SET_TRANSPORT_PROTOCOL_REPLY);
+}
+
+static void
+  vl_api_one_get_transport_protocol_t_handler
+  (vl_api_one_get_transport_protocol_t * mp)
+{
+  vl_api_one_get_transport_protocol_reply_t *rmp;
+  int rv = 0;
+  u8 proto = (u8) vnet_lisp_get_transport_protocol ();
+
+  /* *INDENT-OFF* */
+  REPLY_MACRO2 (VL_API_ONE_GET_TRANSPORT_PROTOCOL_REPLY,
+  ({
+    rmp->protocol = proto;
+  }));
+  /* *INDENT-ON* */
+}
+
+static void
 vl_api_one_ndp_entries_get_t_handler (vl_api_one_ndp_entries_get_t * mp)
 {
   vl_api_one_ndp_entries_get_reply_t *rmp = 0;