return subs;
}
+static int
+vlib_cli_cmp_rule (void * a1, void * a2)
+{
+ vlib_cli_sub_rule_t * r1 = a1;
+ vlib_cli_sub_rule_t * r2 = a2;
+
+ return vec_cmp (r1->name, r2->name);
+}
+
+static int
+vlib_cli_cmp_command (void * a1, void * a2)
+{
+ vlib_cli_command_t * c1 = a1;
+ vlib_cli_command_t * c2 = a2;
+
+ return vec_cmp (c1->path, c2->path);
+}
+
static clib_error_t *
vlib_cli_dispatch_sub_commands (vlib_main_t * vm,
vlib_cli_main_t * cm,
sr->rule_index = ~0;
}
- vec_sort (subs, c1, c2, vec_cmp (c1->name, c2->name));
+ vec_sort_with_function (subs, vlib_cli_cmp_rule);
for (i = 0; i < vec_len (subs); i++)
{
vlib_cli_command_t * sub, * subs;
subs = all_subs (cm, 0, parent_command_index);
- vec_sort (subs, c1, c2, vec_cmp (c1->path, c2->path));
+ vec_sort_with_function (subs, vlib_cli_cmp_command);
vec_foreach (sub, subs)
vlib_cli_output (vm, " %-40U %U",
format_vlib_cli_path, sub->path,
return format (s, "%s", t);
}
+static int
+mc_peer_comp (void * a1, void * a2)
+{
+ mc_stream_peer_t * p1 = a1;
+ mc_stream_peer_t * p2 = a2;
+
+ return mc_peer_id_compare (p1->id, p2->id);
+}
+
u8 * format_mc_main (u8 * s, va_list * args)
{
mc_main_t * mcm = va_arg (*args, mc_main_t *);
if (clib_bitmap_get (t->all_peer_bitmap, p - t->peers))
vec_add1 (ps, p[0]);
}));
- vec_sort (ps, p1, p2, mc_peer_id_compare (p1->id, p2->id));
+ vec_sort_with_function (ps, mc_peer_comp);
s = format (s, "\n%U%=30s%10s%16s%16s",
format_white_space, indent + 6,
"Peer", "Last seq", "Retries", "Future");
#include <vlib/vlib.h>
#include <vlib/threads.h>
+static int
+node_cmp (void * a1, void *a2)
+{
+ vlib_node_t ** n1 = a1;
+ vlib_node_t ** n2 = a2;
+
+ return vec_cmp (n1[0]->name, n2[0]->name);
+}
+
static clib_error_t *
show_node_graph (vlib_main_t * vm,
unformat_input_t * input,
vlib_node_t ** nodes = vec_dup (nm->nodes);
uword i;
- vec_sort (nodes, n1, n2,
- vec_cmp (n1[0]->name, n2[0]->name));
+ vec_sort_with_function (nodes, node_cmp);
for (i = 0; i < vec_len (nodes); i++)
vlib_cli_output (vm, "%U\n\n", format_vlib_node_graph, nm, nodes[i]);
stat_vm = stat_vms[j];
nodes = node_dups[j];
- vec_sort (nodes, n1, n2,
- vec_cmp (n1[0]->name, n2[0]->name));
+ vec_sort_with_function (nodes, node_cmp);
n_input = n_output = n_drop = n_punt = n_clocks = 0;
n_internal_vectors = n_internal_calls = 0;
}
vec_free (bounds);
- vec_sort (pm->parse_registrations, r1, r2,
- rule_length_compare (r1[0], r2[0]));
+ vec_sort_with_function (pm->parse_registrations, rule_length_compare);
for (i = 0; i < vec_len (pm->parse_registrations); i++)
{
.short_help = "Packet tracer commands",
};
+static int
+trace_cmp (void * a1, void * a2)
+{
+ vlib_trace_header_t ** t1 = a1;
+ vlib_trace_header_t ** t2 = a2;
+ i64 dt = t1[0]->time - t2[0]->time;
+ return dt < 0 ? -1 : (dt > 0 ? +1 : 0);
+}
+
static clib_error_t *
cli_show_trace_buffer (vlib_main_t * vm,
unformat_input_t * input,
}
/* Sort them by increasing time. */
- vec_sort (traces, t0, t1, ({
- i64 dt = t0[0]->time - t1[0]->time;
- dt < 0 ? -1 : (dt > 0 ? +1 : 0);
- }));
+ vec_sort_with_function (traces, trace_cmp);
for (i = 0; i < vec_len (traces); i++)
{
}
}
+static int
+feature_cmp (void * a1, void * a2)
+{
+ vnet_config_feature_t * f1 = a1;
+ vnet_config_feature_t * f2 = a2;
+
+ return (int) f1->feature_index - f2->feature_index;
+}
+
always_inline u32 *
vnet_get_config_heap (vnet_config_main_t * cm, u32 ci)
{ return heap_elt_at_index (cm->config_string_heap, ci); }
/* Sort (prioritize) features. */
if (vec_len (new_features) > 1)
- vec_sort (new_features, f1, f2, (int) f1->feature_index - f2->feature_index);
+ vec_sort_with_function (new_features, feature_cmp);
if (old)
remove_reference (cm, old);
u32 index : 26;
}) ip4_route_t;
+static int
+ip4_route_cmp (void * a1, void * a2)
+{
+ ip4_route_t * r1 = a1;
+ ip4_route_t * r2 = a2;
+
+ int cmp = ip4_address_compare (&r1->address, &r2->address);
+ return cmp ? cmp : ((int) r1->address_length - (int) r2->address_length);
+}
+
static clib_error_t *
ip4_show_fib (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
{
}
}
- vec_sort (routes, r1, r2,
- ({ int cmp = ip4_address_compare (&r1->address, &r2->address);
- cmp ? cmp : ((int) r1->address_length - (int) r2->address_length); }));
+ vec_sort_with_function (routes, ip4_route_cmp);
if (vec_len(routes)) {
if (include_empty_fibs == 0)
vlib_cli_output (vm, "Table %d, fib_index %d, flow hash: %U",
ap->count_by_prefix_length[mask_width]++;
}
+static int
+ip6_route_cmp (void * a1, void * a2)
+{
+ ip6_route_t * r1 = a1;
+ ip6_route_t * r2 = a2;
+
+ int cmp = ip6_address_compare (&r1->address, &r2->address);
+ return cmp ? cmp : ((int) r1->address_length - (int) r2->address_length);
+}
static clib_error_t *
ip6_show_fib (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
BV(clib_bihash_foreach_key_value_pair)(h, add_routes_in_fib, a);
- vec_sort (routes, r1, r2,
- ({ int cmp = ip6_address_compare (&r1->address, &r2->address);
- cmp ? cmp : ((int) r1->address_length - (int) r2->address_length); }));
+ vec_sort_with_function (routes, ip6_route_cmp);
vlib_cli_output (vm, "%=45s%=16s%=16s%=16s",
"Destination", "Packets", "Bytes", "Adjacency");
u32 label;
} show_mpls_fib_t;
+static int
+mpls_dest_cmp(void * a1, void * a2)
+{
+ show_mpls_fib_t * r1 = a1;
+ show_mpls_fib_t * r2 = a2;
+
+ return clib_net_to_host_u32(r1->dest) - clib_net_to_host_u32(r2->dest);
+}
+
+static int
+mpls_fib_index_cmp(void * a1, void * a2)
+{
+ show_mpls_fib_t * r1 = a1;
+ show_mpls_fib_t * r2 = a2;
+
+ return r1->fib_index - r2->fib_index;
+}
+
+static int
+mpls_label_cmp(void * a1, void * a2)
+{
+ show_mpls_fib_t * r1 = a1;
+ show_mpls_fib_t * r2 = a2;
+
+ return r1->label - r2->label;
+}
+
static clib_error_t *
show_mpls_fib_command_fn (vlib_main_t * vm,
unformat_input_t * input,
goto decap_table;
}
/* sort output by dst address within fib */
- vec_sort (records, r0, r1, clib_net_to_host_u32(r0->dest) -
- clib_net_to_host_u32(r1->dest));
- vec_sort (records, r0, r1, r0->fib_index - r1->fib_index);
+ vec_sort_with_function (records, mpls_dest_cmp);
+ vec_sort_with_function (records, mpls_fib_index_cmp);
vlib_cli_output (vm, "MPLS encap table");
vlib_cli_output (vm, "%=6s%=16s%=16s", "Table", "Dest address", "Labels");
vec_foreach (s, records)
goto out;
}
- vec_sort (records, r0, r1, r0->label - r1->label);
+ vec_sort_with_function (records, mpls_label_cmp);
vlib_cli_output (vm, "MPLS decap table");
vlib_cli_output (vm, "%=10s%=15s%=6s%=6s", "RX Table", "TX Table/Intfc",
return 0;
}
+static int name_sort_cmp (void * a1, void * a2)
+{
+ name_sort_t * n1 = a1;
+ name_sort_t * n2 = a2;
+
+ return strcmp ((char *)n1->name, (char *)n2->name);
+}
+
static int dump_interface_table (vat_main_t * vam)
{
hash_pair_t * p;
ns->value = (u32) p->value[0];
}));
- vec_sort (nses, n1, n2,
- strcmp ((char *)n1->name, (char *)n2->name));
+ vec_sort_with_function (nses, name_sort_cmp);
fformat (vam->ofp, "%-25s%-15s\n", "Interface", "sw_if_index");
vec_foreach (ns, nses) {
return 0;
}
+static int cmd_cmp (void * a1, void * a2)
+{
+ u8 ** c1 = a1;
+ u8 ** c2 = a2;
+
+ return strcmp ((char *)(c1[0]), (char *)(c2[0]));
+}
+
static int help (vat_main_t * vam)
{
u8 ** cmds = 0;
vec_add1 (cmds, (u8 *)(p->key));
}));
- vec_sort (cmds, c1, c2,
- strcmp ((char *)(c1[0]), (char *)(c2[0])));
+ vec_sort_with_function (cmds, cmd_cmp);
for (j = 0; j < vec_len(cmds); j++)
fformat (vam->ofp, "%s\n", cmds[j]);
} macro_sort_t;
+static int macro_sort_cmp (void * a1, void * a2)
+{
+ macro_sort_t * s1 = a1;
+ macro_sort_t * s2 = a2;
+
+ return strcmp ((char *)(s1->name), (char *)(s2->name));
+}
+
static int dump_macro_table (vat_main_t * vam)
{
macro_sort_t * sort_me = 0, * sm;
sm->value = (u8 *) (p->value[0]);
}));
- vec_sort (sort_me, s1, s2, strcmp ((char *)(s1->name), (char *)(s2->name)));
+ vec_sort_with_function (sort_me, macro_sort_cmp);
if (vec_len(sort_me))
fformat (vam->ofp, "%-15s%s\n", "Name", "Value");
return (rv);
}
+static int
+name_sort_cmp (void * a1, void * a2)
+{
+ name_sort_t * n1 = a1;
+ name_sort_t * n2 = a2;
+
+ return strcmp ((char *)n1->name, (char *)n2->name);
+}
+
JNIEXPORT jstring JNICALL Java_org_openvpp_vppjapi_vppConn_getInterfaceList
(JNIEnv * env, jobject obj, jstring name_filter)
{
}
}));
- vec_sort (nses, n1, n2,
- strcmp ((char *)n1->name, (char *)n2->name));
+ vec_sort_with_function (nses, name_sort_cmp);
vec_foreach (ns, nses)
s = format (s, "%s: %d, ", ns->name, ns->value);
#define API_LINK_STATE_EVENT 1
#define API_ADMIN_UP_DOWN_EVENT 2
+static int
+event_data_cmp (void * a1, void * a2)
+{
+ uword * e1 = a1;
+ uword * e2 = a2;
+
+ return (word) e1[0] - (word) e2[0];
+}
+
static uword
link_state_process (vlib_main_t * vm,
vlib_node_runtime_t * rt,
(vm, &event_data, API_ADMIN_UP_DOWN_EVENT);
/* Sort, so we can eliminate duplicates */
- vec_sort (event_data, e1, e2, (word) e1[0] - (word) e2[0]);
+ vec_sort_with_function (event_data, event_data_cmp);
prev_sw_if_index = ~0;
}
}
+static int elog_cmp (void * a1, void * a2)
+{
+ elog_event_t * e1 = a1;
+ elog_event_t * e2 = a2;
+
+ return e1->time - e2->time;
+}
+
void elog_merge (elog_main_t * dst, u8 * dst_tag,
elog_main_t * src, u8 * src_tag)
{
}
/* Sort events by increasing time. */
- vec_sort (dst->events, e1, e2, e1->time < e2->time ? -1 : (e1->time > e2->time ? +1 : 0));
+ vec_sort_with_function (dst->events, elog_cmp);
/* Recreate the event ring or the results won't serialize */
{
serialize_integer (m, vec_len (em->events), sizeof (u32));
/* SMP logs can easily have local time paradoxes... */
- vec_sort (em->events, e0, e1, e0->time - e1->time);
+ vec_sort_with_function (em->events, elog_cmp);
vec_foreach (e, em->events)
serialize (m, serialize_elog_event, em, e);
f64 time_next_status_update;
} test_timing_wheel_main_t;
+typedef struct {
+ f64 dt;
+ f64 fraction;
+ u64 count;
+} test_timing_wheel_tmp_t;
+
static void set_event (test_timing_wheel_main_t * tm, uword i)
{
timing_wheel_t * w = &tm->timing_wheel;
tm->events[i] = cpu_time;
}
+static int test_timing_wheel_tmp_cmp (void * a1, void * a2)
+{
+ test_timing_wheel_tmp_t * f1 = a1;
+ test_timing_wheel_tmp_t * f2 = a2;
+
+ return f1->dt < f2->dt ? -1 : (f1->dt > f2->dt ? +1 : 0);
+}
+
clib_error_t *
test_timing_wheel_main (unformat_input_t * input)
{
min_error, max_error);
{
- struct tmp {
- f64 dt;
- f64 fraction;
- u64 count;
- } * fs, * f;
+ test_timing_wheel_tmp_t * fs, * f;
f64 total_fraction;
fs = 0;
f->count = error_hist[i];
}
- vec_sort (fs, f1, f2, f1->dt < f2->dt ? -1 : (f1->dt > f2->dt ? +1 : 0));
+ vec_sort_with_function (fs, test_timing_wheel_tmp_cmp);
total_fraction = 0;
vec_foreach (f, fs)