aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/lb
diff options
context:
space:
mode:
authorHongjun Ni <hongjun.ni@intel.com>2019-06-10 19:43:48 +0800
committerAndrew Yourtchenko <ayourtch@gmail.com>2019-07-31 19:35:13 +0000
commit3efcd0d7c3e73b812dece730396cf8816951d8ad (patch)
treebe6ea249ce63f3595c1271ba8e005881e02b9d86 /src/plugins/lb
parent515eed42583a52d4783ff4906afa01244899e030 (diff)
lb: vip and as dump/detail api's
- lb_vip_dump/lb_vip_details - get all vip. - lb_as_dump/lb_as_details - get all as list per vip. - adds api unit test. - adds vpp_lb to test framework. Ticket: Type: feature Change-Id: I24be50d62c5234f3535cc840603ddd9df7eb3f07 Signed-off-by: Hongjun Ni <hongjun.ni@intel.com> Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com> Signed-off-by: Hongjun Ni <hongjun.ni@intel.com>
Diffstat (limited to 'src/plugins/lb')
-rw-r--r--src/plugins/lb/CMakeLists.txt1
-rw-r--r--src/plugins/lb/api.c198
-rw-r--r--src/plugins/lb/lb.api95
-rw-r--r--src/plugins/lb/lb.c2
-rw-r--r--src/plugins/lb/lb_plugin_doc.md14
-rw-r--r--src/plugins/lb/lb_test.c133
-rw-r--r--src/plugins/lb/lb_types.api73
7 files changed, 441 insertions, 75 deletions
diff --git a/src/plugins/lb/CMakeLists.txt b/src/plugins/lb/CMakeLists.txt
index 406b16a9fe2..69ca948a001 100644
--- a/src/plugins/lb/CMakeLists.txt
+++ b/src/plugins/lb/CMakeLists.txt
@@ -21,6 +21,7 @@ add_vpp_plugin(lb
API_FILES
lb.api
+ lb_types.api
INSTALL_HEADERS
lb.h
diff --git a/src/plugins/lb/api.c b/src/plugins/lb/api.c
index ad92b9b97dd..86e2ce08ed7 100644
--- a/src/plugins/lb/api.c
+++ b/src/plugins/lb/api.c
@@ -19,10 +19,11 @@
#include <vppinfra/byte_order.h>
#include <vppinfra/string.h>
-#include <vlibapi/api.h>
+#include <vpp/api/types.h>
#include <vlibapi/api.h>
#include <vlibmemory/api.h>
#include <vpp/app/version.h>
+#include <vnet/ip/ip_types_api.h>
/* define message IDs */
#include <lb/lb_msg_enum.h>
@@ -56,6 +57,8 @@
_(LB_CONF, lb_conf) \
_(LB_ADD_DEL_VIP, lb_add_del_vip) \
_(LB_ADD_DEL_AS, lb_add_del_as) \
+_(LB_VIP_DUMP, lb_vip_dump) \
+_(LB_AS_DUMP, lb_as_dump) \
_(LB_FLUSH_VIP, lb_flush_vip) \
@@ -117,46 +120,46 @@ vl_api_lb_add_del_vip_t_handler
mp->protocol = ~0;
}
- memcpy (&(args.prefix.ip6), mp->ip_prefix, sizeof(args.prefix.ip6));
+ memcpy (&(args.prefix), &mp->pfx, sizeof(args.prefix));
if (mp->is_del) {
u32 vip_index;
- if (!(rv = lb_vip_find_index(&(args.prefix), mp->prefix_length,
+ if (!(rv = lb_vip_find_index(&(args.prefix), mp->pfx.len,
mp->protocol, ntohs(mp->port), &vip_index)))
rv = lb_vip_del(vip_index);
} else {
u32 vip_index;
lb_vip_type_t type = 0;
- if (ip46_prefix_is_ip4(&(args.prefix), mp->prefix_length)) {
- if (mp->encap == LB_ENCAP_TYPE_GRE4)
+ if (ip46_prefix_is_ip4(&(args.prefix), mp->pfx.len)) {
+ if (mp->encap == LB_API_ENCAP_TYPE_GRE4)
type = LB_VIP_TYPE_IP4_GRE4;
- else if (mp->encap == LB_ENCAP_TYPE_GRE6)
+ else if (mp->encap == LB_API_ENCAP_TYPE_GRE6)
type = LB_VIP_TYPE_IP4_GRE6;
- else if (mp->encap == LB_ENCAP_TYPE_L3DSR)
+ else if (mp->encap == LB_API_ENCAP_TYPE_L3DSR)
type = LB_VIP_TYPE_IP4_L3DSR;
- else if (mp->encap == LB_ENCAP_TYPE_NAT4)
+ else if (mp->encap == LB_API_ENCAP_TYPE_NAT4)
type = LB_VIP_TYPE_IP4_NAT4;
} else {
- if (mp->encap == LB_ENCAP_TYPE_GRE4)
+ if (mp->encap == LB_API_ENCAP_TYPE_GRE4)
type = LB_VIP_TYPE_IP6_GRE4;
- else if (mp->encap == LB_ENCAP_TYPE_GRE6)
+ else if (mp->encap == LB_API_ENCAP_TYPE_GRE6)
type = LB_VIP_TYPE_IP6_GRE6;
- else if (mp->encap == LB_ENCAP_TYPE_NAT6)
+ else if (mp->encap == LB_API_ENCAP_TYPE_NAT6)
type = LB_VIP_TYPE_IP6_NAT6;
}
- args.plen = mp->prefix_length;
+ args.plen = mp->pfx.len;
args.protocol = mp->protocol;
args.port = ntohs(mp->port);
args.type = type;
args.new_length = ntohl(mp->new_flows_table_length);
- if (mp->encap == LB_ENCAP_TYPE_L3DSR) {
+ if (mp->encap == LB_API_ENCAP_TYPE_L3DSR) {
args.encap_args.dscp = (u8)(mp->dscp & 0x3F);
}
- else if ((mp->encap == LB_ENCAP_TYPE_NAT4)
- ||(mp->encap == LB_ENCAP_TYPE_NAT6)) {
+ else if ((mp->encap == LB_API_ENCAP_TYPE_NAT4)
+ ||(mp->encap == LB_API_ENCAP_TYPE_NAT6)) {
args.encap_args.srv_type = mp->type;
args.encap_args.target_port = ntohs(mp->target_port);
}
@@ -171,22 +174,22 @@ static void *vl_api_lb_add_del_vip_t_print
{
u8 * s;
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, "%U", format_vl_api_prefix,
+ &mp->pfx);
- s = format (s, "%s ", (mp->encap == LB_ENCAP_TYPE_GRE4)? "gre4"
- : (mp->encap == LB_ENCAP_TYPE_GRE6)? "gre6"
- : (mp->encap == LB_ENCAP_TYPE_NAT4)? "nat4"
- : (mp->encap == LB_ENCAP_TYPE_NAT6)? "nat6"
+ s = format (s, "%s ", (mp->encap == LB_API_ENCAP_TYPE_GRE4)? "gre4"
+ : (mp->encap == LB_API_ENCAP_TYPE_GRE6)? "gre6"
+ : (mp->encap == LB_API_ENCAP_TYPE_NAT4)? "nat4"
+ : (mp->encap == LB_API_ENCAP_TYPE_NAT6)? "nat6"
: "l3dsr");
- if (mp->encap==LB_ENCAP_TYPE_L3DSR)
+ if (mp->encap==LB_API_ENCAP_TYPE_L3DSR)
{
s = format (s, "dscp %u ", mp->dscp);
}
- if ((mp->encap==LB_ENCAP_TYPE_NAT4)
- || (mp->encap==LB_ENCAP_TYPE_NAT6))
+ if ((mp->encap==LB_API_ENCAP_TYPE_NAT4)
+ || (mp->encap==LB_API_ENCAP_TYPE_NAT6))
{
s = format (s, "type %u ", mp->type);
s = format (s, "port %u ", mp->port);
@@ -208,15 +211,15 @@ vl_api_lb_add_del_as_t_handler
u32 vip_index;
ip46_address_t vip_ip_prefix;
- memcpy(&vip_ip_prefix.ip6, mp->vip_ip_prefix,
- sizeof(vip_ip_prefix.ip6));
+ memcpy(&vip_ip_prefix, &mp->pfx,
+ sizeof(vip_ip_prefix));
ip46_address_t as_address;
- memcpy(&as_address.ip6, mp->as_address,
- sizeof(as_address.ip6));
+ memcpy(&as_address, &mp->as_address,
+ sizeof(as_address));
- if ((rv = lb_vip_find_index(&vip_ip_prefix, mp->vip_prefix_length,
+ if ((rv = lb_vip_find_index(&vip_ip_prefix, mp->pfx.len,
mp->protocol, ntohs(mp->port), &vip_index)))
goto done;
@@ -233,16 +236,136 @@ static void *vl_api_lb_add_del_as_t_print
(vl_api_lb_add_del_as_t *mp, void * handle)
{
u8 * s;
+ ip46_address_t address;
s = format (0, "SCRIPT: lb_add_del_as ");
- s = format (s, "%U ", format_ip46_prefix,
- (ip46_address_t *)mp->vip_ip_prefix, mp->vip_prefix_length, IP46_TYPE_ANY);
- s = format (s, "%U ", format_ip46_address,
- (ip46_address_t *)mp->as_address, IP46_TYPE_ANY);
+ s = format (s, "%U ", format_vl_api_prefix,
+ &mp->pfx);
+ s = format(s, "%u ", mp->protocol);
+ if (ip_address_decode (&mp->as_address, &address) == IP46_TYPE_IP6)
+ s = format (s, "%U ", format_ip6_address,
+ (ip6_address_t *) & address.ip6);
+ else
+ s = format (s, "%U ", format_ip4_address,
+ (ip6_address_t *) & address.ip4);
s = format (s, "%s ", mp->is_del?"del":"add");
FINISH;
}
static void
+vl_api_lb_vip_dump_t_handler
+(vl_api_lb_vip_dump_t * mp)
+{
+
+ vl_api_registration_t *reg;
+ reg = vl_api_client_index_to_registration (mp->client_index);
+ if (!reg)
+ return;
+
+ lb_main_t *lbm = &lb_main;
+ vl_api_lb_vip_details_t * rmp;
+ int msg_size = 0;
+ lb_vip_t *vip = 0;
+
+ /* construct vip list */
+ pool_foreach(vip, lbm->vips, {
+ /* Hide dummy VIP */
+ if (vip != lbm->vips) {
+ msg_size = sizeof (*rmp);
+ rmp = vl_msg_api_alloc (msg_size);
+ memset (rmp, 0, msg_size);
+ rmp->_vl_msg_id =
+ htons (VL_API_LB_VIP_DETAILS + lbm->msg_id_base);
+ rmp->context = mp->context;
+
+ ip_address_encode(&vip->prefix, IP46_TYPE_ANY, &rmp->vip.pfx.address);
+ rmp->vip.pfx.len = vip->plen;
+ rmp->vip.protocol = htonl (vip->protocol);
+ rmp->vip.port = htons(vip->port);
+ rmp->encap = htonl(vip->type);
+ rmp->dscp = vip->encap_args.dscp;
+ rmp->srv_type = vip->encap_args.srv_type;
+ rmp->target_port = htons(vip->encap_args.target_port);
+ rmp->flow_table_length = htonl(vip->new_flow_table_mask + 1);
+
+ vl_api_send_msg (reg, (u8 *) rmp);
+ }
+ });
+
+
+}
+
+static void send_lb_as_details
+ (vl_api_registration_t * reg, u32 context, lb_vip_t * vip)
+{
+ vl_api_lb_as_details_t *rmp;
+ lb_main_t *lbm = &lb_main;
+ int msg_size = 0;
+ u32 *as_index;
+ u32 asindex = 0;
+
+ /* construct as list under this vip */
+ lb_as_t *as;
+
+ pool_foreach(as_index, vip->as_indexes, {
+ /* Hide dummy As for specific VIP */
+ if (*as_index != 0) {
+ as = &lbm->ass[*as_index];
+ msg_size = sizeof (*rmp);
+ rmp = vl_msg_api_alloc (msg_size);
+ memset (rmp, 0, msg_size);
+ rmp->_vl_msg_id =
+ htons (VL_API_LB_AS_DETAILS + lbm->msg_id_base);
+ rmp->context = context;
+ ip_address_encode(&vip->prefix, IP46_TYPE_ANY, (vl_api_address_t *)&rmp->vip.pfx.address);
+ rmp->vip.pfx.len = vip->plen;
+ rmp->vip.protocol = htonl (vip->protocol);
+ rmp->vip.port = htons(vip->port);
+ ip_address_encode(&as->address, IP46_TYPE_ANY, &rmp->app_srv);
+ rmp->flags = as->flags;
+ rmp->in_use_since = htonl(as->last_used);
+
+ vl_api_send_msg (reg, (u8 *) rmp);
+ asindex++;
+ }
+ });
+
+
+}
+
+static void
+vl_api_lb_as_dump_t_handler
+(vl_api_lb_as_dump_t * mp)
+{
+ lb_main_t *lbm = &lb_main;
+ lb_vip_t *vip = 0;
+ u8 dump_all = 0;
+ ip46_address_t prefix;
+
+ vl_api_registration_t *reg;
+ reg = vl_api_client_index_to_registration (mp->client_index);
+ if (!reg)
+ return;
+
+ clib_memcpy(&prefix.ip6, mp->pfx.address.un.ip6, sizeof(mp->pfx.address.un.ip6));
+
+ dump_all = (prefix.ip6.as_u64[0] == 0) && (prefix.ip6.as_u64[1] == 0);
+
+ /* *INDENT-OFF* */
+ pool_foreach(vip, lbm->vips,
+ ({
+ if ( dump_all
+ || ((prefix.as_u64[0] == vip->prefix.as_u64[0])
+ && (prefix.as_u64[1] == vip->prefix.as_u64[1])
+ && (mp->protocol == vip->protocol)
+ && (mp->port == vip->port)) )
+ {
+ send_lb_as_details(reg, mp->context, vip);
+ }
+ }));
+ /* *INDENT-ON* */
+}
+
+static void
vl_api_lb_flush_vip_t_handler
(vl_api_lb_flush_vip_t * mp)
{
@@ -258,9 +381,9 @@ vl_api_lb_flush_vip_t_handler
mp->protocol = ~0;
}
- memcpy (&(vip_prefix.ip6), mp->ip_prefix, sizeof(vip_prefix.ip6));
+ memcpy (&(vip_prefix.ip6), mp->pfx.address.un.ip6, sizeof(vip_prefix.ip6));
- vip_plen = mp->prefix_length;
+ vip_plen = mp->pfx.len;
rv = lb_vip_find_index(&vip_prefix, vip_plen, mp->protocol,
ntohs(mp->port), &vip_index);
@@ -275,9 +398,8 @@ static void *vl_api_lb_flush_vip_t_print
{
u8 * s;
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, "%U/%d", format_vl_api_address,
+ &mp->pfx.address, mp->pfx.len);
s = format (s, "protocol %u ", mp->protocol);
s = format (s, "port %u ", mp->port);
diff --git a/src/plugins/lb/lb.api b/src/plugins/lb/lb.api
index c24440936d3..867832df966 100644
--- a/src/plugins/lb/lb.api
+++ b/src/plugins/lb/lb.api
@@ -1,5 +1,5 @@
option version = "1.0.0";
-import "vnet/ip/ip_types.api";
+import "plugins/lb/lb_types.api";
/** \brief Configure Load-Balancer global parameters (unlike the CLI, both ip4_src_address and ip6_src_address need to be specified.
@param client_index - opaque cookie to identify the sender
@@ -24,8 +24,7 @@ autoreply manual_print define lb_conf
/** \brief Add a virtual address (or prefix)
@param client_index - opaque cookie to identify the sender
@param context - sender context, to match reply w/ request
- @param ip_prefix - IP address (IPv4 in lower order 32 bits).
- @param prefix_length - IP prefix length (96 + 'IPv4 prefix length' for IPv4).
+ @param pfx - ip prefix and length
@param protocol - tcp or udp.
@param port - destination port. (0) means 'all-port VIP'
@param encap - Encap is ip4 GRE(0) or ip6 GRE(1) or L3DSR(2) or NAT4(3) or NAT6(4).
@@ -40,24 +39,22 @@ autoreply manual_print define lb_conf
autoreply manual_print define lb_add_del_vip {
u32 client_index;
u32 context;
- u8 ip_prefix[16];
- u8 prefix_length;
- u8 protocol;
+ vl_api_prefix_t pfx;
+ u8 protocol [default=255];
u16 port;
- u8 encap;
+ vl_api_lb_encap_type_t encap;
u8 dscp;
- u8 type;
+ vl_api_lb_srv_type_t type ; /* LB_API_SRV_TYPE_CLUSTERIP */
u16 target_port;
u16 node_port;
- u32 new_flows_table_length;
- u8 is_del;
+ u32 new_flows_table_length [default=1024];
+ bool is_del;
};
/** \brief Add an application server for a given VIP
@param client_index - opaque cookie to identify the sender
@param context - sender context, to match reply w/ request
- @param vip_ip_prefix - VIP IP address (IPv4 in lower order 32 bits).
- @param vip_prefix_length - VIP IP prefix length (96 + 'IPv4 prefix length' for IPv4).
+ @param pfx - ip prefix and length
@param protocol - tcp or udp.
@param port - destination port.
@param as_address - The application server address (IPv4 in lower order 32 bits).
@@ -67,28 +64,82 @@ autoreply manual_print define lb_add_del_vip {
autoreply manual_print define lb_add_del_as {
u32 client_index;
u32 context;
- u8 vip_ip_prefix[16];
- u8 vip_prefix_length;
- u8 protocol;
+ vl_api_prefix_t pfx;
+ u8 protocol [default=255];
u16 port;
- u8 as_address[16];
- u8 is_del;
- u8 is_flush;
+ vl_api_address_t as_address;
+ bool is_del;
+ bool is_flush;
};
/** \brief Flush a given vip
@param client_index - opaque cookie to identify the sender
@param context - sender context, to match reply w/ request
- @param ip_prefix - IP address (IPv4 in lower order 32 bits).
- @param prefix_length - IP prefix length (96 + 'IPv4 prefix length' for IPv4).
+ @param pfx - ip prefix and length
@param protocol - tcp or udp.
@param port - destination port.
*/
autoreply manual_print define lb_flush_vip {
u32 client_index;
u32 context;
- u8 ip_prefix[16];
- u8 prefix_length;
+ vl_api_prefix_t pfx;
+ u8 protocol;
+ u16 port;
+};
+
+/** \brief Dump all vips
+ @param client_index - opaque cookie to identify the sender
+ @param context - sender context, to match reply w/ request
+*/
+define lb_vip_dump{
+ u32 client_index;
+ u32 context;
+ vl_api_prefix_t pfx;
+ vl_api_prefix_matcher_t pfx_matcher;
+ u8 protocol [default=255];
+ u16 port;
+
+};
+
+/** \brief Reply all configured vip
+ @param context - sender context, to match reply w/ request
+ @param vip - all vip addrs.
+*/
+define lb_vip_details {
+ u32 context;
+ vl_api_lb_vip_t vip;
+ vl_api_lb_encap_type_t encap;
+ vl_api_ip_dscp_t dscp;
+ vl_api_lb_srv_type_t srv_type;
+ u16 target_port;
+ u16 flow_table_length;
+};
+
+/** \brief dump AS list per VIP or all ASs for all VIPs
+ @param client_index - opaque cookie to identify the sender
+ @param context - sender context, to match reply w/ request
+ @param pfx - ip prefix and length.
+ @param protocol - tcp or udp.
+ @param port - destination port.
+*/
+define lb_as_dump{
+ u32 client_index;
+ u32 context;
+ /* vip */
+ vl_api_prefix_t pfx;
u8 protocol;
u16 port;
};
+
+/** \brief lb_as_details
+ @param context - sender context, to match reply w/ request
+ @param as - AS detail record
+*/
+define lb_as_details {
+ u32 context;
+ vl_api_lb_vip_t vip;
+ vl_api_address_t app_srv;
+ u8 flags;
+ u32 in_use_since;
+};
+
diff --git a/src/plugins/lb/lb.c b/src/plugins/lb/lb.c
index 3ac2b284ea6..b1e0b237478 100644
--- a/src/plugins/lb/lb.c
+++ b/src/plugins/lb/lb.c
@@ -860,7 +860,7 @@ static int
lb_vip_prefix_index_alloc (lb_main_t *lbm)
{
/*
- * Check for dynamically allocaetd instance number.
+ * Check for dynamically allocated instance number.
*/
u32 bit;
diff --git a/src/plugins/lb/lb_plugin_doc.md b/src/plugins/lb/lb_plugin_doc.md
index 25a4cfa11df..5f6538974e9 100644
--- a/src/plugins/lb/lb_plugin_doc.md
+++ b/src/plugins/lb/lb_plugin_doc.md
@@ -3,8 +3,8 @@
## Version
The load balancer plugin is currently in *beta* version.
-Both CLIs and APIs are subject to *heavy* changes.
-Wich also means feedback is really welcome regarding features, apis, etc...
+Both CLIs and APIs are subject to *heavy* changes,
+which also means feedback is really welcome regarding features, apis, etc...
## Overview
@@ -31,7 +31,7 @@ Meaning that for a given VIP, all AS addresses must be of the same family.
3). IPv4/IPv6 + NAT4/NAT6 encap types:
This type provides kube-proxy data plane on user space,
-which is used to replace linux kernal's kube-proxy based on iptables.
+which is used to replace linux kernel's kube-proxy based on iptables.
Currently, load balancer plugin supports three service types:
a) Cluster IP plus Port: support any protocols, including TCP, UDP.
@@ -55,11 +55,11 @@ Please refer to below for details:
https://schd.ws/hosted_files/ossna2017/1e/VPP_K8S_GTPU_OSSNA.pdf
-## Performances
+## Performance
The load balancer has been tested up to 1 millions flows and still forwards more
than 3Mpps per core in such circumstances.
-Although 3Mpps seems already good, it is likely that performances will be improved
+Although 3Mpps seems already good, it is likely that performance will be improved
in next versions.
## Configuration
@@ -77,10 +77,10 @@ ip4-src-address: the source address used to send encap. packets using IPv4 for G
ip6-src-address: the source address used to send encap. packets using IPv6 for GRE6 mode.
or Node IP6 address for NAT6 mode.
-buckets: the *per-thread* established-connexions-table number of buckets.
+buckets: the *per-thread* established-connections-table number of buckets.
timeout: the number of seconds a connection will remain in the
- established-connexions-table while no packet for this flow
+ established-connections-table while no packet for this flow
is received.
### Configure the VIPs
diff --git a/src/plugins/lb/lb_test.c b/src/plugins/lb/lb_test.c
index 4ac306bba1c..cc8cc58c0be 100644
--- a/src/plugins/lb/lb_test.c
+++ b/src/plugins/lb/lb_test.c
@@ -128,7 +128,9 @@ foreach_standard_reply_retval_handler;
#define foreach_vpe_api_reply_msg \
_(LB_CONF_REPLY, lb_conf_reply) \
_(LB_ADD_DEL_VIP_REPLY, lb_add_del_vip_reply) \
- _(LB_ADD_DEL_AS_REPLY, lb_add_del_as_reply)
+ _(LB_ADD_DEL_AS_REPLY, lb_add_del_as_reply) \
+ _(LB_VIP_DETAILS, lb_vip_details) \
+ _(LB_AS_DETAILS, lb_as_details)
static int api_lb_conf (vat_main_t * vam)
{
@@ -245,8 +247,8 @@ static int api_lb_add_del_vip (vat_main_t * vam)
}
M(LB_ADD_DEL_VIP, mp);
- clib_memcpy (mp->ip_prefix, &ip_prefix, sizeof (ip_prefix));
- mp->prefix_length = prefix_length;
+ clib_memcpy (mp->pfx.address.un.ip6, &ip_prefix.ip6, sizeof (ip_prefix.ip6));
+ mp->pfx.len = prefix_length;
mp->protocol = (u8)protocol;
mp->port = htons((u16)port);
mp->encap = (u8)encap;
@@ -320,11 +322,11 @@ static int api_lb_add_del_as (vat_main_t * vam)
}
M(LB_ADD_DEL_AS, mp);
- clib_memcpy (mp->vip_ip_prefix, &vip_prefix, sizeof (vip_prefix));
- mp->vip_prefix_length = vip_plen;
+ clib_memcpy (mp->pfx.address.un.ip6, &vip_prefix.ip6, sizeof (vip_prefix.ip6));
+ mp->pfx.len = vip_plen;
mp->protocol = (u8)protocol;
mp->port = htons((u16)port);
- clib_memcpy (mp->as_address, &as_addr, sizeof (as_addr));
+ clib_memcpy (&mp->as_address, &as_addr, sizeof (as_addr));
mp->is_del = is_del;
mp->is_flush = is_flush;
@@ -333,6 +335,121 @@ static int api_lb_add_del_as (vat_main_t * vam)
return ret;
}
+static void vl_api_lb_vip_details_t_handler
+ (vl_api_lb_vip_details_t * mp)
+{
+ vat_main_t *vam = &vat_main;
+ lb_main_t *lbm = &lb_main;
+ u32 i = 0;
+
+ u32 vip_count = pool_len(lbm->vips);
+
+ print (vam->ofp, "%11d", vip_count);
+
+ for (i=0; i<vip_count; i--)
+ {
+ print (vam->ofp, "%24U%14d%14d%18d",
+ format_ip46_address, &mp->vip.pfx.address, IP46_TYPE_ANY,
+ mp->vip.pfx.len,
+ mp->vip.protocol,
+ ntohs (mp->vip.port));
+ }
+}
+
+static int api_lb_vip_dump (vat_main_t * vam)
+{
+ vl_api_lb_vip_dump_t *mp;
+ int ret;
+
+ M(LB_VIP_DUMP, mp);
+
+ S(mp);
+ W (ret);
+ return ret;
+}
+
+static void vl_api_lb_as_details_t_handler
+ (vl_api_lb_as_details_t * mp)
+{
+ vat_main_t *vam = &vat_main;
+ lb_main_t *lbm = &lb_main;
+
+ //u32 i = 0;
+
+ print (vam->ofp, "%11d", pool_len(lbm->ass));
+/*
+ for (i=0; i<pool_len(lbm->ass); i--)
+ {
+ print (vam->ofp, "%24U%14d%14d%18d",
+ format_ip46_address, &mp->pfx.address, IP46_TYPE_ANY,
+ mp->pfx.len,
+ mp->pfx.protocol,
+ ntohs (mp->pfx.port),
+ ntohl(mp->app_srv),
+ mp->flags,
+ mp->in_use_;
+ }
+ */
+}
+
+static int api_lb_as_dump (vat_main_t * vam)
+{
+
+ unformat_input_t *line_input = vam->input;
+ vl_api_lb_as_dump_t *mp;
+ int ret;
+ ip46_address_t vip_prefix, as_addr;
+ u8 vip_plen;
+ ip46_address_t *as_array = 0;
+ u32 port = 0;
+ u8 protocol = 0;
+
+ if (!unformat(line_input, "%U", unformat_ip46_prefix,
+ &vip_prefix, &vip_plen, IP46_TYPE_ANY))
+ {
+ errmsg ("lb_add_del_as: invalid vip prefix\n");
+ return -99;
+ }
+
+ while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat(line_input, "%U", unformat_ip46_address,
+ &as_addr, IP46_TYPE_ANY))
+ {
+ vec_add1(as_array, as_addr);
+ }
+ else if (unformat(line_input, "protocol tcp"))
+ {
+ protocol = IP_PROTOCOL_TCP;
+ }
+ else if (unformat(line_input, "protocol udp"))
+ {
+ protocol = IP_PROTOCOL_UDP;
+ }
+ else if (unformat(line_input, "port %d", &port))
+ ;
+ else {
+ errmsg ("invalid arguments\n");
+ return -99;
+ }
+ }
+
+ if (!vec_len(as_array)) {
+ errmsg ("No AS address provided \n");
+ return -99;
+ }
+
+ M(LB_AS_DUMP, mp);
+ clib_memcpy (mp->pfx.address.un.ip6, &vip_prefix.ip6, sizeof (vip_prefix.ip6));
+ mp->pfx.len = vip_plen;
+ mp->protocol = (u8)protocol;
+ mp->port = htons((u16)port);
+
+ S(mp);
+ W (ret);
+ return ret;
+}
+
/*
* List of messages that the api test plugin sends,
* and that the data plane plugin processes
@@ -347,7 +464,9 @@ _(lb_add_del_vip, "<prefix> " \
"[type (nodeport|clusterip) target_port <n>] " \
"[new_len <n>] [del]") \
_(lb_add_del_as, "<vip-prefix> [protocol (tcp|udp) port <n>] " \
- "[<address>] [del] [flush]")
+ "[<address>] [del] [flush]") \
+_(lb_vip_dump, "") \
+_(lb_as_dump, "<vip-prefix> [protocol (tcp|udp) port <n>]")
static void
lb_api_hookup (vat_main_t *vam)
diff --git a/src/plugins/lb/lb_types.api b/src/plugins/lb/lb_types.api
new file mode 100644
index 00000000000..818e51462c5
--- /dev/null
+++ b/src/plugins/lb/lb_types.api
@@ -0,0 +1,73 @@
+/* Hey Emacs use -*- mode: C -*- */
+/*
+ * Copyright (c) 2019 Vinci Consulting Corp. All Rights Reserved.
+ * 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.
+ */
+ import "vnet/ip/ip_types.api";
+
+enum lb_srv_type
+{
+ LB_API_SRV_TYPE_CLUSTERIP = 0,
+ LB_API_SRV_TYPE_NODEPORT = 1,
+ LB_API_SRV_N_TYPES = 2,
+};
+
+enum lb_encap_type
+{
+ LB_API_ENCAP_TYPE_GRE4 = 0,
+ LB_API_ENCAP_TYPE_GRE6 = 1,
+ LB_API_ENCAP_TYPE_L3DSR = 2,
+ LB_API_ENCAP_TYPE_NAT4 = 3 ,
+ LB_API_ENCAP_TYPE_NAT6 =4,
+ LB_API_ENCAP_N_TYPES =5,
+};
+
+/* Lookup types */
+enum lb_lkp_type_t
+{
+ LB_API_LKP_SAME_IP_PORT = 0,
+ LB_API_LKP_DIFF_IP_PORT = 1,
+ LB_API_LKP_ALL_PORT_IP =2,
+ LB_API_LKP_N_TYPES =3,
+};
+
+enum lb_vip_type
+{
+ LB_API_VIP_TYPE_IP6_GRE6 = 0,
+ LB_API_VIP_TYPE_IP6_GRE4 = 1,
+ LB_API_VIP_TYPE_IP4_GRE6 = 2,
+ LB_API_VIP_TYPE_IP4_GRE4 = 3,
+ LB_API_VIP_TYPE_IP4_L3DSR = 4,
+ LB_API_VIP_TYPE_IP4_NAT4 = 5,
+ LB_API_VIP_TYPE_IP6_NAT6 = 6,
+ LB_API_VIP_N_TYPES = 7,
+};
+
+enum lb_nat_protocol
+{
+ LB_API_NAT_PROTOCOL_UDP = 0x06,
+ LB_API_NAT_PROTOCOL_TCP = 0x17,
+ LB_API_NAT_PROTOCOL_ANY = 0xffffffff,
+};
+
+/** \brief Define connection statistics structure
+ @param pfx - ip prefix and length
+ @param protocol - tcp or udp.
+ @param port - destination port.
+*/
+typeonly define lb_vip
+{
+ vl_api_prefix_t pfx;
+ vl_api_ip_proto_t protocol;
+ u16 port;
+};