FD.io VPP  v19.01.3-6-g70449b9b9
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 */
50  ());
51  }
52  else
54 
55  event_type = vlib_process_get_events (vm, &event_data);
56  vec_reset_length (event_data);
57 
58  switch (event_type)
59  {
60  case ~0:
61  /* timer expired */
62  do_scan = 1;
63  break;
64 
66  gs_enabled = 1;
67  break;
68 
70  gs_enabled = 0;
71  break;
72 
74  break;
75 
76  default:
77  ASSERT (0);
78  }
79 
80  if (do_scan)
81  {
82  GBP_SCANNER_DBG ("start");
83  gbp_endpoint_scan (vm);
84  GBP_SCANNER_DBG ("stop");
85  }
86  }
87  return 0;
88 }
89 
90 /* *INDENT-OFF* */
92  .function = gbp_scanner,
93  .type = VLIB_NODE_TYPE_PROCESS,
94  .name = "gbp-scanner",
95 };
96 /* *INDENT-ON* */
97 
98 static clib_error_t *
100  unformat_input_t * input, vlib_cli_command_t * cmd)
101 {
102  vlib_cli_output (vm, "GBP-scanner: enabled:%d interval:%f",
104 
105  return (NULL);
106 }
107 
108 /*?
109  * Show GBP scanner
110  *
111  * @cliexpar
112  * @cliexstart{show gbp scanner}
113  * @cliexend
114  ?*/
115 /* *INDENT-OFF* */
116 VLIB_CLI_COMMAND (gbp_scanner_cli_node, static) = {
117  .path = "show gbp scanner",
118  .short_help = "show gbp scanner",
119  .function = gbp_scanner_cli,
120 };
121 /* *INDENT-ON* */
122 
123 static clib_error_t *
125 {
126  gs_logger = vlib_log_register_class ("gbp", "scan");
127 
128  return (NULL);
129 }
130 
132 
133 /*
134  * fd.io coding-style-patch-verification: ON
135  *
136  * Local Variables:
137  * eval: (c-set-style "gnu")
138  * End:
139  */
vlib_log_class_t vlib_log_register_class(char *class, char *subclass)
Definition: log.c:227
u32 vlib_log_class_t
Definition: log.h:21
#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:673
static uword * vlib_process_wait_for_event(vlib_main_t *vm)
Definition: node_funcs.h:593
#define NULL
Definition: clib.h:58
f64 gbp_endpoint_scan_threshold(void)
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
#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:516
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:91
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169
vlib_main_t * vm
Definition: buffer.c:301
static clib_error_t * gbp_scanner_init(vlib_main_t *vm)
Definition: gbp_scanner.c:124
#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:99
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:762