blob: 300f2cfd6bea52ba8ced644e674c7766283b0d6c [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
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 Ranns1357f3b2016-10-16 12:01:42 -070015#ifndef included_vnet_mpls_h
16#define included_vnet_mpls_h
Ed Warnickecb9cada2015-12-08 15:45:58 -070017
18#include <vnet/vnet.h>
Neale Ranns0bfe5d82016-08-25 15:29:12 +010019#include <vnet/mpls/packet.h>
20#include <vnet/mpls/mpls_types.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070021#include <vnet/ip/ip4_packet.h>
22#include <vnet/ethernet/ethernet.h>
Neale Ranns0bfe5d82016-08-25 15:29:12 +010023#include <vnet/fib/fib_node.h>
24#include <vnet/adj/adj.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070025
Ed Warnickecb9cada2015-12-08 15:45:58 -070026typedef enum {
27#define mpls_error(n,s) MPLS_ERROR_##n,
Neale Ranns0bfe5d82016-08-25 15:29:12 +010028#include <vnet/mpls/error.def>
Ed Warnickecb9cada2015-12-08 15:45:58 -070029#undef mpls_error
30 MPLS_N_ERROR,
Neale Ranns1357f3b2016-10-16 12:01:42 -070031} mpls_error_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -070032
Neale Ranns0bfe5d82016-08-25 15:29:12 +010033#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
41typedef struct mpls_fib_t_
42{
43 /**
44 * A hash table of entries. 21 bit key
45 * Hash table for reduced memory footprint
46 */
Dave Barach75fc8542016-10-11 16:16:02 -040047 uword * mf_entries;
Neale Ranns0bfe5d82016-08-25 15:29:12 +010048
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 */
60typedef void (*mpls_interface_state_change_callback_t)(u32 sw_if_index,
61 u32 is_enable);
62
Ed Warnickecb9cada2015-12-08 15:45:58 -070063typedef struct {
Neale Ranns0bfe5d82016-08-25 15:29:12 +010064 /* 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 Marion8b3191e2016-11-09 19:54:20 +010073 /* Feature arc indices */
74 u8 input_feature_arc_index;
75 u8 output_feature_arc_index;
Neale Ranns0bfe5d82016-08-25 15:29:12 +010076
77 /* IP4 enabled count by software interface */
78 u8 * mpls_enabled_by_sw_if_index;
79
Ed Warnickecb9cada2015-12-08 15:45:58 -070080 /* convenience */
81 vlib_main_t * vlib_main;
82 vnet_main_t * vnet_main;
83} mpls_main_t;
84
Neale Ranns0bfe5d82016-08-25 15:29:12 +010085extern mpls_main_t mpls_main;
86
Neale Ranns0bfe5d82016-08-25 15:29:12 +010087extern clib_error_t * mpls_feature_init(vlib_main_t * vm);
Ed Warnickecb9cada2015-12-08 15:45:58 -070088
Neale Ranns0bfe5d82016-08-25 15:29:12 +010089format_function_t format_mpls_eos_bit;
90format_function_t format_mpls_unicast_header_net_byte_order;
91format_function_t format_mpls_unicast_label;
92format_function_t format_mpls_header;
93
Jean-Mickael Guerin8941ec22016-03-04 14:14:21 +010094extern vlib_node_registration_t mpls_input_node;
Neale Ranns0bfe5d82016-08-25 15:29:12 +010095extern vlib_node_registration_t mpls_output_node;
96extern vlib_node_registration_t mpls_midchain_node;
Ed Warnickecb9cada2015-12-08 15:45:58 -070097
Ed Warnickecb9cada2015-12-08 15:45:58 -070098/* Parse mpls protocol as 0xXXXX or protocol name.
99 In either host or network byte order. */
100unformat_function_t unformat_mpls_protocol_host_byte_order;
101unformat_function_t unformat_mpls_protocol_net_byte_order;
102unformat_function_t unformat_mpls_label_net_byte_order;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100103unformat_function_t unformat_mpls_unicast_label;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700104
105/* Parse mpls header. */
106unformat_function_t unformat_mpls_header;
107unformat_function_t unformat_pg_mpls_header;
108
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100109void mpls_sw_interface_enable_disable (mpls_main_t * mm,
110 u32 sw_if_index,
111 u8 is_enable);
112
113u8 mpls_sw_interface_is_enabled (u32 sw_if_index);
114
Ed Warnickecb9cada2015-12-08 15:45:58 -0700115int mpls_fib_reset_labels (u32 fib_id);
116
marek zavodsky2c21a9a2016-06-21 05:35:16 +0200117int
118mpls_dest_cmp(void * a1, void * a2);
119
120int
121mpls_fib_index_cmp(void * a1, void * a2);
122
123int
124mpls_label_cmp(void * a1, void * a2);
125
Neale Ranns1357f3b2016-10-16 12:01:42 -0700126#endif /* included_vnet_mpls_h */