forked from sonic-net/DASH
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdash_pipeline.p4
334 lines (281 loc) · 9.63 KB
/
dash_pipeline.p4
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
#include <core.p4>
#include <v1model.p4>
#include "dash_headers.p4"
#include "dash_metadata.p4"
#include "dash_parser.p4"
#include "dash_vxlan.p4"
#include "dash_outbound.p4"
#include "dash_inbound.p4"
#include "dash_conntrack.p4"
control dash_verify_checksum(inout headers_t hdr,
inout metadata_t meta)
{
apply { }
}
control dash_compute_checksum(inout headers_t hdr,
inout metadata_t meta)
{
apply { }
}
control dash_ingress(inout headers_t hdr,
inout metadata_t meta,
inout standard_metadata_t standard_metadata)
{
action drop_action() {
mark_to_drop(standard_metadata);
}
action deny() {
meta.dropped = true;
}
action accept() {
}
@name("vip|dash_vip")
@Sai[table_name="vip",api_name="dash_vip"]
table vip {
key = {
hdr.ipv4.dst_addr : exact @name("hdr.ipv4.dst_addr:VIP");
}
actions = {
accept;
@defaultonly deny;
}
const default_action = deny;
}
action set_outbound_direction() {
meta.direction = direction_t.OUTBOUND;
}
action set_inbound_direction() {
meta.direction = direction_t.INBOUND;
}
@name("direction_lookup|dash_direction_lookup")
@Sai[table_name="direction_lookup",api_name="dash_direction_lookup"]
table direction_lookup {
key = {
hdr.vxlan.vni : exact @name("hdr.vxlan.vni:VNI");
}
actions = {
set_outbound_direction;
@defaultonly set_inbound_direction;
}
const default_action = set_inbound_direction;
}
action set_appliance(EthernetAddress neighbor_mac,
EthernetAddress mac) {
meta.encap_data.underlay_dmac = neighbor_mac;
meta.encap_data.underlay_smac = mac;
}
/* This table API should be implemented manually using underlay SAI */
table appliance {
key = {
meta.appliance_id : ternary @name("meta.appliance_id:appliance_id");
}
actions = {
set_appliance;
}
}
#define ACL_GROUPS_PARAM(prefix) \
bit<16> ## prefix ##_stage1_dash_acl_group_id, \
bit<16> ## prefix ##_stage2_dash_acl_group_id, \
bit<16> ## prefix ##_stage3_dash_acl_group_id, \
bit<16> ## prefix ##_stage4_dash_acl_group_id, \
bit<16> ## prefix ##_stage5_dash_acl_group_id
#define ACL_GROUPS_COPY_TO_META(prefix) \
meta.stage1_dash_acl_group_id = ## prefix ##_stage1_dash_acl_group_id; \
meta.stage2_dash_acl_group_id = ## prefix ##_stage2_dash_acl_group_id; \
meta.stage3_dash_acl_group_id = ## prefix ##_stage3_dash_acl_group_id; \
meta.stage4_dash_acl_group_id = ## prefix ##_stage4_dash_acl_group_id; \
meta.stage5_dash_acl_group_id = ## prefix ##_stage5_dash_acl_group_id;
action set_eni_attrs(bit<32> cps,
bit<32> pps,
bit<32> flows,
bit<1> admin_state,
IPv4Address vm_underlay_dip,
bit<24> vm_vni,
@Sai[mandatory=true] bit<16> vnet_id,
ACL_GROUPS_PARAM(inbound_v4),
ACL_GROUPS_PARAM(inbound_v6),
ACL_GROUPS_PARAM(outbound_v4),
ACL_GROUPS_PARAM(outbound_v6)) {
meta.eni_data.cps = cps;
meta.eni_data.pps = pps;
meta.eni_data.flows = flows;
meta.eni_data.admin_state = admin_state;
meta.encap_data.underlay_dip = vm_underlay_dip;
/* vm_vni is the encap VNI used for tunnel between inbound DPU -> VM
* and not a VNET identifier */
meta.encap_data.vni = vm_vni;
meta.vnet_id = vnet_id;
if (meta.is_overlay_ip_v6 == 1) {
if (meta.direction == direction_t.OUTBOUND) {
ACL_GROUPS_COPY_TO_META(outbound_v6);
} else {
ACL_GROUPS_COPY_TO_META(inbound_v6);
}
} else {
if (meta.direction == direction_t.OUTBOUND) {
ACL_GROUPS_COPY_TO_META(outbound_v4);
} else {
ACL_GROUPS_COPY_TO_META(inbound_v4);
}
}
}
@name("eni|dash_eni")
@Sai[table_name="eni",api_name="dash_eni"]
table eni {
key = {
meta.eni_id : exact @name("meta.eni_id:eni_id");
}
actions = {
set_eni_attrs;
@defaultonly deny;
}
const default_action = deny;
}
direct_counter(CounterType.packets_and_bytes) eni_counter;
table eni_meter {
key = {
meta.eni_id : exact @name("meta.eni_id:eni_id");
meta.direction : exact @name("meta.direction:direction");
meta.dropped : exact @name("meta.dropped:dropped");
}
actions = { NoAction; }
counters = eni_counter;
}
action permit() {
}
action vxlan_decap_pa_validate(bit<16> src_vnet_id) {
meta.vnet_id = src_vnet_id;
}
@name("pa_validation|dash_pa_validation")
@Sai[table_name="pa_validation",api_name="dash_pa_validation"]
table pa_validation {
key = {
meta.vnet_id: exact @name("meta.vnet_id:vnet_id");
hdr.ipv4.src_addr : exact @name("hdr.ipv4.src_addr:sip");
}
actions = {
permit;
@defaultonly deny;
}
const default_action = deny;
}
@name("inbound_routing|dash_inbound_routing")
table inbound_routing {
key = {
meta.eni_id: exact @name("meta.eni_id:eni_id");
hdr.vxlan.vni : exact @name("hdr.vxlan.vni:VNI");
hdr.ipv4.src_addr : ternary @name("hdr.ipv4.src_addr:sip");
}
actions = {
vxlan_decap(hdr);
vxlan_decap_pa_validate;
@defaultonly deny;
}
const default_action = deny;
}
action set_eni(bit<16> eni_id) {
meta.eni_id = eni_id;
}
@name("eni_ether_address_map|dash_eni")
@Sai[table_name="eni_ether_address_map",api_name="dash_eni"]
table eni_ether_address_map {
key = {
meta.eni_addr : exact @name("meta.eni_addr:address");
}
actions = {
set_eni;
@defaultonly deny;
}
const default_action = deny;
}
action set_acl_group_attrs(bit<32> ip_addr_family) {
if (ip_addr_family == 0) /* SAI_IP_ADDR_FAMILY_IPV4 */ {
if (meta.is_overlay_ip_v6 == 1) {
meta.dropped = true;
}
} else {
if (meta.is_overlay_ip_v6 == 0) {
meta.dropped = true;
}
}
}
@name("dash_acl_group|dash_acl")
@Sai[table_name="dash_acl_group",api_name="dash_acl"]
table acl_group {
key = {
meta.stage1_dash_acl_group_id : exact @name("meta.stage1_dash_acl_group_id:dash_acl_group_id");
}
actions = {
set_acl_group_attrs();
}
}
apply {
/* Send packet on same port it arrived (echo) by default */
standard_metadata.egress_spec = standard_metadata.ingress_port;
if (vip.apply().hit) {
/* Use the same VIP that was in packet's destination if it's
present in the VIP table */
meta.encap_data.underlay_sip = hdr.ipv4.dst_addr;
}
/* If Outer VNI matches with a reserved VNI, then the direction is Outbound - */
direction_lookup.apply();
appliance.apply();
/* Outer header processing */
if (meta.direction == direction_t.OUTBOUND) {
vxlan_decap(hdr);
} else if (meta.direction == direction_t.INBOUND) {
switch (inbound_routing.apply().action_run) {
vxlan_decap_pa_validate: {
pa_validation.apply();
vxlan_decap(hdr);
}
}
}
meta.is_overlay_ip_v6 = 0;
meta.ip_protocol = 0;
meta.dst_ip_addr = 0;
meta.src_ip_addr = 0;
if (hdr.ipv6.isValid()) {
meta.ip_protocol = hdr.ipv6.next_header;
meta.src_ip_addr = hdr.ipv6.src_addr;
meta.dst_ip_addr = hdr.ipv6.dst_addr;
meta.is_overlay_ip_v6 = 1;
} else if (hdr.ipv4.isValid()) {
meta.ip_protocol = hdr.ipv4.protocol;
meta.src_ip_addr = (bit<128>)hdr.ipv4.src_addr;
meta.dst_ip_addr = (bit<128>)hdr.ipv4.dst_addr;
}
/* At this point the processing is done on customer headers */
/* Put VM's MAC in the direction agnostic metadata field */
meta.eni_addr = meta.direction == direction_t.OUTBOUND ?
hdr.ethernet.src_addr :
hdr.ethernet.dst_addr;
eni_ether_address_map.apply();
eni.apply();
if (meta.eni_data.admin_state == 0) {
deny();
}
acl_group.apply();
if (meta.direction == direction_t.OUTBOUND) {
outbound.apply(hdr, meta, standard_metadata);
} else if (meta.direction == direction_t.INBOUND) {
inbound.apply(hdr, meta, standard_metadata);
}
eni_meter.apply();
if (meta.dropped) {
drop_action();
}
}
}
control dash_egress(inout headers_t hdr,
inout metadata_t meta,
inout standard_metadata_t standard_metadata)
{
apply { }
}
V1Switch(dash_parser(),
dash_verify_checksum(),
dash_ingress(),
dash_egress(),
dash_compute_checksum(),
dash_deparser()) main;