FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
span_api.c
Go to the documentation of this file.
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 
27 #include <vnet/format_fns.h>
28 #include <vnet/span/span.api_enum.h>
29 #include <vnet/span/span.api_types.h>
30 
31 #define REPLY_MSG_ID_BASE span_main.msg_id_base
33 
34 static void
37 {
38  vl_api_sw_interface_span_enable_disable_reply_t *rmp;
39  int rv;
40 
42 
44  ntohl (mp->sw_if_index_to), ntohl (mp->state),
46 
47  REPLY_MACRO (VL_API_SW_INTERFACE_SPAN_ENABLE_DISABLE_REPLY);
48 }
49 
50 static void
52 {
53 
57  span_main_t *sm = &span_main;
58 
60  if (!reg)
61  return;
62 
64  /* *INDENT-OFF* */
66  {
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)
70  {
72  u32 i;
75  {
76  rmp = vl_msg_api_alloc (sizeof (*rmp));
77  clib_memset (rmp, 0, sizeof (*rmp));
78  rmp->_vl_msg_id =
79  ntohs (REPLY_MSG_ID_BASE + VL_API_SW_INTERFACE_SPAN_DETAILS);
80  rmp->context = mp->context;
81 
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));
86  rmp->is_l2 = mp->is_l2;
87 
88  vl_api_send_msg (reg, (u8 *) rmp);
89  }
91  }
92  }
93  /* *INDENT-ON* */
94 }
95 
96 #include <vnet/span/span.api.c>
97 static clib_error_t *
99 {
100  /*
101  * Set up the (msg_name, crc, message-id) table
102  */
104 
105  return 0;
106 }
107 
109 
110 /*
111  * fd.io coding-style-patch-verification: ON
112  *
113  * Local Variables:
114  * eval: (c-set-style "gnu")
115  * End:
116  */
vl_api_client_index_to_registration
static vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
Definition: api.h:79
api.h
ntohs
#define ntohs(x)
Definition: af_xdp.bpf.c:29
vl_api_sw_interface_span_details_t
Reply to SPAN dump request.
Definition: span.api:64
vl_api_sw_interface_span_enable_disable_t::sw_if_index_from
vl_api_interface_index_t sw_if_index_from
Definition: span.api:40
vl_api_send_msg
static void vl_api_send_msg(vl_api_registration_t *rp, u8 *elem)
Definition: api.h:35
vl_api_sw_interface_span_dump_t::is_l2
bool is_l2
Definition: span.api:54
clib_bitmap_t
uword clib_bitmap_t
Definition: bitmap.h:50
vl_api_sw_interface_span_enable_disable_t::state
vl_api_span_state_t state
Definition: span.api:42
vl_api_sw_interface_span_details_t::is_l2
bool is_l2
Definition: span.api:69
span_main_t
Definition: span.h:41
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
span_mirror_t::num_mirror_ports
u32 num_mirror_ports
Definition: span.h:33
VLIB_RX
@ VLIB_RX
Definition: defs.h:46
SPAN_FEAT_DEVICE
@ SPAN_FEAT_DEVICE
Definition: span.h:25
span_main
span_main_t span_main
Definition: span.c:24
VLIB_API_INIT_FUNCTION
VLIB_API_INIT_FUNCTION(span_api_hookup)
vl_api_sw_interface_span_enable_disable_t_handler
static void vl_api_sw_interface_span_enable_disable_t_handler(vl_api_sw_interface_span_enable_disable_t *mp)
Definition: span_api.c:36
clib_bitmap_get
static uword clib_bitmap_get(uword *ai, uword i)
Gets the ith bit value from a bitmap.
Definition: bitmap.h:197
vl_api_sw_interface_span_details_t::context
u32 context
Definition: span.api:65
vl_api_sw_interface_span_enable_disable_t::is_l2
bool is_l2
Definition: span.api:43
vl_api_registration_
An API client registration, only in vpp/vlib.
Definition: api_common.h:47
REPLY_MACRO
#define REPLY_MACRO(t)
Definition: api_helper_macros.h:30
setup_message_id_table
static void setup_message_id_table(api_main_t *am)
Definition: sr_mpls_api.c:174
span_mirror_t::mirror_ports
clib_bitmap_t * mirror_ports
Definition: span.h:32
clib_bitmap_free
#define clib_bitmap_free(v)
Free a bitmap.
Definition: bitmap.h:92
span.h
vl_api_sw_interface_span_dump_t::client_index
u32 client_index
Definition: span.api:52
interface.h
span_api_hookup
static clib_error_t * span_api_hookup(vlib_main_t *vm)
Definition: span_api.c:98
vl_api_sw_interface_span_dump_t_handler
static void vl_api_sw_interface_span_dump_t_handler(vl_api_sw_interface_span_dump_t *mp)
Definition: span_api.c:51
format_fns.h
vl_api_sw_interface_span_enable_disable_t::sw_if_index_to
vl_api_interface_index_t sw_if_index_to
Definition: span.api:41
vl_api_sw_interface_span_details_t::state
vl_api_span_state_t state
Definition: span.api:68
SPAN_FEAT_L2
@ SPAN_FEAT_L2
Definition: span.h:26
vl_api_sw_interface_span_dump_t::context
u32 context
Definition: span.api:53
u32
unsigned int u32
Definition: types.h:88
span_add_delete_entry
int span_add_delete_entry(vlib_main_t *vm, u32 src_sw_if_index, u32 dst_sw_if_index, u8 state, span_feat_t sf)
Definition: span.c:52
si
vnet_sw_interface_t * si
Definition: interface_output.c:418
vl_api_sw_interface_span_dump_t
SPAN dump request.
Definition: span.api:51
span_mirror_t
Definition: span.h:30
api_helper_macros.h
vec_foreach
#define vec_foreach(var, vec)
Vector iterator.
Definition: vec_bootstrap.h:213
vl_api_sw_interface_span_details_t::sw_if_index_from
vl_api_interface_index_t sw_if_index_from
Definition: span.api:66
clib_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
vlib_main_t
Definition: main.h:102
vlib_get_main
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:38
b
vlib_buffer_t ** b
Definition: nat44_ei_out2in.c:717
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
vl_api_sw_interface_span_details_t::sw_if_index_to
vl_api_interface_index_t sw_if_index_to
Definition: span.api:67
REPLY_MSG_ID_BASE
#define REPLY_MSG_ID_BASE
Definition: span_api.c:31
i
int i
Definition: flowhash_template.h:376
rv
int __clib_unused rv
Definition: application.c:491
vnet.h
api_errno.h
span_interface_t
Definition: span.h:36
clib_bitmap_foreach
#define clib_bitmap_foreach(i, ai)
Macro to iterate across set bits in a bitmap.
Definition: bitmap.h:361
span_main_t::interfaces
span_interface_t * interfaces
Definition: span.h:48
VLIB_TX
@ VLIB_TX
Definition: defs.h:47
clib_bitmap_dup_or
static uword * clib_bitmap_dup_or(uword *ai, uword *bi)
Logical operator across two bitmaps which duplicates the first bitmap.
vl_api_sw_interface_span_enable_disable_t
Enable/Disable span to mirror traffic from one interface to another.
Definition: span.api:37
vl_msg_api_alloc
void * vl_msg_api_alloc(int nbytes)
Definition: memory_shared.c:199
span_feat_t
span_feat_t
Definition: span.h:23