2018-04-30 13:03:46 -04:00
|
|
|
;;; plugin-periodic-skel.el - periodic (process) node skeleton
|
|
|
|
;;;
|
|
|
|
;;; Copyright (c) 2016 Cisco and/or its affiliates.
|
|
|
|
;;; Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
;;; you may not use this file except in compliance with the License.
|
|
|
|
;;; You may obtain a copy of the License at:
|
|
|
|
;;;
|
|
|
|
;;; http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
;;;
|
|
|
|
;;; Unless required by applicable law or agreed to in writing, software
|
|
|
|
;;; distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
;;; See the License for the specific language governing permissions and
|
|
|
|
;;; limitations under the License.
|
|
|
|
|
|
|
|
(require 'skeleton)
|
|
|
|
|
|
|
|
(define-skeleton skel-plugin-periodic
|
|
|
|
"Insert a periodic node skeleton "
|
|
|
|
nil
|
|
|
|
'(if (not (boundp 'plugin-name))
|
|
|
|
(setq plugin-name (read-string "Plugin name: ")))
|
|
|
|
'(setq PLUGIN-NAME (upcase plugin-name))
|
|
|
|
'(setq capital-oh-en "ON")
|
2019-05-28 16:31:05 -04:00
|
|
|
'(setq main-p (concat (substring plugin-name 0 1) "mp"))
|
2018-04-30 13:03:46 -04:00
|
|
|
"/*
|
2019-05-28 16:31:05 -04:00
|
|
|
* " plugin-name "_periodic.c - skeleton plug-in periodic function
|
2018-04-30 13:03:46 -04:00
|
|
|
*
|
|
|
|
* Copyright (c) <current-year> <your-organization>
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the \"License\");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at:
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an \"AS IS\" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <vlib/vlib.h>
|
|
|
|
#include <vppinfra/error.h>
|
|
|
|
#include <" plugin-name "/" plugin-name ".h>
|
|
|
|
|
2019-05-28 16:31:05 -04:00
|
|
|
static void
|
2018-04-30 13:03:46 -04:00
|
|
|
handle_event1 (" plugin-name "_main_t *pm, f64 now, uword event_data)
|
|
|
|
{
|
|
|
|
clib_warning (\"received " PLUGIN-NAME "_EVENT1\");
|
|
|
|
}
|
2019-05-28 16:31:05 -04:00
|
|
|
|
|
|
|
static void
|
2018-04-30 13:03:46 -04:00
|
|
|
handle_event2 (" plugin-name "_main_t *pm, f64 now, uword event_data)
|
|
|
|
{
|
|
|
|
clib_warning (\"received " PLUGIN-NAME "_EVENT2\");
|
|
|
|
}
|
2019-05-28 16:31:05 -04:00
|
|
|
|
2018-04-30 13:03:46 -04:00
|
|
|
static void
|
|
|
|
handle_periodic_enable_disable (" plugin-name"_main_t *pm, f64 now, uword event_data)
|
|
|
|
{
|
2019-05-28 16:31:05 -04:00
|
|
|
clib_warning (\"Periodic timeouts now %s\",
|
2018-04-30 13:03:46 -04:00
|
|
|
event_data ? \"enabled\" : \"disabled\");
|
|
|
|
pm->periodic_timer_enabled = event_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
handle_timeout (" plugin-name"_main_t *pm, f64 now)
|
|
|
|
{
|
|
|
|
clib_warning (\"timeout at %.2f\", now);
|
|
|
|
}
|
|
|
|
|
|
|
|
static uword
|
|
|
|
" plugin-name "_periodic_process (vlib_main_t * vm,
|
|
|
|
vlib_node_runtime_t * rt, vlib_frame_t * f)
|
|
|
|
{
|
|
|
|
" plugin-name "_main_t *pm = &" plugin-name "_main;
|
|
|
|
f64 now;
|
|
|
|
f64 timeout = 10.0;
|
|
|
|
uword *event_data = 0;
|
|
|
|
uword event_type;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
if (pm->periodic_timer_enabled)
|
|
|
|
vlib_process_wait_for_event_or_clock (vm, timeout);
|
|
|
|
else
|
|
|
|
vlib_process_wait_for_event (vm);
|
|
|
|
|
|
|
|
now = vlib_time_now (vm);
|
|
|
|
|
|
|
|
event_type = vlib_process_get_events (vm, (uword **) & event_data);
|
|
|
|
|
|
|
|
switch (event_type)
|
|
|
|
{
|
|
|
|
/* Handle " PLUGIN-NAME "_EVENT1 */
|
|
|
|
case " PLUGIN-NAME "_EVENT1:
|
|
|
|
for (i = 0; i < vec_len (event_data); i++)
|
|
|
|
handle_event1 (pm, now, event_data[i]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Handle " PLUGIN-NAME "_EVENT2 */
|
|
|
|
case " PLUGIN-NAME"_EVENT2:
|
|
|
|
for (i = 0; i < vec_len (event_data); i++)
|
|
|
|
handle_event2 (pm, now, event_data[i]);
|
|
|
|
break;
|
|
|
|
/* Handle the periodic timer on/off event */
|
|
|
|
case " PLUGIN-NAME"_EVENT_PERIODIC_ENABLE_DISABLE:
|
|
|
|
for (i = 0; i < vec_len (event_data); i++)
|
|
|
|
handle_periodic_enable_disable (pm, now, event_data[i]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Handle periodic timeouts */
|
|
|
|
case ~0:
|
|
|
|
handle_timeout (pm, now);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
vec_reset_length (event_data);
|
|
|
|
}
|
|
|
|
return 0; /* or not */
|
|
|
|
}
|
|
|
|
|
2019-05-28 16:31:05 -04:00
|
|
|
void " plugin-name "_create_periodic_process (" plugin-name "_main_t *" main-p")
|
2018-04-30 13:03:46 -04:00
|
|
|
{
|
2019-05-28 16:31:05 -04:00
|
|
|
/* Already created the process node? */
|
|
|
|
if (" main-p "->periodic_node_index > 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* No, create it now and make a note of the node index */
|
|
|
|
" main-p "->periodic_node_index = vlib_process_create (" main-p "->vlib_main,
|
|
|
|
\"" plugin-name "-periodic-process\",
|
|
|
|
" plugin-name "_periodic_process, 16 /* log2_n_stack_bytes */);
|
|
|
|
}
|
2018-04-30 13:03:46 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* fd.io coding-style-patch-verification: " capital-oh-en "
|
|
|
|
*
|
|
|
|
* Local Variables:
|
|
|
|
* eval: (c-set-style \"gnu\")
|
|
|
|
* End:
|
|
|
|
*/
|
|
|
|
")
|