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