Skip to content

Commit df87f80

Browse files
Ole TroanNeale Ranns
authored andcommitted
api: vat2 and json autogeneration for api messages
VAT2: A completely auto-generated replacement of VAT. Reads input message in JSON from stdin and outputs received messages in JSON. A VAT2 plugin is automatically built for a .api file. There no longer a need for a separate _test.c. Example: vat2 show_version {} { "_msgname": "show_version_reply", "retval": 0, "program": "vpe", "version": "21.01-rc0~411-gf6eb348a6", "build_date": "2020-11-19T09:49:25", "build_directory": "/vpp/autogen3" } vat2 sw_interface_dump '{"sw_if_index": -1, "name_filter_valid": 0, "name_filter": ""}' [{ "_msgname": "sw_interface_details", "sw_if_index": 0, "sup_sw_if_index": 0, "l2_address": "00:00:00:00:00:00", "flags": "Invalid ENUM", "type": "IF_API_TYPE_HARDWARE", "link_duplex": "LINK_DUPLEX_API_UNKNOWN", "link_speed": 0, "link_mtu": 0, "mtu": [0, 0, 0, 0], "sub_id": 0, "sub_number_of_tags": 0, "sub_outer_vlan_id": 0, "sub_inner_vlan_id": 0, "sub_if_flags": "Invalid ENUM", "vtr_op": 0, "vtr_push_dot1q": 0, "vtr_tag1": 0, "vtr_tag2": 0, "outer_tag": 0, "b_dmac": "00:00:00:00:00:00", "b_smac": "00:00:00:00:00:00", "b_vlanid": 0, "i_sid": 0, "interface_name": "local0", "interface_dev_type": "local", "tag": "" }] This is the first phase and vat2 is not integrated in packaging yet. Type: feature Signed-off-by: Ole Troan <ot@cisco.com> Change-Id: Ib45ddeafb180ea7da8c5dc274a9274d7a4edc876 Signed-off-by: Ole Troan <ot@cisco.com>
1 parent c95cfa2 commit df87f80

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+6021
-1473
lines changed

extras/rpm/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ SPEC_FILE='vpp.spec'
3030

3131
spec:
3232
@echo $(TARBALL)
33-
mkdir -p $(RPMBUILD)/{RPMS,SRPMS,BUILD,SOURCES,SPECS}
33+
mkdir -p $(RPMBUILD)/RPMS $(RPMBUILD)/SRPMS $(RPMBUILD)/BUILD \
34+
$(RPMBUILD)/SOURCES $(RPMBUILD)/SPECS
3435
cp $(TARBALL) $(RPMBUILD)/SOURCES/vpp-$(VERSION)-$(RELEASE).tar.xz
3536
cp $(SPEC_FILE) $(RPMBUILD)/SPECS
3637

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ if(VPP_HOST_TOOLS_ONLY)
164164
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
165165
find_package(OpenSSL REQUIRED)
166166
set(SUBDIRS
167-
vppinfra svm vlib vlibmemory vlibapi vnet vpp vat vcl plugins
167+
vppinfra svm vlib vlibmemory vlibapi vnet vpp vat vat2 vcl plugins
168168
vpp-api tools/vppapigen tools/g2 tools/perftool cmake pkg
169169
tools/appimage
170170
)

