Line data Source code
1 : /*
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:
6 : *
7 : * http://www.apache.org/licenses/LICENSE-2.0
8 : *
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.
14 : */
15 :
16 : #include <vat/vat.h>
17 : #include <vlibapi/api.h>
18 : #include <vlibmemory/api.h>
19 : #include <vppinfra/error.h>
20 :
21 : #include <vnet/ip/ip.h>
22 : #include <vnet/ip/ip_format_fns.h>
23 : #include <vnet/ethernet/ethernet_format_fns.h>
24 :
25 : /* define message IDs */
26 : #include <lldp/lldp.api_enum.h>
27 : #include <lldp/lldp.api_types.h>
28 :
29 : typedef struct
30 : {
31 : /* API message ID base */
32 : u16 msg_id_base;
33 : vat_main_t *vat_main;
34 : } lldp_test_main_t;
35 :
36 : lldp_test_main_t lldp_test_main;
37 :
38 : #define __plugin_msg_base lldp_test_main.msg_id_base
39 : #include <vlibapi/vat_helper_macros.h>
40 :
41 : #define FINISH \
42 : vec_add1 (s, 0); \
43 : vlib_cli_output (handle, (char *) s); \
44 : vec_free (s); \
45 : return handle;
46 :
47 : static int
48 0 : api_lldp_config (vat_main_t * vam)
49 : {
50 0 : unformat_input_t *i = vam->input;
51 : vl_api_lldp_config_t *mp;
52 0 : int tx_hold = 0;
53 0 : int tx_interval = 0;
54 0 : u8 *sys_name = NULL;
55 : int ret;
56 :
57 0 : while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
58 : {
59 0 : if (unformat (i, "system-name %s", &sys_name))
60 : ;
61 0 : else if (unformat (i, "tx-hold %d", &tx_hold))
62 : ;
63 0 : else if (unformat (i, "tx-interval %d", &tx_interval))
64 : ;
65 : else
66 : {
67 0 : clib_warning ("parse error '%U'", format_unformat_error, i);
68 0 : return -99;
69 : }
70 : }
71 :
72 0 : vec_add1 (sys_name, 0);
73 :
74 0 : M (LLDP_CONFIG, mp);
75 0 : mp->tx_hold = htonl (tx_hold);
76 0 : mp->tx_interval = htonl (tx_interval);
77 0 : vl_api_vec_to_api_string (sys_name, &mp->system_name);
78 0 : vec_free (sys_name);
79 :
80 0 : S (mp);
81 0 : W (ret);
82 0 : return ret;
83 : }
84 :
85 : static int
86 0 : api_sw_interface_set_lldp (vat_main_t * vam)
87 : {
88 0 : unformat_input_t *i = vam->input;
89 : vl_api_sw_interface_set_lldp_t *mp;
90 0 : u32 sw_if_index = ~0;
91 0 : u32 enable = 1;
92 0 : u8 *port_desc = NULL, *mgmt_oid = NULL;
93 : ip4_address_t ip4_addr;
94 : ip6_address_t ip6_addr;
95 : int ret;
96 :
97 0 : clib_memset (&ip4_addr, 0, sizeof (ip4_addr));
98 0 : clib_memset (&ip6_addr, 0, sizeof (ip6_addr));
99 :
100 0 : while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
101 : {
102 0 : if (unformat (i, "disable"))
103 0 : enable = 0;
104 : else
105 0 : if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
106 : ;
107 0 : else if (unformat (i, "sw_if_index %d", &sw_if_index))
108 : ;
109 0 : else if (unformat (i, "port-desc %s", &port_desc))
110 : ;
111 0 : else if (unformat (i, "mgmt-ip4 %U", unformat_ip4_address, &ip4_addr))
112 : ;
113 0 : else if (unformat (i, "mgmt-ip6 %U", unformat_ip6_address, &ip6_addr))
114 : ;
115 0 : else if (unformat (i, "mgmt-oid %s", &mgmt_oid))
116 : ;
117 : else
118 0 : break;
119 : }
120 :
121 0 : if (sw_if_index == ~0)
122 : {
123 0 : errmsg ("missing interface name or sw_if_index");
124 0 : return -99;
125 : }
126 :
127 : /* Construct the API message */
128 0 : vec_add1 (port_desc, 0);
129 0 : vec_add1 (mgmt_oid, 0);
130 0 : M (SW_INTERFACE_SET_LLDP, mp);
131 0 : mp->sw_if_index = ntohl (sw_if_index);
132 0 : mp->enable = enable;
133 0 : vl_api_vec_to_api_string (port_desc, &mp->port_desc);
134 0 : clib_memcpy (mp->mgmt_oid, mgmt_oid, vec_len (mgmt_oid));
135 0 : clib_memcpy (mp->mgmt_ip4, &ip4_addr, sizeof (ip4_addr));
136 0 : clib_memcpy (mp->mgmt_ip6, &ip6_addr, sizeof (ip6_addr));
137 0 : vec_free (port_desc);
138 0 : vec_free (mgmt_oid);
139 :
140 0 : S (mp);
141 0 : W (ret);
142 0 : return ret;
143 : }
144 :
145 : #include <lldp/lldp.api_test.c>
|