Move emacs stuff to extras/

Change-Id: Ibbb7d8500e9064215cf912bd00bdf72a748f8a27
Signed-off-by: Damjan Marion <damarion@cisco.com>
This commit is contained in:
Damjan Marion
2017-04-20 11:42:28 +02:00
committed by Damjan Marion
parent 53129423a6
commit 757585db71
27 changed files with 1 additions and 1 deletions

86
extras/emacs/README Normal file
View File

@ -0,0 +1,86 @@
How to construct a complete plugin using the emacs skeletons
0. Install open-vpp, including the development package.
1. Load emacs skeletons
M-x find-file all-skel.el
M-x eval-buffer
2. Pick a single-word, lower-case name for your plugin. For example: macswap.
Hereafter, we'll refer to the selected name as <plugin-name>.
3. Generate the entire plugin:
M-x make-plugin
Plugin-name: <plugin-name>
Or, generate each file individually:
3. Create the required directories, e.g. under .../vpp
$ mkdir -p <plugin-name>-plugin/<plugin-name>
4. Create <plugin-name>-plugin/{configure.ac,Makefile.am}
M-x find-file <plugin-name>-plugin/configure.ac
M-x plugin-configure-skel
M-x find-file <plugin-name>-plugin/Makefile.am
M-x skel-plugin-makefile
5. Create the api skeleton
M-x find-file <plugin-name>-plugin/<plugin-name>/<plugin-name>.api
M-x skel-plugin-api
6. Create the api message enumeration header file
M-x find-file <plugin-name>-plugin/<plugin-name>/<plugin-name>_msg_enum.h
M-x skel-plugin-msg-enum
7. Create the "all-api" header file
M-x find-file <plugin-name>-plugin/<plugin-name>/<plugin-name>_all_api_h.h
M-x skel-plugin-all-apih
8. Create the main data structure definition header file
M-x find-file <plugin-name>-plugin/<plugin-name>/<plugin-name>.h
M-x skel-plugin-h
9. Create the plugin main C file
M-x find-file <plugin-name>-plugin/<plugin-name>/<plugin-name>.c
M-x skel-plugin-main
10. Create the vpp-api-test plugin main C file
M-x find-file <plugin-name>-plugin/<plugin-name>/<plugin-name>_test.c
M-x skel-plugin-test
11. Create the data plane packet processing node
M-x find-file <plugin-name>-plugin/<plugin-name>/node.c
M-x skel-plugin-node
12. Process autotools input files
$ cd <plugin-name>-plugin
$ autoreconf -i -f
13. Build the plugin skeleton
$ mkdir build
$ cd build
$ ../configure
$ make
$ sudo make install

40
extras/emacs/all-skel.el Normal file
View File

@ -0,0 +1,40 @@
;;; 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.
;; plugin all-in-1 program
(load-file "./plugin.el")
;; list of clib / vlib / vnet / vpp skeleton files
(load-file "./cli-cmd-skel.el")
(load-file "./config-skel.el")
(load-file "./dual-loop-skel.el")
(load-file "./periodic-skel.el")
(load-file "./pipe-skel.el")
(load-file "./plugin-all-apih-skel.el")
(load-file "./plugin-am-skel.el")
(load-file "./plugin-api-skel.el")
(load-file "./plugin-h-skel.el")
(load-file "./plugin-main-skel.el")
(load-file "./plugin-msg-enum-skel.el")
(load-file "./plugin-node-skel.el")
(load-file "./plugin-test-skel.el")
(load-file "./tunnel-c-skel.el")
(load-file "./tunnel-decap-skel.el")
(load-file "./tunnel-encap-skel.el")
(load-file "./tunnel-h-skel.el")
(load-file "./elog-4-int-skel.el")
(load-file "./elog-4-int-track-skel.el")
(load-file "./elog-enum-skel.el")
(load-file "./elog-one-datum-skel.el")

View File