src/cmake/api.cmake

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,32 @@ function(vpp_generate_api_c_header file)
2323
if (VPP_INCLUDE_DIR)
2424
set(includedir "--includedir" ${VPP_INCLUDE_DIR})
2525
endif()
26-
add_custom_command (OUTPUT ${output_name}
26+
27+
set(OUTPUT_HEADERS
28+
"${CMAKE_CURRENT_BINARY_DIR}/${file}.h"
29+
"${CMAKE_CURRENT_BINARY_DIR}/${file}_fromjson.h"
30+
"${CMAKE_CURRENT_BINARY_DIR}/${file}_tojson.h"
31+
"${CMAKE_CURRENT_BINARY_DIR}/${file}_enum.h"
32+
"${CMAKE_CURRENT_BINARY_DIR}/${file}_types.h"
33+
"${CMAKE_CURRENT_BINARY_DIR}/${file}.c"
34+
"${CMAKE_CURRENT_BINARY_DIR}/${file}_test.c"
35+
"${CMAKE_CURRENT_BINARY_DIR}/${file}_test2.c"
36+
)
37+
38+
add_custom_command (
39+
OUTPUT ${OUTPUT_HEADERS}
2740
COMMAND mkdir -p ${output_dir}
2841
COMMAND ${VPP_APIGEN}
2942
ARGS ${includedir} --includedir ${CMAKE_SOURCE_DIR} --input ${CMAKE_CURRENT_SOURCE_DIR}/${file} --outputdir ${output_dir} --output ${output_name}
3043
DEPENDS ${VPP_APIGEN} ${CMAKE_CURRENT_SOURCE_DIR}/${file}
3144
COMMENT "Generating API header ${output_name}"
3245
)
46+
get_filename_component(barename ${file} NAME)
47+
set(t ${barename}_deps)
48+
if (NOT TARGET ${t})
49+
add_custom_target(${t} ALL DEPENDS ${OUTPUT_HEADERS})
50+
add_dependencies(api_headers ${t})
51+
endif()
3352
endfunction()
3453

3554
function(vpp_generate_api_json_header file dir component)

src/cmake/library.cmake

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ macro(add_vpp_library lib)
5757
FILES ${file} ${CMAKE_CURRENT_BINARY_DIR}/${file}.h
5858
${CMAKE_CURRENT_BINARY_DIR}/${file}_enum.h
5959
${CMAKE_CURRENT_BINARY_DIR}/${file}_types.h
60+
${CMAKE_CURRENT_BINARY_DIR}/${file}_tojson.h
61+
${CMAKE_CURRENT_BINARY_DIR}/${file}_fromjson.h
6062
DESTINATION include/${lib}/${dir}
6163
COMPONENT vpp-dev
6264
)
@@ -93,3 +95,33 @@ function (add_vpp_headers path)
9395
)
9496
endforeach()
9597
endfunction()
98+
99+
macro(add_vpp_test_library lib)
100+
cmake_parse_arguments(TEST
101+
""
102+
""
103+
${ARGN}
104+
)
105+
106+
foreach(file ${ARGN})
107+
get_filename_component(name ${file} NAME_WE)
108+
set(test_lib ${lib}_${name}_plugin)
109+
add_library(${test_lib} SHARED ${file}_test2.c)
110+
if(NOT VPP_EXTERNAL_PROJECT)
111+
add_dependencies(${test_lib} api_headers)
112+
endif()
113+
include_directories(${CMAKE_CURRENT_BINARY_DIR})
114+
set_target_properties(${test_lib} PROPERTIES NO_SONAME 1)
115+
set_target_properties(${test_lib} PROPERTIES
116+
PREFIX ""
117+
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/vat2_plugins)
118+
119+
# Later: Install and package
120+
# install .so
121+
#install(
122+
# TARGETS ${test_lib}
123+
# DESTINATION ${VPP_LIBRARY_DIR}/vat2_plugins
124+
# #COMPONENT ${ARG_COMPONENT}
125+
# )
126+
endforeach()
127+
endmacro()

