FD.io VPP  v16.09
Vector Packet Processing
ila_api.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <ila/ila.h>
17 
18 #include <vppinfra/byte_order.h>
19 #include <vlibapi/api.h>
20 #include <vlibapi/api.h>
21 #include <vlibmemory/api.h>
22 #include <vlibsocket/api.h>
23 
24 typedef struct
25 {
28 
30 
31 #define vl_msg_id(n,h) n,
32 typedef enum
33 {
34 #include <ila/ila.api.h>
35  /* We'll want to know how many messages IDs we need... */
37 } vl_msg_id_t;
38 #undef vl_msg_id
39 
40 /* define message structures */
41 #define vl_typedefs
42 #include <ila/ila.api.h>
43 #undef vl_typedefs
44 
45 /* define generated endian-swappers */
46 #define vl_endianfun
47 #include <ila/ila.api.h>
48 #undef vl_endianfun
49 
50 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
51 
52 /* Get the API version number */
53 #define vl_api_version(n,v) static u32 api_version=(v);
54 #include <ila/ila.api.h>
55 #undef vl_api_version
56 
57 #define FINISH \
58  vec_add1 (s, 0); \
59  vl_print (handle, (char *)s); \
60  vec_free (s); \
61  return handle;
62 
63 #define REPLY_MACRO(t) \
64 do { \
65  unix_shared_memory_queue_t * q = \
66  vl_api_client_index_to_input_queue (mp->client_index); \
67  if (!q) \
68  return; \
69  \
70  rmp = vl_msg_api_alloc (sizeof (*rmp)); \
71  rmp->_vl_msg_id = ntohs((t)+ila_api_main.msg_id_base); \
72  rmp->context = mp->context; \
73  rmp->retval = ntohl(rv); \
74  \
75  vl_msg_api_send_shmem (q, (u8 *)&rmp); \
76 } while(0);
77 
78 static void
80 {
82  int rv = 0;
83  rv = ila_interface (mp->sw_if_index, !mp->enable);
84 
85  REPLY_MACRO (VL_API_ILA_IFACE_REPLY);
86 }
87 
88 static void *
90 {
91  u8 *s;
92  s = format (0, "SCRIPT: ila_iface ");
93  s = format (s, "%d ", mp->sw_if_index);
94  s = format (s, "%s", mp->enable ? "enable" : "disable");
95  FINISH;
96 }
97 
98 static void
100 {
102  int rv = 0;
104  args.type = mp->type;
105  memcpy (&args.sir_address, mp->sir_address, sizeof (args.sir_address));
106  args.locator = mp->locator;
107  args.vnid = mp->vnid;
108  args.local_adj_index = mp->local_adj_index;
109  args.csum_mode = mp->csum_mode;
110  args.dir = mp->dir;
111  args.is_del = mp->is_del;
112 
113  rv = ila_add_del_entry (&args);
114  REPLY_MACRO (VL_API_ILA_ADD_DEL_ENTRY_REPLY);
115 }
116 
118  (vl_api_ila_add_del_entry_t * mp, void *handle)
119 {
120  u8 *s;
121  s = format (0, "SCRIPT: ila_add_del_entry ");
122  s = format (s, "%U ", format_ila_type, mp->type);
123  s = format (s, "%U ", format_ip6_address, mp->sir_address);
124  s = format (s, "%U ", format_half_ip6_address, mp->locator);
125  s = format (s, "%d ", mp->vnid);
126  s = format (s, "%d ", mp->local_adj_index);
127  s = format (s, "%U ", format_ila_csum_mode, mp->csum_mode);
128  s = format (s, "%U ", format_ila_direction, mp->dir);
129  s = format (s, "%s ", mp->is_del ? "del" : "add");
130  FINISH;
131 }
132 
133 /* List of message types that this plugin understands */
134 #define foreach_ila_plugin_api_msg \
135 _(ILA_IFACE, ila_iface) \
136 _(ILA_ADD_DEL_ENTRY, ila_add_del_entry)
137 
138 static clib_error_t *
140 {
141  u8 *name = format (0, "ila_%08x%c", api_version, 0);
142  ila_api_main.msg_id_base = vl_msg_api_get_msg_ids
143  ((char *) name, VL_MSG_FIRST_AVAILABLE);
144 
145 #define _(N,n) \
146  vl_msg_api_set_handlers((VL_API_##N + ila_api_main.msg_id_base), \
147  #n, \
148  vl_api_##n##_t_handler, \
149  vl_noop_handler, \
150  vl_api_##n##_t_endian, \
151  vl_api_##n##_t_print, \
152  sizeof(vl_api_##n##_t), 1);
154 #undef _
155 
156  return 0;
157 }
158 
ila_direction_t dir
Definition: ila.h:107
u8 csum_mode
Definition: ila.api:53
format_function_t format_ip6_address
Definition: format.h:87
u64 locator
Definition: ila.api:50
u8 * format_half_ip6_address(u8 *s, va_list *va)
Definition: ila.c:63
static void vl_api_ila_add_del_entry_t_handler(vl_api_ila_add_del_entry_t *mp)
Definition: ila_api.c:99
Definition: ila.h:99
u16 msg_id_base
Definition: ila_api.c:26
#define foreach_ila_plugin_api_msg
Definition: ila_api.c:134
vl_msg_id_t
Definition: ila_api.c:32
int ila_add_del_entry(ila_add_del_entry_args_t *args)
Definition: ila.c:619
u32 vnid
Definition: ila.api:51
static void * vl_api_ila_iface_t_print(vl_api_ila_iface_t *mp, void *handle)
Definition: ila_api.c:89
u8 type
Definition: ila.api:48
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:111
u8 is_del
Definition: ila.h:108
u8 dir
Definition: ila.api:54
u32 local_adj_index
Definition: ila.h:105
Definition: ila.api:58
u32 vnid
Definition: ila.h:104
u8 sir_address[16]
Definition: ila.api:49
u8 * format_ila_csum_mode(u8 *s, va_list *va)
Definition: ila.c:85
ila_csum_mode_t csum_mode
Definition: ila.h:106
u32 local_adj_index
Definition: ila.api:52
Add or delete an ILA entry.
Definition: ila.api:45
u8 * format_ila_direction(u8 *s, va_list *args)
Definition: ila.c:73
ila_type_t type
Definition: ila.h:101
static void * vl_api_ila_add_del_entry_t_print(vl_api_ila_add_del_entry_t *mp, void *handle)
Definition: ila_api.c:118
u8 is_del
Definition: ila.api:55
static clib_error_t * ila_api_init(vlib_main_t *vm)
Definition: ila_api.c:139
u8 * format(u8 *s, char *fmt,...)
Definition: format.c:418
#define FINISH
Definition: ila_api.c:57
ip6_address_t sir_address
Definition: ila.h:102
static void vl_api_ila_iface_t_handler(vl_api_ila_iface_t *mp)
Definition: ila_api.c:79
unsigned short u16
Definition: types.h:57
Enable ILA processing of SIR-to-ILA packets on a given interface.
Definition: ila.api:7
unsigned char u8
Definition: types.h:56
u64 locator
Definition: ila.h:103
u16 vl_msg_api_get_msg_ids(char *name, int n)
Definition: api_shared.c:1269
#define REPLY_MACRO(t)
Definition: ila_api.c:63
ila_api_main_t ila_api_main
Definition: ila_api.c:29
u8 * format_ila_type(u8 *s, va_list *args)
Definition: ila.c:106
int ila_interface(u32 sw_if_index, u8 disable)
Definition: ila.c:793