-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwavelets.p4
More file actions
191 lines (168 loc) · 3.8 KB
/
wavelets.p4
File metadata and controls
191 lines (168 loc) · 3.8 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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#include <core.p4>
#include <v1model.p4>
header ethernet_t {
bit<48> dst;
bit<48> src;
bit<16> etype;
}
header ipv4_t {
bit<4> version;
bit<4> ihl;
bit<8> diffserv;
bit<16> total_len;
bit<16> id;
bit<3> flags;
bit<13> offset;
bit<8> ttl;
bit<8> protocol;
bit<16> checksum;
bit<32> src;
bit<32> dst;
}
header tcp_t {
bit<16> src;
bit<16> dst;
bit<32> seqno;
bit<32> ackno;
bit<4> data_offset;
bit<4> reserved;
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> urgent_ptr;
}
struct intrinsic_metadata_t {
bit<64> ingress_global_tstamp;
bit<64> current_global_tstamp;
bit<32> index;
bit<32> timeinterval;
}
struct metadata {
intrinsic_metadata_t intrinsic_metadata;
}
struct headers {
ethernet_t ethernet;
ipv4_t ipv4;
tcp_t tcp;
}
const bit<16> ARP_TYPE = 0x0806;
const bit<16> IPV4_TYPE = 0x0800;
const bit<8> TCP_PROTO = 0x06;
const bit<32> TABLE_SIZE = 4096;
const bit<32> NUM_LEVELS = 17;
/*************************************************************************
*********************** R E G I S T E R S *****************************
*************************************************************************/
register<bit<64>>(TABLE_SIZE * (NUM_LEVELS+1)) sum;
register<bit<32>>(TABLE_SIZE) N;
extern void do_wavelets();
parser ParserImpl(packet_in packet, out headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
state start {
packet.extract(hdr.ethernet);
transition select(hdr.ethernet.etype) {
IPV4_TYPE: parse_ipv4;
default: accept;
}
}
state parse_ipv4 {
packet.extract(hdr.ipv4);
transition select(hdr.ipv4.protocol) {
TCP_PROTO: parse_tcp;
default: accept;
}
}
state parse_tcp {
packet.extract(hdr.tcp);
transition accept;
}
}
control verifyChecksum(inout headers hdr, inout metadata meta) {
apply {
}
}
control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
action act_forward(bit<16> port) {
standard_metadata.egress_spec = port;
}
action act_tag(bit<32> index, bit<32> timeinterval) {
meta.intrinsic_metadata.index = index;
meta.intrinsic_metadata.timeinterval = timeinterval;
}
table tbl_direction {
actions = {
act_forward;
}
key = {
standard_metadata.ingress_port : exact;
}
}
table tbl_flows {
actions = {
act_tag;
}
key = {
hdr.ipv4.dst : ternary;
hdr.ipv4.src : ternary;
hdr.tcp.src : ternary;
hdr.tcp.dst : ternary;
}
}
apply {
if(hdr.ipv4.isValid()) {
if(hdr.tcp.isValid()) {
if(tbl_flows.apply().hit) {
do_wavelets();
}
}
hdr.ipv4.ttl = hdr.ipv4.ttl - 1;
tbl_direction.apply();
} else {
if(hdr.ethernet.etype == ARP_TYPE) {
tbl_direction.apply();
} else {
mark_to_drop();
}
}
}
}
control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
apply {
}
}
control computeChecksum(inout headers hdr, inout metadata meta) {
apply {
update_checksum(
hdr.ipv4.isValid(),
{
hdr.ipv4.version,
hdr.ipv4.ihl,
hdr.ipv4.diffserv,
hdr.ipv4.total_len,
hdr.ipv4.id,
hdr.ipv4.flags,
hdr.ipv4.offset,
hdr.ipv4.ttl,
hdr.ipv4.protocol,
hdr.ipv4.src,
hdr.ipv4.dst
},
hdr.ipv4.checksum,
HashAlgorithm.csum16
);
}
}
control DeparserImpl(packet_out packet, in headers hdr) {
apply {
packet.emit(hdr.ethernet);
packet.emit(hdr.ipv4);
packet.emit(hdr.tcp);
}
}
V1Switch(ParserImpl(), verifyChecksum(), ingress(), egress(), computeChecksum(), DeparserImpl()) main;