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