FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
srp.h
Go to the documentation of this file.
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 /*
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>
46 #include <vnet/pg/pg.h>
47 
49 
50 /* See RFC 2892. */
51 #define foreach_srp_ips_state \
52  _ (idle) \
53  _ (pass_thru) \
54  _ (wrapped)
55 
56 typedef enum {
57 #define _(f) SRP_IPS_STATE_##f,
59 #undef _
62 
63 typedef enum {
67  SRP_SIDE_A = SRP_RING_OUTER, /* outer rx, inner tx */
68  SRP_SIDE_B = SRP_RING_INNER, /* inner rx, outer tx */
71 
72 typedef struct {
74 
75  /* Hardware interface for this ring/side. */
77 
78  /* Software interface corresponding to hardware interface. */
80 
81  /* Mac address of neighbor on RX fiber. */
82  u8 rx_neighbor_address[6];
83 
85 
86  /* True if we are waiting to restore signal. */
88 
89  /* Time stamp when signal became valid. */
92 
93 struct srp_interface_t;
94 typedef void (srp_hw_wrap_function_t) (u32 hw_if_index, u32 wrap_enable);
95 typedef void (srp_hw_enable_function_t) (struct srp_interface_t * si, u32 wrap_enable);
96 
97 typedef struct {
98  /* Delay between wait to restore event and entering idle state in seconds. */
100 
101  /* Number of seconds between sending ips messages to neighbors. */
104 
105 typedef struct srp_interface_t {
106  /* Current IPS state. */
108 
109  /* Address for this interface. */
111 
112  /* Enable IPS process handling for this interface. */
114 
116 
117  /* Configurable parameters. */
119 
121 
124 
125 typedef struct {
127 
128  /* Pool of SRP interfaces. */
130 
132 
133  /* TTL to use for outgoing data packets. */
135 
137 
139 } srp_main_t;
140 
141 /* Registers sides A/B hardware interface as being SRP capable. */
142 void srp_register_interface (u32 * hw_if_indices);
143 
144 /* Enable sending IPS messages for interface implied by given vlib hardware interface. */
145 void srp_interface_enable_ips (u32 hw_if_index);
146 
147 /* Set function to wrap hardware side of SRP interface. */
149 
151 
153 
154 /* Called when an IPS control packet is received on given interface. */
156 
157 /* Preform local IPS request on given interface. */
159 
160 always_inline void
162 {
164  link_is_up
165  ? SRP_IPS_REQUEST_wait_to_restore
166  : SRP_IPS_REQUEST_signal_fail);
167 }
168 
171 
172 extern srp_main_t srp_main;
173 
176 {
177  srp_main_t * sm = &srp_main;
178  uword * p = hash_get (sm->interface_index_by_hw_if_index, hw_if_index);
179  return p ? pool_elt_at_index (sm->interface_pool, p[0]) : 0;
180 }
181 
182 u8 * format_srp_header (u8 * s, va_list * args);
183 u8 * format_srp_header_with_length (u8 * s, va_list * args);
184 u8 * format_srp_device (u8 * s, va_list * args);
185 
186 /* Parse srp header. */
187 uword
188 unformat_srp_header (unformat_input_t * input, va_list * args);
189 
190 uword unformat_pg_srp_header (unformat_input_t * input, va_list * args);
191 
192 always_inline void
194 {
200 }
201 
202 #define foreach_srp_error \
203  _ (NONE, "no error") \
204  _ (UNKNOWN_MODE, "unknown mode in SRP header") \
205  _ (KEEP_ALIVE_DROPPED, "v1 keep alive mode in SRP header") \
206  _ (CONTROL_PACKETS_PROCESSED, "control packets processed") \
207  _ (IPS_PACKETS_PROCESSED, "IPS packets processed") \
208  _ (UNKNOWN_CONTROL, "unknown control packet") \
209  _ (CONTROL_VERSION_NON_ZERO, "control packet with non-zero version") \
210  _ (CONTROL_BAD_CHECKSUM, "control packet with bad checksum") \
211  _ (TOPOLOGY_BAD_LENGTH, "topology packet with bad length")
212 
213 typedef enum {
214 #define _(n,s) SRP_ERROR_##n,
216 #undef _
218 } srp_error_t;
219 
221 
222 #endif /* included_srp_h */
srp_interface_t::rings
srp_interface_ring_t rings[SRP_N_RING]
Definition: srp.h:115
srp_interface_set_hw_enable_function
void srp_interface_set_hw_enable_function(u32 hw_if_index, srp_hw_enable_function_t *f)
Definition: interface.c:162
srp_ring_type_t
srp_ring_type_t
Definition: srp.h:63
foreach_srp_ips_state
#define foreach_srp_ips_state
Definition: srp.h:51
srp_main_t
Definition: srp.h:125
format_srp_header
u8 * format_srp_header(u8 *s, va_list *args)
Definition: format.c:104
srp_main_t::vlib_main
vlib_main_t * vlib_main
Definition: srp.h:126
pg.h
f
vlib_frame_t * f
Definition: interface_output.c:1080
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:553
srp_main_t::interface_index_by_hw_if_index
uword * interface_index_by_hw_if_index
Definition: srp.h:131
srp_ips_rx_packet
void srp_ips_rx_packet(u32 sw_if_index, srp_ips_header_t *ips_packet)
Definition: node.c:667
serialize_function_t
void() serialize_function_t(serialize_main_t *m, va_list *va)
Definition: serialize.h:168
srp_interface_ring_t::sw_if_index
u32 sw_if_index
Definition: srp.h:79
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
node_index
node node_index
Definition: interface_output.c:420
srp_ips_header_t
Definition: packet.h:178
srp_interface_t
struct srp_interface_t srp_interface_t
SRP_RING_OUTER
@ SRP_RING_OUTER
Definition: srp.h:64
unformat_pg_srp_header
uword unformat_pg_srp_header(unformat_input_t *input, va_list *args)
Definition: pg.c:78
unformat_input_t
struct _unformat_input_t unformat_input_t
srp_main_t::default_data_ttl
u32 default_data_ttl
Definition: srp.h:134
srp_interface_t::hw_wrap_function
srp_hw_wrap_function_t * hw_wrap_function
Definition: srp.h:120
vlib_node_t::unformat_buffer
unformat_function_t * unformat_buffer
Definition: node.h:349
unformat_srp_header
uword unformat_srp_header(unformat_input_t *input, va_list *args)
Definition: format.c:111
srp_interface_t::current_ips_state
srp_ips_state_t current_ips_state
Definition: srp.h:107
srp_main_t::interface_pool
srp_interface_t * interface_pool
Definition: srp.h:129
srp_interface_ring_t::hw_if_index
u32 hw_if_index
Definition: srp.h:76
srp_get_interface_from_vnet_hw_interface
static srp_interface_t * srp_get_interface_from_vnet_hw_interface(u32 hw_if_index)
Definition: srp.h:175
ethernet.h
srp_interface_t::config
srp_interface_config_t config
Definition: srp.h:118
pg_node_t
Definition: pg.h:324
packet.h
srp_main_t::srp_register_interface_waiting_process_pool
vlib_one_time_waiting_process_t * srp_register_interface_waiting_process_pool
Definition: srp.h:136
srp_interface_t::hw_enable_function
srp_hw_enable_function_t * hw_enable_function
Definition: srp.h:122
srp_interface_ring_t::rx_neighbor_address_valid
u8 rx_neighbor_address_valid
Definition: srp.h:84
vlib_node_t::format_buffer
format_function_t * format_buffer
Definition: node.h:348
SRP_N_ERROR
@ SRP_N_ERROR
Definition: srp.h:217
srp_hw_enable_function_t
void() srp_hw_enable_function_t(struct srp_interface_t *si, u32 wrap_enable)
Definition: srp.h:95
srp_interface_ring_t::wait_to_restore_start_time
f64 wait_to_restore_start_time
Definition: srp.h:90
SRP_N_RING
@ SRP_N_RING
Definition: srp.h:66
srp_interface_config_t::wait_to_restore_idle_delay
f64 wait_to_restore_idle_delay
Definition: srp.h:99
pg_node_t::unformat_edit
unformat_function_t * unformat_edit
Definition: pg.h:327
srp_interface_set_hw_wrap_function
void srp_interface_set_hw_wrap_function(u32 hw_if_index, srp_hw_wrap_function_t *f)
Definition: interface.c:156
srp_register_interface
void srp_register_interface(u32 *hw_if_indices)
Definition: interface.c:151
c
svmdb_client_t * c
Definition: vpp_get_metrics.c:48
srp_error_t
srp_error_t
Definition: srp.h:213
srp_interface_config_t
Definition: srp.h:97
uword
u64 uword
Definition: types.h:112
pg_get_node
static pg_node_t * pg_get_node(uword node_index)
Definition: pg.h:381
hash_get
#define hash_get(h, key)
Definition: hash.h:249
srp_hw_interface_class
vnet_hw_interface_class_t srp_hw_interface_class
serialize_srp_main
serialize_function_t serialize_srp_main
Definition: srp.h:220
unserialize_srp_main
serialize_function_t unserialize_srp_main
Definition: srp.h:220
vlib_get_node
static vlib_node_t * vlib_get_node(vlib_main_t *vm, u32 i)
Get vlib node by index.
Definition: node_funcs.h:86
f64
double f64
Definition: types.h:142
foreach_srp_error
#define foreach_srp_error
Definition: srp.h:202
srp_ips_state_t
srp_ips_state_t
Definition: srp.h:56
srp_ips_local_request
void srp_ips_local_request(u32 sw_if_index, srp_ips_request_type_t request)
Definition: node.c:750
srp_interface_enable_ips
void srp_interface_enable_ips(u32 hw_if_index)
Definition: interface.c:168
srp_interface_t::my_address
u8 my_address[6]
Definition: srp.h:110
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
SRP_N_SIDE
@ SRP_N_SIDE
Definition: srp.h:69
srp_interface_config_t::ips_tx_interval
f64 ips_tx_interval
Definition: srp.h:102
srp_interface_t
Definition: srp.h:105
request
vhost_user_req_t request
Definition: vhost_user.h:123
always_inline
#define always_inline
Definition: rdma_mlx5dv.h:23
srp_interface_ring_t::ring
srp_ring_type_t ring
Definition: srp.h:73
srp_ips_request_type_t
srp_ips_request_type_t
Definition: packet.h:162
srp_ips_link_change
static void srp_ips_link_change(u32 sw_if_index, u32 link_is_up)
Definition: srp.h:161
u32
unsigned int u32
Definition: types.h:88
srp_interface_ring_t
Definition: srp.h:72
srp_hw_wrap_function_t
void() srp_hw_wrap_function_t(u32 hw_if_index, u32 wrap_enable)
Definition: srp.h:94
SRP_N_IPS_STATE
@ SRP_N_IPS_STATE
Definition: srp.h:60
si
vnet_sw_interface_t * si
Definition: interface_output.c:398
srp_interface_t::ips_process_enable
u8 ips_process_enable
Definition: srp.h:113
srp_interface_get_interface_config
void srp_interface_get_interface_config(u32 hw_if_index, srp_interface_config_t *c)
Definition: interface.c:252
srp_setup_node
static void srp_setup_node(vlib_main_t *vm, u32 node_index)
Definition: srp.h:193
srp_ips_process_node
vlib_node_registration_t srp_ips_process_node
Definition: node.c:857
srp_main_t::srp_register_interface_waiting_process_pool_index_by_hw_if_index
uword * srp_register_interface_waiting_process_pool_index_by_hw_if_index
Definition: srp.h:138
vlib_main_t
Definition: main.h:102
vlib_node_t
Definition: node.h:247
u8
unsigned char u8
Definition: types.h:56
SRP_RING_INNER
@ SRP_RING_INNER
Definition: srp.h:65
vlib_one_time_waiting_process_t
Definition: node.h:602
format_srp_device
u8 * format_srp_device(u8 *s, va_list *args)
Definition: node.c:553
SRP_SIDE_B
@ SRP_SIDE_B
Definition: srp.h:68
srp_interface_ring_t::waiting_to_restore
u8 waiting_to_restore
Definition: srp.h:87
vnet.h
srp_interface_set_interface_config
void srp_interface_set_interface_config(u32 hw_if_index, srp_interface_config_t *c)
Definition: interface.c:259
SRP_SIDE_A
@ SRP_SIDE_A
Definition: srp.h:67
srp_main
srp_main_t srp_main
Definition: node.c:44
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
vnet_hw_interface_class_t
struct _vnet_hw_interface_class vnet_hw_interface_class_t
format_srp_header_with_length
u8 * format_srp_header_with_length(u8 *s, va_list *args)
Definition: format.c:63