docs: Use newer Ubuntu LTS in tutorial
[vpp.git] / src / vnet / devices / pipe / pipe_api.c
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 #include <vnet/devices/pipe/pipe.h>
21
22 #include <vnet/format_fns.h>
23 #include <vnet/devices/pipe/pipe.api_enum.h>
24 #include <vnet/devices/pipe/pipe.api_types.h>
25
26 #define REPLY_MSG_ID_BASE msg_id_base
27 #include <vlibapi/api_helper_macros.h>
28 extern vpe_api_main_t vpe_api_main;
29
30 static u16 msg_id_base;
31
32 static void
33 vl_api_pipe_create_t_handler (vl_api_pipe_create_t * mp)
34 {
35   vl_api_pipe_create_reply_t *rmp;
36   u32 parent_sw_if_index;
37   u32 pipe_sw_if_index[2];
38   int rv;
39   u8 is_specified = mp->is_specified;
40   u32 user_instance = ntohl (mp->user_instance);
41
42   rv = vnet_create_pipe_interface (is_specified, user_instance,
43                                    &parent_sw_if_index, pipe_sw_if_index);
44
45   REPLY_MACRO2(VL_API_PIPE_CREATE_REPLY,
46   ({
47     rmp->sw_if_index = ntohl (parent_sw_if_index);
48     rmp->pipe_sw_if_index[0] = ntohl (pipe_sw_if_index[0]);
49     rmp->pipe_sw_if_index[1] = ntohl (pipe_sw_if_index[1]);
50   }));
51 }
52
53 static void
54 vl_api_pipe_delete_t_handler (vl_api_pipe_delete_t * mp)
55 {
56   vl_api_pipe_delete_reply_t *rmp;
57   int rv;
58
59   rv = vnet_delete_pipe_interface (ntohl (mp->sw_if_index));
60
61   REPLY_MACRO (VL_API_PIPE_DELETE_REPLY);
62 }
63
64 typedef struct pipe_dump_walk_t_
65 {
66   vl_api_registration_t *reg;
67   u32 context;
68 } pipe_dump_walk_t;
69
70 static walk_rc_t
71 pipe_send_details (u32 parent_sw_if_index,
72                    u32 pipe_sw_if_index[2], u32 instance, void *args)
73 {
74   pipe_dump_walk_t *ctx = args;
75   vl_api_pipe_details_t *mp;
76
77   mp = vl_msg_api_alloc (sizeof (*mp));
78   if (!mp)
79     return (WALK_STOP);
80
81   mp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_PIPE_DETAILS);
82   mp->context = ctx->context;
83
84   mp->instance = ntohl (instance);
85   mp->sw_if_index = ntohl (parent_sw_if_index);
86   mp->pipe_sw_if_index[0] = ntohl (pipe_sw_if_index[0]);
87   mp->pipe_sw_if_index[1] = ntohl (pipe_sw_if_index[1]);
88
89   vl_api_send_msg (ctx->reg, (u8 *) mp);
90
91   return (WALK_CONTINUE);
92 }
93
94 static void
95 vl_api_pipe_dump_t_handler (vl_api_pipe_dump_t * mp)
96 {
97   vl_api_registration_t *reg;
98
99   reg = vl_api_client_index_to_registration (mp->client_index);
100   if (!reg)
101     return;
102
103   pipe_dump_walk_t ctx = {
104     .reg = reg,
105     .context = mp->context,
106   };
107
108   pipe_walk (pipe_send_details, &ctx);
109 }
110
111 #include <vnet/devices/pipe/pipe.api.c>
112 static clib_error_t *
113 pipe_api_hookup (vlib_main_t * vm)
114 {
115   /*
116    * Set up the (msg_name, crc, message-id) table
117    */
118   REPLY_MSG_ID_BASE = setup_message_id_table ();
119
120   return 0;
121 }
122
123 VLIB_API_INIT_FUNCTION (pipe_api_hookup);
124
125 /*
126  * fd.io coding-style-patch-verification: ON
127  *
128  * Local Variables:
129  * eval: (c-set-style "gnu")
130  * End:
131  */