-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathml-headers.p4
222 lines (204 loc) · 4.99 KB
/
ml-headers.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
/*
* Copyright 2019, MNK Consulting
* http://mnkcg.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ml-headers.p4
*/
typedef bit<48> mac_addr_t;
typedef bit<128> ipv6_addr_t;
typedef bit<9> port_t;
const bit<16> TYPE_IPV6 = 0x86dd;
const bit<9> TYPE_CPU = 9w192;
const bit<8> PROTO_TCP = 6;
const bit<8> PROTO_UDP = 17;
const bit<8> PROTO_ICMP6 = 58;
const bit<8> TCP_SEQ_LEN = 4;
const bit<8> ICMP6_ECHO_REQUEST = 128;
const bit<8> ICMP6_ECHO_REPLY = 129;
header ethernet_t {
mac_addr_t dstAddr;
mac_addr_t srcAddr;
bit<16> etherType;
}
header ipv6_t {
bit<4> version;
bit<8> traffic_class;
bit<20> flow_label;
bit<16> payload_length;
bit<8> nextHdr;
bit<8> hopLimit;
ipv6_addr_t srcAddr;
ipv6_addr_t dstAddr;
}
header tcp_t {
bit<16> srcPort;
bit<16> dstPort;
int<32> seqNo;
int<32> ackNo;
bit<4> data_offset;
bit<4> res;
bit<1> cwr;
bit<1> ece;
bit<1> urg;
bit<1> ack;
bit<1> psh;
bit<1> rst;
bit<1> syn;
bit<1> fin;
bit<16> window;
bit<16> checksum;
bit<16> urgentPtr;
}
header udp_t {
bit<16> srcPort;
bit<16> dstPort;
bit<16> length_;
bit<16> checksum;
}
header icmp6_t {
bit<8> type;
bit<8> code;
bit<16> checksum;
}
//
// Data structs to implement Algorithm 1 of Switch ML
// from page 4 of https://arxiv.org/pdf/1903.06701.pdf
//
// Number of elements in packet vector.
const bit<8> K = 20;
// Number of Workers.
const bit<8> N = 10;
// Number of integer aggregators
const bit<8> S = 128; // for 10G switch ports
header count_t {
bit<8> cnt;
}
header ml_hdr_t {
int<8> idx;
}
header vec_e_t {
bit<32> e;
}
header aggregator_t {
bit<32> val;
}
struct headers {
ethernet_t inner_ethernet;
icmp6_t inner_icmp6;
ipv6_t inner_ipv6;
tcp_t inner_tcp;
udp_t inner_udp;
ethernet_t ethernet;
icmp6_t icmp6;
ipv6_t ipv6;
tcp_t tcp;
udp_t udp;
ml_hdr_t ml;
vec_e_t[K] vector;
}
struct l3_metadata_t {
bit<2> lkp_ip_type;
bit<4> lkp_ip_version;
bit<8> lkp_ip_proto;
bit<8> lkp_dscp;
bit<8> lkp_ip_ttl;
bit<16> lkp_l4_sport;
bit<16> lkp_l4_dport;
bit<16> lkp_outer_l4_sport;
bit<16> lkp_outer_l4_dport;
bit<16> vrf;
bit<10> rmac_group;
bit<1> rmac_hit;
bit<2> urpf_mode;
bit<1> urpf_hit;
bit<1> urpf_check_fail;
bit<16> urpf_bd_group;
bit<1> fib_hit;
bit<16> fib_nexthop;
bit<2> fib_nexthop_type;
bit<16> same_bd_check;
bit<16> nexthop_index;
bit<1> routed;
bit<1> outer_routed;
bit<8> mtu_index;
bit<1> l3_copy;
bit<16> l3_mtu_check;
bit<16> egress_l4_sport;
bit<16> egress_l4_dport;
}
struct tunnel_metadata_t {
bit<5> ingress_tunnel_type;
bit<24> tunnel_vni;
bit<5> egress_tunnel_type;
bit<14> tunnel_index;
bit<9> tunnel_src_index;
bit<9> tunnel_smac_index;
bit<14> tunnel_dst_index;
bit<14> tunnel_dmac_index;
bit<24> vnid;
bit<1> tunnel_terminate;
bit<1> tunnel_if_check;
bit<4> egress_header_count;
bit<8> inner_ip_proto;
bit<1> skip_encap_inner;
}
struct l2_metadata_t {
bit<48> lkp_mac_sa;
bit<48> lkp_mac_da;
bit<3> lkp_pkt_type;
bit<16> lkp_mac_type;
bit<3> lkp_pcp;
bit<16> l2_nexthop;
bit<2> l2_nexthop_type;
bit<1> l2_redirect;
bit<1> l2_src_miss;
bit<16> l2_src_move;
bit<10> stp_group;
bit<3> stp_state;
bit<16> bd_stats_idx;
bit<1> learning_enabled;
bit<1> port_vlan_mapping_miss;
bit<16> same_if_check;
}
struct ipv6_metadata_t {
bit<128> lkp_ipv6_sa;
bit<128> lkp_ipv6_da;
bit<1> ipv6_unicast_enabled;
bit<1> ipv6_src_is_link_local;
bit<2> ipv6_urpf_mode;
}
struct acl_metadata_t {
bit<1> acl_deny; /* ifacl/vacl deny action */
bit<24> vnid; /* vnid for acls */
bit<14> acl_stats_index; /* acl stats index */
bit<16> egress_if_label; /* if label for egress acls */
bit<16> egress_bd_label; /* bd label for egress acls */
}
struct fwd_meta_t {
bit<32> l2ptr;
bit<24> out_bd;
}
struct metadata_t {
port_t ingress_port;
port_t egress_port;
bit<16> tcp_length;
bit<32> cast_length;
bit<1> do_cksum;
l2_metadata_t l2_metadata;
l3_metadata_t l3_metadata;
ipv6_metadata_t ipv6_metadata;
tunnel_metadata_t tunnel_metadata;
fwd_meta_t fwd;
}