summaryrefslogtreecommitdiffstats
path: root/src/vppinfra/bihash_all_vector.c
blob: 04c1374540239581a2a92b062df6da8d9da11fb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
 * Copyright (c) 2015 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <vppinfra/mem.h>

/* Vector of all bihashes */
__clib_export void **clib_all_bihashes;
static clib_mem_heap_t *clib_all_bihash_heap;

__clib_export clib_mem_heap_t *
clib_all_bihash_set_heap (void)
{
  if (PREDICT_FALSE (clib_all_bihash_heap == 0))
    clib_all_bihash_heap = clib_mem_get_heap ();

  return clib_mem_set_heap (clib_all_bihash_heap);
}

/*
 * Leave it to Beaver to change the size of a bihash
 * by making a clone in a stack local and then copying it...
 */
__clib_export void
clib_bihash_copied (void *dst, void *src)
{
  int i;

  for (i = 0; i < vec_len (clib_all_bihashes); i++)
    {
      if (clib_all_bihashes[i] == src)
	{
	  clib_all_bihashes[i] = dst;
	  return;
	}
    }
  clib_warning ("Couldn't find bihash copy source %llx!", src);
}


/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */
of FIB entries only one chain is required - the * one that forwards traffic matching the fib_entry_t's fib_prefix_t. For those * fib_entry_t that are a resolution target for other fib_entry_t's they will also * need the chain to provide forwarding for those children. We store these additional * chains in delegates to save memory in the common case. */ FIB_ENTRY_DELEGATE_CHAIN_UNICAST_IP4 = FIB_FORW_CHAIN_TYPE_UNICAST_IP4, FIB_ENTRY_DELEGATE_CHAIN_UNICAST_IP6 = FIB_FORW_CHAIN_TYPE_UNICAST_IP6, FIB_ENTRY_DELEGATE_CHAIN_MPLS_EOS = FIB_FORW_CHAIN_TYPE_MPLS_EOS, FIB_ENTRY_DELEGATE_CHAIN_MPLS_NON_EOS = FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS, FIB_ENTRY_DELEGATE_CHAIN_ETHERNET = FIB_FORW_CHAIN_TYPE_ETHERNET, FIB_ENTRY_DELEGATE_CHAIN_NSH = FIB_FORW_CHAIN_TYPE_NSH, /** * Dependency list of covered entries. * these are more specific entries that are interested in changes * to their respective cover */ FIB_ENTRY_DELEGATE_COVERED, /** * BFD session state */ FIB_ENTRY_DELEGATE_BFD, /** * Tracker */ FIB_ENTRY_DELEGATE_TRACK, /** * Attached import/export functionality */ FIB_ENTRY_DELEGATE_ATTACHED_IMPORT, FIB_ENTRY_DELEGATE_ATTACHED_EXPORT, } fib_entry_delegate_type_t; #define FOR_EACH_DELEGATE_CHAIN(_entry, _fdt, _fed, _body) \ { \ for (_fdt = FIB_ENTRY_DELEGATE_CHAIN_UNICAST_IP4; \ _fdt <= FIB_ENTRY_DELEGATE_CHAIN_NSH; \ _fdt++) \ { \ _fed = fib_entry_delegate_find(_entry, _fdt); \ if (NULL != _fed) { \ _body; \ } \ } \ } /** * Distillation of the BFD session states into a go/no-go for using * the associated tracked FIB entry */ typedef enum fib_bfd_state_t_ { FIB_BFD_STATE_UP, FIB_BFD_STATE_DOWN, } fib_bfd_state_t; /** * State for FIB entry tracking */ typedef struct fib_entry_delegate_track_t_ { fib_node_t fedt_node; u32 fedt_sibling; } fib_entry_delegate_track_t; /** * A Delagate is a means to implmenet the Delagation design pattern; the extension of an * objects functionality through the composition of, and delgation to, other objects. * These 'other' objects are delegates. Delagates are thus attached to other FIB objects * to extend their functionality. */ typedef struct fib_entry_delegate_t_ { /** * The FIB entry object to which the delagate is attached */ fib_node_index_t fd_entry_index; /** * The delagate type */ fib_entry_delegate_type_t fd_type; /** * A union of data for the different delegate types * These delegates are stored in a sparse vector on the entry, so they * must all be of the same size. We could use indirection here for all types, * i.e. store an index, that's ok for large delegates, like the attached export * but for the chain delegates it's excessive */ union { /** * Valid for the forwarding chain delegates. The LB that is built. */ dpo_id_t fd_dpo; /** * Valid for the attached import cases. An index of the importer/exporter */ fib_node_index_t fd_index; /** * For the cover tracking. The node list; */ fib_node_list_t fd_list; /** * BFD state */ fib_bfd_state_t fd_bfd_state; /** * tracker state */ fib_entry_delegate_track_t fd_track; }; } fib_entry_delegate_t; struct fib_entry_t_; extern void fib_entry_delegate_remove(fib_entry_t *fib_entry, fib_entry_delegate_type_t type); extern fib_entry_delegate_t *fib_entry_delegate_find_or_add(fib_entry_t *fib_entry, fib_entry_delegate_type_t fdt); extern fib_entry_delegate_t *fib_entry_delegate_find(const fib_entry_t *fib_entry, fib_entry_delegate_type_t type); extern fib_forward_chain_type_t fib_entry_delegate_type_to_chain_type( fib_entry_delegate_type_t type); extern fib_entry_delegate_type_t fib_entry_chain_type_to_delegate_type( fib_forward_chain_type_t type); extern u8 *format_fib_entry_delegate(u8 * s, va_list * args); extern fib_node_index_t fib_entry_delegate_get_index (const fib_entry_delegate_t *fed); extern fib_entry_delegate_t * fib_entry_delegate_get (fib_node_index_t fedi); #endif