blob: 1f0faef7c1e17c57aaff6435ce101c44fbb5577a [file] [log] [blame]
Neale Ranns17ff3c12018-07-04 10:24:24 -07001/*
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>
Neale Ranns17ff3c12018-07-04 10:24:24 -070020#include <vnet/devices/pipe/pipe.h>
Neale Ranns17ff3c12018-07-04 10:24:24 -070021
Filip Tehlar36d5c972021-06-22 11:28:25 +000022#include <vnet/format_fns.h>
23#include <vnet/devices/pipe/pipe.api_enum.h>
24#include <vnet/devices/pipe/pipe.api_types.h>
Neale Ranns17ff3c12018-07-04 10:24:24 -070025
Filip Tehlar36d5c972021-06-22 11:28:25 +000026#define REPLY_MSG_ID_BASE msg_id_base
Neale Ranns17ff3c12018-07-04 10:24:24 -070027#include <vlibapi/api_helper_macros.h>
BenoƮt Ganne47727c02019-02-12 13:35:08 +010028extern vpe_api_main_t vpe_api_main;
Neale Ranns17ff3c12018-07-04 10:24:24 -070029
Filip Tehlar36d5c972021-06-22 11:28:25 +000030static u16 msg_id_base;
Neale Ranns17ff3c12018-07-04 10:24:24 -070031
32static void
33vl_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 /* *INDENT-OFF* */
46 REPLY_MACRO2(VL_API_PIPE_CREATE_REPLY,
47 ({
Neale Ranns208c29a2018-04-11 08:08:30 -070048 rmp->sw_if_index = ntohl (parent_sw_if_index);
Neale Ranns17ff3c12018-07-04 10:24:24 -070049 rmp->pipe_sw_if_index[0] = ntohl (pipe_sw_if_index[0]);
50 rmp->pipe_sw_if_index[1] = ntohl (pipe_sw_if_index[1]);
51 }));
52 /* *INDENT-ON* */
53}
54
55static void
56vl_api_pipe_delete_t_handler (vl_api_pipe_delete_t * mp)
57{
58 vl_api_pipe_delete_reply_t *rmp;
59 int rv;
60
Neale Ranns208c29a2018-04-11 08:08:30 -070061 rv = vnet_delete_pipe_interface (ntohl (mp->sw_if_index));
Neale Ranns17ff3c12018-07-04 10:24:24 -070062
63 REPLY_MACRO (VL_API_PIPE_DELETE_REPLY);
64}
65
66typedef struct pipe_dump_walk_t_
67{
68 vl_api_registration_t *reg;
69 u32 context;
70} pipe_dump_walk_t;
71
72static walk_rc_t
73pipe_send_details (u32 parent_sw_if_index,
74 u32 pipe_sw_if_index[2], u32 instance, void *args)
75{
76 pipe_dump_walk_t *ctx = args;
77 vl_api_pipe_details_t *mp;
78
79 mp = vl_msg_api_alloc (sizeof (*mp));
80 if (!mp)
81 return (WALK_STOP);
82
Filip Tehlar36d5c972021-06-22 11:28:25 +000083 mp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_PIPE_DETAILS);
Neale Ranns17ff3c12018-07-04 10:24:24 -070084 mp->context = ctx->context;
85
86 mp->instance = ntohl (instance);
Neale Ranns208c29a2018-04-11 08:08:30 -070087 mp->sw_if_index = ntohl (parent_sw_if_index);
Neale Ranns17ff3c12018-07-04 10:24:24 -070088 mp->pipe_sw_if_index[0] = ntohl (pipe_sw_if_index[0]);
89 mp->pipe_sw_if_index[1] = ntohl (pipe_sw_if_index[1]);
90
91 vl_api_send_msg (ctx->reg, (u8 *) mp);
92
93 return (WALK_CONTINUE);
94}
95
96static void
97vl_api_pipe_dump_t_handler (vl_api_pipe_dump_t * mp)
98{
99 vl_api_registration_t *reg;
100
101 reg = vl_api_client_index_to_registration (mp->client_index);
102 if (!reg)
103 return;
104
105 pipe_dump_walk_t ctx = {
106 .reg = reg,
107 .context = mp->context,
108 };
109
110 pipe_walk (pipe_send_details, &ctx);
111}
112
Filip Tehlar36d5c972021-06-22 11:28:25 +0000113#include <vnet/devices/pipe/pipe.api.c>
Neale Ranns17ff3c12018-07-04 10:24:24 -0700114static clib_error_t *
115pipe_api_hookup (vlib_main_t * vm)
116{
Neale Ranns17ff3c12018-07-04 10:24:24 -0700117 /*
118 * Set up the (msg_name, crc, message-id) table
119 */
Filip Tehlar36d5c972021-06-22 11:28:25 +0000120 REPLY_MSG_ID_BASE = setup_message_id_table ();
Neale Ranns17ff3c12018-07-04 10:24:24 -0700121
122 return 0;
123}
124
125VLIB_API_INIT_FUNCTION (pipe_api_hookup);
126
127/*
128 * fd.io coding-style-patch-verification: ON
129 *
130 * Local Variables:
131 * eval: (c-set-style "gnu")
132 * End:
133 */