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);
66 #endif /* CLIB_MARCH_VARIANT */
68 vlib_node_registration_t " plugin-name "_node;
70 #define foreach_" plugin-name "_error \\
71 _(SWAPPED, \"Mac swap packets processed\")
75 #define _(sym,str) " PLUGIN-NAME "_ERROR_##sym,
76 foreach_" plugin-name "_error
78 " PLUGIN-NAME "_N_ERROR,
79 } " plugin-name "_error_t;
81 #ifndef CLIB_MARCH_VARIANT
82 static char * " plugin-name "_error_strings[] =
84 #define _(sym,string) string,
85 foreach_" plugin-name "_error
88 #endif /* CLIB_MARCH_VARIANT */
92 " PLUGIN-NAME "_NEXT_DROP,
93 " PLUGIN-NAME "_N_NEXT,
94 } " plugin-name "_next_t;
97 "plugin-name"_inline (vlib_main_t * vm,
98 vlib_node_runtime_t * node, vlib_frame_t * frame,
99 int is_ip4, int is_trace)
101 u32 n_left_from, *from;
102 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b;
103 u16 nexts[VLIB_FRAME_SIZE], *next;
105 from = vlib_frame_vector_args (frame);
106 n_left_from = frame->n_vectors;
108 vlib_get_buffers (vm, from, bufs, n_left_from);
112 while (n_left_from >= 4)
114 /* Prefetch next iteration. */
115 if (PREDICT_TRUE (n_left_from >= 8))
117 vlib_prefetch_buffer_header (b[4], STORE);
118 vlib_prefetch_buffer_header (b[5], STORE);
119 vlib_prefetch_buffer_header (b[6], STORE);
120 vlib_prefetch_buffer_header (b[7], STORE);
121 CLIB_PREFETCH (b[4]->data, CLIB_CACHE_LINE_BYTES, STORE);
122 CLIB_PREFETCH (b[5]->data, CLIB_CACHE_LINE_BYTES, STORE);
123 CLIB_PREFETCH (b[6]->data, CLIB_CACHE_LINE_BYTES, STORE);
124 CLIB_PREFETCH (b[7]->data, CLIB_CACHE_LINE_BYTES, STORE);
127 /* $$$$ process 4x pkts right here */
135 if (b[0]->flags & VLIB_BUFFER_IS_TRACED)
137 "plugin-name"_trace_t *t =
138 vlib_add_trace (vm, node, b[0], sizeof (*t));
139 t->next_index = next[0];
140 t->sw_if_index = vnet_buffer(b[0])->sw_if_index[VLIB_RX];
142 if (b[1]->flags & VLIB_BUFFER_IS_TRACED)
144 "plugin-name"_trace_t *t =
145 vlib_add_trace (vm, node, b[1], sizeof (*t));
146 t->next_index = next[1];
147 t->sw_if_index = vnet_buffer(b[1])->sw_if_index[VLIB_RX];
149 if (b[2]->flags & VLIB_BUFFER_IS_TRACED)
151 "plugin-name"_trace_t *t =
152 vlib_add_trace (vm, node, b[2], sizeof (*t));
153 t->next_index = next[2];
154 t->sw_if_index = vnet_buffer(b[2])->sw_if_index[VLIB_RX];
156 if (b[3]->flags & VLIB_BUFFER_IS_TRACED)
158 "plugin-name"_trace_t *t =
159 vlib_add_trace (vm, node, b[3], sizeof (*t));
160 t->next_index = next[3];
161 t->sw_if_index = vnet_buffer(b[3])->sw_if_index[VLIB_RX];
170 while (n_left_from > 0)
173 /* $$$$ process 1 pkt right here */
178 if (b[0]->flags & VLIB_BUFFER_IS_TRACED)
180 "plugin-name"_trace_t *t =
181 vlib_add_trace (vm, node, b[0], sizeof (*t));
182 t->next_index = next[0];
183 t->sw_if_index = vnet_buffer(b[0])->sw_if_index[VLIB_RX];
192 vlib_buffer_enqueue_to_next (vm, node, from, nexts, frame->n_vectors);
194 return frame->n_vectors;
197 VLIB_NODE_FN ("plugin-name"_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
198 vlib_frame_t * frame)
200 if (PREDICT_FALSE (node->flags & VLIB_NODE_FLAG_TRACE))
201 return " plugin-name "_inline (vm, node, frame, 1 /* is_ip4 */ ,
204 return " plugin-name "_inline (vm, node, frame, 1 /* is_ip4 */ ,
209 #ifndef CLIB_MARCH_VARIANT
210 VLIB_REGISTER_NODE (" plugin-name "_node) =
212 .name = \"" plugin-name "\",
213 .vector_size = sizeof (u32),
214 .format_trace = format_" plugin-name "_trace,
215 .type = VLIB_NODE_TYPE_INTERNAL,
217 .n_errors = ARRAY_LEN(" plugin-name "_error_strings),
218 .error_strings = " plugin-name "_error_strings,
220 .n_next_nodes = " PLUGIN-NAME "_N_NEXT,
222 /* edit / add dispositions here */
224 [" PLUGIN-NAME "_NEXT_DROP] = \"error-drop\",
227 #endif /* CLIB_MARCH_VARIANT */
230 * fd.io coding-style-patch-verification: " capital-oh-en "
233 * eval: (c-set-style \"gnu\")