blob: 3f863e8fd22d8fcf9920bc03446f27df94f01551 [file] [log] [blame]
Jonghwan Hyuned478dc2018-08-06 15:35:18 +09001/*
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 fabric_metadata,
23 inout standard_metadata_t standard_metadata) {
24
25 direct_counter(CounterType.packets_and_bytes) counter_int_insert;
26 direct_counter(CounterType.packets_and_bytes) counter_int_inst_0003;
27 direct_counter(CounterType.packets_and_bytes) counter_int_inst_0407;
28
29 action int_update_total_hop_cnt() {
30 hdr.int_header.total_hop_cnt = hdr.int_header.total_hop_cnt + 1;
31 }
32
33 action int_transit(switch_id_t switch_id) {
34 fabric_metadata.int_meta.switch_id = switch_id;
35 fabric_metadata.int_meta.insert_byte_cnt = (bit<16>) hdr.int_header.ins_cnt << 2;
36 }
37
38 /* Instr Bit 0 */
39 action int_set_header_0() { //switch_id
40 hdr.int_switch_id.setValid();
41 hdr.int_switch_id.switch_id = fabric_metadata.int_meta.switch_id;
42 }
43 action int_set_header_1() { //port_ids
44 hdr.int_port_ids.setValid();
45 hdr.int_port_ids.ingress_port_id =
46 (bit<16>) standard_metadata.ingress_port;
47 hdr.int_port_ids.egress_port_id =
48 (bit<16>) standard_metadata.egress_port;
49 }
50 action int_set_header_2() { //hop_latency
51 hdr.int_hop_latency.setValid();
52 hdr.int_hop_latency.hop_latency =
53 (bit<32>) standard_metadata.deq_timedelta;
54 }
55 action int_set_header_3() { //q_occupancy
56 // TODO: Support egress queue ID
57 hdr.int_q_occupancy.setValid();
58 hdr.int_q_occupancy.q_id =
59 0;
60 // (bit<8>) standard_metadata.egress_qid;
61 hdr.int_q_occupancy.q_occupancy =
62 (bit<24>) standard_metadata.deq_qdepth;
63 }
64 action int_set_header_4() { //ingress_tstamp
65 hdr.int_ingress_tstamp.setValid();
66 hdr.int_ingress_tstamp.ingress_tstamp =
67 (bit<32>) standard_metadata.enq_timestamp;
68 }
69 action int_set_header_5() { //egress_timestamp
70 hdr.int_egress_tstamp.setValid();
71 hdr.int_egress_tstamp.egress_tstamp =
72 (bit<32>) standard_metadata.enq_timestamp +
73 (bit<32>) standard_metadata.deq_timedelta;
74 }
75 action int_set_header_6() { //q_congestion
76 // TODO: implement queue congestion support in BMv2
77 // TODO: update egress queue ID
78 hdr.int_q_congestion.setValid();
79 hdr.int_q_congestion.q_id =
80 0;
81 // (bit<8>) standard_metadata.egress_qid;
82 hdr.int_q_congestion.q_congestion =
83 // (bit<24>) queueing_metadata.deq_congestion;
84 0;
85 }
86 action int_set_header_7() { //egress_port_tx_utilization
87 // TODO: implement tx utilization support in BMv2
88 hdr.int_egress_tx_util.setValid();
89 hdr.int_egress_tx_util.egress_port_tx_util =
90 // (bit<32>) queueing_metadata.tx_utilization;
91 0;
92 }
93
94 /* action function for bits 0-3 combinations, 0 is msb, 3 is lsb */
95 /* Each bit set indicates that corresponding INT header should be added */
96 action int_set_header_0003_i0() {
97 }
98 action int_set_header_0003_i1() {
99 int_set_header_3();
100 }
101 action int_set_header_0003_i2() {
102 int_set_header_2();
103 }
104 action int_set_header_0003_i3() {
105 int_set_header_3();
106 int_set_header_2();
107 }
108 action int_set_header_0003_i4() {
109 int_set_header_1();
110 }
111 action int_set_header_0003_i5() {
112 int_set_header_3();
113 int_set_header_1();
114 }
115 action int_set_header_0003_i6() {
116 int_set_header_2();
117 int_set_header_1();
118 }
119 action int_set_header_0003_i7() {
120 int_set_header_3();
121 int_set_header_2();
122 int_set_header_1();
123 }
124 action int_set_header_0003_i8() {
125 int_set_header_0();
126 }
127 action int_set_header_0003_i9() {
128 int_set_header_3();
129 int_set_header_0();
130 }
131 action int_set_header_0003_i10() {
132 int_set_header_2();
133 int_set_header_0();
134 }
135 action int_set_header_0003_i11() {
136 int_set_header_3();
137 int_set_header_2();
138 int_set_header_0();
139 }
140 action int_set_header_0003_i12() {
141 int_set_header_1();
142 int_set_header_0();
143 }
144 action int_set_header_0003_i13() {
145 int_set_header_3();
146 int_set_header_1();
147 int_set_header_0();
148 }
149 action int_set_header_0003_i14() {
150 int_set_header_2();
151 int_set_header_1();
152 int_set_header_0();
153 }
154 action int_set_header_0003_i15() {
155 int_set_header_3();
156 int_set_header_2();
157 int_set_header_1();
158 int_set_header_0();
159 }
160
161 /* action function for bits 4-7 combinations, 4 is msb, 7 is lsb */
162 action int_set_header_0407_i0() {
163 }
164 action int_set_header_0407_i1() {
165 int_set_header_7();
166 }
167 action int_set_header_0407_i2() {
168 int_set_header_6();
169 }
170 action int_set_header_0407_i3() {
171 int_set_header_7();
172 int_set_header_6();
173 }
174 action int_set_header_0407_i4() {
175 int_set_header_5();
176 }
177 action int_set_header_0407_i5() {
178 int_set_header_7();
179 int_set_header_5();
180 }
181 action int_set_header_0407_i6() {
182 int_set_header_6();
183 int_set_header_5();
184 }
185 action int_set_header_0407_i7() {
186 int_set_header_7();
187 int_set_header_6();
188 int_set_header_5();
189 }
190 action int_set_header_0407_i8() {
191 int_set_header_4();
192 }
193 action int_set_header_0407_i9() {
194 int_set_header_7();
195 int_set_header_4();
196 }
197 action int_set_header_0407_i10() {
198 int_set_header_6();
199 int_set_header_4();
200 }
201 action int_set_header_0407_i11() {
202 int_set_header_7();
203 int_set_header_6();
204 int_set_header_4();
205 }
206 action int_set_header_0407_i12() {
207 int_set_header_5();
208 int_set_header_4();
209 }
210 action int_set_header_0407_i13() {
211 int_set_header_7();
212 int_set_header_5();
213 int_set_header_4();
214 }
215 action int_set_header_0407_i14() {
216 int_set_header_6();
217 int_set_header_5();
218 int_set_header_4();
219 }
220 action int_set_header_0407_i15() {
221 int_set_header_7();
222 int_set_header_6();
223 int_set_header_5();
224 int_set_header_4();
225 }
226
227 table tb_int_insert {
228 key = {}
229 actions = {
230 int_transit;
231 }
232 counters = counter_int_insert;
233 size = 2;
234 }
235
236 /* Table to process instruction bits 0-3 */
237 table tb_int_inst_0003 {
238 key = {
239 hdr.int_header.instruction_mask_0003 : exact;
240 }
241 actions = {
242 int_set_header_0003_i0;
243 int_set_header_0003_i1;
244 int_set_header_0003_i2;
245 int_set_header_0003_i3;
246 int_set_header_0003_i4;
247 int_set_header_0003_i5;
248 int_set_header_0003_i6;
249 int_set_header_0003_i7;
250 int_set_header_0003_i8;
251 int_set_header_0003_i9;
252 int_set_header_0003_i10;
253 int_set_header_0003_i11;
254 int_set_header_0003_i12;
255 int_set_header_0003_i13;
256 int_set_header_0003_i14;
257 int_set_header_0003_i15;
258 }
259 counters = counter_int_inst_0003;
260 size = 16;
261 }
262
263 /* Table to process instruction bits 4-7 */
264 table tb_int_inst_0407 {
265 key = {
266 hdr.int_header.instruction_mask_0407 : exact;
267 }
268 actions = {
269 int_set_header_0407_i0;
270 int_set_header_0407_i1;
271 int_set_header_0407_i2;
272 int_set_header_0407_i3;
273 int_set_header_0407_i4;
274 int_set_header_0407_i5;
275 int_set_header_0407_i6;
276 int_set_header_0407_i7;
277 int_set_header_0407_i8;
278 int_set_header_0407_i9;
279 int_set_header_0407_i10;
280 int_set_header_0407_i11;
281 int_set_header_0407_i12;
282 int_set_header_0407_i13;
283 int_set_header_0407_i14;
284 int_set_header_0407_i15;
285 }
286 counters = counter_int_inst_0407;
287 size = 16;
288 }
289
290 apply {
291 tb_int_insert.apply();
292 tb_int_inst_0003.apply();
293 tb_int_inst_0407.apply();
294 int_update_total_hop_cnt();
295 }
296}
297
298control process_int_outer_encap (
299 inout parsed_headers_t hdr,
300 inout fabric_metadata_t fabric_metadata,
301 inout standard_metadata_t standard_metadata) {
302
303 action int_update_ipv4() {
304 hdr.ipv4.total_len = hdr.ipv4.total_len + fabric_metadata.int_meta.insert_byte_cnt;
305 }
306 action int_update_udp() {
307 hdr.udp.len = hdr.udp.len + fabric_metadata.int_meta.insert_byte_cnt;
308 }
309 action int_update_shim() {
310 hdr.intl4_shim.len = hdr.intl4_shim.len + (bit<8>)hdr.int_header.ins_cnt;
311 }
312
313 apply {
314 if (hdr.ipv4.isValid()) {
315 int_update_ipv4();
316 }
317 if (hdr.udp.isValid()) {
318 int_update_udp();
319 }
320 if (hdr.intl4_shim.isValid()) {
321 int_update_shim();
322 }
323 }
324}
325
326#endif