25 #include <vpp/app/version.h> 42 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) 48 #define vl_api_version(n,v) static u32 api_version=(v); 52 #define REPLY_MSG_ID_BASE lbm->msg_id_base 56 #define foreach_lb_plugin_api_msg \ 58 _(LB_ADD_DEL_VIP, lb_add_del_vip) \ 59 _(LB_ADD_DEL_AS, lb_add_del_as) \ 60 _(LB_VIP_DUMP, lb_vip_dump) \ 61 _(LB_AS_DUMP, lb_as_dump) \ 62 _(LB_FLUSH_VIP, lb_flush_vip) \ 68 vl_print (handle, (char *)s); \ 77 vl_api_lb_conf_reply_t * rmp;
99 s =
format (0,
"SCRIPT: lb_conf ");
113 vl_api_lb_conf_reply_t * rmp;
176 s =
format (0,
"SCRIPT: lb_add_del_vip ");
209 vl_api_lb_conf_reply_t * rmp;
212 ip46_address_t vip_ip_prefix;
213 ip46_address_t as_address;
241 s =
format (0,
"SCRIPT: lb_add_del_as ");
257 (vl_api_lb_vip_dump_t * mp)
273 if (vip != lbm->vips) {
274 msg_size = sizeof (*rmp);
275 rmp = vl_msg_api_alloc (msg_size);
276 memset (rmp, 0, msg_size);
278 htons (VL_API_LB_VIP_DETAILS + lbm->msg_id_base);
279 rmp->context = mp->context;
281 ip_address_encode(&vip->prefix, IP46_TYPE_ANY, &rmp->vip.pfx.address);
282 rmp->vip.pfx.len = vip->plen;
283 rmp->vip.protocol = htonl (vip->protocol);
284 rmp->vip.port = htons(vip->port);
285 rmp->encap = htonl(vip->type);
286 rmp->dscp = vip->encap_args.dscp;
287 rmp->srv_type = vip->encap_args.srv_type;
288 rmp->target_port = htons(vip->encap_args.target_port);
289 rmp->flow_table_length = htonl(vip->new_flow_table_mask + 1);
291 vl_api_send_msg (reg, (u8 *) rmp);
312 if (*as_index != 0) {
313 as = &lbm->ass[*as_index];
314 msg_size = sizeof (*rmp);
315 rmp = vl_msg_api_alloc (msg_size);
316 memset (rmp, 0, msg_size);
318 htons (VL_API_LB_AS_DETAILS + lbm->msg_id_base);
319 rmp->context = context;
320 ip_address_encode(&vip->prefix, IP46_TYPE_ANY, (vl_api_address_t *)&rmp->vip.pfx.address);
321 rmp->vip.pfx.len = vip->plen;
322 rmp->vip.protocol = htonl (vip->protocol);
323 rmp->vip.port = htons(vip->port);
324 ip_address_encode(&as->address, IP46_TYPE_ANY, &rmp->app_srv);
325 rmp->flags = as->flags;
326 rmp->in_use_since = htonl(as->last_used);
328 vl_api_send_msg (reg, (u8 *) rmp);
338 (vl_api_lb_as_dump_t * mp)
350 clib_memcpy(&prefix.ip6, mp->pfx.address.un.ip6,
sizeof(mp->pfx.address.un.ip6));
352 dump_all = (prefix.ip6.as_u64[0] == 0) && (prefix.ip6.as_u64[1] == 0);
358 || ((prefix.as_u64[0] == vip->prefix.as_u64[0])
359 && (prefix.as_u64[1] == vip->prefix.as_u64[1])
360 && (mp->protocol == vip->protocol)
361 && (mp->port == vip->port)) )
363 send_lb_as_details(reg, mp->context, vip);
375 ip46_address_t vip_prefix;
378 vl_api_lb_flush_vip_reply_t * rmp;
385 memcpy (&(vip_prefix.ip6), mp->
pfx.address.un.ip6,
sizeof(vip_prefix.ip6));
387 vip_plen = mp->
pfx.len;
390 ntohs(mp->
port), &vip_index);
401 s =
format (0,
"SCRIPT: lb_add_del_vip ");
403 &mp->
pfx.address, mp->
pfx.len);
416 vl_msg_api_set_handlers((VL_API_##N + lbm->msg_id_base), \ 418 vl_api_##n##_t_handler, \ 420 vl_api_##n##_t_endian, \ 421 vl_api_##n##_t_print, \ 422 sizeof(vl_api_##n##_t), 1); 429 #define vl_msg_name_crc_list 431 #undef vl_msg_name_crc_list 436 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + lmp->msg_id_base); 437 foreach_vl_msg_name_crc_lb ;
450 name =
format (0,
"lb_%08x%c", api_version, 0);
int lb_vip_del_ass(u32 vip_index, ip46_address_t *addresses, u32 n, u8 flush)
vl_api_address_t as_address
static void vl_api_lb_conf_t_handler(vl_api_lb_conf_t *mp)
static void * vl_api_lb_add_del_vip_t_print(vl_api_lb_add_del_vip_t *mp, void *handle)
Each VIP is configured with a set of application server.
vnet_main_t * vnet_get_main(void)
u32 per_cpu_sticky_buckets
Number of buckets in the per-cpu sticky hash table.
Optimized string handling code, including c11-compliant "safe C library" variants.
u16 msg_id_base
API dynamically registered base ID.
u8 * format_vl_api_address(u8 *s, va_list *args)
int lb_conf(ip4_address_t *ip4_address, ip6_address_t *ip6_address, u32 per_cpu_sticky_buckets, u32 flow_timeout)
Fix global load-balancer parameters.
int lb_vip_add_ass(u32 vip_index, ip46_address_t *addresses, u32 n)
u32 new_flows_table_length[default=1024]
static void * vl_api_lb_conf_t_print(vl_api_lb_conf_t *mp, void *handle)
static void * vl_api_lb_add_del_as_t_print(vl_api_lb_add_del_as_t *mp, void *handle)
#define clib_memcpy(d, s, n)
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
#define VLIB_INIT_FUNCTION(x)
vl_api_address_with_prefix_t pfx
static void vl_api_lb_vip_dump_t_handler(vl_api_lb_vip_dump_t *mp)
u32 flow_timeout
Flow timeout in seconds.
static clib_error_t * lb_plugin_api_hookup(vlib_main_t *vm)
ip46_type_t ip_address_decode(const vl_api_address_t *in, ip46_address_t *out)
lb_vip_t * vips
Pool of all Virtual IPs.
vl_api_fib_path_type_t type
u8 * format_vl_api_prefix(u8 *s, va_list *args)
vl_api_ip6_address_t ip6_src_address
int lb_vip_del(u32 vip_index)
#define foreach_lb_plugin_api_msg
vl_api_lb_srv_type_t type
int lb_flush_vip_as(u32 vip_index, u32 as_index)
Add an application server for a given VIP.
API main structure, used by both vpp and binary API clients.
#define ip46_prefix_is_ip4(ip46, len)
An API client registration, only in vpp/vlib.
#define vec_free(V)
Free vector's memory (no header).
static vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
u32 sticky_buckets_per_core
Reply all configured vip.
Add a virtual address (or prefix)
lb_vip_type_t
The load balancer supports IPv4 and IPv6 traffic and GRE4, GRE6, L3DSR and NAT4, NAT6 encap...
vl_api_address_with_prefix_t pfx
int lb_vip_find_index(ip46_address_t *prefix, u8 plen, u8 protocol, u16 port, u32 *vip_index)
lb_vip_encap_args_t encap_args
static void send_lb_as_details(vl_api_registration_t *reg, u32 context, lb_vip_t *vip)
Configure Load-Balancer global parameters (unlike the CLI, both ip4_src_address and ip6_src_address n...
int lb_vip_add(lb_vip_add_args_t args, u32 *vip_index)
vl_api_address_with_prefix_t pfx
static void * vl_api_lb_flush_vip_t_print(vl_api_lb_flush_vip_t *mp, void *handle)
vl_api_ip4_address_t ip4_src_address
static void vl_api_lb_as_dump_t_handler(vl_api_lb_as_dump_t *mp)
static void setup_message_id_table(lb_main_t *lmp, api_main_t *am)
static void vl_api_lb_add_del_vip_t_handler(vl_api_lb_add_del_vip_t *mp)
static void vl_api_lb_flush_vip_t_handler(vl_api_lb_flush_vip_t *mp)
vl_api_lb_encap_type_t encap
static void vl_api_lb_add_del_as_t_handler(vl_api_lb_add_del_as_t *mp)
Load balancing service is provided per VIP+protocol+port.
u32 * as_indexes
Pool of AS indexes used for this VIP.
static clib_error_t * lb_api_init(vlib_main_t *vm)
u16 vl_msg_api_get_msg_ids(const char *name, int n)