@ -0,0 +1,32 @@
;;; cli-cmd-skel.el - cli command skeleton
(require 'skeleton)
(define-skeleton skel-cli-cmd
"Insert a CLI command "
nil
'(setq cmd-name (skeleton-read "Command Name: "))
'(setq path (skeleton-read "Path: "))
"
static clib_error_t *
" cmd-name "_command_fn (vlib_main_t * vm,
unformat_input_t * input,
vlib_cli_command_t * cmd)
{
while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
if (unformat (input, \"whatever %d\", &whatever))
;
else
return clib_error_return (0, \"unknown input `%U'\",
format_unformat_error, input);
}
return 0;
}
VLIB_CLI_COMMAND (" cmd-name "_command, static) = {
.path = \"" path "\",
.short_help = \"" path "\",
.function = " cmd-name "_command_fn,
};
")

View File

@ -0,0 +1,28 @@
;;; config-skel.el - config function command skeleton
(require 'skeleton)
(define-skeleton skel-config
"Insert a vlib config skeleton "
nil
'(setq cfg-name (skeleton-read "Config Class Name: "))
"
static clib_error_t *
" cfg-name "_config (vlib_main_t * vm, unformat_input_t * input)
{
u32 whatever;
while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
if (unformat (input, \"whatever %d\", &whatever))
;
else
return clib_error_return (0, \"unknown input `%U'\",
format_unformat_error, input);
}
return 0;
}
VLIB_CONFIG_FUNCTION (" cfg-name "_config, \"" cfg-name "\");
")

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,31 @@
;;; elog-4-int-skel.el - 4 integer elog skeleton
(require 'skeleton)
(define-skeleton skel-elog-4-int
"Insert a skeleton 4-integer event definition"
nil
'(setq function-name (skeleton-read "Function: "))
'(setq label (skeleton-read "Label: "))
"
/* $$$ May or may not be needed */
#include <vlib/vlib.h>
#include <vppinfra/elog.h>
static inline void " function-name " (u32 *data)
{
ELOG_TYPE_DECLARE(e) =
{
.format = \"" label ": first %d second %d third %d fourth %d\",
.format_args = \"i4i4i4i4\",
};
struct { u32 data[4];} * ed;
ed = ELOG_DATA (&vlib_global_main.elog_main, e);
ed->data[0] = data[0];
ed->data[1] = data[1];
ed->data[2] = data[2];
ed->data[3] = data[3];
}
")

View File

@ -0,0 +1,34 @@
;;; elog-4-int-skel.el - 4 integer elog skeleton
(require 'skeleton)
(define-skeleton skel-elog-4-int-track
"Insert a skeleton 4-integer-with-track event definition"
nil
'(setq function-name (skeleton-read "Function: "))
'(setq track-label (skeleton-read "Track Label: "))
'(setq label (skeleton-read "Label: "))
"
/* $$$ May or may not be needed */
#include <vlib/vlib.h>
#include <vppinfra/elog.h>
static inline void " function-name " (u32 *data)
{
ELOG_TYPE_DECLARE(e) =
{
.format = \"" label ": first %d second %d third %d fourth %d\",
.format_args = \"i4i4i4i4\",
};
struct { u32 data[4];} * ed;
ELOG_TRACK(" track-label ");
ed = ELOG_TRACK_DATA (&vlib_global_main.elog_main, e, " track-label ");
ed->data[0] = data[0];
ed->data[1] = data[1];
ed->data[2] = data[2];
ed->data[3] = data[3];
}
")

View File

@ -0,0 +1,35 @@
;;; elog-enum-skel.el - enum elog skeleton
(require 'skeleton)
(define-skeleton skel-elog-enum
"Insert a skeleton enum event definition"
nil
'(setq function-name (skeleton-read "Function: "))
'(setq label (skeleton-read "Label: "))
"
/* $$$ May or may not be needed */
#include <vlib/vlib.h>
#include <vppinfra/elog.h>
static inline void " function-name " (u8 which)
{
ELOG_TYPE_DECLARE (e) =
{
.format = \"" label ": %s\",
.format_args = \"t1\",
.n_enum_strings = 2,
.enum_strings =
{
\"string 1\",
\"string 2\",
},
};
struct { u8 which;} * ed;
ed = ELOG_DATA (&vlib_global_main.elog_main, e);
ed->which = which;
}
")

View File

@ -0,0 +1,28 @@
;;; elog-one-datum-skel.el - single u32 datum elog skeleton
(require 'skeleton)
(define-skeleton skel-elog-one-datum
"Insert a skeleton single datum event definition"
nil
'(setq function-name (skeleton-read "Function: "))
'(setq label (skeleton-read "Label: "))
"
/* $$$ May or may not be needed */
#include <vlib/vlib.h>
#include <vppinfra/elog.h>
static inline void " function-name " (u32 data)
{
ELOG_TYPE_DECLARE (e) =
{
.format = \"" label ": %d\",
.format_args = \"i4\",
};
elog (&vlib_global_main.elog_main, &e, data);
}
")

162
extras/emacs/fix-coding-style.el Executable file
View File

@ -0,0 +1,162 @@
#!/usr/bin/emacs --script
;; Insert style boilerplate if it's not already there
;;
;; Breaking the string in half keeps emacs
;; from trying to interpret the local variable
;; settings e.g. when it reads the lisp source code
(defun insert-style-boilerplate () (interactive)
(save-excursion
(goto-char (point-min))
(if (eq nil (search-forward "coding-style-patch-verification"
(point-max) t))
(let ((junk 0)) (goto-char (point-max))
(insert "
/*
* fd.io coding-style-patch-verification: ON
*
* Local Var" "iables:
* eval: (c-set-style \"gnu\")
* End:
*/")))))
;; (cons xxx <list>) means insert xxx at the head of <list>
;; Build a sorted list of *INDENT-OFF* lines, by searching
;; backwards. The initial (setq indent-offset-list nil)
;; results in (cdr <last-cell>) nil, which makes it a proper list
(defun find-indent-offs () (interactive)
(save-excursion
(if (boundp 'indent-offset-list)
(makunbound 'indent-offset-list))
(setq indent-offset-list nil)
(goto-char (point-max))
(while (search-backward "*INDENT-OFF*" (point-min) t)
(move-beginning-of-line nil)
(setq indent-offset-list (cons (point) indent-offset-list))
(previous-line))))
;; Insert indent-off ... indent-on brackets around
;; a certain xxx_foreach macro, etc. which "indent"
;; completely screws up. Doesn't handle nesting, of which there
;; are few examples (fortunately).
(defun fix-initializer (what) (interactive)
(find-indent-offs)
(save-excursion
(goto-char (point-min))
(while (search-forward-regexp what (point-max) t)
(move-beginning-of-line nil)
(previous-line)
(let ((index 0)(pointval 0))
(while (and (< pointval (point))(elt indent-offset-list index))
(setq pointval (elt indent-offset-list index))
(setq index (1+ index)))
(if (not (eq pointval (point)))
(let ((junk 0))
(next-line)
(open-line 1)
(c-indent-line-or-region)
(insert "/* *INDENT-OFF* */")
(search-forward "{")
(backward-char)
(forward-sexp)
(move-end-of-line nil)
(newline 1)
(c-indent-line-or-region)
(insert "/* *INDENT-ON* */")
(find-indent-offs))
(search-forward "*INDENT-ON*"))))))
(defun fix-pool-foreach () (interactive)
(fix-initializer "pool_foreach *("))
(defun fix-pool-foreach-index () (interactive)
(fix-initializer "pool_foreach_index *("))
(defun fix-hash-foreach () (interactive)
(fix-initializer "hash_foreach *("))
(defun fix-hash-foreach-pair () (interactive)
(fix-initializer "hash_foreach_pair *("))
(defun fix-hash-foreach-mem () (interactive)
(fix-initializer "hash_foreach_mem *("))
(defun fix-clib-fifo-foreach () (interactive)
(fix-initializer "clib_fifo_foreach *("))
(defun fix-clib-bitmap-foreach () (interactive)
(fix-initializer "clib_bitmap_foreach *("))
(defun fix-foreach-ip-interface-address () (interactive)
(fix-initializer "foreach_ip_interface_address *("))
(defun fix-vlib-register-thread () (interactive)
(fix-initializer "VLIB_REGISTER_THREAD *("))
(defun fix-vlib-cli-command () (interactive)
(fix-initializer "VLIB_CLI_COMMAND *("))
(defun fix-vlib-register-node () (interactive)
(fix-initializer "VLIB_REGISTER_NODE *("))
(defun fix-reply-macro2 () (interactive)
(fix-initializer "REPLY_MACRO2 *("))
(defun fix-vnet-device-class () (interactive)
(fix-initializer "VNET_DEVICE_CLASS *("))
(defun fix-vnet-hw-interface-class () (interactive)
(fix-initializer "VNET_HW_INTERFACE_CLASS *("))
(defun fix-clib-packed () (interactive)
(fix-initializer "CLIB_PACKED *("))
(defun fix-vl-api-packed () (interactive)
(fix-initializer "VL_API_PACKED *("))
;; Driver routine which runs the set of functions
;; defined above, as well as the bottom boilerplate function
(defun fd-io-styleify () (interactive)
(fix-pool-foreach)
(fix-pool-foreach-index)
(fix-hash-foreach)
(fix-hash-foreach-pair)
(fix-hash-foreach-mem)
(fix-foreach-ip-interface-address)
(fix-clib-fifo-foreach)
(fix-clib-bitmap-foreach)
(fix-vlib-register-thread)
(fix-vlib-cli-command)
(fix-vlib-register-node)
(fix-reply-macro2)
(fix-vnet-device-class)
(fix-vnet-hw-interface-class)
(fix-clib-packed)
(fix-vl-api-packed)
(insert-style-boilerplate)
(if (boundp 'indent-offset-list)
(makunbound 'indent-offset-list)))
;; When run as a script, this sexp
;; walks the list of files supplied on the command line.
;;
;; (elt argv index) returns nil if you M-x eval-buffer
;; or M-x load-file the file, so we won't accidentally
;; evaluate (save-buffers-kill-emacs)...
(let ((file-index 0))
(if (elt argv file-index)
(while (elt argv file-index)
(find-file (elt argv file-index))
(fd-io-styleify)
(message "Done %s..." (elt argv file-index))
(setq file-index (1+ file-index))))
(if (> file-index 0)
(let ((junk 0))
(message "Save and quit...")
(save-buffers-kill-emacs t))))

4
extras/emacs/make-plugin.sh Executable file
View File

@ -0,0 +1,4 @@
#!/usr/bin/emacs --script
(load-file "./all-skel.el")
(make-plugin)
(save-some-buffers t)

View File

@ -0,0 +1,86 @@
;;; pipe-skel.el - pipelined graph node skeleton
(require 'skeleton)
(define-skeleton skel-periodic
"Insert a skeleton periodic process node"
nil
'(setq node-name (skeleton-read "Name: "))
'(setq uc-node-name (upcase node-name))
'(setq poll-period (skeleton-read "Poll period (f64 seconds, e.g. 10.0): "))
"
#define " uc-node-name "_POLL_PERIOD " poll-period "
static uword
" node-name "_process (vlib_main_t * vm,
vlib_node_runtime_t * rt,
vlib_frame_t * f)
{
f64 poll_time_remaining;
uword event_type, * event_data = 0;
poll_time_remaining = " uc-node-name "_POLL_PERIOD;
while (1) {
int i;
/*
* Sleep until next periodic call due, or until we receive event(s)
*/
poll_time_remaining =
vlib_process_wait_for_event_or_clock (vm, poll_time_remaining);
event_type = vlib_process_get_events (vm, &event_data);
switch (event_type) {
case ~0: /* no events => timeout */
break;
/*
* $$$$ FIXME: add cases / handlers for each event type
*/
case EVENT1:
for (i = 0; i < vec_len (event_data); i++)
handle_event1 (mm, event_data[i]);
break;
case EVENT2:
for (i = 0; i < vec_len (event_data); i++)
handle_event2 (vm, event_data[i]);
break;
/* ... and so forth for each event type */
default:
/* This should never happen... */
clib_warning (\"BUG: unhandled event type %d\", event_type);
break;
}
if (event_data)
_vec_len (event_data) = 0;
/* Timer expired, call periodic function */
if (vlib_process_suspend_time_is_zero (poll_time_remaining)) {
" node-name "_periodic (vm);
poll_time_remaining = " uc-node-name "_POLL_PERIOD;
}
}
return 0;
}
/*
* " node-name " periodic node declaration
*/
static VLIB_REGISTER_NODE (" node-name "_node) = {
.function = " node-name "_process,
.type = VLIB_NODE_TYPE_PROCESS,
.name = \"" node-name "-process\",
};
/*
* To signal an event:
*
* vlib_process_signal_event (vm, " node-name "_node.index, EVENTn, datum);
*
*/
")

132
extras/emacs/pipe-skel.el Normal file
View File

@ -0,0 +1,132 @@
;;; pipe-skel.el - pipelined graph node skeleton
(require 'skeleton)
(define-skeleton skel-pipeline-node
"Insert a skeleton pipelined graph node"
nil
'(setq node-name (skeleton-read "Node Name: "))
'(setq uc-node-name (upcase node-name))
'(setq nstages (skeleton-read "Number of pipeline stages: "))
"
#include <vlib/vlib.h>
#include <vppinfra/error.h>
/*
* Dump these counters via the \"show error\" CLI command
* FIXME: Add packet counter / error strings as desired
*/
#define foreach_" node-name "_error \\
_(ERROR1, \"sample counter/ error string\")
static char * " node-name "_error_strings[] = {
#define _(sym,string) string,
foreach_" node-name "_error
#undef _
};
/*
* packet error / counter enumeration
*
* To count and drop a vlib_buffer_t *b:
*
* Set b->error = node->errors[" uc-node-name "_ERROR_xxx];
* last_stage returns a disposition index bound to \"error-drop\"
*
* To manually increment the specific counter " uc-node-name "_ERROR1
*
* vlib_node_t *n = vlib_get_node (vm, " node-name ".index);
* u32 node_counter_base_index = n->error_heap_index;
* vlib_error_main_t * em = &vm->error_main;
* em->counters[node_counter_base_index + " uc-node-name "_ERROR1] += 1;
*
*/
typedef enum {
#define _(sym,str) " uc-node-name "_ERROR_##sym,
foreach_" node-name "_error
#undef _
" uc-node-name "_N_ERROR,
} " node-name "_error_t;
/*
* enumeration of per-packet dispositions
* FIXME: add dispositions as desired
*/
typedef enum { \n"
" " uc-node-name "_NEXT_NORMAL,\n"
" " uc-node-name "_N_NEXT,
} " node-name "_next_t;
#define NSTAGES " nstages "
/*
* Use the generic buffer metadata + first line of packet data prefetch
* stage function from <api/pipeline.h>. This is usually a Good Idea.
*/
#define stage0 generic_stage0
/*
* FIXME: add stage functions. Here is the function prototype:
*
* static inline void stageN (vlib_main_t * vm,
* vlib_node_runtime_t * node,
* u32 buffer_index)
*/
/*
* FIXME: the last pipeline stage returns the desired pkt next node index,
* from the " node-name "_next_t enum above
*/
static inline u32 last_stage (vlib_main_t *vm, vlib_node_runtime_t *node,
u32 bi)
{
vlib_buffer_t *b = vlib_get_buffer (vm, bi);
b->error = node->errors[EXAMPLE_ERROR_ERROR1];
return " uc-node-name "_NEXT_NORMAL;
}
#include <api/pipeline.h>
static uword " node-name "_node_fn (vlib_main_t * vm,
vlib_node_runtime_t * node,
vlib_frame_t * frame)
{
return dispatch_pipeline (vm, node, frame);
}
static VLIB_REGISTER_NODE (example_node) = {
.function = " node-name "_node_fn,
.name = \"" node-name "-node\",
.vector_size = sizeof (u32),
.type = VLIB_NODE_TYPE_INTERNAL,
.n_errors = ARRAY_LEN(" node-name "_error_strings),
.error_strings = " node-name "_error_strings,
.n_next_nodes = " uc-node-name "_N_NEXT,
/* edit / add dispositions here */
.next_nodes = {
[" uc-node-name "_NEXT_NORMAL] = \"error-drop\",
},
};
/*
* packet generator definition to push superframes of data into the
* new graph node. Cut and paste into <file>, then
* \"exec <file>\", \"pa enable test\" at the QVNET prompt...
*
packet-generator new {
name test
limit 100
node " node-name "-node
size 374-374
data { hex 0x02b46b96000100096978676265000500bf436973636f20494f5320536f6674776172652c2043333735304520536f66747761726520284333373530452d554e4956455253414c2d4d292c2056657273696f6e2031322e32283335295345352c2052454c4541534520534f4654574152452028666331290a436f707972696768742028632920313938362d3230303720627920436973636f2053797374656d732c20496e632e0a436f6d70696c6564205468752031392d4a756c2d30372031363a3137206279206e616368656e00060018636973636f2057532d4333373530452d3234544400020011000000010101cc0004000000000003001b54656e4769676162697445746865726e6574312f302f3100040008000000280008002400000c011200000000ffffffff010221ff000000000000001e7a50f000ff000000090004000a00060001000b0005010012000500001300050000160011000000010101cc000400000000001a00100000000100000000ffffffff }
}
*/
")

View File

@ -0,0 +1,43 @@
;;; plugin-all-apih-skel.el - vpp engine plug-in "all-apih.c" 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-all-apih
"Insert a plug-in 'all_api_h.h' skeleton "
nil
'(if (not (boundp 'plugin-name))
(setq plugin-name (read-string "Plugin name: ")))
'(setq PLUGIN-NAME (upcase plugin-name))
"
/*
* " plugin-name "_all_api_h.h - skeleton vpp engine plug-in api #include file
*
* 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 the generated file, see BUILT_SOURCES in Makefile.am */
#include <" plugin-name "/" plugin-name ".api.h>
")

View File

@ -0,0 +1,60 @@
;;; plugin-am-skel.el - vpp engine plug-in foo.am 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-makefile-am-fragment
"Insert a plug-in 'foo.am' skeleton "
nil
'(if (not (boundp 'plugin-name))
(setq plugin-name (read-string "Plugin name: ")))
'(setq PLUGIN-NAME (upcase plugin-name))
"
# 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.
vppapitestplugins_LTLIBRARIES += " plugin-name "_test_plugin.la
vppplugins_LTLIBRARIES += " plugin-name "_plugin.la
" plugin-name "_plugin_la_SOURCES = \\
" plugin-name "/node.c \\
" plugin-name "/" plugin-name ".c \\
" plugin-name "/" plugin-name ".h \\
" plugin-name "/" plugin-name "_all_api_h.h \\
" plugin-name "/" plugin-name "_msg_enum.h
API_FILES += " plugin-name "/" plugin-name ".api
nobase_apiinclude_HEADERS += \\
" plugin-name "/" plugin-name "_all_api_h.h \\
" plugin-name "/" plugin-name "_msg_enum.h \\
" plugin-name "/" plugin-name ".api.h
" plugin-name "_test_plugin_la_SOURCES = \\
" plugin-name "/" plugin-name "_test.c \\
" plugin-name "/" plugin-name ".api.h
# vi:syntax=automake
")

View File

@ -0,0 +1,48 @@
;;; plugin-api-skel.el - vpp engine plug-in "all-apih.c" 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-api
"Insert a plug-in '<name>.api' skeleton "
nil
'(if (not (boundp 'plugin-name))
(setq plugin-name (read-string "Plugin name: ")))
'(setq PLUGIN-NAME (upcase plugin-name))
"
/* Define a simple enable-disable binary API to control the feature */
define " plugin-name "_enable_disable {
/* Client identifier, set from api_main.my_client_index */
u32 client_index;
/* Arbitrary context, so client can match reply to request */
u32 context;
/* Enable / disable the feature */
u8 enable_disable;
/* Interface handle */
u32 sw_if_index;
};
define " plugin-name "_enable_disable_reply {
/* From the request */
u32 context;
/* Return value, zero means all OK */
i32 retval;
};
")

View File

@ -0,0 +1,66 @@
;;; plugin-h-skel.el - vpp engine plug-in "main.c" 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-h
"Insert a plug-in 'main.c' skeleton "
nil
'(if (not (boundp 'plugin-name))
(setq plugin-name (read-string "Plugin name: ")))
'(setq PLUGIN-NAME (upcase plugin-name))
"
/*
* " plugin-name ".h - skeleton vpp engine plug-in header file
*
* 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.
*/
#ifndef __included_" plugin-name "_h__
#define __included_" plugin-name "_h__
#include <vnet/vnet.h>
#include <vnet/ip/ip.h>
#include <vnet/ethernet/ethernet.h>
#include <vppinfra/hash.h>
#include <vppinfra/error.h>
typedef struct {
/* API message ID base */
u16 msg_id_base;
/* convenience */
vlib_main_t * vlib_main;
vnet_main_t * vnet_main;
ethernet_main_t * ethernet_main;
} " plugin-name "_main_t;
" plugin-name "_main_t " plugin-name "_main;
vlib_node_registration_t " plugin-name "_node;
#endif /* __included_" plugin-name "_h__ */
")

View File

@ -0,0 +1,280 @@
;;; plugin-main-skel.el - vpp engine plug-in "main.c" 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-main
"Insert a plug-in 'main.c' 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 ".c - skeleton vpp engine plug-in
*
* 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 <vnet/vnet.h>
#include <vnet/plugin/plugin.h>
#include <" plugin-name "/" plugin-name ".h>
#include <vlibapi/api.h>
#include <vlibmemory/api.h>
#include <vlibsocket/api.h>
#include <vpp/app/version.h>
/* define message IDs */
#include <" plugin-name "/" plugin-name "_msg_enum.h>
/* define message structures */
#define vl_typedefs
#include <" plugin-name "/" plugin-name "_all_api_h.h>
#undef vl_typedefs
/* define generated endian-swappers */
#define vl_endianfun
#include <" plugin-name "/" plugin-name "_all_api_h.h>
#undef vl_endianfun
/* instantiate all the print functions we know about */
#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
#define vl_printfun
#include <" plugin-name "/" plugin-name "_all_api_h.h>
#undef vl_printfun
/* Get the API version number */
#define vl_api_version(n,v) static u32 api_version=(v);
#include <" plugin-name "/" plugin-name "_all_api_h.h>
#undef vl_api_version
/*
* A handy macro to set up a message reply.
* Assumes that the following variables are available:
* mp - pointer to request message
* rmp - pointer to reply message type
* rv - return value
*/
#define REPLY_MACRO(t) \\
do { \\
unix_shared_memory_queue_t * q = \\
vl_api_client_index_to_input_queue (mp->client_index); \\
if (!q) \\
return; \\
\\
rmp = vl_msg_api_alloc (sizeof (*rmp)); \\
rmp->_vl_msg_id = ntohs((t)+sm->msg_id_base); \\
rmp->context = mp->context; \\
rmp->retval = ntohl(rv); \\
\\
vl_msg_api_send_shmem (q, (u8 *)&rmp); \\
} while(0);
/* List of message types that this plugin understands */
#define foreach_" plugin-name "_plugin_api_msg \\
_(" PLUGIN-NAME "_ENABLE_DISABLE, " plugin-name "_enable_disable)
/* Action function shared between message handler and debug CLI */
int " plugin-name "_enable_disable (" plugin-name "_main_t * sm, u32 sw_if_index,
int enable_disable)
{
vnet_sw_interface_t * sw;
int rv = 0;
/* Utterly wrong? */
if (pool_is_free_index (sm->vnet_main->interface_main.sw_interfaces,
sw_if_index))
return VNET_API_ERROR_INVALID_SW_IF_INDEX;
/* Not a physical port? */
sw = vnet_get_sw_interface (sm->vnet_main, sw_if_index);
if (sw->type != VNET_SW_INTERFACE_TYPE_HARDWARE)
return VNET_API_ERROR_INVALID_SW_IF_INDEX;
vnet_feature_enable_disable (\"device-input\", \"" plugin-name "\",
sw_if_index, enable_disable, 0, 0);
return rv;
}
static clib_error_t *
" plugin-name "_enable_disable_command_fn (vlib_main_t * vm,
unformat_input_t * input,
vlib_cli_command_t * cmd)
{
" plugin-name "_main_t * sm = &" plugin-name "_main;
u32 sw_if_index = ~0;
int enable_disable = 1;
int rv;
while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
{
if (unformat (input, \"disable\"))
enable_disable = 0;
else if (unformat (input, \"%U\", unformat_vnet_sw_interface,
sm->vnet_main, &sw_if_index))
;
else
break;
}
if (sw_if_index == ~0)
return clib_error_return (0, \"Please specify an interface...\");
rv = " plugin-name "_enable_disable (sm, sw_if_index, enable_disable);
switch(rv)
{
case 0:
break;
case VNET_API_ERROR_INVALID_SW_IF_INDEX:
return clib_error_return
(0, \"Invalid interface, only works on physical ports\");
break;
case VNET_API_ERROR_UNIMPLEMENTED:
return clib_error_return (0, \"Device driver doesn't support redirection\");
break;
default:
return clib_error_return (0, \"" plugin-name "_enable_disable returned %d\",
rv);
}
return 0;
}
/* *INDENT-OFF* */
VLIB_CLI_COMMAND (" plugin-name "_enable_disable_command, static) =
{
.path = \"" plugin-name " enable-disable\",
.short_help =
\"" plugin-name " enable-disable <interface-name> [disable]\",
.function = " plugin-name "_enable_disable_command_fn,
};
/* *INDENT-ON* */
/* API message handler */
static void vl_api_" plugin-name "_enable_disable_t_handler
(vl_api_" plugin-name "_enable_disable_t * mp)
{
vl_api_" plugin-name "_enable_disable_reply_t * rmp;
" plugin-name "_main_t * sm = &" plugin-name "_main;
int rv;
rv = " plugin-name "_enable_disable (sm, ntohl(mp->sw_if_index),
(int) (mp->enable_disable));
REPLY_MACRO(VL_API_" PLUGIN-NAME "_ENABLE_DISABLE_REPLY);
}
/* Set up the API message handling tables */
static clib_error_t *
" plugin-name "_plugin_api_hookup (vlib_main_t *vm)
{
" plugin-name "_main_t * sm = &" plugin-name "_main;
#define _(N,n) \\
vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \\
#n, \\
vl_api_##n##_t_handler, \\
vl_noop_handler, \\
vl_api_##n##_t_endian, \\
vl_api_##n##_t_print, \\
sizeof(vl_api_##n##_t), 1);
foreach_" plugin-name "_plugin_api_msg;
#undef _
return 0;
}
#define vl_msg_name_crc_list
#include <" plugin-name "/" plugin-name "_all_api_h.h>
#undef vl_msg_name_crc_list
static void
setup_message_id_table (" plugin-name "_main_t * sm, api_main_t * am)
{
#define _(id,n,crc) \
vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + sm->msg_id_base);
foreach_vl_msg_name_crc_" plugin-name" ;
#undef _
}
static clib_error_t * " plugin-name "_init (vlib_main_t * vm)
{
" plugin-name "_main_t * sm = &" plugin-name "_main;
clib_error_t * error = 0;
u8 * name;
name = format (0, \"" plugin-name "_%08x%c\", api_version, 0);
/* Ask for a correctly-sized block of API message decode slots */
sm->msg_id_base = vl_msg_api_get_msg_ids
((char *) name, VL_MSG_FIRST_AVAILABLE);
error = " plugin-name "_plugin_api_hookup (vm);
/* Add our API messages to the global name_crc hash table */
setup_message_id_table (sm, &api_main);
vec_free(name);
return error;
}
VLIB_INIT_FUNCTION (" plugin-name "_init);
/* *INDENT-OFF* */
VNET_FEATURE_INIT (" plugin-name ", static) =
{
.arc_name = \"device-input\",
.node_name = \"" plugin-name "\",
.runs_before = VNET_FEATURES (\"ethernet-input\"),
};
/* *INDENT-ON */
/* *INDENT-OFF* */
VLIB_PLUGIN_REGISTER () =
{
.version = VPP_BUILD_VER,
};
/* *INDENT-ON* */
/*
* fd.io coding-style-patch-verification: " capital-oh-en "
*
* Local Variables:
* eval: (c-set-style \"gnu\")
* End:
*/
")

View File

@ -0,0 +1,55 @@
;;; plugin-msg-enum-skel.el - vpp engine plug-in message enum 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-msg-enum
"Insert a plug-in message enumeration skeleton "
nil
'(if (not (boundp 'plugin-name))
(setq plugin-name (read-string "Plugin name: ")))
'(setq PLUGIN-NAME (upcase plugin-name))
"
/*
* " plugin-name "_msg_enum.h - skeleton vpp engine plug-in message enumeration
*
* 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.
*/
#ifndef included_" plugin-name "_msg_enum_h
#define included_" plugin-name "_msg_enum_h
#include <vppinfra/byte_order.h>
#define vl_msg_id(n,h) n,
typedef enum {
#include <" plugin-name "/" plugin-name "_all_api_h.h>
/* We'll want to know how many messages IDs we need... */
VL_MSG_FIRST_AVAILABLE,
} vl_msg_id_t;
#undef vl_msg_id
#endif /* included_" plugin-name "_msg_enum_h */
")

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,212 @@
;;; plugin-test-skel.el - vpp-api-test plug-in 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-test
"Insert a plug-in vpp-api-test 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 ".c - skeleton vpp-api-test plug-in
*
* 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 <vat/vat.h>
#include <vlibapi/api.h>
#include <vlibmemory/api.h>
#include <vlibsocket/api.h>
#include <vppinfra/error.h>
uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
/* Declare message IDs */
#include <" plugin-name "/" plugin-name "_msg_enum.h>
/* define message structures */
#define vl_typedefs
#include <" plugin-name "/" plugin-name "_all_api_h.h>
#undef vl_typedefs
/* declare message handlers for each api */
#define vl_endianfun /* define message structures */
#include <" plugin-name "/" plugin-name "_all_api_h.h>
#undef vl_endianfun
/* instantiate all the print functions we know about */
#define vl_print(handle, ...)
#define vl_printfun
#include <" plugin-name "/" plugin-name "_all_api_h.h>
#undef vl_printfun
/* Get the API version number. */
#define vl_api_version(n,v) static u32 api_version=(v);
#include <" plugin-name "/" plugin-name "_all_api_h.h>
#undef vl_api_version
typedef struct
{
/* API message ID base */
u16 msg_id_base;
vat_main_t *vat_main;
} " plugin-name "_test_main_t;
" plugin-name "_test_main_t " plugin-name "_test_main;
#define __plugin_msg_base " plugin-name"_test_main.msg_id_base
#include <vlibapi/vat_helper_macros.h>
#define foreach_standard_reply_retval_handler \\
_(" plugin-name "_enable_disable_reply)
#define _(n) \\
static void vl_api_##n##_t_handler \\
(vl_api_##n##_t * mp) \\
{ \\
vat_main_t * vam = " plugin-name "_test_main.vat_main; \\
i32 retval = ntohl(mp->retval); \\
if (vam->async_mode) { \\
vam->async_errors += (retval < 0); \\
} else { \\
vam->retval = retval; \\
vam->result_ready = 1; \\
} \\
}
foreach_standard_reply_retval_handler;
#undef _
/*
* Table of message reply handlers, must include boilerplate handlers
* we just generated
*/
#define foreach_vpe_api_reply_msg \\
_(" PLUGIN-NAME "_ENABLE_DISABLE_REPLY, " plugin-name "_enable_disable_reply)
static int api_" plugin-name "_enable_disable (vat_main_t * vam)
{
unformat_input_t * i = vam->input;
int enable_disable = 1;
u32 sw_if_index = ~0;
vl_api_" plugin-name "_enable_disable_t * mp;
int ret;
/* Parse args required to build the message */
while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
{
if (unformat (i, \"%U\", unformat_sw_if_index, vam, &sw_if_index))
;
else if (unformat (i, \"sw_if_index %d\", &sw_if_index))
;
else if (unformat (i, \"disable\"))
enable_disable = 0;
else
break;
}
if (sw_if_index == ~0)
{
errmsg (\"missing interface name / explicit sw_if_index number \\n\");
return -99;
}
/* Construct the API message */
M(" PLUGIN-NAME "_ENABLE_DISABLE, mp);
mp->sw_if_index = ntohl (sw_if_index);
mp->enable_disable = enable_disable;
/* send it... */
S(mp);
/* Wait for a reply... */
W (ret);
return ret;
}
/*
* List of messages that the api test plugin sends,
* and that the data plane plugin processes
*/
#define foreach_vpe_api_msg \\
_(" plugin-name "_enable_disable, \"<intfc> [disable]\")
static void " plugin-name "_api_hookup (vat_main_t *vam)
{
" plugin-name "_test_main_t * sm = &" plugin-name "_test_main;
/* Hook up handlers for replies from the data plane plug-in */
#define _(N,n) \\
vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \\
#n, \\
vl_api_##n##_t_handler, \\
vl_noop_handler, \\
vl_api_##n##_t_endian, \\
vl_api_##n##_t_print, \\
sizeof(vl_api_##n##_t), 1);
foreach_vpe_api_reply_msg;
#undef _
/* API messages we can send */
#define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
foreach_vpe_api_msg;
#undef _
/* Help strings */
#define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
foreach_vpe_api_msg;
#undef _
}
clib_error_t * vat_plugin_register (vat_main_t *vam)
{
" plugin-name "_test_main_t * sm = &" plugin-name "_test_main;
u8 * name;
sm->vat_main = vam;
/* Ask the vpp engine for the first assigned message-id */
name = format (0, \"" plugin-name "_%08x%c\", api_version, 0);
sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
if (sm->msg_id_base != (u16) ~0)
" plugin-name "_api_hookup (vam);
vec_free(name);
return 0;
}
/*
* fd.io coding-style-patch-verification: " capital-oh-en "
*
* Local Variables:
* eval: (c-set-style \"gnu\")
* End:
*/
")

32
extras/emacs/plugin.el Normal file
View File

@ -0,0 +1,32 @@
(defun make-plugin ()
"Create a plugin"
(interactive)
(save-excursion
(let (cd-args cmd-args start-dir)
(setq start-dir default-directory)
(makunbound 'plugin-name)
(makunbound 'PLUGIN-NAME)
(setq plugin-name (read-string "Plugin name: "))
(setq PLUGIN-NAME (upcase plugin-name))
(find-file (concat plugin-name ".am"))
(skel-plugin-makefile-am-fragment)
(setq cmd-args (concat "mkdir -p " plugin-name))
(shell-command cmd-args)
(setq cd-args (concat start-dir "/" plugin-name))
(setq default-directory cd-args)
(find-file (concat plugin-name ".api"))
(skel-plugin-api)
(find-file (concat plugin-name "_all_api_h.h"))
(skel-plugin-all-apih)
(find-file (concat plugin-name ".h"))
(skel-plugin-h)
(find-file (concat plugin-name ".c"))
(skel-plugin-main)
(find-file (concat plugin-name "_msg_enum.h"))
(skel-plugin-msg-enum)
(find-file "node.c")
(skel-plugin-node)
(find-file (concat plugin-name "_test.c"))
(skel-plugin-test)
(cd start-dir))))

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,299 @@
;;; tunnel-decap-skel.el - tunnel decapsulation skeleton
(require 'skeleton)
(define-skeleton skel-tunnel-decap
"Insert a tunnel decap implementation"
nil
'(setq encap_stack (skeleton-read "encap_stack (e.g ip4_udp_lisp): "))
'(setq ENCAP_STACK (upcase encap_stack))
'(setq encap-stack (replace-regexp-in-string "_" "-" encap_stack))
'(setq ENCAP-STACK (upcase encap-stack))
"
#include <vlib/vlib.h>
#include <vnet/pg/pg.h>
#include <vnet/" encap-stack "/" encap_stack ".h>
typedef struct {
u32 next_index;
u32 tunnel_index;
u32 error;
" encap_stack "_header_t h;
} " encap_stack "_rx_trace_t;
static u8 * format_" encap_stack "_rx_trace (u8 * s, va_list * args)
{
CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
" encap_stack "_rx_trace_t * t = va_arg (*args, " encap_stack "_rx_trace_t *);
if (t->tunnel_index != ~0)
{
s = format (s, \"" ENCAP-STACK ": tunnel %d next %d error %d\",
t->tunnel_index, t->next_index, t->error);
}
else
{
s = format (s, \"" ENCAP-STACK ": no tunnel next %d error %d\\n\",
t->next_index, t->error);
}
s = format (s, \"\\n %U\", format_" encap_stack "_header_with_length, &t->h,
(u32) sizeof (t->h) /* max size */);
return s;
}
static uword
" encap_stack "_input (vlib_main_t * vm,
vlib_node_runtime_t * node,
vlib_frame_t * from_frame)
{
u32 n_left_from, next_index, * from, * to_next;
" encap_stack "_main_t * ngm = &" encap_stack "_main;
u32 last_tunnel_index = ~0;
" encap_stack "_tunnel_key_t last_key;
u32 pkts_decapsulated = 0;
memset (&last_key, 0xff, sizeof (last_key));
from = vlib_frame_vector_args (from_frame);
n_left_from = from_frame->n_vectors;
next_index = node->cached_next_index;
while (n_left_from > 0)
{
u32 n_left_to_next;
vlib_get_next_frame (vm, node, next_index,
to_next, n_left_to_next);
#if 0 /* $$$ dual loop when the single loop works */
while (n_left_from >= 4 && n_left_to_next >= 2)
{
u32 bi0, bi1;
vlib_buffer_t * b0, * b1;
nsh_unicast_header_t * h0, * h1;
u32 label0, label1;
u32 next0, next1;
uword * p0, * p1;
/* Prefetch next iteration. */
{
vlib_buffer_t * p2, * p3;
p2 = vlib_get_buffer (vm, from[2]);
p3 = vlib_get_buffer (vm, from[3]);
vlib_prefetch_buffer_header (p2, LOAD);
vlib_prefetch_buffer_header (p3, LOAD);
CLIB_PREFETCH (p2->data, 2*CLIB_CACHE_LINE_BYTES, LOAD);
CLIB_PREFETCH (p3->data, 2*CLIB_CACHE_LINE_BYTES, LOAD);
}
bi0 = from[0];
bi1 = from[1];
to_next[0] = bi0;
to_next[1] = bi1;
from += 2;
to_next += 2;
n_left_to_next -= 2;
n_left_from -= 2;
b0 = vlib_get_buffer (vm, bi0);
b1 = vlib_get_buffer (vm, bi1);
h0 = vlib_buffer_get_current (b0);
h1 = vlib_buffer_get_current (b1);
next0 = next1 = " ENCAP_STACK "_INPUT_NEXT_IP4_INPUT;
label0 = clib_net_to_host_u32 (h0->label_exp_s_ttl);
label1 = clib_net_to_host_u32 (h1->label_exp_s_ttl);
/*
* Translate label contents into a fib index.
* This is a decent sanity check, and guarantees
* a sane FIB for the downstream lookup
*/
label0 = vnet_nsh_uc_get_label (label0);
label1 = vnet_nsh_uc_get_label (label1);
/* If 2xlabels match, and match the 1-wide cache, use it */
if (label0 == label1 && rt->last_label == label0)
{
vnet_buffer(b0)->sw_if_index[VLIB_TX] = rt->last_fib_index;
vnet_buffer(b1)->sw_if_index[VLIB_TX] = rt->last_fib_index;
}
else
{
p0 = hash_get (rt->mm->fib_index_by_nsh_label, label0);
if (PREDICT_FALSE (p0 == 0))
{
next0 = " ENCAP_STACK "_INPUT_NEXT_DROP;
b0->error = node->errors[NSH_ERROR_BAD_LABEL];
}
else
vnet_buffer(b0)->sw_if_index[VLIB_TX] = p0[0];
p1 = hash_get (rt->mm->fib_index_by_nsh_label, label1);
if (PREDICT_FALSE (p1 == 0))
{
next1 = " ENCAP_STACK "_INPUT_NEXT_DROP;
b1->error = node->errors[NSH_ERROR_BAD_LABEL];
}
else
{
vnet_buffer(b1)->sw_if_index[VLIB_TX] = p1[0];
rt->last_fib_index = p1[0];
rt->last_label = label1;
}
}
if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED))
{
nsh_rx_trace_t *tr = vlib_add_trace (vm, node,
b0, sizeof (*tr));
tr->label_exp_s_ttl = label0;
}
if (PREDICT_FALSE(b1->flags & VLIB_BUFFER_IS_TRACED))
{
nsh_rx_trace_t *tr = vlib_add_trace (vm, node,
b1, sizeof (*tr));
tr->label_exp_s_ttl = label1;
}
vlib_buffer_advance (b0, sizeof (*h0));
vlib_buffer_advance (b1, sizeof (*h1));
vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
to_next, n_left_to_next,
bi0, bi1, next0, next1);
}
#endif
while (n_left_from > 0 && n_left_to_next > 0)
{
u32 bi0;
vlib_buffer_t * b0;
u32 next0;
" encap_stack "_header_t * iuX0;
uword * p0;
u32 tunnel_index0;
" encap_stack "_tunnel_t * t0;
" encap_stack "_tunnel_key_t key0;
u32 error0;
bi0 = from[0];
to_next[0] = bi0;
from += 1;
to_next += 1;
n_left_from -= 1;
n_left_to_next -= 1;
b0 = vlib_get_buffer (vm, bi0);
/*
* udp leaves current_data pointing at the tunnel header
* $$$$ FIXME
*/
vlib_buffer_advance
(b0, -(word)(sizeof(udp_header_t)+sizeof(ip4_header_t)));
iuX0 = vlib_buffer_get_current (b0);
/* pop (ip, udp, lisp-gpe) */
vlib_buffer_advance (b0, sizeof (*iuX0));
tunnel_index0 = ~0;
error0 = 0;
next0 = " ENCAP_STACK "_INPUT_NEXT_DROP;
key0.src = iuX0->ip4.src_address.as_u32;
key0.iid = iuX0->lisp.iid;
/* $$$ validate key comparison */
if (PREDICT_FALSE ((key0.as_u64[0] != last_key.as_u64[0])))
{
p0 = hash_get_mem (ngm->" encap_stack "_tunnel_by_key, &key0);
if (p0 == 0)
{
error0 = " ENCAP_STACK "_ERROR_NO_SUCH_TUNNEL;
goto trace0;
}
last_key.as_u64[0] = key0.as_u64[0];
tunnel_index0 = last_tunnel_index = p0[0];
}
else
tunnel_index0 = last_tunnel_index;
t0 = pool_elt_at_index (ngm->tunnels, tunnel_index0);
next0 = t0->decap_next_index;
/* Required to make the l2 tag push / pop code work on l2 subifs */
vnet_update_l2_len (b0);
/*
* ip[46] lookup in the configured FIB
* " encap-stack ", here's the encap tunnel sw_if_index
*/
vnet_buffer(b0)->sw_if_index[VLIB_TX] = t0->decap_fib_index;
pkts_decapsulated ++;
trace0:
b0->error = error0 ? node->errors[error0] : 0;
if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED))
{
" encap_stack "_rx_trace_t *tr
= vlib_add_trace (vm, node, b0, sizeof (*tr));
tr->next_index = next0;
tr->error = error0;
tr->tunnel_index = tunnel_index0;
tr->h = iuX0->lisp;
}
vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
to_next, n_left_to_next,
bi0, next0);
}
vlib_put_next_frame (vm, node, next_index, n_left_to_next);
}
vlib_node_increment_counter (vm, " encap_stack "_input_node.index,
" ENCAP_STACK "_ERROR_DECAPSULATED,
pkts_decapsulated);
return from_frame->n_vectors;
}
static char * " encap_stack "_error_strings[] = {
#define " encap_stack "_error(n,s) s,
#include <vnet/" encap-stack "/" encap_stack "_error.def>
#undef " encap_stack "_error
#undef _
};
VLIB_REGISTER_NODE (" encap_stack "_input_node) = {
.function = \"" encap_stack "_input\",
.name = \"" encap-stack "-input\",
/* Takes a vector of packets. */
.vector_size = sizeof (u32),
.n_errors = " ENCAP_STACK "_N_ERROR,
.error_strings = " encap_stack "_error_strings,
.n_next_nodes = " ENCAP_STACK "_INPUT_N_NEXT,
.next_nodes = {
#define _(s,n) [" ENCAP_STACK "_INPUT_NEXT_##s] = n,
foreach_" encap_stack "_input_next
#undef _
},
.format_buffer = format_" encap_stack "_header_with_length,
.format_trace = format_" encap_stack "_rx_trace,
// $$$$ .unformat_buffer = unformat_" encap_stack "_header,
};
")

View File

@ -0,0 +1,245 @@
;;; tunnel-encap-skel.el - tunnel interface output skeleton
(require 'skeleton)
(define-skeleton skel-tunnel-encap
"Insert a tunnel encap implementation"
nil
'(setq encap_stack (skeleton-read "encap_stack (e.g ip4_udp_lisp): "))
'(setq ENCAP_STACK (upcase encap_stack))
'(setq encap-stack (replace-regexp-in-string "_" "-" encap_stack))
'(setq ENCAP-STACK (upcase encap-stack))
"
#include <vppinfra/error.h>
#include <vppinfra/hash.h>
#include <vnet/vnet.h>
#include <vnet/ip/ip.h>
#include <vnet/ethernet/ethernet.h>
#include <vnet/" encap-stack "/" encap_stack ".h>
/* Statistics (not really errors) */
#define foreach_" encap_stack "_encap_error \\
_(ENCAPSULATED, \"good packets encapsulated\")
static char * " encap_stack "_encap_error_strings[] = {
#define _(sym,string) string,
foreach_" encap_stack "_encap_error
#undef _
};
typedef enum {
#define _(sym,str) " ENCAP_STACK "_ENCAP_ERROR_##sym,
foreach_" encap_stack "_encap_error
#undef _
" ENCAP_STACK "_ENCAP_N_ERROR,
} " encap_stack "_encap_error_t;
typedef enum {
" ENCAP_STACK "_ENCAP_NEXT_IP4_LOOKUP,
" ENCAP_STACK "_ENCAP_NEXT_DROP,
" ENCAP_STACK "_ENCAP_N_NEXT,
} " encap_stack "_encap_next_t;
typedef struct {
u32 tunnel_index;
} " encap_stack "_encap_trace_t;
u8 * format_" encap_stack "_encap_trace (u8 * s, va_list * args)
{
CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
" encap_stack "_encap_trace_t * t
= va_arg (*args, " encap_stack "_encap_trace_t *);
s = format (s, \"" ENCAP-STACK ": tunnel %d\", t->tunnel_index);
return s;
}
/* $$$$ FIXME adjust to match the rewrite string */
#define foreach_fixed_header_offset \\
_(0) _(1) _(2) _(3) _(FIXME)
static uword
" encap_stack "_encap (vlib_main_t * vm,
vlib_node_runtime_t * node,
vlib_frame_t * from_frame)
{
u32 n_left_from, next_index, * from, * to_next;
" encap_stack "_main_t * ngm = &" encap_stack "_main;
vnet_main_t * vnm = ngm->vnet_main;
u32 pkts_encapsulated = 0;
u16 old_l0 = 0, old_l1 = 0;
from = vlib_frame_vector_args (from_frame);
n_left_from = from_frame->n_vectors;
next_index = node->cached_next_index;
while (n_left_from > 0)
{
u32 n_left_to_next;
vlib_get_next_frame (vm, node, next_index,
to_next, n_left_to_next);
#if 0 /* $$$ dual loop when the single loop works */
while (n_left_from >= 4 && n_left_to_next >= 2)
{
u32 bi0, bi1;
vlib_buffer_t * b0, * b1;
nsh_unicast_header_t * h0, * h1;
u32 label0, label1;
u32 next0, next1;
uword * p0, * p1;
/* Prefetch next iteration. */
{
vlib_buffer_t * p2, * p3;
p2 = vlib_get_buffer (vm, from[2]);
p3 = vlib_get_buffer (vm, from[3]);
vlib_prefetch_buffer_header (p2, LOAD);
vlib_prefetch_buffer_header (p3, LOAD);
CLIB_PREFETCH (p2->data, 2*CLIB_CACHE_LINE_BYTES, LOAD);
CLIB_PREFETCH (p3->data, 2*CLIB_CACHE_LINE_BYTES, LOAD);
}
bi0 = from[0];
bi1 = from[1];
to_next[0] = bi0;
to_next[1] = bi1;
from += 2;
to_next += 2;
n_left_to_next -= 2;
n_left_from -= 2;
b0 = vlib_get_buffer (vm, bi0);
b1 = vlib_get_buffer (vm, bi1);
h0 = vlib_buffer_get_current (b0);
h1 = vlib_buffer_get_current (b1);
next0 = next1 = " ENCAP_STACK "_ENCAP_NEXT_IP4_LOOKUP;
vlib_buffer_advance (b0, sizeof (*h0));
vlib_buffer_advance (b1, sizeof (*h1));
vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
to_next, n_left_to_next,
bi0, bi1, next0, next1);
}
#endif
while (n_left_from > 0 && n_left_to_next > 0)
{
u32 bi0;
vlib_buffer_t * b0;
u32 next0 = " ENCAP_STACK "_ENCAP_NEXT_IP4_LOOKUP;
vnet_hw_interface_t * hi0;
ip4_header_t * ip0;
udp_header_t * udp0;
u64 * copy_src0, * copy_dst0;
u32 * copy_src_last0, * copy_dst_last0;
" encap_stack "_tunnel_t * t0;
u16 new_l0;
ip_csum_t sum0;
bi0 = from[0];
to_next[0] = bi0;
from += 1;
to_next += 1;
n_left_from -= 1;
n_left_to_next -= 1;
b0 = vlib_get_buffer (vm, bi0);
/* 1-wide cache? */
hi0 = vnet_get_sup_hw_interface
(vnm, vnet_buffer(b0)->sw_if_index[VLIB_TX]);
t0 = pool_elt_at_index (ngm->tunnels, hi0->dev_instance);
ASSERT(vec_len(t0->rewrite) >= 24);
/* Apply the rewrite string. $$$$ vnet_rewrite? */
vlib_buffer_advance (b0, -(word)_vec_len(t0->rewrite));
ip0 = vlib_buffer_get_current(b0);
/* Copy the fixed header */
copy_dst0 = (u64 *) ip0;
copy_src0 = (u64 *) t0->rewrite;
ASSERT (sizeof (ip4_udp_" encap_stack "_header_t) == FIXME);
/* Copy first N octets 8-bytes at a time */
#define _(offs) copy_dst0[offs] = copy_src0[offs];
foreach_fixed_header_offset;
#undef _
#if 0 /* needed if encap not a multiple of 8 bytes */
/* Last 4 octets. Hopefully gcc will be our friend */
copy_dst_last0 = (u32 *)(&copy_dst0[FIXME]);
copy_src_last0 = (u32 *)(&copy_src0[FIXME]);
copy_dst_last0[0] = copy_src_last0[0];
#endif
/* fix the <bleep>ing outer-IP checksum */
sum0 = ip0->checksum;
/* old_l0 always 0, see the rewrite setup */
new_l0 =
clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b0));
sum0 = ip_csum_update (sum0, old_l0, new_l0, ip4_header_t,
length /* changed member */);
ip0->checksum = ip_csum_fold (sum0);
ip0->length = new_l0;
/* Fix UDP length */
udp0 = (udp_header_t *)(ip0+1);
new_l0 = clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b0)
- sizeof (*ip0));
udp0->length = new_l0;
/* Reset to look up tunnel partner in the configured FIB */
vnet_buffer(b0)->sw_if_index[VLIB_TX] = t0->encap_fib_index;
pkts_encapsulated ++;
if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED))
{
" encap_stack "_encap_trace_t *tr =
vlib_add_trace (vm, node, b0, sizeof (*tr));
tr->tunnel_index = t0 - ngm->tunnels;
}
vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
to_next, n_left_to_next,
bi0, next0);
}
vlib_put_next_frame (vm, node, next_index, n_left_to_next);
}
vlib_node_increment_counter (vm, node->node_index,
" ENCAP_STACK "_ENCAP_ERROR_ENCAPSULATED,
pkts_encapsulated);
return from_frame->n_vectors;
}
VLIB_REGISTER_NODE (" encap_stack "_encap_node) = {
.function = " encap_stack "_encap,
.name = \"" encap-stack "-encap\",
.vector_size = sizeof (u32),
.format_trace = format_" encap_stack "_encap_trace,
.type = VLIB_NODE_TYPE_INTERNAL,
.n_errors = ARRAY_LEN(" encap_stack "_encap_error_strings),
.error_strings = " encap_stack "_encap_error_strings,
.n_next_nodes = " ENCAP_STACK "_ENCAP_N_NEXT,
.next_nodes = {
[" ENCAP_STACK "_ENCAP_NEXT_IP4_LOOKUP] = \"ip4-lookup\",
[" ENCAP_STACK "_ENCAP_NEXT_DROP] = \"error-drop\",
},
};
")

View File

@ -0,0 +1,128 @@
;;; tunnel-h-skel.el - tunnel encap header file skeleton
(require 'skeleton)
(define-skeleton skel-tunnel-h
"Insert a tunnel encap header file"
nil
'(setq encap_stack (skeleton-read "encap_stack (e.g ip4_udp_lisp): "))
'(setq ENCAP_STACK (upcase encap_stack))
'(setq encap-stack (replace-regexp-in-string "_" "-" encap_stack))
"
#ifndef included_vnet_" encap_stack "_h
#define included_vnet_" encap_stack "_h
#include <vppinfra/error.h>
#include <vppinfra/hash.h>
#include <vnet/vnet.h>
#include <vnet/ip/ip.h>
#include <vnet/l2/l2_input.h>
#include <vnet/ethernet/ethernet.h>
#include <vnet/" encap-stack "/" encap_stack "_packet.h>
#include <vnet/ip/ip4_packet.h>
#include <vnet/ip/udp.h>
/* Encap stack built in encap.c */
typedef CLIB_PACKED (struct {
ip4_header_t ip4; /* 20 bytes */
udp_header_t udp; /* 8 bytes */
" encap_stack "_header_t lisp; /* 8 bytes */
}) " encap_stack "_header_t;
typedef CLIB_PACKED(struct {
/*
* Key fields:
* all fields in NET byte order
*/
union {
struct {
u32 FIXME_NET_BYTE_ORDER;
};
u64 as_u64[1];
};
}) " encap_stack "_tunnel_key_t;
typedef struct {
/* Rewrite string. $$$$ maybe: embed vnet_rewrite header */
u8 * rewrite;
/* decap next index */
u32 decap_next_index;
/* tunnel src and dst addresses */
ip4_address_t src;
ip4_address_t dst;
/* FIB indices */
u32 encap_fib_index; /* tunnel partner lookup here */
u32 decap_fib_index; /* inner IP lookup here */
/* vnet intfc hw/sw_if_index */
u32 hw_if_index;
/* encap header fields in HOST byte order */
u32 FIXME;
} " encap_stack "_tunnel_t;
#define foreach_" encap_stack "_input_next \\
_(DROP, \"error-drop\") \\
_(IP4_INPUT, \"ip4-input\") \\
_(IP6_INPUT, \"ip6-input\") \\
_(ETHERNET_INPUT, \"ethernet-input\") \\
_(" ENCAP_STACK "_ENCAP, \"" encap-stack "-encap\")
typedef enum {
#define _(s,n) " ENCAP_STACK "_INPUT_NEXT_##s,
foreach_" encap_stack "_input_next
#undef _
" ENCAP_STACK "_INPUT_N_NEXT,
} " encap_stack "_input_next_t;
typedef enum {
#define " encap_stack "_error(n,s) " ENCAP_STACK "_ERROR_##n,
#include <vnet/" encap-stack "/" encap_stack "_error.def>
#undef " encap_stack "_error
" ENCAP_STACK "_N_ERROR,
} " encap_stack "_input_error_t;
typedef struct {
/* vector of encap tunnel instances */
" encap_stack "_tunnel_t *tunnels;
/* lookup tunnel by key */
uword * " encap_stack "_tunnel_by_key;
/* Free vlib hw_if_indices */
u32 * free_" encap_stack "_tunnel_hw_if_indices;
/* convenience */
vlib_main_t * vlib_main;
vnet_main_t * vnet_main;
} " encap_stack "_main_t;
" encap_stack "_main_t " encap_stack "_main;
vlib_node_registration_t " encap_stack "_input_node;
vlib_node_registration_t " encap_stack "_encap_node;
u8 * format_" encap_stack "_encap_trace (u8 * s, va_list * args);
u8 * format_" encap_stack "_header_with_length (u8 * s, va_list * args);
typedef struct {
u8 is_add;
ip4_address_t src, dst;
u32 encap_fib_index;
u32 decap_fib_index;
u32 decap_next_index;
/* encap fields in HOST byte order */
u8 FIXME_HOST_BYTE_ORDER;
} vnet_" encap_stack "_add_del_tunnel_args_t;
int vnet_" encap_stack "_add_del_tunnel
(vnet_" encap_stack "_add_del_tunnel_args_t *a, u32 * hw_if_indexp);
u8 * format_" encap_stack "_header_with_length (u8 * s, va_list * args);
#endif /* included_vnet_" encap_stack "_h */
")