FIB path preference
[vpp.git] / src / vnet / fib / fib_path.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 /**
17  * Given a route of the form;
18  *   q.r.s.t/Y
19  *     via <interface> <next-hop>
20  *
21  * The prefix is: q.r.s.t./Y
22  * the path is: 'via <interface> <next-hop>
23  *
24  * The path is the description of where to send the traffic, and the
25  * the prefix is a description of which traffic to send.
26  * It is the aim of the FIB to resolve the path, i.e. to find the corresponding
27  * adjacency to match the path's description.
28  */
29
30 #ifndef __FIB_PATH_H__
31 #define __FIB_PATH_H__
32
33 #include <vnet/ip/ip.h>
34 #include <vnet/dpo/load_balance.h>
35
36 #include <vnet/fib/fib_types.h>
37 #include <vnet/adj/adj_types.h>
38
39 /**
40  * Enurmeration of path configuration attributes
41  */
42 typedef enum fib_path_cfg_attribute_t_ {
43     /**
44      * Marker. Add new types after this one.
45      */
46     FIB_PATH_CFG_ATTRIBUTE_FIRST = 0,
47     /**
48      * The path is forced to a drop, whatever the next-hop info says.
49      * something somewhere knows better...
50      */
51     FIB_PATH_CFG_ATTRIBUTE_DROP = FIB_PATH_CFG_ATTRIBUTE_FIRST,
52     /**
53      * The path uses an adj that is exclusive. I.e. it is known only by
54      * the source of the route.
55      */
56     FIB_PATH_CFG_ATTRIBUTE_EXCLUSIVE,
57     /**
58      * Recursion constraint via host
59      */
60     FIB_PATH_CFG_ATTRIBUTE_RESOLVE_HOST,
61     /**
62      * Recursion constraint via attached
63      */
64     FIB_PATH_CFG_ATTRIBUTE_RESOLVE_ATTACHED,
65     /**
66      * The path is attached
67      */
68     FIB_PATH_CFG_ATTRIBUTE_ATTACHED,
69     /**
70      * The path is a for-us path
71      */
72     FIB_PATH_CFG_ATTRIBUTE_INTF_RX,
73     /**
74      * The path is a deag with rpf-id
75      */
76     FIB_PATH_CFG_ATTRIBUTE_RPF_ID,
77     /**
78      * The path is an interface recieve
79      */
80     FIB_PATH_CFG_ATTRIBUTE_LOCAL,
81     /**
82      * Marker. Add new types before this one, then update it.
83      */
84     FIB_PATH_CFG_ATTRIBUTE_LAST = FIB_PATH_CFG_ATTRIBUTE_LOCAL,
85 } __attribute__ ((packed)) fib_path_cfg_attribute_t;
86
87 /**
88  * The maximum number of path attributes
89  */
90 #define FIB_PATH_CFG_ATTRIBUTE_MAX (FIB_PATH_CFG_ATTRIBUTE_LAST + 1)
91
92 #define FIB_PATH_CFG_ATTRIBUTES {                       \
93     [FIB_PATH_CFG_ATTRIBUTE_DROP]  = "drop",            \
94     [FIB_PATH_CFG_ATTRIBUTE_EXCLUSIVE] = "exclusive",   \
95     [FIB_PATH_CFG_ATTRIBUTE_RESOLVE_HOST] = "resolve-host", \
96     [FIB_PATH_CFG_ATTRIBUTE_RESOLVE_ATTACHED] = "resolve-attached", \
97     [FIB_PATH_CFG_ATTRIBUTE_LOCAL] = "local",           \
98     [FIB_PATH_CFG_ATTRIBUTE_ATTACHED] = "attached",     \
99     [FIB_PATH_CFG_ATTRIBUTE_INTF_RX] = "interface-rx",  \
100     [FIB_PATH_CFG_ATTRIBUTE_RPF_ID] = "rpf-id",         \
101 }
102
103 #define FOR_EACH_FIB_PATH_CFG_ATTRIBUTE(_item) \
104     for (_item = FIB_PATH_CFG_ATTRIBUTE_FIRST; \
105          _item <= FIB_PATH_CFG_ATTRIBUTE_LAST; \
106          _item++)
107
108 /**
109  * Path config flags from the attributes
110  */
111 typedef enum fib_path_cfg_flags_t_ {
112     FIB_PATH_CFG_FLAG_NONE  = 0,
113     FIB_PATH_CFG_FLAG_DROP  = (1 << FIB_PATH_CFG_ATTRIBUTE_DROP),
114     FIB_PATH_CFG_FLAG_EXCLUSIVE = (1 << FIB_PATH_CFG_ATTRIBUTE_EXCLUSIVE),
115     FIB_PATH_CFG_FLAG_RESOLVE_HOST = (1 << FIB_PATH_CFG_ATTRIBUTE_RESOLVE_HOST),
116     FIB_PATH_CFG_FLAG_RESOLVE_ATTACHED = (1 << FIB_PATH_CFG_ATTRIBUTE_RESOLVE_ATTACHED),
117     FIB_PATH_CFG_FLAG_LOCAL = (1 << FIB_PATH_CFG_ATTRIBUTE_LOCAL),
118     FIB_PATH_CFG_FLAG_ATTACHED = (1 << FIB_PATH_CFG_ATTRIBUTE_ATTACHED),
119     FIB_PATH_CFG_FLAG_INTF_RX = (1 << FIB_PATH_CFG_ATTRIBUTE_INTF_RX),
120     FIB_PATH_CFG_FLAG_RPF_ID = (1 << FIB_PATH_CFG_ATTRIBUTE_RPF_ID),
121 } __attribute__ ((packed)) fib_path_cfg_flags_t;
122
123
124 extern u8 *fib_path_format(fib_node_index_t pi, u8 *s);
125 extern u8 *fib_path_adj_format(fib_node_index_t pi,
126                                u32 indent,
127                                u8 *s);
128
129 extern u8 * format_fib_path(u8 * s, va_list * args);
130
131 extern fib_node_index_t fib_path_create(fib_node_index_t pl_index,
132                                         const fib_route_path_t *path);
133 extern fib_node_index_t fib_path_create_special(fib_node_index_t pl_index,
134                                                 fib_protocol_t nh_proto,
135                                                 fib_path_cfg_flags_t flags,
136                                                 const dpo_id_t *dpo);
137
138 extern int fib_path_cmp(fib_node_index_t path_index1,
139                         fib_node_index_t path_index2);
140 extern int fib_path_cmp_for_sort(void * a1, void * a2);
141 extern int fib_path_cmp_w_route_path(fib_node_index_t path_index,
142                                      const fib_route_path_t *rpath);
143 extern fib_node_index_t fib_path_copy(fib_node_index_t path_index,
144                                       fib_node_index_t path_list_index);
145 extern int fib_path_resolve(fib_node_index_t path_index);
146 extern int fib_path_is_resolved(fib_node_index_t path_index);
147 extern int fib_path_is_recursive_constrained(fib_node_index_t path_index);
148 extern int fib_path_is_exclusive(fib_node_index_t path_index);
149 extern int fib_path_is_deag(fib_node_index_t path_index);
150 extern int fib_path_is_looped(fib_node_index_t path_index);
151 extern fib_protocol_t fib_path_get_proto(fib_node_index_t path_index);
152 extern void fib_path_destroy(fib_node_index_t path_index);
153 extern uword fib_path_hash(fib_node_index_t path_index);
154 extern load_balance_path_t * fib_path_append_nh_for_multipath_hash(
155     fib_node_index_t path_index,
156     fib_forward_chain_type_t fct,
157     load_balance_path_t *hash_key);
158 extern void fib_path_stack_mpls_disp(fib_node_index_t path_index,
159                                      dpo_proto_t payload_proto,
160                                      dpo_id_t *dpo);
161 extern void fib_path_contribute_forwarding(fib_node_index_t path_index,
162                                            fib_forward_chain_type_t type,
163                                            dpo_id_t *dpo);
164 extern void fib_path_contribute_urpf(fib_node_index_t path_index,
165                                      index_t urpf);
166 extern adj_index_t fib_path_get_adj(fib_node_index_t path_index);
167 extern int fib_path_recursive_loop_detect(fib_node_index_t path_index,
168                                           fib_node_index_t **entry_indicies);
169 extern u32 fib_path_get_resolving_interface(fib_node_index_t fib_entry_index);
170 extern u16 fib_path_get_weight(fib_node_index_t path_index);
171 extern u16 fib_path_get_preference(fib_node_index_t path_index);
172
173 extern void fib_path_module_init(void);
174 extern fib_path_list_walk_rc_t fib_path_encode(fib_node_index_t path_list_index,
175                                                fib_node_index_t path_index,
176                                                void *ctx);
177
178 #endif