blob: 96dab648b324897659bbf9e8b722f46b1e086919 [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/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
59typedef enum {
60#define _(f) SRP_MODE_##f,
61 foreach_srp_mode
62#undef _
63 SRP_N_MODE,
64} srp_mode_t;
65
66typedef union {
67 /* For computing parity bit. */
68 u16 as_u16;
69
70 struct {
71 u8 ttl;
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
88always_inline void
89srp_header_compute_parity (srp_header_t * h)
90{
91 h->parity = 0;
92 h->parity = count_set_bits (h->as_u16) ^ 1; /* odd parity */
93}
94
95typedef struct {
96 srp_header_t srp;
97 ethernet_header_t ethernet;
98} srp_and_ethernet_header_t;
99
100#define foreach_srp_control_packet_type \
101 _ (reserved) \
102 _ (topology) \
103 _ (ips)
104
105typedef enum {
106#define _(f) SRP_CONTROL_PACKET_TYPE_##f,
107 foreach_srp_control_packet_type
108#undef _
109 SRP_N_CONTROL_PACKET_TYPE,
110} srp_control_packet_type_t;
111
112typedef 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
124typedef struct {
125 srp_header_t srp;
126 ethernet_header_t ethernet;
127 srp_control_header_t control;
128} srp_generic_control_header_t;
129
130typedef struct {
131 u8 flags;
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. */
136 u8 address[6];
137} srp_topology_mac_binding_t;
138
139typedef 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
162typedef enum {
163#define _(f,n) SRP_IPS_REQUEST_##f = n,
164 foreach_srp_ips_request_type
165#undef _
166} srp_ips_request_type_t;
167
168#define foreach_srp_ips_status \
169 _ (idle, 0x0) \
170 _ (wrapped, 0x2)
171
172typedef enum {
173#define _(f,n) SRP_IPS_STATUS_##f = n,
174 foreach_srp_ips_status
175#undef _
176} srp_ips_status_t;
177
178typedef struct {
179 srp_header_t srp;
180 ethernet_header_t ethernet;
181 srp_control_header_t control;
182 u8 originator_address[6];
183
184 union {
185 u8 ips_octet;
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
201 u8 reserved;
202} srp_ips_header_t;
203
204#endif /* included_srp_packet_h */