Initial commit of vpp code.
Change-Id: Ib246f1fbfce93274020ee93ce461e3d8bd8b9f17 Signed-off-by: Ed Warnicke <eaw@cisco.com>
This commit is contained in:
11
build-root/emacs-lisp/all-skel.el
Normal file
11
build-root/emacs-lisp/all-skel.el
Normal file
@ -0,0 +1,11 @@
|
||||
;; list of clib / vlib / vnet / vpp skeleton files
|
||||
|
||||
(load-file "./cli-cmd-skel.el")
|
||||
(load-file "./pipe-skel.el")
|
||||
(load-file "./dual-loop-skel.el")
|
||||
(load-file "./periodic-skel.el")
|
||||
(load-file "./config-skel.el")
|
||||
(load-file "./tunnel-c-skel.el")
|
||||
(load-file "./tunnel-h-skel.el")
|
||||
(load-file "./tunnel-encap-skel.el")
|
||||
(load-file "./tunnel-decap-skel.el")
|
32
build-root/emacs-lisp/cli-cmd-skel.el
Normal file
32
build-root/emacs-lisp/cli-cmd-skel.el
Normal file
@ -0,0 +1,32 @@
|
||||
;;; cli-cmd-skel.el - cli command skeleton
|
||||
|
||||
(require 'skeleton)
|
||||
|
||||
(define-skeleton cli-cmd-skel
|
||||
"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,
|
||||
};
|
||||
")
|
28
build-root/emacs-lisp/config-skel.el
Normal file
28
build-root/emacs-lisp/config-skel.el
Normal file
@ -0,0 +1,28 @@
|
||||
;;; config-skel.el - config function command skeleton
|
||||
|
||||
(require 'skeleton)
|
||||
|
||||
(define-skeleton config-skel
|
||||
"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 "\");
|
||||
")
|
290
build-root/emacs-lisp/dual-loop-skel.el
Normal file
290
build-root/emacs-lisp/dual-loop-skel.el
Normal file
@ -0,0 +1,290 @@
|
||||
;;; dual-loop-skel.el - Eliotic dual-loop node skeleton
|
||||
|
||||
(require 'skeleton)
|
||||
|
||||
(define-skeleton dual-loop-skel
|
||||
"Insert a skeleton dual-loop graph node"
|
||||
nil
|
||||
'(setq node-name (skeleton-read "Node Name: "))
|
||||
'(setq uc-node-name (upcase node-name))
|
||||
"
|
||||
#include <vlib/vlib.h>
|
||||
#include <vnet/vnet.h>
|
||||
#include <vnet/pg/pg.h>
|
||||
#include <clib/error.h>
|
||||
|
||||
#include <vnet/ip/ip.h>
|
||||
#include <vnet/ethernet/ethernet.h>
|
||||
|
||||
#include <clib/hash.h>
|
||||
#include <clib/error.h>
|
||||
#include <clib/elog.h>
|
||||
|
||||
typedef struct {
|
||||
/* convenience */
|
||||
vlib_main_t * vlib_main;
|
||||
vnet_main_t * vnet_main;
|
||||
ethernet_main_t * ethernet_main;
|
||||
} " node-name "_main_t;
|
||||
|
||||
" node-name "_main_t " node-name "_main;
|
||||
|
||||
vlib_node_registration_t " node-name "_node;
|
||||
|
||||
typedef struct {
|
||||
u32 next_index;
|
||||
u32 sw_if_index;
|
||||
} " node-name "_trace_t;
|
||||
|
||||
/* packet trace format function */
|
||||
static u8 * format_" node-name "_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 *);
|
||||
" node-name "_trace_t * t = va_arg (*args, " node-name "_trace_t *);
|
||||
|
||||
s = format (s, \"" uc-node-name ": sw_if_index %d, next index %d\",
|
||||
t->sw_if_index, t->next_index);
|
||||
return s;
|
||||
}
|
||||
|
||||
vlib_node_registration_t " node-name "_node;
|
||||
|
||||
#define foreach_" node-name "_error \\
|
||||
_(SWAPPED, \"Mac swap packets processed\")
|
||||
|
||||
typedef enum {
|
||||
#define _(sym,str) " uc-node-name "_ERROR_##sym,
|
||||
foreach_" node-name "_error
|
||||
#undef _
|
||||
" uc-node-name "_N_ERROR,
|
||||
} " node-name "_error_t;
|
||||
|
||||
static char * " node-name "_error_strings[] = {
|
||||
#define _(sym,string) string,
|
||||
foreach_" node-name "_error
|
||||
#undef _
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
" uc-node-name "_NEXT_INTERFACE_OUTPUT,
|
||||
" uc-node-name "_N_NEXT,
|
||||
} " node-name "_next_t;
|
||||
|
||||
#define foreach_mac_address_offset \\
|
||||
_(0) \\
|
||||
_(1) \\
|
||||
_(2) \\
|
||||
_(3) \\
|
||||
_(4) \\
|
||||
_(5)
|
||||
|
||||
static uword
|
||||
" node-name "_node_fn (vlib_main_t * vm,
|
||||
vlib_node_runtime_t * node,
|
||||
vlib_frame_t * frame)
|
||||
{
|
||||
u32 n_left_from, * from, * to_next;
|
||||
" node-name "_next_t next_index;
|
||||
u32 pkts_swapped = 0;
|
||||
|
||||
from = vlib_frame_vector_args (frame);
|
||||
n_left_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);
|
||||
|
||||
while (n_left_from >= 4 && n_left_to_next >= 2)
|
||||
{
|
||||
u32 next0 = " uc-node-name "_NEXT_INTERFACE_OUTPUT;
|
||||
u32 next1 = " uc-node-name "_NEXT_INTERFACE_OUTPUT;
|
||||
u32 sw_if_index0, sw_if_index1;
|
||||
u8 tmp0[6], tmp1[6];
|
||||
ethernet_header_t *en0, *en1;
|
||||
u32 bi0, bi1;
|
||||
vlib_buffer_t * b0, * b1;
|
||||
|
||||
/* 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, CLIB_CACHE_LINE_BYTES, STORE);
|
||||
CLIB_PREFETCH (p3->data, CLIB_CACHE_LINE_BYTES, STORE);
|
||||
}
|
||||
|
||||
/* speculatively enqueue b0 and b1 to the current next frame */
|
||||
to_next[0] = bi0 = from[0];
|
||||
to_next[1] = bi1 = from[1];
|
||||
from += 2;
|
||||
to_next += 2;
|
||||
n_left_from -= 2;
|
||||
n_left_to_next -= 2;
|
||||
|
||||
b0 = vlib_get_buffer (vm, bi0);
|
||||
b1 = vlib_get_buffer (vm, bi1);
|
||||
|
||||
/* $$$$$ Dual loop: process 2 x packets here $$$$$ */
|
||||
ASSERT (b0->current_data == 0);
|
||||
ASSERT (b1->current_data == 0);
|
||||
|
||||
en0 = vlib_buffer_get_current (b0);
|
||||
en1 = vlib_buffer_get_current (b1);
|
||||
|
||||
/* This is not the fastest way to swap src + dst mac addresses */
|
||||
#define _(a) tmp0[a] = en0->src_address[a];
|
||||
foreach_mac_address_offset;
|
||||
#undef _
|
||||
#define _(a) en0->src_address[a] = en0->dst_address[a];
|
||||
foreach_mac_address_offset;
|
||||
#undef _
|
||||
#define _(a) en0->dst_address[a] = tmp0[a];
|
||||
foreach_mac_address_offset;
|
||||
#undef _
|
||||
|
||||
#define _(a) tmp1[a] = en1->src_address[a];
|
||||
foreach_mac_address_offset;
|
||||
#undef _
|
||||
#define _(a) en1->src_address[a] = en1->dst_address[a];
|
||||
foreach_mac_address_offset;
|
||||
#undef _
|
||||
#define _(a) en1->dst_address[a] = tmp1[a];
|
||||
foreach_mac_address_offset;
|
||||
#undef _
|
||||
|
||||
sw_if_index0 = vnet_buffer(b0)->sw_if_index[VLIB_RX];
|
||||
sw_if_index1 = vnet_buffer(b1)->sw_if_index[VLIB_RX];
|
||||
|
||||
/* Send pkt back out the RX interface */
|
||||
vnet_buffer(b0)->sw_if_index[VLIB_TX] = sw_if_index0;
|
||||
vnet_buffer(b1)->sw_if_index[VLIB_TX] = sw_if_index1;
|
||||
|
||||
pkts_swapped += 2;
|
||||
/* $$$$$ End of processing 2 x packets $$$$$ */
|
||||
|
||||
if (PREDICT_FALSE((node->flags & VLIB_NODE_FLAG_TRACE)))
|
||||
{
|
||||
if (b0->flags & VLIB_BUFFER_IS_TRACED)
|
||||
{
|
||||
" node-name "_trace_t *t =
|
||||
vlib_add_trace (vm, node, b0, sizeof (*t));
|
||||
t->sw_if_index = sw_if_index0;
|
||||
t->next_index = next0;
|
||||
}
|
||||
if (b1->flags & VLIB_BUFFER_IS_TRACED)
|
||||
{
|
||||
" node-name "_trace_t *t =
|
||||
vlib_add_trace (vm, node, b1, sizeof (*t));
|
||||
t->sw_if_index = sw_if_index1;
|
||||
t->next_index = next1;
|
||||
}
|
||||
}
|
||||
|
||||
/* verify speculative enqueues, maybe switch current next frame */
|
||||
vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
|
||||
to_next, n_left_to_next,
|
||||
bi0, bi1, next0, next1);
|
||||
}
|
||||
|
||||
while (n_left_from > 0 && n_left_to_next > 0)
|
||||
{
|
||||
u32 bi0;
|
||||
vlib_buffer_t * b0;
|
||||
u32 next0 = " uc-node-name "_NEXT_INTERFACE_OUTPUT;
|
||||
u32 sw_if_index0;
|
||||
u8 tmp0[6];
|
||||
ethernet_header_t *en0;
|
||||
|
||||
/* speculatively enqueue b0 to the current next frame */
|
||||
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);
|
||||
|
||||
/* $$$$$ Single loop: process 1 packet here $$$$$ */
|
||||
|
||||
/*
|
||||
* Direct from the driver, we should be at offset 0
|
||||
* aka at &b0->data[0]
|
||||
*/
|
||||
ASSERT (b0->current_data == 0);
|
||||
|
||||
en0 = vlib_buffer_get_current (b0);
|
||||
|
||||
/* This is not the fastest way to swap src + dst mac addresses */
|
||||
#define _(a) tmp0[a] = en0->src_address[a];
|
||||
foreach_mac_address_offset;
|
||||
#undef _
|
||||
#define _(a) en0->src_address[a] = en0->dst_address[a];
|
||||
foreach_mac_address_offset;
|
||||
#undef _
|
||||
#define _(a) en0->dst_address[a] = tmp0[a];
|
||||
foreach_mac_address_offset;
|
||||
#undef _
|
||||
|
||||
sw_if_index0 = vnet_buffer(b0)->sw_if_index[VLIB_RX];
|
||||
|
||||
/* Send pkt back out the RX interface */
|
||||
vnet_buffer(b0)->sw_if_index[VLIB_TX] = sw_if_index0;
|
||||
|
||||
if (PREDICT_FALSE((node->flags & VLIB_NODE_FLAG_TRACE)
|
||||
&& (b0->flags & VLIB_BUFFER_IS_TRACED)))
|
||||
{
|
||||
" node-name "_trace_t *t =
|
||||
vlib_add_trace (vm, node, b0, sizeof (*t));
|
||||
t->sw_if_index = sw_if_index0;
|
||||
t->next_index = next0;
|
||||
}
|
||||
|
||||
pkts_swapped += 1;
|
||||
|
||||
/* $$$$$ Done processing 1 packet here $$$$$ */
|
||||
|
||||
/* verify speculative enqueue, maybe switch current next frame */
|
||||
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-name "_node.index,
|
||||
" uc-node-name "_ERROR_SWAPPED, pkts_swapped);
|
||||
return frame->n_vectors;
|
||||
}
|
||||
|
||||
VLIB_REGISTER_NODE (" node-name "_node) = {
|
||||
.function = " node-name "_node_fn,
|
||||
.name = \"" node-name "\",
|
||||
.vector_size = sizeof (u32),
|
||||
.format_trace = format_" node-name "_trace,
|
||||
.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_INTERFACE_OUTPUT] = \"interface-output\",
|
||||
},
|
||||
};
|
||||
|
||||
")
|
||||
|
86
build-root/emacs-lisp/periodic-skel.el
Normal file
86
build-root/emacs-lisp/periodic-skel.el
Normal file
@ -0,0 +1,86 @@
|
||||
;;; pipe-skel.el - pipelined graph node skeleton
|
||||
|
||||
(require 'skeleton)
|
||||
|
||||
(define-skeleton periodic-skel
|
||||
"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
build-root/emacs-lisp/pipe-skel.el
Normal file
132
build-root/emacs-lisp/pipe-skel.el
Normal file
@ -0,0 +1,132 @@
|
||||
;;; pipe-skel.el - pipelined graph node skeleton
|
||||
|
||||
(require 'skeleton)
|
||||
|
||||
(define-skeleton pipeline-node-skel
|
||||
"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 <clib/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 }
|
||||
}
|
||||
*/
|
||||
")
|
441
build-root/emacs-lisp/tunnel-c-skel.el
Normal file
441
build-root/emacs-lisp/tunnel-c-skel.el
Normal file
File diff suppressed because it is too large
Load Diff
299
build-root/emacs-lisp/tunnel-decap-skel.el
Normal file
299
build-root/emacs-lisp/tunnel-decap-skel.el
Normal file
@ -0,0 +1,299 @@
|
||||
;;; tunnel-decap-skel.el - tunnel decapsulation skeleton
|
||||
|
||||
(require 'skeleton)
|
||||
|
||||
(define-skeleton tunnel-decap-skel
|
||||
"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,
|
||||
};
|
||||
|
||||
")
|
245
build-root/emacs-lisp/tunnel-encap-skel.el
Normal file
245
build-root/emacs-lisp/tunnel-encap-skel.el
Normal file
@ -0,0 +1,245 @@
|
||||
;;; tunnel-encap-skel.el - tunnel interface output skeleton
|
||||
|
||||
(require 'skeleton)
|
||||
|
||||
(define-skeleton tunnel-encap-skel
|
||||
"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 <clib/error.h>
|
||||
#include <clib/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 *)(©_dst0[FIXME]);
|
||||
copy_src_last0 = (u32 *)(©_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\",
|
||||
},
|
||||
};
|
||||
")
|
128
build-root/emacs-lisp/tunnel-h-skel.el
Normal file
128
build-root/emacs-lisp/tunnel-h-skel.el
Normal file
@ -0,0 +1,128 @@
|
||||
;;; tunnel-h-skel.el - tunnel encap header file skeleton
|
||||
|
||||
(require 'skeleton)
|
||||
|
||||
(define-skeleton tunnel-h-skel
|
||||
"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 <clib/error.h>
|
||||
#include <clib/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 */
|
||||
|
||||
")
|
Reference in New Issue
Block a user