1 ;;; plugin-node-skel.el - vpp engine plug-in "node.c" skeleton
3 ;;; Copyright (c) 2016 Cisco and/or its affiliates.
4 ;;; Licensed under the Apache License, Version 2.0 (the "License");
5 ;;; you may not use this file except in compliance with the License.
6 ;;; You may obtain a copy of the License at:
8 ;;; http://www.apache.org/licenses/LICENSE-2.0
10 ;;; Unless required by applicable law or agreed to in writing, software
11 ;;; distributed under the License is distributed on an "AS IS" BASIS,
12 ;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 ;;; See the License for the specific language governing permissions and
14 ;;; limitations under the License.
18 (define-skeleton skel-plugin-qsnode
19 "Insert a plug-in 'node.c' skeleton "
21 '(if (not (boundp 'plugin-name))
22 (setq plugin-name (read-string "Plugin name: ")))
23 '(setq PLUGIN-NAME (upcase plugin-name))
24 '(setq capital-oh-en "ON")
26 * node.c - skeleton vpp engine plug-in dual-loop node skeleton
28 * Copyright (c) <current-year> <your-organization>
29 * Licensed under the Apache License, Version 2.0 (the \"License\");
30 * you may not use this file except in compliance with the License.
31 * You may obtain a copy of the License at:
33 * http://www.apache.org/licenses/LICENSE-2.0
35 * Unless required by applicable law or agreed to in writing, software
36 * distributed under the License is distributed on an \"AS IS\" BASIS,
37 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
38 * See the License for the specific language governing permissions and
39 * limitations under the License.
41 #include <vlib/vlib.h>
42 #include <vnet/vnet.h>
43 #include <vnet/pg/pg.h>
44 #include <vppinfra/error.h>
45 #include <" plugin-name "/" plugin-name ".h>
51 } " plugin-name "_trace_t;
53 #ifndef CLIB_MARCH_VARIANT
55 /* packet trace format function */
56 static u8 * format_" plugin-name "_trace (u8 * s, va_list * args)
58 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
59 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
60 " plugin-name "_trace_t * t = va_arg (*args, " plugin-name "_trace_t *);
62 s = format (s, \"" PLUGIN-NAME ": sw_if_index %d, next index %d\\n\",
63 t->sw_if_index, t->next_index);
67 vlib_node_registration_t " plugin-name "_node;
69 #endif /* CLIB_MARCH_VARIANT */
71 #define foreach_" plugin-name "_error \\
72 _(SWAPPED, \"Mac swap packets processed\")
76 #define _(sym,str) " PLUGIN-NAME "_ERROR_##sym,
77 foreach_" plugin-name "_error
79 " PLUGIN-NAME "_N_ERROR,
80 } " plugin-name "_error_t;
82 #ifndef CLIB_MARCH_VARIANT
83 static char * " plugin-name "_error_strings[] =
85 #define _(sym,string) string,
86 foreach_" plugin-name "_error
89 #endif /* CLIB_MARCH_VARIANT */
93 " PLUGIN-NAME "_NEXT_DROP,
94 " PLUGIN-NAME "_N_NEXT,
95 } " plugin-name "_next_t;
98 "plugin-name"_inline (vlib_main_t * vm,
99 vlib_node_runtime_t * node, vlib_frame_t * frame,
100 int is_ip4, int is_trace)
102 u32 n_left_from, *from;
103 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b;
104 u16 nexts[VLIB_FRAME_SIZE], *next;
106 from = vlib_frame_vector_args (frame);
107 n_left_from = frame->n_vectors;
109 vlib_get_buffers (vm, from, bufs, n_left_from);
113 while (n_left_from >= 4)
115 /* Prefetch next iteration. */
116 if (PREDICT_TRUE (n_left_from >= 8))
118 vlib_prefetch_buffer_header (b[4], STORE);
119 vlib_prefetch_buffer_header (b[5], STORE);
120 vlib_prefetch_buffer_header (b[6], STORE);
121 vlib_prefetch_buffer_header (b[7], STORE);
122 CLIB_PREFETCH (b[4]->data, CLIB_CACHE_LINE_BYTES, STORE);
123 CLIB_PREFETCH (b[5]->data, CLIB_CACHE_LINE_BYTES, STORE);
124 CLIB_PREFETCH (b[6]->data, CLIB_CACHE_LINE_BYTES, STORE);
125 CLIB_PREFETCH (b[7]->data, CLIB_CACHE_LINE_BYTES, STORE);
128 /* $$$$ process 4x pkts right here */
136 if (b[0]->flags & VLIB_BUFFER_IS_TRACED)
138 "plugin-name"_trace_t *t =
139 vlib_add_trace (vm, node, b[0], sizeof (*t));
140 t->next_index = next[0];
141 t->sw_if_index = vnet_buffer(b[0])->sw_if_index[VLIB_RX];
143 if (b[1]->flags & VLIB_BUFFER_IS_TRACED)
145 "plugin-name"_trace_t *t =
146 vlib_add_trace (vm, node, b[1], sizeof (*t));
147 t->next_index = next[1];
148 t->sw_if_index = vnet_buffer(b[1])->sw_if_index[VLIB_RX];
150 if (b[2]->flags & VLIB_BUFFER_IS_TRACED)
152 "plugin-name"_trace_t *t =
153 vlib_add_trace (vm, node, b[2], sizeof (*t));
154 t->next_index = next[2];
155 t->sw_if_index = vnet_buffer(b[2])->sw_if_index[VLIB_RX];
157 if (b[3]->flags & VLIB_BUFFER_IS_TRACED)
159 "plugin-name"_trace_t *t =
160 vlib_add_trace (vm, node, b[3], sizeof (*t));
161 t->next_index = next[3];
162 t->sw_if_index = vnet_buffer(b[3])->sw_if_index[VLIB_RX];
171 while (n_left_from > 0)
174 /* $$$$ process 1 pkt right here */
179 if (b[0]->flags & VLIB_BUFFER_IS_TRACED)
181 "plugin-name"_trace_t *t =
182 vlib_add_trace (vm, node, b[0], sizeof (*t));
183 t->next_index = next[0];
184 t->sw_if_index = vnet_buffer(b[0])->sw_if_index[VLIB_RX];
193 vlib_buffer_enqueue_to_next (vm, node, from, nexts, frame->n_vectors);
195 return frame->n_vectors;
198 VLIB_NODE_FN ("plugin-name"_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
199 vlib_frame_t * frame)
201 if (PREDICT_FALSE (node->flags & VLIB_NODE_FLAG_TRACE))
202 return " plugin-name "_inline (vm, node, frame, 1 /* is_ip4 */ ,
205 return " plugin-name "_inline (vm, node, frame, 1 /* is_ip4 */ ,
210 #ifndef CLIB_MARCH_VARIANT
211 VLIB_REGISTER_NODE (" plugin-name "_node) =
213 .name = \"" plugin-name "\",
214 .vector_size = sizeof (u32),
215 .format_trace = format_" plugin-name "_trace,
216 .type = VLIB_NODE_TYPE_INTERNAL,
218 .n_errors = ARRAY_LEN(" plugin-name "_error_strings),
219 .error_strings = " plugin-name "_error_strings,
221 .n_next_nodes = " PLUGIN-NAME "_N_NEXT,
223 /* edit / add dispositions here */
225 [" PLUGIN-NAME "_NEXT_DROP] = \"error-drop\",
228 #endif /* CLIB_MARCH_VARIANT */
231 * fd.io coding-style-patch-verification: " capital-oh-en "
234 * eval: (c-set-style \"gnu\")