Add L3DSR feature in LB plugin
[vpp.git] / src / plugins / lb / api.c
index 06c53fa..28af6da 100644 (file)
@@ -19,7 +19,7 @@
 #include <vlibapi/api.h>
 #include <vlibapi/api.h>
 #include <vlibmemory/api.h>
-#include <vlibsocket/api.h>
+
 
 #define vl_msg_id(n,h) n,
 typedef enum {
@@ -51,6 +51,10 @@ typedef enum {
 #include <lb/lb.api.h>
 #undef vl_msg_name_crc_list
 
+
+#define REPLY_MSG_ID_BASE lbm->msg_id_base
+#include <vlibapi/api_helper_macros.h>
+
 static void
 setup_message_id_table (lb_main_t * lbm, api_main_t * am)
 {
@@ -67,29 +71,6 @@ setup_message_id_table (lb_main_t * lbm, api_main_t * am)
     vec_free (s);                               \
     return handle;
 
-/*
- * A handy macro to set up a message reply.
- * Assumes that the following variables are available:
- * mp - pointer to request message
- * rmp - pointer to reply message type
- * rv - return value
- */
-
-#define REPLY_MACRO(t)                                          \
-do {                                                            \
-    unix_shared_memory_queue_t * q =                            \
-    vl_api_client_index_to_input_queue (mp->client_index);      \
-    if (!q)                                                     \
-        return;                                                 \
-                                                                \
-    rmp = vl_msg_api_alloc (sizeof (*rmp));                     \
-    rmp->_vl_msg_id = ntohs((t)+lbm->msg_id_base);               \
-    rmp->context = mp->context;                                 \
-    rmp->retval = ntohl(rv);                                    \
-                                                                \
-    vl_msg_api_send_shmem (q, (u8 *)&rmp);                      \
-} while(0);
-
 static void
 vl_api_lb_conf_t_handler
 (vl_api_lb_conf_t * mp)
@@ -135,14 +116,23 @@ vl_api_lb_add_del_vip_t_handler
       rv = lb_vip_del(vip_index);
   } else {
     u32 vip_index;
-    lb_vip_type_t type;
+    lb_vip_type_t type = 0;
+
     if (ip46_prefix_is_ip4(&prefix, mp->prefix_length)) {
-      type = mp->is_gre4?LB_VIP_TYPE_IP4_GRE4:LB_VIP_TYPE_IP4_GRE6;
+        if (mp->encap == LB_ENCAP_TYPE_GRE4)
+       type = LB_VIP_TYPE_IP4_GRE4;
+        else if (mp->encap == LB_ENCAP_TYPE_GRE6)
+       type = LB_VIP_TYPE_IP4_GRE6;
+        else if (mp->encap == LB_ENCAP_TYPE_L3DSR)
+       type = LB_VIP_TYPE_IP4_L3DSR;
     } else {
-      type = mp->is_gre4?LB_VIP_TYPE_IP6_GRE4:LB_VIP_TYPE_IP6_GRE6;
+        if (mp->encap == LB_ENCAP_TYPE_GRE4)
+       type = LB_VIP_TYPE_IP6_GRE4;
+        else if (mp->encap == LB_ENCAP_TYPE_GRE6)
+       type = LB_VIP_TYPE_IP6_GRE6;
     }
 
-    rv = lb_vip_add(&prefix, mp->prefix_length, type,
+    rv = lb_vip_add(&prefix, mp->prefix_length, type, mp->dscp,
                     mp->new_flows_table_length, &vip_index);
   }
  REPLY_MACRO (VL_API_LB_CONF_REPLY);
@@ -155,7 +145,9 @@ static void *vl_api_lb_add_del_vip_t_print
   s = format (0, "SCRIPT: lb_add_del_vip ");
   s = format (s, "%U ", format_ip46_prefix,
               (ip46_address_t *)mp->ip_prefix, mp->prefix_length, IP46_TYPE_ANY);
-  s = format (s, "%s ", mp->is_gre4?"gre4":"gre6");
+
+  s = format (s, "%s ", (mp->encap==LB_ENCAP_TYPE_GRE4)?
+              "gre4":(mp->encap==LB_ENCAP_TYPE_GRE6)?"gre6":"l3dsr");
   s = format (s, "%u ", mp->new_flows_table_length);
   s = format (s, "%s ", mp->is_del?"del":"add");
   FINISH;