Dave Barach | 8d0f2f0 | 2018-03-12 09:31:36 -0400 | [diff] [blame] | 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: |
| 5 | ;;; |
| 6 | ;;; http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | ;;; |
| 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. |
| 13 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 14 | ;;; pipe-skel.el - pipelined graph node skeleton |
| 15 | |
| 16 | (require 'skeleton) |
| 17 | |
Keith Burns (alagalah) | ca46d8c | 2016-03-18 07:22:15 -0700 | [diff] [blame] | 18 | (define-skeleton skel-pipeline-node |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 19 | "Insert a skeleton pipelined graph node" |
| 20 | nil |
| 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: ")) |
| 24 | " |
| 25 | #include <vlib/vlib.h> |
Dave Wallace | 526b5e8 | 2016-03-14 00:10:24 -0400 | [diff] [blame] | 26 | #include <vppinfra/error.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 27 | |
| 28 | /* |
| 29 | * Dump these counters via the \"show error\" CLI command |
| 30 | * FIXME: Add packet counter / error strings as desired |
| 31 | */ |
| 32 | |
| 33 | #define foreach_" node-name "_error \\ |
| 34 | _(ERROR1, \"sample counter/ error string\") |
| 35 | |
| 36 | static char * " node-name "_error_strings[] = { |
| 37 | #define _(sym,string) string, |
| 38 | foreach_" node-name "_error |
| 39 | #undef _ |
| 40 | }; |
| 41 | |
| 42 | /* |
| 43 | * packet error / counter enumeration |
| 44 | * |
| 45 | * To count and drop a vlib_buffer_t *b: |
| 46 | * |
| 47 | * Set b->error = node->errors[" uc-node-name "_ERROR_xxx]; |
| 48 | * last_stage returns a disposition index bound to \"error-drop\" |
| 49 | * |
| 50 | * To manually increment the specific counter " uc-node-name "_ERROR1 |
| 51 | * |
| 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; |
| 56 | * |
| 57 | */ |
| 58 | |
| 59 | typedef enum { |
| 60 | #define _(sym,str) " uc-node-name "_ERROR_##sym, |
| 61 | foreach_" node-name "_error |
| 62 | #undef _ |
| 63 | " uc-node-name "_N_ERROR, |
| 64 | } " node-name "_error_t; |
| 65 | |
| 66 | /* |
| 67 | * enumeration of per-packet dispositions |
| 68 | * FIXME: add dispositions as desired |
| 69 | */ |
| 70 | |
| 71 | typedef enum { \n" |
| 72 | " " uc-node-name "_NEXT_NORMAL,\n" |
| 73 | " " uc-node-name "_N_NEXT, |
| 74 | } " node-name "_next_t; |
| 75 | |
| 76 | #define NSTAGES " nstages " |
| 77 | |
| 78 | /* |
| 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. |
| 81 | */ |
| 82 | #define stage0 generic_stage0 |
| 83 | |
| 84 | /* |
| 85 | * FIXME: add stage functions. Here is the function prototype: |
| 86 | * |
| 87 | * static inline void stageN (vlib_main_t * vm, |
| 88 | * vlib_node_runtime_t * node, |
| 89 | * u32 buffer_index) |
| 90 | */ |
| 91 | |
| 92 | /* |
| 93 | * FIXME: the last pipeline stage returns the desired pkt next node index, |
| 94 | * from the " node-name "_next_t enum above |
| 95 | */ |
| 96 | static inline u32 last_stage (vlib_main_t *vm, vlib_node_runtime_t *node, |
| 97 | u32 bi) |
| 98 | { |
| 99 | vlib_buffer_t *b = vlib_get_buffer (vm, bi); |
| 100 | |
| 101 | b->error = node->errors[EXAMPLE_ERROR_ERROR1]; |
| 102 | |
| 103 | return " uc-node-name "_NEXT_NORMAL; |
| 104 | } |
| 105 | |
| 106 | #include <api/pipeline.h> |
| 107 | |
| 108 | static uword " node-name "_node_fn (vlib_main_t * vm, |
| 109 | vlib_node_runtime_t * node, |
| 110 | vlib_frame_t * frame) |
| 111 | { |
| 112 | return dispatch_pipeline (vm, node, frame); |
| 113 | } |
| 114 | |
| 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, |
| 120 | |
| 121 | .n_errors = ARRAY_LEN(" node-name "_error_strings), |
| 122 | .error_strings = " node-name "_error_strings, |
| 123 | |
| 124 | .n_next_nodes = " uc-node-name "_N_NEXT, |
| 125 | |
| 126 | /* edit / add dispositions here */ |
| 127 | .next_nodes = { |
| 128 | [" uc-node-name "_NEXT_NORMAL] = \"error-drop\", |
| 129 | }, |
| 130 | }; |
| 131 | |
| 132 | /* |
| 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... |
| 136 | * |
| 137 | packet-generator new { |
| 138 | name test |
| 139 | limit 100 |
| 140 | node " node-name "-node |
| 141 | size 374-374 |
| 142 | data { hex 0x02b46b96000100096978676265000500bf436973636f20494f5320536f6674776172652c2043333735304520536f66747761726520284333373530452d554e4956455253414c2d4d292c2056657273696f6e2031322e32283335295345352c2052454c4541534520534f4654574152452028666331290a436f707972696768742028632920313938362d3230303720627920436973636f2053797374656d732c20496e632e0a436f6d70696c6564205468752031392d4a756c2d30372031363a3137206279206e616368656e00060018636973636f2057532d4333373530452d3234544400020011000000010101cc0004000000000003001b54656e4769676162697445746865726e6574312f302f3100040008000000280008002400000c011200000000ffffffff010221ff000000000000001e7a50f000ff000000090004000a00060001000b0005010012000500001300050000160011000000010101cc000400000000001a00100000000100000000ffffffff } |
| 143 | } |
| 144 | */ |
| 145 | ") |