srv6-ad-flow: SRv6 Per-Flow Dynamic Proxy
[vpp.git] / src / plugins / srv6-ad-flow / ad-flow.h
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  */
15 #ifndef __included_srv6_ad_flow_h__
16 #define __included_srv6_ad_flow_h__
17
18 #include <vnet/vnet.h>
19 #include <vnet/ip/ip.h>
20 #include <vnet/srv6/sr.h>
21 #include <vnet/srv6/sr_packet.h>
22
23 #include <vppinfra/error.h>
24 #include <vppinfra/elog.h>
25
26 #include <vppinfra/dlist.h>
27 #include <vppinfra/bihash_40_8.h>
28
29 #define AD_TYPE_IP4 IP_PROTOCOL_IP_IN_IP
30 #define AD_TYPE_IP6 IP_PROTOCOL_IPV6
31
32 #define SRV6_AD_FLOW_DEFAULT_CACHE_SIZE 100
33 #define SRV6_AD_CACHE_TIMEOUT           300
34
35 /*
36  * Cache entries
37  */
38 typedef struct
39 {
40   /* Cache key (5-tuple) */
41   struct
42   {
43     ip46_address_t s_addr;
44     ip46_address_t d_addr;
45     u8 proto;
46     u16 s_port;
47     u16 d_port;
48   } key;
49
50   /* Cached encapsulation headers */
51   u32 rw_len;
52   u8 *rw_data;
53
54   /* Index in global LRU list */
55   u32 lru_index;
56
57   /* Last update timestamp */
58   f64 last_lru_update;
59
60   /* Last heard timestamp */
61   f64 last_heard;
62 } srv6_ad_flow_entry_t;
63
64 /*
65  * This is the memory that will be stored per each localsid
66  * the user instantiates
67  */
68 typedef struct
69 {
70   ip46_address_t nh_addr; /**< Proxied device address */
71   u32 sw_if_index_out;    /**< Outgoing iface to proxied dev. */
72   u32 nh_adj;             /**< Adjacency index for out. iface */
73   u8 inner_type;
74
75   u32 sw_if_index_in; /**< Incoming iface from proxied dev. */
76
77   u32 cache_size;
78   u32 cache_buckets;
79   uword cache_memory_size;
80
81   clib_bihash_40_8_t ftable;   /**< Flow table */
82   srv6_ad_flow_entry_t *cache; /**< Cache table */
83   dlist_elt_t *lru_pool;
84   u32 lru_head_index;
85
86   u32 index;
87 } srv6_ad_flow_localsid_t;
88
89 typedef struct
90 {
91   u16 msg_id_base; /**< API message ID base */
92
93   vlib_main_t *vlib_main; /**< [convenience] vlib main */
94   vnet_main_t *vnet_main; /**< [convenience] vnet main */
95
96   dpo_type_t srv6_ad_flow_dpo_type; /**< DPO type */
97
98   u32 srv6_localsid_behavior_id; /**< SRv6 LocalSID behavior number */
99
100   u32 *sw_iface_localsid2; /**< Retrieve local SID from iface */
101   u32 *sw_iface_localsid4; /**< Retrieve local SID from iface */
102   u32 *sw_iface_localsid6; /**< Retrieve local SID from iface */
103
104   srv6_ad_flow_localsid_t **sids; /**< Pool of AD SID pointers */
105
106   vlib_combined_counter_main_t
107     sid_bypass_counters; /**< Packets/bytes bypassing NF */
108   vlib_combined_counter_main_t sid_punt_counters; /**< Packets/bytes punted */
109   vlib_combined_counter_main_t sid_cache_full_counters;
110
111   vlib_combined_counter_main_t
112     rw_valid_counters; /**< Valid rewrite counters */
113   vlib_combined_counter_main_t
114     rw_invalid_counters; /**< Invalid rewrite counters */
115 } srv6_ad_flow_main_t;
116
117 typedef struct
118 {
119   srv6_ad_flow_localsid_t *ls;
120   f64 now;
121 } srv6_ad_is_idle_entry_ctx_t;
122
123 extern srv6_ad_flow_main_t srv6_ad_flow_main;
124
125 format_function_t format_srv6_ad_flow_localsid;
126 unformat_function_t unformat_srv6_ad_flow_localsid;
127
128 void srv6_ad_flow_dpo_lock (dpo_id_t *dpo);
129 void srv6_ad_flow_dpo_unlock (dpo_id_t *dpo);
130
131 extern vlib_node_registration_t srv6_ad_flow_localsid_node;
132
133 #endif /* __included_srv6_ad_flow_h__ */
134
135 /*
136  * fd.io coding-style-patch-verification: ON
137  *
138  * Local Variables:
139  * eval: (c-set-style "gnu")
140  * End:
141  */