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