2 *------------------------------------------------------------------
3 * Copyright (c) 2016 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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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 *------------------------------------------------------------------
18 #include <vlib/vlib.h>
19 #include <vlib/unix/unix.h>
20 #include <vnet/ethernet/ethernet.h>
22 #include <vnet/devices/netmap/netmap.h>
25 netmap_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
26 vlib_cli_command_t * cmd)
28 unformat_input_t _line_input, * line_input = &_line_input;
29 u8 * host_if_name = NULL;
36 /* Get a line of input. */
37 if (! unformat_user (input, unformat_line_input, line_input))
40 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
42 if (unformat (line_input, "name %s", &host_if_name))
44 else if (unformat (line_input, "hw-addr %U", unformat_ethernet_address, hwaddr))
46 else if (unformat (line_input, "pipe"))
48 else if (unformat (line_input, "master"))
50 else if (unformat (line_input, "slave"))
53 return clib_error_return (0, "unknown input `%U'", format_unformat_error, input);
55 unformat_free (line_input);
57 if (host_if_name == NULL)
58 return clib_error_return (0, "missing host interface name");
60 r = netmap_create_if(vm, host_if_name, hw_addr_ptr, is_pipe, is_master);
62 if (r == VNET_API_ERROR_SYSCALL_ERROR_1)
63 return clib_error_return(0, "%s (errno %d)", strerror (errno), errno);
65 if (r == VNET_API_ERROR_INVALID_INTERFACE)
66 return clib_error_return(0, "Invalid interface name");
68 if (r == VNET_API_ERROR_SUBIF_ALREADY_EXISTS)
69 return clib_error_return(0, "Interface already exists");
74 VLIB_CLI_COMMAND (netmap_create_command, static) = {
75 .path = "create netmap",
76 .short_help = "create netmap name [<intf name>|valeXXX:YYY] "
77 "[hw-addr <mac>] [pipe] [master|slave]",
78 .function = netmap_create_command_fn,
82 netmap_delete_command_fn (vlib_main_t * vm, unformat_input_t * input,
83 vlib_cli_command_t * cmd)
85 unformat_input_t _line_input, * line_input = &_line_input;
86 u8 * host_if_name = NULL;
88 /* Get a line of input. */
89 if (! unformat_user (input, unformat_line_input, line_input))
92 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
94 if (unformat (line_input, "name %s", &host_if_name))
97 return clib_error_return (0, "unknown input `%U'", format_unformat_error, input);
99 unformat_free (line_input);
101 if (host_if_name == NULL)
102 return clib_error_return (0, "missing host interface name");
104 netmap_delete_if(vm, host_if_name);
109 VLIB_CLI_COMMAND (netmap_delete_command, static) = {
110 .path = "delete netmap",
111 .short_help = "delete netmap name <interface name>",
112 .function = netmap_delete_command_fn,
116 netmap_cli_init (vlib_main_t * vm)
121 VLIB_INIT_FUNCTION (netmap_cli_init);