blob: 3c06c201b18c77ad89867ceace54bf6a88b63de6 [file] [log] [blame]
Yi Tseng21629932017-06-06 11:17:43 -07001#include <core.p4>
2#include <v1model.p4>
3#include "include/defines.p4"
4#include "include/headers.p4"
5#include "include/parsers.p4"
6#include "include/port_counters.p4"
7#include "include/checksums.p4"
8#include "include/actions.p4"
Carmelo Cascone837e6452017-07-19 20:35:22 -04009#include "include/packet_io.p4"
Yi Tseng21629932017-06-06 11:17:43 -070010
11
Carmelo Cascone837e6452017-07-19 20:35:22 -040012control ingress(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t standard_metadata) {
13
Yi Tseng21629932017-06-06 11:17:43 -070014 direct_counter(CounterType.packets) ecmp_group_table_counter;
15 direct_counter(CounterType.packets) table0_counter;
16
Carmelo Cascone837e6452017-07-19 20:35:22 -040017 action ecmp_group(group_id_t group_id, group_size_t groupSize) {
18 meta.ecmp_metadata.group_id = group_id;
19 hash(meta.ecmp_metadata.selector, HashAlgorithm.crc16, (bit<64>)0,
20 { hdr.ipv4.srcAddr, hdr.ipv4.dstAddr, hdr.ipv4.protocol, hdr.tcp.srcPort, hdr.tcp.dstPort, hdr.udp.srcPort,
21 hdr.udp.dstPort },
22 (bit<128>)groupSize);
Yi Tseng21629932017-06-06 11:17:43 -070023 }
24
25 table ecmp_group_table {
26 actions = {
27 set_egress_port(standard_metadata);
28 }
29 key = {
Carmelo Cascone837e6452017-07-19 20:35:22 -040030 meta.ecmp_metadata.group_id : exact;
Yi Tseng21629932017-06-06 11:17:43 -070031 meta.ecmp_metadata.selector: exact;
32 }
33 counters = ecmp_group_table_counter;
34 }
35
36 table table0 {
37 support_timeout = true;
38 actions = {
39 ecmp_group;
40 set_egress_port(standard_metadata);
41 send_to_cpu(standard_metadata);
42 drop(standard_metadata);
43 }
44 key = {
45 standard_metadata.ingress_port: ternary;
46 hdr.ethernet.dstAddr : ternary;
47 hdr.ethernet.srcAddr : ternary;
48 hdr.ethernet.etherType : ternary;
49 }
50 counters = table0_counter;
51 }
Carmelo Cascone837e6452017-07-19 20:35:22 -040052
Yi Tseng21629932017-06-06 11:17:43 -070053 PortCountersControl() port_counters_control;
Carmelo Cascone837e6452017-07-19 20:35:22 -040054 PacketIoIngressControl() packet_io_ingress_control;
55
Yi Tseng21629932017-06-06 11:17:43 -070056 apply {
Carmelo Cascone837e6452017-07-19 20:35:22 -040057 packet_io_ingress_control.apply(hdr, standard_metadata);
58 if (!hdr.packet_out.isValid()) {
59 switch (table0.apply().action_run) {
60 ecmp_group: {
61 ecmp_group_table.apply();
62 }
Yi Tseng21629932017-06-06 11:17:43 -070063 }
64 }
Yi Tseng21629932017-06-06 11:17:43 -070065 port_counters_control.apply(hdr, meta, standard_metadata);
66 }
67}
68
Carmelo Cascone837e6452017-07-19 20:35:22 -040069control egress(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t standard_metadata) {
70
71 PacketIoEgressControl() packet_io_egress_control;
Yi Tseng21629932017-06-06 11:17:43 -070072 apply {
Carmelo Cascone837e6452017-07-19 20:35:22 -040073 packet_io_egress_control.apply(hdr, standard_metadata);
Yi Tseng21629932017-06-06 11:17:43 -070074 }
75}
76
77V1Switch(ParserImpl(), verifyChecksum(), ingress(), egress(), computeChecksum(), DeparserImpl()) main;