blob: b524f6f1bf2d8d4b1a178b39ee8d16af9a436c5c [file] [log] [blame]
Carmelo Cascone79a3a312018-08-16 17:14:43 -07001/*
2 * Copyright 2017-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/* -*- P4_16 -*- */
18#ifndef __INT_TRANSIT__
19#define __INT_TRANSIT__
20control process_int_transit (
21 inout parsed_headers_t hdr,
22 inout fabric_metadata_t fmeta,
23 inout standard_metadata_t smeta) {
24
25 action init_metadata(bit<32> switch_id) {
26 fmeta.int_meta.transit = _TRUE;
27#ifdef _INT_INIT_METADATA
28 // Allow other targets to initialize INT metadata in their own way.
29 _INT_INIT_METADATA
30#else
31 fmeta.int_meta.switch_id = switch_id;
32#endif // _INT_INIT_METADATA
33 }
34
35#ifdef _INT_METADATA_ACTIONS
36 _INT_METADATA_ACTIONS
37#else
38 // Switch ID.
Carmelo Casconeb5324e72018-11-25 02:26:32 -080039 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -070040 action int_set_header_0() {
41 hdr.int_switch_id.setValid();
42 hdr.int_switch_id.switch_id = fmeta.int_meta.switch_id;
43 }
44 // Port IDs.
Carmelo Casconeb5324e72018-11-25 02:26:32 -080045 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -070046 action int_set_header_1() {
47 hdr.int_port_ids.setValid();
48 hdr.int_port_ids.ingress_port_id = (bit<16>) smeta.ingress_port;
49 hdr.int_port_ids.egress_port_id = (bit<16>) smeta.egress_port;
50 }
51 // Hop latency.
Carmelo Casconeb5324e72018-11-25 02:26:32 -080052 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -070053 action int_set_header_2() {
54 hdr.int_hop_latency.setValid();
55 hdr.int_hop_latency.hop_latency = (bit<32>) smeta.deq_timedelta;
56 }
57 // Queue occupancy.
Carmelo Casconeb5324e72018-11-25 02:26:32 -080058 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -070059 action int_set_header_3() {
60 hdr.int_q_occupancy.setValid();
61 // TODO: support queues in BMv2. ATM we assume only one.
62 hdr.int_q_occupancy.q_id = 8w0;
63 hdr.int_q_occupancy.q_occupancy = (bit<24>) smeta.deq_qdepth;
64 }
65 // Ingress timestamp.
Carmelo Casconeb5324e72018-11-25 02:26:32 -080066 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -070067 action int_set_header_4() {
68 hdr.int_ingress_tstamp.setValid();
69 hdr.int_ingress_tstamp.ingress_tstamp = (bit<32>) smeta.enq_timestamp;
70 }
71 // Egress timestamp.
Carmelo Casconeb5324e72018-11-25 02:26:32 -080072 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -070073 action int_set_header_5() {
74 hdr.int_egress_tstamp.setValid();
75 hdr.int_egress_tstamp.egress_tstamp = (bit<32>) smeta.enq_timestamp + (bit<32>) smeta.deq_timedelta;
76 }
77 // Queue congestion.
Carmelo Casconeb5324e72018-11-25 02:26:32 -080078 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -070079 action int_set_header_6() {
80 hdr.int_q_congestion.setValid();
81 // TODO: support queue congestion.
82 hdr.int_q_congestion.q_id = 8w0;
83 hdr.int_q_congestion.q_congestion = 24w0;
84 }
85 // Egress port utilization.
Carmelo Casconeb5324e72018-11-25 02:26:32 -080086 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -070087 action int_set_header_7() {
88 hdr.int_egress_tx_util.setValid();
89 // TODO: implement tx utilization support in BMv2.
90 hdr.int_egress_tx_util.egress_port_tx_util = 32w0;
91 }
92#endif // _INT_METADATA_ACTIONS
93
94 // Actions to keep track of the new metadata added.
Carmelo Casconeb5324e72018-11-25 02:26:32 -080095 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -070096 action add_1() {
97 fmeta.int_meta.new_words = fmeta.int_meta.new_words + 1;
98 fmeta.int_meta.new_bytes = fmeta.int_meta.new_bytes + 4;
99 }
100
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800101 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700102 action add_2() {
103 fmeta.int_meta.new_words = fmeta.int_meta.new_words + 2;
104 fmeta.int_meta.new_bytes = fmeta.int_meta.new_bytes + 8;
105 }
106
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800107 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700108 action add_3() {
109 fmeta.int_meta.new_words = fmeta.int_meta.new_words + 3;
110 fmeta.int_meta.new_bytes = fmeta.int_meta.new_bytes + 12;
111 }
112
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800113 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700114 action add_4() {
115 fmeta.int_meta.new_words = fmeta.int_meta.new_words + 4;
116 fmeta.int_meta.new_bytes = fmeta.int_meta.new_bytes + 16;
117 }
118
119 // Action function for bits 0-3 combinations, 0 is msb, 3 is lsb.
120 // Each bit set indicates that corresponding INT header should be added.
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800121 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700122 action int_set_header_0003_i0() {
123 }
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800124 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700125 action int_set_header_0003_i1() {
126 int_set_header_3();
127 add_1();
128 }
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800129 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700130 action int_set_header_0003_i2() {
131 int_set_header_2();
132 add_1();
133 }
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800134 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700135 action int_set_header_0003_i3() {
136 int_set_header_3();
137 int_set_header_2();
138 add_2();
139 }
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800140 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700141 action int_set_header_0003_i4() {
142 int_set_header_1();
143 add_1();
144 }
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800145 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700146 action int_set_header_0003_i5() {
147 int_set_header_3();
148 int_set_header_1();
149 add_2();
150 }
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800151 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700152 action int_set_header_0003_i6() {
153 int_set_header_2();
154 int_set_header_1();
155 add_2();
156 }
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800157 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700158 action int_set_header_0003_i7() {
159 int_set_header_3();
160 int_set_header_2();
161 int_set_header_1();
162 add_3();
163 }
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800164 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700165 action int_set_header_0003_i8() {
166 int_set_header_0();
167 add_1();
168 }
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800169 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700170 action int_set_header_0003_i9() {
171 int_set_header_3();
172 int_set_header_0();
173 add_2();
174 }
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800175 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700176 action int_set_header_0003_i10() {
177 int_set_header_2();
178 int_set_header_0();
179 add_2();
180 }
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800181 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700182 action int_set_header_0003_i11() {
183 int_set_header_3();
184 int_set_header_2();
185 int_set_header_0();
186 add_3();
187 }
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800188 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700189 action int_set_header_0003_i12() {
190 int_set_header_1();
191 int_set_header_0();
192 add_2();
193 }
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800194 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700195 action int_set_header_0003_i13() {
196 int_set_header_3();
197 int_set_header_1();
198 int_set_header_0();
199 add_3();
200 }
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800201 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700202 action int_set_header_0003_i14() {
203 int_set_header_2();
204 int_set_header_1();
205 int_set_header_0();
206 add_3();
207 }
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800208 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700209 action int_set_header_0003_i15() {
210 int_set_header_3();
211 int_set_header_2();
212 int_set_header_1();
213 int_set_header_0();
214 add_4();
215 }
216
217 // Action function for bits 4-7 combinations, 4 is msb, 7 is lsb.
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800218 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700219 action int_set_header_0407_i0() {
220 }
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800221 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700222 action int_set_header_0407_i1() {
223 int_set_header_7();
224 add_1();
225 }
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800226 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700227 action int_set_header_0407_i2() {
228 int_set_header_6();
229 add_1();
230 }
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800231 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700232 action int_set_header_0407_i3() {
233 int_set_header_7();
234 int_set_header_6();
235 add_2();
236 }
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800237 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700238 action int_set_header_0407_i4() {
239 int_set_header_5();
240 add_1();
241 }
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800242 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700243 action int_set_header_0407_i5() {
244 int_set_header_7();
245 int_set_header_5();
246 add_2();
247 }
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800248 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700249 action int_set_header_0407_i6() {
250 int_set_header_6();
251 int_set_header_5();
252 add_2();
253 }
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800254 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700255 action int_set_header_0407_i7() {
256 int_set_header_7();
257 int_set_header_6();
258 int_set_header_5();
259 add_3();
260 }
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800261 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700262 action int_set_header_0407_i8() {
263 int_set_header_4();
264 add_1();
265 }
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800266 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700267 action int_set_header_0407_i9() {
268 int_set_header_7();
269 int_set_header_4();
270 add_2();
271 }
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800272 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700273 action int_set_header_0407_i10() {
274 int_set_header_6();
275 int_set_header_4();
276 add_2();
277 }
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800278 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700279 action int_set_header_0407_i11() {
280 int_set_header_7();
281 int_set_header_6();
282 int_set_header_4();
283 add_3();
284 }
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800285 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700286 action int_set_header_0407_i12() {
287 int_set_header_5();
288 int_set_header_4();
289 add_2();
290 }
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800291 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700292 action int_set_header_0407_i13() {
293 int_set_header_7();
294 int_set_header_5();
295 int_set_header_4();
296 add_3();
297 }
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800298 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700299 action int_set_header_0407_i14() {
300 int_set_header_6();
301 int_set_header_5();
302 int_set_header_4();
303 add_3();
304 }
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800305 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700306 action int_set_header_0407_i15() {
307 int_set_header_7();
308 int_set_header_6();
309 int_set_header_5();
310 int_set_header_4();
311 add_4();
312 }
313
314 // Default action used to set switch ID.
315 table tb_int_insert {
Carmelo Casconefa421582018-09-13 10:05:57 -0700316 // We don't really need a key here, however we add a dummy one as a
317 // workaround to ONOS inability to properly support default actions.
318 key = {
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800319 hdr.int_header.isValid(): exact @name("int_is_valid");
Carmelo Casconefa421582018-09-13 10:05:57 -0700320 }
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700321 actions = {
322 init_metadata;
Carmelo Casconefa421582018-09-13 10:05:57 -0700323 @defaultonly nop;
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700324 }
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800325 const default_action = nop();
Carmelo Casconefa421582018-09-13 10:05:57 -0700326 size = 1;
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700327 }
328
329 // Table to process instruction bits 0-3.
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800330 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700331 table tb_int_inst_0003 {
332 key = {
333 hdr.int_header.instruction_mask_0003 : exact;
334 }
335 actions = {
336 int_set_header_0003_i0;
337 int_set_header_0003_i1;
338 int_set_header_0003_i2;
339 int_set_header_0003_i3;
340 int_set_header_0003_i4;
341 int_set_header_0003_i5;
342 int_set_header_0003_i6;
343 int_set_header_0003_i7;
344 int_set_header_0003_i8;
345 int_set_header_0003_i9;
346 int_set_header_0003_i10;
347 int_set_header_0003_i11;
348 int_set_header_0003_i12;
349 int_set_header_0003_i13;
350 int_set_header_0003_i14;
351 int_set_header_0003_i15;
352 }
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700353 const entries = {
354 (0x0) : int_set_header_0003_i0();
355 (0x1) : int_set_header_0003_i1();
356 (0x2) : int_set_header_0003_i2();
357 (0x3) : int_set_header_0003_i3();
358 (0x4) : int_set_header_0003_i4();
359 (0x5) : int_set_header_0003_i5();
360 (0x6) : int_set_header_0003_i6();
361 (0x7) : int_set_header_0003_i7();
362 (0x8) : int_set_header_0003_i8();
363 (0x9) : int_set_header_0003_i9();
364 (0xA) : int_set_header_0003_i10();
365 (0xB) : int_set_header_0003_i11();
366 (0xC) : int_set_header_0003_i12();
367 (0xD) : int_set_header_0003_i13();
368 (0xE) : int_set_header_0003_i14();
369 (0xF) : int_set_header_0003_i15();
370 }
371 }
372
373 // Table to process instruction bits 4-7.
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800374 @hidden
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700375 table tb_int_inst_0407 {
376 key = {
377 hdr.int_header.instruction_mask_0407 : exact;
378 }
379 actions = {
380 int_set_header_0407_i0;
381 int_set_header_0407_i1;
382 int_set_header_0407_i2;
383 int_set_header_0407_i3;
384 int_set_header_0407_i4;
385 int_set_header_0407_i5;
386 int_set_header_0407_i6;
387 int_set_header_0407_i7;
388 int_set_header_0407_i8;
389 int_set_header_0407_i9;
390 int_set_header_0407_i10;
391 int_set_header_0407_i11;
392 int_set_header_0407_i12;
393 int_set_header_0407_i13;
394 int_set_header_0407_i14;
395 int_set_header_0407_i15;
396 }
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700397 const entries = {
398 (0x0) : int_set_header_0407_i0();
399 (0x1) : int_set_header_0407_i1();
400 (0x2) : int_set_header_0407_i2();
401 (0x3) : int_set_header_0407_i3();
402 (0x4) : int_set_header_0407_i4();
403 (0x5) : int_set_header_0407_i5();
404 (0x6) : int_set_header_0407_i6();
405 (0x7) : int_set_header_0407_i7();
406 (0x8) : int_set_header_0407_i8();
407 (0x9) : int_set_header_0407_i9();
408 (0xA) : int_set_header_0407_i10();
409 (0xB) : int_set_header_0407_i11();
410 (0xC) : int_set_header_0407_i12();
411 (0xD) : int_set_header_0407_i13();
412 (0xE) : int_set_header_0407_i14();
413 (0xF) : int_set_header_0407_i15();
414 }
415 }
416
417 apply {
418 tb_int_insert.apply();
419 if (fmeta.int_meta.transit == _FALSE) {
420 return;
421 }
422 tb_int_inst_0003.apply();
423 tb_int_inst_0407.apply();
424 // Increment hop cnt
425 hdr.int_header.total_hop_cnt = hdr.int_header.total_hop_cnt + 1;
426 // Update headers lengths.
427 if (hdr.ipv4.isValid()) {
428 hdr.ipv4.total_len = hdr.ipv4.total_len + fmeta.int_meta.new_bytes;
429 }
430 if (hdr.udp.isValid()) {
431 hdr.udp.len = hdr.udp.len + fmeta.int_meta.new_bytes;
432 }
433 if (hdr.intl4_shim.isValid()) {
434 hdr.intl4_shim.len_words = hdr.intl4_shim.len_words + fmeta.int_meta.new_words;
435 }
436 }
437}
438
439#endif