2727parser TpsAggParser (
2828 packet_in packet ,
2929 out headers hdr ,
30- out metadata ig_meta ,
30+ out metadata meta ,
3131 out ingress_intrinsic_metadata_t ig_intr_md ) {
3232
3333 TofinoIngressParser () tofino_parser ;
@@ -49,6 +49,8 @@ parser TpsAggParser(
4949
5050 state parse_ipv4 {
5151 packet .extract (hdr .ipv4 );
52+ meta .ipv6_addr = 0 ;
53+ meta .ipv4_addr = hdr .ipv4 .dstAddr ;
5254 transition select (hdr .ipv4 .protocol ) {
5355 TYPE_UDP : parse_udp_int ;
5456 TYPE_TCP : parse_tcp ;
@@ -58,6 +60,8 @@ parser TpsAggParser(
5860
5961 state parse_ipv6 {
6062 packet .extract (hdr .ipv6 );
63+ meta .ipv4_addr = 0 ;
64+ meta .ipv6_addr = hdr .ipv6 .dstAddr ;
6165 transition select (hdr .ipv6 .next_hdr_proto ) {
6266 TYPE_UDP : parse_udp_int ;
6367 TYPE_TCP : parse_tcp ;
@@ -67,6 +71,7 @@ parser TpsAggParser(
6771
6872 state parse_udp_int {
6973 packet .extract (hdr .udp_int );
74+ meta .dst_port = hdr .udp_int .dst_port ;
7075 transition select (hdr .udp_int .dst_port ) {
7176 UDP_INT_DST_PORT : parse_int_shim ;
7277 default : accept ;
@@ -118,24 +123,6 @@ control TpsAggIngress(
118123
119124 DirectCounter <bit <32 >>(CounterType_t .PACKETS ) droppedPackets ;
120125
121- action pack_meta_tcp () {
122- meta .dst_port = hdr .tcp .dst_port ;
123- }
124-
125- action pack_meta_udp () {
126- meta .dst_port = hdr .udp_int .dst_port ;
127- }
128-
129- action pack_meta_ipv4 () {
130- meta .ipv6_addr = 0 ;
131- meta .ipv4_addr = hdr .ipv4 .dstAddr ;
132- }
133-
134- action pack_meta_ipv6 () {
135- meta .ipv4_addr = 0 ;
136- meta .ipv6_addr = hdr .ipv6 .dstAddr ;
137- }
138-
139126 action data_drop () {
140127 ig_dprsr_md .drop_ctl = 0x1 ;
141128 droppedPackets .count ();
@@ -214,25 +201,23 @@ control TpsAggIngress(
214201
215202 hdr .int_meta .switch_id = switch_id ;
216203 hdr .int_meta .orig_mac = hdr .ethernet .src_mac ;
217-
218- #ifdef IMPL_COUNTER
219- forwardedPackets .count (device );
220- #endif
221204 }
222205
223206 action data_inspect_packet_ipv4 () {
224207 hdr .ipv4 .ttl = hdr .ipv4 .ttl - 1 ;
225208 hdr .int_shim .next_proto = hdr .ipv4 .protocol ;
226209 hdr .ipv4 .protocol = TYPE_UDP ;
227210 // TODO/FIXME - This value will be incorrect once the gateway with INT has been added into the mix
228- hdr .ipv4 .totalLen = hdr .ipv4 .totalLen + IPV4_INT_UDP_BYTES ;
211+ hdr .ipv4 .totalLen = hdr .ipv4 .totalLen + (
212+ (INT_SHIM_BASE_SIZE * BYTES_PER_SHIM ) + UDP_HDR_BYTES );
229213 }
230214
231215 action data_inspect_packet_ipv6 () {
232216 hdr .int_shim .next_proto = hdr .ipv6 .next_hdr_proto ;
233217 hdr .ipv6 .next_hdr_proto = TYPE_UDP ;
234218 // TODO/FIXME - This value will be incorrect once the gateway with INT has been added into the mix
235- hdr .ipv6 .payload_len = hdr .ipv6 .payload_len + IPV6_INT_UDP_BYTES ;
219+ hdr .ipv6 .payload_len = hdr .ipv6 .payload_len + (
220+ (INT_SHIM_BASE_SIZE * BYTES_PER_SHIM ) + UDP_HDR_BYTES );
236221 }
237222
238223 table data_inspection_t {
@@ -256,7 +241,8 @@ control TpsAggIngress(
256241 hdr .udp_int .dst_port = UDP_INT_DST_PORT ;
257242
258243 // TODO/FIXME - This value will be incorrect once the gateway with INT has been added into the mix
259- hdr .udp_int .len = hdr .udp .len + INT_SHIM_UDP_BYTES ;
244+ hdr .udp_int .len = hdr .udp .len + (
245+ (INT_SHIM_BASE_SIZE * BYTES_PER_SHIM ) + UDP_HDR_BYTES );
260246 }
261247
262248 action insert_udp_int_for_tcp_ipv4 () {
@@ -270,79 +256,43 @@ control TpsAggIngress(
270256 hdr .udp_int .setValid ();
271257 hdr .udp_int .src_port = UDP_INT_SRC_PORT ;
272258 hdr .udp_int .dst_port = UDP_INT_DST_PORT ;
273- hdr .udp_int .len = hdr .ipv6 .payload_len - IPV6_HDR_BYTES ;
274- }
275-
276- /*
277- action generate_learn_notification() {
278- digest<mac_learn_digest>((bit<32>) 1024,
279- { hdr.arp.src_mac,
280- standard_metadata.ingress_port
281- });
282- }
283- */
284-
285- /*
286- action arp_flood() {
287- standard_metadata.mcast_grp = 1;
288- }
289-
290- table arp_flood_t {
291- key = {
292- hdr.ethernet.dst_mac: exact;
293- }
294- actions = {
295- arp_flood;
296- NoAction;
297- }
298- default_action = NoAction();
259+ hdr .udp_int .len = hdr .ipv6 .payload_len ;
299260 }
300261
301- */
302262 apply {
263+ /* Value will be set with the udp_int.dst_port in the parser
264+ which would be incorrect in this case */
265+ if (hdr .tcp .isValid ()) {
266+ meta .dst_port = hdr .tcp .dst_port ;
267+ }
303268 if (hdr .int_shim .isValid ()) {
304269 // Add switch ID into existing INT data
305270 add_switch_id_t .apply ();
306271 } else {
307- // Pack metadata with original header values for data drop
308- if (hdr .udp_int .isValid ()) {
309- pack_meta_udp ();
310- } else if (hdr .tcp .isValid ()) {
311- pack_meta_tcp ();
312- }
313- if (hdr .ipv4 .isValid ()) {
314- pack_meta_ipv4 ();
315- } else if (hdr .ipv6 .isValid ()) {
316- pack_meta_ipv6 ();
317- }
318-
319- // Check to see if need to add INT
320- data_inspection_t .apply ();
321-
322272 // Add IP & Protocol specific data to new INT data
323- if (hdr .int_shim .isValid ()) {
273+ if (data_inspection_t .apply ().hit ) {
274+ if (hdr .udp_int .isValid ()) {
275+ insert_udp_int_for_udp ();
276+ }
324277 if (hdr .ipv4 .isValid ()) {
325278 data_inspect_packet_ipv4 ();
326- if (hdr .udp_int .isValid ()) {
327- insert_udp_int_for_udp ();
328- } else if (hdr .tcp .isValid ()) {
279+ if (hdr .tcp .isValid ()) {
329280 insert_udp_int_for_tcp_ipv4 ();
330281 }
331282 }
332283 else if (hdr .ipv6 .isValid ()) {
333284 data_inspect_packet_ipv6 ();
334- if (hdr .udp_int .isValid ()) {
335- insert_udp_int_for_udp ();
336- } else if (hdr .tcp .isValid ()) {
285+ if (hdr .tcp .isValid ()) {
337286 insert_udp_int_for_tcp_ipv6 ();
338287 }
339288 }
340289 }
341290 }
342291
343292 // Basic forwarding and drop logic
344- data_forward_t .apply ();
345- data_drop_t .apply ();
293+ if (data_drop_t .apply ().miss ) {
294+ data_forward_t .apply ();
295+ }
346296 }
347297}
348298
@@ -390,68 +340,9 @@ parser TpsAggEgressParser(
390340 }
391341 state parse_ethernet {
392342 packet .extract (hdr .ethernet );
393- transition select (hdr .ethernet .etherType ) {
394- TYPE_ARP : parse_arp ;
395- TYPE_IPV4 : parse_ipv4 ;
396- TYPE_IPV6 : parse_ipv6 ;
397- default : accept ;
398- }
399- }
400-
401- state parse_ipv4 {
402- packet .extract (hdr .ipv4 );
403- transition select (hdr .ipv4 .protocol ) {
404- TYPE_UDP : parse_udp_int ;
405- TYPE_TCP : parse_tcp ;
406- default : accept ;
407- }
408- }
409-
410- state parse_ipv6 {
411- packet .extract (hdr .ipv6 );
412- transition select (hdr .ipv6 .next_hdr_proto ) {
413- TYPE_UDP : parse_udp_int ;
414- TYPE_TCP : parse_tcp ;
415- default : accept ;
416- }
417- }
418-
419- state parse_udp_int {
420- packet .extract (hdr .udp_int );
421- transition select (hdr .udp_int .dst_port ) {
422- UDP_INT_DST_PORT : parse_int_shim ;
423- default : accept ;
424- }
425- }
426-
427- state parse_int_shim {
428- packet .extract (hdr .int_shim );
429- transition parse_int_hdr ;
430- }
431-
432- state parse_int_hdr {
433- packet .extract (hdr .int_header );
434- transition select (hdr .int_shim .next_proto ){
435- TYPE_UDP : parse_udp ;
436- TYPE_TCP : parse_tcp ;
437- default : accept ;
438- }
439- }
440-
441- state parse_tcp {
442- packet .extract (hdr .tcp );
443- transition accept ;
444- }
445-
446- state parse_udp {
447- packet .extract (hdr .udp );
448343 transition accept ;
449344 }
450345
451- state parse_arp {
452- packet .extract (hdr .arp );
453- transition accept ;
454- }
455346}
456347
457348control TpsAggEgress (
@@ -476,32 +367,8 @@ control TpsAggEgressDeparser(
476367 in metadata meta ,
477368 in egress_intrinsic_metadata_for_deparser_t eg_intr_dprsr_md ) {
478369
479- Checksum () ipv4_checksum ;
480370 apply {
481- hdr .ipv4 .hdrChecksum = ipv4_checksum .update (
482- {hdr .ipv4 .version ,
483- hdr .ipv4 .ihl ,
484- hdr .ipv4 .diffserv ,
485- hdr .ipv4 .totalLen ,
486- hdr .ipv4 .identification ,
487- hdr .ipv4 .flags ,
488- hdr .ipv4 .fragOffset ,
489- hdr .ipv4 .ttl ,
490- hdr .ipv4 .protocol ,
491- hdr .ipv4 .srcAddr ,
492- hdr .ipv4 .dstAddr });
493-
494- packet .emit (hdr .ethernet );
495- packet .emit (hdr .arp );
496- packet .emit (hdr .ipv4 );
497- packet .emit (hdr .ipv6 );
498- packet .emit (hdr .udp_int );
499- packet .emit (hdr .int_shim );
500- packet .emit (hdr .int_header );
501- packet .emit (hdr .int_meta_2 );
502- packet .emit (hdr .int_meta );
503- packet .emit (hdr .udp );
504- packet .emit (hdr .tcp );
371+ packet .emit (hdr );
505372 }
506373}
507374
0 commit comments