Line data Source code
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 31 : #include <vlibapi/api_helper_macros.h> 32 : 33 : /* Action function shared between message handler and debug CLI */ 34 : 35 : int 36 4 : cdp_enable_disable (cdp_main_t * cm, int enable_disable) 37 : { 38 4 : int rv = 0; 39 : 40 4 : if (enable_disable) 41 : { 42 4 : vnet_cdp_create_periodic_process (cm); 43 4 : vlib_process_signal_event (cm->vlib_main, cm->cdp_process_node_index, 44 : CDP_EVENT_ENABLE, 0); 45 : } 46 : else 47 : { 48 0 : vnet_cdp_create_periodic_process (cm); 49 0 : vlib_process_signal_event (cm->vlib_main, cm->cdp_process_node_index, 50 : CDP_EVENT_DISABLE, 0); 51 : } 52 4 : cm->enabled = enable_disable; 53 : 54 4 : return rv; 55 : } 56 : 57 : static clib_error_t * 58 0 : cdp_command_fn (vlib_main_t * vm, 59 : unformat_input_t * input, vlib_cli_command_t * cmd) 60 : { 61 0 : cdp_main_t *cm = &cdp_main; 62 0 : int enable_disable = 1; 63 : 64 : int rv; 65 : 66 0 : while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) 67 : { 68 0 : if (unformat (input, "disable")) 69 0 : enable_disable = 0; 70 0 : else if (unformat (input, "enable")) 71 0 : enable_disable = 1; 72 : else 73 0 : break; 74 : } 75 : 76 0 : rv = cdp_enable_disable (cm, enable_disable); 77 : 78 0 : switch (rv) 79 : { 80 0 : case 0: 81 0 : break; 82 : 83 0 : default: 84 0 : return clib_error_return (0, "cdp_enable_disable returned %d", rv); 85 : } 86 0 : return 0; 87 : } 88 : 89 : /* *INDENT-OFF* */ 90 252167 : VLIB_CLI_COMMAND (cdp_command, static) = 91 : { 92 : .path = "cdp", 93 : .short_help = "cdp enable | disable", 94 : .function = cdp_command_fn, 95 : }; 96 : /* *INDENT-ON* */ 97 : 98 : /* API message handler */ 99 4 : static void vl_api_cdp_enable_disable_t_handler 100 : (vl_api_cdp_enable_disable_t * mp) 101 : { 102 : vl_api_cdp_enable_disable_reply_t *rmp; 103 4 : cdp_main_t *cm = &cdp_main; 104 : int rv; 105 : 106 4 : rv = cdp_enable_disable (cm, (int) (mp->enable_disable)); 107 : 108 4 : REPLY_MACRO (VL_API_CDP_ENABLE_DISABLE_REPLY); 109 : } 110 : 111 : #include <cdp/cdp.api.c> 112 : static clib_error_t * 113 559 : cdp_init (vlib_main_t * vm) 114 : { 115 559 : cdp_main_t *cm = &cdp_main; 116 : 117 559 : cm->vlib_main = vm; 118 : 119 : /* Ask for a correctly-sized block of API message decode slots */ 120 559 : cm->msg_id_base = setup_message_id_table (); 121 : 122 559 : return 0; 123 : } 124 : 125 1119 : VLIB_INIT_FUNCTION (cdp_init); 126 : 127 : /* *INDENT-OFF* */ 128 : VLIB_PLUGIN_REGISTER () = 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 : */