1 ;;; plugin-periodic-skel.el - periodic (process) node skeleton
3 ;;; Copyright (c) 2016 Cisco and/or its affiliates.
4 ;;; Licensed under the Apache License, Version 2.0 (the "License");
5 ;;; you may not use this file except in compliance with the License.
6 ;;; You may obtain a copy of the License at:
8 ;;; http://www.apache.org/licenses/LICENSE-2.0
10 ;;; Unless required by applicable law or agreed to in writing, software
11 ;;; distributed under the License is distributed on an "AS IS" BASIS,
12 ;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 ;;; See the License for the specific language governing permissions and
14 ;;; limitations under the License.
18 (define-skeleton skel-plugin-periodic
19 "Insert a periodic node skeleton "
21 '(if (not (boundp 'plugin-name))
22 (setq plugin-name (read-string "Plugin name: ")))
23 '(setq PLUGIN-NAME (upcase plugin-name))
24 '(setq capital-oh-en "ON")
26 * " plugin-name "_periodic.c - skeleton plug-in periodic function
28 * Copyright (c) <current-year> <your-organization>
29 * Licensed under the Apache License, Version 2.0 (the \"License\");
30 * you may not use this file except in compliance with the License.
31 * You may obtain a copy of the License at:
33 * http://www.apache.org/licenses/LICENSE-2.0
35 * Unless required by applicable law or agreed to in writing, software
36 * distributed under the License is distributed on an \"AS IS\" BASIS,
37 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
38 * See the License for the specific language governing permissions and
39 * limitations under the License.
42 #include <vlib/vlib.h>
43 #include <vppinfra/error.h>
44 #include <" plugin-name "/" plugin-name ".h>
47 handle_event1 (" plugin-name "_main_t *pm, f64 now, uword event_data)
49 clib_warning (\"received " PLUGIN-NAME "_EVENT1\");
53 handle_event2 (" plugin-name "_main_t *pm, f64 now, uword event_data)
55 clib_warning (\"received " PLUGIN-NAME "_EVENT2\");
59 handle_periodic_enable_disable (" plugin-name"_main_t *pm, f64 now, uword event_data)
61 clib_warning (\"Periodic timeouts now %s\",
62 event_data ? \"enabled\" : \"disabled\");
63 pm->periodic_timer_enabled = event_data;
67 handle_timeout (" plugin-name"_main_t *pm, f64 now)
69 clib_warning (\"timeout at %.2f\", now);
73 " plugin-name "_periodic_process (vlib_main_t * vm,
74 vlib_node_runtime_t * rt, vlib_frame_t * f)
76 " plugin-name "_main_t *pm = &" plugin-name "_main;
79 uword *event_data = 0;
85 if (pm->periodic_timer_enabled)
86 vlib_process_wait_for_event_or_clock (vm, timeout);
88 vlib_process_wait_for_event (vm);
90 now = vlib_time_now (vm);
92 event_type = vlib_process_get_events (vm, (uword **) & event_data);
96 /* Handle " PLUGIN-NAME "_EVENT1 */
97 case " PLUGIN-NAME "_EVENT1:
98 for (i = 0; i < vec_len (event_data); i++)
99 handle_event1 (pm, now, event_data[i]);
102 /* Handle " PLUGIN-NAME "_EVENT2 */
103 case " PLUGIN-NAME"_EVENT2:
104 for (i = 0; i < vec_len (event_data); i++)
105 handle_event2 (pm, now, event_data[i]);
107 /* Handle the periodic timer on/off event */
108 case " PLUGIN-NAME"_EVENT_PERIODIC_ENABLE_DISABLE:
109 for (i = 0; i < vec_len (event_data); i++)
110 handle_periodic_enable_disable (pm, now, event_data[i]);
113 /* Handle periodic timeouts */
115 handle_timeout (pm, now);
118 vec_reset_length (event_data);
120 return 0; /* or not */
124 VLIB_REGISTER_NODE ("plugin-name"_periodic_node) =
126 .function = " plugin-name "_periodic_process,
127 .type = VLIB_NODE_TYPE_PROCESS,
128 .name = \"" plugin-name "-periodic-process\",
133 * fd.io coding-style-patch-verification: " capital-oh-en "
136 * eval: (c-set-style \"gnu\")