├── p4k ├── test ├── stf_tests │ ├── test_data │ │ ├── counter5.k │ │ ├── counter5.stf │ │ ├── empty.stf │ │ ├── counter1.expected │ │ ├── counter2.expected │ │ ├── counter3.expected │ │ ├── counter4.expected │ │ ├── counter5.expected │ │ ├── README.md │ │ ├── hash_action_basic.expected │ │ ├── hash_action_gateway.expected │ │ ├── repeater.expected │ │ ├── ternary_match3.expected │ │ ├── bridge1.expected │ │ ├── gateway1.expected │ │ ├── gateway2.expected │ │ ├── gateway3.expected │ │ ├── exact_match1.expected │ │ ├── exact_match2.expected │ │ ├── exact_match3.expected │ │ ├── exact_match_mask1.expected │ │ ├── ternary_match3.stf │ │ ├── issue767.p4 │ │ ├── issue780-7.p4 │ │ ├── bigfield1.expected │ │ ├── issue780-1.p4 │ │ ├── issue780-9.p4 │ │ ├── issue780-3.p4 │ │ ├── issue780-5.p4 │ │ ├── tmvalid.expected │ │ ├── exact_match1.stf │ │ ├── exact_match2.stf │ │ ├── exact_match3.stf │ │ ├── exact_match_mask1.stf │ │ ├── instruct6.expected │ │ ├── action_inline1.expected │ │ ├── action_inline2.expected │ │ ├── instruct6.stf │ │ ├── ternary_match1.expected │ │ ├── gateway6.expected │ │ ├── bigfield1.stf │ │ ├── gateway1.stf │ │ ├── action_inline2.stf │ │ ├── bridge1.stf │ │ ├── action_inline1.stf │ │ ├── issue780-8.p4 │ │ ├── ternary_match1.stf │ │ ├── gateway2.stf │ │ ├── tmvalid.stf │ │ ├── gateway6.stf │ │ ├── gateway4.expected │ │ ├── repeater.stf │ │ ├── issue780-2.p4 │ │ ├── issue604.p4 │ │ ├── gateway3.stf │ │ ├── gateway7.expected │ │ ├── 07-MultiProtocol.expected │ │ ├── gateway7.stf │ │ ├── gateway4.stf │ │ ├── gateway5.stf │ │ ├── gateway5.expected │ │ ├── hash_action_two_separate.expected │ │ ├── action_chain1.expected │ │ ├── exact_match_valid1.stf │ │ ├── parser_dc_full.expected │ │ ├── parser_dc_full.stf │ │ ├── hitmiss.expected │ │ ├── basic_conditionals.p4 │ │ ├── issue781.p4 │ │ ├── repeater.p4 │ │ ├── exact_match_valid1.expected │ │ ├── hitmiss.stf │ │ ├── 17-Minimal.p4 │ │ ├── issue638-2.p4 │ │ ├── action_chain1.stf │ │ ├── hash_action_two_separate.stf │ │ ├── 16-NoHeaders.p4 │ │ ├── hash_action_basic.stf │ │ ├── hash_action_gateway.stf │ │ ├── basic_routing.expected │ │ ├── instruct5.stf │ │ ├── exact_match4.stf │ │ ├── exact_match5.stf │ │ ├── 18-EmptyPipelines.p4 │ │ ├── action_inline.p4 │ │ ├── inline.p4 │ │ ├── 01-DeadMetadata1.p4 │ │ ├── exact_match4.expected │ │ ├── exact_match5.expected │ │ ├── 02-DeadMetadata2.p4 │ │ ├── instruct5.expected │ │ ├── parser_dc_full.k │ │ ├── gateway8.stf │ │ ├── ternary_match3.k │ │ ├── ternary_match0.p4 │ │ ├── gateway8.expected │ │ ├── 14-Counter.p4 │ │ ├── instruct3.p4 │ │ ├── issue60.p4 │ │ ├── 03-DeadMetadata3.p4 │ │ ├── 14-GatewayGreaterThan.p4 │ │ ├── do_nothing.p4 │ │ ├── instruct4.p4 │ │ ├── 07-MultiProtocol.stf │ │ ├── bigfield1.p4 │ │ ├── exact_match1.p4 │ │ ├── swap_1.p4 │ │ ├── hash_action_basic.p4 │ │ ├── exact_match_mask1.p4 │ │ ├── truncate.p4 │ │ ├── exact_match2.p4 │ │ ├── exact_match3.p4 │ │ ├── swap_2.p4 │ │ ├── counter4.stf │ │ ├── 01-JustEthernet.p4 │ │ ├── overflow.p4 │ │ ├── ternary_match1.p4 │ │ ├── ternary_match2.p4 │ │ ├── tmvalid.p4 │ │ ├── counter3.stf │ │ ├── exact_match7.p4 │ │ ├── counter1.stf │ │ ├── exact_match6.p4 │ │ ├── 13-Counters1and2.p4 │ │ ├── ternary_match3.p4 │ │ ├── triv_eth.p4 │ │ ├── action_inline1.p4 │ │ ├── instruct6.p4 │ │ ├── counter1.p4 │ │ ├── counter2.p4 │ │ ├── counter2.stf │ │ ├── ternary_match4.p4 │ │ ├── hash_action_gateway.p4 │ │ ├── 12-Counters.p4 │ │ ├── counter4.p4 │ │ ├── instruct2.p4 │ │ ├── exact_match1.k │ │ ├── exact_match2.k │ │ ├── exact_match3.k │ │ ├── exact_match_mask1.k │ │ ├── instruct6.k │ │ ├── counter5.p4 │ │ ├── gateway7.p4 │ │ ├── gateway6.p4 │ │ ├── gateway1.p4 │ │ ├── counter3.p4 │ │ ├── exact_match9.p4 │ │ ├── action_inline2.p4 │ │ ├── bigfield1.k │ │ ├── gateway2.p4 │ │ ├── action_inline2.k │ │ └── exact_match_valid1.p4 │ ├── compile.sh │ ├── p42json.sh │ ├── stf2k.sh │ ├── run.sh │ └── check_output.sh ├── syntax │ ├── unit │ │ ├── header-instance.p4 │ │ ├── metadata-instance.p4 │ │ ├── header-array-instance.p4 │ │ ├── parser-exception.p4 │ │ ├── customer_meters.p4 │ │ ├── field_list.p4 │ │ ├── metadata-init-instance.p4 │ │ ├── ip_pkts_by_dest-counter.p4 │ │ ├── mtag-parser.p4 │ │ ├── field_list_calculation.p4 │ │ ├── vlan_t.p4 │ │ ├── vlan-parser.p4 │ │ ├── tcp-chksum.p4 │ │ ├── route_ipv4-action.p4 │ │ ├── ethernet-parser.p4 │ │ ├── header-test.p4 │ │ ├── common_copy_pkt_to_cpu-action.p4 │ │ ├── mtag_table.p4 │ │ ├── local_metadata_t.p4 │ │ ├── add_mtag-action.p4 │ │ └── control.p4 │ └── debug │ │ └── parantheses.p4 └── semantics │ ├── features │ ├── run.sh │ ├── multi_var_expr │ │ └── mutivar.p4 │ ├── default_action │ │ ├── default_action.p4 │ │ └── default_action.k │ ├── header_actions │ │ ├── pop.p4 │ │ ├── push.p4 │ │ ├── add_header.p4 │ │ ├── copy_header.p4 │ │ ├── remove_header.p4 │ │ ├── add_header.k │ │ ├── copy_header.k │ │ ├── pop.k │ │ ├── push.k │ │ └── remove_header.k │ ├── exception │ │ ├── exception_out_of_packet.p4 │ │ ├── exception_index_out_of_bound.p4 │ │ ├── exception_unhandled_select.p4 │ │ ├── exception_handler.p4 │ │ ├── exception_handler.k │ │ ├── exception_out_of_packet.k │ │ ├── exception_unhandled_select.k │ │ └── exception_index_out_of_bound.k │ ├── array │ │ ├── array_access.p4 │ │ └── array_access.k │ ├── match_types │ │ ├── lpm.p4 │ │ ├── valid.p4 │ │ ├── range.p4 │ │ └── ternary.p4 │ └── field_list │ │ └── checksum.k │ ├── smoke_tests │ ├── test2-input1.k │ └── test1.p4 │ ├── basic_routing │ ├── sym-input1.cli │ └── input1.cli │ └── switch │ └── input1.k ├── verification ├── verification-debug │ ├── p.lang │ ├── old-specs │ │ ├── 0spec.k │ │ ├── 2spec.k │ │ ├── 4spec.k │ │ └── 3spec.k │ ├── balance_spec.k │ └── size_balance_spec.k └── load-balancer │ ├── prove.sh │ ├── load-balancer.p4 │ ├── old-specs │ └── 2spec.k │ └── tables.k ├── coverage └── extractRules.sh ├── tranlation-validation └── simple │ ├── debug │ ├── empty │ ├── skompile.sh │ ├── sskompile.sh │ ├── kompile.sh │ ├── kkompile.sh │ ├── c.k │ ├── run7.sh │ ├── run8.sh │ ├── run.sh │ ├── test-spec.k │ ├── prun10.sh │ ├── prun9.sh │ ├── 4srun.sh │ ├── 4ssrun.sh │ ├── 4ssrun2.sh │ ├── psrun12.sh │ ├── psrun13.sh │ ├── test2-spec.k │ ├── simpler.p4 │ ├── test.k │ ├── simple.p4 │ └── simple_router.p4 │ ├── kompile.sh │ ├── keq.sh │ └── simple.p4 ├── script ├── preproc.sh ├── run.sh ├── parse.sh ├── kompile-syntax.sh ├── add-data.py └── kompile-semantics.sh ├── src ├── p4 │ └── default-target.k └── stf │ └── stf-test.k ├── experiments └── assert-p4 │ └── NetPaxos │ ├── source │ ├── includes │ │ ├── paxos_parser.p4 │ │ ├── paxos_headers.p4 │ │ └── parser.p4 │ └── commands.txt │ ├── ReadMe.md │ └── input.cli └── multithreaded └── race.p4 /p4k: -------------------------------------------------------------------------------- 1 | python3 script/p4k.py $@ -------------------------------------------------------------------------------- /test/stf_tests/test_data/counter5.k: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/counter5.stf: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/empty.stf: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/counter1.expected: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/counter2.expected: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/counter3.expected: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/counter4.expected: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/counter5.expected: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /verification/verification-debug/p.lang: -------------------------------------------------------------------------------- 1 | @start -------------------------------------------------------------------------------- /coverage/extractRules.sh: -------------------------------------------------------------------------------- 1 | grep -e "^rule " -n $@ 2 | -------------------------------------------------------------------------------- /tranlation-validation/simple/debug/empty: -------------------------------------------------------------------------------- 1 | @val(12,12,false) -------------------------------------------------------------------------------- /test/syntax/unit/header-instance.p4: -------------------------------------------------------------------------------- 1 | 2 | header vlan_t inner_vlan_tag; -------------------------------------------------------------------------------- /test/syntax/unit/metadata-instance.p4: -------------------------------------------------------------------------------- 1 | metadata local_metadata_t local_metadata; -------------------------------------------------------------------------------- /script/preproc.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | gcc -E -x c -w $@ | grep -e "^#" -v 3 | -------------------------------------------------------------------------------- /script/run.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | dir=$(dirname $0) 3 | krun -d $dir/../src/ $@ -------------------------------------------------------------------------------- /test/syntax/unit/header-array-instance.p4: -------------------------------------------------------------------------------- 1 | 2 | header vlan_t inner_vlan_tag [ 10 ]; -------------------------------------------------------------------------------- /script/parse.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | dir=$(dirname $0) 3 | kast -d $dir/../src/syntax/ $@ 4 | -------------------------------------------------------------------------------- /test/stf_tests/compile.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | n=${1%.*} 3 | p4c-bm2-ss --p4v 14 $n.p4 -o $n.json 4 | -------------------------------------------------------------------------------- /test/syntax/unit/parser-exception.p4: -------------------------------------------------------------------------------- 1 | parser_exception pe{ 2 | set_metadata(x.y,10); 3 | return x; 4 | } -------------------------------------------------------------------------------- /test/syntax/unit/customer_meters.p4: -------------------------------------------------------------------------------- 1 | meter customer_meters { 2 | type : bytes; 3 | instance_count : 1000; 4 | } -------------------------------------------------------------------------------- /test/syntax/unit/field_list.p4: -------------------------------------------------------------------------------- 1 | field_list fl { 2 | a; 3 | a.b; 4 | 10; 5 | fl2; 6 | payload; 7 | } -------------------------------------------------------------------------------- /test/syntax/unit/metadata-init-instance.p4: -------------------------------------------------------------------------------- 1 | metadata local_metadata_t local_metadata { 2 | a : 10; 3 | b : 20; 4 | } -------------------------------------------------------------------------------- /test/stf_tests/test_data/README.md: -------------------------------------------------------------------------------- 1 | This folder contains programs written in P4 v1.0 that are used to test the P4 compiler. 2 | -------------------------------------------------------------------------------- /test/syntax/unit/ip_pkts_by_dest-counter.p4: -------------------------------------------------------------------------------- 1 | counter ip_pkts_by_dest { 2 | type : packets; 3 | direct : ip_host_table; 4 | } -------------------------------------------------------------------------------- /tranlation-validation/simple/debug/skompile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | rm -r impp-kompiled common-kompiled 3 | kompile impp.k 4 | kompile common.k 5 | -------------------------------------------------------------------------------- /tranlation-validation/simple/debug/sskompile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | rm -r imppp-kompiled common-kompiled 3 | kompile imppp.k 4 | kompile common.k 5 | -------------------------------------------------------------------------------- /verification/load-balancer/prove.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | time krun load-balancer.p4 --smt_prelude list.smt2 --prove size_balance_spec.k --debug -------------------------------------------------------------------------------- /script/kompile-syntax.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | dir=$(dirname $0) 3 | rm -rf $dir/../src/syntax/p4-kompiled/ 4 | kompile $dir/../src/syntax/p4.k 5 | -------------------------------------------------------------------------------- /tranlation-validation/simple/kompile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | kompile --syntax-module P4-SYNTAX p4-semantics.k 3 | kompile impp.k 4 | kompile common.k 5 | -------------------------------------------------------------------------------- /tranlation-validation/simple/debug/kompile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | kompile --syntax-module P4-SYNTAX p4-semantics.k 3 | kompile impp.k 4 | kompile common.k 5 | -------------------------------------------------------------------------------- /tranlation-validation/simple/debug/kkompile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | kompile --syntax-module P4-SYNTAX p4-semantics.k 3 | kompile imppp.k 4 | kompile common.k 5 | -------------------------------------------------------------------------------- /src/p4/default-target.k: -------------------------------------------------------------------------------- 1 | require "p4-semantics.k" 2 | module DEFAULT-TARGET 3 | imports P4-SEMANTICS 4 | 5 | //no target specific rules by default 6 | 7 | endmodule -------------------------------------------------------------------------------- /test/stf_tests/p42json.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | for i in test_data/*.out; do 4 | echo $i; 5 | n=${i%.*}; 6 | p4c-bm2-ss --p4v 14 $n.p4 -o $n.json; 7 | done -------------------------------------------------------------------------------- /tranlation-validation/simple/debug/c.k: -------------------------------------------------------------------------------- 1 | module C 2 | 3 | //========= 4 | syntax Bool ::= vars(List) 5 | //======== 6 | 7 | 8 | 9 | 10 | endmodule -------------------------------------------------------------------------------- /test/stf_tests/test_data/hash_action_basic.expected: -------------------------------------------------------------------------------- 1 | 00010001000100010001000100010001001000100010001000100010001000100000000100000001000000100000001000000011000000110000010000000100 1 -------------------------------------------------------------------------------- /test/stf_tests/test_data/hash_action_gateway.expected: -------------------------------------------------------------------------------- 1 | 00010001000100010001000100010001001000100010001000100010001000100000000100000001000000100000001000000011000000110000010000000100 1 -------------------------------------------------------------------------------- /test/stf_tests/test_data/repeater.expected: -------------------------------------------------------------------------------- 1 | 0000001000000010000000100000001000000010000000100000001000000010 2 2 | 0000010000000100000001000000010000000100000001000000010000000100 1 -------------------------------------------------------------------------------- /test/stf_tests/stf2k.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | for i in test_data/*.json; do 4 | echo $i; 5 | n=${i%.*}; 6 | python stf2k.py $n.json $n.stf $n.k $n.expected; 7 | done 8 | -------------------------------------------------------------------------------- /test/syntax/unit/mtag-parser.p4: -------------------------------------------------------------------------------- 1 | parser mtag { 2 | extract(mtag); 3 | return select(latest.ethertype) { 4 | 0x800: ipv4; 5 | default: ingress; 6 | } 7 | } -------------------------------------------------------------------------------- /test/stf_tests/test_data/ternary_match3.expected: -------------------------------------------------------------------------------- 1 | 00010000000100010001001000010011************************************************************************************************0111111101100110 2 -------------------------------------------------------------------------------- /test/syntax/unit/field_list_calculation.p4: -------------------------------------------------------------------------------- 1 | field_list_calculation flc { 2 | input { 3 | fl1; 4 | fl2; 5 | } 6 | algorithm : xor16; 7 | output_width : 100; 8 | 9 | } -------------------------------------------------------------------------------- /test/syntax/unit/vlan_t.p4: -------------------------------------------------------------------------------- 1 | header_type vlan_t { 2 | fields { 3 | pcp : 3; 4 | cfi : 1; 5 | vid : 12; 6 | ethertype : 16; 7 | } 8 | } -------------------------------------------------------------------------------- /tranlation-validation/simple/debug/run7.sh: -------------------------------------------------------------------------------- 1 | keq -v --debug --def0 common-kompiled --def1 impp-kompiled --def2 impp-kompiled --prove1 7impp2-spec.k --prove2 7impp-spec.k --smt_prelude ../../verification/load-balancer/list.smt2 2 | -------------------------------------------------------------------------------- /tranlation-validation/simple/debug/run8.sh: -------------------------------------------------------------------------------- 1 | keq -v --debug --def0 common-kompiled --def1 impp-kompiled --def2 impp-kompiled --prove1 8impp2-spec.k --prove2 8impp-spec.k --smt_prelude ../../verification/load-balancer/list.smt2 2 | -------------------------------------------------------------------------------- /tranlation-validation/simple/keq.sh: -------------------------------------------------------------------------------- 1 | keq -v --debug --def0 common-kompiled --def1 p4-semantics-kompiled --def2 impp-kompiled --prove1 p4-spec.k --prove2 impp-spec.k --smt_prelude ../../verification/load-balancer/list.smt2 2 | -------------------------------------------------------------------------------- /tranlation-validation/simple/debug/run.sh: -------------------------------------------------------------------------------- 1 | keq -v --debug --def0 common-kompiled --def1 p4-semantics-kompiled --def2 impp-kompiled --prove1 p4-spec.k --prove2 impp-spec.k --smt_prelude ../../verification/load-balancer/list.smt2 2 | -------------------------------------------------------------------------------- /tranlation-validation/simple/debug/test-spec.k: -------------------------------------------------------------------------------- 1 | 2 | module SPEC 3 | imports TEST 4 | 5 | rule V:Val => I:Int 6 | //requires #noUndef(V) 7 | 8 | //rule V:NUVal => I:Int 9 | 10 | endmodule 11 | -------------------------------------------------------------------------------- /tranlation-validation/simple/debug/prun10.sh: -------------------------------------------------------------------------------- 1 | keq -v --debug --def0 common-kompiled --def1 p4-semantics-kompiled --def2 impp-kompiled --prove1 10p4-spec.k --prove2 10impp-spec.k --smt_prelude ../../verification/load-balancer/list.smt2 2 | -------------------------------------------------------------------------------- /tranlation-validation/simple/debug/prun9.sh: -------------------------------------------------------------------------------- 1 | keq -v --debug --def0 common-kompiled --def1 p4-semantics-kompiled --def2 impp-kompiled --prove1 9p4-spec.k --prove2 9impp-spec.k --smt_prelude ../../verification/load-balancer/list.smt2 2 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/bridge1.expected: -------------------------------------------------------------------------------- 1 | 00000001000000010000000100000001************************************************0111111101100110 2 2 | 00000010000000100000001000000010************************************************0000011101100110 3 -------------------------------------------------------------------------------- /test/stf_tests/test_data/gateway1.expected: -------------------------------------------------------------------------------- 1 | 00000001000000010000000100000001********************************00000001000000010111011110001000 2 2 | 000000010000000100000001000000010000000100000001000000010000000100000010011001100111011110001000 3 -------------------------------------------------------------------------------- /test/stf_tests/test_data/gateway2.expected: -------------------------------------------------------------------------------- 1 | 00000001000000010000000100000001********************************00000001011101110111011100001010 2 2 | 000000010000000100000001000000010000000100000001000000010000000100000010011001100111011110001000 3 -------------------------------------------------------------------------------- /test/stf_tests/test_data/gateway3.expected: -------------------------------------------------------------------------------- 1 | 00000001000000010000000100000001********************************00000001011101111000100000001010 2 2 | 000000010000000100000001000000010000000100000001000000010000000100000010011001100111011110001000 3 -------------------------------------------------------------------------------- /test/syntax/unit/vlan-parser.p4: -------------------------------------------------------------------------------- 1 | parser vlan { 2 | extract(vlan); 3 | return select(latest.ethertype) { 4 | 0xaaaa: mtag; 5 | 0x800: ipv4; 6 | default: ingress; 7 | } 8 | } 9 | 10 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/exact_match1.expected: -------------------------------------------------------------------------------- 1 | 00000001000000010000000100000001************************************************0111111101100110 2 2 | 00000010000000100000001000000010************************************************0000011101100110 3 -------------------------------------------------------------------------------- /test/stf_tests/test_data/exact_match2.expected: -------------------------------------------------------------------------------- 1 | 00000001000000010000000100000001************************************************0111111101100110 2 2 | 00000010000000100000001000000010************************************************0000011101100110 3 -------------------------------------------------------------------------------- /test/stf_tests/test_data/exact_match3.expected: -------------------------------------------------------------------------------- 1 | 00000001000000010000000100000001************************************************0111111101100110 2 2 | 00000010000000100000001000000010************************************************0000011101100110 3 -------------------------------------------------------------------------------- /test/stf_tests/test_data/exact_match_mask1.expected: -------------------------------------------------------------------------------- 1 | 00000001000000010000000100000001************************************************0111111101100110 2 2 | 00000010000000100000001000000010************************************************0000011101100110 3 -------------------------------------------------------------------------------- /tranlation-validation/simple/debug/4srun.sh: -------------------------------------------------------------------------------- 1 | keq -v --debug --def0 common-kompiled --def1 impp-kompiled --def2 impp-kompiled --prove1 impp2-4syncpoints-spec.k --prove2 impp-4syncpoints-spec.k --smt_prelude ../../verification/load-balancer/list.smt2 2 | -------------------------------------------------------------------------------- /test/syntax/unit/tcp-chksum.p4: -------------------------------------------------------------------------------- 1 | calculated_field tcp.chksum { 2 | update tcpv4_calc if (valid(ipv4)); 3 | update tcpv6_calc if (valid(ipv6)); 4 | verify tcpv4_calc if (valid(ipv4)); 5 | verify tcpv6_calc if (valid(ipv6)); 6 | } -------------------------------------------------------------------------------- /tranlation-validation/simple/debug/4ssrun.sh: -------------------------------------------------------------------------------- 1 | keq -v --debug --def0 common-kompiled --def1 imppp-kompiled --def2 imppp-kompiled --prove1 imppp2-4syncpoints-spec.k --prove2 imppp-4syncpoints-spec.k --smt_prelude ../../verification/load-balancer/list.smt2 2 | -------------------------------------------------------------------------------- /test/syntax/unit/route_ipv4-action.p4: -------------------------------------------------------------------------------- 1 | action route_ipv4(dst_mac, src_mac, vid) { 2 | modify_field(ethernet.dst_addr, dst_mac); 3 | modify_field(ethernet.src_addr, src_mac); 4 | modify_field(vlan_tag.vid, vid); 5 | add_to_field(ipv4.ttl, -1); 6 | } -------------------------------------------------------------------------------- /tranlation-validation/simple/debug/4ssrun2.sh: -------------------------------------------------------------------------------- 1 | keq -v --debug --def0 common-kompiled --def1 imppp-kompiled --def2 imppp-kompiled --prove1 2imppp2-4syncpoints-spec.k --prove2 2imppp-4syncpoints-spec.k --smt_prelude ../../verification/load-balancer/list.smt2 2 | -------------------------------------------------------------------------------- /tranlation-validation/simple/debug/psrun12.sh: -------------------------------------------------------------------------------- 1 | keq -v --debug --def0 common-kompiled --def1 p4-semantics-kompiled --def2 imppp-kompiled --prove1 12p4-4syncpoints-spec.k --prove2 12imppp-4syncpoints-spec.k --smt_prelude ../../verification/load-balancer/list.smt2 2 | -------------------------------------------------------------------------------- /tranlation-validation/simple/debug/psrun13.sh: -------------------------------------------------------------------------------- 1 | keq -v --debug --def0 common-kompiled --def1 p4-semantics-kompiled --def2 imppp-kompiled --prove1 13p4-5syncpoints-spec.k --prove2 13imppp-5syncpoints-spec.k --smt_prelude ../../verification/load-balancer/list.smt2 2 | -------------------------------------------------------------------------------- /experiments/assert-p4/NetPaxos/source/includes/paxos_parser.p4: -------------------------------------------------------------------------------- 1 | #ifndef _PAXOS_PARSER_P4_ 2 | #define _PAXOS_PARSER_P4_ 3 | 4 | // Parser for paxos packet headers 5 | 6 | parser parse_paxos { 7 | extract(paxos); 8 | return ingress; 9 | } 10 | 11 | #endif -------------------------------------------------------------------------------- /test/syntax/unit/ethernet-parser.p4: -------------------------------------------------------------------------------- 1 | parser ethernet { 2 | extract(ethernet); // Start with the ethernet header 3 | return select(latest.ethertype) { 4 | 0x8100: vlan; 5 | 0x800: ipv4; 6 | default: ingress; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /test/syntax/unit/header-test.p4: -------------------------------------------------------------------------------- 1 | header_type hdr_t { 2 | fields { 3 | a : *; 4 | b : 4 (signed); 5 | d : 10 (saturating); 6 | e : 20 (signed,saturating); 7 | } 8 | length : 10 + b; 9 | max_length : 100; 10 | } -------------------------------------------------------------------------------- /test/stf_tests/test_data/ternary_match3.stf: -------------------------------------------------------------------------------- 1 | 2 | add test1 0 data.f1:0x10111213 data.f2:0x20212223 data.f3:0x30313233 data.f4:0x40414243 setb1(val:0x7f, port:2) 3 | 4 | expect 2 10111213 ******** ******** ******** 7f 66 5 | packet 0 10111213 20212223 30313233 40414243 55 66 77 88 6 | -------------------------------------------------------------------------------- /test/stf_tests/run.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | dir=$(dirname $0) 4 | root="../.." 5 | 6 | for i in $dir/test_data/*.k; do 7 | echo $i; 8 | n=${i%.*}; 9 | time $root/script/kompile-semantics.sh $n.k --debug && time $root/script/run.sh $n.p4 --debug > $n.out; 10 | done -------------------------------------------------------------------------------- /test/stf_tests/test_data/issue767.p4: -------------------------------------------------------------------------------- 1 | parser start { 2 | return ingress; 3 | } 4 | 5 | action nop() { } 6 | 7 | table exact { 8 | reads { standard_metadata.egress_port: exact; } 9 | actions { nop; } 10 | } 11 | 12 | control ingress { 13 | apply(exact); 14 | } 15 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/issue780-7.p4: -------------------------------------------------------------------------------- 1 | header_type exact { 2 | fields { 3 | counterrevolution : 32; 4 | } 5 | } 6 | header exact heartlands; 7 | parser start { 8 | return ingress; 9 | } 10 | action add_heartlands() { 11 | add_header(heartlands); 12 | } 13 | control ingress { } 14 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/bigfield1.expected: -------------------------------------------------------------------------------- 1 | 00000001000000010000000100000001********************************010100010100000100110001001000010001000100000001********01100110 2 2 | 00000010000000100000001000000010********************************000000000000000000000000000000000000000000000000********01100110 3 -------------------------------------------------------------------------------- /test/stf_tests/test_data/issue780-1.p4: -------------------------------------------------------------------------------- 1 | header_type headers { 2 | fields { 3 | counterrevolution : 32; 4 | } 5 | } 6 | header headers heartlands; 7 | parser start { 8 | return ingress; 9 | } 10 | action add_heartlands() { 11 | add_header(heartlands); 12 | } 13 | control ingress { } 14 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/issue780-9.p4: -------------------------------------------------------------------------------- 1 | header_type exact { 2 | fields { 3 | counterrevolution : 32; 4 | } 5 | } 6 | header exact heartlands; 7 | parser start { 8 | return ingress1; 9 | } 10 | action add_heartlands() { 11 | add_header(heartlands); 12 | } 13 | control ingress1 { } 14 | -------------------------------------------------------------------------------- /test/semantics/features/run.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | dir=$(dirname $0) 4 | root="../../.." 5 | 6 | for i in $(find $dir -name "*.k"); do 7 | echo $i; 8 | n=${i%.*}; 9 | time $root/script/kompile-semantics.sh $n.k --debug && time $root/script/run.sh $n.p4 --debug > $n.out; 10 | done -------------------------------------------------------------------------------- /test/stf_tests/test_data/issue780-3.p4: -------------------------------------------------------------------------------- 1 | header_type metadata { 2 | fields { 3 | counterrevolution : 32; 4 | } 5 | } 6 | header metadata heartlands; 7 | parser start { 8 | return ingress; 9 | } 10 | action add_heartlands() { 11 | add_header(heartlands); 12 | } 13 | control ingress { } 14 | -------------------------------------------------------------------------------- /test/syntax/debug/parantheses.p4: -------------------------------------------------------------------------------- 1 | header_type ht { 2 | fields { 3 | f : 8; 4 | } 5 | } 6 | 7 | header ht h; 8 | 9 | parser start{ 10 | extract(h); 11 | return ingress; 12 | } 13 | 14 | control ingress { 15 | 16 | if ((h.f != 0) and (h.f != 1)){ 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /test/syntax/unit/common_copy_pkt_to_cpu-action.p4: -------------------------------------------------------------------------------- 1 | // Copy the packet to the CPU; 2 | action common_copy_pkt_to_cpu(cpu_code, bad_packet) { 3 | modify_field(local_metadata.copy_to_cpu, 1); 4 | modify_field(local_metadata.cpu_code, cpu_code); 5 | modify_field(local_metadata.bad_packet, bad_packet); 6 | } -------------------------------------------------------------------------------- /test/semantics/features/multi_var_expr/mutivar.p4: -------------------------------------------------------------------------------- 1 | parser start { 2 | return ingress; 3 | } 4 | 5 | action testA() { 6 | 7 | } 8 | 9 | table test { 10 | actions { 11 | testA; 12 | } 13 | } 14 | 15 | control ingress { 16 | if (1 + 1 > 2) { 17 | apply(test); 18 | } 19 | } -------------------------------------------------------------------------------- /test/stf_tests/test_data/issue780-5.p4: -------------------------------------------------------------------------------- 1 | header_type computeChecksum { 2 | fields { 3 | counterrevolution : 32; 4 | } 5 | } 6 | header computeChecksum heartlands; 7 | parser start { 8 | return ingress; 9 | } 10 | action add_heartlands() { 11 | add_header(heartlands); 12 | } 13 | control ingress { } 14 | -------------------------------------------------------------------------------- /tranlation-validation/simple/debug/test2-spec.k: -------------------------------------------------------------------------------- 1 | 2 | module SPEC 3 | imports TEST 4 | 5 | 6 | rule V:Val 7 | //requires #noUndef(V) 8 | ensures vars(ListItem(V) ListItem(0)) 9 | 10 | 11 | rule I:Int 12 | ensures vars(ListItem(I) ListItem(0)) 13 | [trusted] 14 | 15 | endmodule 16 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/tmvalid.expected: -------------------------------------------------------------------------------- 1 | 00000000000000000000000100000001************************************************************************************************0111111101100110 2 2 | 00000000000000000000001000000010************************************************************************************************0000011101100110 3 -------------------------------------------------------------------------------- /test/stf_tests/test_data/exact_match1.stf: -------------------------------------------------------------------------------- 1 | 2 | add test1 data.f1:0x01010101 setb1(val:0x7f, port:2) 3 | add test1 data.f1:0x02020202 setb1(val:7, port:3) 4 | 5 | expect 2 01010101 ******** **** 7f 66 6 | packet 0 01010101 00000202 0303 55 66 77 88 7 | expect 3 02020202 ******** **** 07 66 8 | packet 2 02020202 00000303 0404 55 66 77 88 9 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/exact_match2.stf: -------------------------------------------------------------------------------- 1 | 2 | add test1 data.f1:0x01010101 setb1(val:0x7f, port:2) 3 | add test1 data.f1:0x02020202 setb1(val:7, port:3) 4 | 5 | expect 2 01010101 ******** **** 7f 66 6 | packet 0 01010101 00000202 0303 55 66 77 88 7 | expect 3 02020202 ******** **** 07 66 8 | packet 2 02020202 00000303 0404 55 66 77 88 9 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/exact_match3.stf: -------------------------------------------------------------------------------- 1 | 2 | add test1 data.f1:0x01010101 setb1(val:0x7f, port:2) 3 | add test1 data.f1:0x02020202 setb1(val:7, port:3) 4 | 5 | expect 2 01010101 ******** **** 7f 66 6 | packet 0 01010101 00000202 0303 55 66 77 88 7 | expect 3 02020202 ******** **** 07 66 8 | packet 2 02020202 00000303 0404 55 66 77 88 9 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/exact_match_mask1.stf: -------------------------------------------------------------------------------- 1 | 2 | add test1 data.f1:0x010001 setb1(val:0x7f, port:2) 3 | add test1 data.f1:0x020002 setb1(val:7, port:3) 4 | 5 | expect 2 01010101 ******** **** 7f 66 6 | packet 0 01010101 00000202 0303 55 66 77 88 7 | expect 3 02020202 ******** **** 07 66 8 | packet 2 02020202 00000303 0404 55 66 77 88 9 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/instruct6.expected: -------------------------------------------------------------------------------- 1 | 000000010000000100000001000000010000001000000010000000100000001000010001001100110011001101000100010101010110011001110111100010001001100110101010 2 2 | 000000100000001000000010000000100000000100000001000000010000000100010001001100100011001101000100010101010110011001110111100010001001100110101010 3 -------------------------------------------------------------------------------- /test/stf_tests/test_data/action_inline1.expected: -------------------------------------------------------------------------------- 1 | 00000000000000000000000100000001************************************************************************************************0111111101100110 2 2 | 00000000000000000000001000000010************************************************************************************************0000011101100110 3 -------------------------------------------------------------------------------- /test/stf_tests/test_data/action_inline2.expected: -------------------------------------------------------------------------------- 1 | 00000000000000000000000100000001************************************************************************************************0110011001100110 2 2 | 00000000000000000000001000000010************************************************************************************************0110011001100110 3 -------------------------------------------------------------------------------- /test/stf_tests/test_data/instruct6.stf: -------------------------------------------------------------------------------- 1 | add test1 f1:0x01010101 op1(port:2) 2 | add test1 f1:0x02020202 op2(port:3) 3 | 4 | expect 2 01010101 02020202 1133 3344 55 66 778899aa 5 | packet 0 01010101 02020202 1122 3344 55 66 778899aa 6 | expect 3 02020202 01010101 1132 3344 55 66 778899aa 7 | packet 0 02020202 01010101 1122 3344 55 66 778899aa 8 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/ternary_match1.expected: -------------------------------------------------------------------------------- 1 | 00000000000000000000000100000001************************************************************************************************0111111101100110 2 2 | 00000000000000000000001000000010************************************************************************************************0000011101100110 3 -------------------------------------------------------------------------------- /experiments/assert-p4/NetPaxos/source/commands.txt: -------------------------------------------------------------------------------- 1 | table_set_default round_tbl read_round 2 | table_set_default drop_tbl _nop 3 | table_add drop_tbl _drop 1 => 4 | table_add forward_tbl forward 1 => 2 5 | table_add forward_tbl forward 2 => 1 6 | table_set_default acceptor_tbl _drop 7 | table_add acceptor_tbl handle_1a 0 => 2 8 | table_add acceptor_tbl handle_2a 2 => 2 -------------------------------------------------------------------------------- /test/stf_tests/test_data/gateway6.expected: -------------------------------------------------------------------------------- 1 | 00010010001101000101011001111000000100100011010001010110011110000000000000000001000000000000000011110001 2 2 | 00010010001101000101011001111000000100100011010001010110011110000000000000000010000000000000000011110010 3 3 | 00010010001101000101011001111000000100100011010001010110011110000000000011110001000000000000000011110011 2 -------------------------------------------------------------------------------- /test/stf_tests/test_data/bigfield1.stf: -------------------------------------------------------------------------------- 1 | 2 | add test1 data.f1:0x01010101 setx1(val:0x514131211101, port:2) 3 | add test1 data.f1:0x02020202 setx1(val:0, port:3) 4 | 5 | expect 2 01010101 ******** 514131211101 ** 66 6 | packet 0 01010101 00000202 030303030303 55 66 77 88 7 | expect 3 02020202 ******** 000000000000 ** 66 8 | packet 2 02020202 00000303 040404040404 55 66 77 88 9 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/gateway1.stf: -------------------------------------------------------------------------------- 1 | 2 | add test1 data.f1:0x01010101 setb1(val:1, port:2) 3 | add test2 data.f2:0x01010101 setb1(val:2, port:3) 4 | 5 | expect 2 01010101 ******** 01 01 77 88 6 | packet 0 01010101 00000202 55 01 77 88 7 | packet 0 01010101 00000202 55 66 99 aa 8 | expect 3 01010101 01010101 02 66 77 88 9 | packet 0 01010101 01010101 55 66 77 88 10 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/action_inline2.stf: -------------------------------------------------------------------------------- 1 | 2 | add test1 0 data.f1:0x****0101 setb1(port:2) 3 | add test1 503 data.f1:0x****0202 setb1(port:3) 4 | 5 | expect 2 00000101 ******** ******** ******** 66 66 6 | packet 0 00000101 00000202 00000303 00000404 55 66 77 88 7 | expect 3 00000202 ******** ******** ******** 66 66 8 | packet 2 00000202 00000303 00000404 00000404 55 66 77 88 9 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/bridge1.stf: -------------------------------------------------------------------------------- 1 | # //Ali 2 | setdefault output copyb1() 3 | # 4 | 5 | add test1 data.f1:0x01010101 setb1(val:0x7f, port:2) 6 | add test1 data.f1:0x02020202 setb1(val:7, port:3) 7 | 8 | expect 2 01010101 ******** **** 7f 66 9 | packet 0 01010101 00000202 0303 55 66 77 88 10 | expect 3 02020202 ******** **** 07 66 11 | packet 2 02020202 00000303 0404 55 66 77 88 12 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/action_inline1.stf: -------------------------------------------------------------------------------- 1 | 2 | add test1 0 data.f1:0x****0101 setb1(val:0x7f, port:2) 3 | add test1 503 data.f1:0x****0202 setb1(val:7, port:3) 4 | 5 | expect 2 00000101 ******** ******** ******** 7f 66 6 | packet 0 00000101 00000202 00000303 00000404 55 66 77 88 7 | expect 3 00000202 ******** ******** ******** 07 66 8 | packet 2 00000202 00000303 00000404 00000404 55 66 77 88 9 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/issue780-8.p4: -------------------------------------------------------------------------------- 1 | header_type h_t { 2 | fields { f : 8; } 3 | } 4 | 5 | header h_t h; 6 | 7 | parser start { 8 | extract(h); 9 | return ingress; 10 | } 11 | 12 | action nop() { } 13 | 14 | table exact { 15 | reads { h.f : ternary; } 16 | actions { nop; } 17 | size : 256; 18 | } 19 | 20 | control ingress { 21 | apply(exact); 22 | } 23 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/ternary_match1.stf: -------------------------------------------------------------------------------- 1 | 2 | add test1 0 data.f1:0x****0101 setb1(val:0x7f, port:2) 3 | add test1 503 data.f1:0x****0202 setb1(val:7, port:3) 4 | 5 | expect 2 00000101 ******** ******** ******** 7f 66 6 | packet 0 00000101 00000202 00000303 00000404 55 66 77 88 7 | expect 3 00000202 ******** ******** ******** 07 66 8 | packet 2 00000202 00000303 00000404 00000404 55 66 77 88 9 | -------------------------------------------------------------------------------- /script/add-data.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import sys 4 | import os 5 | dir=os.path.dirname(sys.argv[0]) 6 | if len(sys.argv) < 2: 7 | data="//no input" 8 | else: 9 | data=open(sys.argv[1],'r').read() 10 | config=open(dir+'/../src/initialization-t.k','r').read() 11 | config = config.replace("#include_data",data) 12 | open(dir+'/../src/initialization.k','w').write(config) 13 | 14 | 15 | -------------------------------------------------------------------------------- /test/stf_tests/check_output.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | c=0; 4 | p=0; 5 | f=() 6 | for i in test_data/*.out; do 7 | c=$((c+1)); 8 | echo $i; 9 | n=${i%.*}; 10 | python check_output.py $n.out $n.expected; 11 | if [ $? -eq 0 ]; then 12 | p=$((p+1)); 13 | else 14 | f+=($n); 15 | fi; 16 | done 17 | 18 | echo "PASSED: $p / $c"; 19 | echo "FAILED: ${f[@]}"; -------------------------------------------------------------------------------- /experiments/assert-p4/NetPaxos/ReadMe.md: -------------------------------------------------------------------------------- 1 | Taken from https://github.com/usi-systems/p4xos-public/tree/26b48e0721fee7b3cddfa5c3335936b4f5c86ec7 2 | 3 | 4 | Changes: 5 | - Commented out checksum calculation (did not necessarily need to) 6 | - Replaced `paxos.inst` in `register_read` and `register_write` to 0, since register index need to be a `VAL` according to the language specification. 7 | - Added the assertion -------------------------------------------------------------------------------- /test/stf_tests/test_data/gateway2.stf: -------------------------------------------------------------------------------- 1 | 2 | add test1 data.f1:0x01010101 setb1(val:1, port:2) 3 | add test2 data.f2:0x01010101 setb1(val:2, port:3) 4 | 5 | expect 2 01010101 ******** 01 77 77 0a 6 | packet 0 01010101 00000202 55 77 77 0a 7 | packet 0 01010101 00000202 55 66 99 0a 8 | packet 0 01010101 00000202 55 66 66 99 9 | expect 3 01010101 01010101 02 66 77 88 10 | packet 0 01010101 01010101 55 66 77 88 11 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/tmvalid.stf: -------------------------------------------------------------------------------- 1 | 2 | add test1 0 data.$valid:0b1 data.f1:0x****0101 setb1(val:0x7f, port:2) 3 | add test1 503 data.$valid:0b1 data.f1:0x****0202 setb1(val:7, port:3) 4 | 5 | expect 2 00000101 ******** ******** ******** 7f 66 6 | packet 0 00000101 00000202 00000303 00000404 55 66 77 88 7 | expect 3 00000202 ******** ******** ******** 07 66 8 | packet 2 00000202 00000303 00000404 00000404 55 66 77 88 9 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/gateway6.stf: -------------------------------------------------------------------------------- 1 | add test1 data.f1:0x12345678 output(port:2) 2 | add test2 data.f2:0x12345678 output(port:3) 3 | 4 | expect 2 12345678 12345678 00 01 00 00 f1 5 | packet 0 12345678 12345678 00 01 00 00 f1 6 | expect 3 12345678 12345678 00 02 00 00 f2 7 | packet 0 12345678 12345678 00 02 00 00 f2 8 | expect 2 12345678 12345678 00 f1 00 00 f3 9 | packet 0 12345678 12345678 00 f1 00 00 f3 10 | 11 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/gateway4.expected: -------------------------------------------------------------------------------- 1 | 00000001000000010000000100000001********************************0000001101100110011101111001100100010001001000100011001101000100 2 2 | 00000001000000010000000100000001000000010000000100000001000000010000001001100110011101111000100000010001001000100011001101000100 3 3 | 00000000000000000000000100000001000000010000000100000001000000010000001001100110011101111001100100010001001000100011001101000100 3 -------------------------------------------------------------------------------- /test/stf_tests/test_data/repeater.stf: -------------------------------------------------------------------------------- 1 | add repeater ingress_port:0 my_drop() 2 | add repeater ingress_port:1 set_egress_port(egress_port:2) 3 | add repeater ingress_port:2 my_drop() 4 | add repeater ingress_port:3 set_egress_port(egress_port:1) 5 | 6 | expect 2 02020202 02020202 7 | expect 1 04040404 04040404 8 | packet 0 01010101 01010101 9 | packet 1 02020202 02020202 10 | packet 2 03030303 03030303 11 | packet 3 04040404 04040404 12 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/issue780-2.p4: -------------------------------------------------------------------------------- 1 | header_type main { 2 | fields { 3 | x : 32; 4 | } 5 | } 6 | 7 | header_type packet { 8 | fields { 9 | y: 32; 10 | } 11 | } 12 | 13 | header main heartlands; 14 | header packet z; 15 | 16 | parser start { 17 | return ingress; 18 | } 19 | 20 | action add_heartlands() { 21 | add_header(heartlands); 22 | add_header(z); 23 | } 24 | 25 | control ingress { } 26 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/issue604.p4: -------------------------------------------------------------------------------- 1 | parser start { return ingress; } 2 | extern_type extern_test { 3 | attribute att_test { 4 | type: int; 5 | } 6 | method my_extern_method (); 7 | } 8 | extern extern_test my_extern_inst { 9 | att_test: 0xab; 10 | } 11 | action a() { my_extern_inst.my_extern_method(); } 12 | table t { 13 | actions { a; } 14 | } 15 | control ingress { 16 | apply(t); 17 | } 18 | control egress {} 19 | -------------------------------------------------------------------------------- /test/syntax/unit/mtag_table.p4: -------------------------------------------------------------------------------- 1 | // Check if the packet needs an mtag and add one if it does. 2 | table mTag_table { 3 | reads { 4 | ethernet.dst_addr : exact; 5 | vlan.vid : exact; 6 | } 7 | actions { 8 | add_mTag; // Action called if pkt needs an mtag. 9 | common_copy_pkt_to_cpu; // If no mtag, send to the CPU 10 | no_op; 11 | } 12 | max_size : 20000; 13 | } -------------------------------------------------------------------------------- /test/stf_tests/test_data/gateway3.stf: -------------------------------------------------------------------------------- 1 | 2 | add test1 data.f1:0x01010101 setb1(val:1, port:2) 3 | add test2 data.f2:0x01010101 setb1(val:2, port:3) 4 | 5 | expect 2 01010101 ******** 01 77 88 0a 6 | packet 0 01010101 00000202 77 77 88 0a 7 | packet 0 01010101 00000202 55 66 99 aa 8 | expect 3 01010101 01010101 02 66 77 88 9 | packet 0 01010101 01010101 55 66 77 88 10 | packet 0 01010101 01010101 55 77 77 88 11 | packet 0 01010101 01010101 55 66 77 0a 12 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/gateway7.expected: -------------------------------------------------------------------------------- 1 | 00010010001101000101011001111000000100100011010001010110011110000000000000110010000000000000000011110001 2 2 | 00010010001101000101011001111000000100100011010001010110011110000000000000110001000000000000000011110010 3 3 | 00010010001101000101011001111000000100100011010001010110011110000000000011110001000000000000000011110011 2 4 | 00010010001101000101011001111000000100100011010001010110011110000000000000000011000000000000000011110100 3 -------------------------------------------------------------------------------- /test/semantics/features/default_action/default_action.p4: -------------------------------------------------------------------------------- 1 | header_type ht { 2 | fields { 3 | f1 : 4; 4 | f2 : 4; 5 | } 6 | } 7 | 8 | 9 | header ht h; 10 | 11 | parser start{ 12 | extract(h); 13 | return ingress; 14 | } 15 | 16 | action a(v) { 17 | modify_field(h.f2, v); 18 | } 19 | 20 | table t { 21 | reads { 22 | h.f1 : exact; 23 | } 24 | actions { 25 | a; 26 | } 27 | } 28 | 29 | control ingress{ 30 | apply(t); 31 | } -------------------------------------------------------------------------------- /test/stf_tests/test_data/07-MultiProtocol.expected: -------------------------------------------------------------------------------- 1 | 10101010101010101010101010101010101010101010101010111011101110111011101110111011101110111011101100001000000000000100010100000000000000000010110000000000000000000000000001100101010000000001000101101100010101010000000100000010000000110000010000001010000000000000000000000010000000000110010000000000011001010000000000010000000000000000000000000000000000010000001000000011000001000000010100000110000001110000100000001001000010100000101100001100000011010000111000001111 3 -------------------------------------------------------------------------------- /test/syntax/unit/local_metadata_t.p4: -------------------------------------------------------------------------------- 1 | header_type local_metadata_t { 2 | fields { 3 | cpu_code : 16; // Code for packet going to CPU 4 | port_type : 4; // Type of port: up, down, local... 5 | ingress_error : 1; // An error in ingress port check 6 | was_mtagged : 1; // Track if pkt was mtagged on ingr 7 | copy_to_cpu : 1; // Special code resulting in copy to CPU 8 | bad_packet : 1; // Other error indication 9 | } 10 | } -------------------------------------------------------------------------------- /test/semantics/features/header_actions/pop.p4: -------------------------------------------------------------------------------- 1 | header_type ht { 2 | fields { 3 | f1 : 4; 4 | f2 : 4; 5 | } 6 | } 7 | 8 | 9 | 10 | header ht a[6]; 11 | 12 | parser start{ 13 | extract(a[0]); 14 | extract(a[3]); 15 | return ingress; 16 | } 17 | 18 | action a() { 19 | pop(a,2); 20 | } 21 | 22 | table t { 23 | reads { 24 | a[0].f1 : exact; 25 | } 26 | actions { 27 | a; 28 | } 29 | } 30 | 31 | control ingress{ 32 | apply(t); 33 | } -------------------------------------------------------------------------------- /test/semantics/features/header_actions/push.p4: -------------------------------------------------------------------------------- 1 | header_type ht { 2 | fields { 3 | f1 : 4; 4 | f2 : 4; 5 | } 6 | } 7 | 8 | 9 | 10 | header ht a[6]; 11 | 12 | parser start{ 13 | extract(a[0]); 14 | extract(a[3]); 15 | return ingress; 16 | } 17 | 18 | action a() { 19 | push(a,2); 20 | } 21 | 22 | table t { 23 | reads { 24 | a[0].f1 : exact; 25 | } 26 | actions { 27 | a; 28 | } 29 | } 30 | 31 | control ingress{ 32 | apply(t); 33 | } -------------------------------------------------------------------------------- /verification/verification-debug/old-specs/0spec.k: -------------------------------------------------------------------------------- 1 | 2 | 3 | module SPEC 4 | imports LANG 5 | 6 | rule 7 | 8 | @nextPacket => @nextPacket 9 | 0 10 | 1 => 0 11 | .List => _ 12 | .List => _ 13 | $consPacketList($packet(P:List,_:Int) , Lin:PacketList) => Lin 14 | Lout:PacketList => $consPacketList($packet(P,0) , Lout) 15 | 16 | 17 | 18 | 19 | 20 | endmodule 21 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/gateway7.stf: -------------------------------------------------------------------------------- 1 | 2 | add test1 data.f1:0x12345678 output(port:2) 3 | add test2 data.f2:0x12345678 output(port:3) 4 | 5 | expect 2 12345678 12345678 00 32 00 00 f1 6 | packet 0 12345678 12345678 00 32 00 00 f1 7 | expect 3 12345678 12345678 00 31 00 00 f2 8 | packet 0 12345678 12345678 00 31 00 00 f2 9 | expect 2 12345678 12345678 00 f1 00 00 f3 10 | packet 0 12345678 12345678 00 f1 00 00 f3 11 | expect 3 12345678 12345678 00 03 00 00 f4 12 | packet 0 12345678 12345678 00 03 00 00 f4 13 | 14 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/gateway4.stf: -------------------------------------------------------------------------------- 1 | 2 | add test1 data.f1:0x01010101 setb1(val:3, port:2) 3 | add test2 data.f2:0x01010101 setb1(val:2, port:3) 4 | 5 | expect 2 01010101 ******** 03 66 77 99 11 22 33 44 6 | packet 0 01010101 00000202 01 66 77 99 11 22 33 44 7 | packet 0 01010101 00000202 55 66 99 99 11 22 33 44 8 | expect 3 01010101 01010101 02 66 77 88 11 22 33 44 9 | packet 0 01010101 01010101 55 66 77 88 11 22 33 44 10 | expect 3 00000101 01010101 02 66 77 99 11 22 33 44 11 | packet 0 00000101 01010101 01 66 77 99 11 22 33 44 12 | -------------------------------------------------------------------------------- /test/semantics/features/header_actions/add_header.p4: -------------------------------------------------------------------------------- 1 | header_type ht { 2 | fields { 3 | f1 : 4; 4 | f2 : 4; 5 | } 6 | } 7 | 8 | 9 | header ht h1; 10 | header ht h2; 11 | header ht a[2]; 12 | 13 | parser start{ 14 | extract(h1); 15 | return ingress; 16 | } 17 | 18 | action a() { 19 | add_header(h2); 20 | add_header(a[1]); 21 | } 22 | 23 | table t { 24 | reads { 25 | h1.f1 : exact; 26 | } 27 | actions { 28 | a; 29 | } 30 | } 31 | 32 | control ingress{ 33 | apply(t); 34 | } -------------------------------------------------------------------------------- /test/stf_tests/test_data/gateway5.stf: -------------------------------------------------------------------------------- 1 | add test1 data.f1:0x12345678 output(port:2) 2 | add test2 data.f2:0x12345678 output(port:3) 3 | 4 | expect 2 12345678 12345678 0200 00000000 00 f1 5 | packet 0 12345678 12345678 0200 00000000 00 f1 6 | expect 3 12345678 12345678 0200 00000000 80 f2 7 | packet 0 12345678 12345678 0200 00000000 80 f2 8 | expect 3 12345678 12345678 0600 00000000 80 f3 9 | packet 0 12345678 12345678 0600 00000000 80 f3 10 | expect 3 12345678 12345678 0600 00000000 00 f4 11 | packet 0 12345678 12345678 0600 00000000 00 f4 12 | 13 | -------------------------------------------------------------------------------- /script/kompile-semantics.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | dir=$(dirname $0); 4 | 5 | if [ $# -lt 1 ]; then 6 | echo "usage: kompile-semantics.sh [ | --no-input] [kompile arguments]" 7 | exit 1 8 | fi 9 | DATA=$1 10 | shift 11 | if [ $DATA = "--no-input" ]; then 12 | DATA="" 13 | else 14 | if [ ! -e $DATA ]; then 15 | echo "$DATA does not exist" 16 | exit 1 17 | fi 18 | fi 19 | python $dir/add-data.py $DATA 20 | kompile $dir/../src/p4-semantics.k --debug --syntax-module P4-SYNTAX --main-module P4-SEMANTICS $@ 21 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/gateway5.expected: -------------------------------------------------------------------------------- 1 | 00010010001101000101011001111000000100100011010001010110011110000000001000000000000000000000000000000000000000000000000011110001 2 2 | 00010010001101000101011001111000000100100011010001010110011110000000001000000000000000000000000000000000000000001000000011110010 3 3 | 00010010001101000101011001111000000100100011010001010110011110000000011000000000000000000000000000000000000000001000000011110011 3 4 | 00010010001101000101011001111000000100100011010001010110011110000000011000000000000000000000000000000000000000000000000011110100 3 -------------------------------------------------------------------------------- /test/stf_tests/test_data/hash_action_two_separate.expected: -------------------------------------------------------------------------------- 1 | 00010001000100010001000100010001001000100010001000100010001000100000000100000001000000100000001000000011000000110000010000000100 1 2 | 00100010001000100010001000100010001100110011001100110011001100110000001000000010000000110000001100000100000001000000010100000101 2 3 | 00110011001100110011001100110011010001000100010001000100010001000000001100000011000001000000010000000101000001010000011000000110 2 4 | 01000100010001000100010001000100010101010101010101010101010101010000010000000100000001010000010100000110000001100000011100000111 3 -------------------------------------------------------------------------------- /test/semantics/features/exception/exception_out_of_packet.p4: -------------------------------------------------------------------------------- 1 | header_type ht { 2 | fields { 3 | f1 : 4; 4 | f2 : 4; 5 | } 6 | } 7 | 8 | header_type mdt { 9 | fields { 10 | f : 8; 11 | } 12 | } 13 | 14 | 15 | header ht h; 16 | metadata mdt md; 17 | 18 | parser start{ 19 | extract(h); 20 | return ingress; 21 | } 22 | 23 | action noop() { 24 | 25 | } 26 | 27 | table t { 28 | reads { 29 | h.f1 : exact; 30 | } 31 | actions { 32 | noop; 33 | } 34 | } 35 | 36 | control ingress{ 37 | apply(t); 38 | } -------------------------------------------------------------------------------- /test/semantics/features/exception/exception_index_out_of_bound.p4: -------------------------------------------------------------------------------- 1 | header_type ht { 2 | fields { 3 | f1 : 4; 4 | f2 : 4; 5 | } 6 | } 7 | 8 | header_type mdt { 9 | fields { 10 | f : 8; 11 | } 12 | } 13 | 14 | 15 | header ht h[2]; 16 | metadata mdt md; 17 | 18 | parser start{ 19 | extract(h[2]); 20 | return ingress; 21 | } 22 | 23 | action noop() { 24 | 25 | } 26 | 27 | table t { 28 | reads { 29 | h.f1 : exact; 30 | } 31 | actions { 32 | noop; 33 | } 34 | } 35 | 36 | control ingress{ 37 | apply(t); 38 | } -------------------------------------------------------------------------------- /test/semantics/features/header_actions/copy_header.p4: -------------------------------------------------------------------------------- 1 | header_type ht { 2 | fields { 3 | f1 : 4; 4 | f2 : 4; 5 | } 6 | } 7 | 8 | 9 | header ht h1; 10 | header ht h2; 11 | header ht a[2]; 12 | 13 | parser start{ 14 | extract(h1); 15 | return ingress; 16 | } 17 | 18 | action a() { 19 | copy_header(h2,h1); 20 | copy_header(a[0],h1); 21 | copy_header(h1,a[1]); 22 | } 23 | 24 | table t { 25 | reads { 26 | h1.f1 : exact; 27 | } 28 | actions { 29 | a; 30 | } 31 | } 32 | 33 | control ingress{ 34 | apply(t); 35 | } -------------------------------------------------------------------------------- /test/semantics/smoke_tests/test2-input1.k: -------------------------------------------------------------------------------- 1 | 2 | ... 3 | 4 | ... 5 | egress_meter 6 | .List => ListItem( 7 | $rule( 8 | $ctr(ListItem( @val ( 279611477 , 48 , false ))) 9 | , @call(String2Id("meter_pkt") , $resolved( ListItem(@val(10,0,false)) ) )) 10 | ) 11 | 12 |
13 |
14 | syntax Id ::= "egress_meter" [token] 15 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/action_chain1.expected: -------------------------------------------------------------------------------- 1 | 00000000000000000000000100000001************************************************0111111101100110 2 2 | 00000000000000000000001000000010************************************************0000011101100110 3 3 | 0000000100000001000000010000000100000010000000100000001000000010000000110000001101111111001001100010010100000000001001010111111100000001000000100000001100000100 2 4 | 000000010000000100000001000000010000001000000010000000100000001000000011000000110111111101100110001001010010010100100111111111110011001100110011001010000111111100000001000000100000001100000100 2 -------------------------------------------------------------------------------- /test/stf_tests/test_data/exact_match_valid1.stf: -------------------------------------------------------------------------------- 1 | add test1 data:1 data2:1 setb1(val:0xaa, port:3) 2 | add test1 data:1 data2:0 setb1(val:0xbb, port:2) 3 | 4 | expect 2 01010101 02020202 03030303 04040404 bb 22 33 44 01010101 02020202 03030303 04040404 11 22 33 44 55 66 5 | packet 0 01010101 02020202 03030303 04040404 11 22 33 44 01010101 02020202 03030303 04040404 11 22 33 44 55 66 6 | expect 3 01010101 f2f20202 03030303 04040404 aa 22 33 44 01010101 02020202 03030303 04040404 11 22 33 44 55 66 7 | packet 0 01010101 f2f20202 03030303 04040404 11 22 33 44 01010101 02020202 03030303 04040404 11 22 33 44 55 66 8 | -------------------------------------------------------------------------------- /test/semantics/features/header_actions/remove_header.p4: -------------------------------------------------------------------------------- 1 | header_type ht { 2 | fields { 3 | f1 : 4; 4 | f2 : 4; 5 | } 6 | } 7 | 8 | 9 | header ht h1; 10 | header ht h2; 11 | header ht a[2]; 12 | 13 | parser start{ 14 | extract(h1); 15 | extract(a[0]); 16 | extract(a[1]); 17 | return ingress; 18 | } 19 | 20 | action a() { 21 | remove_header(h1); 22 | remove_header(a[0]); 23 | } 24 | 25 | table t { 26 | reads { 27 | h1.f1 : exact; 28 | } 29 | actions { 30 | a; 31 | } 32 | } 33 | 34 | control ingress{ 35 | apply(t); 36 | } -------------------------------------------------------------------------------- /test/semantics/smoke_tests/test1.p4: -------------------------------------------------------------------------------- 1 | header_type ethernet_t { 2 | fields { 3 | ethertype: 16; 4 | dstAddr : 48; 5 | } 6 | } 7 | 8 | header_type foo_t { 9 | fields { 10 | bar : 12; 11 | } 12 | } 13 | 14 | 15 | header ethernet_t ethernet; 16 | metadata foo_t local_metadata; 17 | 18 | parser start { 19 | return ethernet; 20 | } 21 | 22 | parser ethernet { 23 | extract(ethernet); 24 | return select(ethernet.ethertype) { 25 | 0x8100: vlan; 26 | default: ingress; 27 | } 28 | } 29 | 30 | 31 | parser vlan { 32 | return ingress; 33 | } -------------------------------------------------------------------------------- /experiments/assert-p4/NetPaxos/input.cli: -------------------------------------------------------------------------------- 1 | @setdefault round_tbl read_round() 2 | @setdefault drop_tbl _nop() 3 | @add drop_tbl 1 _drop() 4 | @add forward_tbl 1 forward(2) 5 | @add forward_tbl 2 forward(1) 6 | @setdefault acceptor_tbl _drop() 7 | @add acceptor_tbl 0 handle_1a(2) 8 | @add acceptor_tbl 2 handle_2a(2) 9 | 10 | @sympacket 1 - ?:48 ?:48 2048:16 ?:4 ?:4 ?:8 ?:16 ?:16 ?:3 ?:13 ?:8 17:8 ?:16 ?:32 ?:32 ?:16 34952:16 ?:16 ?:16 ?:16 ?:32 ?:16 ?:16 ?:16 ?:32 ?:256 11 | // eth ip udp paxos 12 | @expect -------------------------------------------------------------------------------- /test/semantics/features/exception/exception_unhandled_select.p4: -------------------------------------------------------------------------------- 1 | header_type ht { 2 | fields { 3 | f1 : 4; 4 | f2 : 4; 5 | } 6 | } 7 | 8 | header_type mdt { 9 | fields { 10 | f : 8; 11 | } 12 | } 13 | 14 | 15 | header ht h; 16 | metadata mdt md; 17 | 18 | parser start{ 19 | extract(h); 20 | return select(h.f1) { 21 | 3 : ingress; 22 | } 23 | } 24 | 25 | action noop() { 26 | 27 | } 28 | 29 | table t { 30 | reads { 31 | h.f1 : exact; 32 | } 33 | actions { 34 | noop; 35 | } 36 | } 37 | 38 | control ingress{ 39 | apply(t); 40 | } -------------------------------------------------------------------------------- /test/stf_tests/test_data/parser_dc_full.expected: -------------------------------------------------------------------------------- 1 | 000000000000000100000001000000010000000100000001000000010000000100000010000000100000001000000010000000100000001010010000000000000000000000000000000100010001000100100010001000100011001100110011010001000100010001010101010101011001000100000000101010101010101010010001000000001011101110111011100010000100011100000000000000000000000000000001000000000000000000000001000000010100010100000000000001000000000000000000000000000000000000000000010000000001000101110110111010111000000000000000000000000000000110000000000000000000000000000001000000000110010000000000011001010000001100000000000000000000000011111111 10 -------------------------------------------------------------------------------- /test/stf_tests/test_data/parser_dc_full.stf: -------------------------------------------------------------------------------- 1 | # Ali 2 | setdefault mark_check mark_forward() 3 | # 4 | 5 | # 2 - ethernet 16 - cpu 30 - vlan x2 38 - mpls x2 46 - inner ip 66 - udp 72 - data 6 | expect 10 0001 0101010101010202020202029000 0000111122223333444455559100 aaaa9100 bbbb8847 00000001 00000101 4500040000000000401176eb8000000180000001 0064006503000000 ff 7 | packet 1 0001 0101010101010202020202029000 0000111122223333444455559100 aaaa9100 bbbb8847 00000001 00000101 4500040000000000401176eb8000000180000001 0064006503000000 01 8 | -------------------------------------------------------------------------------- /test/semantics/features/array/array_access.p4: -------------------------------------------------------------------------------- 1 | 2 | header_type ht { 3 | fields { 4 | f1 : 2; 5 | f2 : 2; 6 | } 7 | } 8 | 9 | header ht h[2]; 10 | 11 | parser start{ 12 | extract(h[next]); 13 | return select(latest.f1){ 14 | 0 : start; 15 | 1 : ingress; 16 | } 17 | } 18 | 19 | action ac (val) { 20 | modify_field(h[0].f2 , val); 21 | modify_field(h[last].f2 , val); 22 | } 23 | 24 | table t { 25 | reads { 26 | h[0].f1 : exact; 27 | h[last].f1 : exact; 28 | } 29 | actions { 30 | ac; 31 | } 32 | } 33 | 34 | control ingress { apply(t); } 35 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/hitmiss.expected: -------------------------------------------------------------------------------- 1 | 00000000000000000000000100000001************************************************************************************************0111111101100110 2 2 | 00000000000000000000001000000010************************************************************************************************0000011101100110 3 3 | 0000000000000000000000010000000100100010001000100010001000100010000000000000000000000011000000110000000000000000000001000000010000000001011001100111011110001000 4 4 | 0000000000000000000100010001000100100010001000100010001000100010000000000000000000000011000000110000000000000000000001000000010000000010011001100111011110001000 5 -------------------------------------------------------------------------------- /tranlation-validation/simple/simple.p4: -------------------------------------------------------------------------------- 1 | header_type h_t { 2 | fields { 3 | f1 : 8; 4 | f2 : 8; 5 | } 6 | } 7 | 8 | header h_t h1; 9 | 10 | 11 | parser start { 12 | extract(h1); 13 | return ingress; 14 | } 15 | 16 | 17 | action a(n) { 18 | modify_field(h1.f2, n); 19 | modify_field(standard_metadata.egress_spec, 1); 20 | } 21 | 22 | action b() { 23 | modify_field(standard_metadata.egress_spec, 2); 24 | } 25 | 26 | table t { 27 | reads { 28 | h1.f1 : exact; 29 | } 30 | actions { 31 | a; 32 | b; 33 | } 34 | } 35 | 36 | control ingress { 37 | apply(t); 38 | } 39 | 40 | -------------------------------------------------------------------------------- /tranlation-validation/simple/debug/simpler.p4: -------------------------------------------------------------------------------- 1 | header_type h_t { 2 | fields { 3 | f1 : 8; 4 | f2 : 8; 5 | } 6 | } 7 | 8 | header h_t h1; 9 | 10 | 11 | parser start { 12 | extract(h1); 13 | return ingress; 14 | } 15 | 16 | 17 | action a(n) { 18 | modify_field(h1.f2, n); 19 | modify_field(standard_metadata.egress_spec, 1); 20 | } 21 | 22 | action b() { 23 | modify_field(standard_metadata.egress_spec, 2); 24 | } 25 | 26 | table t { 27 | reads { 28 | h1.f1 : exact; 29 | } 30 | actions { 31 | a; 32 | b; 33 | } 34 | } 35 | 36 | control ingress { 37 | apply(t); 38 | } 39 | 40 | -------------------------------------------------------------------------------- /test/semantics/features/exception/exception_handler.p4: -------------------------------------------------------------------------------- 1 | header_type ht { 2 | fields { 3 | f1 : 4; 4 | f2 : 4; 5 | } 6 | } 7 | 8 | header_type mdt { 9 | fields { 10 | f : 8; 11 | } 12 | } 13 | 14 | header ht h; 15 | metadata mdt md; 16 | 17 | parser start{ 18 | extract(h); 19 | return ingress; 20 | } 21 | 22 | parser_exception p4_pe_out_of_packet { 23 | set_metadata(md.f, 1); 24 | parser_drop; 25 | } 26 | 27 | action noop() { 28 | 29 | } 30 | 31 | table t { 32 | reads { 33 | h.f1 : exact; 34 | } 35 | actions { 36 | noop; 37 | } 38 | } 39 | 40 | control ingress{ 41 | apply(t); 42 | } -------------------------------------------------------------------------------- /test/stf_tests/test_data/basic_conditionals.p4: -------------------------------------------------------------------------------- 1 | header_type data_t { 2 | fields { 3 | f1 : 32; 4 | f2 : 32; 5 | h1 : 16; 6 | h2 : 16; 7 | h3 : 16; 8 | h4 : 16; 9 | } 10 | } 11 | 12 | header data_t data; 13 | 14 | parser start { 15 | extract(data); 16 | return ingress; 17 | } 18 | 19 | action set_port(port) { 20 | modify_field(standard_metadata.egress_spec, port); 21 | } 22 | 23 | table test1 { 24 | reads { 25 | data.f1 : exact; 26 | } 27 | actions { 28 | set_port; 29 | } 30 | } 31 | 32 | control ingress { 33 | if (true) { 34 | apply(test1); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/issue781.p4: -------------------------------------------------------------------------------- 1 | header_type ipv4_t { 2 | fields { 3 | version : 4; 4 | ihl : 4; 5 | diffserv : 8; 6 | totalLen : 16; 7 | id : 16; 8 | flags : 3; 9 | fragOffset : 13; 10 | ttl : 8; 11 | protocol : 8; 12 | hdrChecksum : 16; 13 | srcAddr : 32; 14 | dstAddr : 32; 15 | options_ipv4: *; 16 | } 17 | length : (ihl << 2); 18 | max_length : 60; 19 | } 20 | 21 | header ipv4_t h; 22 | 23 | parser start { 24 | extract(h); 25 | return ingress; 26 | } 27 | 28 | control ingress { 29 | } -------------------------------------------------------------------------------- /test/stf_tests/test_data/repeater.p4: -------------------------------------------------------------------------------- 1 | //header_type data_t { fields { bit<32> x; } } //Ali 2 | header_type data_t { fields { x : 32; } } 3 | header data_t data; 4 | 5 | parser start { 6 | extract(data); 7 | return ingress; 8 | } 9 | 10 | action my_drop() { 11 | drop(); 12 | } 13 | 14 | action set_egress_port(egress_port) { 15 | modify_field(standard_metadata.egress_spec, egress_port); 16 | } 17 | 18 | table repeater { 19 | reads { 20 | standard_metadata.ingress_port: exact; 21 | } 22 | actions { 23 | my_drop; 24 | set_egress_port; 25 | } 26 | } 27 | 28 | control ingress { 29 | apply(repeater); 30 | } 31 | 32 | control egress { } 33 | -------------------------------------------------------------------------------- /multithreaded/race.p4: -------------------------------------------------------------------------------- 1 | header_type meta_t { 2 | fields { 3 | reg_val : 8; 4 | } 5 | } 6 | 7 | metadata meta_t meta; 8 | 9 | 10 | parser start{ 11 | return ingress; 12 | } 13 | 14 | register reg { 15 | width: 8; 16 | instance_count: 1; 17 | } 18 | 19 | action inc(){ 20 | register_read(meta.reg_val,reg,0); 21 | add(meta.reg_val,meta.reg_val,1); 22 | register_write(reg,0,meta.reg_val); 23 | modify_field(standard_metadata.egress_spec, 0); 24 | } 25 | 26 | table inc_reg_table{ 27 | reads{ 28 | meta.valid : exact; 29 | } 30 | actions{ 31 | inc; 32 | } 33 | } 34 | 35 | 36 | control ingress{ 37 | apply(inc_reg_table); 38 | } -------------------------------------------------------------------------------- /test/syntax/unit/add_mtag-action.p4: -------------------------------------------------------------------------------- 1 | // Add an mTag to the packet; select egress spec based on up1 2 | action add_mTag(up1, up2, down1, down2) { 3 | add_header(mtag); 4 | // Copy VLAN ethertype to mTag 5 | modify_field(mtag.ethertype, vlan.ethertype); 6 | // Set VLAN’s ethertype to signal mTag 7 | modify_field(vlan.ethertype, 0xaaaa); 8 | // Add the tag source routing information 9 | modify_field(mtag.up1, up1); 10 | modify_field(mtag.up2, up2); 11 | modify_field(mtag.down1, down1); 12 | modify_field(mtag.down2, down2); 13 | // Set the destination egress port as well from the tag info 14 | modify_field(standard_metadata.egress_spec, up1); 15 | } -------------------------------------------------------------------------------- /test/stf_tests/test_data/exact_match_valid1.expected: -------------------------------------------------------------------------------- 1 | 000000010000000100000001000000010000001000000010000000100000001000000011000000110000001100000011000001000000010000000100000001001011101100100010001100110100010000000001000000010000000100000001000000100000001000000010000000100000001100000011000000110000001100000100000001000000010000000100000100010010001000110011010001000101010101100110 2 2 | 000000010000000100000001000000011111001011110010000000100000001000000011000000110000001100000011000001000000010000000100000001001010101000100010001100110100010000000001000000010000000100000001000000100000001000000010000000100000001100000011000000110000001100000100000001000000010000000100000100010010001000110011010001000101010101100110 3 -------------------------------------------------------------------------------- /test/semantics/features/match_types/lpm.p4: -------------------------------------------------------------------------------- 1 | header_type ipv4_t { 2 | fields { 3 | ttl : 8; 4 | srcAddr : 32; 5 | dstAddr : 32; 6 | 7 | } 8 | } 9 | 10 | header ipv4_t ipv4; 11 | 12 | parser start{ 13 | extract(ipv4); 14 | return ingress; 15 | } 16 | 17 | 18 | 19 | action route_ipv4(egress_spec) { 20 | add_to_field(ipv4.ttl, -1); 21 | modify_field(standard_metadata.egress_spec, egress_spec); 22 | } 23 | 24 | table routing { 25 | reads { 26 | ipv4.dstAddr : lpm; 27 | } 28 | actions { 29 | route_ipv4; 30 | } 31 | } 32 | 33 | 34 | control ingress { 35 | apply(routing); 36 | } 37 | 38 | control egress { 39 | } 40 | -------------------------------------------------------------------------------- /test/semantics/features/match_types/valid.p4: -------------------------------------------------------------------------------- 1 | header_type ipv4_t { 2 | fields { 3 | ttl : 8; 4 | srcAddr : 32; 5 | dstAddr : 32; 6 | 7 | } 8 | } 9 | 10 | header ipv4_t ipv4; 11 | 12 | parser start{ 13 | extract(ipv4); 14 | return ingress; 15 | } 16 | 17 | 18 | 19 | action route_ipv4(egress_spec) { 20 | add_to_field(ipv4.ttl, -1); 21 | modify_field(standard_metadata.egress_spec, egress_spec); 22 | } 23 | 24 | table routing { 25 | reads { 26 | ipv4 : valid; 27 | } 28 | actions { 29 | route_ipv4; 30 | } 31 | } 32 | 33 | 34 | control ingress { 35 | apply(routing); 36 | } 37 | 38 | control egress { 39 | } 40 | -------------------------------------------------------------------------------- /test/semantics/features/match_types/range.p4: -------------------------------------------------------------------------------- 1 | header_type ipv4_t { 2 | fields { 3 | ttl : 8; 4 | srcAddr : 32; 5 | dstAddr : 32; 6 | 7 | } 8 | } 9 | 10 | header ipv4_t ipv4; 11 | 12 | parser start{ 13 | extract(ipv4); 14 | return ingress; 15 | } 16 | 17 | 18 | 19 | action route_ipv4(egress_spec) { 20 | add_to_field(ipv4.ttl, -1); 21 | modify_field(standard_metadata.egress_spec, egress_spec); 22 | } 23 | 24 | table routing { 25 | reads { 26 | ipv4.dstAddr : range; 27 | } 28 | actions { 29 | route_ipv4; 30 | } 31 | } 32 | 33 | 34 | control ingress { 35 | apply(routing); 36 | } 37 | 38 | control egress { 39 | } 40 | -------------------------------------------------------------------------------- /test/semantics/features/match_types/ternary.p4: -------------------------------------------------------------------------------- 1 | header_type ipv4_t { 2 | fields { 3 | ttl : 8; 4 | srcAddr : 32; 5 | dstAddr : 32; 6 | 7 | } 8 | } 9 | 10 | header ipv4_t ipv4; 11 | 12 | parser start{ 13 | extract(ipv4); 14 | return ingress; 15 | } 16 | 17 | 18 | 19 | action route_ipv4(egress_spec) { 20 | add_to_field(ipv4.ttl, -1); 21 | modify_field(standard_metadata.egress_spec, egress_spec); 22 | } 23 | 24 | table routing { 25 | reads { 26 | ipv4.dstAddr : ternary; 27 | } 28 | actions { 29 | route_ipv4; 30 | } 31 | } 32 | 33 | 34 | control ingress { 35 | apply(routing); 36 | } 37 | 38 | control egress { 39 | } 40 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/hitmiss.stf: -------------------------------------------------------------------------------- 1 | 2 | add test1 0 data.f1:0x****0101 setb1(val:0x7f, port:2) 3 | add test1 503 data.f1:0x****0202 setb1(val:7, port:3) 4 | 5 | add test2 100 data.f2:0x****2222 setb1(val:1, port:4) 6 | add test3 100 data.f3:0x****0303 setb1(val:2, port:5) 7 | 8 | expect 2 00000101 ******** ******** ******** 7f 66 9 | packet 0 00000101 00000202 00000303 00000404 55 66 77 88 10 | expect 3 00000202 ******** ******** ******** 07 66 11 | packet 2 00000202 00000303 00000404 00000404 55 66 77 88 12 | 13 | expect 4 00000101 22222222 00000303 00000404 01 66 77 88 14 | packet 0 00000101 22222222 00000303 00000404 55 66 77 88 15 | expect 5 00001111 22222222 00000303 00000404 02 66 77 88 16 | packet 0 00001111 22222222 00000303 00000404 55 66 77 88 17 | -------------------------------------------------------------------------------- /verification/verification-debug/old-specs/2spec.k: -------------------------------------------------------------------------------- 1 | 2 | 3 | module SPEC 4 | imports LANG 5 | 6 | rule 7 | 8 | @nextPacket => @nextPacket 9 | 0 10 | R1:Int => ?R2:Int 11 | // 1 => 0 12 | .List => _ 13 | .List => _ 14 | $consPacketList($packet(P:List,_:Int) , Lin:PacketList) => Lin 15 | Lout:PacketList => $consPacketList($packet(P,R2) , Lout) 16 | // Lout:PacketList => $consPacketList($packet(P,0) , Lout) 17 | 18 | //requires //absInt(#onPort(Lout,0) -Int #onPort(Lout,1)) <=Int 1 19 | requires (R1 ==Int 1 orBool R1 ==Int 0) 20 | ensures ?R2 ==Int 1 orBool ?R2 ==Int 0 21 | 22 | 23 | 24 | endmodule 25 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/17-Minimal.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | parser start { 18 | return ingress; 19 | } 20 | 21 | control ingress { 22 | } 23 | 24 | control egress { 25 | } 26 | -------------------------------------------------------------------------------- /tranlation-validation/simple/debug/test.k: -------------------------------------------------------------------------------- 1 | //require "c.k" 2 | 3 | module TEST 4 | //imports C 5 | 6 | syntax Val ::= "@undef" [smtlib(val_undef)] 7 | syntax Val ::= "@val" "("Int","Int","Bool")" [smtlib(smt_val)] //int,width,signed 8 | 9 | //syntax Val ::= NUVal 10 | //syntax NUVal ::= "@val" "("Int","Int","Bool")" 11 | 12 | 13 | //========= 14 | //syntax Bool ::= vars(List) 15 | //======== 16 | 17 | 18 | configuration 19 | 20 | $PGM:Val 21 | 22 | 23 | 24 | rule @val(I:Int,_,_) => I 25 | 26 | 27 | syntax Bool ::= "#noUndef" "(" Val ")" [function]//[function, smtlib(no_undef)] 28 | rule #noUndef(@val(_,_,_)) => true //[smt-lemma] 29 | rule #noUndef(@undef) => false //[smt-lemma] 30 | endmodule -------------------------------------------------------------------------------- /test/stf_tests/test_data/issue638-2.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 VMware, Inc. 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 | parser start { 18 | return ingress; 19 | } 20 | 21 | table empty { 22 | actions {} 23 | } 24 | 25 | control ingress { 26 | apply(empty); 27 | } -------------------------------------------------------------------------------- /test/semantics/basic_routing/sym-input1.cli: -------------------------------------------------------------------------------- 1 | @add port_mapping 1 set_bd(10) 2 | @add port_mapping 2 set_bd(10) 3 | @add port_mapping 3 set_bd(20) 4 | @add port_mapping 4 set_bd(20) 5 | 6 | @add bd 10 set_vrf(30) 7 | @add bd 20 set_vrf(30) 8 | 9 | @add ipv4_fib 30 3232235520 fib_hit_nexthop(1) 10 | @add ipv4_fib 30 167772160 fib_hit_nexthop(3) 11 | 12 | @add nexthop 1 set_egress_details(1) 13 | @add nexthop 2 set_egress_details(2) 14 | @add nexthop 3 set_egress_details(3) 15 | @add nexthop 4 set_egress_details(4) 16 | 17 | @add rewrite_mac 1 rewrite_src_dst_mac(1103823438081, 4311810305) 18 | @add rewrite_mac 2 rewrite_src_dst_mac(1108135248386, 8623620610) 19 | @add rewrite_mac 3 rewrite_src_dst_mac(1112447058691, 12935430915) 20 | @add rewrite_mac 4 rewrite_src_dst_mac(1116758868996, 17247241220) 21 | 22 | @sympacket 23 | @expect -------------------------------------------------------------------------------- /test/stf_tests/test_data/action_chain1.stf: -------------------------------------------------------------------------------- 1 | 2 | add test1 0 data.f1:0x****0101 setb1(val:0x7f, port:2) 3 | add test1 503 data.f1:0x****0202 setb1(val:7, port:3) 4 | 5 | expect 2 00000101 ******** **** 7f 66 6 | packet 0 00000101 00000202 0303 55 66 7777 88 00 7 | expect 3 00000202 ******** **** 07 66 8 | packet 2 00000202 00000303 0404 55 66 7777 88 00 9 | wait 10 | 11 | add ex1 100 extra$0.h:0x25** act1(val:0x25) 12 | add tbl1 100 data.f2:0x0202**** setb2(val:0x26) 13 | add ex1 110 extra$0.h:0x2525 act2(val:0x27) 14 | add tbl2 100 data.f2:0x0202**** set1b1(val:0x28) 15 | 16 | expect 2 01010101 02020202 0303 7f 26 2500 25 7f 01020304 17 | packet 0 01010101 02020202 0303 55 66 2500 ff 7f 01020304 18 | expect 2 01010101 02020202 0303 7f 66 2525 27 ff 3333 28 7f 01020304 19 | packet 0 01010101 02020202 0303 55 66 2525 ff ff 3333 ff 7f 01020304 20 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/hash_action_two_separate.stf: -------------------------------------------------------------------------------- 1 | add index_setter data.f1:0x11111111 data.f2:0x22222222 set_index(index1:9, index2:10, port:1) 2 | add index_setter data.f1:0x22222222 data.f2:0x33333333 set_index(index1:9, index2:11, port:2) 3 | add index_setter data.f1:0x33333333 data.f2:0x44444444 set_index(index1:9, index2:11, port:2) 4 | add index_setter data.f1:0x44444444 data.f2:0x55555555 set_index(index1:8, index2:11, port:3) 5 | 6 | expect 1 11111111 22222222 0101 0202 0303 0404 7 | packet 0 11111111 22222222 0101 0202 0303 0404 8 | 9 | expect 2 22222222 33333333 0202 0303 0404 0505 10 | packet 0 22222222 33333333 0202 0303 0404 0505 11 | 12 | expect 2 33333333 44444444 0303 0404 0505 0606 13 | packet 0 33333333 44444444 0303 0404 0505 0606 14 | 15 | expect 3 44444444 55555555 0404 0505 0606 0707 16 | packet 0 44444444 55555555 0404 0505 0606 0707 17 | -------------------------------------------------------------------------------- /tranlation-validation/simple/debug/simple.p4: -------------------------------------------------------------------------------- 1 | header_type h_t { 2 | fields { 3 | f1 : 8; 4 | f2 : 8; 5 | } 6 | } 7 | 8 | header h_t h1; 9 | header h_t h2; 10 | 11 | parser start { 12 | extract(h1); 13 | return select(h1.f1){ 14 | 1 : parse_h2; 15 | default : ingress; 16 | } 17 | } 18 | 19 | parser parse_h2 { 20 | extract(h2); 21 | return ingress; 22 | } 23 | 24 | action a(n) { 25 | modify_field(h2.f2, n); 26 | modify_field(standard_metadata.egress_spec, 10); 27 | } 28 | 29 | action b() { 30 | modify_field(standard_metadata.egress_spec, 20); 31 | } 32 | 33 | table t { 34 | reads { 35 | h2.f1 : exact; 36 | h2.f2 : exact; 37 | } 38 | actions { 39 | a; 40 | b; 41 | } 42 | } 43 | 44 | control ingress { 45 | if (valid(h2)) { 46 | apply(t); 47 | } 48 | } 49 | 50 | -------------------------------------------------------------------------------- /test/syntax/unit/control.p4: -------------------------------------------------------------------------------- 1 | // The ingress control function 2 | control ingress { 3 | // Verify mTag state and port are consistent 4 | apply(check_mtag); 5 | apply(identify_port); 6 | apply(select_output_port); 7 | apply(egress_meter) { 8 | hit { // If egress meter table matched, apply policy 9 | apply(meter_policy); 10 | } 11 | } 12 | apply(routing_table) { 13 | ipv4_route_action { // IPv4 action was used 14 | apply(v4_rpf); 15 | apply(v4_acl); 16 | } 17 | ipv6_route_action { // IPv6 action was used 18 | apply(v6_option_check); 19 | apply(v6_acl); 20 | } 21 | default { // Some other action was used 22 | if (standard_metadata.ingress_port == 1) { 23 | apply(cpu_ingress_check); 24 | } 25 | } 26 | } 27 | } 28 | 29 | 30 | -------------------------------------------------------------------------------- /verification/load-balancer/load-balancer.p4: -------------------------------------------------------------------------------- 1 | header_type meta_t { 2 | fields { 3 | reg_val : 8; 4 | } 5 | } 6 | 7 | metadata meta_t meta; 8 | 9 | 10 | parser start{ 11 | return ingress; 12 | } 13 | 14 | register reg { 15 | width: 8; 16 | instance_count: 1; 17 | } 18 | 19 | action read_reg(){ 20 | register_read(meta.reg_val,reg,0); 21 | } 22 | 23 | table read_reg_table{ 24 | reads{ 25 | meta.valid : exact; 26 | } 27 | actions{ 28 | read_reg; 29 | } 30 | } 31 | 32 | 33 | action balance(port,val){ 34 | modify_field(standard_metadata.egress_spec, port); 35 | register_write(reg, 0, val); 36 | } 37 | 38 | table balance_table{ 39 | reads{ 40 | meta.reg_val : exact; 41 | } 42 | actions{ 43 | balance; 44 | } 45 | } 46 | 47 | 48 | control ingress{ 49 | apply(read_reg_table); 50 | apply(balance_table); 51 | } -------------------------------------------------------------------------------- /test/stf_tests/test_data/16-NoHeaders.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | parser start { 18 | return ingress; 19 | } 20 | 21 | action a1() { 22 | } 23 | 24 | table t1 { 25 | actions { 26 | a1; 27 | } 28 | } 29 | 30 | control ingress { 31 | apply(t1); 32 | } 33 | 34 | control egress { 35 | } 36 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/hash_action_basic.stf: -------------------------------------------------------------------------------- 1 | add index_setter data.f1:0x11111111 data.f2:0x22222222 set_index(index:9, port:1) 2 | add index_setter data.f1:0x22222222 data.f2:0x33333333 set_index(index:9, port:2) 3 | add index_setter data.f1:0x33333333 data.f2:0x44444444 set_index(index:9, port:2) 4 | add index_setter data.f1:0x44444444 data.f2:0x55555555 set_index(index:8, port:3) 5 | 6 | expect 1 11111111 22222222 0101 0202 0303 0404 7 | packet 0 11111111 22222222 0101 0202 0303 0404 8 | 9 | # expect 2 22222222 33333333 0202 0303 0404 0505 10 | # packet 0 22222222 33333333 0202 0303 0404 0505 11 | 12 | # expect 2 33333333 44444444 0303 0404 0505 0606 13 | # packet 0 33333333 44444444 0303 0404 0505 0606 14 | 15 | # expect 3 44444444 55555555 0404 0505 0606 0707 16 | # packet 0 44444444 55555555 0404 0505 0606 0707 17 | 18 | wait 19 | # check_counter count1(8) packets == 1 20 | check_counter count1(9) packets == 1 21 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/hash_action_gateway.stf: -------------------------------------------------------------------------------- 1 | 2 | add index_setter data.f1:0x11111111 data.f2:0x22222222 set_index(index:9, port:1) 3 | add index_setter data.f1:0x22222222 data.f2:0x33333333 set_index(index:9, port:2) 4 | add index_setter data.f1:0x33333333 data.f2:0x44444444 set_index(index:9, port:2) 5 | add index_setter data.f1:0x44444444 data.f2:0x55555555 set_index(index:8, port:3) 6 | 7 | 8 | expect 1 11111111 22222222 0101 0202 0303 0404 9 | packet 0 11111111 22222222 0101 0202 0303 0404 10 | 11 | # expect 2 22222222 33333333 0202 0303 0404 0505 12 | # packet 0 22222222 33333333 0202 0303 0404 0505 13 | 14 | # expect 2 33333333 44444444 0303 0404 0505 0606 15 | # packet 0 33333333 44444444 0303 0404 0505 0606 16 | 17 | # expect 3 44444444 55555555 0404 0505 0606 0707 18 | # packet 0 44444444 55555555 0404 0505 0606 0707 19 | 20 | wait 21 | # check_counter count1(8) packets == 1 22 | check_counter count1(9) packets == 1 23 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/basic_routing.expected: -------------------------------------------------------------------------------- 1 | 0000000000000011000000110000001100000011000000110000000100000011000000110000001100000011000000110000100000000000010001010000000000000000001011000000000000000000000000000110010100111111000100010110****010101010000000100000010000000110000010000001010000000000000000000000010000000000110010000000000011001010000000000010000000000000000000000000000000000010000001000000011000001000000010100000110000001110000100000001001000010100000101100001100000011010000111000001111 3 2 | 0000000000000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000100000000000010001010000000000000000001011000000000000000000000000000110010100111111000100011011****101011000000000100000010000000110000010011000000101010000000000100000010000000000110010000000000011001010000000000010000000000000000000000000000000000010000001000000011000001000000010100000110000001110000100000001001000010100000101100001100000011010000111000001111 1 -------------------------------------------------------------------------------- /test/stf_tests/test_data/instruct5.stf: -------------------------------------------------------------------------------- 1 | # Ali 2 | setdefault output output(port:1) 3 | # 4 | 5 | add test1 f1:0x01010101 push1(x1:0x21) 6 | add test1 f1:0x01010102 push2(x1:0x22, x2:0x32) 7 | add test1 f1:0x01010103 pop1() 8 | 9 | expect 1 01010101 02020202 03030301 00002100 00 01 02 03 10 | packet 0 01010101 02020202 03030300 00 01 02 03 11 | expect 1 01010101 02020202 03030301 00002101 aabbcc00 00 01 02 03 12 | packet 0 01010101 02020202 03030301 aabbcc00 00 01 02 03 13 | expect 1 01010102 02020202 03030301 00002201 00003200 00 01 02 03 14 | packet 0 01010102 02020202 03030300 00 01 02 03 15 | expect 1 01010102 02020202 03030301 00002201 00003201 aabbcc00 00 01 02 03 16 | packet 0 01010102 02020202 03030301 aabbcc00 00 01 02 03 17 | expect 1 01010103 02020202 03030300 00 01 02 03 18 | packet 0 01010103 02020202 03030301 aabbcc00 00 01 02 03 19 | expect 1 01010103 02020202 03030301 ddeeff00 00 01 02 03 20 | packet 0 01010103 02020202 03030301 aabbcc01 ddeeff00 00 01 02 03 21 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/exact_match4.stf: -------------------------------------------------------------------------------- 1 | 2 | add test1 data1.f1:0x01010101010101010101010101010101 data2.f2:0x01010101010101010101010101010101 data3.f3:0x01010101010101010101010101010101 setb1(val:0x7f, port:2) 3 | add test1 data1.f1:0x02020202020202020202020202020202 data2.f2:0x02020202020202020202020202020202 data3.f3:0x02020202020202020202020202020202 setb1(val:7, port:3) 4 | 5 | expect 2 01010101010101010101010101010101 01010101010101010101010101010101 01010101010101010101010101010101 ******************************** 7f 66 6 | packet 0 01010101010101010101010101010101 01010101010101010101010101010101 01010101010101010101010101010101 00000202000002020000020200000202 55 66 77 88 7 | expect 3 02020202020202020202020202020202 02020202020202020202020202020202 02020202020202020202020202020202 ******************************** 07 66 8 | packet 2 02020202020202020202020202020202 02020202020202020202020202020202 02020202020202020202020202020202 00000303000003030000030300000303 55 66 77 88 9 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/exact_match5.stf: -------------------------------------------------------------------------------- 1 | 2 | add test1 data1.f1:0x0102030405060708090a0b0c0d0e0f10 data2.f2:0x1112131415161718191a1b1c1d1e1f20 data3.f3:0x2122232425262728292a2b2c2d2e2f30 setb1(val:0x7f, port:2) 3 | add test1 data1.f1:0x02020202020202020202020202020202 data2.f2:0x02020202020202020202020202020202 data3.f3:0x02020202020202020202020202020202 setb1(val:7, port:3) 4 | 5 | expect 2 0102030405060708090a0b0c0d0e0f10 1112131415161718191a1b1c1d1e1f20 2122232425262728292a2b2c2d2e2f30 ******************************** 7f 66 6 | packet 0 0102030405060708090a0b0c0d0e0f10 1112131415161718191a1b1c1d1e1f20 2122232425262728292a2b2c2d2e2f30 00000202000002020000020200000202 55 66 77 88 7 | expect 3 02020202020202020202020202020202 02020202020202020202020202020202 02020202020202020202020202020202 ******************************** 07 66 8 | packet 2 02020202020202020202020202020202 02020202020202020202020202020202 02020202020202020202020202020202 00000303000003030000030300000303 55 66 77 88 9 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/18-EmptyPipelines.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | header_type ethernet_t { 18 | fields { 19 | dstAddr : 48; 20 | srcAddr : 48; 21 | ethertype : 16; 22 | } 23 | } 24 | 25 | header ethernet_t ethernet; 26 | 27 | parser start { 28 | extract(ethernet); 29 | return ingress; 30 | } 31 | 32 | control ingress { 33 | } 34 | 35 | control egress { 36 | } 37 | -------------------------------------------------------------------------------- /experiments/assert-p4/NetPaxos/source/includes/paxos_headers.p4: -------------------------------------------------------------------------------- 1 | #ifndef _PAXOS_HEADERS_P4_ 2 | #define _PAXOS_HEADERS_P4_ 3 | 4 | // Headers for Paxos 5 | #define PAXOS_1A 0 6 | #define PAXOS_1B 1 7 | #define PAXOS_2A 2 8 | #define PAXOS_2B 3 9 | 10 | #define MSGTYPE_SIZE 16 11 | #define INSTANCE_SIZE 32 12 | #define ROUND_SIZE 16 13 | #define DATAPATH_SIZE 16 14 | #define VALUE_SIZE 256 15 | 16 | #define INSTANCE_COUNT 65536 17 | 18 | header_type paxos_t { 19 | fields { 20 | msgtype : MSGTYPE_SIZE; // indicates the message type e.g., 1A, 1B, etc. 21 | inst : INSTANCE_SIZE; // instance number 22 | rnd : ROUND_SIZE; // round number 23 | vrnd : ROUND_SIZE; // round in which an acceptor casted a vote 24 | acptid : DATAPATH_SIZE; // Switch ID 25 | paxoslen : 32; // the length of paxos_value 26 | paxosval : VALUE_SIZE; // the value the acceptor voted for 27 | } 28 | } 29 | 30 | header paxos_t paxos; 31 | 32 | #endif -------------------------------------------------------------------------------- /test/stf_tests/test_data/action_inline.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | header_type ht { fields { b : 1; } } 19 | metadata ht md; 20 | 21 | parser start { 22 | return ingress; 23 | } 24 | 25 | action a(y0) 26 | { add_to_field(y0, 1); } 27 | 28 | action b() { 29 | a(md.b); 30 | a(md.b); 31 | } 32 | 33 | table t { 34 | actions { b; } 35 | } 36 | 37 | control ingress { 38 | apply(t); 39 | } 40 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/inline.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | header_type h { 18 | fields { 19 | b : 1; 20 | } 21 | } 22 | 23 | metadata h m; 24 | 25 | parser start { 26 | return ingress; 27 | } 28 | 29 | action x() {} 30 | 31 | table t { 32 | actions { x; } 33 | } 34 | 35 | control c { 36 | if (m.b == 1) { apply(t); } 37 | } 38 | 39 | control d { 40 | c(); 41 | } 42 | 43 | control ingress { 44 | d(); 45 | } -------------------------------------------------------------------------------- /test/stf_tests/test_data/01-DeadMetadata1.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | parser start { 18 | return ingress; 19 | } 20 | 21 | header_type m_t { 22 | fields { 23 | f1 : 32; 24 | } 25 | } 26 | 27 | metadata m_t m; 28 | 29 | action a1() { 30 | modify_field(m.f1, 1); 31 | } 32 | 33 | table t1 { 34 | actions { 35 | a1; 36 | } 37 | } 38 | 39 | control ingress { 40 | apply(t1); 41 | } 42 | 43 | control egress { 44 | } 45 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/exact_match4.expected: -------------------------------------------------------------------------------- 1 | 000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001********************************************************************************************************************************0111111101100110 2 2 | 000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010********************************************************************************************************************************0000011101100110 3 -------------------------------------------------------------------------------- /test/stf_tests/test_data/exact_match5.expected: -------------------------------------------------------------------------------- 1 | 000000010000001000000011000001000000010100000110000001110000100000001001000010100000101100001100000011010000111000001111000100000001000100010010000100110001010000010101000101100001011100011000000110010001101000011011000111000001110100011110000111110010000000100001001000100010001100100100001001010010011000100111001010000010100100101010001010110010110000101101001011100010111100110000********************************************************************************************************************************0111111101100110 2 2 | 000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010********************************************************************************************************************************0000011101100110 3 -------------------------------------------------------------------------------- /test/semantics/basic_routing/input1.cli: -------------------------------------------------------------------------------- 1 | @add port_mapping 1 set_bd(10) 2 | @add port_mapping 2 set_bd(10) 3 | @add port_mapping 3 set_bd(20) 4 | @add port_mapping 4 set_bd(20) 5 | 6 | @add bd 10 set_vrf(30) 7 | @add bd 20 set_vrf(30) 8 | 9 | @add ipv4_fib 30 3232235520 fib_hit_nexthop(1) 10 | @add ipv4_fib 30 167772160 fib_hit_nexthop(3) 11 | 12 | @add nexthop 1 set_egress_details(1) 13 | @add nexthop 2 set_egress_details(2) 14 | @add nexthop 3 set_egress_details(3) 15 | @add nexthop 4 set_egress_details(4) 16 | 17 | @add rewrite_mac 1 rewrite_src_dst_mac(1103823438081, 4311810305) 18 | @add rewrite_mac 2 rewrite_src_dst_mac(1108135248386, 8623620610) 19 | @add rewrite_mac 3 rewrite_src_dst_mac(1112447058691, 12935430915) 20 | @add rewrite_mac 4 rewrite_src_dst_mac(1116758868996, 17247241220) 21 | 22 | @packet 1 "00000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000001000000000000100010100000000000000000100010010101101000010110000000000000000010000000001000101110010011100100000101000000000000000000000000100001010000000000000000000000000" 23 | @expect -------------------------------------------------------------------------------- /test/stf_tests/test_data/02-DeadMetadata2.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | parser start { 18 | set_metadata(m.f1, 2); 19 | return ingress; 20 | } 21 | 22 | header_type m_t { 23 | fields { 24 | f1 : 32; 25 | } 26 | } 27 | 28 | metadata m_t m; 29 | 30 | action a1() { 31 | modify_field(m.f1, 1); 32 | } 33 | 34 | table t1 { 35 | actions { 36 | a1; 37 | } 38 | } 39 | 40 | control ingress { 41 | apply(t1); 42 | } 43 | 44 | control egress { 45 | } 46 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/instruct5.expected: -------------------------------------------------------------------------------- 1 | 0000000100000001000000010000000100000010000000100000001000000010000000110000001100000011000000010000000000000000001000010000000000000000000000010000001000000011 1 2 | 000000010000000100000001000000010000001000000010000000100000001000000011000000110000001100000001000000000000000000100001000000011010101010111011110011000000000000000000000000010000001000000011 1 3 | 000000010000000100000001000000100000001000000010000000100000001000000011000000110000001100000001000000000000000000100010000000010000000000000000001100100000000000000000000000010000001000000011 1 4 | 00000001000000010000000100000010000000100000001000000010000000100000001100000011000000110000000100000000000000000010001000000001000000000000000000110010000000011010101010111011110011000000000000000000000000010000001000000011 1 5 | 00000001000000010000000100000011000000100000001000000010000000100000001100000011000000110000000000000000000000010000001000000011 1 6 | 0000000100000001000000010000001100000010000000100000001000000010000000110000001100000011000000011101110111101110111111110000000000000000000000010000001000000011 1 -------------------------------------------------------------------------------- /tranlation-validation/simple/debug/simple_router.p4: -------------------------------------------------------------------------------- 1 | header_type ethernet_t { 2 | fields { 3 | dstAddr : 48; 4 | srcAddr : 48; 5 | etherType : 16; 6 | } 7 | } 8 | 9 | header_type ipv4_t { 10 | fields { 11 | srcAddr : 32; 12 | dstAddr: 32; 13 | ttl : 8; 14 | } 15 | } 16 | 17 | header ethernet_t ethernet; 18 | header ipv4_t ipv4; 19 | 20 | parser start { 21 | return parse_ethernet; 22 | } 23 | 24 | parser parse_ethernet { 25 | extract(ethernet); 26 | return select(latest.etherType) { 27 | 0x0800 : parse_ipv4; 28 | default: ingress; 29 | } 30 | } 31 | 32 | parser parse_ipv4 { 33 | extract(ipv4); 34 | return ingress; 35 | } 36 | 37 | action fib_hit_nexthop(nexthop_index) { 38 | modify_field(standard_metadata.egress_spec, nexthop_index); 39 | subtract_from_field(ipv4.ttl, 1); 40 | } 41 | 42 | table ipv4_fib { 43 | reads { 44 | ipv4.dstAddr : exact; 45 | } 46 | actions { 47 | fib_hit_nexthop; 48 | } 49 | } 50 | 51 | control ingress { 52 | if (valid(ipv4)) { 53 | apply(ipv4_fib) 54 | } 55 | } -------------------------------------------------------------------------------- /test/stf_tests/test_data/parser_dc_full.k: -------------------------------------------------------------------------------- 1 | 2 | 3 | ... 4 | 5 | 6 | ... 7 | mark_check 8 | .List => .List 9 | .K => 10 | @call( 11 | String2Id("mark_forward"), 12 | $resolved( 13 | .List 14 | ) 15 | ) 16 | 17 |
18 | 19 |
20 | 21 | .List => 22 | ListItem($packet("000000000000000100000001000000010000000100000001000000010000000100000010000000100000001000000010000000100000001010010000000000000000000000000000000100010001000100100010001000100011001100110011010001000100010001010101010101011001000100000000101010101010101010010001000000001011101110111011100010000100011100000000000000000000000000000001000000000000000000000001000000010100010100000000000001000000000000000000000000000000000000000000010000000001000101110110111010111000000000000000000000000000000110000000000000000000000000000001000000000110010000000000011001010000001100000000000000000000000000000001",1)) 23 | 24 | 25 | syntax Id ::= 26 | "mark_check" [token] 27 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/gateway8.stf: -------------------------------------------------------------------------------- 1 | 2 | add test1 data.f1:0x01010101 setb1(val:1, port:2) 3 | add test2 data.f2:0x01010101 setb1(val:2, port:3) 4 | 5 | expect 2 01010101 01010101 01 01 77 88 6 | packet 0 01010101 01010101 55 01 77 88 7 | expect 2 01010101 01010101 01 02 77 88 8 | packet 0 01010101 01010101 55 02 77 88 9 | expect 3 01010101 01010101 02 03 77 88 10 | packet 0 01010101 01010101 55 03 77 88 11 | expect 3 01010101 01010101 02 04 77 88 12 | packet 0 01010101 01010101 55 04 77 88 13 | expect 2 01010101 01010101 01 05 77 88 14 | packet 0 01010101 01010101 55 05 77 88 15 | expect 3 01010101 01010101 02 06 77 88 16 | packet 0 01010101 01010101 55 06 77 88 17 | expect 2 01010101 01010101 01 0a 77 88 18 | packet 0 01010101 01010101 55 0a 77 88 19 | expect 3 01010101 01010101 02 0b 77 88 20 | packet 0 01010101 01010101 55 0b 77 88 21 | expect 2 01010101 01010101 01 11 77 88 22 | packet 0 01010101 01010101 55 11 77 88 23 | expect 3 01010101 01010101 02 12 77 88 24 | packet 0 01010101 01010101 55 12 77 88 25 | expect 2 01010101 01010101 01 13 77 88 26 | packet 0 01010101 01010101 55 13 77 88 27 | expect 3 01010101 01010101 02 14 77 88 28 | packet 0 01010101 01010101 55 14 77 88 29 | -------------------------------------------------------------------------------- /verification/verification-debug/balance_spec.k: -------------------------------------------------------------------------------- 1 | // also checked manually 2 | 3 | module SPEC 4 | imports LANG 5 | 6 | rule [loop-inv]: 7 | 8 | @nextPacket => @end // @nextPacket => @nextPacket does not work but I don't know why, 9 | 0 10 | (R:Int) => _:Int 11 | _:List => _:List 12 | _:List => _:List 13 | _:PacketList => $nilPacketList 14 | O1:PacketList => ?O2:PacketList 15 | 16 | requires (R ==Int 1 andBool (#onPort(O1, 0) ==Int #onPort(O1, 1)) ) 17 | orBool (R ==Int 0 andBool (#onPort(O1,0) ==Int (#onPort(O1,1) +Int 1))) 18 | ensures absInt(#onPort(?O2,0) -Int #onPort(?O2,1)) <=Int 1 19 | 20 | 21 | 22 | rule [spec]: 23 | 24 | @start => @end 25 | 0 26 | 1 => _:Int 27 | _:List => _:List 28 | _:List => _:List 29 | _:PacketList => $nilPacketList 30 | $nilPacketList => ?O2:PacketList 31 | 32 | ensures absInt(#onPort(?O2,0) -Int #onPort(?O2,1)) <=Int 1 33 | 34 | 35 | 36 | endmodule 37 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/ternary_match3.k: -------------------------------------------------------------------------------- 1 | 2 | 3 | ... 4 | 5 | 6 | ... 7 | test1 8 | .List => 9 | ListItem($rule(0, 10 | $ctr( 11 | ListItem($pair(@val(269554195,32,false),@val(4294967295,32,false))) ListItem($pair(@val(539042339,32,false),@val(4294967295,32,false))) ListItem($pair(@val(808530483,32,false),@val(4294967295,32,false))) ListItem($pair(@val(1078018627,32,false),@val(4294967295,32,false))) 12 | ), 13 | @call( 14 | String2Id("setb1"), 15 | $resolved( 16 | ListItem(@val(127,0,false)) ListItem(@val(2,0,false)) 17 | ) 18 | ) 19 | )) 20 | 21 | .K => .K 22 |
23 | 24 |
25 | 26 | .List => 27 | ListItem($packet("0001000000010001000100100001001100100000001000010010001000100011001100000011000100110010001100110100000001000001010000100100001101010101011001100111011110001000",0)) 28 | 29 | 30 | syntax Id ::= 31 | "test1" [token] 32 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/ternary_match0.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | header_type data_t { 19 | fields { 20 | f1 : 32; 21 | f2 : 32; 22 | f3 : 32; 23 | f4 : 32; 24 | b1 : 8; 25 | b2 : 8; 26 | b3 : 8; 27 | b4 : 8; 28 | } 29 | } 30 | header data_t data; 31 | 32 | parser start { 33 | extract(data); 34 | return ingress; 35 | } 36 | 37 | action noop() { } 38 | 39 | table test1 { 40 | reads { 41 | data.f1 : ternary; 42 | } 43 | actions { 44 | noop; 45 | } 46 | } 47 | 48 | control ingress { 49 | apply(test1); 50 | } 51 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/gateway8.expected: -------------------------------------------------------------------------------- 1 | 000000010000000100000001000000010000000100000001000000010000000100000001000000010111011110001000 2 2 | 000000010000000100000001000000010000000100000001000000010000000100000001000000100111011110001000 2 3 | 000000010000000100000001000000010000000100000001000000010000000100000010000000110111011110001000 3 4 | 000000010000000100000001000000010000000100000001000000010000000100000010000001000111011110001000 3 5 | 000000010000000100000001000000010000000100000001000000010000000100000001000001010111011110001000 2 6 | 000000010000000100000001000000010000000100000001000000010000000100000010000001100111011110001000 3 7 | 000000010000000100000001000000010000000100000001000000010000000100000001000010100111011110001000 2 8 | 000000010000000100000001000000010000000100000001000000010000000100000010000010110111011110001000 3 9 | 000000010000000100000001000000010000000100000001000000010000000100000001000100010111011110001000 2 10 | 000000010000000100000001000000010000000100000001000000010000000100000010000100100111011110001000 3 11 | 000000010000000100000001000000010000000100000001000000010000000100000001000100110111011110001000 2 12 | 000000010000000100000001000000010000000100000001000000010000000100000010000101000111011110001000 3 -------------------------------------------------------------------------------- /test/stf_tests/test_data/14-Counter.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | header_type ethernet_t { 18 | fields { 19 | dstAddr : 48; 20 | srcAddr : 48; 21 | ethertype : 16; 22 | } 23 | } 24 | 25 | header ethernet_t ethernet; 26 | 27 | parser start { 28 | extract(ethernet); 29 | return ingress; 30 | } 31 | 32 | counter c1 { 33 | type : packets; 34 | instance_count : 1024; 35 | } 36 | 37 | action count_c1_1() { 38 | count(c1, 1); 39 | } 40 | 41 | table t1 { 42 | actions { 43 | count_c1_1; 44 | } 45 | } 46 | 47 | control ingress { 48 | apply(t1); 49 | } 50 | 51 | control egress { 52 | } 53 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/instruct3.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | header_type data_t { 19 | fields { 20 | f1 : 32; 21 | f2 : 32; 22 | x1 : 2; 23 | x2 : 2; 24 | x3 : 2; 25 | x4 : 2; 26 | } 27 | } 28 | header data_t data; 29 | 30 | parser start { 31 | extract(data); 32 | return ingress; 33 | } 34 | 35 | action noop() { } 36 | action setx() { modify_field(data.x2, 2); modify_field(data.x4,1); } 37 | 38 | table test1 { 39 | reads { 40 | data.f1 : exact; 41 | } 42 | actions { 43 | setx; 44 | noop; 45 | } 46 | } 47 | 48 | control ingress { 49 | apply(test1); 50 | } 51 | -------------------------------------------------------------------------------- /experiments/assert-p4/NetPaxos/source/includes/parser.p4: -------------------------------------------------------------------------------- 1 | #ifndef _PARSER_P4_ 2 | #define _PARSER_P4_ 3 | 4 | // Parser for ethernet, ipv4, and udp headers 5 | 6 | #define ETHERTYPE_ARP 0x0806 7 | #define ETHERTYPE_IPV4 0x0800 8 | #define UDP_PROTOCOL 0x11 9 | #define ETHERTYPE_IPV6 0x86dd 10 | #define PAXOS_COORDINATOR 0x8888 11 | #define PAXOS_ACCEPTOR 0x8889 12 | 13 | parser start { 14 | return parse_ethernet; 15 | } 16 | 17 | parser parse_ethernet { 18 | extract(ethernet); 19 | return select(latest.etherType) { 20 | ETHERTYPE_ARP : parse_arp; 21 | ETHERTYPE_IPV4 : parse_ipv4; 22 | ETHERTYPE_IPV6 : parse_ipv6; 23 | default : ingress; 24 | } 25 | } 26 | 27 | parser parse_arp { 28 | extract(arp); 29 | return ingress; 30 | } 31 | 32 | parser parse_ipv4 { 33 | extract(ipv4); 34 | return select(latest.protocol) { 35 | UDP_PROTOCOL : parse_udp; 36 | default : ingress; 37 | } 38 | } 39 | 40 | parser parse_ipv6 { 41 | extract(ipv6); 42 | return ingress; 43 | } 44 | 45 | parser parse_udp { 46 | extract(udp); 47 | return select(udp.dstPort) { 48 | PAXOS_COORDINATOR : parse_paxos; 49 | PAXOS_ACCEPTOR : parse_paxos; 50 | default: ingress; 51 | } 52 | } 53 | 54 | 55 | #endif -------------------------------------------------------------------------------- /test/stf_tests/test_data/issue60.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 VMware, Inc. 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 | header_type ethernet_t { 17 | fields { 18 | dstAddr : 48; 19 | srcAddr : 48; 20 | ethertype : 16; 21 | } 22 | } 23 | 24 | header ethernet_t ethernet; 25 | 26 | parser start { 27 | extract(ethernet); 28 | return ingress; 29 | } 30 | 31 | action set_egress_port(port) { 32 | modify_field(standard_metadata.egress_spec, port); 33 | } 34 | 35 | table t1 { 36 | reads { 37 | ethernet.dstAddr : lpm; 38 | ethernet.srcAddr : lpm; 39 | } 40 | actions { 41 | set_egress_port; 42 | } 43 | } 44 | 45 | control ingress { 46 | apply(t1); 47 | } 48 | 49 | control egress { 50 | } -------------------------------------------------------------------------------- /test/semantics/features/header_actions/add_header.k: -------------------------------------------------------------------------------- 1 | 2 | ... 3 | 4 | ... 5 | t 6 | .List => ( 7 | ListItem( 8 | $rule(0, 9 | $ctr(ListItem(@val ( 1 , 0 , false ))) 10 | , @call(String2Id("a") , $resolved( .List ) ) ) 11 | ) 12 | ) 13 | 14 |
15 | ... 16 |
17 | 18 | // . => "00000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000001000000000000100010100000000000000000100010010101101000010110000000000000000010000000001000101110010011100100000101000000000000000000000000100001010000000000000000000000000" 19 | 20 | .List => 21 | ListItem($packet( 22 | ListItem(@val(1,4,false)) //f1 23 | ListItem(@val(2,4,false)) //f2 24 | , 1 //port 25 | )) 26 | 27 | ... 28 | 29 | 30 | syntax Id ::= "t" [token] 31 | -------------------------------------------------------------------------------- /test/semantics/features/header_actions/copy_header.k: -------------------------------------------------------------------------------- 1 | 2 | ... 3 | 4 | ... 5 | t 6 | .List => ( 7 | ListItem( 8 | $rule(0, 9 | $ctr(ListItem(@val ( 1 , 0 , false ))) 10 | , @call(String2Id("a") , $resolved( .List ) ) ) 11 | ) 12 | ) 13 | 14 |
15 | ... 16 |
17 | 18 | // . => "00000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000001000000000000100010100000000000000000100010010101101000010110000000000000000010000000001000101110010011100100000101000000000000000000000000100001010000000000000000000000000" 19 | 20 | .List => 21 | ListItem($packet( 22 | ListItem(@val(1,4,false)) //f1 23 | ListItem(@val(1,4,false)) //f2 24 | , 1 //port 25 | )) 26 | 27 | ... 28 | 29 | 30 | syntax Id ::= "t" [token] 31 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/03-DeadMetadata3.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | parser start { 18 | return ingress; 19 | } 20 | 21 | header_type m_t { 22 | fields { 23 | f1 : 32; 24 | f2 : 32; 25 | } 26 | } 27 | 28 | metadata m_t m; 29 | 30 | action a1() { 31 | modify_field(m.f1, 1); 32 | } 33 | 34 | table t1 { 35 | actions { 36 | a1; 37 | } 38 | } 39 | 40 | action a2() { 41 | modify_field(m.f2, 2); 42 | } 43 | 44 | table t2 { 45 | reads { 46 | m.f1 : exact; 47 | } 48 | actions { 49 | a2; 50 | } 51 | } 52 | 53 | control ingress { 54 | apply(t1); 55 | apply(t2); 56 | } 57 | 58 | control egress { 59 | } 60 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/14-GatewayGreaterThan.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | header_type ethernet_t { 18 | fields { 19 | dstAddr : 48; 20 | srcAddr : 48; 21 | ethertype : 16; 22 | } 23 | } 24 | 25 | header ethernet_t ethernet; 26 | 27 | header_type h_t { 28 | fields { 29 | f1 : 13; 30 | } 31 | } 32 | 33 | header h_t h; 34 | 35 | parser start { 36 | extract(ethernet); 37 | return ingress; 38 | } 39 | 40 | action nop() { 41 | } 42 | 43 | table t1 { 44 | actions { 45 | nop; 46 | } 47 | } 48 | 49 | control ingress { 50 | if (h.f1 > 1) { 51 | apply(t1); 52 | } 53 | } 54 | 55 | control egress { 56 | } 57 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/do_nothing.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | /* Sample P4 program */ 18 | header_type ethernet_t { 19 | fields { 20 | dstAddr : 48; 21 | srcAddr : 48; 22 | etherType : 16; 23 | } 24 | } 25 | 26 | parser start { 27 | return parse_ethernet; 28 | } 29 | 30 | header ethernet_t ethernet; 31 | 32 | parser parse_ethernet { 33 | extract(ethernet); 34 | return ingress; 35 | } 36 | 37 | action action_0(){ 38 | no_op(); 39 | } 40 | 41 | table table_0 { 42 | reads { 43 | ethernet.etherType : ternary; 44 | } 45 | actions { 46 | action_0; 47 | } 48 | } 49 | 50 | control ingress { 51 | apply(table_0); 52 | } 53 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/instruct4.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | header_type data_t { 18 | fields { 19 | f1 : 32; 20 | f2 : 32; 21 | f3 : 32; 22 | f4 : 32; 23 | b1 : 8; 24 | b2 : 8; 25 | b3 : 8; 26 | b4 : 8; 27 | } 28 | } 29 | header data_t data; 30 | 31 | parser start { 32 | extract(data); 33 | return ingress; 34 | } 35 | 36 | action noop() { } 37 | action setf4() { modify_field(data.f4, 0x70a50); } 38 | 39 | table test1 { 40 | reads { 41 | data.f1 : exact; 42 | } 43 | actions { 44 | setf4; 45 | noop; 46 | } 47 | } 48 | 49 | control ingress { 50 | apply(test1); 51 | } 52 | -------------------------------------------------------------------------------- /src/stf/stf-test.k: -------------------------------------------------------------------------------- 1 | require "../p4-semantics.k" 2 | 3 | 4 | module STF-TEST-COMMON 5 | imports ACTION-SYNTAX 6 | imports INT 7 | 8 | 9 | syntax STFTableMatches ::= List{STFTableMatch, ""} 10 | syntax STFTableMatch ::= Id ":" UnsignedValue 11 | syntax STFACtionCall ::= Id "(" Args ")" 12 | 13 | syntax STFTestCommands ::= List{STFTestCommand, ""} 14 | syntax STFTestCommand ::= 15 | "setdefault" STFACtionCall 16 | | "add" STFTableMatches STFACtionCall 17 | | "packet" Int Int 18 | | "expect" Int HexaDecimalString 19 | 20 | syntax HexaDecimalString ::= HexaDecimalStringToken 21 | syntax HexaDecimalStringToken [token] 22 | 23 | syntax STFPgm ::= STFTestCommands 24 | 25 | endmodule 26 | 27 | module STF-TEST-SYNTAX 28 | imports STF-TEST-COMMON 29 | //imports P4-TOKEN-SYNTAX 30 | 31 | //syntax HexaDecimalStringToken ::= r"[0-9a-fA-F\\ ]+" [token] 32 | //syntax #Layout ::= r"(#[^\\n\\r]*)" // "#" 33 | // | r"([\\ \\n\\r\\t])" // Whitespace 34 | // | r"(//[^\\n\\r]*)" // "//" 35 | 36 | endmodule 37 | 38 | module STF-TEST-SEMANTICS 39 | imports STF-TEST-COMMON 40 | imports P4-SEMANTICS 41 | 42 | configuration 43 | 44 | 45 | $STF:STFPgm 46 | 47 | 48 | endmodule -------------------------------------------------------------------------------- /test/stf_tests/test_data/07-MultiProtocol.stf: -------------------------------------------------------------------------------- 1 | setdefault ethertype_match l2_packet() 2 | add ethertype_match etherType:0x800 ipv4_packet() 3 | add ethertype_match etherType:0x86dd ipv6_packet() 4 | add ethertype_match etherType:0x8100 mpls_packet() 5 | add ethertype_match etherType:0x9100 mim_packet() 6 | 7 | add set_egress drop:0 send_packet() 8 | add set_egress drop:1 nop() 9 | 10 | add ipv4_match dstAddr:0xa000002 set_egress_port(egress_port:3) 11 | #add udp_check dstPort:0xaa drop() //Ali 12 | add udp_check dstPort:0xaa _drop() 13 | 14 | 15 | # | ethernet header | | IPv4 header | | UDP header | | payload ... 16 | # dstAddr srcAddr type VL len id ttl csum | sp dp len | | 17 | expect 3 aaaaaaaaaaaa bbbbbbbbbbbb 0800 4500 002c 0000 0065 40 11 6c55 01020304 0a000002 0064 0065 0010 0000 000102030405060708090a0b0c0d0e0f 18 | 19 | # first packet should be dropped by drop rule 20 | packet 0 aaaaaaaaaaaa bbbbbbbbbbbb 0800 4500 002c 0000 0065 40 11 6c55 01020304 0a000002 0064 00aa 0010 0000 000102030405060708090a0b0c0d0e0f 21 | # second packet should be forwarded to port 3 22 | packet 0 aaaaaaaaaaaa bbbbbbbbbbbb 0800 4500 002c 0000 0065 40 11 6c55 01020304 0a000002 0064 0065 0010 0000 000102030405060708090a0b0c0d0e0f 23 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/bigfield1.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | header_type data_t { 18 | fields { 19 | f1 : 32; 20 | f2 : 32; 21 | x1 : 48; 22 | b1 : 8; 23 | b2 : 8; 24 | } 25 | } 26 | header data_t data; 27 | 28 | parser start { 29 | extract(data); 30 | return ingress; 31 | } 32 | 33 | action noop() { } 34 | action setx1(val, port) { 35 | modify_field(data.x1, val); 36 | modify_field(standard_metadata.egress_spec, port); 37 | } 38 | 39 | table test1 { 40 | reads { 41 | data.f1 : exact; 42 | } 43 | actions { 44 | setx1; 45 | noop; 46 | } 47 | } 48 | 49 | control ingress { 50 | apply(test1); 51 | } 52 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/exact_match1.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | header_type data_t { 18 | fields { 19 | f1 : 32; 20 | f2 : 32; 21 | h1 : 16; 22 | b1 : 8; 23 | b2 : 8; 24 | } 25 | } 26 | header data_t data; 27 | 28 | parser start { 29 | extract(data); 30 | return ingress; 31 | } 32 | 33 | action noop() { } 34 | action setb1(val, port) { 35 | modify_field(data.b1, val); 36 | modify_field(standard_metadata.egress_spec, port); 37 | } 38 | 39 | table test1 { 40 | reads { 41 | data.f1 : exact; 42 | } 43 | actions { 44 | setb1; 45 | noop; 46 | } 47 | } 48 | 49 | control ingress { 50 | apply(test1); 51 | } 52 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/swap_1.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | header_type hdr1_t { 18 | fields { 19 | f1 : 8; 20 | f2 : 8; 21 | } 22 | } 23 | 24 | header hdr1_t hdr1; 25 | 26 | parser start { 27 | extract(hdr1); 28 | return ingress; 29 | } 30 | 31 | action a11() { 32 | modify_field(standard_metadata.egress_spec, 1); 33 | } 34 | 35 | action a12() { 36 | modify_field(standard_metadata.egress_spec, 2); 37 | } 38 | 39 | table t_ingress_1 { 40 | reads { 41 | hdr1.f1 : exact; 42 | } 43 | actions { 44 | a11; a12; 45 | } 46 | size : 128; 47 | } 48 | 49 | control ingress { 50 | apply(t_ingress_1); 51 | } 52 | 53 | control egress { 54 | } 55 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/hash_action_basic.p4: -------------------------------------------------------------------------------- 1 | header_type data_t { 2 | fields { 3 | f1 : 32; 4 | f2 : 32; 5 | h1 : 16; 6 | h2 : 16; 7 | h3 : 16; 8 | h4 : 16; 9 | } 10 | } 11 | 12 | header data_t data; 13 | 14 | header_type counter_metadata_t { 15 | fields { 16 | counter_index : 16; 17 | } 18 | } 19 | 20 | metadata counter_metadata_t counter_metadata; 21 | 22 | parser start { 23 | extract(data); 24 | return ingress; 25 | } 26 | 27 | action set_index(index, port) { 28 | modify_field(counter_metadata.counter_index, index); 29 | modify_field(standard_metadata.egress_spec, port); 30 | } 31 | 32 | table index_setter { 33 | reads { 34 | data.f1 : exact; 35 | data.f2 : exact; 36 | } 37 | actions { 38 | set_index; 39 | } 40 | size : 2048; 41 | } 42 | 43 | counter count1 { 44 | type : packets; 45 | static : stats; 46 | instance_count : 16384; 47 | min_width : 32; 48 | } 49 | 50 | action count_entries() { 51 | count(count1, counter_metadata.counter_index); 52 | } 53 | 54 | table stats { 55 | actions { 56 | count_entries; 57 | } 58 | //default_action: count_entries; //Ali 59 | } 60 | 61 | control ingress { 62 | apply(index_setter); 63 | apply(stats); 64 | } 65 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/exact_match_mask1.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | header_type data_t { 18 | fields { 19 | f1 : 32; 20 | f2 : 32; 21 | h1 : 16; 22 | b1 : 8; 23 | b2 : 8; 24 | } 25 | } 26 | header data_t data; 27 | 28 | parser start { 29 | extract(data); 30 | return ingress; 31 | } 32 | 33 | action noop() { } 34 | action setb1(val, port) { 35 | modify_field(data.b1, val); 36 | modify_field(standard_metadata.egress_spec, port); 37 | } 38 | 39 | table test1 { 40 | reads { 41 | data.f1 mask 0xff00ff : exact; 42 | } 43 | actions { 44 | setb1; 45 | noop; 46 | } 47 | } 48 | 49 | control ingress { 50 | apply(test1); 51 | } 52 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/truncate.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | header_type hdrA_t { 18 | fields { 19 | f1 : 8; 20 | f2 : 64; 21 | } 22 | } 23 | 24 | header hdrA_t hdrA; 25 | 26 | parser start { 27 | extract(hdrA); 28 | return ingress; 29 | } 30 | 31 | action _nop() { 32 | 33 | } 34 | 35 | action _truncate(new_length, port) { 36 | modify_field(standard_metadata.egress_spec, port); 37 | truncate(new_length); 38 | } 39 | 40 | table t_ingress { 41 | reads { 42 | hdrA.f1 : exact; 43 | } 44 | actions { 45 | _nop; _truncate; 46 | } 47 | size : 128; 48 | } 49 | 50 | control ingress { 51 | apply(t_ingress); 52 | } 53 | 54 | control egress { 55 | } 56 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/exact_match2.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | header_type data_t { 18 | fields { 19 | f1 : 32; 20 | f2 : 32; 21 | h1 : 16; 22 | b1 : 8; 23 | b2 : 8; 24 | } 25 | } 26 | header data_t data; 27 | 28 | parser start { 29 | extract(data); 30 | return ingress; 31 | } 32 | 33 | action noop() { } 34 | action setb1(val, port) { 35 | modify_field(data.b1, val); 36 | modify_field(standard_metadata.egress_spec, port); 37 | } 38 | 39 | table test1 { 40 | reads { 41 | data.f1 : exact; 42 | } 43 | actions { 44 | setb1; 45 | noop; 46 | } 47 | size: 10000; 48 | } 49 | 50 | control ingress { 51 | apply(test1); 52 | } 53 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/exact_match3.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | header_type data_t { 18 | fields { 19 | f1 : 32; 20 | f2 : 32; 21 | h1 : 16; 22 | b1 : 8; 23 | b2 : 8; 24 | } 25 | } 26 | header data_t data; 27 | 28 | parser start { 29 | extract(data); 30 | return ingress; 31 | } 32 | 33 | action noop() { } 34 | action setb1(val, port) { 35 | modify_field(data.b1, val); 36 | modify_field(standard_metadata.egress_spec, port); 37 | } 38 | 39 | table test1 { 40 | reads { 41 | data.f1 : exact; 42 | } 43 | actions { 44 | setb1; 45 | noop; 46 | } 47 | size: 300000; 48 | } 49 | 50 | control ingress { 51 | apply(test1); 52 | } 53 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/swap_2.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | header_type hdr2_t { 18 | fields { 19 | f1 : 8; 20 | f2 : 8; 21 | f3 : 16; 22 | } 23 | } 24 | 25 | header hdr2_t hdr2; 26 | 27 | parser start { 28 | extract(hdr2); 29 | return ingress; 30 | } 31 | 32 | action a21() { 33 | modify_field(standard_metadata.egress_spec, 3); 34 | } 35 | 36 | action a22() { 37 | modify_field(standard_metadata.egress_spec, 4); 38 | } 39 | 40 | table t_ingress_2 { 41 | reads { 42 | hdr2.f1 : exact; 43 | } 44 | actions { 45 | a21; a22; 46 | } 47 | size : 64; 48 | } 49 | 50 | control ingress { 51 | apply(t_ingress_2); 52 | } 53 | 54 | control egress { 55 | } 56 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/counter4.stf: -------------------------------------------------------------------------------- 1 | add tab1 ethernet.dstAddr:0xa1a2a3a4a5a6 act(port:2, idx:10) 2 | add tab1 ethernet.dstAddr:0xb1b2b3b4b5b6 act(port:3, idx:11) 3 | add tab1 ethernet.dstAddr:0xc1c2c3c4c5c6 act(port:5, idx:10) 4 | 5 | expect 2 6 | expect 3 7 | expect 5 8 | packet 0 a1a2a3a4a5a6 0000 9 | wait 10 | check_counter cntDum(10) packets == 1 11 | packet 0 a1a2a3a4a5a6 0001 12 | wait 13 | check_counter cntDum(10) packets == 2 14 | packet 0 a1a2a3a4a5a6 0002 15 | wait 16 | check_counter cntDum(10) packets == 3 17 | 18 | packet 0 b1b2b3b4b5b6 0001 19 | packet 0 b1b2b3b4b5b6 0002 20 | packet 0 b1b2b3b4b5b6 0003 21 | packet 0 b1b2b3b4b5b6 0004 22 | packet 0 b1b2b3b4b5b6 0005 23 | packet 0 b1b2b3b4b5b6 0006 24 | packet 0 b1b2b3b4b5b6 0007 25 | packet 0 b1b2b3b4b5b6 0008 26 | packet 0 b1b2b3b4b5b6 0009 27 | packet 0 b1b2b3b4b5b6 0010 28 | packet 0 b1b2b3b4b5b6 0011 29 | packet 0 b1b2b3b4b5b6 0012 30 | packet 0 b1b2b3b4b5b6 0013 31 | packet 0 b1b2b3b4b5b6 0014 32 | packet 0 b1b2b3b4b5b6 0015 33 | packet 0 b1b2b3b4b5b6 0016 34 | packet 0 b1b2b3b4b5b6 0017 35 | packet 0 b1b2b3b4b5b6 0018 36 | packet 0 b1b2b3b4b5b6 0019 37 | packet 0 b1b2b3b4b5b6 0020 38 | 39 | packet 0 c1c2c3c4c5c6 0001 40 | packet 0 c1c2c3c4c5c6 0002 41 | packet 0 c1c2c3c4c5c6 0003 42 | 43 | wait 44 | check_counter cntDum(10) packets == 6 45 | check_counter cntDum(11) packets == 20 46 | -------------------------------------------------------------------------------- /verification/verification-debug/size_balance_spec.k: -------------------------------------------------------------------------------- 1 | // also checked manually 2 | 3 | module SPEC 4 | imports LANG 5 | 6 | rule [loop-inv]: 7 | 8 | @nextPacket => @end // @nextPacket => @nextPacket does not work but I don't know why, 9 | 0 10 | (R:Int) => _:Int 11 | _:List => _:List 12 | _:List => _:List 13 | I:PacketList => $nilPacketList 14 | O1:PacketList => ?O2:PacketList 15 | 16 | requires (R ==Int 1 andBool (#onPort(O1, 0) ==Int #onPort(O1, 1)) ) 17 | orBool (R ==Int 0 andBool (#onPort(O1,0) ==Int (#onPort(O1,1) +Int 1))) 18 | ensures (absInt(#onPort(?O2,0) -Int #onPort(?O2,1)) <=Int 1) 19 | andBool (#packetListSize(I) +Int #packetListSize(O1) ==Int #packetListSize(?O2)) 20 | 21 | 22 | 23 | 24 | rule [spec]: 25 | 26 | @start => @end 27 | 0 28 | 1 => _:Int 29 | _:List => _:List 30 | _:List => _:List 31 | I:PacketList => $nilPacketList 32 | $nilPacketList => ?O:PacketList 33 | 34 | ensures (absInt(#onPort(?O,0) -Int #onPort(?O,1)) <=Int 1) 35 | andBool (#packetListSize(I) ==Int #packetListSize(?O)) 36 | 37 | 38 | 39 | endmodule 40 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/01-JustEthernet.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | header_type ethernet_t { 18 | fields { 19 | dstAddr : 48; 20 | srcAddr : 48; 21 | ethertype : 16; 22 | } 23 | } 24 | 25 | header ethernet_t ethernet; 26 | 27 | parser start { 28 | extract(ethernet); 29 | return ingress; 30 | } 31 | 32 | action nop() { 33 | } 34 | 35 | table t1 { 36 | reads { 37 | ethernet.dstAddr : exact; 38 | } 39 | actions { 40 | nop; 41 | } 42 | } 43 | 44 | table t2 { 45 | reads { 46 | ethernet.srcAddr : exact; 47 | } 48 | actions { 49 | nop; 50 | } 51 | } 52 | 53 | control ingress { 54 | // apply(t1); 55 | } 56 | 57 | control egress { 58 | // apply(t2); 59 | } 60 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/overflow.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | header_type metadata_t { 18 | fields { 19 | field_1_1_1 : 1; 20 | field_2_1_1 : 1; 21 | } 22 | } 23 | 24 | metadata metadata_t md; 25 | 26 | parser start { 27 | return ingress; 28 | } 29 | 30 | #define ACTION(w, n) \ 31 | action action_##w##_##n(value) { \ 32 | modify_field(md.field_1_##w##_##n, value); \ 33 | modify_field(md.field_2_##w##_##n, w##n); \ 34 | } 35 | 36 | ACTION(1, 1) 37 | 38 | table dmac { 39 | reads { 40 | } 41 | actions { 42 | action_1_1; 43 | } 44 | } 45 | 46 | control ingress { 47 | apply(dmac); 48 | } 49 | 50 | control egress { 51 | } 52 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/ternary_match1.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | header_type data_t { 19 | fields { 20 | f1 : 32; 21 | f2 : 32; 22 | f3 : 32; 23 | f4 : 32; 24 | b1 : 8; 25 | b2 : 8; 26 | h1 : 16; 27 | } 28 | } 29 | header data_t data; 30 | 31 | parser start { 32 | extract(data); 33 | return ingress; 34 | } 35 | 36 | action noop() { } 37 | action setb1(val, port) { 38 | modify_field(data.b1, val); 39 | modify_field(standard_metadata.egress_spec, port); 40 | } 41 | 42 | table test1 { 43 | reads { 44 | data.f1 : ternary; 45 | } 46 | actions { 47 | setb1; 48 | noop; 49 | } 50 | } 51 | 52 | control ingress { 53 | apply(test1); 54 | } 55 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/ternary_match2.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | header_type data_t { 19 | fields { 20 | f1 : 32; 21 | f2 : 32; 22 | f3 : 32; 23 | f4 : 32; 24 | b1 : 8; 25 | b2 : 8; 26 | } 27 | } 28 | header data_t data; 29 | 30 | parser start { 31 | extract(data); 32 | return ingress; 33 | } 34 | 35 | action noop() { } 36 | action setb1(val, port) { 37 | modify_field(data.b1, val); 38 | modify_field(standard_metadata.egress_spec, port); 39 | } 40 | 41 | table test1 { 42 | reads { 43 | data.f1 : ternary; 44 | } 45 | actions { 46 | setb1; 47 | noop; 48 | } 49 | size: 10000; 50 | } 51 | 52 | control ingress { 53 | apply(test1); 54 | } 55 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/tmvalid.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | header_type data_t { 19 | fields { 20 | f1 : 32; 21 | f2 : 32; 22 | f3 : 32; 23 | f4 : 32; 24 | b1 : 8; 25 | b2 : 8; 26 | h1 : 16; 27 | } 28 | } 29 | header data_t data; 30 | 31 | parser start { 32 | extract(data); 33 | return ingress; 34 | } 35 | 36 | action noop() { } 37 | action setb1(val, port) { 38 | modify_field(data.b1, val); 39 | modify_field(standard_metadata.egress_spec, port); 40 | } 41 | 42 | table test1 { 43 | reads { 44 | data.valid : ternary; 45 | data.f1 : ternary; 46 | } 47 | actions { 48 | setb1; 49 | noop; 50 | } 51 | } 52 | 53 | control ingress { 54 | apply(test1); 55 | } 56 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/counter3.stf: -------------------------------------------------------------------------------- 1 | #add tab1 ethernet.dstAddr:0xa1a2a3a4a5a6 act(port:2) = A 2 | #add tab1 ethernet.dstAddr:0xb1b2b3b4b5b6 act(port:3) = B 3 | #add tab1 ethernet.dstAddr:0xc1c2c3c4c5c6 act(port:5) = C 4 | #Ali 5 | add tab1 ethernet.dstAddr:0xa1a2a3a4a5a6 act(port:2) 6 | add tab1 ethernet.dstAddr:0xb1b2b3b4b5b6 act(port:3) 7 | add tab1 ethernet.dstAddr:0xc1c2c3c4c5c6 act(port:5) 8 | 9 | expect 2 10 | expect 3 11 | expect 5 12 | packet 0 a1a2a3a4a5a6 0000 13 | wait 14 | check_counter cnt($A) bytes == 8 15 | packet 0 a1a2a3a4a5a6 000100 16 | wait 17 | check_counter cnt($A) bytes == 17 18 | packet 0 a1a2a3a4a5a6 00020000 19 | wait 20 | check_counter cnt($A) bytes == 27 21 | 22 | packet 0 b1b2b3b4b5b6 0001 23 | packet 0 b1b2b3b4b5b6 0002 24 | packet 0 b1b2b3b4b5b6 0003 25 | packet 0 b1b2b3b4b5b6 0004 26 | packet 0 b1b2b3b4b5b6 0005 27 | packet 0 b1b2b3b4b5b6 0006 28 | packet 0 b1b2b3b4b5b6 0007 29 | packet 0 b1b2b3b4b5b6 0008 30 | packet 0 b1b2b3b4b5b6 0009 31 | packet 0 b1b2b3b4b5b6 0010 32 | packet 0 b1b2b3b4b5b6 0011 33 | packet 0 b1b2b3b4b5b6 0012 34 | packet 0 b1b2b3b4b5b6 0013 35 | packet 0 b1b2b3b4b5b6 0014 36 | packet 0 b1b2b3b4b5b6 0015 37 | packet 0 b1b2b3b4b5b6 0016 38 | packet 0 b1b2b3b4b5b6 0017 39 | packet 0 b1b2b3b4b5b6 0018 40 | packet 0 b1b2b3b4b5b6 0019 41 | packet 0 b1b2b3b4b5b6 0020 42 | 43 | wait 44 | check_counter cnt($A) bytes == 27 45 | check_counter cnt($B) bytes == 160 46 | -------------------------------------------------------------------------------- /verification/load-balancer/old-specs/2spec.k: -------------------------------------------------------------------------------- 1 | 2 | module SPEC 3 | imports P4-SEMANTICS 4 | 5 | syntax Id ::= "reg" [token] | "reg_val" [token] | "meta" [token] 6 | 7 | rule 8 | 9 | @nextPacket => @nextPacket 10 | 11 | 12 | standard_metadata 13 | _:Map => _:Map 14 | 15 | 16 | meta 17 | reg_val |-> (@val ( 0 , 8 , false ) => @val ( 1 , 8 , false )) 18 | 19 | 20 | 21 | 22 | reg 23 | .Map => (0 |-> @val(1,8,false)) 24 | 25 | 26 | .List => _ .Map => _ 27 | . => _ 28 | .List => _ 29 | 30 | 31 | 0 => _ 32 | . => _ 33 | . => _ 34 | . => _ 35 | 36 | 37 | 38 | ListItem($packet(.List,10)) => .List 39 | .List => ListItem($packet(.List,0)) 40 | 41 | 42 | 43 | endmodule 44 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/exact_match7.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | header_type data_t { 19 | fields { 20 | x1 : 3; 21 | f1 : 7; 22 | x2 : 6; 23 | f2 : 32; 24 | x3 : 5; 25 | f3 : 20; 26 | x4 : 7; 27 | f4 : 32; 28 | b1 : 8; 29 | b2 : 8; 30 | b3 : 8; 31 | b4 : 8; 32 | } 33 | } 34 | header data_t data; 35 | 36 | parser start { 37 | extract(data); 38 | return ingress; 39 | } 40 | 41 | action noop() { } 42 | action setb1(val) { modify_field(data.b1, val); } 43 | 44 | table test1 { 45 | reads { 46 | data.f1 : exact; 47 | data.f3 : exact; 48 | } 49 | actions { 50 | setb1; 51 | noop; 52 | } 53 | } 54 | 55 | control ingress { 56 | apply(test1); 57 | } 58 | -------------------------------------------------------------------------------- /test/semantics/features/header_actions/pop.k: -------------------------------------------------------------------------------- 1 | 2 | ... 3 | 4 | ... 5 | t 6 | .List => ( 7 | ListItem( 8 | $rule(0, 9 | $ctr(ListItem(@val ( 1 , 0 , false ))) 10 | , @call(String2Id("a") , $resolved( .List ) ) ) 11 | ) 12 | ) 13 | 14 |
15 | ... 16 |
17 | 18 | // . => "00000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000001000000000000100010100000000000000000100010010101101000010110000000000000000010000000001000101110010011100100000101000000000000000000000000100001010000000000000000000000000" 19 | 20 | .List => 21 | ListItem($packet( 22 | ListItem(@val(1,4,false)) //f1 23 | ListItem(@val(1,4,false)) //f2 24 | ListItem(@val(2,4,false)) //f1 25 | ListItem(@val(2,4,false)) //f2 26 | , 1 //port 27 | )) 28 | 29 | ... 30 | 31 | 32 | syntax Id ::= "t" [token] 33 | -------------------------------------------------------------------------------- /test/semantics/features/header_actions/push.k: -------------------------------------------------------------------------------- 1 | 2 | ... 3 | 4 | ... 5 | t 6 | .List => ( 7 | ListItem( 8 | $rule(0, 9 | $ctr(ListItem(@val ( 1 , 0 , false ))) 10 | , @call(String2Id("a") , $resolved( .List ) ) ) 11 | ) 12 | ) 13 | 14 |
15 | ... 16 |
17 | 18 | // . => "00000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000001000000000000100010100000000000000000100010010101101000010110000000000000000010000000001000101110010011100100000101000000000000000000000000100001010000000000000000000000000" 19 | 20 | .List => 21 | ListItem($packet( 22 | ListItem(@val(1,4,false)) //f1 23 | ListItem(@val(1,4,false)) //f2 24 | ListItem(@val(2,4,false)) //f1 25 | ListItem(@val(2,4,false)) //f2 26 | , 1 //port 27 | )) 28 | 29 | ... 30 | 31 | 32 | syntax Id ::= "t" [token] 33 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/counter1.stf: -------------------------------------------------------------------------------- 1 | 2 | #add tab1 ethernet.dstAddr:0xa1a2a3a4a5a6 act(port:2) = A 3 | #add tab1 ethernet.dstAddr:0xb1b2b3b4b5b6 act(port:3) = B 4 | #add tab1 ethernet.dstAddr:0xc1c2c3c4c5c6 act(port:5) = C 5 | #Ali 6 | add tab1 ethernet.dstAddr:0xa1a2a3a4a5a6 act(port:2) 7 | add tab1 ethernet.dstAddr:0xb1b2b3b4b5b6 act(port:3) 8 | add tab1 ethernet.dstAddr:0xc1c2c3c4c5c6 act(port:5) 9 | 10 | expect 2 11 | expect 3 12 | expect 5 13 | # check_counter cnt($A) 14 | packet 0 a1a2a3a4a5a6 15 | wait 16 | check_counter cnt($A) packets == 1 17 | packet 0 a1a2a3a4a5a6 18 | wait 19 | check_counter cnt($A) packets == 2 20 | packet 0 a1a2a3a4a5a6 21 | wait 22 | check_counter cnt($A) packets == 3 23 | 24 | packet 0 b1b2b3b4b5b6 0001 25 | packet 0 b1b2b3b4b5b6 0002 26 | packet 0 b1b2b3b4b5b6 0003 27 | packet 0 b1b2b3b4b5b6 0004 28 | packet 0 b1b2b3b4b5b6 0005 29 | packet 0 b1b2b3b4b5b6 0006 30 | packet 0 b1b2b3b4b5b6 0007 31 | packet 0 b1b2b3b4b5b6 0008 32 | packet 0 b1b2b3b4b5b6 0009 33 | packet 0 b1b2b3b4b5b6 0010 34 | packet 0 b1b2b3b4b5b6 0011 35 | packet 0 b1b2b3b4b5b6 0012 36 | packet 0 b1b2b3b4b5b6 0013 37 | packet 0 b1b2b3b4b5b6 0014 38 | packet 0 b1b2b3b4b5b6 0015 39 | packet 0 b1b2b3b4b5b6 0016 40 | packet 0 b1b2b3b4b5b6 0017 41 | packet 0 b1b2b3b4b5b6 0018 42 | packet 0 b1b2b3b4b5b6 0019 43 | packet 0 b1b2b3b4b5b6 0020 44 | 45 | wait 46 | check_counter cnt($A) packets == 3 47 | check_counter cnt($B) packets == 20 48 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/exact_match6.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | header_type data_t { 19 | fields { 20 | f1 : 32; 21 | f2 : 32; 22 | f3 : 32; 23 | f4 : 32; 24 | b1 : 8; 25 | b2 : 8; 26 | b3 : 8; 27 | b4 : 8; 28 | } 29 | } 30 | header data_t data; 31 | 32 | header_type meta_t { 33 | fields { 34 | sum : 32; 35 | } 36 | } 37 | metadata meta_t meta; 38 | 39 | parser start { 40 | extract(data); 41 | return ingress; 42 | } 43 | 44 | action noop() { } 45 | action addf2() { add(meta.sum, data.f2, 100); } 46 | 47 | table test1 { 48 | reads { 49 | data.f1 : exact; 50 | } 51 | actions { 52 | addf2; 53 | noop; 54 | } 55 | } 56 | 57 | control ingress { 58 | apply(test1); 59 | } 60 | -------------------------------------------------------------------------------- /test/semantics/features/default_action/default_action.k: -------------------------------------------------------------------------------- 1 | 2 | ... 3 | 4 | ... 5 | t 6 | .List => ( 7 | ListItem( 8 | $rule(0, 9 | $ctr(ListItem(@val ( 3 , 4 , false ))) 10 | , @call(String2Id("a") , $resolved( ListItem(@val(4,0,false)) ) ) ) 11 | ) 12 | ) 13 | 14 | .K => @call(String2Id("a") , $resolved( ListItem(@val(5,0,false)) ) ) 15 |
16 | ... 17 |
18 | 19 | // . => "00000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000001000000000000100010100000000000000000100010010101101000010110000000000000000010000000001000101110010011100100000101000000000000000000000000100001010000000000000000000000000" 20 | 21 | .List => 22 | ListItem($packet( 23 | ListItem(@val(1,4,false)) //f1 24 | ListItem(@val(2,4,false)) //f2 25 | , 1 //port 26 | )) 27 | 28 | ... 29 | 30 | 31 | syntax Id ::= "t" [token] 32 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/13-Counters1and2.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | header_type ethernet_t { 18 | fields { 19 | dstAddr : 48; 20 | srcAddr : 48; 21 | ethertype : 16; 22 | } 23 | } 24 | 25 | header ethernet_t ethernet; 26 | 27 | parser start { 28 | extract(ethernet); 29 | return ingress; 30 | } 31 | 32 | counter c1 { 33 | type : packets; 34 | instance_count : 1024; 35 | } 36 | 37 | action count_c1_1() { 38 | count(c1, 1); 39 | } 40 | 41 | action count_c1_2() { 42 | count(c1, 2); 43 | } 44 | 45 | table t1 { 46 | actions { 47 | count_c1_1; 48 | } 49 | } 50 | 51 | table t2 { 52 | actions { 53 | count_c1_2; 54 | } 55 | } 56 | 57 | control ingress { 58 | apply(t1); 59 | apply(t2); 60 | } 61 | 62 | control egress { 63 | } 64 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/ternary_match3.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | header_type data_t { 18 | fields { 19 | f1 : 32; 20 | f2 : 32; 21 | f3 : 32; 22 | f4 : 32; 23 | b1 : 8; 24 | b2 : 8; 25 | } 26 | } 27 | header data_t data; 28 | 29 | parser start { 30 | extract(data); 31 | return ingress; 32 | } 33 | 34 | action noop() { } 35 | action setb1(val, port) { 36 | modify_field(data.b1, val); 37 | modify_field(standard_metadata.egress_spec, port); 38 | } 39 | 40 | table test1 { 41 | reads { 42 | data.f1 : ternary; 43 | data.f2 : ternary; 44 | data.f3 : ternary; 45 | data.f4 : ternary; 46 | } 47 | actions { 48 | setb1; 49 | noop; 50 | } 51 | } 52 | 53 | control ingress { 54 | apply(test1); 55 | } 56 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/triv_eth.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | // Standard L2 Ethernet header 18 | header_type ethernet_t { 19 | fields { 20 | dst_addr : 48; // width in bits 21 | src_addr : 48; 22 | ethertype : 16; 23 | } 24 | } 25 | 26 | header ethernet_t ethernet; 27 | 28 | // just ethernet 29 | parser start { 30 | extract(ethernet); 31 | return ingress; 32 | } 33 | 34 | action route_eth(egress_spec, src_addr) { 35 | modify_field(standard_metadata.egress_spec, egress_spec); 36 | modify_field(ethernet.src_addr, src_addr); 37 | } 38 | action noop() { } 39 | 40 | table routing { 41 | reads { 42 | ethernet.dst_addr : lpm; 43 | } 44 | actions { 45 | route_eth; 46 | noop; 47 | } 48 | } 49 | 50 | control ingress { 51 | apply(routing); 52 | } 53 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/action_inline1.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | header_type data_t { 19 | fields { 20 | f1 : 32; 21 | f2 : 32; 22 | f3 : 32; 23 | f4 : 32; 24 | b1 : 8; 25 | b2 : 8; 26 | h1 : 16; 27 | } 28 | } 29 | header data_t data; 30 | 31 | parser start { 32 | extract(data); 33 | return ingress; 34 | } 35 | 36 | action setbyte(dest, val) { 37 | modify_field(dest, val); 38 | } 39 | 40 | action noop() { } 41 | action setb1(val, port) { 42 | setbyte(data.b1, val); 43 | modify_field(standard_metadata.egress_spec, port); 44 | } 45 | 46 | table test1 { 47 | reads { 48 | data.f1 : ternary; 49 | } 50 | actions { 51 | setb1; 52 | noop; 53 | } 54 | } 55 | 56 | control ingress { 57 | apply(test1); 58 | } 59 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/instruct6.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | header_type data_t { 18 | fields { 19 | f1 : 32; 20 | f2 : 32; 21 | h1 : 16; 22 | h2 : 16; 23 | b1 : 8; 24 | b2 : 8; 25 | } 26 | } 27 | header data_t data; 28 | 29 | parser start { 30 | extract(data); 31 | return ingress; 32 | } 33 | 34 | action noop() { } 35 | action op1(port) { 36 | modify_field_with_shift(data.h1, data.h2, 8, 0xff); 37 | modify_field(standard_metadata.egress_spec, port); 38 | } 39 | action op2(port) { 40 | modify_field_with_shift(data.h1, data.h2, 4, 0xf0); 41 | modify_field(standard_metadata.egress_spec, port); 42 | } 43 | 44 | table test1 { 45 | reads { data.f1 : exact; } 46 | actions { op1; op2; noop; } 47 | } 48 | 49 | control ingress { 50 | apply(test1); 51 | } 52 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/counter1.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | * Simple stat program. 19 | * Direct mapped, that does not go across stages 20 | */ 21 | 22 | header_type ethernet_t { 23 | fields { 24 | dstAddr : 48; 25 | } 26 | } 27 | parser start { 28 | return parse_ethernet; 29 | } 30 | 31 | header ethernet_t ethernet; 32 | 33 | parser parse_ethernet { 34 | extract(ethernet); 35 | return ingress; 36 | } 37 | action act(port) { 38 | modify_field(standard_metadata.egress_spec, port); 39 | } 40 | table tab1 { 41 | reads { 42 | ethernet.dstAddr : exact; 43 | } 44 | actions { 45 | act; 46 | } 47 | size: 128; 48 | } 49 | 50 | counter cnt { 51 | type: packets; 52 | direct: tab1; 53 | 54 | } 55 | control ingress { 56 | apply(tab1); 57 | } 58 | control egress { 59 | 60 | } 61 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/counter2.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | * Simple stat program. 19 | * Direct mapped, that does not go across stages 20 | */ 21 | 22 | header_type ethernet_t { 23 | fields { 24 | dstAddr : 48; 25 | } 26 | } 27 | parser start { 28 | return parse_ethernet; 29 | } 30 | 31 | header ethernet_t ethernet; 32 | 33 | parser parse_ethernet { 34 | extract(ethernet); 35 | return ingress; 36 | } 37 | action act(port) { 38 | modify_field(standard_metadata.egress_spec, port); 39 | } 40 | table tab1 { 41 | reads { 42 | ethernet.dstAddr : ternary; 43 | } 44 | actions { 45 | act; 46 | } 47 | size: 6100; 48 | } 49 | 50 | counter cnt { 51 | type: packets; 52 | direct: tab1; 53 | 54 | } 55 | control ingress { 56 | apply(tab1); 57 | } 58 | control egress { 59 | 60 | } 61 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/counter2.stf: -------------------------------------------------------------------------------- 1 | 2 | #add tab1 600 ethernet.dstAddr:0xa1a2a3a4a5a6 act(port:2) = A 3 | #add tab1 400 ethernet.dstAddr:0xb1b2b3b4b5b6 act(port:3) = B 4 | #add tab1 200 ethernet.dstAddr:0xc1c2c3c4c5c6 act(port:5) = C 5 | #Ali 6 | add tab1 600 ethernet.dstAddr:0xa1a2a3a4a5a6 act(port:2) 7 | add tab1 400 ethernet.dstAddr:0xb1b2b3b4b5b6 act(port:3) 8 | add tab1 200 ethernet.dstAddr:0xc1c2c3c4c5c6 act(port:5) 9 | 10 | expect 2 11 | expect 3 12 | expect 5 13 | check_counter cnt($A) 14 | packet 0 a1a2a3a4a5a6 0000 15 | wait 16 | check_counter cnt($A) packets == 1 17 | packet 0 a1a2a3a4a5a6 0001 18 | wait 19 | check_counter cnt($A) packets == 2 20 | packet 0 a1a2a3a4a5a6 0002 21 | wait 22 | check_counter cnt($A) packets == 3 23 | 24 | packet 0 b1b2b3b4b5b6 0001 25 | packet 0 b1b2b3b4b5b6 0002 26 | packet 0 b1b2b3b4b5b6 0003 27 | packet 0 b1b2b3b4b5b6 0004 28 | packet 0 b1b2b3b4b5b6 0005 29 | packet 0 b1b2b3b4b5b6 0006 30 | packet 0 b1b2b3b4b5b6 0007 31 | packet 0 b1b2b3b4b5b6 0008 32 | packet 0 b1b2b3b4b5b6 0009 33 | packet 0 b1b2b3b4b5b6 0010 34 | packet 0 b1b2b3b4b5b6 0011 35 | packet 0 b1b2b3b4b5b6 0012 36 | packet 0 b1b2b3b4b5b6 0013 37 | packet 0 b1b2b3b4b5b6 0014 38 | packet 0 b1b2b3b4b5b6 0015 39 | packet 0 b1b2b3b4b5b6 0016 40 | packet 0 b1b2b3b4b5b6 0017 41 | packet 0 b1b2b3b4b5b6 0018 42 | packet 0 b1b2b3b4b5b6 0019 43 | packet 0 b1b2b3b4b5b6 0020 44 | 45 | wait 46 | check_counter cnt($A) packets == 3 47 | check_counter cnt($B) packets == 20 48 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/ternary_match4.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | header_type data_t { 18 | fields { 19 | f1 : 32; 20 | f2 : 32; 21 | f3 : 32; 22 | f4 : 32; 23 | b1 : 8; 24 | b2 : 8; 25 | } 26 | } 27 | header data_t data; 28 | 29 | parser start { 30 | extract(data); 31 | return ingress; 32 | } 33 | 34 | action noop() { } 35 | action setb1(val, port) { 36 | modify_field(data.b1, val); 37 | modify_field(standard_metadata.egress_spec, port); 38 | } 39 | 40 | table test1 { 41 | reads { 42 | data.f1 : ternary; 43 | data.f2 : ternary; 44 | data.f3 : ternary; 45 | data.f4 : ternary; 46 | } 47 | actions { 48 | setb1; 49 | noop; 50 | } 51 | size: 10000; 52 | } 53 | 54 | control ingress { 55 | apply(test1); 56 | } 57 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/hash_action_gateway.p4: -------------------------------------------------------------------------------- 1 | 2 | header_type data_t { 3 | fields { 4 | f1 : 32; 5 | f2 : 32; 6 | h1 : 16; 7 | h2 : 16; 8 | h3 : 16; 9 | h4 : 16; 10 | } 11 | } 12 | 13 | header data_t data; 14 | 15 | header_type counter_metadata_t { 16 | fields { 17 | counter_index : 16; 18 | counter_run : 4; 19 | } 20 | } 21 | 22 | metadata counter_metadata_t counter_metadata; 23 | 24 | parser start { 25 | extract(data); 26 | return ingress; 27 | } 28 | 29 | action set_index(index, port) { 30 | modify_field(counter_metadata.counter_index, index); 31 | modify_field(standard_metadata.egress_spec, port); 32 | modify_field(counter_metadata.counter_run, 1); 33 | } 34 | 35 | table index_setter { 36 | reads { 37 | data.f1 : exact; 38 | data.f2 : exact; 39 | } 40 | actions { 41 | set_index; 42 | } 43 | size : 2048; 44 | } 45 | 46 | counter count1 { 47 | type : packets; 48 | static : stats; 49 | instance_count : 16384; 50 | min_width : 32; 51 | } 52 | 53 | action count_entries() { 54 | count(count1, counter_metadata.counter_index); 55 | } 56 | 57 | table stats { 58 | actions { 59 | count_entries; 60 | } 61 | //default_action : count_entries; //Ali 62 | } 63 | 64 | control ingress { 65 | apply(index_setter); 66 | if (counter_metadata.counter_run == 1) { 67 | apply(stats); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/12-Counters.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | header_type ethernet_t { 18 | fields { 19 | dstAddr : 48; 20 | srcAddr : 48; 21 | ethertype : 16; 22 | } 23 | } 24 | 25 | header ethernet_t ethernet; 26 | 27 | parser start { 28 | extract(ethernet); 29 | return ingress; 30 | } 31 | 32 | counter c1 { 33 | type : packets; 34 | instance_count : 1024; 35 | } 36 | 37 | action count_c1_1() { 38 | count(c1, 1); 39 | } 40 | 41 | table t1 { 42 | reads { 43 | ethernet.dstAddr : exact; 44 | } 45 | actions { 46 | count_c1_1; 47 | } 48 | } 49 | 50 | table t2 { 51 | reads { 52 | ethernet.srcAddr : exact; 53 | } 54 | actions { 55 | count_c1_1; 56 | } 57 | } 58 | 59 | control ingress { 60 | apply(t1); 61 | apply(t2); 62 | } 63 | 64 | control egress { 65 | } 66 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/counter4.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | * Simple program, just a direct mapped RAM 19 | */ 20 | 21 | header_type ethernet_t { 22 | fields { 23 | dstAddr : 48; 24 | } 25 | } 26 | parser start { 27 | return parse_ethernet; 28 | } 29 | 30 | header ethernet_t ethernet; 31 | 32 | parser parse_ethernet { 33 | extract(ethernet); 34 | return ingress; 35 | } 36 | action act(port, idx) { 37 | modify_field(standard_metadata.egress_spec, port); 38 | count(cntDum, idx); 39 | } 40 | table tab1 { 41 | reads { 42 | ethernet.dstAddr : exact; 43 | } 44 | actions { 45 | act; 46 | } 47 | size: 70000; 48 | } 49 | 50 | counter cntDum { 51 | type: packets; 52 | static: tab1; 53 | instance_count: 200; 54 | 55 | } 56 | control ingress { 57 | apply(tab1); 58 | } 59 | control egress { 60 | 61 | } 62 | -------------------------------------------------------------------------------- /verification/verification-debug/old-specs/4spec.k: -------------------------------------------------------------------------------- 1 | 2 | 3 | module SPEC 4 | imports LANG 5 | 6 | rule 7 | 8 | @nextPacket => @end // @nextPacket => @nextPacket does not work but I don't know why, 9 | 0 10 | (R1:Int) => ?R2:Int 11 | _:List => _:List 12 | _:List => _:List 13 | _:PacketList => $nilPacketList 14 | Lout:PacketList => ?Lout2:PacketList 15 | 16 | requires R1 ==Int 1 orBool R1 ==Int 0 17 | ensures ?R2 ==Int 0 orBool ?R2 ==Int 1 18 | //requires //absInt(#onPort(Lout,0) -Int #onPort(Lout,1)) <=Int 1 19 | 20 | //requires (R1 ==Int 1 orBool R1 ==Int 0) 21 | //andBool absInt(#onPort(Lout,0) -Int #onPort(Lout,1)) <=Int 1 22 | //ensures (?R2 ==Int 1 orBool ?R2 ==Int 0) 23 | 24 | //ensures 25 | // andBool 26 | // #onPort($consPacketList($packet(P,R2), Lout),0) -Int #onPort($consPacketList($packet(P,R2), Lout),1))) ==Int 1 27 | 28 | 29 | //rule 30 | // 31 | // @start => @end 32 | // 0 33 | // // R1:Int => ?R2:Int 34 | // 1 => _ 35 | // .List => _ 36 | // .List => _ 37 | // Lin:PacketList => $nilPacketList 38 | // $nilPacketList => ?Lout:PacketList 39 | // 40 | // 41 | //ensures absInt(#onPort(?Lout, 0) -Int #onPort(?Lout,1)) <=Int 1 42 | 43 | 44 | endmodule 45 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/instruct2.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | header_type data_t { 18 | fields { 19 | f1 : 32; 20 | f2 : 32; 21 | f3 : 32; 22 | f4 : 32; 23 | b1 : 8; 24 | b2 : 8; 25 | b3 : 8; 26 | b4 : 8; 27 | } 28 | } 29 | header data_t data; 30 | 31 | parser start { 32 | extract(data); 33 | return ingress; 34 | } 35 | 36 | action do_xor() { bit_xor(data.b1, data.b2, data.b3); } 37 | action do_and() { bit_and(data.b2, data.b3, data.b4); } 38 | action do_or() { bit_or(data.b4, data.b3, data.b1); } 39 | action do_add() { add(data.b3, data.b1, data.b2); } 40 | 41 | table test1 { 42 | reads { 43 | data.f1 : exact; 44 | } 45 | actions { 46 | do_add; 47 | do_and; 48 | do_or; 49 | do_xor; 50 | } 51 | } 52 | 53 | control ingress { 54 | apply(test1); 55 | } 56 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/exact_match1.k: -------------------------------------------------------------------------------- 1 | 2 | 3 | ... 4 | 5 | 6 | ... 7 | test1 8 | .List => 9 | ListItem($rule(0, 10 | $ctr( 11 | ListItem(@val(16843009,0,false)) 12 | ), 13 | @call( 14 | String2Id("setb1"), 15 | $resolved( 16 | ListItem(@val(127,0,false)) ListItem(@val(2,0,false)) 17 | ) 18 | ) 19 | )) 20 | 21 | 22 | ListItem($rule(1, 23 | $ctr( 24 | ListItem(@val(33686018,0,false)) 25 | ), 26 | @call( 27 | String2Id("setb1"), 28 | $resolved( 29 | ListItem(@val(7,0,false)) ListItem(@val(3,0,false)) 30 | ) 31 | ) 32 | )) 33 | 34 | .K => .K 35 |
36 | 37 |
38 | 39 | .List => 40 | ListItem($packet("0000000100000001000000010000000100000000000000000000001000000010000000110000001101010101011001100111011110001000",0)) 41 | ListItem($packet("0000001000000010000000100000001000000000000000000000001100000011000001000000010001010101011001100111011110001000",2)) 42 | 43 | 44 | syntax Id ::= 45 | "test1" [token] 46 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/exact_match2.k: -------------------------------------------------------------------------------- 1 | 2 | 3 | ... 4 | 5 | 6 | ... 7 | test1 8 | .List => 9 | ListItem($rule(0, 10 | $ctr( 11 | ListItem(@val(16843009,0,false)) 12 | ), 13 | @call( 14 | String2Id("setb1"), 15 | $resolved( 16 | ListItem(@val(127,0,false)) ListItem(@val(2,0,false)) 17 | ) 18 | ) 19 | )) 20 | 21 | 22 | ListItem($rule(1, 23 | $ctr( 24 | ListItem(@val(33686018,0,false)) 25 | ), 26 | @call( 27 | String2Id("setb1"), 28 | $resolved( 29 | ListItem(@val(7,0,false)) ListItem(@val(3,0,false)) 30 | ) 31 | ) 32 | )) 33 | 34 | .K => .K 35 |
36 | 37 |
38 | 39 | .List => 40 | ListItem($packet("0000000100000001000000010000000100000000000000000000001000000010000000110000001101010101011001100111011110001000",0)) 41 | ListItem($packet("0000001000000010000000100000001000000000000000000000001100000011000001000000010001010101011001100111011110001000",2)) 42 | 43 | 44 | syntax Id ::= 45 | "test1" [token] 46 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/exact_match3.k: -------------------------------------------------------------------------------- 1 | 2 | 3 | ... 4 | 5 | 6 | ... 7 | test1 8 | .List => 9 | ListItem($rule(0, 10 | $ctr( 11 | ListItem(@val(16843009,0,false)) 12 | ), 13 | @call( 14 | String2Id("setb1"), 15 | $resolved( 16 | ListItem(@val(127,0,false)) ListItem(@val(2,0,false)) 17 | ) 18 | ) 19 | )) 20 | 21 | 22 | ListItem($rule(1, 23 | $ctr( 24 | ListItem(@val(33686018,0,false)) 25 | ), 26 | @call( 27 | String2Id("setb1"), 28 | $resolved( 29 | ListItem(@val(7,0,false)) ListItem(@val(3,0,false)) 30 | ) 31 | ) 32 | )) 33 | 34 | .K => .K 35 |
36 | 37 |
38 | 39 | .List => 40 | ListItem($packet("0000000100000001000000010000000100000000000000000000001000000010000000110000001101010101011001100111011110001000",0)) 41 | ListItem($packet("0000001000000010000000100000001000000000000000000000001100000011000001000000010001010101011001100111011110001000",2)) 42 | 43 | 44 | syntax Id ::= 45 | "test1" [token] 46 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/exact_match_mask1.k: -------------------------------------------------------------------------------- 1 | 2 | 3 | ... 4 | 5 | 6 | ... 7 | test1 8 | .List => 9 | ListItem($rule(0, 10 | $ctr( 11 | ListItem(@val(65537,0,false)) 12 | ), 13 | @call( 14 | String2Id("setb1"), 15 | $resolved( 16 | ListItem(@val(127,0,false)) ListItem(@val(2,0,false)) 17 | ) 18 | ) 19 | )) 20 | 21 | 22 | ListItem($rule(1, 23 | $ctr( 24 | ListItem(@val(131074,0,false)) 25 | ), 26 | @call( 27 | String2Id("setb1"), 28 | $resolved( 29 | ListItem(@val(7,0,false)) ListItem(@val(3,0,false)) 30 | ) 31 | ) 32 | )) 33 | 34 | .K => .K 35 |
36 | 37 |
38 | 39 | .List => 40 | ListItem($packet("0000000100000001000000010000000100000000000000000000001000000010000000110000001101010101011001100111011110001000",0)) 41 | ListItem($packet("0000001000000010000000100000001000000000000000000000001100000011000001000000010001010101011001100111011110001000",2)) 42 | 43 | 44 | syntax Id ::= 45 | "test1" [token] 46 | -------------------------------------------------------------------------------- /test/semantics/features/exception/exception_handler.k: -------------------------------------------------------------------------------- 1 | 2 | ... 3 | 4 | ... 5 | t 6 | .List => ( 7 | ListItem( 8 | $rule(0, 9 | $ctr(ListItem(@val ( 0 , 0 , false ))) 10 | , @call(String2Id("noop") , $resolved( .List ) ) ) 11 | ) 12 | ) 13 | 14 |
15 | ... 16 |
17 | 18 | //00:00:00:00:00:01 00:00:00:00:00:00 .... TTL:64 .... 10.0.0.1 10.0.0.0 19 | //0000 0000 0001 0000 0000 0000 0800 4500 0044 ad0b 0000 4011 7272 0a00 0001 0a00 0000 20 | // . => "00000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000001000000000000100010100000000000000000100010010101101000010110000000000000000010000000001000101110010011100100000101000000000000000000000000100001010000000000000000000000000" 21 | 22 | .List => 23 | ListItem($packet( 24 | ListItem(@val(0,4,false)) //f1 25 | //ListItem(@val(1,4,false)) //f2 26 | , 1 //port 27 | )) 28 | 29 | ... 30 | 31 | 32 | syntax Id ::= "t" [token] 33 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/instruct6.k: -------------------------------------------------------------------------------- 1 | 2 | 3 | ... 4 | 5 | 6 | ... 7 | test1 8 | .List => 9 | ListItem($rule(0, 10 | $ctr( 11 | ListItem(@val(16843009,0,false)) 12 | ), 13 | @call( 14 | String2Id("op1"), 15 | $resolved( 16 | ListItem(@val(2,0,false)) 17 | ) 18 | ) 19 | )) 20 | 21 | 22 | ListItem($rule(1, 23 | $ctr( 24 | ListItem(@val(33686018,0,false)) 25 | ), 26 | @call( 27 | String2Id("op2"), 28 | $resolved( 29 | ListItem(@val(3,0,false)) 30 | ) 31 | ) 32 | )) 33 | 34 | .K => .K 35 |
36 | 37 |
38 | 39 | .List => 40 | ListItem($packet("000000010000000100000001000000010000001000000010000000100000001000010001001000100011001101000100010101010110011001110111100010001001100110101010",0)) 41 | ListItem($packet("000000100000001000000010000000100000000100000001000000010000000100010001001000100011001101000100010101010110011001110111100010001001100110101010",0)) 42 | 43 | 44 | syntax Id ::= 45 | "test1" [token] 46 | -------------------------------------------------------------------------------- /test/semantics/features/exception/exception_out_of_packet.k: -------------------------------------------------------------------------------- 1 | 2 | ... 3 | 4 | ... 5 | t 6 | .List => ( 7 | ListItem( 8 | $rule(0, 9 | $ctr(ListItem(@val ( 0 , 0 , false ))) 10 | , @call(String2Id("noop") , $resolved( .List ) ) ) 11 | ) 12 | ) 13 | 14 |
15 | ... 16 |
17 | 18 | //00:00:00:00:00:01 00:00:00:00:00:00 .... TTL:64 .... 10.0.0.1 10.0.0.0 19 | //0000 0000 0001 0000 0000 0000 0800 4500 0044 ad0b 0000 4011 7272 0a00 0001 0a00 0000 20 | // . => "00000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000001000000000000100010100000000000000000100010010101101000010110000000000000000010000000001000101110010011100100000101000000000000000000000000100001010000000000000000000000000" 21 | 22 | .List => 23 | ListItem($packet( 24 | ListItem(@val(0,4,false)) //f1 25 | //ListItem(@val(1,4,false)) //f2 26 | , 1 //port 27 | )) 28 | 29 | ... 30 | 31 | 32 | syntax Id ::= "t" [token] 33 | -------------------------------------------------------------------------------- /test/semantics/features/exception/exception_unhandled_select.k: -------------------------------------------------------------------------------- 1 | 2 | ... 3 | 4 | ... 5 | t 6 | .List => ( 7 | ListItem( 8 | $rule(0, 9 | $ctr(ListItem(@val ( 0 , 0 , false ))) 10 | , @call(String2Id("noop") , $resolved( .List ) ) ) 11 | ) 12 | ) 13 | 14 |
15 | ... 16 |
17 | 18 | //00:00:00:00:00:01 00:00:00:00:00:00 .... TTL:64 .... 10.0.0.1 10.0.0.0 19 | //0000 0000 0001 0000 0000 0000 0800 4500 0044 ad0b 0000 4011 7272 0a00 0001 0a00 0000 20 | // . => "00000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000001000000000000100010100000000000000000100010010101101000010110000000000000000010000000001000101110010011100100000101000000000000000000000000100001010000000000000000000000000" 21 | 22 | .List => 23 | ListItem($packet( 24 | ListItem(@val(0,4,false)) //f1 25 | ListItem(@val(1,4,false)) //f2 26 | , 1 //port 27 | )) 28 | 29 | ... 30 | 31 | 32 | syntax Id ::= "t" [token] 33 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/counter5.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | * Simple program, just a direct mapped RAM 19 | */ 20 | 21 | header_type ethernet_t { 22 | fields { 23 | dstAddr : 48; 24 | } 25 | } 26 | parser start { 27 | return parse_ethernet; 28 | } 29 | 30 | header ethernet_t ethernet; 31 | 32 | parser parse_ethernet { 33 | extract(ethernet); 34 | return ingress; 35 | } 36 | action act(port, idx) { 37 | modify_field(standard_metadata.egress_spec, port); 38 | count(cntDum, idx); 39 | } 40 | table tab1 { 41 | reads { 42 | ethernet.dstAddr : exact; 43 | } 44 | actions { 45 | act; 46 | } 47 | size: 160000; 48 | } 49 | 50 | counter cntDum { 51 | type: packets; 52 | static: tab1; 53 | instance_count: 70000; 54 | min_width:64; 55 | } 56 | control ingress { 57 | apply(tab1); 58 | } 59 | control egress { 60 | 61 | } 62 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/gateway7.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | header_type data_t { 18 | fields { 19 | f1 : 32; 20 | f2 : 32; 21 | b1 : 8; 22 | b2 : 8; 23 | b3 : 8; 24 | b4 : 8; 25 | } 26 | } 27 | header data_t data; 28 | 29 | parser start { 30 | extract(data); 31 | return ingress; 32 | } 33 | 34 | action noop() { } 35 | action output(port) { modify_field(standard_metadata.egress_spec, port); } 36 | 37 | table test1 { 38 | reads { 39 | data.f1 : exact; 40 | } 41 | actions { 42 | output; 43 | noop; 44 | } 45 | } 46 | table test2 { 47 | reads { 48 | data.f2 : exact; 49 | } 50 | actions { 51 | output; 52 | noop; 53 | } 54 | } 55 | 56 | control ingress { 57 | if (data.b2 > 49) { 58 | apply(test1); 59 | } else { 60 | apply(test2); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /test/semantics/features/exception/exception_index_out_of_bound.k: -------------------------------------------------------------------------------- 1 | 2 | ... 3 | 4 | ... 5 | t 6 | .List => ( 7 | ListItem( 8 | $rule(0, 9 | $ctr(ListItem(@val ( 0 , 0 , false ))) 10 | , @call(String2Id("noop") , $resolved( .List ) ) ) 11 | ) 12 | ) 13 | 14 |
15 | ... 16 |
17 | 18 | //00:00:00:00:00:01 00:00:00:00:00:00 .... TTL:64 .... 10.0.0.1 10.0.0.0 19 | //0000 0000 0001 0000 0000 0000 0800 4500 0044 ad0b 0000 4011 7272 0a00 0001 0a00 0000 20 | // . => "00000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000001000000000000100010100000000000000000100010010101101000010110000000000000000010000000001000101110010011100100000101000000000000000000000000100001010000000000000000000000000" 21 | 22 | .List => 23 | ListItem($packet( 24 | ListItem(@val(0,4,false)) //f1 25 | ListItem(@val(1,4,false)) //f2 26 | , 1 //port 27 | )) 28 | 29 | ... 30 | 31 | 32 | syntax Id ::= "t" [token] 33 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/gateway6.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | header_type data_t { 18 | fields { 19 | f1 : 32; 20 | f2 : 32; 21 | b1 : 8; 22 | b2 : 8; 23 | b3 : 8; 24 | b4 : 8; 25 | } 26 | } 27 | header data_t data; 28 | 29 | parser start { 30 | extract(data); 31 | return ingress; 32 | } 33 | 34 | action noop() { } 35 | action output(port) { modify_field(standard_metadata.egress_spec, port); } 36 | 37 | table test1 { 38 | reads { 39 | data.f1 : exact; 40 | } 41 | actions { 42 | output; 43 | noop; 44 | } 45 | } 46 | table test2 { 47 | reads { 48 | data.f2 : exact; 49 | } 50 | actions { 51 | output; 52 | noop; 53 | } 54 | } 55 | 56 | control ingress { 57 | if (1 == (15 & data.b2)) { 58 | apply(test1); 59 | } else { 60 | apply(test2); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/gateway1.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | header_type data_t { 18 | fields { 19 | f1 : 32; 20 | f2 : 32; 21 | b1 : 8; 22 | b2 : 8; 23 | } 24 | } 25 | header data_t data; 26 | 27 | parser start { 28 | extract(data); 29 | return ingress; 30 | } 31 | 32 | action noop() { } 33 | action setb1(val, port) { 34 | modify_field(data.b1, val); 35 | modify_field(standard_metadata.egress_spec, port); 36 | } 37 | 38 | 39 | table test1 { 40 | reads { 41 | data.f1 : exact; 42 | } 43 | actions { 44 | setb1; 45 | noop; 46 | } 47 | } 48 | table test2 { 49 | reads { 50 | data.f2 : exact; 51 | } 52 | actions { 53 | setb1; 54 | noop; 55 | } 56 | } 57 | 58 | control ingress { 59 | if (data.b2 == 1) { 60 | apply(test1); 61 | } else { 62 | apply(test2); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /verification/verification-debug/old-specs/3spec.k: -------------------------------------------------------------------------------- 1 | 2 | 3 | module SPEC 4 | imports LANG 5 | 6 | rule 7 | 8 | @nextPacket => @nextPacket 9 | 0 10 | // R1:Int => ?R2:Int 11 | R1:Int 12 | .List => _ 13 | .List => _ 14 | $consPacketList($packet(P1:List,_:Int) , $consPacketList($packet(P2:List,_:Int) , Lin:PacketList)) => Lin 15 | Lout:PacketList => $consPacketList($packet(P2,R1) , $consPacketList($packet(P1,?R2:Int) , Lout)) 16 | // Lout:PacketList => $consPacketList($packet(P,0) , Lout) 17 | 18 | //requires //absInt(#onPort(Lout,0) -Int #onPort(Lout,1)) <=Int 1 19 | 20 | requires (R1 ==Int 1 orBool R1 ==Int 0) 21 | //andBool absInt(#onPort(Lout,0) -Int #onPort(Lout,1)) <=Int 1 22 | ensures (?R2 ==Int 1 orBool ?R2 ==Int 0) 23 | 24 | //ensures 25 | // andBool 26 | // #onPort($consPacketList($packet(P,R2), Lout),0) -Int #onPort($consPacketList($packet(P,R2), Lout),1))) ==Int 1 27 | 28 | 29 | rule 30 | 31 | @start => @end 32 | 0 33 | // R1:Int => ?R2:Int 34 | 1 => _ 35 | .List => _ 36 | .List => _ 37 | Lin:PacketList => $nilPacketList 38 | $nilPacketList => ?Lout:PacketList 39 | 40 | 41 | //ensures absInt(#onPort(?Lout, 0) -Int #onPort(?Lout,1)) <=Int 1 42 | 43 | 44 | endmodule 45 | -------------------------------------------------------------------------------- /test/semantics/features/header_actions/remove_header.k: -------------------------------------------------------------------------------- 1 | 2 | ... 3 | 4 | ... 5 | t 6 | .List => ( 7 | ListItem( 8 | $rule(0, 9 | $ctr(ListItem(@val ( 1 , 0 , false ))) 10 | , @call(String2Id("a") , $resolved( .List ) ) ) 11 | ) 12 | ) 13 | 14 |
15 | ... 16 |
17 | 18 | // . => "00000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000001000000000000100010100000000000000000100010010101101000010110000000000000000010000000001000101110010011100100000101000000000000000000000000100001010000000000000000000000000" 19 | 20 | .List => 21 | ListItem($packet( 22 | ListItem(@val(1,4,false)) //f1 23 | ListItem(@val(1,4,false)) //f2 24 | ListItem(@val(2,4,false)) //f1 25 | ListItem(@val(2,4,false)) //f2 26 | ListItem(@val(3,4,false)) //f1 27 | ListItem(@val(3,4,false)) //f2 28 | , 1 //port 29 | )) 30 | 31 | ... 32 | 33 | 34 | syntax Id ::= "t" [token] 35 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/counter3.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | * Simple stat program. 19 | * Statically mapped, that should be optimized away by the compiler 20 | * because there isn't a count primitive in any of the actions 21 | * 22 | */ 23 | 24 | header_type ethernet_t { 25 | fields { 26 | dstAddr : 48; 27 | } 28 | } 29 | parser start { 30 | return parse_ethernet; 31 | } 32 | 33 | header ethernet_t ethernet; 34 | 35 | parser parse_ethernet { 36 | extract(ethernet); 37 | return ingress; 38 | } 39 | action act(port) { 40 | modify_field(standard_metadata.egress_spec, port); 41 | } 42 | table tab1 { 43 | reads { 44 | ethernet.dstAddr : exact; 45 | } 46 | actions { 47 | act; 48 | } 49 | size: 128; 50 | } 51 | 52 | counter cnt { 53 | type: bytes; 54 | direct: tab1; 55 | } 56 | 57 | control ingress { 58 | apply(tab1); 59 | } 60 | control egress { 61 | 62 | } 63 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/exact_match9.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | header_type data_t { 19 | fields { 20 | f1 : 32; 21 | f2 : 32; 22 | f3 : 32; 23 | f4 : 32; 24 | b1 : 8; 25 | b2 : 8; 26 | b3 : 8; 27 | b4 : 8; 28 | } 29 | } 30 | header data_t data; 31 | 32 | parser start { 33 | extract(data); 34 | return ingress; 35 | } 36 | 37 | action noop() { } 38 | action setb1(val) { modify_field(data.b1, val); } 39 | action setb2(val) { modify_field(data.b2, val); } 40 | action setb3(val) { modify_field(data.b3, val); } 41 | action setb4(val) { modify_field(data.b4, val); } 42 | 43 | table test1 { 44 | reads { 45 | data.f1 : exact; 46 | } 47 | actions { 48 | noop; 49 | setb1; 50 | setb2; 51 | setb3; 52 | setb4; 53 | } 54 | } 55 | 56 | control ingress { 57 | if (data.f2 != 0) { 58 | apply(test1); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/action_inline2.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | header_type data_t { 19 | fields { 20 | f1 : 32; 21 | f2 : 32; 22 | f3 : 32; 23 | f4 : 32; 24 | b1 : 8; 25 | b2 : 8; 26 | h1 : 16; 27 | } 28 | } 29 | header data_t data; 30 | 31 | parser start { 32 | extract(data); 33 | return ingress; 34 | } 35 | 36 | action copy2(dest, val) { 37 | modify_field(dest, val); 38 | } 39 | 40 | action copy(dest, val) { 41 | copy2(dest, val); 42 | } 43 | 44 | action setbyte(dest, val) { 45 | copy(dest, val); 46 | } 47 | 48 | action noop() { } 49 | action setb1(port) { 50 | setbyte(data.b1, data.b2); 51 | modify_field(standard_metadata.egress_spec, port); 52 | } 53 | 54 | table test1 { 55 | reads { 56 | data.f1 : ternary; 57 | } 58 | actions { 59 | setb1; 60 | noop; 61 | } 62 | } 63 | 64 | control ingress { 65 | apply(test1); 66 | } 67 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/bigfield1.k: -------------------------------------------------------------------------------- 1 | 2 | 3 | ... 4 | 5 | 6 | ... 7 | test1 8 | .List => 9 | ListItem($rule(0, 10 | $ctr( 11 | ListItem(@val(16843009,0,false)) 12 | ), 13 | @call( 14 | String2Id("setx1"), 15 | $resolved( 16 | ListItem(@val(89340438974721,0,false)) ListItem(@val(2,0,false)) 17 | ) 18 | ) 19 | )) 20 | 21 | 22 | ListItem($rule(1, 23 | $ctr( 24 | ListItem(@val(33686018,0,false)) 25 | ), 26 | @call( 27 | String2Id("setx1"), 28 | $resolved( 29 | ListItem(@val(0,0,false)) ListItem(@val(3,0,false)) 30 | ) 31 | ) 32 | )) 33 | 34 | .K => .K 35 |
36 | 37 |
38 | 39 | .List => 40 | ListItem($packet("000000010000000100000001000000010000000000000000000000100000001000000011000000110000001100000011000000110000001101010101011001100111011110001000",0)) 41 | ListItem($packet("000000100000001000000010000000100000000000000000000000110000001100000100000001000000010000000100000001000000010001010101011001100111011110001000",2)) 42 | 43 | 44 | syntax Id ::= 45 | "test1" [token] 46 | -------------------------------------------------------------------------------- /test/semantics/features/array/array_access.k: -------------------------------------------------------------------------------- 1 | 2 | ... 3 | 4 | ... 5 | t 6 | .List => ( 7 | ListItem( 8 | $rule(0, 9 | $ctr(ListItem(@val ( 0 , 2 , false )) ListItem(@val ( 1 , 2 , false ))) 10 | , @call(String2Id("ac") , $resolved( ListItem(@val(3,2,false)) ) ) ) 11 | ) 12 | ) 13 | 14 |
15 | ... 16 |
17 | //00:00:00:00:00:01 00:00:00:00:00:00 .... TTL:64 .... 10.0.0.1 10.0.0.0 18 | //0000 0000 0001 0000 0000 0000 0800 4500 0044 ad0b 0000 4011 7272 0a00 0001 0a00 0000 19 | // . => "00000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000001000000000000100010100000000000000000100010010101101000010110000000000000000010000000001000101110010011100100000101000000000000000000000000100001010000000000000000000000000" 20 | 21 | .List => ListItem($packet( 22 | ListItem(@val(0,2,false)) //f1 23 | ListItem(@val(0,2,false)) //f2 24 | ListItem(@val(1,2,false)) //f1 25 | ListItem(@val(1,2,false)) //f2 26 | , 1 //port 27 | )) 28 | 29 | ... 30 | 31 | 32 | syntax Id ::= "t" [token] -------------------------------------------------------------------------------- /test/stf_tests/test_data/gateway2.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | header_type data_t { 18 | fields { 19 | f1 : 32; 20 | f2 : 32; 21 | b1 : 8; 22 | b2 : 8; 23 | b3 : 8; 24 | b4 : 8; 25 | } 26 | } 27 | header data_t data; 28 | 29 | parser start { 30 | extract(data); 31 | return ingress; 32 | } 33 | 34 | action noop() { } 35 | action setb1(val, port) { 36 | modify_field(data.b1, val); 37 | modify_field(standard_metadata.egress_spec, port); 38 | } 39 | 40 | table test1 { 41 | reads { 42 | data.f1 : exact; 43 | } 44 | actions { 45 | setb1; 46 | noop; 47 | } 48 | } 49 | table test2 { 50 | reads { 51 | data.f2 : exact; 52 | } 53 | actions { 54 | setb1; 55 | noop; 56 | } 57 | } 58 | 59 | control ingress { 60 | if (data.b2 == data.b3 and data.b4 == 10) { 61 | apply(test1); 62 | } else { 63 | apply(test2); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /test/stf_tests/test_data/action_inline2.k: -------------------------------------------------------------------------------- 1 | 2 | 3 | ... 4 | 5 | 6 | ... 7 | test1 8 | .List => 9 | ListItem($rule(1, 10 | $ctr( 11 | ListItem($pair(@val(514,32,false),@val(65535,32,false))) 12 | ), 13 | @call( 14 | String2Id("setb1"), 15 | $resolved( 16 | ListItem(@val(3,0,false)) 17 | ) 18 | ) 19 | )) 20 | 21 | 22 | ListItem($rule(0, 23 | $ctr( 24 | ListItem($pair(@val(257,32,false),@val(65535,32,false))) 25 | ), 26 | @call( 27 | String2Id("setb1"), 28 | $resolved( 29 | ListItem(@val(2,0,false)) 30 | ) 31 | ) 32 | )) 33 | 34 | .K => .K 35 |
36 | 37 |
38 | 39 | .List => 40 | ListItem($packet("0000000000000000000000010000000100000000000000000000001000000010000000000000000000000011000000110000000000000000000001000000010001010101011001100111011110001000",0)) 41 | ListItem($packet("0000000000000000000000100000001000000000000000000000001100000011000000000000000000000100000001000000000000000000000001000000010001010101011001100111011110001000",2)) 42 | 43 | 44 | syntax Id ::= 45 | "test1" [token] 46 | -------------------------------------------------------------------------------- /verification/load-balancer/tables.k: -------------------------------------------------------------------------------- 1 | 2 | ... 3 | 4 | ... 5 | read_reg_table 6 | .List => ( 7 | ListItem( 8 | $rule(0, 9 | $ctr(ListItem(@val ( 1 , 0 , false ))) 10 | , @call(String2Id("read_reg") , $resolved( .List ) ) ) 11 | ) 12 | ) 13 | 14 |
15 | 16 | ... 17 | balance_table 18 | .List => ( 19 | ListItem( 20 | $rule(0, 21 | $ctr(ListItem(@val ( 0 , 0 , false ))) 22 | , @call(String2Id("balance") , $resolved( ListItem(@val(0,0,false)) ListItem(@val(1,0,false)) ) ) ) 23 | ) 24 | ListItem( 25 | $rule(1, 26 | $ctr(ListItem(@val ( 1 , 0 , false ))) 27 | , @call(String2Id("balance") , $resolved( ListItem(@val(1,0,false)) ListItem(@val(0,0,false)) ) ) ) 28 | ) 29 | ) 30 | 31 |
32 | 33 |
34 | 35 | 36 | syntax Id ::= "read_reg_table" [token] | "balance_table" [token] -------------------------------------------------------------------------------- /test/stf_tests/test_data/exact_match_valid1.p4: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013-present Barefoot Networks, Inc. 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 | header_type data_t { 18 | fields { 19 | f1 : 32; 20 | f2 : 32; 21 | f3 : 32; 22 | f4 : 32; 23 | b1 : 8; 24 | b2 : 8; 25 | b3 : 8; 26 | b4 : 8; 27 | } 28 | } 29 | header data_t data; 30 | header data_t data2; 31 | 32 | parser start { 33 | extract(data); 34 | return select(data.f2) { 35 | 0xf0000000 mask 0xf0000000 : parse_data2; 36 | default : ingress; 37 | } 38 | } 39 | parser parse_data2 { 40 | extract(data2); 41 | return ingress; 42 | } 43 | 44 | action noop() { } 45 | action setb1(val, port) { 46 | modify_field(data.b1, val); 47 | modify_field(standard_metadata.egress_spec, port); 48 | } 49 | 50 | table test1 { 51 | reads { 52 | data : valid; 53 | data2 : valid; 54 | } 55 | actions { 56 | setb1; 57 | noop; 58 | } 59 | } 60 | 61 | control ingress { 62 | apply(test1); 63 | } 64 | -------------------------------------------------------------------------------- /test/semantics/switch/input1.k: -------------------------------------------------------------------------------- 1 | 2 | //00:00:00:00:00:01 00:00:00:00:00:00 .... TTL:64 .... 10.0.0.1 10.0.0.0 3 | //0000 0000 0001 0000 0000 0000 0800 4500 0044 ad0b 0000 4011 7272 0a00 0001 0a00 0000 4 | // . => "00000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000001000000000000100010100000000000000000100010010101101000010110000000000000000010000000001000101110010011100100000101000000000000000000000000100001010000000000000000000000000" 5 | 6 | .List => ListItem($packet( 7 | ListItem(@val(1,48,false)) //dst mac 8 | ListItem(@val(0,48,false)) //src mac 9 | ListItem(@val(2048,16,false)) //ethertype 10 | ListItem(@val(4,4,false)) //ip version 11 | ListItem(@val(20,4,false)) //ihl 12 | ListItem(@val(0,8,false)) //diffserv 13 | ListItem(@val(68,16,false)) //total len 14 | ListItem(@val(44299,16,false)) //id 15 | ListItem(@val(0,3,false)) //flags 16 | ListItem(@val(0,13,false)) //frag offset 17 | ListItem(@val(64,8,false)) //ttl 18 | ListItem(@val(17,8,false)) //protocol 19 | ListItem(@val(7272,16,false)) //checksum 20 | ListItem(@val(167772161,32,false)) //src ip 21 | ListItem(@val(167772160,32,false)) //dst ip 22 | , 1 //port 23 | )) 24 | 25 | ... 26 | 27 | -------------------------------------------------------------------------------- /test/semantics/features/field_list/checksum.k: -------------------------------------------------------------------------------- 1 | 2 | //00:00:00:00:00:01 00:00:00:00:00:00 .... TTL:64 .... 10.0.0.1 10.0.0.0 3 | //0000 0000 0001 0000 0000 0000 0800 4500 0044 ad0b 0000 4011 7272 0a00 0001 0a00 0000 4 | // . => "00000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000001000000000000100010100000000000000000100010010101101000010110000000000000000010000000001000101110010011100100000101000000000000000000000000100001010000000000000000000000000" 5 | 6 | .List => ListItem($packet( 7 | ListItem(@val(1,48,false)) //dst mac 8 | ListItem(@val(0,48,false)) //src mac 9 | ListItem(@val(2048,16,false)) //ethertype 10 | ListItem(@val(4,4,false)) //ip version 11 | ListItem(@val(5,4,false)) //ihl 12 | ListItem(@val(0,8,false)) //diffserv 13 | ListItem(@val(68,16,false)) //total len 14 | ListItem(@val(44299,16,false)) //id 15 | ListItem(@val(0,3,false)) //flags 16 | ListItem(@val(0,13,false)) //frag offset 17 | ListItem(@val(64,8,false)) //ttl 18 | ListItem(@val(17,8,false)) //protocol 19 | ListItem(@val(7272,16,false)) //checksum 20 | ListItem(@val(167772161,32,false)) //src ip 21 | ListItem(@val(167772160,32,false)) //dst ip 22 | , 1 //port 23 | )) 24 | 25 | ... 26 | 27 | --------------------------------------------------------------------------------