Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [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 | #ifndef __LOAD_BALANCE_MAP_H__ |
| 20 | #define __LOAD_BALANCE_MAP_H__ |
| 21 | |
| 22 | #include <vlib/vlib.h> |
| 23 | #include <vnet/fib/fib_types.h> |
| 24 | #include <vnet/dpo/load_balance.h> |
| 25 | |
| 26 | struct load_balance_map_path_t_; |
| 27 | |
| 28 | /** |
| 29 | */ |
| 30 | typedef struct load_balance_map_t_ { |
| 31 | /** |
| 32 | * The buckets of the map that provide the index to index translation. |
| 33 | * In the first cacheline. |
| 34 | */ |
| 35 | u16 *lbm_buckets; |
| 36 | |
| 37 | /** |
| 38 | * the vector of paths this MAP represents |
| 39 | */ |
| 40 | struct load_balance_map_path_t_ *lbm_paths; |
| 41 | |
| 42 | /** |
| 43 | * the sum of the normalised weights. cache for convenience |
| 44 | */ |
| 45 | u32 lbm_sum_of_norm_weights; |
| 46 | |
| 47 | /** |
| 48 | * Number of locks. Maps are shared by a large number of recrusvie fib_entry_ts |
| 49 | */ |
| 50 | u32 lbm_locks; |
| 51 | } load_balance_map_t; |
| 52 | |
| 53 | extern index_t load_balance_map_add_or_lock(u32 n_buckets, |
| 54 | u32 sum_of_weights, |
| 55 | const load_balance_path_t *norm_paths); |
| 56 | |
| 57 | extern void load_balance_map_lock(index_t lmbi); |
| 58 | extern void load_balance_map_unlock(index_t lbmi); |
| 59 | |
| 60 | extern void load_balance_map_path_state_change(fib_node_index_t path_index); |
| 61 | |
| 62 | extern u8* format_load_balance_map(u8 *s, va_list ap); |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 63 | extern void load_balance_map_show_mem(void); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 64 | |
| 65 | /** |
| 66 | * The encapsulation breakages are for fast DP access |
| 67 | */ |
| 68 | extern load_balance_map_t *load_balance_map_pool; |
| 69 | |
| 70 | static inline load_balance_map_t* |
| 71 | load_balance_map_get (index_t lbmi) |
| 72 | { |
| 73 | return (pool_elt_at_index(load_balance_map_pool, lbmi)); |
| 74 | } |
| 75 | |
| 76 | |
| 77 | extern void load_balance_map_module_init(void); |
| 78 | |
| 79 | #endif |