Reorganize source tree to use single autotools instance
[vpp.git] / src / vnet / fib / fib_path_list.h
1 /*
2  * Copyright (c) 2016 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
16 #ifndef __FIB_PATH_LIST_H__
17 #define __FIB_PATH_LIST_H__
18
19 #include <vlib/vlib.h>
20 #include <vnet/adj/adj.h>
21
22 #include "fib_node.h"
23 #include "fib_path.h"
24
25 /**
26  * Enumeration of path-list flags.
27  */
28 typedef enum fib_path_list_attribute_t_ {
29     /**
30      * Marker. Add new flags after this one.
31      */
32     FIB_PATH_LIST_ATTRIBUTE_FIRST = 0,
33     /**
34      * This path list is shareable. Shareable path-lists
35      * are inserted into the path-list data-base.
36      * All path-list are inherently shareable, the reason we share some and
37      * not others is to limit the size of the path-list database. This DB must
38      * be searched for each route update.
39      */
40     FIB_PATH_LIST_ATTRIBUTE_SHARED = FIB_PATH_LIST_ATTRIBUTE_FIRST,
41     /**
42      * explicit drop path-list. Used when the entry source needs to 
43      * force a drop, despite the fact the path info is present.
44      */
45     FIB_PATH_LIST_ATTRIBUTE_DROP,
46     /**
47      * explicit local path-list.
48      */
49     FIB_PATH_LIST_ATTRIBUTE_LOCAL,
50     /**
51      * exclusive path-list. Exclusive means the path will resolve via the
52      * exclusive (user provided) adj.
53      */
54     FIB_PATH_LIST_ATTRIBUTE_EXCLUSIVE,
55     /**
56      * resolved path-list
57      */
58     FIB_PATH_LIST_ATTRIBUTE_RESOLVED,
59     /**
60      * looped path-list. one path looped implies the whole list is
61      */
62     FIB_PATH_LIST_ATTRIBUTE_LOOPED,
63     /**
64      * Marher. Add new flags before this one, and then update it.
65      */
66     FIB_PATH_LIST_ATTRIBUTE_LAST = FIB_PATH_LIST_ATTRIBUTE_LOOPED,
67 } fib_path_list_attribute_t;
68
69 typedef enum fib_path_list_flags_t_ {
70     FIB_PATH_LIST_FLAG_NONE      = 0,
71     FIB_PATH_LIST_FLAG_SHARED    = (1 << FIB_PATH_LIST_ATTRIBUTE_SHARED),
72     FIB_PATH_LIST_FLAG_DROP      = (1 << FIB_PATH_LIST_ATTRIBUTE_DROP),
73     FIB_PATH_LIST_FLAG_LOCAL     = (1 << FIB_PATH_LIST_ATTRIBUTE_LOCAL),
74     FIB_PATH_LIST_FLAG_EXCLUSIVE = (1 << FIB_PATH_LIST_ATTRIBUTE_EXCLUSIVE),
75     FIB_PATH_LIST_FLAG_RESOLVED  = (1 << FIB_PATH_LIST_ATTRIBUTE_RESOLVED),
76     FIB_PATH_LIST_FLAG_LOOPED    = (1 << FIB_PATH_LIST_ATTRIBUTE_LOOPED),
77 } fib_path_list_flags_t;
78
79 #define FIB_PATH_LIST_ATTRIBUTES {                       \
80     [FIB_PATH_LIST_ATTRIBUTE_SHARED]    = "shared",      \
81     [FIB_PATH_LIST_ATTRIBUTE_RESOLVED]  = "resolved",    \
82     [FIB_PATH_LIST_ATTRIBUTE_DROP]      = "drop",        \
83     [FIB_PATH_LIST_ATTRIBUTE_EXCLUSIVE] = "exclusive",   \
84     [FIB_PATH_LIST_ATTRIBUTE_LOCAL]     = "local",       \
85     [FIB_PATH_LIST_ATTRIBUTE_LOOPED]     = "looped",     \
86 }
87
88 #define FOR_EACH_PATH_LIST_ATTRIBUTE(_item)             \
89     for (_item = FIB_PATH_LIST_ATTRIBUTE_FIRST;         \
90          _item <= FIB_PATH_LIST_ATTRIBUTE_LAST;         \
91          _item++)
92
93 extern fib_node_index_t fib_path_list_create(fib_path_list_flags_t flags,
94                                              const fib_route_path_t *paths);
95 extern fib_node_index_t fib_path_list_create_special(fib_protocol_t nh_proto,
96                                                      fib_path_list_flags_t flags,
97                                                      const dpo_id_t *dpo);
98
99 extern fib_node_index_t fib_path_list_copy_and_path_add(
100     fib_node_index_t pl_index,
101     fib_path_list_flags_t flags,
102     const fib_route_path_t *path);
103 extern fib_node_index_t fib_path_list_copy_and_path_remove(
104     fib_node_index_t pl_index,
105     fib_path_list_flags_t flags,
106     const fib_route_path_t *path);
107 extern void fib_path_list_contribute_forwarding(fib_node_index_t path_list_index,
108                                                 fib_forward_chain_type_t type,
109                                                 dpo_id_t *dpo);
110 extern void fib_path_list_contribute_urpf(fib_node_index_t path_index,
111                                           index_t urpf);
112 extern index_t fib_path_list_get_urpf(fib_node_index_t path_list_index);
113 extern index_t fib_path_list_get_adj(fib_node_index_t path_list_index,
114                                      fib_forward_chain_type_t type);
115
116 extern u32 fib_path_list_child_add(fib_node_index_t pl_index,
117                                    fib_node_type_t type,
118                                    fib_node_index_t child_index);
119 extern void fib_path_list_child_remove(fib_node_index_t pl_index,
120                                        fib_node_index_t sibling_index);
121 extern void fib_path_list_back_walk(fib_node_index_t pl_index,
122                                     fib_node_back_walk_ctx_t *ctx);
123 extern void fib_path_list_lock(fib_node_index_t pl_index);
124 extern void fib_path_list_unlock(fib_node_index_t pl_index);
125 extern int fib_path_list_recursive_loop_detect(fib_node_index_t path_list_index,
126                                                fib_node_index_t **entry_indicies);
127 extern u32 fib_path_list_get_resolving_interface(fib_node_index_t path_list_index);
128 extern int fib_path_list_is_looped(fib_node_index_t path_list_index);
129 extern fib_protocol_t fib_path_list_get_proto(fib_node_index_t path_list_index);
130 extern u8 * fib_path_list_format(fib_node_index_t pl_index,
131                                  u8 * s);
132 extern u8 * fib_path_list_adjs_format(fib_node_index_t pl_index,
133                                       u32 indent,
134                                       u8 * s);
135 extern index_t fib_path_list_lb_map_add_or_lock(fib_node_index_t pl_index,
136                                                 const fib_node_index_t *pis);
137 /**
138  * A callback function type for walking a path-list's paths
139  */
140 typedef int (*fib_path_list_walk_fn_t)(fib_node_index_t pl_index,
141                                        fib_node_index_t path_index,
142                                        void *ctx);
143
144 extern void fib_path_list_walk(fib_node_index_t pl_index,
145                                fib_path_list_walk_fn_t func,
146                                void *ctx);
147
148 extern void fib_path_list_module_init(void);
149
150 extern void fib_path_list_module_init(void);
151
152 /*
153  * functions for testing.
154  */
155 u32 fib_path_list_pool_size(void);
156 u32 fib_path_list_db_size(void);
157
158 #endif