a2d0c9a98cbb9fa19847c37d9b66b8dc72b44254
[vpp.git] / src / plugins / gbp / gbp_scanner.c
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
18 #include <plugins/gbp/gbp_scanner.h>
19 #include <plugins/gbp/gbp_endpoint.h>
20 #include <plugins/gbp/gbp_vxlan.h>
21
22 vlib_log_class_t gs_logger;
23
24 #define GBP_SCANNER_DBG(...)                                      \
25     vlib_log_debug (gs_logger, __VA_ARGS__);
26
27 static uword
28 gbp_scanner (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f)
29 {
30   uword event_type, *event_data = 0;
31   bool enabled = 0, do_scan = 0;
32
33   while (1)
34     {
35       do_scan = 0;
36
37       if (enabled)
38         {
39           /* scan every 'inactive threshold' seconds */
40           vlib_process_wait_for_event_or_clock (vm,
41                                                 gbp_endpoint_scan_threshold
42                                                 ());
43         }
44       else
45         vlib_process_wait_for_event (vm);
46
47       event_type = vlib_process_get_events (vm, &event_data);
48       vec_reset_length (event_data);
49
50       switch (event_type)
51         {
52         case ~0:
53           /* timer expired */
54           do_scan = 1;
55           break;
56
57         case GBP_ENDPOINT_SCAN_START:
58           enabled = 1;
59           break;
60
61         case GBP_ENDPOINT_SCAN_STOP:
62           enabled = 0;
63           break;
64
65         default:
66           ASSERT (0);
67         }
68
69       if (do_scan)
70         {
71           GBP_SCANNER_DBG ("start");
72           gbp_endpoint_scan (vm);
73           GBP_SCANNER_DBG ("stop");
74         }
75     }
76   return 0;
77 }
78
79 /* *INDENT-OFF* */
80 VLIB_REGISTER_NODE (gbp_scanner_node) = {
81     .function = gbp_scanner,
82     .type = VLIB_NODE_TYPE_PROCESS,
83     .name = "gbp-scanner",
84 };
85 /* *INDENT-ON* */
86
87
88 static clib_error_t *
89 gbp_scanner_init (vlib_main_t * vm)
90 {
91   gs_logger = vlib_log_register_class ("gbp", "scan");
92
93   return (NULL);
94 }
95
96 VLIB_INIT_FUNCTION (gbp_scanner_init);
97
98 /*
99  * fd.io coding-style-patch-verification: ON
100  *
101  * Local Variables:
102  * eval: (c-set-style "gnu")
103  * End:
104  */