1 ;;; Copyright (c) 2016 Cisco and/or its affiliates.
2 ;;; Licensed under the Apache License, Version 2.0 (the "License");
3 ;;; you may not use this file except in compliance with the License.
4 ;;; You may obtain a copy of the License at:
6 ;;; http://www.apache.org/licenses/LICENSE-2.0
8 ;;; Unless required by applicable law or agreed to in writing, software
9 ;;; distributed under the License is distributed on an "AS IS" BASIS,
10 ;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 ;;; See the License for the specific language governing permissions and
12 ;;; limitations under the License.
14 ;;; pipe-skel.el - pipelined graph node skeleton
18 (define-skeleton skel-pipeline-node
19 "Insert a skeleton pipelined graph node"
21 '(setq node-name (skeleton-read "Node Name: "))
22 '(setq uc-node-name (upcase node-name))
23 '(setq nstages (skeleton-read "Number of pipeline stages: "))
25 #include <vlib/vlib.h>
26 #include <vppinfra/error.h>
29 * Dump these counters via the \"show error\" CLI command
30 * FIXME: Add packet counter / error strings as desired
33 #define foreach_" node-name "_error \\
34 _(ERROR1, \"sample counter/ error string\")
36 static char * " node-name "_error_strings[] = {
37 #define _(sym,string) string,
38 foreach_" node-name "_error
43 * packet error / counter enumeration
45 * To count and drop a vlib_buffer_t *b:
47 * Set b->error = node->errors[" uc-node-name "_ERROR_xxx];
48 * last_stage returns a disposition index bound to \"error-drop\"
50 * To manually increment the specific counter " uc-node-name "_ERROR1
52 * vlib_node_t *n = vlib_get_node (vm, " node-name ".index);
53 * u32 node_counter_base_index = n->error_heap_index;
54 * vlib_error_main_t * em = &vm->error_main;
55 * em->counters[node_counter_base_index + " uc-node-name "_ERROR1] += 1;
60 #define _(sym,str) " uc-node-name "_ERROR_##sym,
61 foreach_" node-name "_error
63 " uc-node-name "_N_ERROR,
64 } " node-name "_error_t;
67 * enumeration of per-packet dispositions
68 * FIXME: add dispositions as desired
72 " " uc-node-name "_NEXT_NORMAL,\n"
73 " " uc-node-name "_N_NEXT,
74 } " node-name "_next_t;
76 #define NSTAGES " nstages "
79 * Use the generic buffer metadata + first line of packet data prefetch
80 * stage function from <api/pipeline.h>. This is usually a Good Idea.
82 #define stage0 generic_stage0
85 * FIXME: add stage functions. Here is the function prototype:
87 * static inline void stageN (vlib_main_t * vm,
88 * vlib_node_runtime_t * node,
93 * FIXME: the last pipeline stage returns the desired pkt next node index,
94 * from the " node-name "_next_t enum above
96 static inline u32 last_stage (vlib_main_t *vm, vlib_node_runtime_t *node,
99 vlib_buffer_t *b = vlib_get_buffer (vm, bi);
101 b->error = node->errors[EXAMPLE_ERROR_ERROR1];
103 return " uc-node-name "_NEXT_NORMAL;
106 #include <api/pipeline.h>
108 static uword " node-name "_node_fn (vlib_main_t * vm,
109 vlib_node_runtime_t * node,
110 vlib_frame_t * frame)
112 return dispatch_pipeline (vm, node, frame);
115 static VLIB_REGISTER_NODE (example_node) = {
116 .function = " node-name "_node_fn,
117 .name = \"" node-name "-node\",
118 .vector_size = sizeof (u32),
119 .type = VLIB_NODE_TYPE_INTERNAL,
121 .n_errors = ARRAY_LEN(" node-name "_error_strings),
122 .error_strings = " node-name "_error_strings,
124 .n_next_nodes = " uc-node-name "_N_NEXT,
126 /* edit / add dispositions here */
128 [" uc-node-name "_NEXT_NORMAL] = \"error-drop\",
133 * packet generator definition to push superframes of data into the
134 * new graph node. Cut and paste into <file>, then
135 * \"exec <file>\", \"pa enable test\" at the QVNET prompt...
137 packet-generator new {
140 node " node-name "-node
142 data { hex 0x02b46b96000100096978676265000500bf436973636f20494f5320536f6674776172652c2043333735304520536f66747761726520284333373530452d554e4956455253414c2d4d292c2056657273696f6e2031322e32283335295345352c2052454c4541534520534f4654574152452028666331290a436f707972696768742028632920313938362d3230303720627920436973636f2053797374656d732c20496e632e0a436f6d70696c6564205468752031392d4a756c2d30372031363a3137206279206e616368656e00060018636973636f2057532d4333373530452d3234544400020011000000010101cc0004000000000003001b54656e4769676162697445746865726e6574312f302f3100040008000000280008002400000c011200000000ffffffff010221ff000000000000001e7a50f000ff000000090004000a00060001000b0005010012000500001300050000160011000000010101cc000400000000001a00100000000100000000ffffffff }