ip: fix udp/tcp checksum corner cases
[vpp.git] / src / plugins / oddbuf / oddbuf_periodic.c
1 /*
2  * oddbuf_periodic.c - skeleton plug-in periodic function
3  *
4  * Copyright (c) <current-year> <your-organization>
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 <vlib/vlib.h>
19 #include <vppinfra/error.h>
20 #include <oddbuf/oddbuf.h>
21
22 static void
23 handle_event1 (oddbuf_main_t * pm, f64 now, uword event_data)
24 {
25   clib_warning ("received ODDBUF_EVENT1");
26 }
27
28 static void
29 handle_event2 (oddbuf_main_t * pm, f64 now, uword event_data)
30 {
31   clib_warning ("received ODDBUF_EVENT2");
32 }
33
34 static void
35 handle_periodic_enable_disable (oddbuf_main_t * pm, f64 now, uword event_data)
36 {
37   clib_warning ("Periodic timeouts now %s",
38                 event_data ? "enabled" : "disabled");
39   pm->periodic_timer_enabled = event_data;
40 }
41
42 static void
43 handle_timeout (oddbuf_main_t * pm, f64 now)
44 {
45   clib_warning ("timeout at %.2f", now);
46 }
47
48 static uword
49 oddbuf_periodic_process (vlib_main_t * vm,
50                          vlib_node_runtime_t * rt, vlib_frame_t * f)
51 {
52   oddbuf_main_t *pm = &oddbuf_main;
53   f64 now;
54   f64 timeout = 10.0;
55   uword *event_data = 0;
56   uword event_type;
57   int i;
58
59   while (1)
60     {
61       if (pm->periodic_timer_enabled)
62         vlib_process_wait_for_event_or_clock (vm, timeout);
63       else
64         vlib_process_wait_for_event (vm);
65
66       now = vlib_time_now (vm);
67
68       event_type = vlib_process_get_events (vm, (uword **) & event_data);
69
70       switch (event_type)
71         {
72           /* Handle ODDBUF_EVENT1 */
73         case ODDBUF_EVENT1:
74           for (i = 0; i < vec_len (event_data); i++)
75             handle_event1 (pm, now, event_data[i]);
76           break;
77
78           /* Handle ODDBUF_EVENT2 */
79         case ODDBUF_EVENT2:
80           for (i = 0; i < vec_len (event_data); i++)
81             handle_event2 (pm, now, event_data[i]);
82           break;
83           /* Handle the periodic timer on/off event */
84         case ODDBUF_EVENT_PERIODIC_ENABLE_DISABLE:
85           for (i = 0; i < vec_len (event_data); i++)
86             handle_periodic_enable_disable (pm, now, event_data[i]);
87           break;
88
89           /* Handle periodic timeouts */
90         case ~0:
91           handle_timeout (pm, now);
92           break;
93         }
94       vec_reset_length (event_data);
95     }
96   return 0;                     /* or not */
97 }
98
99 void
100 oddbuf_create_periodic_process (oddbuf_main_t * omp)
101 {
102   /* Already created the process node? */
103   if (omp->periodic_node_index > 0)
104     return;
105
106   /* No, create it now and make a note of the node index */
107   omp->periodic_node_index = vlib_process_create (omp->vlib_main, "oddbuf-periodic-process", oddbuf_periodic_process, 16        /* log2_n_stack_bytes */
108     );
109 }
110
111 /*
112  * fd.io coding-style-patch-verification: ON
113  *
114  * Local Variables:
115  * eval: (c-set-style "gnu")
116  * End:
117  */