FD.io VPP  v19.04.2-12-g66b1689
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");
81  gbp_endpoint_scan (vm);
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* */
113 VLIB_CLI_COMMAND (gbp_scanner_cli_node, static) = {
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  */
vlib_log_class_t vlib_log_register_class(char *class, char *subclass)
Definition: log.c:227
#define GBP_SCANNER_DBG(...)
Definition: gbp_scanner.c:32
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:703
static uword * vlib_process_wait_for_event(vlib_main_t *vm)
Definition: node_funcs.h:623
#define NULL
Definition: clib.h:58
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
u32 vlib_log_class_t
Definition: vlib.h:50
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:163
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:546
vlib_log_class_t gs_logger
Scanner logger.
Definition: gbp_scanner.c:25
struct _unformat_input_t unformat_input_t
static uword gbp_scanner(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
Definition: gbp_scanner.c:36
void gbp_endpoint_scan(vlib_main_t *vm)
vlib_node_registration_t gbp_scanner_node
(constructor) VLIB_REGISTER_NODE (gbp_scanner_node)
Definition: gbp_scanner.c:89
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169
vlib_main_t * vm
Definition: buffer.c:312
static clib_error_t * gbp_scanner_init(vlib_main_t *vm)
Definition: gbp_scanner.c:121
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:155
#define ASSERT(truth)
static bool gs_enabled
Scanner state.
Definition: gbp_scanner.c:30
u64 uword
Definition: types.h:112
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
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:762