blob: d09eab8aacd26a0cb45f858d1c8b441d331094c9 [file] [log] [blame]
Carmelo Cascone04888222018-03-19 22:18:12 -07001control int_metadata_insert(inout parsed_headers_t hdr,
2 in int_metadata_t int_metadata,
3 inout standard_metadata_t standard_metadata) {
4 // this implementation covers only INT instructions 0, 1, 2, 4, 5
5 action int_set_header_0() {
6 hdr.int_switch_id.setValid();
7 hdr.int_switch_id.switch_id = int_metadata.switch_id;
8 }
9
10 action int_set_header_1() {
11 hdr.int_port_ids.setValid();
12 hdr.int_port_ids.ingress_port_id =
13 (bit<16>) standard_metadata.ingress_port;
14 hdr.int_port_ids.egress_port_id =
15 (bit<16>) standard_metadata.egress_port;
16 }
17
18 action int_set_header_2() {
19 hdr.int_hop_latency.setValid();
20 hdr.int_hop_latency.hop_latency = 0xffffffff;
21 }
22
23 action int_set_header_3() { // Queue ID + Queue occupancy, not supported
24 hdr.int_q_occupancy.setValid();
25 hdr.int_q_occupancy.q_id = 0x00;
26 hdr.int_q_occupancy.q_occupancy = (bit<24>) standard_metadata.deq_qdepth;
27 }
28
29 action int_set_header_4() {
30 hdr.int_ingress_tstamp.setValid();
31 hdr.int_ingress_tstamp.ingress_tstamp =
32 (bit<32>) standard_metadata.ingress_global_timestamp;
33 }
34
35 action int_set_header_5() {
36 hdr.int_egress_tstamp.setValid();
37 hdr.int_egress_tstamp.egress_tstamp =
38 (bit<32>) standard_metadata.egress_global_timestamp;
39 }
40
41 action int_set_header_6() { // Queue ID + Queue congestion status, not supported
42 hdr.int_q_congestion.setValid();
43 hdr.int_q_congestion.q_id = 0xff;
44 hdr.int_q_congestion.q_congestion = 0xffffff;
45 }
46
47 action int_set_header_7() { // Egress port tx utilization, not supported
48 hdr.int_egress_port_tx_util.setValid();
49 hdr.int_egress_port_tx_util.egress_port_tx_util = 0xffffffff;
50 }
51
52 action int_set_header_0003_i0() {
53 }
54 action int_set_header_0003_i1() {
55 int_set_header_3();
56 }
57 action int_set_header_0003_i2() {
58 int_set_header_2();
59 }
60 action int_set_header_0003_i3() {
61 int_set_header_3();
62 int_set_header_2();
63 }
64 action int_set_header_0003_i4() {
65 int_set_header_1();
66 }
67 action int_set_header_0003_i5() {
68 int_set_header_3();
69 int_set_header_1();
70 }
71 action int_set_header_0003_i6() {
72 int_set_header_2();
73 int_set_header_1();
74 }
75 action int_set_header_0003_i7() {
76 int_set_header_3();
77 int_set_header_2();
78 int_set_header_1();
79 }
80 action int_set_header_0003_i8() {
81 int_set_header_0();
82 }
83 action int_set_header_0003_i9() {
84 int_set_header_3();
85 int_set_header_0();
86 }
87 action int_set_header_0003_i10() {
88 int_set_header_2();
89 int_set_header_0();
90 }
91 action int_set_header_0003_i11() {
92 int_set_header_3();
93 int_set_header_2();
94 int_set_header_0();
95 }
96 action int_set_header_0003_i12() {
97 int_set_header_1();
98 int_set_header_0();
99 }
100 action int_set_header_0003_i13() {
101 int_set_header_3();
102 int_set_header_1();
103 int_set_header_0();
104 }
105 action int_set_header_0003_i14() {
106 int_set_header_2();
107 int_set_header_1();
108 int_set_header_0();
109 }
110 action int_set_header_0003_i15() {
111 int_set_header_3();
112 int_set_header_2();
113 int_set_header_1();
114 int_set_header_0();
115 }
116
117 table int_inst_0003 {
118 key = {
119 hdr.int_header.instruction_mask_0003 : exact;
120 }
121 actions = {
122 int_set_header_0003_i0;
123 int_set_header_0003_i1;
124 int_set_header_0003_i2;
125 int_set_header_0003_i3;
126 int_set_header_0003_i4;
127 int_set_header_0003_i5;
128 int_set_header_0003_i6;
129 int_set_header_0003_i7;
130 int_set_header_0003_i8;
131 int_set_header_0003_i9;
132 int_set_header_0003_i10;
133 int_set_header_0003_i11;
134 int_set_header_0003_i12;
135 int_set_header_0003_i13;
136 int_set_header_0003_i14;
137 int_set_header_0003_i15;
138 }
139 default_action = int_set_header_0003_i0();
140 size = 17;
141 }
142
143 action int_set_header_0407_i0() {
144 }
145 action int_set_header_0407_i1() {
146 int_set_header_7();
147 }
148 action int_set_header_0407_i2() {
149 int_set_header_6();
150 }
151 action int_set_header_0407_i3() {
152 int_set_header_7();
153 int_set_header_6();
154 }
155 action int_set_header_0407_i4() {
156 int_set_header_5();
157 }
158 action int_set_header_0407_i5() {
159 int_set_header_7();
160 int_set_header_5();
161 }
162 action int_set_header_0407_i6() {
163 int_set_header_6();
164 int_set_header_5();
165 }
166 action int_set_header_0407_i7() {
167 int_set_header_7();
168 int_set_header_6();
169 int_set_header_5();
170 }
171 action int_set_header_0407_i8() {
172 int_set_header_4();
173 }
174 action int_set_header_0407_i9() {
175 int_set_header_7();
176 int_set_header_4();
177 }
178 action int_set_header_0407_i10() {
179 int_set_header_6();
180 int_set_header_4();
181 }
182 action int_set_header_0407_i11() {
183 int_set_header_7();
184 int_set_header_6();
185 int_set_header_4();
186 }
187 action int_set_header_0407_i12() {
188 int_set_header_5();
189 int_set_header_4();
190 }
191 action int_set_header_0407_i13() {
192 int_set_header_7();
193 int_set_header_5();
194 int_set_header_4();
195 }
196 action int_set_header_0407_i14() {
197 int_set_header_6();
198 int_set_header_5();
199 int_set_header_4();
200 }
201 action int_set_header_0407_i15() {
202 int_set_header_7();
203 int_set_header_6();
204 int_set_header_5();
205 int_set_header_4();
206 }
207
208 table int_inst_0407 {
209 key = {
210 hdr.int_header.instruction_mask_0407 : exact;
211 }
212 actions = {
213 int_set_header_0407_i0;
214 int_set_header_0407_i1;
215 int_set_header_0407_i2;
216 int_set_header_0407_i3;
217 int_set_header_0407_i4;
218 int_set_header_0407_i5;
219 int_set_header_0407_i6;
220 int_set_header_0407_i7;
221 int_set_header_0407_i8;
222 int_set_header_0407_i9;
223 int_set_header_0407_i10;
224 int_set_header_0407_i11;
225 int_set_header_0407_i12;
226 int_set_header_0407_i13;
227 int_set_header_0407_i14;
228 int_set_header_0407_i15;
229 }
230 default_action = int_set_header_0407_i0();
231 size = 17;
232 }
233
234 apply {
235 int_inst_0003.apply();
236 int_inst_0407.apply();
237 }
238}
239
240control int_outer_encap(inout parsed_headers_t hdr,
241 in int_metadata_t int_metadata) {
242 action int_update_ipv4() {
243 hdr.ipv4.total_len = hdr.ipv4.total_len + int_metadata.insert_byte_cnt;
244 }
245 action int_update_udp() {
246 hdr.udp.len = hdr.udp.len + int_metadata.insert_byte_cnt;
247 hdr.udp.checksum = 0;
248 }
249 action int_update_shim() {
250 hdr.intl4_shim.len = hdr.intl4_shim.len + int_metadata.int_hdr_word_len;
251 }
252
253 apply{
254 if (hdr.ipv4.isValid()) {
255 int_update_ipv4();
256 }
257 if (hdr.udp.isValid()) {
258 int_update_udp();
259 }
260 if (hdr.intl4_shim.isValid()) {
261 int_update_shim();
262 }
263 }
264}
265
266control int_egress(inout parsed_headers_t hdr,
267 inout int_metadata_t int_metadata,
268 inout standard_metadata_t standard_metadata) {
269 action int_transit(bit<32> switch_id) {
270 int_metadata.switch_id = switch_id;
271 int_metadata.insert_byte_cnt = (bit<16>) (hdr.int_header.ins_cnt << 2);
272 int_metadata.int_hdr_word_len = (bit<8>) int_metadata.ins_cnt_tmp;
273 }
274 table int_prep {
275 key = {}
276 actions = {int_transit;}
277 }
278
279 action int_hop_cnt_increment() {
280 hdr.int_header.total_hop_cnt = hdr.int_header.total_hop_cnt + 1;
281 }
282 action int_hop_cnt_exceeded() {
283 hdr.int_header.e = 1;
284 }
285
286 apply{
287 if(hdr.int_header.isValid()) {
288 if(hdr.int_header.total_hop_cnt != hdr.int_header.max_hop_cnt &&
289 hdr.int_header.e == 0) {
290 int_hop_cnt_increment();
291 int_prep.apply();
292 int_metadata_insert.apply(hdr, int_metadata, standard_metadata);
293 int_outer_encap.apply(hdr, int_metadata);
294 } else {
295 int_hop_cnt_exceeded();
296 }
297 }
298 }
299}