blob: 9c066bd055a437613c59cbaa9bc7513b44d5bc3e [file] [log] [blame]
Jonghwan Hyun4a9a6712017-11-13 14:43:55 -08001/*
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 headers_t hdr,
22 inout local_metadata_t local_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 local_metadata.int_meta.switch_id = switch_id;
35 local_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 = local_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 local_metadata.int_meta.sink: exact;
230 }
231 actions = {
232 int_transit;
233 }
234 counters = counter_int_insert;
235 size = 2;
236 }
237
238 /* Table to process instruction bits 0-3 */
239 table tb_int_inst_0003 {
240 key = {
241 hdr.int_header.instruction_mask_0003 : exact;
242 }
243 actions = {
244 int_set_header_0003_i0;
245 int_set_header_0003_i1;
246 int_set_header_0003_i2;
247 int_set_header_0003_i3;
248 int_set_header_0003_i4;
249 int_set_header_0003_i5;
250 int_set_header_0003_i6;
251 int_set_header_0003_i7;
252 int_set_header_0003_i8;
253 int_set_header_0003_i9;
254 int_set_header_0003_i10;
255 int_set_header_0003_i11;
256 int_set_header_0003_i12;
257 int_set_header_0003_i13;
258 int_set_header_0003_i14;
259 int_set_header_0003_i15;
260 }
261 counters = counter_int_inst_0003;
262 size = 16;
263 }
264
265 /* Table to process instruction bits 4-7 */
266 table tb_int_inst_0407 {
267 key = {
268 hdr.int_header.instruction_mask_0407 : exact;
269 }
270 actions = {
271 int_set_header_0407_i0;
272 int_set_header_0407_i1;
273 int_set_header_0407_i2;
274 int_set_header_0407_i3;
275 int_set_header_0407_i4;
276 int_set_header_0407_i5;
277 int_set_header_0407_i6;
278 int_set_header_0407_i7;
279 int_set_header_0407_i8;
280 int_set_header_0407_i9;
281 int_set_header_0407_i10;
282 int_set_header_0407_i11;
283 int_set_header_0407_i12;
284 int_set_header_0407_i13;
285 int_set_header_0407_i14;
286 int_set_header_0407_i15;
287 }
288 counters = counter_int_inst_0407;
289 size = 16;
290 }
291
292 apply {
293 tb_int_insert.apply();
294 tb_int_inst_0003.apply();
295 tb_int_inst_0407.apply();
296 int_update_total_hop_cnt();
297 }
298}
299
300control process_int_outer_encap (
301 inout headers_t hdr,
302 inout local_metadata_t local_metadata,
303 inout standard_metadata_t standard_metadata) {
304
305 action int_update_ipv4() {
306 hdr.ipv4.len = hdr.ipv4.len + local_metadata.int_meta.insert_byte_cnt;
307 }
308 action int_update_udp() {
309 hdr.udp.length_ = hdr.udp.length_ + local_metadata.int_meta.insert_byte_cnt;
Jonghwan Hyun8be03392017-12-04 15:48:44 -0800310 }
311 action int_update_shim() {
Jonghwan Hyun4a9a6712017-11-13 14:43:55 -0800312 hdr.intl4_shim.len = hdr.intl4_shim.len + (bit<8>)hdr.int_header.ins_cnt;
313 }
314
315 apply {
316 if (hdr.ipv4.isValid()) {
317 int_update_ipv4();
318 }
Jonghwan Hyun8be03392017-12-04 15:48:44 -0800319 if (hdr.udp.isValid()) {
Jonghwan Hyun4a9a6712017-11-13 14:43:55 -0800320 int_update_udp();
321 }
Jonghwan Hyun8be03392017-12-04 15:48:44 -0800322 if (hdr.intl4_shim.isValid()) {
323 int_update_shim();
324 }
Jonghwan Hyun4a9a6712017-11-13 14:43:55 -0800325 }
326}
327
328#endif