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