blob: 21aecadc28012f30d7b45b284e5c390964524a9e [file] [log] [blame]
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001/*
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#ifndef __LOOKUP_DPO_H__
17#define __LOOKUP_DPO_H__
18
19#include <vnet/vnet.h>
20#include <vnet/fib/fib_types.h>
21#include <vnet/dpo/dpo.h>
22
23/**
24 * Switch to use the packet's source or destination address for lookup
25 */
26typedef enum lookup_input_t_ {
27 LOOKUP_INPUT_SRC_ADDR,
28 LOOKUP_INPUT_DST_ADDR,
29} __attribute__ ((packed)) lookup_input_t;
30
31#define LOOKUP_INPUTS { \
32 [LOOKUP_INPUT_SRC_ADDR] = "src-address", \
33 [LOOKUP_INPUT_DST_ADDR] = "dst-address", \
34}
35
36/**
37 * Switch to use the packet's source or destination address for lookup
38 */
39typedef enum lookup_table_t_ {
40 LOOKUP_TABLE_FROM_INPUT_INTERFACE,
41 LOOKUP_TABLE_FROM_CONFIG,
42} __attribute__ ((packed)) lookup_table_t;
43
44#define LOOKUP_TABLES { \
Neale Ranns054c03a2017-10-13 05:15:07 -070045 [LOOKUP_TABLE_FROM_INPUT_INTERFACE] = "table-input-interface", \
46 [LOOKUP_TABLE_FROM_CONFIG] = "table-configured", \
Neale Ranns0bfe5d82016-08-25 15:29:12 +010047}
48
49/**
Neale Ranns0f26c5a2017-03-01 15:12:11 -080050 * Switch to use the packet's source or destination address for lookup
51 */
52typedef enum lookup_cast_t_ {
53 LOOKUP_UNICAST,
54 LOOKUP_MULTICAST,
55} __attribute__ ((packed)) lookup_cast_t;
56
57#define LOOKUP_CASTS { \
58 [LOOKUP_UNICAST] = "unicast", \
59 [LOOKUP_MULTICAST] = "multicast", \
60}
61
62/**
Neale Ranns0bfe5d82016-08-25 15:29:12 +010063 * A representation of an MPLS label for imposition in the data-path
64 */
65typedef struct lookup_dpo_t
66{
67 /**
Dave Baracheb987d32018-05-03 08:26:39 -040068 * required for pool_get_aligned.
69 * memebers used in the switch path come first!
70 */
71 CLIB_CACHE_LINE_ALIGN_MARK(cacheline0);
72
73 /**
Neale Ranns0bfe5d82016-08-25 15:29:12 +010074 * The FIB, or interface from which to get a FIB, in which to perform
75 * the next lookup;
76 */
77 fib_node_index_t lkd_fib_index;
78
79 /**
80 * The protocol of the FIB for the lookup, and hence
81 * the protocol of the packet
82 */
83 dpo_proto_t lkd_proto;
84
85 /**
86 * Switch to use src or dst address
87 */
88 lookup_input_t lkd_input;
89
90 /**
91 * Switch to use the table index passed, or the table of the input interface
92 */
93 lookup_table_t lkd_table;
94
95 /**
Neale Ranns0f26c5a2017-03-01 15:12:11 -080096 * Unicast of rmulticast FIB lookup
97 */
98 lookup_cast_t lkd_cast;
99
100 /**
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100101 * Number of locks
102 */
103 u16 lkd_locks;
104} lookup_dpo_t;
105
106extern void lookup_dpo_add_or_lock_w_fib_index(fib_node_index_t fib_index,
107 dpo_proto_t proto,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800108 lookup_cast_t cast,
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100109 lookup_input_t input,
110 lookup_table_t table,
111 dpo_id_t *dpo);
112extern void lookup_dpo_add_or_lock_w_table_id(u32 table_id,
113 dpo_proto_t proto,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800114 lookup_cast_t cast,
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100115 lookup_input_t input,
116 lookup_table_t table,
117 dpo_id_t *dpo);
118
119extern u8* format_lookup_dpo(u8 *s, va_list *args);
120
121/*
122 * Encapsulation violation for fast data-path access
123 */
124extern lookup_dpo_t *lookup_dpo_pool;
125
126static inline lookup_dpo_t *
127lookup_dpo_get (index_t index)
128{
129 return (pool_elt_at_index(lookup_dpo_pool, index));
130}
131
132extern void lookup_dpo_module_init(void);
133
134#endif