From 7d9e9e1cfdfe063cfb93f3d986352c70d6c36c25 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 27 Mar 2019 18:05:59 +0100 Subject: [PATCH] Replace switch in action with multiple if's p4c --target bmv2 --arch v1model --std p4-16 "../p4src/static-mapping.p4" -o "/home/p4/master-thesis/p4src" ../p4src/static-mapping.p4(60): error: SwitchStatement: switch statements not allowed in actions switch(hdr.icmp6.type) { ^^^^^^ --- doc/plan.org | 10 ++++++++++ p4src/static-mapping.p4 | 8 +++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/doc/plan.org b/doc/plan.org index 6bdd04d..a557f6e 100644 --- a/doc/plan.org +++ b/doc/plan.org @@ -141,6 +141,9 @@ | 2019-03-26 | | | | | Find out where packet is stuck | | | | | | +| 2019-03-27 | | | +| | switch cannot be used in actions! | | +| | | | | 2019-03-28 | Meet Laurent #4 | | | | - Router solicitation for finding router on startup! | | | | - test.py for TDD | | @@ -1388,6 +1391,13 @@ me available? I could work around this by using if(! .. .hit) { my_action(table_id) }, but it would not work with using default_action = ... +**** No switch in actions +#+BEGIN_SRC +../p4src/static-mapping.p4(60): error: SwitchStatement: switch statements not allowed in actions + switch(hdr.icmp6.type) { + ^^^^^^ +#+END_SRC + *** Implementation limitations **** No fragmentation support (yet) **** No session handling (yet) diff --git a/p4src/static-mapping.p4 b/p4src/static-mapping.p4 index a4d933b..1238306 100644 --- a/p4src/static-mapping.p4 +++ b/p4src/static-mapping.p4 @@ -57,9 +57,11 @@ control MyIngress(inout headers hdr, hdr.icmp.setValid(); hdr.ipv4.protocol = PROTO_ICMP; // overwrite generic same protocol assumption - switch(hdr.icmp6.type) { - ICMP6_ECHO_REQUEST: { hdr.icmp.type = ICMP_ECHO_REQUEST; } - ICMP6_ECHO_REPLY: { hdr.icmp.type = ICMP_ECHO_REPLY; } + if(hdr.icmp6.type == ICMP6_ECHO_REQUEST) { + hdr.icmp.type = ICMP_ECHO_REQUEST; + } + if(hdr.icmp6.type == ICMP6_ECHO_REPLY) { + hdr.icmp.type = ICMP_ECHO_REPLY; } /* trigger checksumming */