Pavel Kotucek | 3a2a1c4 | 2016-12-06 10:10:10 +0100 | [diff] [blame] | 1 | /* |
| 2 | *------------------------------------------------------------------ |
| 3 | * span_api.c - span mirroring api |
| 4 | * |
| 5 | * Copyright (c) 2016 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/span/span.h> |
| 26 | |
Filip Tehlar | 6f6663f | 2021-06-22 22:22:58 +0000 | [diff] [blame] | 27 | #include <vnet/format_fns.h> |
| 28 | #include <vnet/span/span.api_enum.h> |
| 29 | #include <vnet/span/span.api_types.h> |
Pavel Kotucek | 3a2a1c4 | 2016-12-06 10:10:10 +0100 | [diff] [blame] | 30 | |
Filip Tehlar | 6f6663f | 2021-06-22 22:22:58 +0000 | [diff] [blame] | 31 | #define REPLY_MSG_ID_BASE span_main.msg_id_base |
Pavel Kotucek | 3a2a1c4 | 2016-12-06 10:10:10 +0100 | [diff] [blame] | 32 | #include <vlibapi/api_helper_macros.h> |
| 33 | |
Pavel Kotucek | 3a2a1c4 | 2016-12-06 10:10:10 +0100 | [diff] [blame] | 34 | static void |
| 35 | vl_api_sw_interface_span_enable_disable_t_handler |
| 36 | (vl_api_sw_interface_span_enable_disable_t * mp) |
| 37 | { |
| 38 | vl_api_sw_interface_span_enable_disable_reply_t *rmp; |
| 39 | int rv; |
| 40 | |
| 41 | vlib_main_t *vm = vlib_get_main (); |
| 42 | |
| 43 | rv = span_add_delete_entry (vm, ntohl (mp->sw_if_index_from), |
Jakub Grajciar | 908965d | 2020-01-31 09:51:41 +0100 | [diff] [blame] | 44 | ntohl (mp->sw_if_index_to), ntohl (mp->state), |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 45 | mp->is_l2 ? SPAN_FEAT_L2 : SPAN_FEAT_DEVICE); |
Pavel Kotucek | 3a2a1c4 | 2016-12-06 10:10:10 +0100 | [diff] [blame] | 46 | |
| 47 | REPLY_MACRO (VL_API_SW_INTERFACE_SPAN_ENABLE_DISABLE_REPLY); |
| 48 | } |
| 49 | |
| 50 | static void |
| 51 | vl_api_sw_interface_span_dump_t_handler (vl_api_sw_interface_span_dump_t * mp) |
| 52 | { |
| 53 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 54 | vl_api_registration_t *reg; |
Pavel Kotucek | 3a2a1c4 | 2016-12-06 10:10:10 +0100 | [diff] [blame] | 55 | span_interface_t *si; |
| 56 | vl_api_sw_interface_span_details_t *rmp; |
| 57 | span_main_t *sm = &span_main; |
| 58 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 59 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 60 | if (!reg) |
Pavel Kotucek | 3a2a1c4 | 2016-12-06 10:10:10 +0100 | [diff] [blame] | 61 | return; |
| 62 | |
Eyal Bari | 5b31120 | 2017-07-31 13:12:30 +0300 | [diff] [blame] | 63 | span_feat_t sf = mp->is_l2 ? SPAN_FEAT_L2 : SPAN_FEAT_DEVICE; |
Pavel Kotucek | 3a2a1c4 | 2016-12-06 10:10:10 +0100 | [diff] [blame] | 64 | /* *INDENT-OFF* */ |
| 65 | vec_foreach (si, sm->interfaces) |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 66 | { |
Eyal Bari | 5b31120 | 2017-07-31 13:12:30 +0300 | [diff] [blame] | 67 | span_mirror_t * rxm = &si->mirror_rxtx[sf][VLIB_RX]; |
| 68 | span_mirror_t * txm = &si->mirror_rxtx[sf][VLIB_TX]; |
| 69 | if (rxm->num_mirror_ports || txm->num_mirror_ports) |
Pavel Kotucek | 3a2a1c4 | 2016-12-06 10:10:10 +0100 | [diff] [blame] | 70 | { |
| 71 | clib_bitmap_t *b; |
| 72 | u32 i; |
Eyal Bari | 5b31120 | 2017-07-31 13:12:30 +0300 | [diff] [blame] | 73 | b = clib_bitmap_dup_or (rxm->mirror_ports, txm->mirror_ports); |
Damjan Marion | f0ca1e8 | 2020-12-13 23:26:56 +0100 | [diff] [blame] | 74 | clib_bitmap_foreach (i, b) |
Pavel Kotucek | 3a2a1c4 | 2016-12-06 10:10:10 +0100 | [diff] [blame] | 75 | { |
| 76 | rmp = vl_msg_api_alloc (sizeof (*rmp)); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 77 | clib_memset (rmp, 0, sizeof (*rmp)); |
Filip Tehlar | 6f6663f | 2021-06-22 22:22:58 +0000 | [diff] [blame] | 78 | rmp->_vl_msg_id = |
| 79 | ntohs (REPLY_MSG_ID_BASE + VL_API_SW_INTERFACE_SPAN_DETAILS); |
| 80 | rmp->context = mp->context; |
Pavel Kotucek | 3a2a1c4 | 2016-12-06 10:10:10 +0100 | [diff] [blame] | 81 | |
Filip Tehlar | 6f6663f | 2021-06-22 22:22:58 +0000 | [diff] [blame] | 82 | rmp->sw_if_index_from = htonl (si - sm->interfaces); |
| 83 | rmp->sw_if_index_to = htonl (i); |
| 84 | rmp->state = htonl ((clib_bitmap_get (rxm->mirror_ports, i) + |
| 85 | clib_bitmap_get (txm->mirror_ports, i) * 2)); |
Jon Loeliger | 179ab36 | 2018-03-12 14:50:08 -0500 | [diff] [blame] | 86 | rmp->is_l2 = mp->is_l2; |
Pavel Kotucek | 3a2a1c4 | 2016-12-06 10:10:10 +0100 | [diff] [blame] | 87 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 88 | vl_api_send_msg (reg, (u8 *) rmp); |
Damjan Marion | f0ca1e8 | 2020-12-13 23:26:56 +0100 | [diff] [blame] | 89 | } |
Pavel Kotucek | 3a2a1c4 | 2016-12-06 10:10:10 +0100 | [diff] [blame] | 90 | clib_bitmap_free (b); |
| 91 | } |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 92 | } |
Pavel Kotucek | 3a2a1c4 | 2016-12-06 10:10:10 +0100 | [diff] [blame] | 93 | /* *INDENT-ON* */ |
| 94 | } |
| 95 | |
Filip Tehlar | 6f6663f | 2021-06-22 22:22:58 +0000 | [diff] [blame] | 96 | #include <vnet/span/span.api.c> |
Pavel Kotucek | 3a2a1c4 | 2016-12-06 10:10:10 +0100 | [diff] [blame] | 97 | static clib_error_t * |
| 98 | span_api_hookup (vlib_main_t * vm) |
| 99 | { |
Pavel Kotucek | 3a2a1c4 | 2016-12-06 10:10:10 +0100 | [diff] [blame] | 100 | /* |
| 101 | * Set up the (msg_name, crc, message-id) table |
| 102 | */ |
Filip Tehlar | 6f6663f | 2021-06-22 22:22:58 +0000 | [diff] [blame] | 103 | REPLY_MSG_ID_BASE = setup_message_id_table (); |
Pavel Kotucek | 3a2a1c4 | 2016-12-06 10:10:10 +0100 | [diff] [blame] | 104 | |
| 105 | return 0; |
| 106 | } |
| 107 | |
| 108 | VLIB_API_INIT_FUNCTION (span_api_hookup); |
| 109 | |
| 110 | /* |
| 111 | * fd.io coding-style-patch-verification: ON |
| 112 | * |
| 113 | * Local Variables: |
| 114 | * eval: (c-set-style "gnu") |
| 115 | * End: |
| 116 | */ |