blob: a564739c9f29cd5c8e51085c1567385aa752b531 [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>
28
29/**
30 * replicate main
31 */
32typedef struct replicate_main_t_
33{
34 vlib_combined_counter_main_t repm_counters;
35} replicate_main_t;
36
37extern replicate_main_t replicate_main;
38
39/**
40 * The number of buckets that a load-balance object can have and still
41 * fit in one cache-line
42 */
43#define REP_NUM_INLINE_BUCKETS 4
44
45/**
46 * The FIB DPO provieds;
47 * - load-balancing over the next DPOs in the chain/graph
48 * - per-route counters
49 */
50typedef struct replicate_t_ {
51 /**
52 * number of buckets in the load-balance. always a power of 2.
53 */
54 u16 rep_n_buckets;
55
56 /**
57 * The protocol of packets that traverse this REP.
58 * need in combination with the flow hash config to determine how to hash.
59 * u8.
60 */
61 dpo_proto_t rep_proto;
62
63 /**
64 * The number of locks, which is approximately the number of users,
65 * of this load-balance.
66 * Load-balance objects of via-entries are heavily shared by recursives,
67 * so the lock count is a u32.
68 */
69 u32 rep_locks;
70
71 /**
72 * Vector of buckets containing the next DPOs, sized as repo_num
73 */
74 dpo_id_t *rep_buckets;
75
76 /**
77 * The rest of the cache line is used for buckets. In the common case
78 * where there there are less than 4 buckets, then the buckets are
79 * on the same cachlie and we save ourselves a pointer dereferance in
80 * the data-path.
81 */
82 dpo_id_t rep_buckets_inline[REP_NUM_INLINE_BUCKETS];
83} replicate_t;
84
85STATIC_ASSERT(sizeof(replicate_t) <= CLIB_CACHE_LINE_BYTES,
86 "A replicate object size exceeds one cachline");
87
88/**
89 * Flags controlling load-balance formatting/display
90 */
91typedef enum replicate_format_flags_t_ {
92 REPLICATE_FORMAT_NONE,
93 REPLICATE_FORMAT_DETAIL = (1 << 0),
94} replicate_format_flags_t;
95
96extern index_t replicate_create(u32 num_buckets,
97 dpo_proto_t rep_proto);
98extern void replicate_multipath_update(
99 const dpo_id_t *dpo,
100 load_balance_path_t *next_hops);
101
102extern void replicate_set_bucket(index_t repi,
103 u32 bucket,
104 const dpo_id_t *next);
105
106extern u8* format_replicate(u8 * s, va_list * args);
107
108extern const dpo_id_t *replicate_get_bucket(index_t repi,
109 u32 bucket);
110extern int replicate_is_drop(const dpo_id_t *dpo);
111
112/**
113 * The encapsulation breakages are for fast DP access
114 */
115extern replicate_t *replicate_pool;
116static inline replicate_t*
117replicate_get (index_t repi)
118{
119 return (pool_elt_at_index(replicate_pool, repi));
120}
121
122#define REP_HAS_INLINE_BUCKETS(_rep) \
123 ((_rep)->rep_n_buckets <= REP_NUM_INLINE_BUCKETS)
124
125static inline const dpo_id_t *
126replicate_get_bucket_i (const replicate_t *rep,
127 u32 bucket)
128{
129 ASSERT(bucket < rep->rep_n_buckets);
130
131 if (PREDICT_TRUE(REP_HAS_INLINE_BUCKETS(rep)))
132 {
133 return (&rep->rep_buckets_inline[bucket]);
134 }
135 else
136 {
137 return (&rep->rep_buckets[bucket]);
138 }
139}
140
141extern void replicate_module_init(void);
142
143#endif