Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | ;;; pipe-skel.el - pipelined graph node skeleton |
| 2 | |
| 3 | (require 'skeleton) |
| 4 | |
| 5 | (define-skeleton pipeline-node-skel |
| 6 | "Insert a skeleton pipelined graph node" |
| 7 | nil |
| 8 | '(setq node-name (skeleton-read "Node Name: ")) |
| 9 | '(setq uc-node-name (upcase node-name)) |
| 10 | '(setq nstages (skeleton-read "Number of pipeline stages: ")) |
| 11 | " |
| 12 | #include <vlib/vlib.h> |
| 13 | #include <clib/error.h> |
| 14 | |
| 15 | /* |
| 16 | * Dump these counters via the \"show error\" CLI command |
| 17 | * FIXME: Add packet counter / error strings as desired |
| 18 | */ |
| 19 | |
| 20 | #define foreach_" node-name "_error \\ |
| 21 | _(ERROR1, \"sample counter/ error string\") |
| 22 | |
| 23 | static char * " node-name "_error_strings[] = { |
| 24 | #define _(sym,string) string, |
| 25 | foreach_" node-name "_error |
| 26 | #undef _ |
| 27 | }; |
| 28 | |
| 29 | /* |
| 30 | * packet error / counter enumeration |
| 31 | * |
| 32 | * To count and drop a vlib_buffer_t *b: |
| 33 | * |
| 34 | * Set b->error = node->errors[" uc-node-name "_ERROR_xxx]; |
| 35 | * last_stage returns a disposition index bound to \"error-drop\" |
| 36 | * |
| 37 | * To manually increment the specific counter " uc-node-name "_ERROR1 |
| 38 | * |
| 39 | * vlib_node_t *n = vlib_get_node (vm, " node-name ".index); |
| 40 | * u32 node_counter_base_index = n->error_heap_index; |
| 41 | * vlib_error_main_t * em = &vm->error_main; |
| 42 | * em->counters[node_counter_base_index + " uc-node-name "_ERROR1] += 1; |
| 43 | * |
| 44 | */ |
| 45 | |
| 46 | typedef enum { |
| 47 | #define _(sym,str) " uc-node-name "_ERROR_##sym, |
| 48 | foreach_" node-name "_error |
| 49 | #undef _ |
| 50 | " uc-node-name "_N_ERROR, |
| 51 | } " node-name "_error_t; |
| 52 | |
| 53 | /* |
| 54 | * enumeration of per-packet dispositions |
| 55 | * FIXME: add dispositions as desired |
| 56 | */ |
| 57 | |
| 58 | typedef enum { \n" |
| 59 | " " uc-node-name "_NEXT_NORMAL,\n" |
| 60 | " " uc-node-name "_N_NEXT, |
| 61 | } " node-name "_next_t; |
| 62 | |
| 63 | #define NSTAGES " nstages " |
| 64 | |
| 65 | /* |
| 66 | * Use the generic buffer metadata + first line of packet data prefetch |
| 67 | * stage function from <api/pipeline.h>. This is usually a Good Idea. |
| 68 | */ |
| 69 | #define stage0 generic_stage0 |
| 70 | |
| 71 | /* |
| 72 | * FIXME: add stage functions. Here is the function prototype: |
| 73 | * |
| 74 | * static inline void stageN (vlib_main_t * vm, |
| 75 | * vlib_node_runtime_t * node, |
| 76 | * u32 buffer_index) |
| 77 | */ |
| 78 | |
| 79 | /* |
| 80 | * FIXME: the last pipeline stage returns the desired pkt next node index, |
| 81 | * from the " node-name "_next_t enum above |
| 82 | */ |
| 83 | static inline u32 last_stage (vlib_main_t *vm, vlib_node_runtime_t *node, |
| 84 | u32 bi) |
| 85 | { |
| 86 | vlib_buffer_t *b = vlib_get_buffer (vm, bi); |
| 87 | |
| 88 | b->error = node->errors[EXAMPLE_ERROR_ERROR1]; |
| 89 | |
| 90 | return " uc-node-name "_NEXT_NORMAL; |
| 91 | } |
| 92 | |
| 93 | #include <api/pipeline.h> |
| 94 | |
| 95 | static uword " node-name "_node_fn (vlib_main_t * vm, |
| 96 | vlib_node_runtime_t * node, |
| 97 | vlib_frame_t * frame) |
| 98 | { |
| 99 | return dispatch_pipeline (vm, node, frame); |
| 100 | } |
| 101 | |
| 102 | static VLIB_REGISTER_NODE (example_node) = { |
| 103 | .function = " node-name "_node_fn, |
| 104 | .name = \"" node-name "-node\", |
| 105 | .vector_size = sizeof (u32), |
| 106 | .type = VLIB_NODE_TYPE_INTERNAL, |
| 107 | |
| 108 | .n_errors = ARRAY_LEN(" node-name "_error_strings), |
| 109 | .error_strings = " node-name "_error_strings, |
| 110 | |
| 111 | .n_next_nodes = " uc-node-name "_N_NEXT, |
| 112 | |
| 113 | /* edit / add dispositions here */ |
| 114 | .next_nodes = { |
| 115 | [" uc-node-name "_NEXT_NORMAL] = \"error-drop\", |
| 116 | }, |
| 117 | }; |
| 118 | |
| 119 | /* |
| 120 | * packet generator definition to push superframes of data into the |
| 121 | * new graph node. Cut and paste into <file>, then |
| 122 | * \"exec <file>\", \"pa enable test\" at the QVNET prompt... |
| 123 | * |
| 124 | packet-generator new { |
| 125 | name test |
| 126 | limit 100 |
| 127 | node " node-name "-node |
| 128 | size 374-374 |
| 129 | data { hex 0x02b46b96000100096978676265000500bf436973636f20494f5320536f6674776172652c2043333735304520536f66747761726520284333373530452d554e4956455253414c2d4d292c2056657273696f6e2031322e32283335295345352c2052454c4541534520534f4654574152452028666331290a436f707972696768742028632920313938362d3230303720627920436973636f2053797374656d732c20496e632e0a436f6d70696c6564205468752031392d4a756c2d30372031363a3137206279206e616368656e00060018636973636f2057532d4333373530452d3234544400020011000000010101cc0004000000000003001b54656e4769676162697445746865726e6574312f302f3100040008000000280008002400000c011200000000ffffffff010221ff000000000000001e7a50f000ff000000090004000a00060001000b0005010012000500001300050000160011000000010101cc000400000000001a00100000000100000000ffffffff } |
| 130 | } |
| 131 | */ |
| 132 | ") |