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