u32 bier_fmask_db_find_or_create_and_lock (index_t bti, const fib_route_path_t *rpath) { bier_fmask_id_t fmid; u32 index; uword *p; bier_fmask_db_mk_key(bti, rpath, &fmid); p = hash_get_mem(bier_fmask_db.bfdb_hash, &fmid); if (NULL == p) { bier_fmask_t *bfm; /* * adding a new fmask object */ index = bier_fmask_create_and_lock(&fmid, rpath); bfm = bier_fmask_get(index); hash_set_mem(bier_fmask_db.bfdb_hash, bfm->bfm_id, index); } else { index = p[0]; bier_fmask_lock(index); } return (index); }
int event_pass2(cpel_section_header_t *sh, int verbose, FILE *ofp) { event_section_header_t *eh; u32 event_code, track_code, datum; u64 starttime = ~0ULL; int nevents; int i; event_entry_t *ep; u64 now; u64 delta; u32 time0, time1; double d; uword *p; eh = (event_section_header_t *)(sh+1); nevents = ntohl(eh->number_of_events); ticks_per_ns = ntohl(eh->clock_ticks_per_second)/1e9; ep = (event_entry_t *)(eh+1); p = hash_get_mem(the_strtab_hash, eh->string_table_name); if (!p) { fprintf(ofp, "Fatal: couldn't find string table\n"); return(1); } event_strtab = (u8 *)p[0]; cpel_event_init(nevents); for (i = 0; i < nevents; i++) { time0 = ntohl (ep->time[0]); time1 = ntohl (ep->time[1]); now = (((u64) time0)<<32) | time1; /* Convert from bus ticks to usec */ d = now; d /= ticks_per_ns; now = d; if (starttime == ~0ULL) starttime = now; delta = now - starttime; /* Delta = time since first event, in usec */ event_code = ntohl(ep->event_code); track_code = ntohl(ep->track); datum = ntohl(ep->event_datum); add_cpel_event(delta, track_code, event_code, datum); ep++; } cpel_event_finalize(); return(0); }
int evtdef_pass1(cpel_section_header_t *sh, int verbose, FILE *ofp) { int i, nevents; event_definition_section_header_t *edh; event_definition_t *ep; u8 *this_strtab; u32 event_code; uword *p; bound_event_t *bp; edh = (event_definition_section_header_t *)(sh+1); nevents = ntohl(edh->number_of_event_definitions); if (verbose) { fprintf(ofp, "Event Definition Section: %d definitions\n", nevents); } p = hash_get_mem(the_strtab_hash, edh->string_table_name); if (!p) { fprintf(ofp, "Fatal: couldn't find string table\n"); return(1); } this_strtab = (u8 *)p[0]; initialize_events(); ep = (event_definition_t *)(edh+1); for (i = 0; i < nevents; i++) { event_code = ntohl(ep->event); p = hash_get(the_evtdef_hash, event_code); if (p) { fprintf(ofp, "Event %d redefined, retain first definition\n", event_code); continue; } vec_add2(bound_events, bp, 1); bp->event_code = event_code; bp->event_str = this_strtab + ntohl(ep->event_format); bp->datum_str = this_strtab + ntohl(ep->datum_format); hash_set(the_evtdef_hash, event_code, bp - bound_events); add_event_from_cpel_file(event_code, (char *) bp->event_str, (char *)bp->datum_str); ep++; } finalize_events(); return (0); }
int trackdef_pass1(cpel_section_header_t *sh, int verbose, FILE *ofp) { int i, nevents; track_definition_section_header_t *tdh; track_definition_t *tp; u8 *this_strtab; u32 track_code; uword *p; bound_track_t *btp; int track_strlen; tdh = (track_definition_section_header_t *)(sh+1); nevents = ntohl(tdh->number_of_track_definitions); if (verbose) { fprintf(ofp, "Track Definition Section: %d definitions\n", nevents); } p = hash_get_mem(the_strtab_hash, tdh->string_table_name); if (!p) { fprintf(ofp, "Fatal: couldn't find string table\n"); return(1); } this_strtab = (u8 *)p[0]; tp = (track_definition_t *)(tdh+1); for (i = 0; i < nevents; i++) { track_code = ntohl(tp->track); p = hash_get(the_trackdef_hash, track_code); if (p) { fprintf(ofp, "track %d redefined, retain first definition\n", track_code); continue; } vec_add2(bound_tracks, btp, 1); btp->track = track_code; btp->track_str = this_strtab + ntohl(tp->track_format); hash_set(the_trackdef_hash, track_code, btp - bound_tracks); track_strlen = strlen((char *)btp->track_str); if (track_strlen > widest_track_format) widest_track_format = track_strlen; tp++; } return (0); }
void bier_fmask_db_remove (const bier_fmask_id_t *fmid) { uword *p; p = hash_get_mem(bier_fmask_db.bfdb_hash, fmid); if (NULL == p) { /* * remove a non-existent entry - oops */ ASSERT (!"remove non-existent fmask"); } else { hash_unset(bier_fmask_db.bfdb_hash, fmid); } }
u32 bier_fmask_db_find (index_t bti, const fib_route_path_t *rpath) { bier_fmask_id_t fmid; uword *p; bier_fmask_db_mk_key(bti, rpath, &fmid); p = hash_get_mem(bier_fmask_db.bfdb_hash, &fmid); if (NULL != p) { return (p[0]); } return (INDEX_INVALID); }
static u32 elog_id_for_msg_name (vlib_main_t * vm, char *msg_name) { uword * p, r; static uword * h; u8 *name_copy; if (! h) h = hash_create_string (0, sizeof (uword)); p = hash_get_mem (h, msg_name); if (p) return p[0]; r = elog_string (&vm->elog_main, "%s", msg_name); name_copy = format (0, "%s%c", msg_name, 0); hash_set_mem (h, name_copy, r); return r; }
int strtab_pass1(cpel_section_header_t *sh, int verbose, FILE *ofp) { uword *p; u8 *strtab_data_area = (u8 *)(sh+1); /* Multiple string tables with the same name are Bad... */ p = hash_get_mem(the_strtab_hash, strtab_data_area); if (p) { fprintf(ofp, "Duplicate string table name %s", strtab_data_area); } /* * Looks funny, but we really do want key = first string in the * table, value = address(first string in the table) */ hash_set_mem(the_strtab_hash, strtab_data_area, strtab_data_area); if (verbose) { fprintf(ofp, "String Table %s\n", strtab_data_area); } return(0); }
static u32 ip_multipath_adjacency_get (ip_lookup_main_t * lm, ip_multipath_next_hop_t * raw_next_hops, uword create_if_non_existent) { uword * p; u32 i, j, n_adj, adj_index, adj_heap_handle; ip_adjacency_t * adj, * copy_adj; ip_multipath_next_hop_t * nh, * nhs; ip_multipath_adjacency_t * madj; n_adj = ip_multipath_normalize_next_hops (lm, raw_next_hops, &lm->next_hop_hash_lookup_key_normalized); nhs = lm->next_hop_hash_lookup_key_normalized; /* Basic sanity. */ ASSERT (n_adj >= vec_len (raw_next_hops)); /* Use normalized next hops to see if we've seen a block equivalent to this one before. */ p = hash_get_mem (lm->multipath_adjacency_by_next_hops, nhs); if (p) return p[0]; if (! create_if_non_existent) return 0; adj = ip_add_adjacency (lm, /* copy_adj */ 0, n_adj, &adj_index); adj_heap_handle = adj[0].heap_handle; /* Fill in adjacencies in block based on corresponding next hop adjacencies. */ i = 0; vec_foreach (nh, nhs) { copy_adj = ip_get_adjacency (lm, nh->next_hop_adj_index); for (j = 0; j < nh->weight; j++) { adj[i] = copy_adj[0]; adj[i].heap_handle = adj_heap_handle; adj[i].n_adj = n_adj; i++; } }
static void lisp_gpe_increment_stats_counters (lisp_cp_main_t * lcm, ip_adjacency_t * adj, vlib_buffer_t * b) { lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main (); lisp_gpe_adjacency_t *ladj; ip_address_t rloc; index_t lai; u32 si, di; gid_address_t src, dst; uword *feip; ip46_address_to_ip_address (&adj->sub_type.nbr.next_hop, &rloc); si = vnet_buffer (b)->sw_if_index[VLIB_TX]; lai = lisp_adj_find (&rloc, si); ASSERT (INDEX_INVALID != lai); ladj = pool_elt_at_index (lisp_adj_pool, lai); u8 *lisp_data = (u8 *) vlib_buffer_get_current (b); /* skip IP header */ if (is_v4_packet (lisp_data)) lisp_data += sizeof (ip4_header_t); else lisp_data += sizeof (ip6_header_t); /* skip UDP header */ lisp_data += sizeof (udp_header_t); // TODO: skip TCP? /* skip LISP GPE header */ lisp_data += sizeof (lisp_gpe_header_t); i16 saved_current_data = b->current_data; b->current_data = lisp_data - b->data; lisp_afi_e afi = lisp_afi_from_vnet_link_type (adj->ia_link); get_src_and_dst_eids_from_buffer (lcm, b, &src, &dst, afi); b->current_data = saved_current_data; di = gid_dictionary_sd_lookup (&lcm->mapping_index_by_gid, &dst, &src); if (PREDICT_FALSE (~0 == di)) { clib_warning ("dst mapping not found (%U, %U)", format_gid_address, &src, format_gid_address, &dst); return; } feip = hash_get (lcm->fwd_entry_by_mapping_index, di); if (PREDICT_FALSE (!feip)) return; lisp_stats_key_t key; clib_memset (&key, 0, sizeof (key)); key.fwd_entry_index = feip[0]; key.tunnel_index = ladj->tunnel_index; uword *p = hash_get_mem (lgm->lisp_stats_index_by_key, &key); ASSERT (p); /* compute payload length starting after GPE */ u32 bytes = b->current_length - (lisp_data - b->data - b->current_data); vlib_increment_combined_counter (&lgm->counters, vlib_get_thread_index (), p[0], 1, bytes); }
int vat_load_new_plugins (plugin_main_t * pm) { DIR *dp; struct dirent *entry; struct stat statb; uword *p; plugin_info_t *pi; u8 **plugin_path; int i; plugin_path = split_plugin_path (pm); for (i = 0; i < vec_len (plugin_path); i++) { dp = opendir ((char *) plugin_path[i]); if (dp == 0) continue; while ((entry = readdir (dp))) { u8 *plugin_name; u8 *file_name; if (pm->plugin_name_filter) { int j; for (j = 0; j < vec_len (pm->plugin_name_filter); j++) if (entry->d_name[j] != pm->plugin_name_filter[j]) goto next; } file_name = format (0, "%s/%s%c", plugin_path[i], entry->d_name, 0); plugin_name = format (0, "%s%c", entry->d_name, 0); /* unreadable */ if (stat ((char *) file_name, &statb) < 0) { ignore: vec_free (file_name); vec_free (plugin_name); continue; } /* a dir or other things which aren't plugins */ if (!S_ISREG (statb.st_mode)) goto ignore; p = hash_get_mem (pm->plugin_by_name_hash, plugin_name); if (p == 0) { vec_add2 (pm->plugin_info, pi, 1); pi->name = plugin_name; pi->filename = file_name; pi->file_info = statb; if (load_one_vat_plugin (pm, pi)) { vec_free (file_name); vec_free (plugin_name); _vec_len (pm->plugin_info) = vec_len (pm->plugin_info) - 1; continue; } clib_memset (pi, 0, sizeof (*pi)); hash_set_mem (pm->plugin_by_name_hash, plugin_name, pi - pm->plugin_info); } next: ; } closedir (dp); vec_free (plugin_path[i]); } vec_free (plugin_path); return 0; }
clib_error_t * policer_add_del (vlib_main_t *vm, u8 * name, sse2_qos_pol_cfg_params_st * cfg, u32 * policer_index, u8 is_add) { vnet_policer_main_t *pm = &vnet_policer_main; policer_read_response_type_st test_policer; policer_read_response_type_st * policer; uword * p; u32 pi; int rv; p = hash_get_mem (pm->policer_config_by_name, name); if (is_add == 0) { if (p == 0) { vec_free(name); return clib_error_return (0, "No such policer configuration"); } hash_unset_mem (pm->policer_config_by_name, name); hash_unset_mem (pm->policer_index_by_name, name); vec_free(name); return 0; } if (p != 0) { vec_free(name); return clib_error_return (0, "Policer already exists"); } /* Vet the configuration before adding it to the table */ rv = sse2_pol_logical_2_physical (cfg, &test_policer); if (rv == 0) { policer_read_response_type_st *pp; sse2_qos_pol_cfg_params_st *cp; pool_get (pm->configs, cp); pool_get (pm->policer_templates, pp); ASSERT (cp - pm->configs == pp - pm->policer_templates); clib_memcpy (cp, cfg, sizeof (*cp)); clib_memcpy (pp, &test_policer, sizeof (*pp)); hash_set_mem (pm->policer_config_by_name, name, cp - pm->configs); pool_get_aligned (pm->policers, policer, CLIB_CACHE_LINE_BYTES); policer[0] = pp[0]; pi = policer - pm->policers; hash_set_mem (pm->policer_index_by_name, name, pi); *policer_index = pi; } else { vec_free (name); return clib_error_return (0, "Config failed sanity check"); } return 0; }
clib_error_t * vlib_call_all_config_functions (vlib_main_t * vm, unformat_input_t * input, int is_early) { clib_error_t *error = 0; vlib_config_function_runtime_t *c, **all; uword *hash = 0, *p; uword i; hash = hash_create_string (0, sizeof (uword)); all = 0; c = vm->config_function_registrations; while (c) { hash_set_mem (hash, c->name, vec_len (all)); vec_add1 (all, c); unformat_init (&c->input, 0, 0); c = c->next_registration; } while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { u8 *s, *v; if (!unformat (input, "%s %v", &s, &v) || !(p = hash_get_mem (hash, s))) { error = clib_error_create ("unknown input `%s %v'", s, v); goto done; } c = all[p[0]]; if (vec_len (c->input.buffer) > 0) vec_add1 (c->input.buffer, ' '); vec_add (c->input.buffer, v, vec_len (v)); vec_free (v); vec_free (s); } for (i = 0; i < vec_len (all); i++) { c = all[i]; /* Is this an early config? Are we doing early configs? */ if (is_early ^ c->is_early) continue; /* Already called? */ if (hash_get (vm->init_functions_called, c->function)) continue; hash_set1 (vm->init_functions_called, c->function); error = c->function (vm, &c->input); if (error) goto done; } done: for (i = 0; i < vec_len (all); i++) { c = all[i]; unformat_free (&c->input); } vec_free (all); hash_free (hash); return error; }
void scrape_and_clear_counters (perfmon_main_t * pm) { int i, j, k; vlib_main_t *vm = pm->vlib_main; vlib_main_t *stat_vm; vlib_node_main_t *nm; vlib_node_t ***node_dups = 0; vlib_node_t **nodes; vlib_node_t *n; perfmon_capture_t *c; perfmon_event_config_t *current_event; uword *p; u8 *counter_name; u64 vectors_this_counter; /* snapshoot the nodes, including pm counters */ vlib_worker_thread_barrier_sync (vm); for (j = 0; j < vec_len (vlib_mains); j++) { stat_vm = vlib_mains[j]; if (stat_vm == 0) continue; nm = &stat_vm->node_main; for (i = 0; i < vec_len (nm->nodes); i++) { n = nm->nodes[i]; vlib_node_sync_stats (stat_vm, n); } nodes = 0; vec_validate (nodes, vec_len (nm->nodes) - 1); vec_add1 (node_dups, nodes); /* Snapshoot and clear the per-node perfmon counters */ for (i = 0; i < vec_len (nm->nodes); i++) { n = nm->nodes[i]; nodes[i] = clib_mem_alloc (sizeof (*n)); clib_memcpy_fast (nodes[i], n, sizeof (*n)); n->stats_total.perf_counter0_ticks = 0; n->stats_total.perf_counter1_ticks = 0; n->stats_total.perf_counter_vectors = 0; n->stats_last_clear.perf_counter0_ticks = 0; n->stats_last_clear.perf_counter1_ticks = 0; n->stats_last_clear.perf_counter_vectors = 0; } } vlib_worker_thread_barrier_release (vm); for (j = 0; j < vec_len (vlib_mains); j++) { stat_vm = vlib_mains[j]; if (stat_vm == 0) continue; nodes = node_dups[j]; for (i = 0; i < vec_len (nodes); i++) { u8 *capture_name; n = nodes[i]; if (n->stats_total.perf_counter0_ticks == 0 && n->stats_total.perf_counter1_ticks == 0) goto skip_this_node; for (k = 0; k < 2; k++) { u64 counter_value, counter_last_clear; /* * We collect 2 counters at once, except for the * last counter when the user asks for an odd number of * counters */ if ((pm->current_event + k) >= vec_len (pm->single_events_to_collect)) break; if (k == 0) { counter_value = n->stats_total.perf_counter0_ticks; counter_last_clear = n->stats_last_clear.perf_counter0_ticks; } else { counter_value = n->stats_total.perf_counter1_ticks; counter_last_clear = n->stats_last_clear.perf_counter1_ticks; } capture_name = format (0, "t%d-%v%c", j, n->name, 0); p = hash_get_mem (pm->capture_by_thread_and_node_name, capture_name); if (p == 0) { pool_get (pm->capture_pool, c); memset (c, 0, sizeof (*c)); c->thread_and_node_name = capture_name; hash_set_mem (pm->capture_by_thread_and_node_name, capture_name, c - pm->capture_pool); } else { c = pool_elt_at_index (pm->capture_pool, p[0]); vec_free (capture_name); } /* Snapshoot counters, etc. into the capture */ current_event = pm->single_events_to_collect + pm->current_event + k; counter_name = (u8 *) current_event->name; vectors_this_counter = n->stats_total.perf_counter_vectors - n->stats_last_clear.perf_counter_vectors; vec_add1 (c->counter_names, counter_name); vec_add1 (c->counter_values, counter_value - counter_last_clear); vec_add1 (c->vectors_this_counter, vectors_this_counter); } skip_this_node: clib_mem_free (n); } vec_free (nodes); } vec_free (node_dups); }
int test_ptclosure_main (unformat_input_t * input) { test_main_t *tm = &test_main; u8 *item_name; int i, j; u8 **orig; u8 **closure; u8 *a_name, *b_name; int a_index, b_index; uword *p; u8 *this_constraint; int n; u32 *result = 0; tm->index_by_name = hash_create_string (0, sizeof (uword)); n = ARRAY_LEN (items); for (i = 0; i < n; i++) { item_name = (u8 *) items[i]; hash_set_mem (tm->index_by_name, item_name, i); } orig = clib_ptclosure_alloc (n); for (i = 0; i < ARRAY_LEN (constraints); i++) { this_constraint = format (0, "%s%c", constraints[i], 0); if (comma_split (this_constraint, &a_name, &b_name)) { clib_warning ("couldn't split '%s'", constraints[i]); return 1; } p = hash_get_mem (tm->index_by_name, a_name); if (p == 0) { clib_warning ("couldn't find '%s'", a_name); return 1; } a_index = p[0]; p = hash_get_mem (tm->index_by_name, b_name); if (p == 0) { clib_warning ("couldn't find '%s'", b_name); return 1; } b_index = p[0]; orig[a_index][b_index] = 1; vec_free (this_constraint); } dump_closure (tm, "original relation", orig); closure = clib_ptclosure (orig); dump_closure (tm, "closure", closure); /* * Output partial order */ again: for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { if (closure[i][j]) goto item_constrained; } /* Item i can be output */ vec_add1 (result, i); { int k; for (k = 0; k < n; k++) closure[k][i] = 0; /* "Magic" a before a, to keep from ever outputting it again */ closure[i][i] = 1; goto again; } item_constrained: ; } if (vec_len (result) != n) { clib_warning ("no partial order exists"); exit (1); } fformat (stdout, "Partial order:\n"); for (i = vec_len (result) - 1; i >= 0; i--) { fformat (stdout, "%s\n", items[result[i]]); } vec_free (result); clib_ptclosure_free (orig); clib_ptclosure_free (closure); return 0; }