src/cmake/plugin.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ macro(add_vpp_plugin name)
1515
cmake_parse_arguments(PLUGIN
1616
""
1717
"LINK_FLAGS;COMPONENT;DEV_COMPONENT"
18-
"SOURCES;API_FILES;MULTIARCH_SOURCES;LINK_LIBRARIES;INSTALL_HEADERS;API_TEST_SOURCES"
18+
"SOURCES;API_FILES;MULTIARCH_SOURCES;LINK_LIBRARIES;INSTALL_HEADERS;API_TEST_SOURCES;"
1919
${ARGN}
2020
)
2121
set(plugin_name ${name}_plugin)
@@ -99,6 +99,10 @@ macro(add_vpp_plugin name)
9999
COMPONENT ${PLUGIN_COMPONENT}
100100
)
101101
endif()
102+
if (PLUGIN_API_FILES)
103+
add_vpp_test_library(${name}_test_plugin ${PLUGIN_API_FILES})
104+
endif()
105+
102106
install(
103107
TARGETS ${plugin_name}
104108
DESTINATION ${VPP_LIBRARY_DIR}/vpp_plugins

src/plugins/acl/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,4 @@ add_vpp_plugin(acl
3030

3131
API_TEST_SOURCES
3232
acl_test.c
33-
34-
INSTALL_HEADERS
35-
manual_fns.h
3633
)

src/plugins/acl/acl.api

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ define acl_plugin_get_conn_table_max_entries_reply
102102
@r - Rules for this access-list
103103
*/
104104

105-
manual_print manual_endian define acl_add_replace
105+
define acl_add_replace
106106
{
107107
u32 client_index;
108108
u32 context;
@@ -132,7 +132,7 @@ define acl_add_replace_reply
132132
@param acl_index - ACL index to delete
133133
*/
134134

135-
autoreply manual_print define acl_del
135+
autoreply define acl_del
136136
{
137137
u32 client_index;
138138
u32 context;
@@ -151,7 +151,7 @@ autoreply manual_print define acl_del
151151
@param acl_index - index of ACL for the operation
152152
*/
153153

154-
autoreply manual_print define acl_interface_add_del
154+
autoreply define acl_interface_add_del
155155
{
156156
u32 client_index;
157157
u32 context;
@@ -175,7 +175,7 @@ autoreply manual_print define acl_interface_add_del
175175
@param acls - vector of ACL indices
176176
*/
177177

178-
autoreply manual_print define acl_interface_set_acl_list
178+
autoreply define acl_interface_set_acl_list
179179
{
180180
u32 client_index;
181181
u32 context;
@@ -213,7 +213,7 @@ define acl_dump
213213
@param r - Array of rules within this ACL
214214
*/
215215

216-
manual_endian manual_print define acl_details
216+
define acl_details
217217
{
218218
u32 context;
219219
u32 acl_index;
@@ -261,7 +261,7 @@ define acl_interface_list_details
261261
@param r - vector of MACIP ACL rules
262262
*/
263263

264-
manual_endian manual_print define macip_acl_add
264+
define macip_acl_add
265265
{
266266
u32 client_index;
267267
u32 context;
@@ -293,7 +293,7 @@ define macip_acl_add_reply
293293
@param r - vector of MACIP ACL rules
294294
*/
295295

296-
manual_endian manual_print define macip_acl_add_replace
296+
define macip_acl_add_replace
297297
{
298298
u32 client_index;
299299
u32 context;
@@ -323,7 +323,7 @@ define macip_acl_add_replace_reply
323323
@param acl_index - MACIP ACL index to delete
324324
*/
325325

326-
autoreply manual_print define macip_acl_del
326+
autoreply define macip_acl_del
327327
{
328328
u32 client_index;
329329
u32 context;
@@ -339,7 +339,7 @@ autoreply manual_print define macip_acl_del
339339
@param acl_index - MACIP ACL index
340340
*/
341341

342-
autoreply manual_print define macip_acl_interface_add_del
342+
autoreply define macip_acl_interface_add_del
343343
{
344344
u32 client_index;
345345
u32 context;
@@ -372,7 +372,7 @@ define macip_acl_dump
372372
@param r - rules comprising this MACIP ACL
373373
*/
374374

375-
manual_endian manual_print define macip_acl_details
375+
define macip_acl_details
376376
{
377377
u32 context;
378378
u32 acl_index;
@@ -442,7 +442,7 @@ define macip_acl_interface_list_details
442442
@param whitelist - vector of whitelisted ethertypes
443443
*/
444444

445-
autoreply manual_print define acl_interface_set_etype_whitelist
445+
autoreply define acl_interface_set_etype_whitelist
446446
{
447447
u32 client_index;
448448
u32 context;

src/plugins/acl/acl.c

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
#include <vpp/app/version.h>
2626

2727
#include <vnet/ethernet/ethernet_types_api.h>
28+
#include <vnet/ip/format.h>
29+
#include <vnet/ethernet/ethernet.h>
30+
#include <vnet/ip/ip_types_api.h>
2831

2932
#include <vlibapi/api.h>
3033
#include <vlibmemory/api.h>
@@ -34,7 +37,6 @@
3437
#include <acl/acl.api_types.h>
3538

3639
#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
37-
#include "manual_fns.h"
3840

3941
#include "fa_node.h"
4042
#include "public_inlines.h"
@@ -132,6 +134,26 @@ print_cli_and_reset (vlib_main_t * vm, u8 * out0)
132134

133135
typedef void (*acl_vector_print_func_t) (vlib_main_t * vm, u8 * out0);
134136

137+
static inline u8 *
138+
format_acl_action (u8 * s, u8 action)
139+
{
140+
switch (action)
141+
{
142+
case 0:
143+
s = format (s, "deny");
144+
break;
145+
case 1:
146+
s = format (s, "permit");
147+
break;
148+
case 2:
149+
s = format (s, "permit+reflect");
150+
break;
151+
default:
152+
s = format (s, "action %d", action);
153+
}
154+
return (s);
155+
}
156+
135157
static void
136158
acl_print_acl_x (acl_vector_print_func_t vpr, vlib_main_t * vm,
137159
acl_main_t * am, int acl_index)
@@ -629,16 +651,16 @@ acl_interface_set_inout_acl_list (acl_main_t * am, u32 sw_if_index,
629651

630652

631653
u32 **pinout_lc_index_by_sw_if_index =
632-
is_input ? &am->
633-
input_lc_index_by_sw_if_index : &am->output_lc_index_by_sw_if_index;
654+
is_input ? &am->input_lc_index_by_sw_if_index : &am->
655+
output_lc_index_by_sw_if_index;
634656

635657
u32 ***pinout_acl_vec_by_sw_if_index =
636-
is_input ? &am->
637-
input_acl_vec_by_sw_if_index : &am->output_acl_vec_by_sw_if_index;
658+
is_input ? &am->input_acl_vec_by_sw_if_index : &am->
659+
output_acl_vec_by_sw_if_index;
638660

639661
u32 ***pinout_sw_if_index_vec_by_acl =
640-
is_input ? &am->
641-
input_sw_if_index_vec_by_acl : &am->output_sw_if_index_vec_by_acl;
662+
is_input ? &am->input_sw_if_index_vec_by_acl : &am->
663+
output_sw_if_index_vec_by_acl;
642664

643665
vec_validate ((*pinout_acl_vec_by_sw_if_index), sw_if_index);
644666

@@ -713,7 +735,9 @@ acl_interface_set_inout_acl_list (acl_main_t * am, u32 sw_if_index,
713735
{
714736
if (~0 != (*pinout_lc_index_by_sw_if_index)[sw_if_index])
715737
{
716-
acl_plugin.put_lookup_context_index ((*pinout_lc_index_by_sw_if_index)[sw_if_index]);
738+
acl_plugin.
739+
put_lookup_context_index ((*pinout_lc_index_by_sw_if_index)
740+
[sw_if_index]);
717741
(*pinout_lc_index_by_sw_if_index)[sw_if_index] = ~0;
718742
}
719743
}
@@ -750,8 +774,8 @@ acl_interface_add_del_inout_acl (u32 sw_if_index, u8 is_add, u8 is_input,
750774
: VNET_API_ERROR_ACL_IN_USE_OUTBOUND;
751775

752776
u32 ***pinout_acl_vec_by_sw_if_index =
753-
is_input ? &am->
754-
input_acl_vec_by_sw_if_index : &am->output_acl_vec_by_sw_if_index;
777+
is_input ? &am->input_acl_vec_by_sw_if_index : &am->
778+
output_acl_vec_by_sw_if_index;
755779
int rv = 0;
756780
if (is_add)
757781
{
@@ -1435,9 +1459,9 @@ macip_create_classify_tables (acl_main_t * am, u32 macip_acl_index)
14351459

14361460
vnet_classify_add_del_session (cm, tag_table,
14371461
mask,
1438-
a->
1439-
rules[i].is_permit ? ~0 : 0,
1440-
i, 0, action, metadata, 1);
1462+
a->rules[i].
1463+
is_permit ? ~0 : 0, i, 0,
1464+
action, metadata, 1);
14411465
}
14421466
}
14431467
}
@@ -2280,7 +2304,8 @@ static void
22802304
if (~0 != am->macip_acl_by_sw_if_index[sw_if_index])
22812305
{
22822306
send_macip_acl_interface_list_details (am, reg, sw_if_index,
2283-
am->macip_acl_by_sw_if_index
2307+
am->
2308+
macip_acl_by_sw_if_index
22842309
[sw_if_index],
22852310
mp->context);
22862311
}

src/plugins/acl/acl_test.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
3737
#include <acl/acl.api_enum.h>
3838
#include <acl/acl.api_types.h>
3939
#define vl_print(handle, ...)
40-
#include <acl/manual_fns.h>
4140
#undef vl_print
4241
#define vl_endianfun /* define message structures */
4342
#include <acl/acl.api.h>

0 commit comments

Comments
 (0)