blob: 13eab5360e1e291b03361541378c304f1f907541 [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 * @brief bier_fmask : The BIER fmask
17 *
18 * The BIER fmask contains the bitString that is applied to packets that
19 * egress towards the next-hop. As such the fmask is part of the rewrite
20 * (adj) for that next-hop. It it thus an extension of the next-hop and in
21 * no way associated with the bit-position(s) that are reachable through it.
22 * Fmasks are thus shared by bit-positions that egress throught the same
23 * nh (BFR-NBR).
24 * Deag fmasks are also shread in the event that a router has local
25 * bit-positions. This is necessary to prevent the router recieving two copies
26 * of each packet. Consequently it also means that they share the same
27 * disposition data for the global data.
28 */
29
30#ifndef __BIER_FMASK_H__
31#define __BIER_FMASK_H__
32
33#include <vlib/vlib.h>
34
35#include <vnet/fib/fib_node.h>
36#include <vnet/mpls/packet.h>
37#include <vnet/dpo/dpo.h>
38
39#include <vnet/bier/bier_types.h>
40#include <vnet/bier/bier_fmask_db.h>
41
42/**
43 * A struct that represents the reference counting of the bits
44 */
45typedef struct bier_fmask_bits_t_ {
46 /**
47 * each bit in the mask needs to be reference counted
48 * and set/cleared on the 0->1 and 1->0 transitions.
49 */
50 bier_bit_string_t bfmb_input_reset_string;
51 u32 *bfmb_refs;
52
53 /**
54 * The total number of references to bits set on this mask
55 * in effect a count of the number of children.
56 */
Neale Rannsa2a7db82017-11-10 02:34:04 -080057 u32 bfmb_count;
Neale Rannsd792d9c2017-10-21 10:53:20 -070058} bier_fmask_bits_t;
59
60/**
61 * Flags on fmask
62 */
63typedef enum bier_fmask_attributes_t_
64{
65 BIER_FMASK_ATTR_FIRST,
66 BIER_FMASK_ATTR_FORWARDING = BIER_FMASK_ATTR_FIRST,
67 BIER_FMASK_ATTR_DISP,
68 BIER_FMASK_ATTR_LAST = BIER_FMASK_ATTR_DISP,
69} bier_fmask_attributes_t;
70
71#define BIER_FMASK_ATTR_NAMES { \
72 [BIER_FMASK_ATTR_FORWARDING] = "forwarding", \
73 [BIER_FMASK_ATTR_DISP] = "disposition", \
74}
75
76#define FOR_EACH_BIER_FMASK_ATTR(_item) \
77 for (_item = BIER_FMASK_ATTR_FIRST; \
78 _item <= BIER_FMASK_ATTR_LAST; \
79 _item++)
80
81typedef enum bier_fmask_flags_t_
82{
83 BIER_FMASK_FLAG_FORWARDING = (1 << BIER_FMASK_ATTR_FORWARDING),
84 BIER_FMASK_FLAG_DISP = (1 << BIER_FMASK_ATTR_DISP),
85} bier_fmask_flags_t;
86
87/**
88 * An outgoing BIER mask. aka forwarding bit mask (in the RFCs)
89 *
90 * This mask's function is two-fold
91 * 1 - it is logical-AND with the input packet header to produce the
92 * output packet header
93 * 2 - it is logical NAND with the input packet header to modify the bit-mask
94 * for the next lookup
95 */
96typedef struct bier_fmask_t_ {
97 /**
98 * The BIER fmask is a child of a FIB entry in the FIB graph.
99 */
100 fib_node_t bfm_node;
101
102 /**
103 * operational/state flags on the fmask
104 */
105 bier_fmask_flags_t bfm_flags;
106
107 /**
108 * The bits, and their ref counts, that are set on this mask
109 * This mask changes as BIER entries link to and from this fmask
110 */
111 bier_fmask_bits_t bfm_bits;
112
113 struct
114 {
115 /**
116 * The key to this fmask - used for store/lookup in the DB
117 */
118 bier_fmask_id_t bfm_id;
119
120 /**
121 * The BIER Table this Fmask is used in
122 */
123 index_t bfm_fib_index;
124 };
125
126 union
127 {
128 /**
129 * For forwarding via a next-hop
130 */
131 struct
132 {
133 /**
134 * The parent fib entry
135 */
136 fib_node_index_t bfm_fei;
137 /**
138 * The MPLS label to paint on the header during forwarding
139 */
140 mpls_label_t bfm_label;
141 };
142
143 /**
144 * For disposition
145 */
146 struct
147 {
148 /**
149 * The parent disposition table object
150 */
151 index_t bfm_disp;
152 };
153 };
154
155 /**
156 * the index of this fmask in the parent's child list.
157 */
158 u32 bfm_sibling;
159
160 /**
161 * The index into the adj table for the adj that
162 * this fmask resolves via
163 */
164 dpo_id_t bfm_dpo;
165} bier_fmask_t;
166
167extern void bier_fmask_link(index_t bfmi, bier_bp_t bp);
168extern void bier_fmask_unlink(index_t bfmi, bier_bp_t bp);
169extern void bier_fmask_unlock(index_t bfmi);
170extern void bier_fmask_lock(index_t bfmi);
171
172extern index_t bier_fmask_create_and_lock(const bier_fmask_id_t *fmid,
173 index_t bti,
174 const fib_route_path_t *rpath);
175
176extern u8* format_bier_fmask(u8 *s, va_list *ap);
177
178extern void bier_fmask_contribute_forwarding(index_t bfmi,
179 dpo_id_t *dpo);
180
181extern u32 bier_fmask_child_add (fib_node_index_t fib_entry_index,
182 fib_node_type_t child_type,
183 fib_node_index_t child_index);
184extern void bier_fmask_child_remove (fib_node_index_t fib_entry_index,
185 u32 sibling_index);
186
187/*
188 * provided for fast data-path access
189 */
190bier_fmask_t *bier_fmask_pool;
191
192static inline bier_fmask_t *
193bier_fmask_get (u32 index)
194{
195 return (pool_elt_at_index(bier_fmask_pool, index));
196}
197
198#endif