blob: 3b7f6eb5df64b4c70aa1a0029c492f6590ce63e9 [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#define SELECTOR_WIDTH 64
12const bit<SELECTOR_WIDTH> ONE = 64w1;
13
Carmelo Cascone837e6452017-07-19 20:35:22 -040014control ingress(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t standard_metadata) {
15
Yi Tseng21629932017-06-06 11:17:43 -070016 direct_counter(CounterType.packets) table0_counter;
17 direct_counter(CounterType.packets) wcmp_group_table_counter;
18
Carmelo Cascone837e6452017-07-19 20:35:22 -040019 action wcmp_group(group_id_t group_id) {
20 meta.wcmp_meta.group_id = group_id;
21 hash(meta.wcmp_meta.numBits, HashAlgorithm.crc16, (bit<64>)2,
22 { hdr.ipv4.srcAddr, hdr.ipv4.dstAddr, hdr.ipv4.protocol, hdr.tcp.srcPort, hdr.tcp.dstPort, hdr.udp.srcPort,
23 hdr.udp.dstPort },
24 (bit<128>)62);
Yi Tseng21629932017-06-06 11:17:43 -070025 }
26
27 action wcmp_set_selector() {
28 meta.wcmp_meta.selector = ((ONE << meta.wcmp_meta.numBits) - ONE) << (SELECTOR_WIDTH - meta.wcmp_meta.numBits);
29 }
30
31 table table0 {
32 support_timeout = true;
33 actions = {
34 set_egress_port(standard_metadata);
35 wcmp_group;
36 send_to_cpu(standard_metadata);
37 drop(standard_metadata);
38 }
39 key = {
40 standard_metadata.ingress_port: ternary;
41 hdr.ethernet.dstAddr : ternary;
42 hdr.ethernet.srcAddr : ternary;
43 hdr.ethernet.etherType : ternary;
44 }
45 counters = table0_counter;
46 }
47
48 table wcmp_group_table {
49 actions = {
50 set_egress_port(standard_metadata);
51 }
52 key = {
Carmelo Cascone837e6452017-07-19 20:35:22 -040053 meta.wcmp_meta.group_id : exact;
Yi Tseng21629932017-06-06 11:17:43 -070054 meta.wcmp_meta.selector: lpm;
55 }
56 counters = wcmp_group_table_counter;
57 }
58
59 PortCountersControl() port_counters_control;
Carmelo Cascone837e6452017-07-19 20:35:22 -040060 PacketIoIngressControl() packet_io_ingress_control;
61
Yi Tseng21629932017-06-06 11:17:43 -070062 apply {
Carmelo Cascone837e6452017-07-19 20:35:22 -040063 packet_io_ingress_control.apply(hdr, standard_metadata);
64 if (!hdr.packet_out.isValid()) {
65 switch (table0.apply().action_run) {
66 wcmp_group: {
67 wcmp_set_selector();
68 wcmp_group_table.apply();
69 }
Yi Tseng21629932017-06-06 11:17:43 -070070 }
71 }
72 port_counters_control.apply(hdr, meta, standard_metadata);
73 }
74}
75
Carmelo Cascone837e6452017-07-19 20:35:22 -040076control egress(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t standard_metadata) {
77
78 PacketIoEgressControl() packet_io_egress_control;
Yi Tseng21629932017-06-06 11:17:43 -070079 apply {
Carmelo Cascone837e6452017-07-19 20:35:22 -040080 packet_io_egress_control.apply(hdr, standard_metadata);
Yi Tseng21629932017-06-06 11:17:43 -070081 }
82}
83
84V1Switch(ParserImpl(), verifyChecksum(), ingress(), egress(), computeChecksum(), DeparserImpl()) main;