blob: a1d5acf90666312bc45ce60612a284e903db744f [file] [log] [blame]
Neale Ranns32e1c012016-11-22 17:07:28 +00001/*
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 __MFIB_ENTRY_H__
17#define __MFIB_ENTRY_H__
18
19#include <vnet/fib/fib_node.h>
20#include <vnet/mfib/mfib_types.h>
21#include <vnet/mfib/mfib_itf.h>
22#include <vnet/ip/ip.h>
23#include <vnet/dpo/dpo.h>
24
25/**
26 * An entry in a FIB table.
27 *
28 * This entry represents a route added to the FIB that is stored
29 * in one of the FIB tables.
30 */
31typedef struct mfib_entry_t_ {
32 CLIB_CACHE_LINE_ALIGN_MARK(cacheline0);
33 /**
34 * Base class. The entry's node representation in the graph.
35 */
36 fib_node_t mfe_node;
37 /**
38 * The prefix of the route
39 */
40 mfib_prefix_t mfe_prefix;
41 /**
42 * The index of the FIB table this entry is in
43 */
44 u32 mfe_fib_index;
Neale Ranns32e1c012016-11-22 17:07:28 +000045
46 /**
47 * A vector of sources contributing forwarding
48 */
49 struct mfib_entry_src_t_ *mfe_srcs;
50
51 /**
Neale Rannsc2aad532017-05-30 09:53:52 -070052 * The path-list of which this entry is a child
53 */
54 fib_node_index_t mfe_pl;
55
56 /**
57 * The sibling index on the path-list
58 */
59 u32 mfe_sibling;
60
61 /**
Neale Ranns32e1c012016-11-22 17:07:28 +000062 * 2nd cache line has the members used in the data plane
63 */
64 CLIB_CACHE_LINE_ALIGN_MARK(cacheline1);
65
66 /**
Neale Ranns0f26c5a2017-03-01 15:12:11 -080067 * The DPO used for forwarding; replicate, drop, etc..
Neale Ranns32e1c012016-11-22 17:07:28 +000068 */
69 dpo_id_t mfe_rep;
70
71 /**
72 * Route flags
73 */
74 mfib_entry_flags_t mfe_flags;
75
76 /**
Neale Ranns0f26c5a2017-03-01 15:12:11 -080077 * RPF-ID used when the packets ingress not from an interface
78 */
79 fib_rpf_id_t mfe_rpf_id;
80
81 /**
Neale Ranns32e1c012016-11-22 17:07:28 +000082 * A hash table of interfaces
83 */
84 mfib_itf_t *mfe_itfs;
85} mfib_entry_t;
86
87#define MFIB_ENTRY_FORMAT_BRIEF (0x0)
88#define MFIB_ENTRY_FORMAT_DETAIL (0x1)
89#define MFIB_ENTRY_FORMAT_DETAIL2 (0x2)
90
91extern u8 *format_mfib_entry(u8 * s, va_list * args);
92
93
94extern fib_node_index_t mfib_entry_create(u32 fib_index,
95 mfib_source_t source,
96 const mfib_prefix_t *prefix,
Neale Ranns0f26c5a2017-03-01 15:12:11 -080097 fib_rpf_id_t rpf_id,
Neale Ranns32e1c012016-11-22 17:07:28 +000098 mfib_entry_flags_t entry_flags);
99
100extern int mfib_entry_update(fib_node_index_t fib_entry_index,
101 mfib_source_t source,
Neale Rannsa9374df2017-02-02 02:18:18 -0800102 mfib_entry_flags_t entry_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800103 fib_rpf_id_t rpf_id,
Neale Rannsa9374df2017-02-02 02:18:18 -0800104 index_t rep_dpo);
Neale Ranns32e1c012016-11-22 17:07:28 +0000105
106extern void mfib_entry_path_update(fib_node_index_t fib_entry_index,
107 mfib_source_t source,
108 const fib_route_path_t *rpath,
109 mfib_itf_flags_t itf_flags);
110
111
112extern int mfib_entry_path_remove(fib_node_index_t fib_entry_index,
113 mfib_source_t source,
114 const fib_route_path_t *rpath);
115
116extern int mfib_entry_delete(fib_node_index_t mfib_entry_index,
117 mfib_source_t source);
118
119extern int mfib_entry_cmp_for_sort(void *i1, void *i2);
120
121extern u32 mfib_entry_child_add(fib_node_index_t mfib_entry_index,
122 fib_node_type_t type,
123 fib_node_index_t child_index);
124extern void mfib_entry_child_remove(fib_node_index_t mfib_entry_index,
125 u32 sibling_index);
126
127extern void mfib_entry_lock(fib_node_index_t fib_entry_index);
128extern void mfib_entry_unlock(fib_node_index_t fib_entry_index);
129
130extern void mfib_entry_get_prefix(fib_node_index_t fib_entry_index,
131 mfib_prefix_t *pfx);
132extern u32 mfib_entry_get_fib_index(fib_node_index_t fib_entry_index);
Neale Ranns15002542017-09-10 04:39:11 -0700133extern int mfib_entry_is_sourced(fib_node_index_t fib_entry_index,
134 mfib_source_t source);
Neale Ranns32e1c012016-11-22 17:07:28 +0000135
Neale Rannsff233892017-12-12 00:21:19 -0800136extern const dpo_id_t*mfib_entry_contribute_ip_forwarding(
137 fib_node_index_t mfib_entry_index);
138
Neale Ranns32e1c012016-11-22 17:07:28 +0000139extern void mfib_entry_contribute_forwarding(
140 fib_node_index_t mfib_entry_index,
141 fib_forward_chain_type_t type,
142 dpo_id_t *dpo);
143
Neale Ranns5a8123b2017-01-26 01:18:23 -0800144extern void mfib_entry_encode(fib_node_index_t fib_entry_index,
145 fib_route_path_encode_t **api_rpaths);
146
Neale Ranns32e1c012016-11-22 17:07:28 +0000147extern void mfib_entry_module_init(void);
148
149
150extern mfib_entry_t *mfib_entry_pool;
151
152static inline mfib_entry_t *
153mfib_entry_get (fib_node_index_t index)
154{
155 return (pool_elt_at_index(mfib_entry_pool, index));
156}
157static inline fib_node_index_t
158mfib_entry_get_index (const mfib_entry_t *mfe)
159{
160 return (mfe - mfib_entry_pool);
161}
162
163
164static inline mfib_itf_t *
165mfib_entry_itf_find (mfib_itf_t *itfs,
166 u32 sw_if_index)
167{
168 uword *p;
169
170 p = hash_get(itfs, sw_if_index);
171
172 if (NULL != p)
173 {
174 return (mfib_itf_get(p[0]));
175 }
176
177 return (NULL);
178}
179
180static inline mfib_itf_t *
181mfib_entry_get_itf (const mfib_entry_t *mfe,
182 u32 sw_if_index)
183{
184 return (mfib_entry_itf_find(mfe->mfe_itfs, sw_if_index));
185}
186
187#endif