blob: 6dff6f119f81bd2ba169b8ea1b95894ce5d90ddc [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"
9
10#define SELECTOR_WIDTH 64
11const bit<SELECTOR_WIDTH> ONE = 64w1;
12
13control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
14 direct_counter(CounterType.packets) table0_counter;
15 direct_counter(CounterType.packets) wcmp_group_table_counter;
16
17 action wcmp_group(GroupId groupId) {
18 meta.wcmp_meta.groupId = groupId;
19 hash(meta.wcmp_meta.numBits, HashAlgorithm.crc16, (bit<64>)2, { hdr.ipv4.srcAddr, hdr.ipv4.dstAddr, hdr.ipv4.protocol, hdr.tcp.srcPort, hdr.tcp.dstPort, hdr.udp.srcPort, hdr.udp.dstPort }, (bit<128>)62);
20 }
21
22 action wcmp_set_selector() {
23 meta.wcmp_meta.selector = ((ONE << meta.wcmp_meta.numBits) - ONE) << (SELECTOR_WIDTH - meta.wcmp_meta.numBits);
24 }
25
26 table table0 {
27 support_timeout = true;
28 actions = {
29 set_egress_port(standard_metadata);
30 wcmp_group;
31 send_to_cpu(standard_metadata);
32 drop(standard_metadata);
33 }
34 key = {
35 standard_metadata.ingress_port: ternary;
36 hdr.ethernet.dstAddr : ternary;
37 hdr.ethernet.srcAddr : ternary;
38 hdr.ethernet.etherType : ternary;
39 }
40 counters = table0_counter;
41 }
42
43 table wcmp_group_table {
44 actions = {
45 set_egress_port(standard_metadata);
46 }
47 key = {
48 meta.wcmp_meta.groupId : exact;
49 meta.wcmp_meta.selector: lpm;
50 }
51 counters = wcmp_group_table_counter;
52 }
53
54 PortCountersControl() port_counters_control;
55 apply {
56 switch (table0.apply().action_run) {
57 wcmp_group: {
58 wcmp_set_selector();
59 wcmp_group_table.apply();
60 }
61 }
62 port_counters_control.apply(hdr, meta, standard_metadata);
63 }
64}
65
66control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
67 apply {
68 // Nothing to do
69 }
70}
71
72V1Switch(ParserImpl(), verifyChecksum(), ingress(), egress(), computeChecksum(), DeparserImpl()) main;