2 * Copyright (c) 2021 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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
15 #include <vlib/vlib.h>
17 #include <plugins/linux-cp/lcp_interface.h>
20 const static char *host_template = "tap%d";
23 lcp_add_pair_command_fn (vlib_main_t *vm, unformat_input_t *input,
24 vlib_cli_command_t *cmd)
26 u32 phy_sw_if_index, host_sw_if_index;
27 u8 is_add, *host_name;
28 vnet_main_t *vnm = vnet_get_main ();
31 host_name = format (NULL, host_template, host_vif);
32 phy_sw_if_index = host_sw_if_index = ~0;
34 lcp_main.test_mode = 1;
36 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
38 if (unformat (input, "add"))
40 else if (unformat (input, "del"))
42 else if (unformat (input, "phy %U", unformat_vnet_sw_interface, vnm,
45 else if (unformat (input, "host %U", unformat_vnet_sw_interface, vnm,
49 return clib_error_return (0, "unknown input:%U", format_unformat_error,
53 if (phy_sw_if_index == ~0)
54 return clib_error_return (0, "ERROR; no phy:%U", format_unformat_error,
57 lip_host_type_t host_type =
58 (vnet_sw_interface_is_p2p (vnm, phy_sw_if_index) ? LCP_ITF_HOST_TUN :
65 if (host_sw_if_index == ~0)
66 return clib_error_return (0, "ERROR no-host:%U", format_unformat_error,
69 rv = lcp_itf_pair_add (host_sw_if_index, phy_sw_if_index, host_name,
70 host_vif, host_type, NULL);
73 rv = lcp_itf_pair_del (phy_sw_if_index);
76 return clib_error_return (0, "ERROR rv:%d", rv);
81 VLIB_CLI_COMMAND (test_time_range_command, static) = {
83 .short_help = "lcp [add|del] phy <SW_IF_INDEX> host <SW_IF_INDEX>",
84 .function = lcp_add_pair_command_fn,
87 #include <vnet/plugin/plugin.h>
88 #include <vpp/app/version.h>
89 VLIB_PLUGIN_REGISTER () = {
90 .version = VPP_BUILD_VER,
91 .description = "Linux Control Plane - Unit Test",
92 .default_disabled = 1,
96 * fd.io coding-style-patch-verification: ON
99 * eval: (c-set-style "gnu")