static clib_error_t * cdp_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { cdp_main_t *cm = &cdp_main; int enable_disable = 1; int rv; while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { if (unformat (input, "disable")) enable_disable = 0; else if (unformat (input, "enable")) enable_disable = 1; else break; } rv = cdp_enable_disable (cm, enable_disable); switch (rv) { case 0: break; default: return clib_error_return (0, "cdp_enable_disable returned %d", rv); } return 0; }
static clib_error_t * promiscuous_cmd (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { vnet_main_t * vnm = vnet_get_main(); u32 hw_if_index; u32 flags = ETHERNET_INTERFACE_FLAG_ACCEPT_ALL; if (unformat (input, "on %U", unformat_ethernet_interface, vnm, &hw_if_index)) { ethernet_set_flags (vnm, hw_if_index, flags); } else if (unformat (input, "off %U", unformat_ethernet_interface, vnm, &hw_if_index)) { flags = 0; ethernet_set_flags (vnm, hw_if_index, flags); } else return clib_error_return (0, "unknown input `%U'", format_unformat_error, input); return 0; }
static clib_error_t * cj_config (vlib_main_t * vm, unformat_input_t * input) { cj_main_t * cjm = &cj_main; int matched = 0; int enable = 0; while (unformat_check_input(input) != UNFORMAT_END_OF_INPUT) { if (unformat (input, "records %d", &cjm->num_records)) matched = 1; else if (unformat (input, "on")) enable = 1; else return clib_error_return (0, "cj_config: unknown input '%U'", format_unformat_error, input); } if (matched == 0) return 0; cjm->num_records = max_pow2 (cjm->num_records); vec_validate (cjm->records, cjm->num_records-1); memset (cjm->records, 0xff, cjm->num_records * sizeof (cj_record_t)); cjm->tail = ~0; cjm->enable = enable; return 0; }
static uword unformat_ethernet_arp_opcode_host_byte_order (unformat_input_t * input, va_list * args) { int * result = va_arg (*args, int *); ethernet_arp_main_t * am = ðernet_arp_main; int x, i; /* Numeric opcode. */ if (unformat (input, "0x%x", &x) || unformat (input, "%d", &x)) { if (x >= (1 << 16)) return 0; *result = x; return 1; } /* Named type. */ if (unformat_user (input, unformat_vlib_number_by_name, am->opcode_by_name, &i)) { *result = i; return 1; } return 0; }
static clib_error_t * cj_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { int is_enable = -1; int is_dump = -1; while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { if (unformat (input, "enable") || unformat (input, "on")) is_enable = 1; else if (unformat (input, "disable") || unformat (input, "off")) is_enable = 0; else if (unformat (input, "dump")) is_dump = 1; else return clib_error_return (0, "unknown input `%U'", format_unformat_error, input); } if (is_enable >= 0) cj_enable_disable (is_enable); if (is_dump > 0) cj_dump (); return 0; }
static clib_error_t * virtio_pci_create_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { unformat_input_t _line_input, *line_input = &_line_input; virtio_pci_create_if_args_t args; u64 feature_mask = (u64) ~ (0ULL); /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) return 0; memset (&args, 0, sizeof (args)); while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { if (unformat (line_input, "%U", unformat_vlib_pci_addr, &args.addr)) ; else if (unformat (line_input, "feature-mask 0x%llx", &feature_mask)) args.features = feature_mask; else return clib_error_return (0, "unknown input `%U'", format_unformat_error, input); } unformat_free (line_input); virtio_pci_create_if (vm, &args); return args.error; }
static clib_error_t * abf_policy_cmd (vlib_main_t * vm, unformat_input_t * main_input, vlib_cli_command_t * cmd) { unformat_input_t _line_input, *line_input = &_line_input; u32 acl_index, policy_id; fib_route_path_t *rpaths = NULL, rpath; u32 is_del; is_del = 0; acl_index = INDEX_INVALID; policy_id = INDEX_INVALID; /* Get a line of input. */ if (!unformat_user (main_input, unformat_line_input, line_input)) return 0; while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { if (unformat (line_input, "acl %d", &acl_index)) ; else if (unformat (line_input, "id %d", &policy_id)) ; else if (unformat (line_input, "del")) is_del = 1; else if (unformat (line_input, "add")) is_del = 0; else if (unformat (line_input, "via %U", unformat_fib_route_path, &rpath)) vec_add1 (rpaths, rpath); else return (clib_error_return (0, "unknown input '%U'", format_unformat_error, line_input)); } if (INDEX_INVALID == policy_id) { vlib_cli_output (vm, "Specify a Policy ID"); return 0; } if (!is_del) { if (INDEX_INVALID == acl_index) { vlib_cli_output (vm, "ACL index must be set"); return 0; } abf_policy_update (policy_id, acl_index, rpaths); } else { abf_policy_delete (policy_id, rpaths); } unformat_free (line_input); return (NULL); }
static clib_error_t * show_errors (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { vlib_error_main_t *em = &vm->error_main; vlib_node_t *n; u32 code, i, ni; u64 c; int index = 0; int verbose = 0; u64 *sums = 0; if (unformat (input, "verbose %d", &verbose)) ; else if (unformat (input, "verbose")) verbose = 1; vec_validate (sums, vec_len (em->counters)); if (verbose) vlib_cli_output (vm, "%=10s%=40s%=20s%=6s", "Count", "Node", "Reason", "Index"); else vlib_cli_output (vm, "%=10s%=40s%=6s", "Count", "Node", "Reason"); /* *INDENT-OFF* */ foreach_vlib_main(({ em = &this_vlib_main->error_main; if (verbose) vlib_cli_output(vm, "Thread %u (%v):", index, vlib_worker_threads[index].name); for (ni = 0; ni < vec_len (this_vlib_main->node_main.nodes); ni++) { n = vlib_get_node (this_vlib_main, ni); for (code = 0; code < n->n_errors; code++) { i = n->error_heap_index + code; c = em->counters[i]; if (i < vec_len (em->counters_last_clear)) c -= em->counters_last_clear[i]; sums[i] += c; if (c == 0 && verbose < 2) continue; if (verbose) vlib_cli_output (vm, "%10Ld%=40v%=20s%=6d", c, n->name, em->error_strings_heap[i], i); else vlib_cli_output (vm, "%10d%=40v%s", c, n->name, em->error_strings_heap[i]); } } index++; }));
static clib_error_t * netmap_create_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { unformat_input_t _line_input, * line_input = &_line_input; u8 * host_if_name = NULL; u8 hwaddr [6]; u8 * hw_addr_ptr = 0; int r; u8 is_pipe = 0; u8 is_master = 0; u32 sw_if_index = ~0; /* Get a line of input. */ if (! unformat_user (input, unformat_line_input, line_input)) return 0; while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { if (unformat (line_input, "name %s", &host_if_name)) ; else if (unformat (line_input, "hw-addr %U", unformat_ethernet_address, hwaddr)) hw_addr_ptr = hwaddr; else if (unformat (line_input, "pipe")) is_pipe = 1; else if (unformat (line_input, "master")) is_master = 1; else if (unformat (line_input, "slave")) is_master = 0; else return clib_error_return (0, "unknown input `%U'", format_unformat_error, input); } unformat_free (line_input); if (host_if_name == NULL) return clib_error_return (0, "missing host interface name"); r = netmap_create_if(vm, host_if_name, hw_addr_ptr, is_pipe, is_master, &sw_if_index); if (r == VNET_API_ERROR_SYSCALL_ERROR_1) return clib_error_return(0, "%s (errno %d)", strerror (errno), errno); if (r == VNET_API_ERROR_INVALID_INTERFACE) return clib_error_return(0, "Invalid interface name"); if (r == VNET_API_ERROR_SUBIF_ALREADY_EXISTS) return clib_error_return(0, "Interface already exists"); vlib_cli_output(vm, "%U\n", format_vnet_sw_if_index_name, vnet_get_main(), sw_if_index); return 0; }
static clib_error_t * mtu_cmd (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { vnet_main_t * vnm = vnet_get_main(); u32 hw_if_index, mtu; u32 flags = ETHERNET_INTERFACE_FLAG_MTU; if (unformat (input, "%d %U", &mtu, unformat_ethernet_interface, vnm, &hw_if_index)) { vnet_hw_interface_t * hi = vnet_get_hw_interface (vnm, hw_if_index); if (mtu < ETHERNET_MIN_PACKET_BYTES) return clib_error_return (0, "Invalid mtu (%d): " "must be >= min pkt bytes (%d)", mtu, hi->min_packet_bytes); if (mtu > ETHERNET_MAX_PACKET_BYTES) return clib_error_return (0, "Invalid mtu (%d): must be <= 9216", mtu); if (hi->max_packet_bytes != mtu) { hi->max_packet_bytes = mtu; ethernet_set_flags (vnm, hw_if_index, flags); } } else return clib_error_return (0, "unknown input `%U'", format_unformat_error, input); return 0; }
u8 * vlib_sysfs_link_to_name (char *link) { char *p, buffer[64]; unformat_input_t in; u8 *s = 0; int r; r = readlink (link, buffer, sizeof (buffer) - 1); if (r < 0) return 0; buffer[r] = 0; p = strrchr (buffer, '/'); if (!p) return 0; unformat_init_string (&in, p + 1, strlen (p + 1)); unformat (&in, "%s", &s); unformat_free (&in); return s; }
static int test_time_main (unformat_input_t * input) { f64 wait, error; f64 t, tu[3], ave, rms; clib_time_t c; int i, n, j; clib_time_init (&c); wait = 1e-3; n = 1000; unformat (input, "%f %d", &wait, &n); ave = rms = 0; tu[0] = unix_time_now (); tu[1] = unix_time_now (); for (i = 0; i < n; i++) { j = 0; t = clib_time_now (&c); while (clib_time_now (&c) < t + wait) j++; t = j; ave += t; rms += t*t; } tu[2] = unix_time_now (); ave /= n; rms = sqrt (rms/n - ave*ave); error = ((tu[2] - tu[1]) - 2 * (tu[1] - tu[0]) - n*wait) / n; if_verbose ("tested %d x %.6e sec waits, error %.6e loops %.6e +- %.6e\n", n, wait, error, ave, rms); return 0; }
static clib_error_t * netmap_delete_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { unformat_input_t _line_input, * line_input = &_line_input; u8 * host_if_name = NULL; /* Get a line of input. */ if (! unformat_user (input, unformat_line_input, line_input)) return 0; while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { if (unformat (line_input, "name %s", &host_if_name)) ; else return clib_error_return (0, "unknown input `%U'", format_unformat_error, input); } unformat_free (line_input); if (host_if_name == NULL) return clib_error_return (0, "missing host interface name"); netmap_delete_if(vm, host_if_name); return 0; }
static clib_error_t * mrvl_pp2_create_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { unformat_input_t _line_input, *line_input = &_line_input; mrvl_pp2_create_if_args_t args = { 0 }; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) return 0; while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { if (unformat (line_input, "name %s", &args.name)) ; else return clib_error_return (0, "unknown input `%U'", format_unformat_error, input); } unformat_free (line_input); mrvl_pp2_create_if (&args); vec_free (args.name); return args.error; }
/* vmxnet3 delete API */ static int api_vmxnet3_delete (vat_main_t * vam) { unformat_input_t *i = vam->input; vl_api_vmxnet3_delete_t *mp; u32 sw_if_index = 0; u8 index_defined = 0; int ret; while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { if (unformat (i, "sw_if_index %u", &sw_if_index)) index_defined = 1; else { clib_warning ("unknown input '%U'", format_unformat_error, i); return -99; } } if (!index_defined) { errmsg ("missing sw_if_index\n"); return -99; } M (VMXNET3_DELETE, mp); mp->sw_if_index = clib_host_to_net_u32 (sw_if_index); S (mp); W (ret); return ret; }
static clib_error_t * macswap_enable_disable_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { sample_main_t * sm = &sample_main; u32 sw_if_index = ~0; int enable_disable = 1; int rv; while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { if (unformat (input, "disable")) enable_disable = 0; else if (unformat (input, "%U", unformat_vnet_sw_interface, sm->vnet_main, &sw_if_index)) ; else break; } if (sw_if_index == ~0) return clib_error_return (0, "Please specify an interface..."); rv = sample_macswap_enable_disable (sm, sw_if_index, enable_disable); switch(rv) { case 0: break; case VNET_API_ERROR_INVALID_SW_IF_INDEX: return clib_error_return (0, "Invalid interface, only works on physical ports"); break; case VNET_API_ERROR_UNIMPLEMENTED: return clib_error_return (0, "Device driver doesn't support redirection"); break; default: return clib_error_return (0, "sample_macswap_enable_disable returned %d", rv); } return 0; }
static clib_error_t * set_ioam_export_ipfix_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { ioam_export_main_t *em = &ioam_export_main; ip4_address_t collector, src; u8 is_disable = 0; collector.as_u32 = 0; src.as_u32 = 0; while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { if (unformat (input, "collector %U", unformat_ip4_address, &collector)) ; else if (unformat (input, "src %U", unformat_ip4_address, &src)) ; else if (unformat (input, "disable")) is_disable = 1; else break; } if (collector.as_u32 == 0) return clib_error_return (0, "collector address required"); if (src.as_u32 == 0) return clib_error_return (0, "src address required"); em->ipfix_collector.as_u32 = collector.as_u32; em->src_address.as_u32 = src.as_u32; vlib_cli_output (vm, "Collector %U, src address %U", format_ip4_address, &em->ipfix_collector, format_ip4_address, &em->src_address); /* Turn on the export timer process */ // vlib_process_signal_event (vm, flow_report_process_node.index, //1, 0); ioam_export_ip6_enable_disable (em, is_disable, &collector, &src); return 0; }
static clib_error_t * qos_mark_cli (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { qos_egress_map_id_t map_id; u32 sw_if_index, qs; vnet_main_t *vnm; int rv, enable; vnm = vnet_get_main (); map_id = ~0; qs = 0xff; enable = 1; while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { if (unformat (input, "id %d", &map_id)) ; else if (unformat (input, "disable")) enable = 0; else if (unformat (input, "%U", unformat_qos_source, &qs)) ; else if (unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index)) ; else break; } if (~0 == sw_if_index) return clib_error_return (0, "interface must be specified"); if (0xff == qs) return clib_error_return (0, "output location must be specified"); if (enable) rv = qos_mark_enable (sw_if_index, qs, map_id); else rv = qos_mark_disable (sw_if_index, qs); if (0 == rv) return (NULL); return clib_error_return (0, "Failed to map interface"); }
static clib_error_t * show_virtio_pci_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { virtio_main_t *vim = &virtio_main; vnet_main_t *vnm = &vnet_main; virtio_if_t *vif; clib_error_t *error = 0; u32 hw_if_index, *hw_if_indices = 0; vnet_hw_interface_t *hi; u8 show_descr = 0, show_device_config = 0; while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { if (unformat (input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index)) { hi = vnet_get_hw_interface (vnm, hw_if_index); if (virtio_device_class.index != hi->dev_class_index) { error = clib_error_return (0, "unknown input `%U'", format_unformat_error, input); goto done; } vec_add1 (hw_if_indices, hw_if_index); } else if (unformat (input, "descriptors") || unformat (input, "desc")) show_descr = 1; else if (unformat (input, "debug-device")) show_device_config = 1; else { error = clib_error_return (0, "unknown input `%U'", format_unformat_error, input); goto done; } } if (vec_len (hw_if_indices) == 0) { pool_foreach (vif, vim->interfaces, vec_add1 (hw_if_indices, vif->hw_if_index); );
static clib_error_t * virtio_pci_delete_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { unformat_input_t _line_input, *line_input = &_line_input; u32 sw_if_index = ~0; vnet_hw_interface_t *hw; virtio_main_t *vim = &virtio_main; virtio_if_t *vif; vnet_main_t *vnm = vnet_get_main (); /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) return 0; while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { if (unformat (line_input, "sw_if_index %d", &sw_if_index)) ; else if (unformat (line_input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index)) ; else return clib_error_return (0, "unknown input `%U'", format_unformat_error, input); } unformat_free (line_input); if (sw_if_index == ~0) return clib_error_return (0, "please specify interface name or sw_if_index"); hw = vnet_get_sup_hw_interface (vnm, sw_if_index); if (hw == NULL || virtio_device_class.index != hw->dev_class_index) return clib_error_return (0, "not a virtio interface"); vif = pool_elt_at_index (vim->interfaces, hw->dev_instance); if (virtio_pci_delete_if (vm, vif) < 0) return clib_error_return (0, "not a virtio pci interface"); return 0; }
static int api_trace_profile_add (vat_main_t * vam) { unformat_input_t *input = vam->input; vl_api_trace_profile_add_t *mp; u8 trace_type = 0; u8 num_elts = 0; u32 node_id = 0; u32 app_data = 0; u8 trace_tsp = 0; int ret; while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { if (unformat (input, "trace-type 0x%x", &trace_type)) ; else if (unformat (input, "trace-elts %d", &num_elts)) ; else if (unformat (input, "trace-tsp %d", &trace_tsp)) ; else if (unformat (input, "node-id 0x%x", &node_id)) ; else if (unformat (input, "app-data 0x%x", &app_data)) ; else break; } M (TRACE_PROFILE_ADD, mp); mp->trace_type = trace_type; mp->trace_tsp = trace_tsp; mp->node_id = htonl (node_id); mp->app_data = htonl (app_data); mp->num_elts = num_elts; S (mp); W (ret); return ret; }
static clib_error_t * cj_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { int is_enable = -1; int is_dump = -1; unformat_input_t _line_input, *line_input = &_line_input; clib_error_t *error = NULL; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) return clib_error_return (0, "expected enable | disable | dump"); while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { if (unformat (line_input, "enable") || unformat (line_input, "on")) is_enable = 1; else if (unformat (line_input, "disable") || unformat (line_input, "off")) is_enable = 0; else if (unformat (line_input, "dump")) is_dump = 1; else { error = clib_error_return (0, "unknown input `%U'", format_unformat_error, line_input); goto done; } } if (is_enable >= 0) cj_enable_disable (is_enable); if (is_dump > 0) cj_dump (); done: unformat_free (line_input); return error; }
/* vmxnet3 create API */ static int api_vmxnet3_create (vat_main_t * vam) { unformat_input_t *i = vam->input; vl_api_vmxnet3_create_t *mp; vmxnet3_create_if_args_t args; int ret; u32 x[4]; clib_memset (&args, 0, sizeof (vmxnet3_create_if_args_t)); while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { if (unformat (i, "%x:%x:%x.%x", &x[0], &x[1], &x[2], &x[3])) { args.addr.domain = x[0]; args.addr.bus = x[1]; args.addr.slot = x[2]; args.addr.function = x[3]; } else if (unformat (i, "elog")) args.enable_elog = 1; else if (unformat (i, "bind")) args.bind = 1; else if (unformat (i, "rx-queue-size %u", &args.rxq_size)) ; else if (unformat (i, "tx-queue-size %u", &args.txq_size)) ; else if (unformat (i, "num-tx-queues %u", &args.txq_num)) ; else if (unformat (i, "num-rx-queues %u", &args.rxq_num)) ; else { clib_warning ("unknown input '%U'", format_unformat_error, i); return -99; } } M (VMXNET3_CREATE, mp); mp->pci_addr = clib_host_to_net_u32 (args.addr.as_u32); mp->enable_elog = clib_host_to_net_u16 (args.enable_elog); mp->rxq_size = clib_host_to_net_u16 (args.rxq_size); mp->txq_size = clib_host_to_net_u16 (args.txq_size); mp->txq_num = clib_host_to_net_u16 (args.txq_num); mp->rxq_num = clib_host_to_net_u16 (args.rxq_num); mp->bind = args.bind; S (mp); W (ret); return ret; }
static clib_error_t * mpls_interface_enable_disable (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { vnet_main_t * vnm = vnet_get_main(); clib_error_t * error = 0; u32 sw_if_index, enable; int rv; sw_if_index = ~0; if (! unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index)) { error = clib_error_return (0, "unknown interface `%U'", format_unformat_error, input); goto done; } if (unformat (input, "enable")) enable = 1; else if (unformat (input, "disable")) enable = 0; else { error = clib_error_return (0, "expected 'enable' or 'disable'", format_unformat_error, input); goto done; } rv = mpls_sw_interface_enable_disable(&mpls_main, sw_if_index, enable, 0); if (VNET_API_ERROR_NO_SUCH_FIB == rv) error = clib_error_return (0, "default MPLS table must be created first"); done: return error; }
static clib_error_t * rdma_create_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { unformat_input_t _line_input, *line_input = &_line_input; rdma_create_if_args_t args; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) return 0; clib_memset (&args, 0, sizeof (rdma_create_if_args_t)); while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { if (unformat (line_input, "host-if %s", &args.ifname)) ; else if (unformat (line_input, "name %s", &args.name)) ; else if (unformat (line_input, "rx-queue-size %u", &args.rxq_size)) ; else if (unformat (line_input, "tx-queue-size %u", &args.txq_size)) ; else if (unformat (line_input, "num-rx-queues %u", &args.rxq_num)) ; else return clib_error_return (0, "unknown input `%U'", format_unformat_error, input); } unformat_free (line_input); rdma_create_if (vm, &args); vec_free (args.ifname); vec_free (args.name); return args.error; }
clib_error_t * ssvm_config (vlib_main_t * vm, unformat_input_t * input) { u8 * name; int is_master = 1; int i, rv; ssvm_eth_main_t * em = &ssvm_eth_main; while (unformat_check_input(input) != UNFORMAT_END_OF_INPUT) { if (unformat (input, "base-va %llx", &em->next_base_va)) ; else if (unformat (input, "segment-size %lld", &em->segment_size)) em->segment_size = 1ULL << (max_log2 (em->segment_size)); else if (unformat (input, "nbuffers %lld", &em->nbuffers)) ; else if (unformat (input, "queue-elts %lld", &em->queue_elts)) ; else if (unformat (input, "slave")) is_master = 0; else if (unformat (input, "%s", &name)) { vec_add1 (em->names, name); printf("AYXX: adding %s\n", name); } else break; } /* No configured instances, we're done... */ if (vec_len (em->names) == 0) return 0; for (i = 0; i < vec_len (em->names); i++) { rv = ssvm_eth_create (em, em->names[i], is_master); if (rv < 0) return clib_error_return (0, "ssvm_eth_create '%s' failed, error %d", em->names[i], rv); } return 0; }
int DFS(char s[], int step, int cur) { if(step >= strlen(cs)) { if(strlen(ys) == 4) flag = true; return 0; } if(cur < 0) //back track return 0; if(step == 0) { for(int c = step; c <= strlen(cs) - 1; c++) //dfs and back trace { char es[10] = {0}; int i = 0, j = 0, e = 0; for(i = cur; i >= 0; i--) { if(isdigit(s[i])) { if(c != (strlen(cs) - 1)) { for(j = i - 1; j <= i; j++)// 2 bits es[e++] = s[j]; es[e] = '\0'; } else { for(j = i - 3; j <= i; j++)// 2 bits { if(j < 0) break; es[e++] = s[j]; } es[e] = '\0'; } break; } } int next_cur = i - 2; format(es, c); DFS(s, c + 1, next_cur);//dfs next step if(flag) return 0; unformat(es, c); } } else { char es[10] = {0}; int i = 0, j = 0, e = 0; for(i = cur; i >= 0; i--) { if(isdigit(s[i])) { if(step != (strlen(cs) - 1)) { for(j = i - 1; j <= i; j++)// 2 bits es[e++] = s[j]; es[e] = '\0'; } else { for(j = i - 3; j <= i; j++)// 2 bits { if(j < 0) break; es[e++] = s[j]; } es[e] = '\0'; } break; } } int next_cur = i - 2; format(es, step); DFS(s, step + 1, next_cur);//dfs next step if(flag) return 0; unformat(es, step); } return 0; }
pixel_data(int pixel, SDL_PixelFormat* fmt) : r(0), g(0), b(0) { unformat(pixel, fmt); }
static clib_error_t * unix_config (vlib_main_t * vm, unformat_input_t * input) { unix_main_t *um = &unix_main; clib_error_t *error = 0; gid_t gid; int pidfd = -1; /* Defaults */ um->cli_pager_buffer_limit = UNIX_CLI_DEFAULT_PAGER_LIMIT; um->cli_history_limit = UNIX_CLI_DEFAULT_HISTORY; while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { char *cli_prompt; if (unformat (input, "interactive")) um->flags |= UNIX_FLAG_INTERACTIVE; else if (unformat (input, "nodaemon")) um->flags |= UNIX_FLAG_NODAEMON; else if (unformat (input, "cli-prompt %s", &cli_prompt)) vlib_unix_cli_set_prompt (cli_prompt); else if (unformat (input, "cli-listen %s", &um->cli_listen_socket.config)) ; else if (unformat (input, "runtime-dir %s", &um->runtime_dir)) ; else if (unformat (input, "cli-line-mode")) um->cli_line_mode = 1; else if (unformat (input, "cli-no-banner")) um->cli_no_banner = 1; else if (unformat (input, "cli-no-pager")) um->cli_no_pager = 1; else if (unformat (input, "poll-sleep-usec %d", &um->poll_sleep_usec)) ; else if (unformat (input, "cli-pager-buffer-limit %d", &um->cli_pager_buffer_limit)) ; else if (unformat (input, "cli-history-limit %d", &um->cli_history_limit)) ; else if (unformat (input, "coredump-size")) { uword coredump_size = 0; if (unformat (input, "unlimited")) { coredump_size = RLIM_INFINITY; } else if (!unformat (input, "%U", unformat_memory_size, &coredump_size)) { return clib_error_return (0, "invalid coredump-size parameter `%U'", format_unformat_error, input); } const struct rlimit new_limit = { coredump_size, coredump_size }; if (0 != setrlimit (RLIMIT_CORE, &new_limit)) { clib_unix_warning ("prlimit() failed"); } } else if (unformat (input, "full-coredump")) { int fd; fd = open ("/proc/self/coredump_filter", O_WRONLY); if (fd >= 0) { if (write (fd, "0x6f\n", 5) != 5) clib_unix_warning ("coredump filter write failed!"); close (fd); } else clib_unix_warning ("couldn't open /proc/self/coredump_filter"); } else if (unformat (input, "startup-config %s", &um->startup_config_filename)) ; else if (unformat (input, "exec %s", &um->startup_config_filename)) ; else if (unformat (input, "log %s", &um->log_filename)) { um->log_fd = open ((char *) um->log_filename, O_CREAT | O_WRONLY | O_APPEND, 0644); if (um->log_fd < 0) { clib_warning ("couldn't open log '%s'\n", um->log_filename); um->log_fd = 0; } else { u8 *lv = 0; lv = format (0, "%U: ***** Start: PID %d *****\n", format_timeval, 0 /* current bat-time */ , 0 /* current bat-format */ , getpid ()); { int rv __attribute__ ((unused)) = write (um->log_fd, lv, vec_len (lv)); } vec_free (lv); } } else if (unformat (input, "gid %U", unformat_unix_gid, &gid)) { if (setegid (gid) == -1) return clib_error_return_unix (0, "setegid"); } else if (unformat (input, "pidfile %s", &um->pidfile)) ; else return clib_error_return (0, "unknown input `%U'", format_unformat_error, input); } if (um->runtime_dir == 0) { uid_t uid = geteuid (); if (uid == 00) um->runtime_dir = format (0, "/run/%s%c", vlib_default_runtime_dir, 0); else um->runtime_dir = format (0, "/run/user/%u/%s%c", uid, vlib_default_runtime_dir, 0); } error = setup_signal_handlers (um); if (error) return error; if (um->pidfile) { if ((error = vlib_unix_validate_runtime_file (um, (char *) um->pidfile, &um->pidfile))) return error; if (((pidfd = open ((char *) um->pidfile, O_CREAT | O_WRONLY | O_TRUNC, 0644)) < 0)) { return clib_error_return_unix (0, "open"); } } if (!(um->flags & UNIX_FLAG_INTERACTIVE)) { openlog (vm->name, LOG_CONS | LOG_PERROR | LOG_PID, LOG_DAEMON); clib_error_register_handler (unix_error_handler, um); if (!(um->flags & UNIX_FLAG_NODAEMON) && daemon ( /* chdir to / */ 0, /* stdin/stdout/stderr -> /dev/null */ 0) < 0) clib_error_return (0, "daemon () fails"); } if (pidfd >= 0) { u8 *lv = format (0, "%d", getpid ()); if (write (pidfd, (char *) lv, vec_len (lv)) != vec_len (lv)) { vec_free (lv); close (pidfd); return clib_error_return_unix (0, "write"); } vec_free (lv); close (pidfd); } um->unix_config_complete = 1; return 0; }
int test_random_main (unformat_input_t * input) { uword n_iterations; uword i, repeat_count; uword * bitmap = 0; uword print; u32 seed; u32 *seedp = &seed; /* first, check known sequence from Numerical Recipes in C, 2nd ed. page 284 */ seed = known_random_sequence[0]; for (i = 0; i < ARRAY_LEN(known_random_sequence)-1; i++) { u32 rv; rv = random_u32 (seedp); if (rv != known_random_sequence[i+1]) { fformat(stderr, "known sequence check FAILS at index %d", i+1); break; } } clib_warning ("known sequence check passes"); n_iterations = 1000; seed = 0; print = 1 << 24; while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { if (0 == unformat (input, "iter %d", &n_iterations) && 0 == unformat (input, "print %d", &print) && 0 == unformat (input, "seed %d", &seed)) clib_error ("unknown input `%U'", format_unformat_error, input); } if (! seed) seed = random_default_seed (); if (n_iterations == 0) n_iterations = random_u32_max (); clib_warning ("%d iterations, seed %d\n", n_iterations, seed); repeat_count = 0; for (i = 0; i < n_iterations; i++) { uword r = random_u32 (&seed); uword b, ri, rj; ri = r / BITS (bitmap[0]); rj = (uword) 1 << (r % BITS (bitmap[0])); vec_validate (bitmap, ri); b = bitmap[ri]; if (b & rj) goto repeat; b |= rj; bitmap[ri] = b; if (0 == (i & (print - 1))) fformat (stderr, "0x%08x iterations %d repeats\n", i, repeat_count); continue; repeat: fformat (stderr, "repeat found at iteration %d/%d\n", i, n_iterations); repeat_count++; continue; } return 0; }