nat: deal with flows instead of sessions
[vpp.git] / src / plugins / nat / nat44-ei / nat44_ei_ha.h
1 /*
2  * Copyright (c) 2019 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  * @file
17  * @brief NAT active-passive HA
18  */
19
20 #ifndef __included_nat_ha_h__
21 #define __included_nat_ha_h__
22
23 #include <vnet/vnet.h>
24 #include <vnet/ip/ip.h>
25 #include <nat/nat.h>
26
27 /* Call back functions for received HA events on passive/failover */
28 typedef void (*nat_ha_sadd_cb_t) (ip4_address_t * in_addr, u16 in_port,
29                                   ip4_address_t * out_addr, u16 out_port,
30                                   ip4_address_t * eh_addr, u16 eh_port,
31                                   ip4_address_t * ehn_addr, u16 ehn_port,
32                                   u8 proto, u32 fib_index, u16 flags,
33                                   u32 thread_index);
34
35 typedef void (*nat_ha_sdel_cb_t) (ip4_address_t * out_addr, u16 out_port,
36                                   ip4_address_t * eh_addr, u16 eh_port,
37                                   u8 proto, u32 fib_index, u32 thread_index);
38 typedef void (*nat_ha_sref_cb_t) (ip4_address_t * out_addr, u16 out_port,
39                                   ip4_address_t * eh_addr, u16 eh_port,
40                                   u8 proto, u32 fib_index, u32 total_pkts,
41                                   u64 total_bytes, u32 thread_index);
42
43 /**
44  * @brief Enable NAT HA
45  */
46 void nat_ha_enable ();
47
48 /**
49  * @brief Disable NAT HA
50  */
51 void nat_ha_disable ();
52
53 /**
54  * @brief Initialize NAT HA
55  */
56 void nat_ha_init (vlib_main_t * vm, u32 num_workers, u32 num_threads);
57
58 /**
59  * @brief Set HA listener (local settings)
60  *
61  * @param addr local IP4 address
62  * @param port local UDP port number
63  * @param path_mtu path MTU between local and failover
64  *
65  * @returns 0 on success, non-zero value otherwise.
66  */
67 int nat_ha_set_listener (ip4_address_t * addr, u16 port, u32 path_mtu);
68
69 /**
70  * @brief Get HA listener/local configuration
71  */
72 void nat_ha_get_listener (ip4_address_t * addr, u16 * port, u32 * path_mtu);
73
74 /**
75  * @brief Set HA failover (remote settings)
76  *
77  * @param addr failover IP4 address
78  * @param port failvoer UDP port number
79  * @param session_refresh_interval number of seconds after which to send
80  *                                 session counters refresh
81  *
82  * @returns 0 on success, non-zero value otherwise.
83  */
84 int nat_ha_set_failover (ip4_address_t * addr, u16 port,
85                          u32 session_refresh_interval);
86
87 /**
88  * @brief Get HA failover/remote settings
89  */
90 void nat_ha_get_failover (ip4_address_t * addr, u16 * port,
91                           u32 * session_refresh_interval);
92
93 /**
94  * @brief Create session add HA event
95  *
96  * @param in_addr inside IPv4 address
97  * @param in_port inside L4 port number
98  * @param out_addr outside IPv4 address
99  * @param out_port outside L4 port number
100  * @param eh_addr external host IPv4 address
101  * @param eh_port external host L4 port number
102  * @param ehn_addr external host IPv4 address after translation
103  * @param ehn_port external host L4 port number after translation
104  * @param proto L4 protocol
105  * @param fib_index fib index
106  * @param flags session flags
107  * @param thread_index thread index
108  * @param is_resync 1 if HA resync
109  */
110 void nat_ha_sadd (ip4_address_t * in_addr, u16 in_port,
111                   ip4_address_t * out_addr, u16 out_port,
112                   ip4_address_t * eh_addr, u16 eh_port,
113                   ip4_address_t * ehn_addr, u16 ehn_port, u8 proto,
114                   u32 fib_index, u16 flags, u32 thread_index, u8 is_resync);
115
116 /**
117  * @brief Create session delete HA event
118  *
119  * @param out_addr outside IPv4 address
120  * @param out_port outside L4 port number
121  * @param eh_addr external host IPv4 address
122  * @param eh_port external host L4 port number
123  * @param proto L4 protocol
124  * @param fib_index fib index
125  * @param thread_index thread index
126  */
127 void nat_ha_sdel (ip4_address_t * out_addr, u16 out_port,
128                   ip4_address_t * eh_addr, u16 eh_port, u8 proto,
129                   u32 fib_index, u32 thread_index);
130
131 /**
132  * @brief Create session refresh HA event
133  *
134  * @param out_addr outside IPv4 address
135  * @param out_port outside L4 port number
136  * @param eh_addr external host IPv4 address
137  * @param eh_port external host L4 port number
138  * @param proto L4 protocol
139  * @param fib_index fib index
140  * @param total_pkts total packets processed
141  * @param total_bytes total bytes processed
142  * @param thread_index thread index
143  * @param last_refreshed last session refresh time
144  * @param now current time
145  */
146 void nat_ha_sref (ip4_address_t * out_addr, u16 out_port,
147                   ip4_address_t * eh_addr, u16 eh_port, u8 proto,
148                   u32 fib_index, u32 total_pkts, u64 total_bytes,
149                   u32 thread_index, f64 * last_refreshed, f64 now);
150
151 /**
152  * @brief Flush the current HA data (for testing)
153  */
154 void nat_ha_flush (u8 is_resync);
155
156 typedef void (*nat_ha_resync_event_cb_t) (u32 client_index, u32 pid,
157                                           u32 missed_count);
158
159 /**
160  * @brief Resync HA (resend existing sessions to new failover)
161  */
162 int nat_ha_resync (u32 client_index, u32 pid,
163                    nat_ha_resync_event_cb_t event_callback);
164
165 /**
166  * @brief Get resync status
167  *
168  * @param in_resync 1 if resync in progress
169  * @param resync_ack_missed number of missed (not ACKed) messages
170  */
171 void nat_ha_get_resync_status (u8 * in_resync, u32 * resync_ack_missed);
172
173 #endif /* __included_nat_ha_h__ */
174
175 /*
176  * fd.io coding-style-patch-verification: ON
177  *
178  * Local Variables:
179  * eval: (c-set-style "gnu")
180  * End:
181  */