FD.io VPP  v18.07.1-13-g909ba93
Vector Packet Processing
pipe_api.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2018 Cisco and/or its affiliates.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *------------------------------------------------------------------
16  */
17 
18 #include <vnet/vnet.h>
19 #include <vlibmemory/api.h>
20 
21 #include <vnet/devices/pipe/pipe.h>
22 #include <vnet/vnet_msg_enum.h>
23 
24 #define vl_typedefs /* define message structures */
25 #include <vnet/vnet_all_api_h.h>
26 #undef vl_typedefs
27 
28 #define vl_endianfun /* define message structures */
29 #include <vnet/vnet_all_api_h.h>
30 #undef vl_endianfun
31 
32 /* instantiate all the print functions we know about */
33 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
34 #define vl_printfun
35 #include <vnet/vnet_all_api_h.h>
36 #undef vl_printfun
37 
40 
41 #define foreach_vpe_api_msg \
42  _(PIPE_CREATE, pipe_create) \
43  _(PIPE_DELETE, pipe_delete) \
44  _(PIPE_DUMP, pipe_dump)
45 
46 static void
48 {
50  u32 parent_sw_if_index;
51  u32 pipe_sw_if_index[2];
52  int rv;
53  u8 is_specified = mp->is_specified;
54  u32 user_instance = ntohl (mp->user_instance);
55 
56  rv = vnet_create_pipe_interface (is_specified, user_instance,
57  &parent_sw_if_index, pipe_sw_if_index);
58 
59  /* *INDENT-OFF* */
60  REPLY_MACRO2(VL_API_PIPE_CREATE_REPLY,
61  ({
62  rmp->sw_if_index = ntohl (parent_sw_if_index);
63  rmp->pipe_sw_if_index[0] = ntohl (pipe_sw_if_index[0]);
64  rmp->pipe_sw_if_index[1] = ntohl (pipe_sw_if_index[1]);
65  }));
66  /* *INDENT-ON* */
67 }
68 
69 static void
71 {
72  vl_api_pipe_delete_reply_t *rmp;
73  int rv;
74 
75  rv = vnet_delete_pipe_interface (ntohl (mp->sw_if_index));
76 
77  REPLY_MACRO (VL_API_PIPE_DELETE_REPLY);
78 }
79 
80 typedef struct pipe_dump_walk_t_
81 {
85 
86 static walk_rc_t
87 pipe_send_details (u32 parent_sw_if_index,
88  u32 pipe_sw_if_index[2], u32 instance, void *args)
89 {
90  pipe_dump_walk_t *ctx = args;
92 
93  mp = vl_msg_api_alloc (sizeof (*mp));
94  if (!mp)
95  return (WALK_STOP);
96 
97  mp->_vl_msg_id = ntohs (VL_API_PIPE_DETAILS);
98  mp->context = ctx->context;
99 
100  mp->instance = ntohl (instance);
101  mp->sw_if_index = ntohl (parent_sw_if_index);
102  mp->pipe_sw_if_index[0] = ntohl (pipe_sw_if_index[0]);
103  mp->pipe_sw_if_index[1] = ntohl (pipe_sw_if_index[1]);
104 
105  vl_api_send_msg (ctx->reg, (u8 *) mp);
106 
107  return (WALK_CONTINUE);
108 }
109 
110 static void
112 {
114 
116  if (!reg)
117  return;
118 
120  .reg = reg,
121  .context = mp->context,
122  };
123 
125 }
126 
127 /*
128  * vpe_api_hookup
129  * Add vpe's API message handlers to the table.
130  * vlib has alread mapped shared memory and
131  * added the client registration handlers.
132  * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
133  */
134 #define vl_msg_name_crc_list
135 #include <vnet/devices/pipe/pipe.api.h>
136 #undef vl_msg_name_crc_list
137 
138 static void
140 {
141 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
142  foreach_vl_msg_name_crc_pipe;
143 #undef _
144 }
145 
146 static clib_error_t *
148 {
149  api_main_t *am = &api_main;
150 
151 #define _(N,n) \
152  vl_msg_api_set_handlers(VL_API_##N, #n, \
153  vl_api_##n##_t_handler, \
154  vl_noop_handler, \
155  vl_api_##n##_t_endian, \
156  vl_api_##n##_t_print, \
157  sizeof(vl_api_##n##_t), 1);
159 #undef _
160 
161  /*
162  * Set up the (msg_name, crc, message-id) table
163  */
165 
166  return 0;
167 }
168 
170 
171 /*
172  * fd.io coding-style-patch-verification: ON
173  *
174  * Local Variables:
175  * eval: (c-set-style "gnu")
176  * End:
177  */
#define REPLY_MACRO2(t, body)
static void vl_api_send_msg(vl_api_registration_t *rp, u8 *elem)
Definition: api.h:34
static void vl_api_pipe_delete_t_handler(vl_api_pipe_delete_t *mp)
Definition: pipe_api.c:70
void * vl_msg_api_alloc(int nbytes)
#define foreach_vpe_api_msg
Definition: pipe_api.c:41
unsigned char u8
Definition: types.h:56
enum walk_rc_t_ walk_rc_t
Walk return code.
unsigned int u32
Definition: types.h:88
static void vl_api_pipe_dump_t_handler(vl_api_pipe_dump_t *mp)
Definition: pipe_api.c:111
void pipe_walk(pipe_cb_fn_t fn, void *ctx)
Walk all the of pipe interfaces.
Definition: pipe.c:658
Reply for pipe dump request.
Definition: pipe.api:78
#define REPLY_MACRO(t)
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:201
An API client registration, only in vpp/vlib.
Definition: api_common.h:44
static void vl_api_pipe_create_t_handler(vl_api_pipe_create_t *mp)
Definition: pipe_api.c:47
vlib_main_t * vm
Definition: buffer.c:294
int vnet_delete_pipe_interface(u32 sw_if_index)
Definition: pipe.c:717
Dump pipe interfaces request.
Definition: pipe.api:66
static vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
Definition: api.h:56
struct pipe_dump_walk_t_ pipe_dump_walk_t
Initialize a new pipe interface with the given paramters.
Definition: pipe.api:30
long ctx[MAX_CONNS]
Definition: main.c:126
Reply for pipe create reply.
Definition: pipe.api:45
int vnet_create_pipe_interface(u8 is_specified, u32 user_instance, u32 *parent_sw_if_index, u32 pipe_sw_if_index[2])
Create a new pipe interface.
Definition: pipe.c:540
vl_api_registration_t * reg
Definition: pipe_api.c:82
static walk_rc_t pipe_send_details(u32 parent_sw_if_index, u32 pipe_sw_if_index[2], u32 instance, void *args)
Definition: pipe_api.c:87
static clib_error_t * pipe_api_hookup(vlib_main_t *vm)
Definition: pipe_api.c:147
static void setup_message_id_table(api_main_t *am)
Definition: pipe_api.c:139
VLIB_API_INIT_FUNCTION(pipe_api_hookup)
vpe_api_main_t vpe_api_main
Definition: pipe_api.c:39
api_main_t api_main
Definition: api_shared.c:35
u32 pipe_sw_if_index[2]
Definition: pipe.api:82
Delete pipe interface.
Definition: pipe.api:58