Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | #include <vlib/vlib.h> |
| 16 | #include <vlib/unix/unix.h> |
| 17 | #include <math.h> |
| 18 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 19 | int |
| 20 | main (int argc, char *argv[]) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 21 | { |
| 22 | return vlib_unix_main (argc, argv); |
| 23 | } |
| 24 | |
| 25 | static clib_error_t * |
| 26 | main_stub_init (vlib_main_t * vm) |
| 27 | { |
Dave Barach | f8d5068 | 2019-05-14 18:01:44 -0400 | [diff] [blame] | 28 | clib_error_t *error = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 29 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 30 | return error; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 31 | } |
| 32 | |
Dave Barach | f8d5068 | 2019-05-14 18:01:44 -0400 | [diff] [blame] | 33 | /* *INDENT-OFF* */ |
| 34 | VLIB_INIT_FUNCTION (main_stub_init) = |
| 35 | { |
| 36 | .runs_after = VLIB_INITS("unix_physmem_init", "unix_cli_init"), |
| 37 | }; |
| 38 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 39 | |
| 40 | #if 0 |
| 41 | /* Node test code. */ |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 42 | typedef struct |
| 43 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 44 | int scalar; |
| 45 | int vector[0]; |
| 46 | } my_frame_t; |
| 47 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 48 | static u8 * |
| 49 | format_my_node_frame (u8 * s, va_list * va) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 50 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 51 | vlib_frame_t *f = va_arg (*va, vlib_frame_t *); |
Damjan Marion | a3d5986 | 2018-11-10 10:23:00 +0100 | [diff] [blame] | 52 | my_frame_t *g = vlib_frame_scalar_args (f); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 53 | int i; |
| 54 | |
| 55 | s = format (s, "scalar %d, vector { ", g->scalar); |
| 56 | for (i = 0; i < f->n_vectors; i++) |
| 57 | s = format (s, "%d, ", g->vector[i]); |
| 58 | s = format (s, " }"); |
| 59 | |
| 60 | return s; |
| 61 | } |
| 62 | |
| 63 | static uword |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 64 | my_func (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 65 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 66 | vlib_node_t *node; |
| 67 | my_frame_t *y; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 68 | u32 i, n_left = 0; |
| 69 | static int serial; |
| 70 | int verbose; |
| 71 | |
| 72 | node = vlib_get_node (vm, rt->node_index); |
| 73 | |
| 74 | verbose = 0; |
| 75 | |
| 76 | if (verbose && f) |
| 77 | vlib_cli_output (vm, "%v: call frame %p %U", node->name, |
| 78 | f, format_my_node_frame, f); |
| 79 | |
| 80 | if (rt->n_next_nodes > 0) |
| 81 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 82 | vlib_frame_t *next = vlib_get_next_frame (vm, rt, /* next index */ 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 83 | n_left = VLIB_FRAME_SIZE - next->n_vectors; |
Damjan Marion | a3d5986 | 2018-11-10 10:23:00 +0100 | [diff] [blame] | 84 | y = vlib_frame_scalar_args (next); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 85 | y->scalar = serial++; |
| 86 | } |
| 87 | else |
| 88 | y = 0; |
| 89 | |
| 90 | for (i = 0; i < 5; i++) |
| 91 | { |
| 92 | if (y) |
| 93 | { |
| 94 | ASSERT (n_left > 0); |
| 95 | n_left--; |
| 96 | y->vector[i] = y->scalar + i; |
| 97 | } |
| 98 | } |
| 99 | if (y) |
| 100 | vlib_put_next_frame (vm, rt, /* next index */ 0, n_left); |
| 101 | |
| 102 | if (verbose) |
| 103 | vlib_cli_output (vm, "%v: return frame %p", node->name, f); |
| 104 | |
| 105 | return i; |
| 106 | } |
| 107 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 108 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 109 | VLIB_REGISTER_NODE (my_node1,static) = { |
| 110 | .function = my_func, |
| 111 | .type = VLIB_NODE_TYPE_INPUT, |
| 112 | .name = "my-node1", |
| 113 | .scalar_size = sizeof (my_frame_t), |
| 114 | .vector_size = STRUCT_SIZE_OF (my_frame_t, vector[0]), |
| 115 | .n_next_nodes = 1, |
| 116 | .next_nodes = { |
| 117 | [0] = "my-node2", |
| 118 | }, |
| 119 | }; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 120 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 121 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 122 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 123 | VLIB_REGISTER_NODE (my_node2,static) = { |
| 124 | .function = my_func, |
| 125 | .name = "my-node2", |
| 126 | .scalar_size = sizeof (my_frame_t), |
| 127 | .vector_size = STRUCT_SIZE_OF (my_frame_t, vector[0]), |
| 128 | }; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 129 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 130 | |
| 131 | #endif |
| 132 | |
| 133 | #if 0 |
| 134 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 135 | typedef enum |
| 136 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 137 | MY_EVENT_TYPE1, |
| 138 | MY_EVENT_TYPE2, |
| 139 | } my_process_completion_type_t; |
| 140 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 141 | typedef struct |
| 142 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 143 | int a; |
| 144 | f64 b; |
| 145 | } my_process_event_data_t; |
| 146 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 147 | static u8 * |
| 148 | format_my_process_event_data (u8 * s, va_list * va) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 149 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 150 | my_process_event_data_t *d = va_arg (*va, my_process_event_data_t *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 151 | return format (s, "{ a %d b %.6f}", d->a, d->b); |
| 152 | } |
| 153 | |
| 154 | static uword |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 155 | my_proc (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 156 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 157 | vlib_node_t *node; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 158 | u32 i; |
| 159 | |
| 160 | node = vlib_get_node (vm, rt->node_index); |
| 161 | |
| 162 | vlib_cli_output (vm, "%v: call frame %p", node->name, f); |
| 163 | |
| 164 | for (i = 0; i < 5; i++) |
| 165 | { |
| 166 | vlib_cli_output (vm, "%v: %d", node->name, i); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 167 | vlib_process_suspend (vm, 1e0 /* secs */ ); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | vlib_cli_output (vm, "%v: return frame %p", node->name, f); |
| 171 | |
| 172 | if (0) |
| 173 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 174 | uword n_events_seen, type, *data = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 175 | |
| 176 | for (n_events_seen = 0; n_events_seen < 2;) |
| 177 | { |
| 178 | vlib_process_wait_for_event (vm); |
| 179 | type = vlib_process_get_events (vm, &data); |
| 180 | n_events_seen += vec_len (data); |
| 181 | vlib_cli_output (vm, "%U %v: completion #%d type %d data 0x%wx", |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 182 | format_time_interval, "h:m:s:u", |
| 183 | vlib_time_now (vm), node->name, i, type, data[0]); |
Damjan Marion | 8bea589 | 2022-04-04 22:40:45 +0200 | [diff] [blame] | 184 | vec_set_len (data, 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | vec_free (data); |
| 188 | } |
| 189 | else |
| 190 | { |
| 191 | uword n_events_seen, i, type; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 192 | my_process_event_data_t *data; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 193 | for (n_events_seen = 0; n_events_seen < 2;) |
| 194 | { |
| 195 | vlib_process_wait_for_event (vm); |
| 196 | data = vlib_process_get_event_data (vm, &type); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 197 | vec_foreach_index (i, data) |
| 198 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 199 | vlib_cli_output (vm, "%U event type %d data %U", |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 200 | format_time_interval, "h:m:s:u", |
| 201 | vlib_time_now (vm), type, |
| 202 | format_my_process_event_data, data); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 203 | } |
| 204 | n_events_seen += vec_len (data); |
| 205 | vlib_process_put_event_data (vm, data); |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | return i; |
| 210 | } |
| 211 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 212 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 213 | VLIB_REGISTER_NODE (my_proc_node,static) = { |
| 214 | .function = my_proc, |
| 215 | .type = VLIB_NODE_TYPE_PROCESS, |
| 216 | .name = "my-proc", |
| 217 | }; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 218 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 219 | |
| 220 | static uword |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 221 | my_proc_input (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 222 | { |
| 223 | static int i; |
| 224 | |
| 225 | if (i++ < 2) |
| 226 | { |
| 227 | if (0) |
| 228 | vlib_process_signal_event (vm, my_proc_node.index, |
| 229 | i == 1 ? MY_EVENT_TYPE1 : MY_EVENT_TYPE2, |
| 230 | 0x12340000 + i); |
| 231 | else |
| 232 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 233 | my_process_event_data_t *d; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 234 | f64 dt = 5; |
| 235 | d = vlib_process_signal_event_at_time (vm, |
| 236 | i * dt, |
| 237 | my_proc_node.index, |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 238 | i == |
| 239 | 1 ? MY_EVENT_TYPE1 : |
| 240 | MY_EVENT_TYPE2, |
| 241 | 1 /* elts */ , |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 242 | sizeof (d[0])); |
| 243 | d->a = i; |
| 244 | d->b = vlib_time_now (vm); |
| 245 | } |
| 246 | } |
| 247 | else |
| 248 | vlib_node_set_state (vm, rt->node_index, VLIB_NODE_STATE_DISABLED); |
| 249 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 250 | return 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 251 | } |
| 252 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 253 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 254 | VLIB_REGISTER_NODE (my_proc_input_node,static) = { |
| 255 | .function = my_proc_input, |
| 256 | .type = VLIB_NODE_TYPE_INPUT, |
| 257 | .name = "my-proc-input", |
| 258 | }; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 259 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 260 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 261 | static uword |
| 262 | _unformat_farith (unformat_input_t * i, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 263 | { |
| 264 | u32 prec = va_arg (*args, u32); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 265 | f64 *result = va_arg (*args, f64 *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 266 | f64 tmp[2]; |
| 267 | |
| 268 | /* Binary operations in from lowest to highest precedence. */ |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 269 | char *binops[] = { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 270 | "+%U", "-%U", "/%U", "*%U", "^%U", |
| 271 | }; |
| 272 | |
| 273 | if (prec <= ARRAY_LEN (binops) - 1 |
| 274 | && unformat_user (i, _unformat_farith, prec + 1, &tmp[0])) |
| 275 | { |
| 276 | int p; |
| 277 | for (p = prec; p < ARRAY_LEN (binops); p++) |
| 278 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 279 | if (unformat (i, binops[p], _unformat_farith, prec + 0, &tmp[1])) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 280 | { |
| 281 | switch (binops[p][0]) |
| 282 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 283 | case '+': |
| 284 | result[0] = tmp[0] + tmp[1]; |
| 285 | break; |
| 286 | case '-': |
| 287 | result[0] = tmp[0] - tmp[1]; |
| 288 | break; |
| 289 | case '/': |
| 290 | result[0] = tmp[0] / tmp[1]; |
| 291 | break; |
| 292 | case '*': |
| 293 | result[0] = tmp[0] * tmp[1]; |
| 294 | break; |
| 295 | case '^': |
| 296 | result[0] = pow (tmp[0], tmp[1]); |
| 297 | break; |
| 298 | default: |
| 299 | abort (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 300 | } |
| 301 | return 1; |
| 302 | } |
| 303 | } |
| 304 | result[0] = tmp[0]; |
| 305 | return 1; |
| 306 | } |
| 307 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 308 | else if (unformat (i, "-%U", _unformat_farith, prec + 0, &tmp[0])) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 309 | { |
| 310 | result[0] = -tmp[0]; |
| 311 | return 1; |
| 312 | } |
| 313 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 314 | else if (unformat (i, "(%U)", _unformat_farith, 0, &tmp[0])) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 315 | { |
| 316 | result[0] = tmp[0]; |
| 317 | return 1; |
| 318 | } |
| 319 | |
| 320 | else if (unformat (i, "%f", result)) |
| 321 | return 1; |
| 322 | |
| 323 | else |
| 324 | return 0; |
| 325 | } |
| 326 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 327 | static uword |
| 328 | unformat_farith (unformat_input_t * i, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 329 | { |
| 330 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 331 | f64 *result = va_arg (*args, f64 *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 332 | return unformat_user (i, _unformat_farith, 0, result); |
| 333 | } |
| 334 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 335 | static uword |
| 336 | unformat_integer (unformat_input_t * i, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 337 | { |
| 338 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 339 | u32 *data = va_arg (*args, u32 *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 340 | return unformat (i, "%d", data); |
| 341 | } |
| 342 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 343 | static VLIB_CLI_PARSE_RULE (my_parse_rule1) = |
| 344 | { |
| 345 | .name = "decimal_integer",.short_help = |
| 346 | "a decimal integer",.unformat_function = unformat_integer,.data_size = |
| 347 | sizeof (u32),}; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 348 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 349 | static VLIB_CLI_PARSE_RULE (my_parse_rule2) = |
| 350 | { |
| 351 | .name = "float_expression",.short_help = |
| 352 | "floating point expression",.unformat_function = |
| 353 | unformat_farith,.data_size = sizeof (f64),}; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 354 | |
| 355 | static clib_error_t * |
| 356 | bar_command (vlib_main_t * vm, |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 357 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 358 | { |
| 359 | switch (cmd->function_arg) |
| 360 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 361 | case 2: |
| 362 | { |
| 363 | u32 *d, *e; |
| 364 | d = vlib_cli_get_parse_rule_result (vm, 0); |
| 365 | e = vlib_cli_get_parse_rule_result (vm, 1); |
| 366 | vlib_cli_output (vm, "bar2 %d %d", d[0], e[0]); |
| 367 | break; |
| 368 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 369 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 370 | case 1: |
| 371 | { |
| 372 | u32 *d = vlib_cli_get_parse_rule_result (vm, 0); |
| 373 | vlib_cli_output (vm, "bar1 %d", d[0]); |
| 374 | break; |
| 375 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 376 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 377 | case 3: |
| 378 | { |
| 379 | f64 *d = vlib_cli_get_parse_rule_result (vm, 0); |
| 380 | vlib_cli_output (vm, "expr %.6f", d[0]); |
| 381 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | return 0; |
| 385 | } |
| 386 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 387 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 388 | VLIB_CLI_COMMAND (bar_command2, static) = { |
| 389 | .path = "bar %decimal_integer", |
| 390 | .short_help = "bar1 command", |
| 391 | .function = bar_command, |
| 392 | .function_arg = 1, |
| 393 | }; |
| 394 | VLIB_CLI_COMMAND (bar_command1, static) = { |
| 395 | .path = "bar %decimal_integer %decimal_integer", |
| 396 | .short_help = "bar2 command", |
| 397 | .function = bar_command, |
| 398 | .function_arg = 2, |
| 399 | }; |
| 400 | VLIB_CLI_COMMAND (bar_command3, static) = { |
| 401 | .path = "zap %float_expression", |
| 402 | .short_help = "bar3 command", |
| 403 | .function = bar_command, |
| 404 | .function_arg = 3, |
| 405 | }; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 406 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 407 | |
| 408 | #endif |
| 409 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 410 | /* |
| 411 | * fd.io coding-style-patch-verification: ON |
| 412 | * |
| 413 | * Local Variables: |
| 414 | * eval: (c-set-style "gnu") |
| 415 | * End: |
| 416 | */ |