blob: 908c20c1d56ea8996208c29d3d468914413087aa [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 * @brief
17 *
18 */
19
20#ifndef __REPLICATE_DPO_H__
21#define __REPLICATE_DPO_H__
22
23#include <vlib/vlib.h>
24#include <vnet/ip/lookup.h>
25#include <vnet/dpo/dpo.h>
26#include <vnet/dpo/load_balance.h>
27#include <vnet/fib/fib_types.h>
Neale Ranns0f26c5a2017-03-01 15:12:11 -080028#include <vnet/mpls/mpls_types.h>
Neale Ranns32e1c012016-11-22 17:07:28 +000029
30/**
31 * replicate main
32 */
33typedef struct replicate_main_t_
34{
35 vlib_combined_counter_main_t repm_counters;
Damjan Marionc47ed032017-01-25 14:18:03 +010036
37 /* per-cpu vector of cloned packets */
38 u32 **clones;
Neale Ranns32e1c012016-11-22 17:07:28 +000039} replicate_main_t;
40
41extern replicate_main_t replicate_main;
42
43/**
44 * The number of buckets that a load-balance object can have and still
45 * fit in one cache-line
46 */
47#define REP_NUM_INLINE_BUCKETS 4
48
49/**
Neale Ranns9e829a82018-12-17 05:50:32 -080050 * Flags on the replicate DPO
51 */
52typedef enum replicate_flags_t_
53{
54 REPLICATE_FLAGS_NONE,
55 REPLICATE_FLAGS_HAS_LOCAL,
56} __clib_packed replicate_flags_t;
57
58/**
Neale Ranns32e1c012016-11-22 17:07:28 +000059 * The FIB DPO provieds;
60 * - load-balancing over the next DPOs in the chain/graph
61 * - per-route counters
62 */
63typedef struct replicate_t_ {
64 /**
Dave Baracheb987d32018-05-03 08:26:39 -040065 * required for pool_get_aligned.
66 * memebers used in the switch path come first!
67 */
68 CLIB_CACHE_LINE_ALIGN_MARK(cacheline0);
69
70 /**
Neale Ranns2303cb12018-02-21 04:57:17 -080071 * number of buckets in the replicate.
Neale Ranns32e1c012016-11-22 17:07:28 +000072 */
73 u16 rep_n_buckets;
74
75 /**
76 * The protocol of packets that traverse this REP.
77 * need in combination with the flow hash config to determine how to hash.
78 * u8.
79 */
80 dpo_proto_t rep_proto;
81
82 /**
Neale Ranns9e829a82018-12-17 05:50:32 -080083 * Flags specifying the replicate properties/behaviour
84 */
85 replicate_flags_t rep_flags;
86
87 /**
Neale Ranns32e1c012016-11-22 17:07:28 +000088 * The number of locks, which is approximately the number of users,
89 * of this load-balance.
90 * Load-balance objects of via-entries are heavily shared by recursives,
91 * so the lock count is a u32.
92 */
93 u32 rep_locks;
94
95 /**
96 * Vector of buckets containing the next DPOs, sized as repo_num
97 */
98 dpo_id_t *rep_buckets;
99
100 /**
101 * The rest of the cache line is used for buckets. In the common case
102 * where there there are less than 4 buckets, then the buckets are
103 * on the same cachlie and we save ourselves a pointer dereferance in
104 * the data-path.
105 */
106 dpo_id_t rep_buckets_inline[REP_NUM_INLINE_BUCKETS];
107} replicate_t;
108
109STATIC_ASSERT(sizeof(replicate_t) <= CLIB_CACHE_LINE_BYTES,
Lijian.Zhang33af8c12019-09-16 16:22:36 +0800110 "A replicate object size exceeds one cacheline");
Neale Ranns32e1c012016-11-22 17:07:28 +0000111
112/**
113 * Flags controlling load-balance formatting/display
114 */
115typedef enum replicate_format_flags_t_ {
116 REPLICATE_FORMAT_NONE,
117 REPLICATE_FORMAT_DETAIL = (1 << 0),
118} replicate_format_flags_t;
119
120extern index_t replicate_create(u32 num_buckets,
121 dpo_proto_t rep_proto);
122extern void replicate_multipath_update(
123 const dpo_id_t *dpo,
124 load_balance_path_t *next_hops);
125
126extern void replicate_set_bucket(index_t repi,
Neale Ranns2303cb12018-02-21 04:57:17 -0800127 u32 bucket,
128 const dpo_id_t *next);
Neale Ranns32e1c012016-11-22 17:07:28 +0000129
130extern u8* format_replicate(u8 * s, va_list * args);
131
132extern const dpo_id_t *replicate_get_bucket(index_t repi,
Neale Ranns2303cb12018-02-21 04:57:17 -0800133 u32 bucket);
Neale Ranns32e1c012016-11-22 17:07:28 +0000134extern int replicate_is_drop(const dpo_id_t *dpo);
135
Neale Ranns2303cb12018-02-21 04:57:17 -0800136extern u16 replicate_n_buckets(index_t repi);
137
Neale Ranns9e829a82018-12-17 05:50:32 -0800138extern index_t replicate_dup(replicate_flags_t flags,
139 index_t repi);
140
Neale Ranns32e1c012016-11-22 17:07:28 +0000141/**
142 * The encapsulation breakages are for fast DP access
143 */
144extern replicate_t *replicate_pool;
145static inline replicate_t*
146replicate_get (index_t repi)
147{
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800148 repi &= ~MPLS_IS_REPLICATE;
Neale Ranns32e1c012016-11-22 17:07:28 +0000149 return (pool_elt_at_index(replicate_pool, repi));
150}
151
152#define REP_HAS_INLINE_BUCKETS(_rep) \
153 ((_rep)->rep_n_buckets <= REP_NUM_INLINE_BUCKETS)
154
155static inline const dpo_id_t *
156replicate_get_bucket_i (const replicate_t *rep,
157 u32 bucket)
158{
159 ASSERT(bucket < rep->rep_n_buckets);
160
161 if (PREDICT_TRUE(REP_HAS_INLINE_BUCKETS(rep)))
162 {
163 return (&rep->rep_buckets_inline[bucket]);
164 }
165 else
166 {
167 return (&rep->rep_buckets[bucket]);
168 }
169}
170
171extern void replicate_module_init(void);
172
173#endif