-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathecmp_2.p4
More file actions
172 lines (157 loc) · 4.53 KB
/
ecmp_2.p4
File metadata and controls
172 lines (157 loc) · 4.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#include <core.p4>
#include <v1model.p4>
struct routing_metadata_t {
bit<32> nhop_ipv4;
}
header ethernet_t {
bit<48> dstAddr;
bit<48> srcAddr;
bit<16> etherType;
}
header ipv4_t {
bit<4> version;
bit<4> ihl;
bit<8> diffserv;
bit<16> totalLen;
bit<16> identification;
bit<3> flags;
bit<13> fragOffset;
bit<8> ttl;
bit<8> protocol;
bit<16> hdrChecksum;
bit<32> srcAddr;
bit<32> dstAddr;
}
header tcp_t {
bit<16> srcPort;
bit<16> dstPort;
bit<32> seqNo;
bit<32> ackNo;
bit<4> dataOffset;
bit<3> res;
bit<3> ecn;
bit<6> ctrl;
bit<16> window;
bit<16> checksum;
bit<16> urgentPtr;
}
struct metadata {
@name(".routing_metadata")
routing_metadata_t routing_metadata;
}
struct headers {
@name(".ethernet")
ethernet_t ethernet;
@name(".ipv4")
ipv4_t ipv4;
@name(".tcp")
tcp_t tcp;
}
parser ParserImpl(packet_in packet, out headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
@name(".parse_ethernet") state parse_ethernet {
packet.extract(hdr.ethernet);
transition select(hdr.ethernet.etherType) {
16w0x800: parse_ipv4;
default: accept;
}
}
@name(".parse_ipv4") state parse_ipv4 {
packet.extract(hdr.ipv4);
transition select(hdr.ipv4.protocol) {
8w6: parse_tcp;
default: accept;
}
}
@name(".parse_tcp") state parse_tcp {
packet.extract(hdr.tcp);
transition accept;
}
@name(".start") state start {
transition parse_ethernet;
}
}
@name(".ecmp_action_profile") action_selector(HashAlgorithm.crc16, 32w16384, 32w10) ecmp_action_profile;
control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
@name(".rewrite_mac") action rewrite_mac(bit<48> smac) {
hdr.ethernet.srcAddr = smac;
}
@name("._drop") action _drop() {
mark_to_drop();
}
@name(".send_frame") table send_frame {
actions = {
rewrite_mac;
_drop;
}
key = {
standard_metadata.egress_port: exact;
}
size = 256;
}
apply {
send_frame.apply();
}
}
control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
@name("._drop") action _drop() {
mark_to_drop();
}
@name(".set_nhop") action set_nhop(bit<32> nhop_ipv4, bit<9> port) {
meta.routing_metadata.nhop_ipv4 = nhop_ipv4;
standard_metadata.egress_spec = port;
hdr.ipv4.ttl = hdr.ipv4.ttl + 8w255;
}
@name(".set_dmac") action set_dmac(bit<48> dmac) {
hdr.ethernet.dstAddr = dmac;
}
@name(".ecmp_group") table ecmp_group {
actions = {
_drop;
set_nhop;
}
key = {
hdr.ipv4.dstAddr : lpm;
hdr.ipv4.srcAddr : selector;
hdr.ipv4.dstAddr : selector;
hdr.ipv4.protocol: selector;
hdr.tcp.srcPort : selector;
hdr.tcp.dstPort : selector;
}
size = 1024;
implementation = ecmp_action_profile;
}
@name(".forward") table forward {
actions = {
set_dmac;
_drop;
}
key = {
meta.routing_metadata.nhop_ipv4: exact;
}
size = 512;
}
apply {
if (hdr.ipv4.isValid() && hdr.ipv4.ttl > 8w0) {
ecmp_group.apply();
forward.apply();
}
}
}
control DeparserImpl(packet_out packet, in headers hdr) {
apply {
packet.emit(hdr.ethernet);
packet.emit(hdr.ipv4);
packet.emit(hdr.tcp);
}
}
control verifyChecksum(inout headers hdr, inout metadata meta) {
apply {
verify_checksum(true, { hdr.ipv4.version, hdr.ipv4.ihl, hdr.ipv4.diffserv, hdr.ipv4.totalLen, hdr.ipv4.identification, hdr.ipv4.flags, hdr.ipv4.fragOffset, hdr.ipv4.ttl, hdr.ipv4.protocol, hdr.ipv4.srcAddr, hdr.ipv4.dstAddr }, hdr.ipv4.hdrChecksum, HashAlgorithm.csum16);
}
}
control computeChecksum(inout headers hdr, inout metadata meta) {
apply {
update_checksum(true, { hdr.ipv4.version, hdr.ipv4.ihl, hdr.ipv4.diffserv, hdr.ipv4.totalLen, hdr.ipv4.identification, hdr.ipv4.flags, hdr.ipv4.fragOffset, hdr.ipv4.ttl, hdr.ipv4.protocol, hdr.ipv4.srcAddr, hdr.ipv4.dstAddr }, hdr.ipv4.hdrChecksum, HashAlgorithm.csum16);
}
}
V1Switch(ParserImpl(), verifyChecksum(), ingress(), egress(), computeChecksum(), DeparserImpl()) main;