blob: f17514bbec0b83293f243ed922014dd34e4d93f6 [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"
Carmelo Cascone3304fd52017-07-30 00:43:01 -04005
6typedef bit<16> group_id_t;
7typedef bit<8> group_size_t;
8
9struct ecmp_metadata_t {
10 group_id_t group_id;
11 bit<16> selector;
12}
13
14struct metadata_t {
15 ecmp_metadata_t ecmp_metadata;
16 intrinsic_metadata_t intrinsic_metadata;
17}
18
Yi Tseng21629932017-06-06 11:17:43 -070019#include "include/parsers.p4"
20#include "include/port_counters.p4"
21#include "include/checksums.p4"
22#include "include/actions.p4"
Carmelo Cascone837e6452017-07-19 20:35:22 -040023#include "include/packet_io.p4"
Yi Tseng21629932017-06-06 11:17:43 -070024
25
Carmelo Cascone837e6452017-07-19 20:35:22 -040026control ingress(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t standard_metadata) {
27
Yi Tseng21629932017-06-06 11:17:43 -070028 direct_counter(CounterType.packets) ecmp_group_table_counter;
29 direct_counter(CounterType.packets) table0_counter;
30
Carmelo Cascone837e6452017-07-19 20:35:22 -040031 action ecmp_group(group_id_t group_id, group_size_t groupSize) {
32 meta.ecmp_metadata.group_id = group_id;
33 hash(meta.ecmp_metadata.selector, HashAlgorithm.crc16, (bit<64>)0,
34 { hdr.ipv4.srcAddr, hdr.ipv4.dstAddr, hdr.ipv4.protocol, hdr.tcp.srcPort, hdr.tcp.dstPort, hdr.udp.srcPort,
35 hdr.udp.dstPort },
36 (bit<128>)groupSize);
Yi Tseng21629932017-06-06 11:17:43 -070037 }
38
39 table ecmp_group_table {
40 actions = {
41 set_egress_port(standard_metadata);
42 }
43 key = {
Carmelo Cascone837e6452017-07-19 20:35:22 -040044 meta.ecmp_metadata.group_id : exact;
Yi Tseng21629932017-06-06 11:17:43 -070045 meta.ecmp_metadata.selector: exact;
46 }
47 counters = ecmp_group_table_counter;
48 }
49
50 table table0 {
51 support_timeout = true;
52 actions = {
53 ecmp_group;
54 set_egress_port(standard_metadata);
55 send_to_cpu(standard_metadata);
56 drop(standard_metadata);
57 }
58 key = {
59 standard_metadata.ingress_port: ternary;
60 hdr.ethernet.dstAddr : ternary;
61 hdr.ethernet.srcAddr : ternary;
62 hdr.ethernet.etherType : ternary;
63 }
64 counters = table0_counter;
65 }
Carmelo Cascone837e6452017-07-19 20:35:22 -040066
Yi Tseng21629932017-06-06 11:17:43 -070067 PortCountersControl() port_counters_control;
Carmelo Cascone837e6452017-07-19 20:35:22 -040068 PacketIoIngressControl() packet_io_ingress_control;
69
Yi Tseng21629932017-06-06 11:17:43 -070070 apply {
Carmelo Cascone837e6452017-07-19 20:35:22 -040071 packet_io_ingress_control.apply(hdr, standard_metadata);
72 if (!hdr.packet_out.isValid()) {
73 switch (table0.apply().action_run) {
74 ecmp_group: {
75 ecmp_group_table.apply();
76 }
Yi Tseng21629932017-06-06 11:17:43 -070077 }
78 }
Yi Tseng21629932017-06-06 11:17:43 -070079 port_counters_control.apply(hdr, meta, standard_metadata);
80 }
81}
82
Carmelo Cascone837e6452017-07-19 20:35:22 -040083control egress(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t standard_metadata) {
84
85 PacketIoEgressControl() packet_io_egress_control;
Yi Tseng21629932017-06-06 11:17:43 -070086 apply {
Carmelo Cascone837e6452017-07-19 20:35:22 -040087 packet_io_egress_control.apply(hdr, standard_metadata);
Yi Tseng21629932017-06-06 11:17:43 -070088 }
89}
90
91V1Switch(ParserImpl(), verifyChecksum(), ingress(), egress(), computeChecksum(), DeparserImpl()) main;