2 * Copyright (c) 2015 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.
17 #include <vlibapi/api.h>
18 #include <vlibmemory/api.h>
19 #include <vppinfra/error.h>
21 #include <vnet/ip/ip.h>
22 #include <vnet/ip/ip_format_fns.h>
23 #include <vnet/ethernet/ethernet_format_fns.h>
25 /* define message IDs */
26 #include <lldp/lldp.api_enum.h>
27 #include <lldp/lldp.api_types.h>
31 /* API message ID base */
36 lldp_test_main_t lldp_test_main;
38 #define __plugin_msg_base lldp_test_main.msg_id_base
39 #include <vlibapi/vat_helper_macros.h>
41 /* Macro to finish up custom dump fns */
42 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
45 vl_print (handle, (char *)s); \
50 api_lldp_config (vat_main_t * vam)
52 unformat_input_t *i = vam->input;
53 vl_api_lldp_config_t *mp;
59 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
61 if (unformat (i, "system-name %s", &sys_name))
63 else if (unformat (i, "tx-hold %d", &tx_hold))
65 else if (unformat (i, "tx-interval %d", &tx_interval))
69 clib_warning ("parse error '%U'", format_unformat_error, i);
74 vec_add1 (sys_name, 0);
77 mp->tx_hold = htonl (tx_hold);
78 mp->tx_interval = htonl (tx_interval);
79 vl_api_vec_to_api_string (sys_name, &mp->system_name);
88 api_sw_interface_set_lldp (vat_main_t * vam)
90 unformat_input_t *i = vam->input;
91 vl_api_sw_interface_set_lldp_t *mp;
94 u8 *port_desc = NULL, *mgmt_oid = NULL;
95 ip4_address_t ip4_addr;
96 ip6_address_t ip6_addr;
99 clib_memset (&ip4_addr, 0, sizeof (ip4_addr));
100 clib_memset (&ip6_addr, 0, sizeof (ip6_addr));
102 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
104 if (unformat (i, "disable"))
107 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
109 else if (unformat (i, "sw_if_index %d", &sw_if_index))
111 else if (unformat (i, "port-desc %s", &port_desc))
113 else if (unformat (i, "mgmt-ip4 %U", unformat_ip4_address, &ip4_addr))
115 else if (unformat (i, "mgmt-ip6 %U", unformat_ip6_address, &ip6_addr))
117 else if (unformat (i, "mgmt-oid %s", &mgmt_oid))
123 if (sw_if_index == ~0)
125 errmsg ("missing interface name or sw_if_index");
129 /* Construct the API message */
130 vec_add1 (port_desc, 0);
131 vec_add1 (mgmt_oid, 0);
132 M (SW_INTERFACE_SET_LLDP, mp);
133 mp->sw_if_index = ntohl (sw_if_index);
135 vl_api_vec_to_api_string (port_desc, &mp->port_desc);
136 clib_memcpy (mp->mgmt_oid, mgmt_oid, vec_len (mgmt_oid));
137 clib_memcpy (mp->mgmt_ip4, &ip4_addr, sizeof (ip4_addr));
138 clib_memcpy (mp->mgmt_ip6, &ip6_addr, sizeof (ip6_addr));
139 vec_free (port_desc);
147 #include <lldp/lldp.api_test.c>