|
| 1 | +/* |
| 2 | +Copyright 2026 Deval Gupta |
| 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 | +/* |
| 18 | + * Test for issue #5042: Directionless action parameters should accept |
| 19 | + * non-compile-time-known values when provided by the P4 program. |
| 20 | + * Per P4 Spec Section 6.8, such parameters behave as 'in' direction. |
| 21 | + */ |
| 22 | + |
| 23 | +#include <core.p4> |
| 24 | +#include <v1model.p4> |
| 25 | + |
| 26 | +header h_t { |
| 27 | + bit<8> f; |
| 28 | +} |
| 29 | + |
| 30 | +struct metadata_t { |
| 31 | + bit<8> x; |
| 32 | +} |
| 33 | + |
| 34 | +struct headers_t { |
| 35 | + h_t h; |
| 36 | +} |
| 37 | + |
| 38 | +parser p(packet_in pkt, out headers_t hdr, inout metadata_t meta, |
| 39 | + inout standard_metadata_t std_meta) { |
| 40 | + state start { |
| 41 | + pkt.extract(hdr.h); |
| 42 | + meta.x = hdr.h.f; |
| 43 | + transition accept; |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +control ingress(inout headers_t hdr, inout metadata_t meta, |
| 48 | + inout standard_metadata_t std_meta) { |
| 49 | + // Action with directionless parameter 'data' |
| 50 | + action a(bit<8> data) { |
| 51 | + hdr.h.f = data; |
| 52 | + } |
| 53 | + |
| 54 | + table t { |
| 55 | + key = { hdr.h.f : exact; } |
| 56 | + actions = { a; } |
| 57 | + // meta.x is NOT compile-time known, but per P4 Spec 6.8 |
| 58 | + // directionless params behave as 'in' when provided by program |
| 59 | + default_action = a(meta.x); |
| 60 | + } |
| 61 | + |
| 62 | + apply { |
| 63 | + t.apply(); |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +control egress(inout headers_t hdr, inout metadata_t meta, |
| 68 | + inout standard_metadata_t std_meta) { |
| 69 | + apply { } |
| 70 | +} |
| 71 | + |
| 72 | +control deparser(packet_out pkt, in headers_t hdr) { |
| 73 | + apply { pkt.emit(hdr.h); } |
| 74 | +} |
| 75 | + |
| 76 | +control verifyChecksum(inout headers_t hdr, inout metadata_t meta) { |
| 77 | + apply { } |
| 78 | +} |
| 79 | + |
| 80 | +control computeChecksum(inout headers_t hdr, inout metadata_t meta) { |
| 81 | + apply { } |
| 82 | +} |
| 83 | + |
| 84 | +V1Switch(p(), verifyChecksum(), ingress(), egress(), |
| 85 | + computeChecksum(), deparser()) main; |
0 commit comments