blob: a22e2e335b20a00df4c949c91229b396f5fb09c3 [file] [log] [blame]
Neale Rannsd792d9c2017-10-21 10:53:20 -07001/*
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 __BIER_TABLE_H__
17#define __BIER_TABLE_H__
18
19#include <vlib/vlib.h>
20#include <vnet/fib/fib_types.h>
21#include <vnet/bier/bier_types.h>
22#include <vnet/bier/bier_entry.h>
23
24#include <vnet/dpo/dpo.h>
25
26/**
27 * Forward declarations
28 */
29struct bier_route_update_t_;
30
31/**
32 * A BIER Table is the bit-indexed forwarding table.
33 * Each entry (bit-position) represents one destination, and its reachability
34 *
35 * The number of entries in a table is thus the maximum supported
36 * bit-position. Since this is smal <4096, the table is a flat arry
37 */
38typedef struct bier_table_t_ {
39 /**
40 * Save the MPLS local label associated with the table
41 */
42 mpls_label_t bt_ll;
43
44 /**
45 * The path-list used for the ECMP-tables
46 */
47 fib_node_index_t bt_pl;
48
49 /**
50 * The index of the lfib entry created for this table.
51 * Only the EOS is required.
52 */
53 fib_node_index_t bt_lfei;
54
55 /**
56 * Number of locks on the table
57 */
58 u16 bt_locks;
59
60 /**
61 * Entries in the table
62 * This is a vector sized to the appropriate number of entries
63 * given the table's supported Bit-string length
64 */
65 index_t *bt_entries;
66
67 /**
68 * Everything before this declaration is unused in the switch path
69 */
70 CLIB_CACHE_LINE_ALIGN_MARK(cacheline0);
71
72 /**
73 * The identity/key or the table. we need the hdr_len in the data-path
74 */
75 bier_table_id_t bt_id;
76
77 /**
78 * f-masks in the ECMP table
79 * This is a vector sized to the appropriate number of entries
80 * given the table's supported Bit-string length.
81 * In the ECMP table the LB choice has been pre-resolved, so each entry
82 * links to just one f-mask, i.e. there is a 1:1 mapping of bit-position to
83 * fmask. For efficient forwarding we collapse the fmasks up to the table.
84 */
85 index_t *bt_fmasks;
86} bier_table_t;
87
88STATIC_ASSERT((sizeof(bier_table_t) <= 2*CLIB_CACHE_LINE_BYTES),
89 "BIER table fits on 2 cache lines");
90
91extern index_t bier_table_add_or_lock(const bier_table_id_t *id,
92 mpls_label_t ll);
93extern void bier_table_unlock(const bier_table_id_t *id);
94
95extern void bier_table_route_add(const bier_table_id_t *bti,
96 bier_bp_t bp,
97 fib_route_path_t *brp);
98extern void bier_table_route_remove(const bier_table_id_t *bti,
99 bier_bp_t bp,
100 fib_route_path_t *brp);
101
102extern void bier_table_show_all(vlib_main_t * vm,
103 bier_show_flags_t flags);
104
105extern const bier_table_id_t *bier_table_get_id(index_t bti);
106
107extern u8 *format_bier_table (u8 *s, va_list *args);
108extern u8 *format_bier_table_entry (u8 *s, va_list *args);
109
110extern index_t bier_table_ecmp_create_and_lock(const bier_table_id_t *id);
111extern void bier_table_ecmp_unlock(index_t bti);
112extern void bier_table_ecmp_set_fmask(index_t bti,
113 bier_bp_t bp,
114 index_t bfmi);
115
116extern void bier_table_contribute_forwarding(index_t bti,
117 dpo_id_t *dpo);
118
119/**
120 * Types and functions to walk the ECMP tables of a main table
121 */
122typedef void (*bier_table_ecmp_walk_fn_t)(index_t btei,
123 void *ctx);
124extern void bier_table_ecmp_walk(index_t bti,
125 bier_table_ecmp_walk_fn_t fn,
126 void *ctx);
127extern int bier_table_is_main (const bier_table_t *bt);
128
129/**
130 * Types and functions to walk all the BIER Tables
131 */
132typedef void (*bier_tables_walk_fn_t)(const bier_table_t *bt,
133 void *ctx);
134extern void bier_tables_walk(bier_tables_walk_fn_t fn,
135 void *ctx);
136
137/**
138 * Types and functions to walk all the entries in one BIER Table
139 */
140typedef void (*bier_table_walk_fn_t)(const bier_table_t *bt,
141 const bier_entry_t *be,
142 void *ctx);
143extern void bier_table_walk(const bier_table_id_t *id,
144 bier_table_walk_fn_t fn,
145 void *ctx);
146
147/*
148 * provided for fast data plane access.
149 */
150extern bier_table_t *bier_table_pool;
151
152static inline bier_table_t *
153bier_table_get (index_t bti)
154{
155 return (pool_elt_at_index(bier_table_pool, bti));
156}
157
158static inline const index_t
159bier_table_lookup (const bier_table_t *bt,
160 bier_bp_t bp)
161{
162 return (bt->bt_entries[BIER_BP_TO_INDEX(bp)]);
163}
164
165static inline const index_t
166bier_table_fwd_lookup (const bier_table_t *bt,
167 bier_bp_t bp)
168{
169 return (bt->bt_fmasks[BIER_BP_TO_INDEX(bp)]);
170}
171
172#endif