Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 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 | */ |
Neale Ranns | 1357f3b | 2016-10-16 12:01:42 -0700 | [diff] [blame] | 15 | #ifndef included_vnet_mpls_h |
| 16 | #define included_vnet_mpls_h |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 17 | |
| 18 | #include <vnet/vnet.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 19 | #include <vnet/mpls/packet.h> |
| 20 | #include <vnet/mpls/mpls_types.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 21 | #include <vnet/ip/ip4_packet.h> |
| 22 | #include <vnet/ethernet/ethernet.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 23 | #include <vnet/fib/fib_node.h> |
| 24 | #include <vnet/adj/adj.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 25 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 26 | typedef enum { |
| 27 | #define mpls_error(n,s) MPLS_ERROR_##n, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 28 | #include <vnet/mpls/error.def> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 29 | #undef mpls_error |
| 30 | MPLS_N_ERROR, |
Neale Ranns | 1357f3b | 2016-10-16 12:01:42 -0700 | [diff] [blame] | 31 | } mpls_error_t; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 32 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 33 | #define MPLS_FIB_DEFAULT_TABLE_ID 0 |
| 34 | |
| 35 | /** |
| 36 | * Type exposure is to allow the DP fast/inlined access |
| 37 | */ |
| 38 | #define MPLS_FIB_KEY_SIZE 21 |
| 39 | #define MPLS_FIB_DB_SIZE (1 << (MPLS_FIB_KEY_SIZE-1)) |
| 40 | |
| 41 | typedef struct mpls_fib_t_ |
| 42 | { |
| 43 | /** |
| 44 | * A hash table of entries. 21 bit key |
| 45 | * Hash table for reduced memory footprint |
| 46 | */ |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 47 | uword * mf_entries; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 48 | |
| 49 | /** |
| 50 | * The load-balance indeices keyed by 21 bit label+eos bit. |
| 51 | * A flat array for maximum lookup performace. |
| 52 | */ |
| 53 | index_t mf_lbs[MPLS_FIB_DB_SIZE]; |
| 54 | } mpls_fib_t; |
| 55 | |
| 56 | /** |
| 57 | * @brief Definition of a callback for receiving MPLS interface state change |
| 58 | * notifications |
| 59 | */ |
| 60 | typedef void (*mpls_interface_state_change_callback_t)(u32 sw_if_index, |
| 61 | u32 is_enable); |
| 62 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 63 | typedef struct { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 64 | /* MPLS FIB index for each software interface */ |
| 65 | u32 *fib_index_by_sw_if_index; |
| 66 | |
| 67 | /** A pool of all the MPLS FIBs */ |
| 68 | struct fib_table_t_ *fibs; |
| 69 | |
| 70 | /** A hash table to lookup the mpls_fib by table ID */ |
| 71 | uword *fib_index_by_table_id; |
| 72 | |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 73 | /* Feature arc indices */ |
| 74 | u8 input_feature_arc_index; |
| 75 | u8 output_feature_arc_index; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 76 | |
| 77 | /* IP4 enabled count by software interface */ |
| 78 | u8 * mpls_enabled_by_sw_if_index; |
| 79 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 80 | /* convenience */ |
| 81 | vlib_main_t * vlib_main; |
| 82 | vnet_main_t * vnet_main; |
| 83 | } mpls_main_t; |
| 84 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 85 | extern mpls_main_t mpls_main; |
| 86 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 87 | extern clib_error_t * mpls_feature_init(vlib_main_t * vm); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 88 | |
| 89 | format_function_t format_mpls_protocol; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 90 | format_function_t format_mpls_encap_index; |
| 91 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 92 | format_function_t format_mpls_eos_bit; |
| 93 | format_function_t format_mpls_unicast_header_net_byte_order; |
| 94 | format_function_t format_mpls_unicast_label; |
| 95 | format_function_t format_mpls_header; |
| 96 | |
Jean-Mickael Guerin | 8941ec2 | 2016-03-04 14:14:21 +0100 | [diff] [blame] | 97 | extern vlib_node_registration_t mpls_input_node; |
| 98 | extern vlib_node_registration_t mpls_policy_encap_node; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 99 | extern vlib_node_registration_t mpls_output_node; |
| 100 | extern vlib_node_registration_t mpls_midchain_node; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 101 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 102 | /* Parse mpls protocol as 0xXXXX or protocol name. |
| 103 | In either host or network byte order. */ |
| 104 | unformat_function_t unformat_mpls_protocol_host_byte_order; |
| 105 | unformat_function_t unformat_mpls_protocol_net_byte_order; |
| 106 | unformat_function_t unformat_mpls_label_net_byte_order; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 107 | unformat_function_t unformat_mpls_unicast_label; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 108 | |
| 109 | /* Parse mpls header. */ |
| 110 | unformat_function_t unformat_mpls_header; |
| 111 | unformat_function_t unformat_pg_mpls_header; |
| 112 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 113 | void mpls_sw_interface_enable_disable (mpls_main_t * mm, |
| 114 | u32 sw_if_index, |
| 115 | u8 is_enable); |
| 116 | |
| 117 | u8 mpls_sw_interface_is_enabled (u32 sw_if_index); |
| 118 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 119 | int mpls_fib_reset_labels (u32 fib_id); |
| 120 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 121 | #define foreach_mpls_input_next \ |
| 122 | _(DROP, "error-drop") \ |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 123 | _(LOOKUP, "mpls-lookup") |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 124 | |
| 125 | typedef enum { |
| 126 | #define _(s,n) MPLS_INPUT_NEXT_##s, |
| 127 | foreach_mpls_input_next |
| 128 | #undef _ |
| 129 | MPLS_INPUT_N_NEXT, |
| 130 | } mpls_input_next_t; |
| 131 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 132 | #define foreach_mpls_lookup_next \ |
| 133 | _(DROP, "error-drop") \ |
| 134 | _(IP4_INPUT, "ip4-input") \ |
| 135 | _(L2_OUTPUT, "l2-output") |
| 136 | |
| 137 | // FIXME remove. |
| 138 | typedef enum { |
| 139 | #define _(s,n) MPLS_LOOKUP_NEXT_##s, |
| 140 | foreach_mpls_lookup_next |
| 141 | #undef _ |
| 142 | MPLS_LOOKUP_N_NEXT, |
| 143 | } mpls_lookup_next_t; |
| 144 | |
| 145 | #define foreach_mpls_output_next \ |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 146 | _(DROP, "error-drop") |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 147 | |
| 148 | typedef enum { |
| 149 | #define _(s,n) MPLS_OUTPUT_NEXT_##s, |
| 150 | foreach_mpls_output_next |
| 151 | #undef _ |
| 152 | MPLS_OUTPUT_N_NEXT, |
| 153 | } mpls_output_next_t; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 154 | |
| 155 | typedef struct { |
marek zavodsky | 2c21a9a | 2016-06-21 05:35:16 +0200 | [diff] [blame] | 156 | u32 fib_index; |
| 157 | u32 entry_index; |
| 158 | u32 dest; |
| 159 | u32 s_bit; |
| 160 | u32 label; |
| 161 | } show_mpls_fib_t; |
| 162 | |
| 163 | int |
| 164 | mpls_dest_cmp(void * a1, void * a2); |
| 165 | |
| 166 | int |
| 167 | mpls_fib_index_cmp(void * a1, void * a2); |
| 168 | |
| 169 | int |
| 170 | mpls_label_cmp(void * a1, void * a2); |
| 171 | |
Neale Ranns | 1357f3b | 2016-10-16 12:01:42 -0700 | [diff] [blame] | 172 | #endif /* included_vnet_mpls_h */ |