summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--extras/emacs/all-skel.el1
-rw-r--r--extras/emacs/periodic-skel.el2
-rw-r--r--extras/emacs/plugin-am-skel.el1
-rw-r--r--extras/emacs/plugin-h-skel.el9
-rw-r--r--extras/emacs/plugin-main-skel.el5
-rw-r--r--extras/emacs/plugin-periodic-skel.el139
-rw-r--r--extras/emacs/plugin.el2
7 files changed, 158 insertions, 1 deletions
diff --git a/extras/emacs/all-skel.el b/extras/emacs/all-skel.el
index f0cc9fe382c..1ab20c5466d 100644
--- a/extras/emacs/all-skel.el
+++ b/extras/emacs/all-skel.el
@@ -30,6 +30,7 @@
(load-file "./plugin-msg-enum-skel.el")
(load-file "./plugin-node-skel.el")
(load-file "./plugin-test-skel.el")
+(load-file "./plugin-periodic-skel.el")
(load-file "./tunnel-c-skel.el")
(load-file "./tunnel-decap-skel.el")
(load-file "./tunnel-encap-skel.el")
diff --git a/extras/emacs/periodic-skel.el b/extras/emacs/periodic-skel.el
index b744fcd46d2..9e73d00dec8 100644
--- a/extras/emacs/periodic-skel.el
+++ b/extras/emacs/periodic-skel.el
@@ -84,7 +84,7 @@ static uword
/*
* " node-name " periodic node declaration
*/
-static VLIB_REGISTER_NODE (" node-name "_node) = {
+VLIB_REGISTER_NODE (" plugin-name "_periodic_node,static) = {
.function = " node-name "_process,
.type = VLIB_NODE_TYPE_PROCESS,
.name = \"" node-name "-process\",
diff --git a/extras/emacs/plugin-am-skel.el b/extras/emacs/plugin-am-skel.el
index 5a082b4c002..0a218e2f00e 100644
--- a/extras/emacs/plugin-am-skel.el
+++ b/extras/emacs/plugin-am-skel.el
@@ -41,6 +41,7 @@ vppplugins_LTLIBRARIES += " plugin-name "_plugin.la
" plugin-name "_plugin_la_SOURCES = \\
" plugin-name "/node.c \\
" plugin-name "/" plugin-name ".c \\
+ " plugin-name "/" plugin-name "_periodic.c \\
" plugin-name "/" plugin-name ".h \\
" plugin-name "/" plugin-name "_all_api_h.h \\
" plugin-name "/" plugin-name "_msg_enum.h
diff --git a/extras/emacs/plugin-h-skel.el b/extras/emacs/plugin-h-skel.el
index 94f60afcfa0..465a069de1e 100644
--- a/extras/emacs/plugin-h-skel.el
+++ b/extras/emacs/plugin-h-skel.el
@@ -53,6 +53,9 @@ typedef struct {
/* API message ID base */
u16 msg_id_base;
+ /* on/off switch for the periodic function */
+ u8 periodic_timer_enabled;
+
/* convenience */
vlib_main_t * vlib_main;
vnet_main_t * vnet_main;
@@ -62,6 +65,12 @@ typedef struct {
" plugin-name "_main_t " plugin-name "_main;
vlib_node_registration_t " plugin-name "_node;
+vlib_node_registration_t " plugin-name "_periodic_node;
+
+/* Periodic function events */
+#define " PLUGIN-NAME "_EVENT1 1
+#define " PLUGIN-NAME "_EVENT2 2
+#define " PLUGIN-NAME "_EVENT_PERIODIC_ENABLE_DISABLE 3
#endif /* __included_" plugin-name "_h__ */
diff --git a/extras/emacs/plugin-main-skel.el b/extras/emacs/plugin-main-skel.el
index 47f030c44f1..8d18cff0fee 100644
--- a/extras/emacs/plugin-main-skel.el
+++ b/extras/emacs/plugin-main-skel.el
@@ -102,6 +102,11 @@ int " plugin-name "_enable_disable (" plugin-name "_main_t * sm, u32 sw_if_index
vnet_feature_enable_disable (\"device-input\", \"" plugin-name "\",
sw_if_index, enable_disable, 0, 0);
+ /* Send an event to enable/disable the periodic scanner process */
+ vlib_process_signal_event (sm->vlib_main, " plugin-name"_periodic_node.index,
+ " PLUGIN-NAME"_EVENT_PERIODIC_ENABLE_DISABLE,
+ (uword)enable_disable);
+
return rv;
}
diff --git a/extras/emacs/plugin-periodic-skel.el b/extras/emacs/plugin-periodic-skel.el
new file mode 100644
index 00000000000..ff1d94e02b4
--- /dev/null
+++ b/extras/emacs/plugin-periodic-skel.el
@@ -0,0 +1,139 @@
+;;; 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")
+"/*
+ * " plugin-name "_periodic.c - skeleton plug-in periodic function
+ *
+ * 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>
+
+static void
+handle_event1 (" plugin-name "_main_t *pm, f64 now, uword event_data)
+{
+ clib_warning (\"received " PLUGIN-NAME "_EVENT1\");
+}
+
+static void
+handle_event2 (" plugin-name "_main_t *pm, f64 now, uword event_data)
+{
+ clib_warning (\"received " PLUGIN-NAME "_EVENT2\");
+}
+
+static void
+handle_periodic_enable_disable (" plugin-name"_main_t *pm, f64 now, uword event_data)
+{
+ clib_warning (\"Periodic timeouts now %s\",
+ 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 */
+}
+
+/* *INDENT-OFF* */
+VLIB_REGISTER_NODE ("plugin-name"_periodic_node) =
+{
+ .function = " plugin-name "_periodic_process,
+ .type = VLIB_NODE_TYPE_PROCESS,
+ .name = \"" plugin-name "-periodic-process\",
+};
+/* *INDENT-ON* */
+
+/*
+ * fd.io coding-style-patch-verification: " capital-oh-en "
+ *
+ * Local Variables:
+ * eval: (c-set-style \"gnu\")
+ * End:
+ */
+")
diff --git a/extras/emacs/plugin.el b/extras/emacs/plugin.el
index 47bffb693c7..bf6e123bc86 100644
--- a/extras/emacs/plugin.el
+++ b/extras/emacs/plugin.el
@@ -41,5 +41,7 @@
(skel-plugin-node)
(find-file (concat plugin-name "_test.c"))
(skel-plugin-test)
+ (find-file (concat plugin-name "_periodic.c"))
+ (skel-plugin-periodic)
(cd start-dir))))