FD.io VPP  v17.10-9-gd594711
Vector Packet Processing
lldp_api.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * lldp_api.c - lldp api
4  *
5  * Copyright (c) 2017 Cisco and/or its affiliates.
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at:
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *------------------------------------------------------------------
18  */
19 
20 #include <vnet/vnet.h>
21 #include <vlibmemory/api.h>
22 
23 #include <vnet/interface.h>
24 #include <vnet/api_errno.h>
25 #include <vnet/lldp/lldp.h>
26 
27 #include <vnet/vnet_msg_enum.h>
28 
29 #define vl_typedefs /* define message structures */
30 #include <vnet/vnet_all_api_h.h>
31 #undef vl_typedefs
32 
33 #define vl_endianfun /* define message structures */
34 #include <vnet/vnet_all_api_h.h>
35 #undef vl_endianfun
36 
37 /* instantiate all the print functions we know about */
38 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
39 #define vl_printfun
40 #include <vnet/vnet_all_api_h.h>
41 #undef vl_printfun
42 
44 
45 #define foreach_vpe_api_msg \
46 _(LLDP_CONFIG, lldp_config) \
47 _(SW_INTERFACE_SET_LLDP, sw_interface_set_lldp)
48 
49 static void
51 {
52  vl_api_lldp_config_reply_t *rmp;
53  int rv = 0;
54  u8 *sys_name = 0;
55 
56  vec_validate (sys_name, strlen ((char *) mp->system_name) - 1);
57  strncpy ((char *) sys_name, (char *) mp->system_name, vec_len (sys_name));
58 
59  if (lldp_cfg_set (&sys_name, ntohl (mp->tx_hold),
60  ntohl (mp->tx_interval)) != lldp_ok)
61  {
62  vec_free (sys_name);
63  rv = VNET_API_ERROR_INVALID_VALUE;
64  }
65 
66  REPLY_MACRO (VL_API_LLDP_CONFIG_REPLY);
67 }
68 
69 static void
71 {
72  vl_api_sw_interface_set_lldp_reply_t *rmp;
73  int rv = 0;
74  u8 *port_desc = 0;
75 
76  vec_validate (port_desc, strlen ((char *) mp->port_desc) - 1);
77  strncpy ((char *) port_desc, (char *) mp->port_desc, vec_len (port_desc));
78 
80 
81  if (lldp_cfg_intf_set (ntohl (mp->sw_if_index), &port_desc,
82  mp->enable) != lldp_ok)
83  {
84  vec_free (port_desc);
85  rv = VNET_API_ERROR_INVALID_VALUE;
86  }
87 
89 
90  REPLY_MACRO (VL_API_SW_INTERFACE_SET_LLDP_REPLY);
91 }
92 
93 
94 /*
95  * * lldp_api_hookup
96  * * Add vpe's API message handlers to the table.
97  * * vlib has alread mapped shared memory and
98  * * added the client registration handlers.
99  * * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
100  * */
101 #define vl_msg_name_crc_list
102 #include <vnet/vnet_all_api_h.h>
103 #undef vl_msg_name_crc_list
104 
105 static void
107 {
108 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
109  foreach_vl_msg_name_crc_lldp;
110 #undef _
111 }
112 
113 static clib_error_t *
115 {
116  api_main_t *am = &api_main;
117 
118 #define _(N,n) \
119  vl_msg_api_set_handlers(VL_API_##N, #n, \
120  vl_api_##n##_t_handler, \
121  vl_noop_handler, \
122  vl_api_##n##_t_endian, \
123  vl_api_##n##_t_print, \
124  sizeof(vl_api_##n##_t), 1);
126 #undef _
127 
128  /*
129  * * Set up the (msg_name, crc, message-id) table
130  * */
132 
133  return 0;
134 }
135 
137 
138 /*
139  * fd.io coding-style-patch-verification: ON
140  *
141  * Local Variables:
142  * eval: (c-set-style "gnu")
143  * End:
144  */
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:432
Definition: lldp.h:24
lldp_cfg_err_t lldp_cfg_intf_set(u32 hw_if_index, u8 **port_desc, int enable)
Definition: lldp_cli.c:46
#define foreach_vpe_api_msg
Definition: lldp_api.c:45
VLIB_API_INIT_FUNCTION(lldp_api_hookup)
u8 system_name[256]
Definition: lldp.api:28
#define REPLY_MACRO(t)
LLDP external definition.
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:182
#define BAD_SW_IF_INDEX_LABEL
api_main_t api_main
Definition: api_shared.c:35
static void vl_api_lldp_config_t_handler(vl_api_lldp_config_t *mp)
Definition: lldp_api.c:50
vlib_main_t * vm
Definition: buffer.c:283
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:336
static void vl_api_sw_interface_set_lldp_t_handler(vl_api_sw_interface_set_lldp_t *mp)
Definition: lldp_api.c:70
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
unsigned char u8
Definition: types.h:56
static void setup_message_id_table(api_main_t *am)
Definition: lldp_api.c:106
Interface set LLDP request.
Definition: lldp.api:40
configure global parameter for LLDP
Definition: lldp.api:24
lldp_cfg_err_t lldp_cfg_set(u8 **host, int hold_time, int tx_interval)
Definition: lldp_cli.c:125
static clib_error_t * lldp_api_hookup(vlib_main_t *vm)
Definition: lldp_api.c:114
#define VALIDATE_SW_IF_INDEX(mp)