blob: 2873d5a218464c423f0b01d6822eef9adc5ab842 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
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/*
16 * srp.h: types/functions for srp.
17 *
18 * Copyright (c) 2008 Eliot Dresselhaus
19 *
20 * Permission is hereby granted, free of charge, to any person obtaining
21 * a copy of this software and associated documentation files (the
22 * "Software"), to deal in the Software without restriction, including
23 * without limitation the rights to use, copy, modify, merge, publish,
24 * distribute, sublicense, and/or sell copies of the Software, and to
25 * permit persons to whom the Software is furnished to do so, subject to
26 * the following conditions:
27 *
28 * The above copyright notice and this permission notice shall be
29 * included in all copies or substantial portions of the Software.
30 *
31 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
35 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 */
39
40#ifndef included_srp_h
41#define included_srp_h
42
43#include <vnet/vnet.h>
44#include <vnet/srp/packet.h>
45#include <vnet/ethernet/ethernet.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070046
47extern vnet_hw_interface_class_t srp_hw_interface_class;
48
49/* See RFC 2892. */
50#define foreach_srp_ips_state \
51 _ (idle) \
52 _ (pass_thru) \
53 _ (wrapped)
54
55typedef enum {
56#define _(f) SRP_IPS_STATE_##f,
57 foreach_srp_ips_state
58#undef _
59 SRP_N_IPS_STATE,
60} srp_ips_state_t;
61
62typedef enum {
63 SRP_RING_OUTER,
64 SRP_RING_INNER,
65 SRP_N_RING = 2,
66 SRP_SIDE_A = SRP_RING_OUTER, /* outer rx, inner tx */
67 SRP_SIDE_B = SRP_RING_INNER, /* inner rx, outer tx */
68 SRP_N_SIDE = 2,
69} srp_ring_type_t;
70
71typedef struct {
72 srp_ring_type_t ring;
73
74 /* Hardware interface for this ring/side. */
75 u32 hw_if_index;
76
77 /* Software interface corresponding to hardware interface. */
78 u32 sw_if_index;
79
80 /* Mac address of neighbor on RX fiber. */
81 u8 rx_neighbor_address[6];
82
83 u8 rx_neighbor_address_valid;
84
85 /* True if we are waiting to restore signal. */
86 u8 waiting_to_restore;
87
88 /* Time stamp when signal became valid. */
89 f64 wait_to_restore_start_time;
90} srp_interface_ring_t;
91
92struct srp_interface_t;
93typedef void (srp_hw_wrap_function_t) (u32 hw_if_index, u32 wrap_enable);
94typedef void (srp_hw_enable_function_t) (struct srp_interface_t * si, u32 wrap_enable);
95
96typedef struct {
97 /* Delay between wait to restore event and entering idle state in seconds. */
98 f64 wait_to_restore_idle_delay;
99
100 /* Number of seconds between sending ips messages to neighbors. */
101 f64 ips_tx_interval;
102} srp_interface_config_t;
103
104typedef struct srp_interface_t {
105 /* Current IPS state. */
106 srp_ips_state_t current_ips_state;
107
108 /* Address for this interface. */
109 u8 my_address[6];
110
111 /* Enable IPS process handling for this interface. */
112 u8 ips_process_enable;
113
114 srp_interface_ring_t rings[SRP_N_RING];
115
116 /* Configurable parameters. */
117 srp_interface_config_t config;
118
119 srp_hw_wrap_function_t * hw_wrap_function;
120
121 srp_hw_enable_function_t * hw_enable_function;
122} srp_interface_t;
123
124typedef struct {
125 vlib_main_t * vlib_main;
126
127 /* Pool of SRP interfaces. */
128 srp_interface_t * interface_pool;
129
130 uword * interface_index_by_hw_if_index;
131
132 /* TTL to use for outgoing data packets. */
133 u32 default_data_ttl;
134
135 vlib_one_time_waiting_process_t * srp_register_interface_waiting_process_pool;
136
137 uword * srp_register_interface_waiting_process_pool_index_by_hw_if_index;
138} srp_main_t;
139
140/* Registers sides A/B hardware interface as being SRP capable. */
141void srp_register_interface (u32 * hw_if_indices);
142
143/* Enable sending IPS messages for interface implied by given vlib hardware interface. */
144void srp_interface_enable_ips (u32 hw_if_index);
145
146/* Set function to wrap hardware side of SRP interface. */
147void srp_interface_set_hw_wrap_function (u32 hw_if_index, srp_hw_wrap_function_t * f);
148
149void srp_interface_set_hw_enable_function (u32 hw_if_index, srp_hw_enable_function_t * f);
150
Jean-Mickael Guerin8941ec22016-03-04 14:14:21 +0100151extern vlib_node_registration_t srp_ips_process_node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700152
153/* Called when an IPS control packet is received on given interface. */
154void srp_ips_rx_packet (u32 sw_if_index, srp_ips_header_t * ips_packet);
155
156/* Preform local IPS request on given interface. */
157void srp_ips_local_request (u32 sw_if_index, srp_ips_request_type_t request);
158
159always_inline void
160srp_ips_link_change (u32 sw_if_index, u32 link_is_up)
161{
162 srp_ips_local_request (sw_if_index,
163 link_is_up
164 ? SRP_IPS_REQUEST_wait_to_restore
165 : SRP_IPS_REQUEST_signal_fail);
166}
167
168void srp_interface_get_interface_config (u32 hw_if_index, srp_interface_config_t * c);
169void srp_interface_set_interface_config (u32 hw_if_index, srp_interface_config_t * c);
170
Dave Wallace71612d62017-10-24 01:32:41 -0400171extern srp_main_t srp_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700172
173always_inline srp_interface_t *
174srp_get_interface_from_vnet_hw_interface (u32 hw_if_index)
175{
176 srp_main_t * sm = &srp_main;
177 uword * p = hash_get (sm->interface_index_by_hw_if_index, hw_if_index);
178 return p ? pool_elt_at_index (sm->interface_pool, p[0]) : 0;
179}
180
181u8 * format_srp_header (u8 * s, va_list * args);
182u8 * format_srp_header_with_length (u8 * s, va_list * args);
183u8 * format_srp_device (u8 * s, va_list * args);
184
185/* Parse srp header. */
186uword
187unformat_srp_header (unformat_input_t * input, va_list * args);
188
189uword unformat_pg_srp_header (unformat_input_t * input, va_list * args);
190
Ed Warnickecb9cada2015-12-08 15:45:58 -0700191#define foreach_srp_error \
192 _ (NONE, "no error") \
193 _ (UNKNOWN_MODE, "unknown mode in SRP header") \
194 _ (KEEP_ALIVE_DROPPED, "v1 keep alive mode in SRP header") \
195 _ (CONTROL_PACKETS_PROCESSED, "control packets processed") \
196 _ (IPS_PACKETS_PROCESSED, "IPS packets processed") \
197 _ (UNKNOWN_CONTROL, "unknown control packet") \
198 _ (CONTROL_VERSION_NON_ZERO, "control packet with non-zero version") \
199 _ (CONTROL_BAD_CHECKSUM, "control packet with bad checksum") \
200 _ (TOPOLOGY_BAD_LENGTH, "topology packet with bad length")
201
202typedef enum {
203#define _(n,s) SRP_ERROR_##n,
204 foreach_srp_error
205#undef _
206 SRP_N_ERROR,
207} srp_error_t;
208
209serialize_function_t serialize_srp_main, unserialize_srp_main;
210
211#endif /* included_srp_h */