Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 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 | * @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 Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 28 | #include <vnet/mpls/mpls_types.h> |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 29 | |
| 30 | /** |
| 31 | * replicate main |
| 32 | */ |
| 33 | typedef struct replicate_main_t_ |
| 34 | { |
| 35 | vlib_combined_counter_main_t repm_counters; |
Damjan Marion | c47ed03 | 2017-01-25 14:18:03 +0100 | [diff] [blame] | 36 | |
| 37 | /* per-cpu vector of cloned packets */ |
| 38 | u32 **clones; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 39 | } replicate_main_t; |
| 40 | |
| 41 | extern 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 | /** |
| 50 | * The FIB DPO provieds; |
| 51 | * - load-balancing over the next DPOs in the chain/graph |
| 52 | * - per-route counters |
| 53 | */ |
| 54 | typedef struct replicate_t_ { |
| 55 | /** |
Dave Barach | eb987d3 | 2018-05-03 08:26:39 -0400 | [diff] [blame] | 56 | * required for pool_get_aligned. |
| 57 | * memebers used in the switch path come first! |
| 58 | */ |
| 59 | CLIB_CACHE_LINE_ALIGN_MARK(cacheline0); |
| 60 | |
| 61 | /** |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 62 | * number of buckets in the replicate. |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 63 | */ |
| 64 | u16 rep_n_buckets; |
| 65 | |
| 66 | /** |
| 67 | * The protocol of packets that traverse this REP. |
| 68 | * need in combination with the flow hash config to determine how to hash. |
| 69 | * u8. |
| 70 | */ |
| 71 | dpo_proto_t rep_proto; |
| 72 | |
| 73 | /** |
| 74 | * The number of locks, which is approximately the number of users, |
| 75 | * of this load-balance. |
| 76 | * Load-balance objects of via-entries are heavily shared by recursives, |
| 77 | * so the lock count is a u32. |
| 78 | */ |
| 79 | u32 rep_locks; |
| 80 | |
| 81 | /** |
| 82 | * Vector of buckets containing the next DPOs, sized as repo_num |
| 83 | */ |
| 84 | dpo_id_t *rep_buckets; |
| 85 | |
| 86 | /** |
| 87 | * The rest of the cache line is used for buckets. In the common case |
| 88 | * where there there are less than 4 buckets, then the buckets are |
| 89 | * on the same cachlie and we save ourselves a pointer dereferance in |
| 90 | * the data-path. |
| 91 | */ |
| 92 | dpo_id_t rep_buckets_inline[REP_NUM_INLINE_BUCKETS]; |
| 93 | } replicate_t; |
| 94 | |
| 95 | STATIC_ASSERT(sizeof(replicate_t) <= CLIB_CACHE_LINE_BYTES, |
| 96 | "A replicate object size exceeds one cachline"); |
| 97 | |
| 98 | /** |
| 99 | * Flags controlling load-balance formatting/display |
| 100 | */ |
| 101 | typedef enum replicate_format_flags_t_ { |
| 102 | REPLICATE_FORMAT_NONE, |
| 103 | REPLICATE_FORMAT_DETAIL = (1 << 0), |
| 104 | } replicate_format_flags_t; |
| 105 | |
| 106 | extern index_t replicate_create(u32 num_buckets, |
| 107 | dpo_proto_t rep_proto); |
| 108 | extern void replicate_multipath_update( |
| 109 | const dpo_id_t *dpo, |
| 110 | load_balance_path_t *next_hops); |
| 111 | |
| 112 | extern void replicate_set_bucket(index_t repi, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 113 | u32 bucket, |
| 114 | const dpo_id_t *next); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 115 | |
| 116 | extern u8* format_replicate(u8 * s, va_list * args); |
| 117 | |
| 118 | extern const dpo_id_t *replicate_get_bucket(index_t repi, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 119 | u32 bucket); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 120 | extern int replicate_is_drop(const dpo_id_t *dpo); |
| 121 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 122 | extern u16 replicate_n_buckets(index_t repi); |
| 123 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 124 | /** |
| 125 | * The encapsulation breakages are for fast DP access |
| 126 | */ |
| 127 | extern replicate_t *replicate_pool; |
| 128 | static inline replicate_t* |
| 129 | replicate_get (index_t repi) |
| 130 | { |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 131 | repi &= ~MPLS_IS_REPLICATE; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 132 | return (pool_elt_at_index(replicate_pool, repi)); |
| 133 | } |
| 134 | |
| 135 | #define REP_HAS_INLINE_BUCKETS(_rep) \ |
| 136 | ((_rep)->rep_n_buckets <= REP_NUM_INLINE_BUCKETS) |
| 137 | |
| 138 | static inline const dpo_id_t * |
| 139 | replicate_get_bucket_i (const replicate_t *rep, |
| 140 | u32 bucket) |
| 141 | { |
| 142 | ASSERT(bucket < rep->rep_n_buckets); |
| 143 | |
| 144 | if (PREDICT_TRUE(REP_HAS_INLINE_BUCKETS(rep))) |
| 145 | { |
| 146 | return (&rep->rep_buckets_inline[bucket]); |
| 147 | } |
| 148 | else |
| 149 | { |
| 150 | return (&rep->rep_buckets[bucket]); |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | extern void replicate_module_init(void); |
| 155 | |
| 156 | #endif |