FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
cdp.c
Go to the documentation of this file.
1 /*
2  * cdp.c - cdp protocol plug-in
3  *
4  * Copyright (c) 2011-2018 by Cisco and/or its affiliates.
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #include <vnet/vnet.h>
19 #include <vnet/plugin/plugin.h>
20 #include <cdp/cdp.h>
21 
22 #include <vlibapi/api.h>
23 #include <vlibmemory/api.h>
24 #include <vpp/app/version.h>
25 
26 /* define message IDs */
27 #include <cdp/cdp.api_enum.h>
28 #include <cdp/cdp.api_types.h>
29 
30 #define REPLY_MSG_ID_BASE cm->msg_id_base
32 
33 /* Action function shared between message handler and debug CLI */
34 
35 int
36 cdp_enable_disable (cdp_main_t * cm, int enable_disable)
37 {
38  int rv = 0;
39 
40  if (enable_disable)
41  {
43  vlib_process_signal_event (cm->vlib_main, cm->cdp_process_node_index,
44  CDP_EVENT_ENABLE, 0);
45  }
46  else
47  {
49  vlib_process_signal_event (cm->vlib_main, cm->cdp_process_node_index,
51  }
52  cm->enabled = enable_disable;
53 
54  return rv;
55 }
56 
57 static clib_error_t *
59  unformat_input_t * input, vlib_cli_command_t * cmd)
60 {
62  int enable_disable = 1;
63 
64  int rv;
65 
67  {
68  if (unformat (input, "disable"))
69  enable_disable = 0;
70  else if (unformat (input, "enable"))
71  enable_disable = 1;
72  else
73  break;
74  }
75 
76  rv = cdp_enable_disable (cm, enable_disable);
77 
78  switch (rv)
79  {
80  case 0:
81  break;
82 
83  default:
84  return clib_error_return (0, "cdp_enable_disable returned %d", rv);
85  }
86  return 0;
87 }
88 
89 /* *INDENT-OFF* */
91 {
92  .path = "cdp",
93  .short_help = "cdp enable | disable",
94  .function = cdp_command_fn,
95 };
96 /* *INDENT-ON* */
97 
98 /* API message handler */
101 {
102  vl_api_cdp_enable_disable_reply_t *rmp;
103  cdp_main_t *cm = &cdp_main;
104  int rv;
105 
106  rv = cdp_enable_disable (cm, (int) (mp->enable_disable));
107 
108  REPLY_MACRO (VL_API_CDP_ENABLE_DISABLE_REPLY);
109 }
110 
111 #include <cdp/cdp.api.c>
112 static clib_error_t *
114 {
115  cdp_main_t *cm = &cdp_main;
116 
117  cm->vlib_main = vm;
118 
119  /* Ask for a correctly-sized block of API message decode slots */
120  cm->msg_id_base = setup_message_id_table ();
121 
122  return 0;
123 }
124 
126 
127 /* *INDENT-OFF* */
129 {
130  .version = VPP_BUILD_VER,
131  .description = "Cisco Discovery Protocol (CDP)",
132 };
133 /* *INDENT-ON* */
134 
135 /*
136  * fd.io coding-style-patch-verification: ON
137  *
138  * Local Variables:
139  * eval: (c-set-style "gnu")
140  * End:
141  */
api.h
clib_error_return
#define clib_error_return(e, args...)
Definition: error.h:99
vlib_cli_command_t::path
char * path
Definition: cli.h:96
cdp_enable_disable
int cdp_enable_disable(cdp_main_t *cm, int enable_disable)
Definition: cdp.c:36
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
api.h
cdp_command
static vlib_cli_command_t cdp_command
(constructor) VLIB_CLI_COMMAND (cdp_command)
Definition: cdp.c:90
cdp_main
cdp_main_t cdp_main
Definition: cdp_input.c:17
unformat_input_t
struct _unformat_input_t unformat_input_t
vlib_process_signal_event
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
Definition: node_funcs.h:1019
cdp_command_fn
static clib_error_t * cdp_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cdp.c:58
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
setup_message_id_table
static void setup_message_id_table(api_main_t *am)
Definition: bfd_api.c:451
CDP_EVENT_ENABLE
@ CDP_EVENT_ENABLE
Definition: cdp.h:137
vl_api_cdp_enable_disable_t
Definition: cdp.api:20
REPLY_MACRO
#define REPLY_MACRO(t)
Definition: api_helper_macros.h:30
unformat_check_input
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:163
CDP_EVENT_DISABLE
@ CDP_EVENT_DISABLE
Definition: cdp.h:138
cdp_init
static clib_error_t * cdp_init(vlib_main_t *vm)
Definition: cdp.c:113
cm
vnet_feature_config_main_t * cm
Definition: nat44_ei_hairpinning.c:591
vl_api_cdp_enable_disable_t_handler
static void vl_api_cdp_enable_disable_t_handler(vl_api_cdp_enable_disable_t *mp)
Definition: cdp.c:100
VLIB_CLI_COMMAND
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:163
vl_api_cdp_enable_disable_t::enable_disable
bool enable_disable
Definition: cdp.api:29
cdp.h
plugin.h
VLIB_PLUGIN_REGISTER
VLIB_PLUGIN_REGISTER()
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
api_helper_macros.h
vlib_main_t
Definition: main.h:102
clib_error_t
Definition: clib_error.h:21
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
rv
int __clib_unused rv
Definition: application.c:491
vnet.h
vnet_cdp_create_periodic_process
void vnet_cdp_create_periodic_process(cdp_main_t *cmp)
Definition: cdp_node.c:201
vlib_cli_command_t
Definition: cli.h:92
cdp_main_t
Definition: cdp.h:79
UNFORMAT_END_OF_INPUT
#define UNFORMAT_END_OF_INPUT
Definition: format.h:137