FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
gbp_scanner.c
Go to the documentation of this file.
1 /*
2  * gbp.h : Group Based Policy
3  *
4  * Copyright (c) 2018 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 
20 #include <plugins/gbp/gbp_vxlan.h>
21 
22 /**
23  * Scanner logger
24  */
26 
27 /**
28  * Scanner state
29  */
30 static bool gs_enabled;
31 
32 #define GBP_SCANNER_DBG(...) \
33  vlib_log_debug (gs_logger, __VA_ARGS__);
34 
35 static uword
37 {
38  uword event_type, *event_data = 0;
39  bool do_scan = 0;
40 
41  while (1)
42  {
43  do_scan = 0;
44 
45  if (gs_enabled)
46  {
47  /* scan every 'inactive threshold' seconds */
49  }
50  else
52 
53  event_type = vlib_process_get_events (vm, &event_data);
54  vec_reset_length (event_data);
55 
56  switch (event_type)
57  {
58  case ~0:
59  /* timer expired */
60  do_scan = 1;
61  break;
62 
64  gs_enabled = 1;
65  break;
66 
68  gs_enabled = 0;
69  break;
70 
72  break;
73 
74  default:
75  ASSERT (0);
76  }
77 
78  if (do_scan)
79  {
80  GBP_SCANNER_DBG ("start");
82  GBP_SCANNER_DBG ("stop");
83  }
84  }
85  return 0;
86 }
87 
88 /* *INDENT-OFF* */
90  .function = gbp_scanner,
91  .type = VLIB_NODE_TYPE_PROCESS,
92  .name = "gbp-scanner",
93 };
94 /* *INDENT-ON* */
95 
96 static clib_error_t *
98  unformat_input_t * input, vlib_cli_command_t * cmd)
99 {
100  vlib_cli_output (vm, "GBP-scanner: enabled:%d interval:2", gs_enabled);
101 
102  return (NULL);
103 }
104 
105 /*?
106  * Show GBP scanner
107  *
108  * @cliexpar
109  * @cliexstart{show gbp scanner}
110  * @cliexend
111  ?*/
112 /* *INDENT-OFF* */
114  .path = "show gbp scanner",
115  .short_help = "show gbp scanner",
116  .function = gbp_scanner_cli,
117 };
118 /* *INDENT-ON* */
119 
120 static clib_error_t *
122 {
123  gs_logger = vlib_log_register_class ("gbp", "scan");
124 
125  return (NULL);
126 }
127 
129 
130 /*
131  * fd.io coding-style-patch-verification: ON
132  *
133  * Local Variables:
134  * eval: (c-set-style "gnu")
135  * End:
136  */
vec_reset_length
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
Definition: vec_bootstrap.h:194
GBP_ENDPOINT_SCAN_STOP
@ GBP_ENDPOINT_SCAN_STOP
Definition: gbp_scanner.h:24
gs_logger
vlib_log_class_t gs_logger
Scanner logger.
Definition: gbp_scanner.c:25
vlib_process_wait_for_event
static uword * vlib_process_wait_for_event(vlib_main_t *vm)
Definition: node_funcs.h:660
f
vlib_frame_t * f
Definition: interface_output.c:1098
gbp_scanner
static uword gbp_scanner(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
Definition: gbp_scanner.c:36
vlib_log_class_t
u32 vlib_log_class_t
Definition: vlib.h:52
vlib_log_register_class
vlib_log_class_t vlib_log_register_class(char *class, char *subclass)
Definition: log.c:339
gbp_scanner_cli_node
static vlib_cli_command_t gbp_scanner_cli_node
(constructor) VLIB_CLI_COMMAND (gbp_scanner_cli_node)
Definition: gbp_scanner.c:113
gbp_scanner_node
vlib_node_registration_t gbp_scanner_node
(constructor) VLIB_REGISTER_NODE (gbp_scanner_node)
Definition: gbp_scanner.c:89
vlib_cli_command_t::path
char * path
Definition: cli.h:96
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
unformat_input_t
struct _unformat_input_t unformat_input_t
vlib_frame_t
Definition: node.h:372
vlib_process_get_events
static uword vlib_process_get_events(vlib_main_t *vm, uword **data_vector)
Return the first event type which has occurred and a vector of per-event data of that type,...
Definition: node_funcs.h:583
gbp_vxlan.h
gs_enabled
static bool gs_enabled
Scanner state.
Definition: gbp_scanner.c:30
gbp_endpoint_scan
void gbp_endpoint_scan(vlib_main_t *vm)
Definition: gbp_endpoint.c:1492
GBP_SCANNER_DBG
#define GBP_SCANNER_DBG(...)
Definition: gbp_scanner.c:32
uword
u64 uword
Definition: types.h:112
gbp_scanner_cli
static clib_error_t * gbp_scanner_cli(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: gbp_scanner.c:97
VLIB_CLI_COMMAND
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:163
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
vlib_cli_output
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:716
GBP_ENDPOINT_SCAN_START
@ GBP_ENDPOINT_SCAN_START
Definition: gbp_scanner.h:23
vlib_process_wait_for_event_or_clock
static f64 vlib_process_wait_for_event_or_clock(vlib_main_t *vm, f64 dt)
Suspend a cooperative multi-tasking thread Waits for an event, or for the indicated number of seconds...
Definition: node_funcs.h:755
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
VLIB_NODE_TYPE_PROCESS
@ VLIB_NODE_TYPE_PROCESS
Definition: node.h:84
gbp_endpoint.h
gbp_scanner.h
vlib_main_t
Definition: main.h:102
clib_error_t
Definition: clib_error.h:21
rt
vnet_interface_output_runtime_t * rt
Definition: interface_output.c:419
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
GBP_ENDPOINT_SCAN_SET_TIME
@ GBP_ENDPOINT_SCAN_SET_TIME
Definition: gbp_scanner.h:25
gbp_scanner_init
static clib_error_t * gbp_scanner_init(vlib_main_t *vm)
Definition: gbp_scanner.c:121
vlib_node_runtime_t
Definition: node.h:454
vlib_cli_command_t
Definition: cli.h:92
VLIB_REGISTER_NODE
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169