FD.io VPP  v18.10-32-g1161dda
Vector Packet Processing
packet.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/packet.h: srp packet format.
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_packet_h
41 #define included_srp_packet_h
42 
43 #include <vppinfra/byte_order.h>
44 #include <vppinfra/bitops.h>
45 #include <vnet/ethernet/packet.h>
46 
47 /* SRP version 2. */
48 
49 #define foreach_srp_mode \
50  _ (reserved0) \
51  _ (reserved1) \
52  _ (reserved2) \
53  _ (reserved3) \
54  _ (control_pass_to_host) \
55  _ (control_locally_buffered_for_host) \
56  _ (keep_alive) \
57  _ (data)
58 
59 typedef enum {
60 #define _(f) SRP_MODE_##f,
62 #undef _
64 } srp_mode_t;
65 
66 typedef union {
67  /* For computing parity bit. */
69 
70  struct {
72 
73 #if CLIB_ARCH_IS_BIG_ENDIAN
74  u8 is_inner_ring : 1;
75  u8 mode : 3;
76  u8 priority : 3;
77  u8 parity : 1;
78 #endif
79 #if CLIB_ARCH_IS_LITTLE_ENDIAN
80  u8 parity : 1;
81  u8 priority : 3;
82  u8 mode : 3;
83  u8 is_inner_ring : 1;
84 #endif
85  };
86 } srp_header_t;
87 
88 always_inline void
90 {
91  h->parity = 0;
92  h->parity = count_set_bits (h->as_u16) ^ 1; /* odd parity */
93 }
94 
95 typedef struct {
99 
100 #define foreach_srp_control_packet_type \
101  _ (reserved) \
102  _ (topology) \
103  _ (ips)
104 
105 typedef enum {
106 #define _(f) SRP_CONTROL_PACKET_TYPE_##f,
108 #undef _
111 
112 typedef CLIB_PACKED (struct {
113  /* Set to 0. */
114  u8 version;
115 
116  srp_control_packet_type_t type : 8;
117 
118  /* IP4-like checksum of packet starting with start of control header. */
119  u16 checksum;
120 
121  u16 ttl;
122 }) srp_control_header_t;
123 
124 typedef struct {
127  srp_control_header_t control;
129 
130 typedef struct {
132 #define SRP_TOPOLOGY_MAC_BINDING_FLAG_IS_INNER_RING (1 << 6)
133 #define SRP_TOPOLOGY_MAC_BINDING_FLAG_IS_WRAPPED (1 << 5)
134 
135  /* MAC address. */
138 
139 typedef CLIB_PACKED (struct {
140  srp_header_t srp;
141  ethernet_header_t ethernet;
142  srp_control_header_t control;
143 
144  /* Length in bytes of data that follows. */
145  u16 n_bytes_of_data_that_follows;
146 
147  /* MAC address of originator of this topology request. */
148  u8 originator_address[6];
149 
150  /* Bindings follow. */
151  srp_topology_mac_binding_t bindings[0];
152 }) srp_topology_header_t;
153 
154 #define foreach_srp_ips_request_type \
155  _ (idle, 0x0) \
156  _ (wait_to_restore, 0x5) \
157  _ (manual_switch, 0x6) \
158  _ (signal_degrade, 0x8) \
159  _ (signal_fail, 0xb) \
160  _ (forced_switch, 0xd)
161 
162 typedef enum {
163 #define _(f,n) SRP_IPS_REQUEST_##f = n,
165 #undef _
167 
168 #define foreach_srp_ips_status \
169  _ (idle, 0x0) \
170  _ (wrapped, 0x2)
171 
172 typedef enum {
173 #define _(f,n) SRP_IPS_STATUS_##f = n,
175 #undef _
177 
178 typedef struct {
181  srp_control_header_t control;
182  u8 originator_address[6];
183 
184  union {
186 
187  struct {
188 #if CLIB_ARCH_IS_BIG_ENDIAN
189  u8 request_type : 4;
190  u8 is_long_path : 1;
191  u8 status : 3;
192 #endif
193 #if CLIB_ARCH_IS_LITTLE_ENDIAN
194  u8 status : 3;
195  u8 is_long_path : 1;
196  u8 request_type : 4;
197 #endif
198  };
199  };
200 
203 
204 #endif /* included_srp_packet_h */
typedef address
Definition: ip_types.api:35
srp_ips_status_t
Definition: packet.h:172
srp_control_header_t control
Definition: packet.h:127
srp_mode_t
Definition: packet.h:59
static void srp_header_compute_parity(srp_header_t *h)
Definition: packet.h:89
#define foreach_srp_mode
Definition: packet.h:49
unsigned char u8
Definition: types.h:56
ethernet_header_t ethernet
Definition: packet.h:97
#define foreach_srp_ips_status
Definition: packet.h:168
ethernet_header_t ethernet
Definition: packet.h:180
#define always_inline
Definition: clib.h:94
srp_control_packet_type_t
Definition: packet.h:105
srp_header_t srp
Definition: packet.h:96
srp_header_t srp
Definition: packet.h:179
srp_ips_request_type_t
Definition: packet.h:162
unsigned short u16
Definition: types.h:57
typedef CLIB_PACKED(struct{u8 b_dst_address[6];u8 b_src_address[6];u16 b_type;u16 priority_dei_id;u16 i_type;u32 priority_dei_uca_res_sid;}) ethernet_pbb_header_packed_t
#define foreach_srp_ips_request_type
Definition: packet.h:154
ethernet_header_t ethernet
Definition: packet.h:126
option version
Definition: memclnt.api:17
srp_control_header_t control
Definition: packet.h:181
u16 as_u16
Definition: packet.h:68
static uword count_set_bits(uword x)
Definition: bitops.h:45
#define foreach_srp_control_packet_type
Definition: packet.h:100