SassyTeckel commited on
Commit
b536889
·
verified ·
1 Parent(s): 3c3146c

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. individual_files/000028__raw-repositories__bartoszlomiej__Mininet-P4-introduction.p4 +224 -0
  2. individual_files/000029__raw-repositories__bartoszlomiej__Mininet-P4-introduction.p4 +232 -0
  3. individual_files/000032__raw-repositories__bartoszlomiej__Mininet-P4-introduction.p4 +213 -0
  4. individual_files/000033__raw-repositories__0Shark__p4lab.p4 +414 -0
  5. individual_files/000034__raw-repositories__0Shark__p4lab.p4 +214 -0
  6. individual_files/000035__raw-repositories__0Shark__p4lab.p4 +184 -0
  7. individual_files/000036__raw-repositories__0Shark__p4lab.p4 +158 -0
  8. individual_files/000037__raw-repositories__ana13zs__p4tutorials.p4 +144 -0
  9. individual_files/000038__raw-repositories__ana13zs__p4tutorials.p4 +183 -0
  10. individual_files/000039__raw-repositories__ana13zs__p4tutorials.p4 +163 -0
  11. individual_files/000040__raw-repositories__ana13zs__p4tutorials.p4 +232 -0
  12. individual_files/000041__raw-repositories__benedettapacilli__programmable-networking-lab-exercises.p4 +279 -0
  13. individual_files/000042__raw-repositories__benedettapacilli__programmable-networking-lab-exercises.p4 +292 -0
  14. individual_files/000043__raw-repositories__ByungUkMin__p4-encryption.p4 +164 -0
  15. individual_files/000044__raw-repositories__ByungUkMin__p4-encryption.p4 +287 -0
  16. individual_files/000045__raw-repositories__cpt-harlock__p4-cuckoo-hash.p4 +198 -0
  17. individual_files/000046__raw-repositories__bennyrubin__HydraCode.p4 +406 -0
  18. individual_files/000047__raw-repositories__bennyrubin__HydraCode.p4 +487 -0
  19. individual_files/000048__raw-repositories__cslev__p4.p4 +114 -0
  20. individual_files/000049__raw-repositories__dcomp-leris__VR-AR-CG-network-telemetry.p4 +252 -0
  21. individual_files/000050__raw-repositories__DETERMINISTIC6G__det6g-blog-prog-soft-tsn-switch.p4 +168 -0
  22. individual_files/000051__raw-repositories__emdneto__dh-aes-p4.p4 +172 -0
  23. individual_files/000052__raw-repositories__epap011__P4Lang-SimpleLoadBalancer.p4 +416 -0
  24. individual_files/000053__raw-repositories__ebiken__p4srv6.p4 +1067 -0
  25. individual_files/000054__raw-repositories__ElhNoah__INT.p4 +1277 -0
  26. individual_files/000055__raw-repositories__felipejrampazzo__Projeto-IA376C.p4 +618 -0
  27. individual_files/000056__raw-repositories__f-555__Lemon.p4 +278 -0
  28. individual_files/000057__raw-repositories__f-555__Lemon.p4 +471 -0
  29. individual_files/000058__raw-repositories__f-555__Lemon.p4 +454 -0
  30. individual_files/000059__raw-repositories__diogocampos__p4-data-flow.p4 +287 -0
  31. individual_files/000060__raw-repositories__cornell-netlab__capisce.p4 +285 -0
  32. individual_files/000061__raw-repositories__cornell-netlab__capisce.p4 +243 -0
  33. individual_files/000062__raw-repositories__cornell-netlab__capisce.p4 +374 -0
  34. individual_files/000063__raw-repositories__cornell-netlab__capisce.p4 +274 -0
  35. individual_files/000064__raw-repositories__cornell-netlab__capisce.p4 +340 -0
  36. individual_files/000065__raw-repositories__cornell-netlab__capisce.p4 +222 -0
  37. individual_files/000066__raw-repositories__cornell-netlab__capisce.p4 +387 -0
  38. individual_files/000067__raw-repositories__cornell-netlab__capisce.p4 +323 -0
  39. individual_files/000068__raw-repositories__cornell-netlab__capisce.p4 +180 -0
  40. individual_files/000069__raw-repositories__cornell-netlab__capisce.p4 +392 -0
  41. individual_files/000070__raw-repositories__cornell-netlab__capisce.p4 +200 -0
  42. individual_files/000071__raw-repositories__cornell-netlab__capisce.p4 +213 -0
  43. individual_files/000072__raw-repositories__cornell-netlab__capisce.p4 +177 -0
  44. individual_files/000073__raw-repositories__cornell-netlab__capisce.p4 +279 -0
  45. individual_files/000074__raw-repositories__cornell-netlab__capisce.p4 +246 -0
  46. individual_files/000075__raw-repositories__cornell-netlab__capisce.p4 +98 -0
  47. individual_files/000076__raw-repositories__cornell-netlab__capisce.p4 +122 -0
  48. individual_files/000077__raw-repositories__cornell-netlab__capisce.p4 +186 -0
  49. individual_files/000078__raw-repositories__cornell-netlab__capisce.p4 +172 -0
  50. individual_files/000079__raw-repositories__cornell-netlab__capisce.p4 +191 -0
individual_files/000028__raw-repositories__bartoszlomiej__Mininet-P4-introduction.p4 ADDED
@@ -0,0 +1,224 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <core.p4>
2
+
3
+ #include <v1model.p4>
4
+
5
+ const bit<16> TYPE_IPV4 = 0x800;
6
+ const bit<16> TYPE_8021Q = 0x8100;
7
+
8
+ typedef bit<9> egressSpec_t;
9
+ typedef bit<48> macAddr_t;
10
+ typedef bit<32> ip4Addr_t;
11
+
12
+ typedef bit<16> tpid_t;
13
+
14
+ header ethernet_t{
15
+ macAddr_t dstAddr;
16
+ macAddr_t srcAddr;
17
+ bit<16> etherType;
18
+ }
19
+
20
+ header vlanTag_t{
21
+ tpid_t tpid;
22
+
23
+ // Tag protocol identifier
24
+ bit<1> pcp;
25
+
26
+ // Priority code point
27
+ bit<3> dei;
28
+
29
+ // Drop eligible indicator
30
+ bit<12> vid;
31
+
32
+ // VLAN identifier
33
+ }
34
+
35
+ header ipv4_t{
36
+ bit<4> version;
37
+ bit<4> ihl;
38
+ bit<8> diffserv;
39
+ bit<16> totalLen;
40
+ bit<16> identification;
41
+ bit<3> flags;
42
+ bit<13> fragOffset;
43
+ bit<8> ttl;
44
+ bit<8> protocol;
45
+ bit<16> hdrChecksum;
46
+ ip4Addr_t srcAddr;
47
+ ip4Addr_t dstAddr;
48
+ }
49
+
50
+ struct headers{
51
+ ethernet_t ethernet;
52
+ vlanTag_t vlanTag;
53
+ ipv4_t ipv4;
54
+ }
55
+
56
+ struct metadata{
57
+ egressSpec_t port;
58
+ }
59
+
60
+ parser parserI(packet_in pkt, out headers hdr, inout metadata meta, inout standard_metadata_t stdmeta){
61
+ state start{
62
+
63
+ transition parse_ethernet;
64
+ }
65
+
66
+ state parse_ethernet {
67
+ pkt.extract(hdr.ethernet);
68
+ transition select(hdr.ethernet.etherType){
69
+ TYPE_8021Q: parse_vlanTag;
70
+ TYPE_IPV4: parse_ipv4;
71
+ default: accept;
72
+ }
73
+ }
74
+
75
+ state parse_vlanTag{
76
+ pkt.extract(hdr.vlanTag);
77
+ transition accept;
78
+ }
79
+
80
+ state parse_ipv4{
81
+ pkt.extract(hdr.ipv4);
82
+ transition accept;
83
+ }
84
+ }
85
+
86
+ control myVerifyChecksum(inout headers hdr, inout metadata meta){
87
+ apply{}
88
+ }
89
+
90
+ control cIngress(inout headers hdr, inout metadata meta, inout standard_metadata_t stdmeta){
91
+ action drop(){
92
+ mark_to_drop(stdmeta);
93
+ }
94
+
95
+ action mac_forward(macAddr_t dstAddr, egressSpec_t port){
96
+ stdmeta.egress_spec = port;
97
+ meta.port = port;
98
+ hdr.ethernet.srcAddr = hdr.ethernet.dstAddr;
99
+ hdr.ethernet.dstAddr = dstAddr;
100
+ }
101
+
102
+ table vlan_parse_exact{
103
+ key = {
104
+ hdr.ethernet.srcAddr: exact;
105
+ }
106
+ actions = {
107
+ mac_forward;
108
+ drop;
109
+ NoAction;
110
+ }
111
+ size = 1024;
112
+ default_action = NoAction();
113
+ }
114
+
115
+
116
+
117
+ action add_vlanTag(macAddr_t dstAddr, egressSpec_t port, bit<12> vid){
118
+ stdmeta.egress_spec = port;
119
+ hdr.ethernet.srcAddr = hdr.ethernet.dstAddr;
120
+ hdr.ethernet.dstAddr = dstAddr;
121
+ hdr.vlanTag.tpid = TYPE_8021Q;
122
+ hdr.vlanTag.vid = vid;
123
+ hdr.vlanTag.setValid();
124
+ hdr.ethernet.etherType = TYPE_8021Q;
125
+ }
126
+
127
+ table add_vlanTag_exact{
128
+ key = {
129
+ hdr.ethernet.srcAddr: exact;
130
+ }
131
+
132
+ actions = {
133
+ add_vlanTag;
134
+ drop;
135
+ NoAction;
136
+ }
137
+ default_action = NoAction();
138
+ }
139
+
140
+ apply{
141
+ if(hdr.ipv4.isValid() && !hdr.vlanTag.isValid()){
142
+ add_vlanTag_exact.apply();
143
+
144
+ }
145
+ else if(hdr.vlanTag.isValid()){
146
+ vlan_parse_exact.apply();
147
+ }
148
+ }
149
+ }
150
+
151
+
152
+ control cEgress(inout headers hdr, inout metadata meta, inout standard_metadata_t stdmeta){
153
+
154
+ action remove_vlanTag(){
155
+ hdr.vlanTag.setInvalid();
156
+ hdr.ethernet.etherType = TYPE_IPV4;
157
+ }
158
+
159
+ action remove(){
160
+ hdr.vlanTag.setInvalid();
161
+ hdr.ethernet.etherType = TYPE_IPV4;
162
+ }
163
+
164
+ table remove_vlanTag_exact{
165
+ key = {
166
+ meta.port: exact;
167
+ }
168
+
169
+ actions = {
170
+ remove_vlanTag;
171
+ remove;
172
+ NoAction;
173
+ }
174
+
175
+ default_action = remove();
176
+ }
177
+ apply{
178
+
179
+
180
+ if(hdr.vlanTag.isValid()){
181
+ remove_vlanTag_exact.apply();
182
+ }
183
+
184
+ }
185
+ }
186
+
187
+
188
+ control myComputeChecksum(inout headers hdr, inout metadata meta){
189
+ apply{/*
190
+ update_checksum(
191
+ hdr.ipv4.isValid(),
192
+ { hdr.ipv4.version,
193
+ hdr.ipv4.ihl,
194
+ hdr.ipv4.diffserv,
195
+ hdr.ipv4.totalLen,
196
+ hdr.ipv4.identification,
197
+ hdr.ipv4.flags,
198
+ hdr.ipv4.fragOffset,
199
+ hdr.ipv4.ttl,
200
+ hdr.ipv4.protocol,
201
+ hdr.ipv4.srcAddr,
202
+ hdr.ipv4.dstAddr },
203
+ hdr.ipv4.hdrChecksum,
204
+ HashAlgorithm.csum16);
205
+ */
206
+ }
207
+ }
208
+
209
+ control deparserI(packet_out packet, in headers hdr){
210
+ apply{
211
+ packet.emit(hdr.ethernet);
212
+
213
+ packet.emit(hdr.ipv4);
214
+ }
215
+ }
216
+
217
+ V1Switch(
218
+ parserI(),
219
+ myVerifyChecksum(),
220
+ cIngress(),
221
+ cEgress(),
222
+ myComputeChecksum(),
223
+ deparserI()
224
+ ) main;
individual_files/000029__raw-repositories__bartoszlomiej__Mininet-P4-introduction.p4 ADDED
@@ -0,0 +1,232 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <core.p4>
2
+
3
+ #include <v1model.p4>
4
+
5
+ const bit<16> TYPE_IPV4 = 0x800;
6
+ const bit<8> TYPE_TCP = 6;
7
+ const bit<8> TYPE_UDP = 17;
8
+
9
+
10
+ typedef bit<9> egressSpec_t;
11
+ typedef bit<48> macAddr_t;
12
+ typedef bit<32> ip4Addr_t;
13
+ typedef bit<128> ip6Addr_t;
14
+
15
+ typedef bit<32> packetCounter_t;
16
+ typedef bit<8> port_id_t;
17
+
18
+ header ethernet_t{
19
+ macAddr_t dstAddr;
20
+ macAddr_t srcAddr;
21
+ bit<16> etherType;
22
+ }
23
+
24
+ header ipv4_t{
25
+ bit<4> version;
26
+ bit<4> ihl;
27
+ bit<8> diffserv;
28
+ bit<16> totalLen;
29
+ bit<16> identification;
30
+ bit<3> flags;
31
+ bit<13> fragOffset;
32
+ bit<8> ttl;
33
+ bit<8> protocol;
34
+ bit<16> hdrChecksum;
35
+ ip4Addr_t srcAddr;
36
+ ip4Addr_t dstAddr;
37
+ }
38
+
39
+
40
+ header udp_t{
41
+ bit<16> source_port;
42
+ bit<16> destination_port;
43
+ bit<16> length;
44
+ bit<16> check_sum;
45
+ }
46
+
47
+ header tcp_t{
48
+ bit<16> srcPort;
49
+ bit<16> dstPort;
50
+ bit<32> seqNo;
51
+ bit<32> ackNo;
52
+ bit<4> dataOffset;
53
+ bit<4> res;
54
+ bit<1> cwr;
55
+ bit<1> ece;
56
+ bit<1> urg;
57
+ bit<1> ack;
58
+ bit<1> psh;
59
+ bit<1> rst;
60
+ bit<1> syn;
61
+ bit<1> fin;
62
+ bit<16> window;
63
+ bit<16> checksum;
64
+ bit<16> urgentPtr;
65
+ }
66
+
67
+ struct headers{
68
+ ethernet_t ethernet;
69
+ ipv4_t ipv4;
70
+ tcp_t tcp;
71
+ }
72
+
73
+ struct metadata{
74
+ bit<16> port;
75
+ }
76
+
77
+ parser parserI(packet_in pkt, out headers hdr, inout metadata meta, inout standard_metadata_t stdmeta){
78
+ state start{
79
+
80
+ transition parse_ethernet;
81
+ }
82
+
83
+ state parse_ethernet {
84
+ pkt.extract(hdr.ethernet);
85
+ transition select(hdr.ethernet.etherType){
86
+ TYPE_IPV4: parse_ipv4;
87
+ default: accept;
88
+ }
89
+ }
90
+
91
+ state parse_ipv4{
92
+ pkt.extract(hdr.ipv4);
93
+ transition select(hdr.ipv4.protocol){
94
+ TYPE_TCP: parse_transport;
95
+ TYPE_UDP: parse_transport;
96
+ default: accept;
97
+ }
98
+ }
99
+
100
+ state parse_transport{
101
+ pkt.extract(hdr.tcp);
102
+
103
+ transition accept;
104
+ }
105
+ }
106
+
107
+ control myVerifyChecksum(inout headers hdr, inout metadata meta){
108
+ apply{}
109
+ }
110
+
111
+ control cIngress(inout headers hdr, inout metadata meta, inout standard_metadata_t stdmeta){
112
+
113
+ counter(64, CounterType.packets) count_parsed;
114
+ direct_counter(CounterType.packets) count_dropped;
115
+
116
+ action drop(){
117
+ count_dropped.count();
118
+
119
+ // counts dropped packets on all ports
120
+ mark_to_drop(stdmeta);
121
+ }
122
+
123
+ action ipv4_forward(macAddr_t dstAddr, egressSpec_t port){
124
+ stdmeta.egress_spec = port;
125
+ hdr.ethernet.srcAddr = hdr.ethernet.dstAddr;
126
+ hdr.ethernet.dstAddr = dstAddr;
127
+ hdr.ipv4.ttl = hdr.ipv4.ttl - 1;
128
+ count_parsed.count((bit<32>) stdmeta.ingress_port);
129
+
130
+ // counts
131
+ }
132
+
133
+ table ipv4_lpm{
134
+ key = {
135
+ hdr.ipv4.dstAddr: lpm;
136
+ }
137
+ actions = {
138
+ ipv4_forward;
139
+ drop;
140
+ NoAction;
141
+ }
142
+ size = 1024;
143
+ default_action = NoAction();
144
+ }
145
+
146
+ table traffic_filter{
147
+ key = {
148
+ hdr.ipv4.dstAddr: ternary;
149
+
150
+ }
151
+ actions = {
152
+ ipv4_forward;
153
+ drop;
154
+ }
155
+ counters = count_dropped;
156
+ size = 1024;
157
+ default_action = drop();
158
+ }
159
+
160
+ apply{
161
+ if(hdr.ipv4.isValid()){
162
+
163
+
164
+ if(hdr.tcp.isValid()){
165
+ traffic_filter.apply();
166
+ }
167
+ }
168
+ }
169
+ }
170
+
171
+
172
+ control cEgress(inout headers hdr, inout metadata meta, inout standard_metadata_t stdmeta){
173
+
174
+ counter(64, CounterType.packets) count_sent;
175
+
176
+ action updateCounter(){
177
+ count_sent.count((bit<32>) stdmeta.egress_spec);
178
+ }
179
+
180
+ table statistics{
181
+ key = {
182
+ hdr.ipv4.dstAddr: lpm;
183
+ }
184
+ actions = {
185
+ updateCounter;
186
+ NoAction;
187
+ }
188
+ size = 1024;
189
+ default_action = NoAction();
190
+ }
191
+ apply{
192
+ statistics.apply();
193
+ }
194
+ }
195
+
196
+
197
+ control myComputeChecksum(inout headers hdr, inout metadata meta){
198
+ apply{
199
+ update_checksum(
200
+ hdr.ipv4.isValid(),
201
+ { hdr.ipv4.version,
202
+ hdr.ipv4.ihl,
203
+ hdr.ipv4.diffserv,
204
+ hdr.ipv4.totalLen,
205
+ hdr.ipv4.identification,
206
+ hdr.ipv4.flags,
207
+ hdr.ipv4.fragOffset,
208
+ hdr.ipv4.ttl,
209
+ hdr.ipv4.protocol,
210
+ hdr.ipv4.srcAddr,
211
+ hdr.ipv4.dstAddr },
212
+ hdr.ipv4.hdrChecksum,
213
+ HashAlgorithm.csum16);
214
+ }
215
+ }
216
+
217
+ control deparserI(packet_out packet, in headers hdr){
218
+ apply{
219
+ packet.emit(hdr.ethernet);
220
+ packet.emit(hdr.ipv4);
221
+ packet.emit(hdr.tcp);
222
+ }
223
+ }
224
+
225
+ V1Switch(
226
+ parserI(),
227
+ myVerifyChecksum(),
228
+ cIngress(),
229
+ cEgress(),
230
+ myComputeChecksum(),
231
+ deparserI()
232
+ ) main;
individual_files/000032__raw-repositories__bartoszlomiej__Mininet-P4-introduction.p4 ADDED
@@ -0,0 +1,213 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <core.p4>
2
+
3
+ #include <v1model.p4>
4
+
5
+ const bit<16> TYPE_IPV4 = 0x800;
6
+ const bit<16> TYPE_8021Q = 0x8100;
7
+
8
+ typedef bit<9> egressSpec_t;
9
+ typedef bit<48> macAddr_t;
10
+ typedef bit<32> ip4Addr_t;
11
+
12
+ typedef bit<16> tpid_t;
13
+
14
+ header ethernet_t{
15
+ macAddr_t dstAddr;
16
+ macAddr_t srcAddr;
17
+ bit<16> etherType;
18
+ }
19
+
20
+ header vlanTag_t{
21
+ tpid_t tpid;
22
+
23
+ // Tag protocol identifier
24
+ bit<1> pcp;
25
+
26
+ // Priority code point
27
+ bit<3> dei;
28
+
29
+ // Drop eligible indicator
30
+ bit<12> vid;
31
+
32
+ // VLAN identifier
33
+ }
34
+
35
+ header ipv4_t{
36
+ bit<4> version;
37
+ bit<4> ihl;
38
+ bit<8> diffserv;
39
+ bit<16> totalLen;
40
+ bit<16> identification;
41
+ bit<3> flags;
42
+ bit<13> fragOffset;
43
+ bit<8> ttl;
44
+ bit<8> protocol;
45
+ bit<16> hdrChecksum;
46
+ ip4Addr_t srcAddr;
47
+ ip4Addr_t dstAddr;
48
+ }
49
+
50
+ struct headers{
51
+ ethernet_t ethernet;
52
+ vlanTag_t vlanTag;
53
+ ipv4_t ipv4;
54
+ }
55
+
56
+ struct mac_learn_t{
57
+ bit<48> srcAddr;
58
+ bit<9> ingress_port;
59
+ bit<32> srcIpAddr;
60
+ }
61
+
62
+ struct metadata{
63
+ egressSpec_t port;
64
+ mac_learn_t mac_learn_msg;
65
+ }
66
+
67
+ parser parserI(packet_in pkt, out headers hdr, inout metadata meta, inout standard_metadata_t stdmeta){
68
+ state start{
69
+
70
+ transition parse_ethernet;
71
+ }
72
+
73
+ state parse_ethernet {
74
+ pkt.extract(hdr.ethernet);
75
+ transition select(hdr.ethernet.etherType){
76
+ TYPE_IPV4: parse_ipv4;
77
+ default: accept;
78
+ }
79
+ }
80
+
81
+ state parse_ipv4{
82
+ pkt.extract(hdr.ipv4);
83
+ meta.mac_learn_msg.srcIpAddr = hdr.ipv4.srcAddr;
84
+ transition accept;
85
+ }
86
+ }
87
+
88
+ control myVerifyChecksum(inout headers hdr, inout metadata meta){
89
+ apply{}
90
+ }
91
+
92
+ control cIngress(inout headers hdr, inout metadata meta, inout standard_metadata_t stdmeta){
93
+
94
+ action drop(){
95
+ mark_to_drop(stdmeta);
96
+ }
97
+
98
+ action unknown_source(){
99
+ meta.mac_learn_msg.srcAddr = hdr.ethernet.srcAddr;
100
+ meta.mac_learn_msg.ingress_port = stdmeta.ingress_port;
101
+
102
+ digest<mac_learn_t>(0, meta.mac_learn_msg);
103
+
104
+ // possible error
105
+ }
106
+
107
+ table learned_MAC{
108
+ key = {
109
+ hdr.ethernet.srcAddr: exact;
110
+ }
111
+ actions = {
112
+ unknown_source;
113
+ NoAction;
114
+ }
115
+ default_action = unknown_source();
116
+ }
117
+
118
+ action mac_forward(macAddr_t dstAddr, egressSpec_t port){
119
+ stdmeta.egress_spec = port;
120
+
121
+ hdr.ethernet.dstAddr = dstAddr;
122
+ }
123
+
124
+ table l2_table{
125
+ key = {
126
+ hdr.ipv4.dstAddr: exact;
127
+ }
128
+ actions = {
129
+ mac_forward;
130
+ drop;
131
+ NoAction;
132
+ }
133
+ size = 1024;
134
+ default_action = NoAction();
135
+ }
136
+
137
+ apply{
138
+ if(hdr.ipv4.isValid()){
139
+ learned_MAC.apply();
140
+ l2_table.apply();
141
+ }
142
+ }
143
+ }
144
+
145
+
146
+ control cEgress(inout headers hdr, inout metadata meta, inout standard_metadata_t stdmeta){
147
+
148
+ action remove_vlanTag(){
149
+ hdr.vlanTag.setInvalid();
150
+ hdr.ethernet.etherType = TYPE_IPV4;
151
+ }
152
+
153
+ action remove(){
154
+ hdr.vlanTag.setInvalid();
155
+ hdr.ethernet.etherType = TYPE_IPV4;
156
+ }
157
+
158
+ table remove_vlanTag_exact{
159
+ key = {
160
+ meta.port: exact;
161
+ }
162
+
163
+ actions = {
164
+ remove_vlanTag;
165
+ remove;
166
+ NoAction;
167
+ }
168
+ default_action = NoAction();
169
+ }
170
+ apply{
171
+
172
+
173
+ }
174
+ }
175
+
176
+
177
+ control myComputeChecksum(inout headers hdr, inout metadata meta){
178
+ apply{/*
179
+ update_checksum(
180
+ hdr.ipv4.isValid(),
181
+ { hdr.ipv4.version,
182
+ hdr.ipv4.ihl,
183
+ hdr.ipv4.diffserv,
184
+ hdr.ipv4.totalLen,
185
+ hdr.ipv4.identification,
186
+ hdr.ipv4.flags,
187
+ hdr.ipv4.fragOffset,
188
+ hdr.ipv4.ttl,
189
+ hdr.ipv4.protocol,
190
+ hdr.ipv4.srcAddr,
191
+ hdr.ipv4.dstAddr },
192
+ hdr.ipv4.hdrChecksum,
193
+ HashAlgorithm.csum16);
194
+ */
195
+ }
196
+ }
197
+
198
+ control deparserI(packet_out packet, in headers hdr){
199
+ apply{
200
+ packet.emit(hdr.ethernet);
201
+
202
+ packet.emit(hdr.ipv4);
203
+ }
204
+ }
205
+
206
+ V1Switch(
207
+ parserI(),
208
+ myVerifyChecksum(),
209
+ cIngress(),
210
+ cEgress(),
211
+ myComputeChecksum(),
212
+ deparserI()
213
+ ) main;
individual_files/000033__raw-repositories__0Shark__p4lab.p4 ADDED
@@ -0,0 +1,414 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <core.p4>
2
+ #include <v1model.p4>
3
+
4
+ const bit<16> TYPE_IPV4 = 0x800;
5
+ const bit<16> TYPE_HULA = 0x2345;
6
+
7
+ #define MAX_HOPS 9
8
+ #define TOR_NUM 32
9
+ #define TOR_NUM_1 33
10
+
11
+
12
+
13
+ typedef bit<9> egressSpec_t;
14
+ typedef bit<48> macAddr_t;
15
+ typedef bit<32> ip4Addr_t;
16
+ typedef bit<15> qdepth_t;
17
+ typedef bit<32> digest_t;
18
+
19
+ header ethernet_t {
20
+ macAddr_t dstAddr;
21
+ macAddr_t srcAddr;
22
+ bit<16> etherType;
23
+ }
24
+
25
+ header srcRoute_t {
26
+ bit<1> bos;
27
+ bit<15> port;
28
+ }
29
+
30
+ header hula_t {
31
+
32
+ /* 0 is forward path, 1 is the backward path */
33
+ bit<1> dir;
34
+
35
+ /* max qdepth seen so far in the forward path */
36
+ qdepth_t qdepth;
37
+
38
+ /* digest of the source routing list to uniquely identify each path */
39
+ digest_t digest;
40
+ }
41
+
42
+ header ipv4_t {
43
+ bit<4> version;
44
+ bit<4> ihl;
45
+ bit<8> diffserv;
46
+ bit<16> totalLen;
47
+ bit<16> identification;
48
+ bit<3> flags;
49
+ bit<13> fragOffset;
50
+ bit<8> ttl;
51
+ bit<8> protocol;
52
+ bit<16> hdrChecksum;
53
+ ip4Addr_t srcAddr;
54
+ ip4Addr_t dstAddr;
55
+ }
56
+
57
+ header udp_t {
58
+ bit<16> srcPort;
59
+ bit<16> dstPort;
60
+ bit<16> length_;
61
+ bit<16> checksum;
62
+ }
63
+
64
+ struct metadata {
65
+
66
+ bit<32> index;
67
+ }
68
+
69
+ struct headers {
70
+ ethernet_t ethernet;
71
+ srcRoute_t[MAX_HOPS] srcRoutes;
72
+ ipv4_t ipv4;
73
+ udp_t udp;
74
+ hula_t hula;
75
+ }
76
+
77
+
78
+
79
+ parser MyParser(packet_in packet,
80
+ out headers hdr,
81
+ inout metadata meta,
82
+ inout standard_metadata_t standard_metadata) {
83
+
84
+ state start {
85
+ transition parse_ethernet;
86
+ }
87
+
88
+ state parse_ethernet {
89
+ packet.extract(hdr.ethernet);
90
+ transition select(hdr.ethernet.etherType) {
91
+ TYPE_HULA : parse_hula;
92
+ TYPE_IPV4 : parse_ipv4;
93
+ default : accept;
94
+ }
95
+ }
96
+
97
+ state parse_hula {
98
+ packet.extract(hdr.hula);
99
+ transition parse_srcRouting;
100
+ }
101
+
102
+ state parse_srcRouting {
103
+ packet.extract(hdr.srcRoutes.next);
104
+ transition select(hdr.srcRoutes.last.bos) {
105
+ 1 : parse_ipv4;
106
+ default : parse_srcRouting;
107
+ }
108
+ }
109
+
110
+ state parse_ipv4 {
111
+ packet.extract(hdr.ipv4);
112
+ transition select(hdr.ipv4.protocol) {
113
+ 8w17: parse_udp;
114
+ default: accept;
115
+ }
116
+ }
117
+
118
+ state parse_udp {
119
+ packet.extract(hdr.udp);
120
+ transition accept;
121
+ }
122
+
123
+ }
124
+
125
+
126
+
127
+
128
+ control MyVerifyChecksum(inout headers hdr, inout metadata meta) {
129
+ apply { }
130
+ }
131
+
132
+
133
+
134
+
135
+ control MyIngress(inout headers hdr,
136
+ inout metadata meta,
137
+ inout standard_metadata_t standard_metadata) {
138
+
139
+
140
+ register<qdepth_t>(TOR_NUM) srcindex_qdepth_reg;
141
+
142
+
143
+ register<digest_t>(TOR_NUM) srcindex_digest_reg;
144
+
145
+
146
+ /* At each hop, saves the next hop to reach each destination ToR */
147
+ register<bit<16>>(TOR_NUM) dstindex_nhop_reg;
148
+
149
+
150
+ /* At each hop saves the next hop for each flow */
151
+ register<bit<16>>(65536) flow_port_reg;
152
+
153
+
154
+ /* This action will drop packets */
155
+ action drop() {
156
+ mark_to_drop(standard_metadata);
157
+ }
158
+
159
+ action nop() {
160
+ }
161
+
162
+ action update_ttl(){
163
+ hdr.ipv4.ttl = hdr.ipv4.ttl - 1;
164
+ }
165
+
166
+ action set_dmac(macAddr_t dstAddr){
167
+ hdr.ethernet.srcAddr = hdr.ethernet.dstAddr;
168
+ hdr.ethernet.dstAddr = dstAddr;
169
+ }
170
+
171
+
172
+ /* This action just applies source routing */
173
+ action srcRoute_nhop() {
174
+ standard_metadata.egress_spec = (bit<9>)hdr.srcRoutes[0].port;
175
+ hdr.srcRoutes.pop_front(1);
176
+ }
177
+
178
+
179
+ action hula_dst(bit<32> index) {
180
+ meta.index = index;
181
+ }
182
+
183
+
184
+ action hula_set_nhop(bit<32> index) {
185
+ dstindex_nhop_reg.write(index, (bit<16>)standard_metadata.ingress_port);
186
+ }
187
+
188
+
189
+ action hula_get_nhop(bit<32> index){
190
+ bit<16> tmp;
191
+ dstindex_nhop_reg.read(tmp, index);
192
+ standard_metadata.egress_spec = (bit<9>)tmp;
193
+ }
194
+
195
+
196
+ /* Record best path at destination ToR */
197
+ action change_best_path_at_dst(){
198
+ srcindex_qdepth_reg.write(meta.index, hdr.hula.qdepth);
199
+ srcindex_digest_reg.write(meta.index, hdr.hula.digest);
200
+ }
201
+
202
+
203
+ action return_hula_to_src(){
204
+ hdr.hula.dir = 1;
205
+ standard_metadata.egress_spec = standard_metadata.ingress_port;
206
+ }
207
+
208
+
209
+ table hula_fwd {
210
+ key = {
211
+ hdr.ipv4.dstAddr: exact;
212
+ hdr.ipv4.srcAddr: exact;
213
+ }
214
+ actions = {
215
+ hula_dst;
216
+ srcRoute_nhop;
217
+ }
218
+ default_action = srcRoute_nhop;
219
+ size = TOR_NUM_1;
220
+
221
+ }
222
+
223
+
224
+ table hula_bwd {
225
+ key = {
226
+ hdr.ipv4.dstAddr: lpm;
227
+ }
228
+ actions = {
229
+ hula_set_nhop;
230
+ }
231
+ size = TOR_NUM;
232
+ }
233
+
234
+
235
+ table hula_src {
236
+ key = {
237
+ hdr.ipv4.srcAddr: exact;
238
+ }
239
+ actions = {
240
+ drop;
241
+ srcRoute_nhop;
242
+ }
243
+ default_action = srcRoute_nhop;
244
+ size = 2;
245
+ }
246
+
247
+
248
+ /* Get nexthop based on dstAddr using registers */
249
+ table hula_nhop {
250
+ key = {
251
+ hdr.ipv4.dstAddr: lpm;
252
+ }
253
+ actions = {
254
+ hula_get_nhop;
255
+ drop;
256
+ }
257
+ default_action = drop;
258
+ size = TOR_NUM;
259
+ }
260
+
261
+
262
+ /* Set right dmac for packets going to hosts */
263
+ table dmac {
264
+ key = {
265
+ standard_metadata.egress_spec : exact;
266
+ }
267
+ actions = {
268
+ set_dmac;
269
+ nop;
270
+ }
271
+ default_action = nop;
272
+ size = 16;
273
+ }
274
+
275
+ apply {
276
+ if (hdr.hula.isValid()){
277
+ if (hdr.hula.dir == 0){
278
+ switch(hula_fwd.apply().action_run){
279
+
280
+
281
+ hula_dst: {
282
+
283
+
284
+ /* if it is the destination ToR compare qdepth */
285
+ qdepth_t old_qdepth;
286
+ srcindex_qdepth_reg.read(old_qdepth, meta.index);
287
+
288
+ if (old_qdepth > hdr.hula.qdepth){
289
+ change_best_path_at_dst();
290
+
291
+
292
+ /* only return hula packets that update best path */
293
+ return_hula_to_src();
294
+ }else{
295
+
296
+
297
+ digest_t old_digest;
298
+ srcindex_digest_reg.read(old_digest, meta.index);
299
+ if (old_digest == hdr.hula.digest){
300
+ srcindex_qdepth_reg.write(meta.index, hdr.hula.qdepth);
301
+ }
302
+
303
+ drop();
304
+ }
305
+ }
306
+ }
307
+ }else {
308
+
309
+ /* update routing table in reverse path */
310
+ hula_bwd.apply();
311
+
312
+
313
+ /* drop if source ToR */
314
+ hula_src.apply();
315
+ }
316
+ } else if (hdr.ipv4.isValid()){
317
+ bit<32> flow_hash;
318
+ hash(
319
+ flow_hash,
320
+ HashAlgorithm.crc16,
321
+ 32w0,
322
+ { hdr.ipv4.srcAddr, hdr.ipv4.dstAddr, hdr.udp.srcPort},
323
+ 32w65536
324
+ );
325
+
326
+ bit<16> port;
327
+ flow_port_reg.read(port, flow_hash);
328
+
329
+ if (port == 0) {
330
+
331
+ // next hop for destination ToR
332
+ hula_nhop.apply();
333
+ bit<16> next_hop = (bit<16>)standard_metadata.egress_spec;
334
+ flow_port_reg.write(flow_hash, next_hop);
335
+ } else {
336
+ standard_metadata.egress_spec = (bit<9>)port;
337
+ }
338
+
339
+
340
+ /* set the right dmac so that ping and iperf work */
341
+ dmac.apply();
342
+ }else {
343
+ drop();
344
+ }
345
+
346
+ if (hdr.ipv4.isValid()){
347
+ update_ttl();
348
+ }
349
+ }
350
+ }
351
+
352
+
353
+
354
+ control MyEgress(inout headers hdr,
355
+ inout metadata meta,
356
+ inout standard_metadata_t standard_metadata) {
357
+ apply {
358
+
359
+ //hula header is valid and forward path
360
+ if (hdr.hula.isValid() && hdr.hula.dir == 0) {
361
+
362
+ // hula qdepth greater than curr queue depth
363
+ if (hdr.hula.qdepth < (qdepth_t)standard_metadata.deq_qdepth) {
364
+ hdr.hula.qdepth = (qdepth_t)standard_metadata.deq_qdepth;
365
+ }
366
+ }
367
+ }
368
+ }
369
+
370
+
371
+
372
+ control MyComputeChecksum(inout headers hdr, inout metadata meta) {
373
+ apply {
374
+ update_checksum(
375
+ hdr.ipv4.isValid(),
376
+ { hdr.ipv4.version,
377
+ hdr.ipv4.ihl,
378
+ hdr.ipv4.diffserv,
379
+ hdr.ipv4.totalLen,
380
+ hdr.ipv4.identification,
381
+ hdr.ipv4.flags,
382
+ hdr.ipv4.fragOffset,
383
+ hdr.ipv4.ttl,
384
+ hdr.ipv4.protocol,
385
+ hdr.ipv4.srcAddr,
386
+ hdr.ipv4.dstAddr },
387
+ hdr.ipv4.hdrChecksum,
388
+ HashAlgorithm.csum16);
389
+ }
390
+ }
391
+
392
+
393
+
394
+
395
+ control MyDeparser(packet_out packet, in headers hdr) {
396
+ apply {
397
+ packet.emit(hdr.ethernet);
398
+ packet.emit(hdr.hula);
399
+ packet.emit(hdr.srcRoutes);
400
+ packet.emit(hdr.ipv4);
401
+ packet.emit(hdr.udp);
402
+ }
403
+ }
404
+
405
+
406
+
407
+ V1Switch(
408
+ MyParser(),
409
+ MyVerifyChecksum(),
410
+ MyIngress(),
411
+ MyEgress(),
412
+ MyComputeChecksum(),
413
+ MyDeparser()
414
+ ) main;
individual_files/000034__raw-repositories__0Shark__p4lab.p4 ADDED
@@ -0,0 +1,214 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <core.p4>
2
+ #include <v1model.p4>
3
+
4
+
5
+
6
+ header ethernet_t {
7
+ bit<48> dstAddr;
8
+ bit<48> srcAddr;
9
+ bit<16> etherType;
10
+ }
11
+
12
+ header ipv4_t {
13
+ bit<4> version;
14
+ bit<4> ihl;
15
+ bit<8> diffserv;
16
+ bit<16> totalLen;
17
+ bit<16> identification;
18
+ bit<3> flags;
19
+ bit<13> fragOffset;
20
+ bit<8> ttl;
21
+ bit<8> protocol;
22
+ bit<16> hdrChecksum;
23
+ bit<32> srcAddr;
24
+ bit<32> dstAddr;
25
+ }
26
+
27
+ header tcp_t {
28
+ bit<16> srcPort;
29
+ bit<16> dstPort;
30
+ bit<32> seqNo;
31
+ bit<32> ackNo;
32
+ bit<4> dataOffset;
33
+ bit<3> res;
34
+ bit<3> ecn;
35
+ bit<6> ctrl;
36
+ bit<16> window;
37
+ bit<16> checksum;
38
+ bit<16> urgentPtr;
39
+ }
40
+
41
+ struct metadata {
42
+ bit<14> ecmp_select;
43
+ }
44
+
45
+ struct headers {
46
+ ethernet_t ethernet;
47
+ ipv4_t ipv4;
48
+ tcp_t tcp;
49
+ }
50
+
51
+
52
+
53
+ parser MyParser(packet_in packet,
54
+ out headers hdr,
55
+ inout metadata meta,
56
+ inout standard_metadata_t standard_metadata) {
57
+ state start {
58
+ transition parse_ethernet;
59
+ }
60
+ state parse_ethernet {
61
+ packet.extract(hdr.ethernet);
62
+ transition select(hdr.ethernet.etherType) {
63
+ 0x800: parse_ipv4;
64
+ default: accept;
65
+ }
66
+ }
67
+ state parse_ipv4 {
68
+ packet.extract(hdr.ipv4);
69
+ transition select(hdr.ipv4.protocol) {
70
+ 6: parse_tcp;
71
+ default: accept;
72
+ }
73
+ }
74
+ state parse_tcp {
75
+ packet.extract(hdr.tcp);
76
+ transition accept;
77
+ }
78
+ }
79
+
80
+
81
+
82
+ control MyVerifyChecksum(inout headers hdr, inout metadata meta) {
83
+ apply { }
84
+ }
85
+
86
+
87
+
88
+ control MyIngress(inout headers hdr,
89
+ inout metadata meta,
90
+ inout standard_metadata_t standard_metadata) {
91
+ bit<14> flow_hash;
92
+
93
+ action drop() {
94
+ mark_to_drop(standard_metadata);
95
+ }
96
+ action set_ecmp_select(bit<16> ecmp_base, bit<32> ecmp_count) {
97
+ hash(
98
+ flow_hash,
99
+ HashAlgorithm.crc16,
100
+ ecmp_base,
101
+ { hdr.ipv4.srcAddr,
102
+ hdr.ipv4.dstAddr,
103
+ hdr.ipv4.protocol,
104
+ hdr.tcp.srcPort,
105
+ hdr.tcp.dstPort },
106
+ ecmp_count
107
+ );
108
+
109
+ meta.ecmp_select = flow_hash;
110
+ }
111
+ action set_nhop(bit<48> nhop_dmac, bit<32> nhop_ipv4, bit<9> port) {
112
+ hdr.ethernet.dstAddr = nhop_dmac;
113
+ hdr.ipv4.dstAddr = nhop_ipv4;
114
+ standard_metadata.egress_spec = port;
115
+ hdr.ipv4.ttl = hdr.ipv4.ttl - 1;
116
+ }
117
+ table ecmp_group {
118
+ key = {
119
+ hdr.ipv4.dstAddr: lpm;
120
+ }
121
+ actions = {
122
+ drop;
123
+ set_ecmp_select;
124
+ }
125
+ size = 1024;
126
+ }
127
+ table ecmp_nhop {
128
+ key = {
129
+ meta.ecmp_select: exact;
130
+ }
131
+ actions = {
132
+ drop;
133
+ set_nhop;
134
+ }
135
+ size = 2;
136
+ }
137
+ apply {
138
+
139
+ if (hdr.ipv4.isValid() && hdr.ipv4.ttl > 0) {
140
+ ecmp_group.apply();
141
+ ecmp_nhop.apply();
142
+ }
143
+ }
144
+ }
145
+
146
+
147
+
148
+ control MyEgress(inout headers hdr,
149
+ inout metadata meta,
150
+ inout standard_metadata_t standard_metadata) {
151
+
152
+ action rewrite_mac(bit<48> smac) {
153
+ hdr.ethernet.srcAddr = smac;
154
+ }
155
+ action drop() {
156
+ mark_to_drop(standard_metadata);
157
+ }
158
+ table send_frame {
159
+ key = {
160
+ standard_metadata.egress_port: exact;
161
+ }
162
+ actions = {
163
+ rewrite_mac;
164
+ drop;
165
+ }
166
+ size = 256;
167
+ }
168
+ apply {
169
+ send_frame.apply();
170
+ }
171
+ }
172
+
173
+
174
+
175
+ control MyComputeChecksum(inout headers hdr, inout metadata meta) {
176
+ apply {
177
+ update_checksum(
178
+ hdr.ipv4.isValid(),
179
+ { hdr.ipv4.version,
180
+ hdr.ipv4.ihl,
181
+ hdr.ipv4.diffserv,
182
+ hdr.ipv4.totalLen,
183
+ hdr.ipv4.identification,
184
+ hdr.ipv4.flags,
185
+ hdr.ipv4.fragOffset,
186
+ hdr.ipv4.ttl,
187
+ hdr.ipv4.protocol,
188
+ hdr.ipv4.srcAddr,
189
+ hdr.ipv4.dstAddr },
190
+ hdr.ipv4.hdrChecksum,
191
+ HashAlgorithm.csum16);
192
+ }
193
+ }
194
+
195
+
196
+
197
+ control MyDeparser(packet_out packet, in headers hdr) {
198
+ apply {
199
+ packet.emit(hdr.ethernet);
200
+ packet.emit(hdr.ipv4);
201
+ packet.emit(hdr.tcp);
202
+ }
203
+ }
204
+
205
+
206
+
207
+ V1Switch(
208
+ MyParser(),
209
+ MyVerifyChecksum(),
210
+ MyIngress(),
211
+ MyEgress(),
212
+ MyComputeChecksum(),
213
+ MyDeparser()
214
+ ) main;
individual_files/000035__raw-repositories__0Shark__p4lab.p4 ADDED
@@ -0,0 +1,184 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <core.p4>
2
+ #include <v1model.p4>
3
+
4
+ const bit<16> TYPE_IPV4 = 0x800;
5
+
6
+
7
+ /* IP protocols */
8
+ const bit<8> IP_PROTOCOLS_ICMP = 1;
9
+ const bit<8> IP_PROTOCOLS_IGMP = 2;
10
+ const bit<8> IP_PROTOCOLS_IPV4 = 4;
11
+ const bit<8> IP_PROTOCOLS_TCP = 6;
12
+ const bit<8> IP_PROTOCOLS_UDP = 17;
13
+ const bit<8> IP_PROTOCOLS_IPV6 = 41;
14
+ const bit<8> IP_PROTOCOLS_GRE = 47;
15
+ const bit<8> IP_PROTOCOLS_IPSEC_ESP = 50;
16
+ const bit<8> IP_PROTOCOLS_IPSEC_AH = 51;
17
+ const bit<8> IP_PROTOCOLS_ICMPV6 = 58;
18
+ const bit<8> IP_PROTOCOLS_EIGRP = 88;
19
+ const bit<8> IP_PROTOCOLS_OSPF = 89;
20
+ const bit<8> IP_PROTOCOLS_PIM = 103;
21
+ const bit<8> IP_PROTOCOLS_VRRP = 112;
22
+
23
+
24
+
25
+
26
+ typedef bit<9> egressSpec_t;
27
+ typedef bit<48> macAddr_t;
28
+ typedef bit<32> ip4Addr_t;
29
+
30
+ header ethernet_t {
31
+ macAddr_t dstAddr;
32
+ macAddr_t srcAddr;
33
+ bit<16> etherType;
34
+ }
35
+
36
+
37
+ header ipv4_t {
38
+ bit<4> version;
39
+ bit<4> ihl;
40
+ bit<8> tos;
41
+ bit<16> totalLen;
42
+ bit<16> identification;
43
+ bit<3> flags;
44
+ bit<13> fragOffset;
45
+ bit<8> ttl;
46
+ bit<8> protocol;
47
+ bit<16> hdrChecksum;
48
+ ip4Addr_t srcAddr;
49
+ ip4Addr_t dstAddr;
50
+ }
51
+
52
+
53
+ struct metadata {
54
+ }
55
+
56
+ struct headers {
57
+ ethernet_t ethernet;
58
+ ipv4_t ipv4;
59
+ }
60
+
61
+
62
+
63
+ parser MyParser(packet_in packet,
64
+ out headers hdr,
65
+ inout metadata meta,
66
+ inout standard_metadata_t standard_metadata) {
67
+
68
+ state start {
69
+ transition parse_ethernet;
70
+ }
71
+
72
+ state parse_ethernet {
73
+ packet.extract(hdr.ethernet);
74
+ transition select(hdr.ethernet.etherType) {
75
+ TYPE_IPV4: parse_ipv4;
76
+ default: accept;
77
+ }
78
+ }
79
+
80
+ state parse_ipv4 {
81
+ packet.extract(hdr.ipv4);
82
+ transition accept;
83
+ }
84
+ }
85
+
86
+
87
+
88
+
89
+ control MyVerifyChecksum(inout headers hdr, inout metadata meta) {
90
+ apply { }
91
+ }
92
+
93
+
94
+
95
+
96
+ control MyIngress(inout headers hdr,
97
+ inout metadata meta,
98
+ inout standard_metadata_t standard_metadata) {
99
+ action drop() {
100
+ mark_to_drop(standard_metadata);
101
+ }
102
+
103
+ action ipv4_forward(macAddr_t dstAddr, egressSpec_t port) {
104
+ standard_metadata.egress_spec = port;
105
+ hdr.ethernet.srcAddr = hdr.ethernet.dstAddr;
106
+ hdr.ethernet.dstAddr = dstAddr;
107
+ hdr.ipv4.ttl = hdr.ipv4.ttl - 1;
108
+ }
109
+
110
+
111
+
112
+
113
+ table ipv4_lpm {
114
+ key = {
115
+ hdr.ipv4.dstAddr: lpm;
116
+ }
117
+ actions = {
118
+ ipv4_forward;
119
+ drop;
120
+ NoAction;
121
+ }
122
+ size = 1024;
123
+ default_action = NoAction();
124
+ }
125
+
126
+
127
+ apply {
128
+ if (hdr.ipv4.isValid()) {
129
+ ipv4_lpm.apply();
130
+ }
131
+ }
132
+ }
133
+
134
+
135
+
136
+ control MyEgress(inout headers hdr,
137
+ inout metadata meta,
138
+ inout standard_metadata_t standard_metadata) {
139
+ apply { }
140
+ }
141
+
142
+
143
+
144
+
145
+ control MyComputeChecksum(inout headers hdr, inout metadata meta) {
146
+ apply {
147
+
148
+ update_checksum(
149
+ hdr.ipv4.isValid(),
150
+ { hdr.ipv4.version,
151
+ hdr.ipv4.ihl,
152
+ hdr.ipv4.tos,
153
+ hdr.ipv4.totalLen,
154
+ hdr.ipv4.identification,
155
+ hdr.ipv4.flags,
156
+ hdr.ipv4.fragOffset,
157
+ hdr.ipv4.ttl,
158
+ hdr.ipv4.protocol,
159
+ hdr.ipv4.srcAddr,
160
+ hdr.ipv4.dstAddr },
161
+ hdr.ipv4.hdrChecksum,
162
+ HashAlgorithm.csum16);
163
+ }
164
+ }
165
+
166
+
167
+
168
+ control MyDeparser(packet_out packet, in headers hdr) {
169
+ apply {
170
+ packet.emit(hdr.ethernet);
171
+ packet.emit(hdr.ipv4);
172
+ }
173
+ }
174
+
175
+
176
+
177
+ V1Switch(
178
+ MyParser(),
179
+ MyVerifyChecksum(),
180
+ MyIngress(),
181
+ MyEgress(),
182
+ MyComputeChecksum(),
183
+ MyDeparser()
184
+ ) main;
individual_files/000036__raw-repositories__0Shark__p4lab.p4 ADDED
@@ -0,0 +1,158 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <core.p4>
2
+ #include <v1model.p4>
3
+
4
+ const bit<16> TYPE_IPV4 = 0x800;
5
+ const bit<16> TYPE_SRCROUTING = 0x1234;
6
+
7
+ #define MAX_HOPS 9
8
+
9
+
10
+
11
+ typedef bit<9> egressSpec_t;
12
+ typedef bit<48> macAddr_t;
13
+ typedef bit<32> ip4Addr_t;
14
+
15
+ header ethernet_t {
16
+ macAddr_t dstAddr;
17
+ macAddr_t srcAddr;
18
+ bit<16> etherType;
19
+ }
20
+
21
+ header srcRoute_t {
22
+ bit<1> bos;
23
+ bit<15> port;
24
+ }
25
+
26
+ header ipv4_t {
27
+ bit<4> version;
28
+ bit<4> ihl;
29
+ bit<8> diffserv;
30
+ bit<16> totalLen;
31
+ bit<16> identification;
32
+ bit<3> flags;
33
+ bit<13> fragOffset;
34
+ bit<8> ttl;
35
+ bit<8> protocol;
36
+ bit<16> hdrChecksum;
37
+ ip4Addr_t srcAddr;
38
+ ip4Addr_t dstAddr;
39
+ }
40
+
41
+ struct metadata {
42
+
43
+ /* empty */
44
+ }
45
+
46
+ struct headers {
47
+ ethernet_t ethernet;
48
+ srcRoute_t[MAX_HOPS] srcRoutes;
49
+ ipv4_t ipv4;
50
+ }
51
+
52
+
53
+
54
+ parser MyParser(packet_in packet,
55
+ out headers hdr,
56
+ inout metadata meta,
57
+ inout standard_metadata_t standard_metadata) {
58
+
59
+
60
+ state start {
61
+ transition parse_ethernet;
62
+ }
63
+
64
+ state parse_ethernet {
65
+ packet.extract(hdr.ethernet);
66
+
67
+ transition accept;
68
+ }
69
+
70
+ state parse_srcRouting {
71
+
72
+ transition accept;
73
+ }
74
+
75
+ state parse_ipv4 {
76
+ packet.extract(hdr.ipv4);
77
+ transition accept;
78
+ }
79
+
80
+ }
81
+
82
+
83
+
84
+
85
+ control MyVerifyChecksum(inout headers hdr, inout metadata meta) {
86
+ apply { }
87
+ }
88
+
89
+
90
+
91
+
92
+ control MyIngress(inout headers hdr,
93
+ inout metadata meta,
94
+ inout standard_metadata_t standard_metadata) {
95
+
96
+ action drop() {
97
+ mark_to_drop(standard_metadata);
98
+ }
99
+
100
+ action srcRoute_nhop() {
101
+
102
+ }
103
+
104
+ action srcRoute_finish() {
105
+ hdr.ethernet.etherType = TYPE_IPV4;
106
+ }
107
+
108
+ action update_ttl(){
109
+ hdr.ipv4.ttl = hdr.ipv4.ttl - 1;
110
+ }
111
+
112
+ apply {
113
+ if (hdr.srcRoutes[0].isValid()){
114
+
115
+
116
+ if (hdr.ipv4.isValid()){
117
+ update_ttl();
118
+ }
119
+ }else{
120
+ drop();
121
+ }
122
+ }
123
+ }
124
+
125
+
126
+
127
+ control MyEgress(inout headers hdr,
128
+ inout metadata meta,
129
+ inout standard_metadata_t standard_metadata) {
130
+ apply { }
131
+ }
132
+
133
+
134
+
135
+ control MyComputeChecksum(inout headers hdr, inout metadata meta) {
136
+ apply { }
137
+ }
138
+
139
+
140
+
141
+ control MyDeparser(packet_out packet, in headers hdr) {
142
+ apply {
143
+ packet.emit(hdr.ethernet);
144
+ packet.emit(hdr.srcRoutes);
145
+ packet.emit(hdr.ipv4);
146
+ }
147
+ }
148
+
149
+
150
+
151
+ V1Switch(
152
+ MyParser(),
153
+ MyVerifyChecksum(),
154
+ MyIngress(),
155
+ MyEgress(),
156
+ MyComputeChecksum(),
157
+ MyDeparser()
158
+ ) main;
individual_files/000037__raw-repositories__ana13zs__p4tutorials.p4 ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <core.p4>
2
+ #include <v1model.p4>
3
+
4
+ const bit<16> TYPE_IPV4 = 0x800;
5
+
6
+
7
+
8
+ typedef bit<9> egressSpec_t;
9
+ typedef bit<48> macAddr_t;
10
+ typedef bit<32> ip4Addr_t;
11
+
12
+ header ethernet_t {
13
+ macAddr_t dstAddr;
14
+ macAddr_t srcAddr;
15
+ bit<16> etherType;
16
+ }
17
+
18
+ header ipv4_t {
19
+ bit<4> version;
20
+ bit<4> ihl;
21
+ bit<8> diffserv;
22
+ bit<16> totalLen;
23
+ bit<16> identification;
24
+ bit<3> flags;
25
+ bit<13> fragOffset;
26
+ bit<8> ttl;
27
+ bit<8> protocol;
28
+ bit<16> hdrChecksum;
29
+ ip4Addr_t srcAddr;
30
+ ip4Addr_t dstAddr;
31
+ }
32
+
33
+ struct metadata {
34
+
35
+ /* empty */
36
+ }
37
+
38
+ struct headers {
39
+ ethernet_t ethernet;
40
+ ipv4_t ipv4;
41
+ }
42
+
43
+
44
+
45
+ parser MyParser(packet_in packet,
46
+ out headers hdr,
47
+ inout metadata meta,
48
+ inout standard_metadata_t standard_metadata) {
49
+
50
+ state start {
51
+
52
+ transition accept;
53
+ }
54
+ }
55
+
56
+
57
+
58
+
59
+ control MyVerifyChecksum(inout headers hdr, inout metadata meta) {
60
+ apply { }
61
+ }
62
+
63
+
64
+
65
+
66
+ control MyIngress(inout headers hdr,
67
+ inout metadata meta,
68
+ inout standard_metadata_t standard_metadata) {
69
+ action drop() {
70
+ mark_to_drop(standard_metadata);
71
+ }
72
+
73
+ action ipv4_forward(macAddr_t dstAddr, egressSpec_t port) {
74
+
75
+ }
76
+
77
+ table ipv4_lpm {
78
+ key = {
79
+ hdr.ipv4.dstAddr: lpm;
80
+ }
81
+ actions = {
82
+ ipv4_forward;
83
+ drop;
84
+ NoAction;
85
+ }
86
+ size = 1024;
87
+ default_action = NoAction();
88
+ }
89
+
90
+ apply {
91
+
92
+ ipv4_lpm.apply();
93
+ }
94
+ }
95
+
96
+
97
+
98
+ control MyEgress(inout headers hdr,
99
+ inout metadata meta,
100
+ inout standard_metadata_t standard_metadata) {
101
+ apply { }
102
+ }
103
+
104
+
105
+
106
+ control MyComputeChecksum(inout headers hdr, inout metadata meta) {
107
+ apply {
108
+ update_checksum(
109
+ hdr.ipv4.isValid(),
110
+ { hdr.ipv4.version,
111
+ hdr.ipv4.ihl,
112
+ hdr.ipv4.diffserv,
113
+ hdr.ipv4.totalLen,
114
+ hdr.ipv4.identification,
115
+ hdr.ipv4.flags,
116
+ hdr.ipv4.fragOffset,
117
+ hdr.ipv4.ttl,
118
+ hdr.ipv4.protocol,
119
+ hdr.ipv4.srcAddr,
120
+ hdr.ipv4.dstAddr },
121
+ hdr.ipv4.hdrChecksum,
122
+ HashAlgorithm.csum16);
123
+ }
124
+ }
125
+
126
+
127
+
128
+
129
+ control MyDeparser(packet_out packet, in headers hdr) {
130
+ apply {
131
+
132
+ }
133
+ }
134
+
135
+
136
+
137
+ V1Switch(
138
+ MyParser(),
139
+ MyVerifyChecksum(),
140
+ MyIngress(),
141
+ MyEgress(),
142
+ MyComputeChecksum(),
143
+ MyDeparser()
144
+ ) main;
individual_files/000038__raw-repositories__ana13zs__p4tutorials.p4 ADDED
@@ -0,0 +1,183 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <core.p4>
2
+ #include <v1model.p4>
3
+
4
+
5
+ // NOTE: new type added here
6
+ const bit<16> TYPE_MYTUNNEL = 0x1212;
7
+ const bit<16> TYPE_IPV4 = 0x800;
8
+
9
+
10
+
11
+ typedef bit<9> egressSpec_t;
12
+ typedef bit<48> macAddr_t;
13
+ typedef bit<32> ip4Addr_t;
14
+
15
+ header ethernet_t {
16
+ macAddr_t dstAddr;
17
+ macAddr_t srcAddr;
18
+ bit<16> etherType;
19
+ }
20
+
21
+
22
+ // NOTE: added new header type
23
+ header myTunnel_t {
24
+ bit<16> proto_id;
25
+ bit<16> dst_id;
26
+ }
27
+
28
+ header ipv4_t {
29
+ bit<4> version;
30
+ bit<4> ihl;
31
+ bit<8> diffserv;
32
+ bit<16> totalLen;
33
+ bit<16> identification;
34
+ bit<3> flags;
35
+ bit<13> fragOffset;
36
+ bit<8> ttl;
37
+ bit<8> protocol;
38
+ bit<16> hdrChecksum;
39
+ ip4Addr_t srcAddr;
40
+ ip4Addr_t dstAddr;
41
+ }
42
+
43
+ struct metadata {
44
+
45
+ /* empty */
46
+ }
47
+
48
+
49
+ // NOTE: Added new header type to headers struct
50
+ struct headers {
51
+ ethernet_t ethernet;
52
+ myTunnel_t myTunnel;
53
+ ipv4_t ipv4;
54
+ }
55
+
56
+
57
+
58
+
59
+ parser MyParser(packet_in packet,
60
+ out headers hdr,
61
+ inout metadata meta,
62
+ inout standard_metadata_t standard_metadata) {
63
+
64
+ state start {
65
+ transition parse_ethernet;
66
+ }
67
+
68
+ state parse_ethernet {
69
+ packet.extract(hdr.ethernet);
70
+ transition select(hdr.ethernet.etherType) {
71
+ TYPE_IPV4 : parse_ipv4;
72
+ default : accept;
73
+ }
74
+ }
75
+
76
+ state parse_ipv4 {
77
+ packet.extract(hdr.ipv4);
78
+ transition accept;
79
+ }
80
+
81
+
82
+ }
83
+
84
+
85
+
86
+ control MyVerifyChecksum(inout headers hdr, inout metadata meta) {
87
+ apply { }
88
+ }
89
+
90
+
91
+
92
+
93
+ control MyIngress(inout headers hdr,
94
+ inout metadata meta,
95
+ inout standard_metadata_t standard_metadata) {
96
+ action drop() {
97
+ mark_to_drop(standard_metadata);
98
+ }
99
+
100
+ action ipv4_forward(macAddr_t dstAddr, egressSpec_t port) {
101
+ standard_metadata.egress_spec = port;
102
+ hdr.ethernet.srcAddr = hdr.ethernet.dstAddr;
103
+ hdr.ethernet.dstAddr = dstAddr;
104
+ hdr.ipv4.ttl = hdr.ipv4.ttl - 1;
105
+ }
106
+
107
+ table ipv4_lpm {
108
+ key = {
109
+ hdr.ipv4.dstAddr: lpm;
110
+ }
111
+ actions = {
112
+ ipv4_forward;
113
+ drop;
114
+ NoAction;
115
+ }
116
+ size = 1024;
117
+ default_action = drop();
118
+ }
119
+
120
+
121
+
122
+
123
+
124
+
125
+
126
+ apply {
127
+
128
+ if (hdr.ipv4.isValid()) {
129
+ ipv4_lpm.apply();
130
+ }
131
+ }
132
+ }
133
+
134
+
135
+
136
+ control MyEgress(inout headers hdr,
137
+ inout metadata meta,
138
+ inout standard_metadata_t standard_metadata) {
139
+ apply { }
140
+ }
141
+
142
+
143
+
144
+ control MyComputeChecksum(inout headers hdr, inout metadata meta) {
145
+ apply {
146
+ update_checksum(
147
+ hdr.ipv4.isValid(),
148
+ { hdr.ipv4.version,
149
+ hdr.ipv4.ihl,
150
+ hdr.ipv4.diffserv,
151
+ hdr.ipv4.totalLen,
152
+ hdr.ipv4.identification,
153
+ hdr.ipv4.flags,
154
+ hdr.ipv4.fragOffset,
155
+ hdr.ipv4.ttl,
156
+ hdr.ipv4.protocol,
157
+ hdr.ipv4.srcAddr,
158
+ hdr.ipv4.dstAddr },
159
+ hdr.ipv4.hdrChecksum,
160
+ HashAlgorithm.csum16);
161
+ }
162
+ }
163
+
164
+
165
+
166
+ control MyDeparser(packet_out packet, in headers hdr) {
167
+ apply {
168
+ packet.emit(hdr.ethernet);
169
+
170
+ packet.emit(hdr.ipv4);
171
+ }
172
+ }
173
+
174
+
175
+
176
+ V1Switch(
177
+ MyParser(),
178
+ MyVerifyChecksum(),
179
+ MyIngress(),
180
+ MyEgress(),
181
+ MyComputeChecksum(),
182
+ MyDeparser()
183
+ ) main;
individual_files/000039__raw-repositories__ana13zs__p4tutorials.p4 ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <core.p4>
2
+ #include <v1model.p4>
3
+
4
+ const bit<8> TCP_PROTOCOL = 0x06;
5
+ const bit<16> TYPE_IPV4 = 0x800;
6
+ const bit<19> ECN_THRESHOLD = 10;
7
+
8
+
9
+
10
+ typedef bit<9> egressSpec_t;
11
+ typedef bit<48> macAddr_t;
12
+ typedef bit<32> ip4Addr_t;
13
+
14
+ header ethernet_t {
15
+ macAddr_t dstAddr;
16
+ macAddr_t srcAddr;
17
+ bit<16> etherType;
18
+ }
19
+
20
+
21
+ header ipv4_t {
22
+ bit<4> version;
23
+ bit<4> ihl;
24
+ bit<8> tos;
25
+ bit<16> totalLen;
26
+ bit<16> identification;
27
+ bit<3> flags;
28
+ bit<13> fragOffset;
29
+ bit<8> ttl;
30
+ bit<8> protocol;
31
+ bit<16> hdrChecksum;
32
+ ip4Addr_t srcAddr;
33
+ ip4Addr_t dstAddr;
34
+ }
35
+
36
+ struct metadata {
37
+ }
38
+
39
+ struct headers {
40
+ ethernet_t ethernet;
41
+ ipv4_t ipv4;
42
+ }
43
+
44
+
45
+
46
+ parser MyParser(packet_in packet,
47
+ out headers hdr,
48
+ inout metadata meta,
49
+ inout standard_metadata_t standard_metadata) {
50
+
51
+ state start {
52
+ transition parse_ethernet;
53
+ }
54
+
55
+ state parse_ethernet {
56
+ packet.extract(hdr.ethernet);
57
+ transition select(hdr.ethernet.etherType) {
58
+ TYPE_IPV4: parse_ipv4;
59
+ default: accept;
60
+ }
61
+ }
62
+
63
+ state parse_ipv4 {
64
+ packet.extract(hdr.ipv4);
65
+ transition accept;
66
+ }
67
+ }
68
+
69
+
70
+
71
+
72
+ control MyVerifyChecksum(inout headers hdr, inout metadata meta) {
73
+ apply { }
74
+ }
75
+
76
+
77
+
78
+
79
+ control MyIngress(inout headers hdr,
80
+ inout metadata meta,
81
+ inout standard_metadata_t standard_metadata) {
82
+ action drop() {
83
+ mark_to_drop(standard_metadata);
84
+ }
85
+
86
+ action ipv4_forward(macAddr_t dstAddr, egressSpec_t port) {
87
+ standard_metadata.egress_spec = port;
88
+ hdr.ethernet.srcAddr = hdr.ethernet.dstAddr;
89
+ hdr.ethernet.dstAddr = dstAddr;
90
+ hdr.ipv4.ttl = hdr.ipv4.ttl - 1;
91
+ }
92
+
93
+ table ipv4_lpm {
94
+ key = {
95
+ hdr.ipv4.dstAddr: lpm;
96
+ }
97
+ actions = {
98
+ ipv4_forward;
99
+ drop;
100
+ }
101
+ size = 1024;
102
+ default_action = drop;
103
+ }
104
+
105
+ apply {
106
+ if (hdr.ipv4.isValid()) {
107
+ ipv4_lpm.apply();
108
+ }
109
+ }
110
+ }
111
+
112
+
113
+
114
+ control MyEgress(inout headers hdr,
115
+ inout metadata meta,
116
+ inout standard_metadata_t standard_metadata) {
117
+ apply {
118
+
119
+ }
120
+ }
121
+
122
+
123
+
124
+ control MyComputeChecksum(inout headers hdr, inout metadata meta) {
125
+ apply {
126
+
127
+ update_checksum(
128
+ hdr.ipv4.isValid(),
129
+ { hdr.ipv4.version,
130
+ hdr.ipv4.ihl,
131
+ hdr.ipv4.tos,
132
+ hdr.ipv4.totalLen,
133
+ hdr.ipv4.identification,
134
+ hdr.ipv4.flags,
135
+ hdr.ipv4.fragOffset,
136
+ hdr.ipv4.ttl,
137
+ hdr.ipv4.protocol,
138
+ hdr.ipv4.srcAddr,
139
+ hdr.ipv4.dstAddr },
140
+ hdr.ipv4.hdrChecksum,
141
+ HashAlgorithm.csum16);
142
+ }
143
+ }
144
+
145
+
146
+
147
+ control MyDeparser(packet_out packet, in headers hdr) {
148
+ apply {
149
+ packet.emit(hdr.ethernet);
150
+ packet.emit(hdr.ipv4);
151
+ }
152
+ }
153
+
154
+
155
+
156
+ V1Switch(
157
+ MyParser(),
158
+ MyVerifyChecksum(),
159
+ MyIngress(),
160
+ MyEgress(),
161
+ MyComputeChecksum(),
162
+ MyDeparser()
163
+ ) main;
individual_files/000040__raw-repositories__ana13zs__p4tutorials.p4 ADDED
@@ -0,0 +1,232 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <core.p4>
2
+ #include <v1model.p4>
3
+
4
+ const bit<8> UDP_PROTOCOL = 0x11;
5
+ const bit<16> TYPE_IPV4 = 0x800;
6
+ const bit<5> IPV4_OPTION_MRI = 31;
7
+
8
+ #define MAX_HOPS 9
9
+
10
+
11
+
12
+ typedef bit<9> egressSpec_t;
13
+ typedef bit<48> macAddr_t;
14
+ typedef bit<32> ip4Addr_t;
15
+ typedef bit<32> switchID_t;
16
+ typedef bit<32> qdepth_t;
17
+
18
+ header ethernet_t {
19
+ macAddr_t dstAddr;
20
+ macAddr_t srcAddr;
21
+ bit<16> etherType;
22
+ }
23
+
24
+ header ipv4_t {
25
+ bit<4> version;
26
+ bit<4> ihl;
27
+ bit<8> diffserv;
28
+ bit<16> totalLen;
29
+ bit<16> identification;
30
+ bit<3> flags;
31
+ bit<13> fragOffset;
32
+ bit<8> ttl;
33
+ bit<8> protocol;
34
+ bit<16> hdrChecksum;
35
+ ip4Addr_t srcAddr;
36
+ ip4Addr_t dstAddr;
37
+ }
38
+
39
+ header ipv4_option_t {
40
+ bit<1> copyFlag;
41
+ bit<2> optClass;
42
+ bit<5> option;
43
+ bit<8> optionLength;
44
+ }
45
+
46
+ header mri_t {
47
+ bit<16> count;
48
+ }
49
+
50
+ header switch_t {
51
+ switchID_t swid;
52
+ qdepth_t qdepth;
53
+ }
54
+
55
+ struct ingress_metadata_t {
56
+ bit<16> count;
57
+ }
58
+
59
+ struct parser_metadata_t {
60
+ bit<16> remaining;
61
+ }
62
+
63
+ struct metadata {
64
+ ingress_metadata_t ingress_metadata;
65
+ parser_metadata_t parser_metadata;
66
+ }
67
+
68
+ struct headers {
69
+ ethernet_t ethernet;
70
+ ipv4_t ipv4;
71
+ ipv4_option_t ipv4_option;
72
+ mri_t mri;
73
+ switch_t[MAX_HOPS] swtraces;
74
+ }
75
+
76
+ error { IPHeaderTooShort }
77
+
78
+
79
+
80
+ parser MyParser(packet_in packet,
81
+ out headers hdr,
82
+ inout metadata meta,
83
+ inout standard_metadata_t standard_metadata) {
84
+
85
+ state start {
86
+ transition parse_ethernet;
87
+ }
88
+
89
+ state parse_ethernet {
90
+ packet.extract(hdr.ethernet);
91
+ transition select(hdr.ethernet.etherType) {
92
+ TYPE_IPV4: parse_ipv4;
93
+ default: accept;
94
+ }
95
+ }
96
+
97
+ state parse_ipv4 {
98
+ packet.extract(hdr.ipv4);
99
+ verify(hdr.ipv4.ihl >= 5, error.IPHeaderTooShort);
100
+ transition select(hdr.ipv4.ihl) {
101
+ 5 : accept;
102
+ default : parse_ipv4_option;
103
+ }
104
+ }
105
+
106
+ state parse_ipv4_option {
107
+
108
+ transition accept;
109
+ }
110
+
111
+ state parse_mri {
112
+
113
+ transition accept;
114
+ }
115
+
116
+ state parse_swtrace {
117
+
118
+ transition accept;
119
+ }
120
+ }
121
+
122
+
123
+
124
+
125
+ control MyVerifyChecksum(inout headers hdr, inout metadata meta) {
126
+ apply { }
127
+ }
128
+
129
+
130
+
131
+
132
+ control MyIngress(inout headers hdr,
133
+ inout metadata meta,
134
+ inout standard_metadata_t standard_metadata) {
135
+ action drop() {
136
+ mark_to_drop(standard_metadata);
137
+ }
138
+
139
+ action ipv4_forward(macAddr_t dstAddr, egressSpec_t port) {
140
+ standard_metadata.egress_spec = port;
141
+ hdr.ethernet.srcAddr = hdr.ethernet.dstAddr;
142
+ hdr.ethernet.dstAddr = dstAddr;
143
+ hdr.ipv4.ttl = hdr.ipv4.ttl - 1;
144
+ }
145
+
146
+ table ipv4_lpm {
147
+ key = {
148
+ hdr.ipv4.dstAddr: lpm;
149
+ }
150
+ actions = {
151
+ ipv4_forward;
152
+ drop;
153
+ NoAction;
154
+ }
155
+ size = 1024;
156
+ default_action = NoAction();
157
+ }
158
+
159
+ apply {
160
+ if (hdr.ipv4.isValid()) {
161
+ ipv4_lpm.apply();
162
+ }
163
+ }
164
+ }
165
+
166
+
167
+
168
+ control MyEgress(inout headers hdr,
169
+ inout metadata meta,
170
+ inout standard_metadata_t standard_metadata) {
171
+ action add_swtrace(switchID_t swid) {
172
+
173
+ }
174
+
175
+ table swtrace {
176
+ actions = {
177
+ add_swtrace;
178
+ NoAction;
179
+ }
180
+
181
+ default_action = NoAction();
182
+ }
183
+
184
+ apply {
185
+
186
+ swtrace.apply();
187
+ }
188
+ }
189
+
190
+
191
+
192
+ control MyComputeChecksum(inout headers hdr, inout metadata meta) {
193
+ apply {
194
+ update_checksum(
195
+ hdr.ipv4.isValid(),
196
+ { hdr.ipv4.version,
197
+ hdr.ipv4.ihl,
198
+ hdr.ipv4.diffserv,
199
+ hdr.ipv4.totalLen,
200
+ hdr.ipv4.identification,
201
+ hdr.ipv4.flags,
202
+ hdr.ipv4.fragOffset,
203
+ hdr.ipv4.ttl,
204
+ hdr.ipv4.protocol,
205
+ hdr.ipv4.srcAddr,
206
+ hdr.ipv4.dstAddr },
207
+ hdr.ipv4.hdrChecksum,
208
+ HashAlgorithm.csum16);
209
+ }
210
+ }
211
+
212
+
213
+
214
+ control MyDeparser(packet_out packet, in headers hdr) {
215
+ apply {
216
+ packet.emit(hdr.ethernet);
217
+ packet.emit(hdr.ipv4);
218
+
219
+
220
+ }
221
+ }
222
+
223
+
224
+
225
+ V1Switch(
226
+ MyParser(),
227
+ MyVerifyChecksum(),
228
+ MyIngress(),
229
+ MyEgress(),
230
+ MyComputeChecksum(),
231
+ MyDeparser()
232
+ ) main;
individual_files/000041__raw-repositories__benedettapacilli__programmable-networking-lab-exercises.p4 ADDED
@@ -0,0 +1,279 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <core.p4>
2
+ #include <v1model.p4>
3
+
4
+
5
+
6
+ const bit<16> TYPE_IPV4 = 0x800;
7
+ typedef bit<10> PortId_t;
8
+ const PortId_t NUM_PORTS = 512;
9
+ #define PACKET_COUNT_WIDTH 32
10
+ #define TRESHOLD 200
11
+ #define BYTE_COUNT_WIDTH 48
12
+
13
+ #define PACKET_BYTE_COUNT_WIDTH 80
14
+
15
+ #define PACKET_COUNT_RANGE (PACKET_BYTE_COUNT_WIDTH-1):BYTE_COUNT_WIDTH
16
+ #define BYTE_COUNT_RANGE (BYTE_COUNT_WIDTH-1):0
17
+
18
+ #define FLOW_TABLE_SIZE_EACH 1024
19
+ #define HASH_BASE 10w0
20
+ #define HASH_MAX 10w1023
21
+ typedef bit<PACKET_BYTE_COUNT_WIDTH> PacketByteCountState_t;
22
+
23
+
24
+
25
+
26
+ typedef bit<9> egressSpec_t;
27
+ typedef bit<48> macAddr_t;
28
+ typedef bit<32> ip4Addr_t;
29
+
30
+ struct ingress_metadata_t {
31
+
32
+ bit<64> my_flowID;
33
+ bit<64> my_estimated_count;
34
+ bit<1> already_matched;
35
+ bit<32> nhop_ipv4;
36
+ bit<64> carry_min;
37
+ bit<64> carry_min_plus_one;
38
+ bit<8> min_stage;
39
+ bit<1> do_recirculate;
40
+ bit<9> orig_egr_port;
41
+
42
+ bit<32> hashed_flow;
43
+ bit<32> hashed_flow_opposite;
44
+ bit<32> hashed_address_s3;
45
+
46
+ bit<64> random_bits;
47
+ bit<12> random_bits_short;
48
+ }
49
+
50
+ header ethernet_t {
51
+ macAddr_t dstAddr;
52
+ macAddr_t srcAddr;
53
+ bit<16> etherType;
54
+ }
55
+
56
+ header ipv4_t {
57
+ bit<4> version;
58
+ bit<4> ihl;
59
+ bit<8> diffserv;
60
+ bit<16> totalLen;
61
+ bit<16> identification;
62
+ bit<3> flags;
63
+ bit<13> fragOffset;
64
+ bit<8> ttl;
65
+ bit<8> protocol;
66
+ bit<16> hdrChecksum;
67
+ ip4Addr_t srcAddr;
68
+ ip4Addr_t dstAddr;
69
+ ip4Addr_t realsrcAddr;
70
+ ip4Addr_t realdstAddr;
71
+ }
72
+
73
+ struct metadata {
74
+ @name("ingress_metadata")
75
+ ingress_metadata_t ingress_metadata;
76
+ }
77
+
78
+ struct headers {
79
+ ethernet_t ethernet;
80
+ ipv4_t ipv4;
81
+ }
82
+
83
+
84
+
85
+ parser MyParser(packet_in packet,
86
+ out headers hdr,
87
+ inout metadata meta,
88
+ inout standard_metadata_t standard_metadata) {
89
+
90
+ state start {
91
+ transition parse_ethernet;
92
+ }
93
+
94
+ state parse_ethernet {
95
+ packet.extract(hdr.ethernet);
96
+ transition select(hdr.ethernet.etherType) {
97
+ TYPE_IPV4: parse_ipv4;
98
+ default: accept;
99
+ }
100
+ }
101
+
102
+ state parse_ipv4 {
103
+ packet.extract(hdr.ipv4);
104
+ transition accept;
105
+ }
106
+
107
+ }
108
+
109
+
110
+
111
+ control MyVerifyChecksum(inout headers hdr, inout metadata meta) {
112
+ apply { }
113
+ }
114
+
115
+
116
+
117
+
118
+ control MyIngress(inout headers hdr,
119
+ inout metadata meta,
120
+ inout standard_metadata_t standard_metadata) {
121
+ action drop() {
122
+ mark_to_drop(standard_metadata);
123
+ }
124
+ direct_counter(CounterType.packets) c;
125
+ register<bit<48>>(1024) last_seen;
126
+
127
+ register<bit<64>>(1024) flows;
128
+
129
+ action get_inter_packet_gap(out bit<48> interval,bit<32> flow_id)
130
+
131
+ {
132
+ bit<48> last_pkt_cnt;
133
+ bit<32> index;
134
+
135
+ /* Get the time the previous packet was seen */
136
+ last_seen.read(last_pkt_cnt,flow_id);
137
+ interval = last_pkt_cnt + 1;
138
+
139
+ /* Update the register with the new timestamp */
140
+ last_seen.write((bit<32>)flow_id,
141
+ interval);
142
+ }
143
+ action compute_flow_id () {
144
+
145
+ // combines the source and destination IP addresses to create a unique flow ID for each flow
146
+ meta.ingress_metadata.my_flowID[31:0]=hdr.ipv4.srcAddr;
147
+ meta.ingress_metadata.my_flowID[63:32]=hdr.ipv4.dstAddr;
148
+ }
149
+ action compute_reg_index () {
150
+
151
+ hash(meta.ingress_metadata.hashed_flow, HashAlgorithm.crc16, HASH_BASE,
152
+ {hdr.ipv4.srcAddr, 7w11, hdr.ipv4.dstAddr}, HASH_MAX);
153
+ hash(meta.ingress_metadata.hashed_flow_opposite, HashAlgorithm.crc16, HASH_BASE,
154
+ {hdr.ipv4.dstAddr, 7w11, hdr.ipv4.srcAddr}, HASH_MAX);
155
+ }
156
+
157
+ action ipv4_forward(macAddr_t dstAddr, egressSpec_t port) {
158
+ standard_metadata.egress_spec = port;
159
+ hdr.ethernet.srcAddr = hdr.ethernet.dstAddr;
160
+ hdr.ethernet.dstAddr = dstAddr;
161
+ hdr.ipv4.ttl = hdr.ipv4.ttl - 1;
162
+ }
163
+ action update_origin(macAddr_t dstAddr, egressSpec_t port) {
164
+ standard_metadata.egress_spec = port;
165
+ hdr.ethernet.srcAddr = hdr.ethernet.dstAddr;
166
+ hdr.ethernet.dstAddr = dstAddr;
167
+ hdr.ipv4.ttl = hdr.ipv4.ttl - 1;
168
+ }
169
+
170
+ table ipv4_lpm {
171
+ key = {
172
+ hdr.ipv4.dstAddr: lpm;
173
+ }
174
+ counters = c;
175
+ actions = {
176
+ ipv4_forward;
177
+ drop;
178
+ NoAction;
179
+ }
180
+ size = 1024;
181
+ default_action = NoAction();
182
+ }
183
+
184
+ apply {
185
+ if (hdr.ipv4.isValid()) {
186
+
187
+ // if the packet is an IPv4 packet
188
+ ipv4_lpm.apply();
189
+
190
+ // apply the LPM table for routing
191
+ bit<48> tmp;
192
+ bit<32> flow;
193
+ bit<32> flow_opp;
194
+ compute_reg_index();
195
+
196
+ // compute the register index for the flow
197
+ bit<48> last_pkt_cnt;
198
+ bit<48> last_pkt_cnt_opp;
199
+
200
+ /* Get the time the previous packet was seen */
201
+ flow = meta.ingress_metadata.hashed_flow;
202
+
203
+ // get the flow ID
204
+ flow_opp = meta.ingress_metadata.hashed_flow_opposite;
205
+
206
+ // get the opposite flow ID
207
+ last_seen.read(last_pkt_cnt,flow);
208
+
209
+ // read the last packet count of the flow
210
+ last_seen.read(last_pkt_cnt_opp,flow_opp);
211
+
212
+ // read the last packet count of the opposite flow
213
+ tmp = last_pkt_cnt - last_pkt_cnt_opp + 1;
214
+
215
+ // calculate the inter-packet gap
216
+ if(tmp < TRESHOLD) {
217
+
218
+ // if the inter-packet gap is less than the threshold
219
+
220
+ get_inter_packet_gap(last_pkt_cnt,flow);
221
+
222
+ // it updates the inter-packet gap
223
+ }
224
+ else{
225
+ drop();
226
+ }
227
+ }
228
+ }
229
+ }
230
+
231
+
232
+
233
+ control MyEgress(inout headers hdr,
234
+ inout metadata meta,
235
+ inout standard_metadata_t standard_metadata) {
236
+ apply { }
237
+ }
238
+
239
+
240
+
241
+ control MyComputeChecksum(inout headers hdr, inout metadata meta) {
242
+ apply {
243
+ update_checksum(
244
+ hdr.ipv4.isValid(),
245
+ { hdr.ipv4.version,
246
+ hdr.ipv4.ihl,
247
+ hdr.ipv4.diffserv,
248
+ hdr.ipv4.totalLen,
249
+ hdr.ipv4.identification,
250
+ hdr.ipv4.flags,
251
+ hdr.ipv4.fragOffset,
252
+ hdr.ipv4.ttl,
253
+ hdr.ipv4.protocol,
254
+ hdr.ipv4.srcAddr,
255
+ hdr.ipv4.dstAddr },
256
+ hdr.ipv4.hdrChecksum,
257
+ HashAlgorithm.csum16);
258
+ }
259
+ }
260
+
261
+
262
+
263
+ control MyDeparser(packet_out packet, in headers hdr) {
264
+ apply {
265
+ packet.emit(hdr.ethernet);
266
+ packet.emit(hdr.ipv4);
267
+ }
268
+ }
269
+
270
+
271
+
272
+ V1Switch(
273
+ MyParser(),
274
+ MyVerifyChecksum(),
275
+ MyIngress(),
276
+ MyEgress(),
277
+ MyComputeChecksum(),
278
+ MyDeparser()
279
+ ) main;
individual_files/000042__raw-repositories__benedettapacilli__programmable-networking-lab-exercises.p4 ADDED
@@ -0,0 +1,292 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <core.p4>
2
+ #include <v1model.p4>
3
+
4
+
5
+
6
+ const bit<16> TYPE_IPV4 = 0x800;
7
+ typedef bit<10> PortId_t;
8
+ const PortId_t NUM_PORTS = 512;
9
+ #define PACKET_COUNT_WIDTH 32
10
+ #define TRESHOLD 200
11
+
12
+ //microseconds
13
+ #define WINDOW 15000000
14
+
15
+ // 15 seconds, time window for resetting asymmetric flow detection
16
+ #define BYTE_COUNT_WIDTH 48
17
+
18
+ #define PACKET_BYTE_COUNT_WIDTH 80
19
+
20
+ #define PACKET_COUNT_RANGE (PACKET_BYTE_COUNT_WIDTH-1):BYTE_COUNT_WIDTH
21
+ #define BYTE_COUNT_RANGE (BYTE_COUNT_WIDTH-1):0
22
+
23
+ #define FLOW_TABLE_SIZE_EACH 1024
24
+ #define HASH_BASE 10w0
25
+ #define HASH_MAX 10w1023
26
+ typedef bit<PACKET_BYTE_COUNT_WIDTH> PacketByteCountState_t;
27
+
28
+
29
+
30
+
31
+ typedef bit<9> egressSpec_t;
32
+ typedef bit<48> macAddr_t;
33
+ typedef bit<32> ip4Addr_t;
34
+
35
+ struct ingress_metadata_t {
36
+
37
+ bit<64> my_flowID;
38
+ bit<64> my_estimated_count;
39
+ bit<1> already_matched;
40
+ bit<32> nhop_ipv4;
41
+ bit<64> carry_min;
42
+ bit<64> carry_min_plus_one;
43
+ bit<8> min_stage;
44
+ bit<1> do_recirculate;
45
+ bit<9> orig_egr_port;
46
+
47
+
48
+ bit<32> hashed_flow;
49
+ bit<32> hashed_flow_opposite;
50
+ bit<32> hashed_address_s3;
51
+
52
+ bit<64> random_bits;
53
+ bit<12> random_bits_short;
54
+ }
55
+
56
+ header ethernet_t {
57
+ macAddr_t dstAddr;
58
+ macAddr_t srcAddr;
59
+ bit<16> etherType;
60
+ }
61
+
62
+ header ipv4_t {
63
+ bit<4> version;
64
+ bit<4> ihl;
65
+ bit<8> diffserv;
66
+ bit<16> totalLen;
67
+ bit<16> identification;
68
+ bit<3> flags;
69
+ bit<13> fragOffset;
70
+ bit<8> ttl;
71
+ bit<8> protocol;
72
+ bit<16> hdrChecksum;
73
+ ip4Addr_t srcAddr;
74
+ ip4Addr_t dstAddr;
75
+ ip4Addr_t realsrcAddr;
76
+ ip4Addr_t realdstAddr;
77
+ }
78
+
79
+ struct metadata {
80
+ @name("ingress_metadata")
81
+ ingress_metadata_t ingress_metadata;
82
+ }
83
+
84
+ struct headers {
85
+ ethernet_t ethernet;
86
+ ipv4_t ipv4;
87
+ }
88
+
89
+
90
+
91
+ parser MyParser(packet_in packet,
92
+ out headers hdr,
93
+ inout metadata meta,
94
+ inout standard_metadata_t standard_metadata) {
95
+
96
+ state start {
97
+ transition parse_ethernet;
98
+ }
99
+
100
+ state parse_ethernet {
101
+ packet.extract(hdr.ethernet);
102
+ transition select(hdr.ethernet.etherType) {
103
+ TYPE_IPV4: parse_ipv4;
104
+ default: accept;
105
+ }
106
+ }
107
+
108
+ state parse_ipv4 {
109
+ packet.extract(hdr.ipv4);
110
+ transition accept;
111
+ }
112
+
113
+ }
114
+
115
+
116
+
117
+ control MyVerifyChecksum(inout headers hdr, inout metadata meta) {
118
+ apply { }
119
+ }
120
+
121
+
122
+
123
+
124
+ control MyIngress(inout headers hdr,
125
+ inout metadata meta,
126
+ inout standard_metadata_t standard_metadata) {
127
+ action drop() {
128
+ mark_to_drop(standard_metadata);
129
+ }
130
+ direct_counter(CounterType.packets) c;
131
+ register<bit<48>>(1024) last_seen;
132
+ register<bit<48>>(1024) window;
133
+
134
+ action get_inter_packet_gap(out bit<48> interval,bit<32> flow_id)
135
+
136
+ {
137
+ bit<48> last_pkt_cnt;
138
+ bit<32> index;
139
+
140
+ /* Get the time the previous packet was seen */
141
+ last_seen.read(last_pkt_cnt,flow_id);
142
+ interval = last_pkt_cnt + 1;
143
+
144
+ /* Update the register with the new timestamp */
145
+ last_seen.write((bit<32>)flow_id,
146
+ interval);
147
+ }
148
+
149
+ action restore_flow(bit<32> flow,bit<32> flow_opp)
150
+
151
+ // resets the flow and the opposite registers
152
+ {
153
+
154
+ last_seen.write((bit<32>)flow,0);
155
+ last_seen.write((bit<32>)flow_opp,0);
156
+ }
157
+
158
+ action compute_reg_index () {
159
+
160
+ hash(meta.ingress_metadata.hashed_flow, HashAlgorithm.crc16, HASH_BASE,
161
+ {hdr.ipv4.srcAddr, 7w11, hdr.ipv4.dstAddr}, HASH_MAX);
162
+ hash(meta.ingress_metadata.hashed_flow_opposite, HashAlgorithm.crc16, HASH_BASE,
163
+ {hdr.ipv4.dstAddr, 7w11, hdr.ipv4.srcAddr}, HASH_MAX);
164
+ }
165
+
166
+ action ipv4_forward(macAddr_t dstAddr, egressSpec_t port) {
167
+ standard_metadata.egress_spec = port;
168
+ hdr.ethernet.srcAddr = hdr.ethernet.dstAddr;
169
+ hdr.ethernet.dstAddr = dstAddr;
170
+ hdr.ipv4.ttl = hdr.ipv4.ttl - 1;
171
+ }
172
+
173
+ table ipv4_lpm {
174
+ key = {
175
+ hdr.ipv4.dstAddr: lpm;
176
+ }
177
+ counters = c;
178
+ actions = {
179
+ ipv4_forward;
180
+ drop;
181
+ NoAction;
182
+ }
183
+ size = 1024;
184
+ default_action = NoAction();
185
+ }
186
+
187
+ apply {
188
+ if (hdr.ipv4.isValid()) {
189
+ ipv4_lpm.apply();
190
+ bit<48> tmp;
191
+ bit<48> time;
192
+ bit<32> flow;
193
+ bit<32> flow_opp;
194
+ compute_reg_index();
195
+ bit<48> last_pkt_cnt;
196
+ bit<48> last_pkt_cnt_opp;
197
+
198
+ bit<48> last_time;
199
+ bit<48> intertime;
200
+
201
+ /* Get the time the previous packet was seen */
202
+ flow = meta.ingress_metadata.hashed_flow;
203
+ flow_opp = meta.ingress_metadata.hashed_flow_opposite;
204
+
205
+ window.read(last_time,flow);
206
+
207
+
208
+ // first time initialize
209
+ if(last_time == (bit<48>)0){
210
+ window.write((bit<32>)flow,standard_metadata.ingress_global_timestamp);
211
+
212
+ // write the first packet
213
+ }
214
+
215
+ intertime = standard_metadata.ingress_global_timestamp - last_time;
216
+
217
+ // intertime is the time difference between the last packet and the current packet
218
+ window.write((bit<32>)flow,standard_metadata.ingress_global_timestamp);
219
+
220
+ // check window
221
+ if(intertime > WINDOW){
222
+
223
+ // if the time difference is greater than the window, reset the flow
224
+ restore_flow(flow,flow_opp);
225
+ }
226
+ else{
227
+
228
+ }
229
+
230
+ last_seen.read(last_pkt_cnt,flow);
231
+ last_seen.read(last_pkt_cnt_opp,flow_opp);
232
+ tmp = last_pkt_cnt - last_pkt_cnt_opp + 1;
233
+
234
+ if(tmp < TRESHOLD) {
235
+ get_inter_packet_gap(last_pkt_cnt,flow);
236
+ }
237
+ else{
238
+ drop();
239
+ }
240
+ }
241
+ }
242
+ }
243
+
244
+
245
+
246
+ control MyEgress(inout headers hdr,
247
+ inout metadata meta,
248
+ inout standard_metadata_t standard_metadata) {
249
+ apply { }
250
+ }
251
+
252
+
253
+
254
+ control MyComputeChecksum(inout headers hdr, inout metadata meta) {
255
+ apply {
256
+ update_checksum(
257
+ hdr.ipv4.isValid(),
258
+ { hdr.ipv4.version,
259
+ hdr.ipv4.ihl,
260
+ hdr.ipv4.diffserv,
261
+ hdr.ipv4.totalLen,
262
+ hdr.ipv4.identification,
263
+ hdr.ipv4.flags,
264
+ hdr.ipv4.fragOffset,
265
+ hdr.ipv4.ttl,
266
+ hdr.ipv4.protocol,
267
+ hdr.ipv4.srcAddr,
268
+ hdr.ipv4.dstAddr },
269
+ hdr.ipv4.hdrChecksum,
270
+ HashAlgorithm.csum16);
271
+ }
272
+ }
273
+
274
+
275
+
276
+ control MyDeparser(packet_out packet, in headers hdr) {
277
+ apply {
278
+ packet.emit(hdr.ethernet);
279
+ packet.emit(hdr.ipv4);
280
+ }
281
+ }
282
+
283
+
284
+
285
+ V1Switch(
286
+ MyParser(),
287
+ MyVerifyChecksum(),
288
+ MyIngress(),
289
+ MyEgress(),
290
+ MyComputeChecksum(),
291
+ MyDeparser()
292
+ ) main;
individual_files/000043__raw-repositories__ByungUkMin__p4-encryption.p4 ADDED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <core.p4>
2
+ #include <v1model.p4>
3
+
4
+ #define MCAST_ID 1
5
+ #define CPU_PORT 255
6
+
7
+
8
+ typedef bit<48> macAddr_t;
9
+
10
+
11
+ /**/
12
+ /* Headers */
13
+ /**/
14
+
15
+ @controller_header("packet_in")
16
+ header packet_in_header_t {
17
+ bit<9> ingress_port;
18
+ bit<7> _pad;
19
+ }
20
+
21
+ header ethernet_t {
22
+ macAddr_t dstAddr;
23
+ macAddr_t srcAddr;
24
+ bit<16> etherType;
25
+ }
26
+
27
+ struct metadata {
28
+
29
+ /* empty */
30
+ }
31
+
32
+ struct headers {
33
+ ethernet_t ethernet;
34
+ packet_in_header_t packet_in;
35
+ }
36
+
37
+
38
+ /**/
39
+ /* Parser */
40
+ /**/
41
+
42
+ parser MyParser(packet_in packet,
43
+ out headers hdr,
44
+ inout metadata meta,
45
+ inout standard_metadata_t standard_metadata) {
46
+
47
+ state start {
48
+ transition parse_ethernet;
49
+ }
50
+
51
+ state parse_ethernet {
52
+ packet.extract(hdr.ethernet);
53
+ transition accept;
54
+ }
55
+ }
56
+
57
+
58
+ /**/
59
+ /* Checksum Verification */
60
+ /**/
61
+
62
+ control MyVerifyChecksum(inout headers hdr, inout metadata meta) {
63
+ apply { }
64
+ }
65
+
66
+
67
+ /**/
68
+ /* Ingress Processing */
69
+ /**/
70
+
71
+ control MyIngress(inout headers hdr,
72
+ inout metadata meta,
73
+ inout standard_metadata_t standard_metadata) {
74
+
75
+ action drop() {
76
+ mark_to_drop(standard_metadata);
77
+ }
78
+
79
+ action flood() {
80
+ standard_metadata.mcast_grp = MCAST_ID;
81
+ }
82
+
83
+ table bridge_table {
84
+ key = {
85
+ hdr.ethernet.dstAddr: exact;
86
+ standard_metadata.ingress_port: exact;
87
+ }
88
+ actions = {
89
+ drop;
90
+ flood;
91
+ }
92
+ size = 1024;
93
+ default_action = flood;
94
+ }
95
+
96
+ apply {
97
+ bridge_table.apply();
98
+ }
99
+ }
100
+
101
+
102
+ /**/
103
+ /* Egress Processing */
104
+ /**/
105
+
106
+ control MyEgress(inout headers hdr,
107
+ inout metadata meta,
108
+ inout standard_metadata_t standard_metadata) {
109
+ action drop() {
110
+ mark_to_drop(standard_metadata);
111
+ }
112
+
113
+ action to_controller() {
114
+ hdr.packet_in.setValid();
115
+ hdr.packet_in.ingress_port = standard_metadata.ingress_port;
116
+ }
117
+
118
+ apply {
119
+
120
+ // Prune multicast packets going to ingress port to prevent loops
121
+ if (standard_metadata.egress_port == standard_metadata.ingress_port)
122
+ drop();
123
+
124
+
125
+ // Send a copy of the packet to the controller for learning
126
+ if (standard_metadata.egress_port == CPU_PORT)
127
+ to_controller();
128
+ }
129
+ }
130
+
131
+
132
+ /**/
133
+ /* Checksum Computation */
134
+ /**/
135
+
136
+ control MyComputeChecksum(inout headers hdr, inout metadata meta) {
137
+ apply { }
138
+ }
139
+
140
+
141
+ /**/
142
+ /* Deparser */
143
+ /**/
144
+
145
+ control MyDeparser(packet_out packet, in headers hdr) {
146
+ apply {
147
+ packet.emit(hdr.packet_in);
148
+ packet.emit(hdr.ethernet);
149
+ }
150
+ }
151
+
152
+
153
+ /**/
154
+ /* Bridge */
155
+ /**/
156
+
157
+ V1Switch(
158
+ MyParser(),
159
+ MyVerifyChecksum(),
160
+ MyIngress(),
161
+ MyEgress(),
162
+ MyComputeChecksum(),
163
+ MyDeparser()
164
+ ) main;
individual_files/000044__raw-repositories__ByungUkMin__p4-encryption.p4 ADDED
@@ -0,0 +1,287 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <core.p4>
2
+ #include <v1model.p4>
3
+
4
+ #define MCAST_ID 1
5
+ #define CPU_PORT 255
6
+
7
+
8
+ #define ETH_TYPE_ARP 0x0806
9
+ #define ETH_TYPE_VLAN 0x8100
10
+
11
+ typedef bit<9> egressSpec_t;
12
+ typedef bit<48> macAddr_t;
13
+
14
+
15
+ /**/
16
+ /* Headers */
17
+ /**/
18
+
19
+ @controller_header("packet_in")
20
+ header packet_in_header_t {
21
+ bit<9> ingress_port;
22
+ bit<7> _pad;
23
+ }
24
+
25
+ header ethernet_t {
26
+ macAddr_t dstAddr;
27
+ macAddr_t srcAddr;
28
+ bit<16> etherType;
29
+ }
30
+
31
+ header vlan_t {
32
+ bit<3> pcp;
33
+ bit<1> cfi;
34
+ bit<12> vid;
35
+ bit<16> etherType;
36
+ }
37
+
38
+ struct metadata {
39
+ bit<12> vid;
40
+ bit<16> etherType;
41
+ bit<4> _pad;
42
+ }
43
+
44
+ struct headers {
45
+ vlan_t vlan;
46
+ ethernet_t ethernet;
47
+ packet_in_header_t packet_in;
48
+ }
49
+
50
+
51
+ /**/
52
+ /* Parser */
53
+ /**/
54
+
55
+ parser MyParser(packet_in packet,
56
+ out headers hdr,
57
+ inout metadata meta,
58
+ inout standard_metadata_t standard_metadata) {
59
+
60
+ state start {
61
+ transition parse_ethernet;
62
+ }
63
+
64
+ state parse_ethernet {
65
+ packet.extract(hdr.ethernet);
66
+ meta.vid = 0;
67
+ meta.etherType = hdr.ethernet.etherType;
68
+ transition select(hdr.ethernet.etherType) {
69
+ ETH_TYPE_VLAN: parse_vlan;
70
+ default: accept;
71
+ }
72
+ }
73
+
74
+ state parse_vlan {
75
+ packet.extract(hdr.vlan);
76
+ meta.vid = hdr.vlan.vid;
77
+ meta.etherType = hdr.vlan.etherType;
78
+ transition accept;
79
+ }
80
+ }
81
+
82
+
83
+ /**/
84
+ /* Checksum Verification */
85
+ /**/
86
+
87
+ control MyVerifyChecksum(inout headers hdr, inout metadata meta) {
88
+ apply { }
89
+ }
90
+
91
+
92
+ /**/
93
+ /* Ingress Processing */
94
+ /**/
95
+
96
+ control MyIngress(inout headers hdr,
97
+ inout metadata meta,
98
+ inout standard_metadata_t standard_metadata) {
99
+
100
+ action forward(egressSpec_t port) {
101
+ standard_metadata.egress_spec = port;
102
+ }
103
+
104
+ action flood() {
105
+ standard_metadata.mcast_grp = MCAST_ID;
106
+ }
107
+
108
+ /**/
109
+ /* Switch Table Logic - Begins */
110
+ /**/
111
+
112
+
113
+
114
+ table switch_table {
115
+ key = {
116
+ hdr.ethernet.dstAddr: exact;
117
+ meta.vid: exact;
118
+
119
+ }
120
+ actions = {
121
+ flood;
122
+ forward;
123
+ }
124
+ size = 1024;
125
+ default_action = flood;
126
+ }
127
+
128
+
129
+ /**/
130
+ /* Switch Table Logic - Ends */
131
+ /**/
132
+
133
+ apply {
134
+
135
+ /**/
136
+ /* Ingress Apply Logic - Begins */
137
+ /**/
138
+
139
+
140
+
141
+ if (hdr.ethernet.etherType == ETH_TYPE_VLAN) {
142
+
143
+ // VLAN-enabled
144
+ if (meta.etherType == ETH_TYPE_ARP) {
145
+
146
+ // VLAN-enabled + ARP packet
147
+ flood();
148
+ }
149
+ else {
150
+
151
+ // VLAN-enabled + Non-ARP packet
152
+ switch_table.apply();
153
+ }
154
+ }
155
+ else if (hdr.ethernet.etherType == ETH_TYPE_ARP) {
156
+
157
+ // Non-VLAN + ARP packet
158
+ flood();
159
+ }
160
+ else {
161
+
162
+ // Non-VLAN + Non-ARP packet
163
+ switch_table.apply();
164
+ }
165
+
166
+
167
+ /**/
168
+ /* Ingress Apply Logic - Ends */
169
+ /**/
170
+ }
171
+ }
172
+
173
+
174
+ /**/
175
+ /* Egress Processing */
176
+ /**/
177
+
178
+ control MyEgress(inout headers hdr,
179
+ inout metadata meta,
180
+ inout standard_metadata_t standard_metadata) {
181
+ action noop() {
182
+
183
+ /* empty */
184
+ }
185
+
186
+ action drop() {
187
+ mark_to_drop(standard_metadata);
188
+ }
189
+
190
+ action to_controller() {
191
+ hdr.packet_in.setValid();
192
+ hdr.packet_in.ingress_port = standard_metadata.ingress_port;
193
+ }
194
+
195
+
196
+ /**/
197
+ /* VLAN Table Logic - Begins */
198
+ /**/
199
+
200
+
201
+
202
+ table vlan_table {
203
+ key = {
204
+
205
+ meta.vid: exact;
206
+ standard_metadata.egress_port: exact;
207
+ }
208
+ actions = {
209
+ noop;
210
+ drop;
211
+ }
212
+ size = 1024;
213
+ default_action = drop;
214
+ }
215
+
216
+
217
+ /**/
218
+ /* Switch Table Logic - Ends */
219
+ /**/
220
+
221
+ apply {
222
+
223
+ /**/
224
+ /* Egress Apply Logic - Begins */
225
+ /**/
226
+
227
+
228
+
229
+
230
+ // (1) Prune multicast packets going to ingress port to prevent loops
231
+ if (standard_metadata.egress_port == standard_metadata.ingress_port)
232
+ drop();
233
+
234
+
235
+
236
+ // (2) Send a copy of the packet to the controller for learning
237
+ if (standard_metadata.egress_port == CPU_PORT)
238
+ to_controller();
239
+
240
+
241
+ // (3) Check if the VLAN header exists. If yes, then drop packets ...
242
+ if (hdr.ethernet.etherType == ETH_TYPE_VLAN) {
243
+ vlan_table.apply();
244
+ }
245
+
246
+
247
+ /**/
248
+ /* Egress Apply Logic - Ends */
249
+ /**/
250
+ }
251
+ }
252
+
253
+
254
+ /**/
255
+ /* Checksum Computation */
256
+ /**/
257
+
258
+ control MyComputeChecksum(inout headers hdr, inout metadata meta) {
259
+ apply { }
260
+ }
261
+
262
+
263
+ /**/
264
+ /* Deparser */
265
+ /**/
266
+
267
+ control MyDeparser(packet_out packet, in headers hdr) {
268
+ apply {
269
+ packet.emit(hdr.packet_in);
270
+ packet.emit(hdr.ethernet);
271
+ packet.emit(hdr.vlan);
272
+ }
273
+ }
274
+
275
+
276
+ /**/
277
+ /* Switch */
278
+ /**/
279
+
280
+ V1Switch(
281
+ MyParser(),
282
+ MyVerifyChecksum(),
283
+ MyIngress(),
284
+ MyEgress(),
285
+ MyComputeChecksum(),
286
+ MyDeparser()
287
+ ) main;
individual_files/000045__raw-repositories__cpt-harlock__p4-cuckoo-hash.p4 ADDED
@@ -0,0 +1,198 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <v1model.p4>
2
+ #include <core.p4>
3
+
4
+ typedef bit<9> egressSpec_t;
5
+ typedef bit<48> macAddr_t;
6
+ typedef bit<32> ip4Addr_t;
7
+
8
+
9
+ #define CH_LENGTH 512
10
+ #define CH_LENGTH_BIT 16w512
11
+
12
+ // 106 bits per register, first 96 bits for key and others for value
13
+ register<bit<106>>(CH_LENGTH) ch_first_row;
14
+ register<bit<106>>(CH_LENGTH) ch_second_row;
15
+ register<bit<10>>(1) counter_reg;
16
+
17
+ header ethernet_t {
18
+ macAddr_t dstAddr;
19
+ macAddr_t srcAddr;
20
+ bit<16> etherType;
21
+ }
22
+
23
+ header ipv4_t {
24
+ bit<4> version;
25
+ bit<4> ihl;
26
+ bit<8> diffserv;
27
+ bit<16> totalLen;
28
+ bit<16> identification;
29
+ bit<3> flags;
30
+ bit<13> fragOffset;
31
+ bit<8> ttl;
32
+ bit<8> protocol;
33
+ bit<16> hdrChecksum;
34
+ ip4Addr_t srcAddr;
35
+ ip4Addr_t dstAddr;
36
+ }
37
+
38
+ header tcp_t {
39
+ bit<16> srcPort;
40
+ bit<16> dstPort;
41
+ bit<32> seqNo;
42
+ bit<32> ackNo;
43
+ bit<4> dataOffset;
44
+ bit<3> res;
45
+ bit<3> ecn;
46
+ bit<6> ctrl;
47
+ bit<16> window;
48
+ bit<16> checksum;
49
+ bit<16> urgentPtr;
50
+ }
51
+
52
+ struct metadata {
53
+
54
+ /* empty */
55
+ }
56
+
57
+ struct headers {
58
+ ethernet_t ethernet;
59
+ ipv4_t ipv4;
60
+ tcp_t tcp;
61
+ }
62
+
63
+
64
+
65
+ parser MyParser(packet_in packet,
66
+ out headers hdr,
67
+ inout metadata meta,
68
+ inout standard_metadata_t standard_metadata) {
69
+
70
+ state start {
71
+ transition parse_ethernet;
72
+ }
73
+
74
+ state parse_ethernet {
75
+ packet.extract(hdr.ethernet);
76
+ transition select(hdr.ethernet.etherType) {
77
+ 0x0800: parse_ip;
78
+ default: reject;
79
+ }
80
+ }
81
+
82
+ state parse_ip {
83
+ packet.extract(hdr.ipv4);
84
+ transition select(hdr.ipv4.protocol) {
85
+ 0x6: parse_tcp;
86
+ default: reject;
87
+ }
88
+ }
89
+
90
+ state parse_tcp {
91
+ packet.extract(hdr.tcp);
92
+ transition accept;
93
+ }
94
+ }
95
+
96
+
97
+
98
+
99
+ control MyVerifyChecksum(inout headers hdr, inout metadata meta) {
100
+ apply { }
101
+ }
102
+
103
+
104
+
105
+
106
+ control MyIngress(inout headers hdr,
107
+ inout metadata meta,
108
+ inout standard_metadata_t standard_metadata) {
109
+
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+
118
+ //compute CH indices
119
+ apply {
120
+ bit<32> first_index;
121
+ bit<32> second_index;
122
+ bit<96> packet_key = hdr.ipv4.srcAddr ++ hdr.ipv4.dstAddr ++ hdr.tcp.srcPort ++ hdr.tcp.dstPort;
123
+ hash(first_index, HashAlgorithm.crc16, 16w0, { 0w0, hdr.ipv4.srcAddr, hdr.ipv4.dstAddr, hdr.tcp.srcPort, hdr.tcp.dstPort }, 16w512);
124
+ hash(second_index, HashAlgorithm.crc16, 16w0, { 1w0, hdr.ipv4.srcAddr, hdr.ipv4.dstAddr, hdr.tcp.srcPort, hdr.tcp.dstPort }, 16w512);
125
+ bit<106> first_result;
126
+ bit<106> second_result;
127
+ bit<10> counter_result;
128
+ ch_first_row.read(first_result, first_index);
129
+ ch_second_row.read(second_result, second_index);
130
+ if (first_result[95:0] == packet_key) {
131
+
132
+ //do nothing
133
+ } else if (second_result[95:0] == packet_key) {
134
+
135
+ //do nothing
136
+ } else if (first_result[95:0] == 96w0) {
137
+ counter_reg.read(counter_result, 0);
138
+ ch_first_row.write(first_index, counter_result ++ packet_key);
139
+ counter_reg.write(0, counter_result+1);
140
+ } else if (second_result[95:0] == 96w0) {
141
+ counter_reg.read(counter_result, 0);
142
+ ch_second_row.write(second_index, counter_result ++ packet_key);
143
+ counter_reg.write(0, counter_result+1);
144
+ }
145
+
146
+
147
+ }
148
+ }
149
+
150
+
151
+
152
+ control MyEgress(inout headers hdr,
153
+ inout metadata meta,
154
+ inout standard_metadata_t standard_metadata) {
155
+ apply { }
156
+ }
157
+
158
+
159
+
160
+ control MyComputeChecksum(inout headers hdr, inout metadata meta) {
161
+ apply {
162
+ update_checksum(
163
+ hdr.ipv4.isValid(),
164
+ { hdr.ipv4.version,
165
+ hdr.ipv4.ihl,
166
+ hdr.ipv4.diffserv,
167
+ hdr.ipv4.totalLen,
168
+ hdr.ipv4.identification,
169
+ hdr.ipv4.flags,
170
+ hdr.ipv4.fragOffset,
171
+ hdr.ipv4.ttl,
172
+ hdr.ipv4.protocol,
173
+ hdr.ipv4.srcAddr,
174
+ hdr.ipv4.dstAddr },
175
+ hdr.ipv4.hdrChecksum,
176
+ HashAlgorithm.csum16);
177
+ }
178
+ }
179
+
180
+
181
+
182
+
183
+ control MyDeparser(packet_out packet, in headers hdr) {
184
+ apply {
185
+
186
+ }
187
+ }
188
+
189
+
190
+
191
+ V1Switch(
192
+ MyParser(),
193
+ MyVerifyChecksum(),
194
+ MyIngress(),
195
+ MyEgress(),
196
+ MyComputeChecksum(),
197
+ MyDeparser()
198
+ ) main;
individual_files/000046__raw-repositories__bennyrubin__HydraCode.p4 ADDED
@@ -0,0 +1,406 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <core.p4>
2
+ #include <v1model.p4>
3
+
4
+ #include <v1model.p4>
5
+
6
+ #define ETHERTYPE_CHECKER 0x5678;
7
+
8
+ header eth_type2_t {
9
+ bit<16> value;
10
+ }
11
+ header variables_t {
12
+
13
+ }
14
+ header slices_preamble_t {
15
+ bit<8> num_items_slices;
16
+ }
17
+ header slices_item_t {
18
+ bit<32> value;
19
+ }
20
+ struct hydra_header_t {
21
+ eth_type2_t eth_type;
22
+ variables_t variables;
23
+ slices_preamble_t slices_preamble;
24
+ slices_item_t[3] slices;
25
+ }
26
+ struct hydra_metadata_t {
27
+ bool reject0;
28
+ bit<8> num_list_items;
29
+ bit<32> switch_slice;
30
+ }
31
+ parser CheckerHeaderParser(packet_in packet, out hydra_header_t hydra_header,
32
+ inout hydra_metadata_t hydra_metadata) {
33
+ state start {
34
+ packet.extract(hydra_header.eth_type);
35
+ transition parse_variables;
36
+ }
37
+ state parse_variables {
38
+ packet.extract(hydra_header.variables);
39
+ transition parse_slices_preamble;
40
+ }
41
+ state parse_slices_preamble
42
+ {
43
+ packet.extract(hydra_header.slices_preamble);
44
+ hydra_metadata.num_list_items =
45
+ hydra_header.slices_preamble.num_items_slices;
46
+ transition select(hydra_metadata.num_list_items) {
47
+ 0: accept;
48
+ default: parse_slices;
49
+ }
50
+ }
51
+ state parse_slices
52
+ {
53
+ packet.extract(hydra_header.slices.next);
54
+ hydra_metadata.num_list_items = hydra_metadata.num_list_items-1;
55
+ transition select(hydra_metadata.num_list_items) {
56
+ 0: accept;
57
+ default: parse_slices;
58
+ }
59
+ }
60
+ }
61
+ control CheckerHeaderDeparser(packet_out packet,
62
+ in hydra_header_t hydra_header) {
63
+ apply
64
+ {
65
+ packet.emit(hydra_header.eth_type);
66
+ packet.emit(hydra_header.variables);
67
+ packet.emit(hydra_header.slices_preamble);
68
+ packet.emit(hydra_header.slices);
69
+ }
70
+ }
71
+ control initControl(inout hydra_header_t hydra_header,
72
+ inout hydra_metadata_t hydra_metadata) {
73
+ action init_cp_vars(bit<32> switch_slice)
74
+ {
75
+ hydra_metadata.switch_slice = switch_slice;
76
+ }
77
+ table tb_init_cp_vars {
78
+ key = {
79
+
80
+ }
81
+ actions = {
82
+ init_cp_vars;
83
+ }
84
+ size = 2;
85
+ }
86
+ apply
87
+ {
88
+ tb_init_cp_vars.apply();
89
+ hydra_header.eth_type.setValid();
90
+ hydra_header.eth_type.value = ETHERTYPE_CHECKER;
91
+ hydra_header.slices_preamble.setValid();
92
+ hydra_header.slices_preamble.num_items_slices = 0;
93
+ }
94
+ }
95
+ control telemetryControl(inout hydra_header_t hydra_header,
96
+ inout hydra_metadata_t hydra_metadata) {
97
+ action init_cp_vars(bit<32> switch_slice)
98
+ {
99
+ hydra_metadata.switch_slice = switch_slice;
100
+ }
101
+ table tb_init_cp_vars {
102
+ key = {
103
+
104
+ }
105
+ actions = {
106
+ init_cp_vars;
107
+ }
108
+ size = 2;
109
+ }
110
+ apply
111
+ {
112
+ tb_init_cp_vars.apply();
113
+ hydra_header.slices.push_front(1);
114
+ hydra_header.slices[0].setValid();
115
+ hydra_header.slices[0].value = 1;
116
+ hydra_header.slices_preamble.num_items_slices = hydra_header.slices_preamble.num_items_slices + 1;
117
+ }
118
+ }
119
+ control checkerControl(inout hydra_header_t hydra_header,
120
+ inout hydra_metadata_t hydra_metadata) {
121
+ action init_cp_vars(bit<32> switch_slice)
122
+ {
123
+ hydra_metadata.switch_slice = switch_slice;
124
+ }
125
+ table tb_init_cp_vars {
126
+ key = {
127
+
128
+ }
129
+ actions = {
130
+ init_cp_vars;
131
+ }
132
+ size = 2;
133
+ }
134
+ apply
135
+ {
136
+ tb_init_cp_vars.apply();
137
+ bit<32> prev_slice = hydra_header.slices[0].value;
138
+ bit<32> slice;
139
+ if (hydra_header.slices[0].isValid())
140
+ {
141
+ slice = hydra_header.slices[0].value;
142
+ if (prev_slice!=slice) {
143
+ hydra_metadata.reject0 = true;
144
+ }
145
+ prev_slice = slice;
146
+ if (hydra_header.slices[1].isValid())
147
+ {
148
+ slice = hydra_header.slices[1].value;
149
+ if (prev_slice!=slice) {
150
+ hydra_metadata.reject0 = true;
151
+ }
152
+ prev_slice = slice;
153
+ if (hydra_header.slices[2].isValid())
154
+ {
155
+ slice = hydra_header.slices[2].value;
156
+ if (prev_slice!=slice) {
157
+ hydra_metadata.reject0 = true;
158
+ }
159
+ prev_slice = slice;
160
+ }
161
+ }
162
+ }
163
+
164
+ hydra_header.eth_type.setInvalid();
165
+ hydra_header.variables.setInvalid();
166
+ hydra_header.slices_preamble.setInvalid();
167
+ hydra_header.slices[0].setInvalid();
168
+ hydra_header.slices[1].setInvalid();
169
+ hydra_header.slices[2].setInvalid();
170
+ }
171
+ }
172
+
173
+
174
+ const bit<16> TYPE_IPV4 = 0x800;
175
+ const bit<16> TYPE_HYDRA = 0x5678;
176
+
177
+
178
+
179
+ typedef bit<9> egressSpec_t;
180
+ typedef bit<48> macAddr_t;
181
+ typedef bit<32> ip4Addr_t;
182
+
183
+ header ethernet_t {
184
+ macAddr_t dstAddr;
185
+ macAddr_t srcAddr;
186
+ }
187
+
188
+ header eth_type_t {
189
+ bit<16> etherType;
190
+ }
191
+
192
+ header ipv4_t {
193
+ bit<4> version;
194
+ bit<4> ihl;
195
+ bit<8> diffserv;
196
+ bit<16> totalLen;
197
+ bit<16> identification;
198
+ bit<3> flags;
199
+ bit<13> fragOffset;
200
+ bit<8> ttl;
201
+ bit<8> protocol;
202
+ bit<16> hdrChecksum;
203
+ ip4Addr_t srcAddr;
204
+ ip4Addr_t dstAddr;
205
+ }
206
+
207
+ struct metadata {
208
+ bool first_hop;
209
+ bool last_hop;
210
+ hydra_metadata_t hydra_metadata;
211
+ }
212
+
213
+ struct headers {
214
+ ethernet_t ethernet;
215
+ hydra_header_t hydra_header;
216
+ eth_type_t eth_type;
217
+ ipv4_t ipv4;
218
+ }
219
+
220
+
221
+
222
+ parser MyParser(packet_in packet,
223
+ out headers hdr,
224
+ inout metadata meta,
225
+ inout standard_metadata_t standard_metadata) {
226
+
227
+ CheckerHeaderParser() hydra_parser;
228
+
229
+ state start {
230
+ transition parse_ethernet;
231
+ }
232
+
233
+ state parse_ethernet {
234
+ packet.extract(hdr.ethernet);
235
+ transition parse_tele_or_eth_type;
236
+ }
237
+
238
+ state parse_tele_or_eth_type {
239
+ transition select(packet.lookahead<bit<16>>()) {
240
+ TYPE_HYDRA: parse_hydra_headers;
241
+ default: parse_eth_type;
242
+ }
243
+ }
244
+
245
+ state parse_hydra_headers {
246
+ hydra_parser.apply(packet, hdr.hydra_header, meta.hydra_metadata);
247
+ transition parse_eth_type;
248
+ }
249
+
250
+ state parse_eth_type {
251
+ packet.extract(hdr.eth_type);
252
+ transition select(hdr.eth_type.etherType) {
253
+ TYPE_IPV4: parse_ipv4;
254
+ default: accept;
255
+ }
256
+ }
257
+
258
+ state parse_ipv4 {
259
+ packet.extract(hdr.ipv4);
260
+ transition accept;
261
+ }
262
+ }
263
+
264
+
265
+
266
+ control MyVerifyChecksum(inout headers hdr, inout metadata meta) {
267
+ apply { }
268
+ }
269
+
270
+
271
+
272
+
273
+ control MyIngress(inout headers hdr,
274
+ inout metadata meta,
275
+ inout standard_metadata_t standard_metadata) {
276
+ action drop() {
277
+ mark_to_drop(standard_metadata);
278
+ }
279
+
280
+ action ipv4_forward(macAddr_t dstAddr, egressSpec_t port) {
281
+ standard_metadata.egress_spec = port;
282
+ hdr.ethernet.srcAddr = hdr.ethernet.dstAddr;
283
+ hdr.ethernet.dstAddr = dstAddr;
284
+ hdr.ipv4.ttl = hdr.ipv4.ttl - 1;
285
+ }
286
+
287
+ table ipv4_lpm {
288
+ key = {
289
+ hdr.ipv4.dstAddr: lpm;
290
+ }
291
+ actions = {
292
+ ipv4_forward;
293
+ drop;
294
+ NoAction;
295
+ }
296
+ size = 1024;
297
+ default_action = drop();
298
+ }
299
+
300
+ action set_first_hop() {
301
+ meta.first_hop = true;
302
+ }
303
+
304
+ table tb_check_first_hop {
305
+ key = {
306
+ standard_metadata.ingress_port: exact;
307
+ }
308
+ actions = {
309
+ @defaultonly NoAction;
310
+ set_first_hop;
311
+ }
312
+ const default_action = NoAction();
313
+ size = 512;
314
+ }
315
+
316
+ apply {
317
+ tb_check_first_hop.apply();
318
+ if (meta.first_hop) {
319
+ initControl.apply(hdr.hydra_header, meta.hydra_metadata);
320
+ }
321
+ if (hdr.ipv4.isValid()) {
322
+ ipv4_lpm.apply();
323
+ }
324
+ }
325
+ }
326
+
327
+
328
+
329
+ control MyEgress(inout headers hdr,
330
+ inout metadata meta,
331
+ inout standard_metadata_t standard_metadata) {
332
+
333
+ action set_last_hop() {
334
+ meta.last_hop = true;
335
+ }
336
+
337
+ table tb_check_last_hop {
338
+ key = {
339
+ standard_metadata.egress_port: exact;
340
+ }
341
+ actions = {
342
+ @defaultonly NoAction;
343
+ set_last_hop;
344
+ }
345
+ const default_action = NoAction();
346
+ size = 512;
347
+ }
348
+
349
+ apply {
350
+ telemetryControl.apply(hdr.hydra_header, meta.hydra_metadata);
351
+ tb_check_last_hop.apply();
352
+ if (meta.last_hop) {
353
+ checkerControl.apply(hdr.hydra_header, meta.hydra_metadata);
354
+ }
355
+ if (meta.hydra_metadata.reject0) {
356
+ mark_to_drop(standard_metadata);
357
+ }
358
+ }
359
+ }
360
+
361
+
362
+
363
+ control MyComputeChecksum(inout headers hdr, inout metadata meta) {
364
+ apply {
365
+ update_checksum(
366
+ hdr.ipv4.isValid(),
367
+ { hdr.ipv4.version,
368
+ hdr.ipv4.ihl,
369
+ hdr.ipv4.diffserv,
370
+ hdr.ipv4.totalLen,
371
+ hdr.ipv4.identification,
372
+ hdr.ipv4.flags,
373
+ hdr.ipv4.fragOffset,
374
+ hdr.ipv4.ttl,
375
+ hdr.ipv4.protocol,
376
+ hdr.ipv4.srcAddr,
377
+ hdr.ipv4.dstAddr },
378
+ hdr.ipv4.hdrChecksum,
379
+ HashAlgorithm.csum16);
380
+ }
381
+ }
382
+
383
+
384
+
385
+ control MyDeparser(packet_out packet, in headers hdr) {
386
+
387
+ CheckerHeaderDeparser() hydra_deparser;
388
+
389
+ apply {
390
+ packet.emit(hdr.ethernet);
391
+ hydra_deparser.apply(packet, hdr.hydra_header);
392
+ packet.emit(hdr.eth_type);
393
+ packet.emit(hdr.ipv4);
394
+ }
395
+ }
396
+
397
+
398
+
399
+ V1Switch(
400
+ MyParser(),
401
+ MyVerifyChecksum(),
402
+ MyIngress(),
403
+ MyEgress(),
404
+ MyComputeChecksum(),
405
+ MyDeparser()
406
+ ) main;
individual_files/000047__raw-repositories__bennyrubin__HydraCode.p4 ADDED
@@ -0,0 +1,487 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <core.p4>
2
+ #include <v1model.p4>
3
+
4
+ const bit<16> TYPE_IPV4 = 0x800;
5
+ const bit<16> TYPE_SRCROUTING = 0x1234;
6
+ const bit<16> TYPE_HYDRA = 0x5678;
7
+
8
+
9
+ #define MAX_HOPS 9
10
+
11
+
12
+
13
+ typedef bit<9> egressSpec_t;
14
+ typedef bit<48> macAddr_t;
15
+ typedef bit<32> ip4Addr_t;
16
+
17
+ header ethernet_t {
18
+ macAddr_t dstAddr;
19
+ macAddr_t srcAddr;
20
+ bit<16> etherType;
21
+ }
22
+
23
+ header srcRoute_t {
24
+ bit<1> bos;
25
+ bit<15> port;
26
+ }
27
+
28
+ header ipv4_t {
29
+ bit<4> version;
30
+ bit<4> ihl;
31
+ bit<8> diffserv;
32
+ bit<16> totalLen;
33
+ bit<16> identification;
34
+ bit<3> flags;
35
+ bit<13> fragOffset;
36
+ bit<8> ttl;
37
+ bit<8> protocol;
38
+ bit<16> hdrChecksum;
39
+ ip4Addr_t srcAddr;
40
+ ip4Addr_t dstAddr;
41
+ }
42
+
43
+
44
+ #include <v1model.p4>
45
+
46
+ #define ETHERTYPE_CHECKER 0x5678;
47
+
48
+
49
+ header eth_type2_t {
50
+ bit<16> value;
51
+ }
52
+ header variables_t {
53
+ bit<7> index;
54
+ bool to_reject;
55
+ }
56
+ header expected_path_preamble_t {
57
+ bit<8> num_items_expected_path;
58
+ }
59
+ header expected_path_item_t {
60
+ bit<16> value;
61
+ }
62
+ struct hydra_header_t {
63
+ eth_type2_t eth_type;
64
+ variables_t variables;
65
+ expected_path_preamble_t expected_path_preamble;
66
+ expected_path_item_t[3] expected_path;
67
+ }
68
+ struct hydra_metadata_t {
69
+ bool reject0;
70
+ bit<8> num_list_items;
71
+ bit<16> switch_id;
72
+ bit<32> expected_s3_dict_var0;
73
+ bit<32> expected_s2_dict_var0;
74
+ bit<32> expected_s1_dict_var0;
75
+ bit<16> expected_s1_dict;
76
+ bit<16> expected_s2_dict;
77
+ bit<16> expected_s3_dict;
78
+ }
79
+ parser CheckerHeaderParser(packet_in packet, out hydra_header_t hydra_header,
80
+ inout hydra_metadata_t hydra_metadata) {
81
+ state start {
82
+ packet.extract(hydra_header.eth_type);
83
+ transition parse_variables;
84
+ }
85
+ state parse_variables {
86
+ packet.extract(hydra_header.variables);
87
+ transition parse_expected_path_preamble;
88
+ }
89
+
90
+ state parse_expected_path_preamble
91
+ {
92
+ packet.extract(hydra_header.expected_path_preamble);
93
+ hydra_metadata.num_list_items =
94
+ hydra_header.expected_path_preamble.num_items_expected_path;
95
+ transition select(hydra_metadata.num_list_items) {
96
+ 0: accept;
97
+ default: parse_expected_path;
98
+ }
99
+ }
100
+
101
+ state parse_expected_path
102
+ {
103
+ packet.extract(hydra_header.expected_path.next);
104
+ hydra_metadata.num_list_items = hydra_metadata.num_list_items-1;
105
+ transition select(hydra_metadata.num_list_items) {
106
+ 0: accept;
107
+ default: parse_expected_path;
108
+ }
109
+ }
110
+ }
111
+ control CheckerHeaderDeparser(packet_out packet,
112
+ in hydra_header_t hydra_header) {
113
+ apply
114
+ {
115
+ packet.emit(hydra_header.eth_type);
116
+ packet.emit(hydra_header.variables);
117
+ packet.emit(hydra_header.expected_path_preamble);
118
+ packet.emit(hydra_header.expected_path);
119
+ }
120
+ }
121
+ control initControl(in ipv4_t ipv4,
122
+ inout hydra_header_t hydra_header,
123
+ inout hydra_metadata_t hydra_metadata) {
124
+
125
+ action lkp_cp_dict_expected_s3_dict(bit<16> expected_s3_dict)
126
+ {
127
+ hydra_metadata.expected_s3_dict = expected_s3_dict;
128
+ }
129
+ table tbl_lkp_cp_dict_expected_s3_dict
130
+ {
131
+ key = {
132
+ hydra_metadata.expected_s3_dict_var0: lpm;
133
+ }
134
+ actions = {
135
+ lkp_cp_dict_expected_s3_dict;
136
+ }
137
+ size = 64;
138
+ }
139
+
140
+ action lkp_cp_dict_expected_s2_dict(bit<16> expected_s2_dict)
141
+ {
142
+ hydra_metadata.expected_s2_dict = expected_s2_dict;
143
+ }
144
+
145
+ table tbl_lkp_cp_dict_expected_s2_dict
146
+ {
147
+ key = {
148
+ hydra_metadata.expected_s2_dict_var0: lpm;
149
+ }
150
+ actions = {
151
+ lkp_cp_dict_expected_s2_dict;
152
+ }
153
+ size = 64;
154
+ }
155
+
156
+ action lkp_cp_dict_expected_s1_dict(bit<16> expected_s1_dict)
157
+ {
158
+ hydra_metadata.expected_s1_dict = expected_s1_dict;
159
+ }
160
+
161
+ table tbl_lkp_cp_dict_expected_s1_dict
162
+ {
163
+ key = {
164
+ hydra_metadata.expected_s1_dict_var0: lpm;
165
+ }
166
+ actions = {
167
+ lkp_cp_dict_expected_s1_dict;
168
+ }
169
+ size = 64;
170
+ }
171
+
172
+ table tb_debug {
173
+ key = {
174
+ hydra_header.expected_path[0].value: exact;
175
+ hydra_header.expected_path[1].value: exact;
176
+ hydra_header.expected_path[2].value: exact;
177
+ }
178
+ actions = {
179
+ lkp_cp_dict_expected_s1_dict;
180
+ }
181
+ const entries = {
182
+ (0,0,0): lkp_cp_dict_expected_s1_dict(0);
183
+ }
184
+ size = 2;
185
+ }
186
+
187
+ apply
188
+ {
189
+ hydra_header.eth_type.setValid();
190
+ hydra_header.eth_type.value = ETHERTYPE_CHECKER;
191
+ hydra_header.variables.setValid();
192
+ hydra_header.variables.index = 0;
193
+ hydra_header.variables.to_reject = false;
194
+ hydra_header.expected_path_preamble.setValid();
195
+ hydra_metadata.expected_s3_dict_var0 = ipv4.dstAddr;
196
+
197
+ // 167773188;
198
+ tbl_lkp_cp_dict_expected_s3_dict.apply();
199
+ hydra_header.expected_path.push_front(1);
200
+ hydra_header.expected_path[0].setValid();
201
+ hydra_header.expected_path[0].value =
202
+ hydra_metadata.expected_s3_dict;
203
+ hydra_metadata.expected_s2_dict_var0 = ipv4.dstAddr;
204
+ tbl_lkp_cp_dict_expected_s2_dict.apply();
205
+ hydra_header.expected_path.push_front(1);
206
+ hydra_header.expected_path[0].setValid();
207
+ hydra_header.expected_path[0].value =
208
+ hydra_metadata.expected_s2_dict;
209
+ hydra_metadata.expected_s1_dict_var0 = ipv4.dstAddr;
210
+ tbl_lkp_cp_dict_expected_s1_dict.apply();
211
+ hydra_header.expected_path.push_front(1);
212
+ hydra_header.expected_path[0].setValid();
213
+ hydra_header.expected_path[0].value =
214
+ hydra_metadata.expected_s1_dict;
215
+ hydra_header.expected_path_preamble.num_items_expected_path = 3;
216
+ tb_debug.apply();
217
+ }
218
+ }
219
+ control telemetryControl(
220
+ inout hydra_header_t hydra_header,
221
+ inout hydra_metadata_t hydra_metadata) {
222
+ action init_cp_vars(bit<16> switch_id)
223
+ {
224
+ hydra_metadata.switch_id = switch_id;
225
+ }
226
+ table tb_init_cp_vars {
227
+ key = {
228
+ hydra_header.eth_type.isValid(): exact;
229
+ }
230
+ actions = {
231
+ init_cp_vars;
232
+ }
233
+ size = 2;
234
+ }
235
+
236
+ table tb_debug {
237
+ key = {
238
+ hydra_header.expected_path[0].value: exact;
239
+ hydra_header.expected_path[1].value: exact;
240
+ hydra_header.expected_path[2].value: exact;
241
+ hydra_metadata.switch_id: exact;
242
+ hydra_header.variables.index: exact;
243
+ }
244
+ actions = {
245
+ init_cp_vars;
246
+ }
247
+ const entries = {
248
+ (0,0,0,0,0): init_cp_vars(0);
249
+ }
250
+ size = 2;
251
+ }
252
+
253
+ apply {
254
+ tb_init_cp_vars.apply();
255
+ tb_debug.apply();
256
+ if (hydra_header.expected_path[hydra_header.variables.index].value != hydra_metadata.switch_id)
257
+ {
258
+ hydra_header.variables.to_reject = true;
259
+ } else {
260
+ if (hydra_header.variables.index<3) {
261
+ hydra_header.variables.index = hydra_header.variables.index+1;
262
+ } else {
263
+ hydra_header.variables.to_reject = true;
264
+ }
265
+ }
266
+ }
267
+ }
268
+ control checkerControl(
269
+ inout hydra_header_t hydra_header,
270
+ inout hydra_metadata_t hydra_metadata) {
271
+
272
+ apply
273
+ {
274
+
275
+ if (hydra_header.variables.to_reject) {
276
+ hydra_metadata.reject0 = true;
277
+ }
278
+ hydra_header.eth_type.setInvalid();
279
+ hydra_header.variables.setInvalid();
280
+ hydra_header.expected_path_preamble.setInvalid();
281
+ hydra_header.expected_path[0].setInvalid();
282
+ hydra_header.expected_path[1].setInvalid();
283
+ hydra_header.expected_path[2].setInvalid();
284
+ }
285
+ }
286
+
287
+
288
+
289
+
290
+ struct metadata {
291
+ bool first_hop;
292
+ bool last_hop;
293
+ hydra_metadata_t hydra_metadata;
294
+ }
295
+
296
+ struct headers {
297
+ ethernet_t ethernet;
298
+ hydra_header_t hydra_header;
299
+ srcRoute_t[MAX_HOPS] srcRoutes;
300
+ ipv4_t ipv4;
301
+ }
302
+
303
+
304
+
305
+
306
+
307
+ parser MyParser(packet_in packet,
308
+ out headers hdr,
309
+ inout metadata meta,
310
+ inout standard_metadata_t standard_metadata) {
311
+
312
+ CheckerHeaderParser() hydra_parser;
313
+
314
+ state start {
315
+ transition parse_ethernet;
316
+ }
317
+
318
+ state parse_ethernet {
319
+ packet.extract(hdr.ethernet);
320
+ transition parse_hydra_or_eth_type;
321
+ }
322
+
323
+ state parse_hydra_or_eth_type {
324
+ transition select(packet.lookahead<bit<16>>()) {
325
+ TYPE_HYDRA: parse_hydra_headers;
326
+ default: parse_srcRouting_first;
327
+ }
328
+ }
329
+
330
+ state parse_hydra_headers {
331
+ hydra_parser.apply(packet, hdr.hydra_header, meta.hydra_metadata);
332
+ transition parse_srcRouting_first;
333
+ }
334
+
335
+ state parse_srcRouting_first {
336
+ transition select(hdr.ethernet.etherType) {
337
+ TYPE_SRCROUTING: parse_srcRouting;
338
+ default: accept;
339
+ }
340
+ }
341
+
342
+ state parse_srcRouting {
343
+ packet.extract(hdr.srcRoutes.next);
344
+ transition select(hdr.srcRoutes.last.bos) {
345
+ 1: parse_ipv4;
346
+ default: parse_srcRouting;
347
+ }
348
+ }
349
+
350
+ state parse_ipv4 {
351
+ packet.extract(hdr.ipv4);
352
+ transition accept;
353
+ }
354
+
355
+ }
356
+
357
+
358
+
359
+
360
+ control MyVerifyChecksum(inout headers hdr, inout metadata meta) {
361
+ apply { }
362
+ }
363
+
364
+
365
+
366
+
367
+ control MyIngress(inout headers hdr,
368
+ inout metadata meta,
369
+ inout standard_metadata_t standard_metadata) {
370
+
371
+ action drop() {
372
+ mark_to_drop(standard_metadata);
373
+ }
374
+
375
+ action srcRoute_nhop() {
376
+ standard_metadata.egress_spec = (bit<9>)hdr.srcRoutes[0].port;
377
+ hdr.srcRoutes.pop_front(1);
378
+ }
379
+
380
+ action srcRoute_finish() {
381
+ hdr.ethernet.etherType = TYPE_IPV4;
382
+ }
383
+
384
+ action update_ttl(){
385
+ hdr.ipv4.ttl = hdr.ipv4.ttl - 1;
386
+ }
387
+
388
+ action set_first_hop() {
389
+ meta.first_hop = true;
390
+ }
391
+
392
+ table tb_check_first_hop {
393
+ key = {
394
+ standard_metadata.ingress_port: exact;
395
+ }
396
+ actions = {
397
+ @defaultonly NoAction;
398
+ set_first_hop;
399
+ }
400
+ const default_action = NoAction();
401
+ size = 512;
402
+ }
403
+
404
+ apply {
405
+
406
+ tb_check_first_hop.apply();
407
+ if (meta.first_hop) {
408
+ initControl.apply(hdr.ipv4, hdr.hydra_header, meta.hydra_metadata);
409
+ }
410
+
411
+ if (hdr.srcRoutes[0].isValid()){
412
+ if (hdr.srcRoutes[0].bos == 1){
413
+ srcRoute_finish();
414
+ }
415
+ srcRoute_nhop();
416
+ if (hdr.ipv4.isValid()){
417
+ update_ttl();
418
+ }
419
+ }else{
420
+ drop();
421
+ }
422
+ }
423
+ }
424
+
425
+
426
+
427
+ control MyEgress(inout headers hdr,
428
+ inout metadata meta,
429
+ inout standard_metadata_t standard_metadata) {
430
+ action set_last_hop() {
431
+ meta.last_hop = true;
432
+ }
433
+
434
+ table tb_check_last_hop {
435
+ key = {
436
+ standard_metadata.egress_port: exact;
437
+ }
438
+ actions = {
439
+ @defaultonly NoAction;
440
+ set_last_hop;
441
+ }
442
+ const default_action = NoAction();
443
+ size = 512;
444
+ }
445
+
446
+ apply {
447
+ telemetryControl.apply(hdr.hydra_header, meta.hydra_metadata);
448
+ tb_check_last_hop.apply();
449
+ if (meta.last_hop) {
450
+ checkerControl.apply(hdr.hydra_header, meta.hydra_metadata);
451
+ }
452
+ if (meta.hydra_metadata.reject0) {
453
+ mark_to_drop(standard_metadata);
454
+ }
455
+ }
456
+ }
457
+
458
+
459
+
460
+ control MyComputeChecksum(inout headers hdr, inout metadata meta) {
461
+ apply { }
462
+ }
463
+
464
+
465
+
466
+ control MyDeparser(packet_out packet, in headers hdr) {
467
+
468
+ CheckerHeaderDeparser() hydra_deparser;
469
+
470
+ apply {
471
+ packet.emit(hdr.ethernet);
472
+ hydra_deparser.apply(packet, hdr.hydra_header);
473
+ packet.emit(hdr.srcRoutes);
474
+ packet.emit(hdr.ipv4);
475
+ }
476
+ }
477
+
478
+
479
+
480
+ V1Switch(
481
+ MyParser(),
482
+ MyVerifyChecksum(),
483
+ MyIngress(),
484
+ MyEgress(),
485
+ MyComputeChecksum(),
486
+ MyDeparser()
487
+ ) main;
individual_files/000048__raw-repositories__cslev__p4.p4 ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <core.p4>
2
+ #include <v1model.p4>
3
+
4
+
5
+
6
+
7
+ typedef bit<9> egressSpec_t;
8
+ typedef bit<48> macAddr_t;
9
+
10
+ header ethernet_t {
11
+ macAddr_t dstAddr;
12
+ macAddr_t srcAddr;
13
+ bit<16> etherType;
14
+ }
15
+
16
+ struct metadata {
17
+
18
+ /* empty */
19
+ }
20
+
21
+ struct headers {
22
+ ethernet_t ethernet;
23
+ }
24
+
25
+
26
+
27
+ parser MyParser(packet_in packet,
28
+ out headers hdr,
29
+ inout metadata meta,
30
+ inout standard_metadata_t standard_metadata) {
31
+
32
+ state start {
33
+ packet.extract(hdr.ethernet);
34
+ transition accept;
35
+ }
36
+
37
+ }
38
+
39
+
40
+
41
+
42
+ control MyVerifyChecksum(inout headers hdr, inout metadata meta) {
43
+ apply { }
44
+ }
45
+
46
+
47
+
48
+
49
+ control MyIngress(inout headers hdr,
50
+ inout metadata meta,
51
+ inout standard_metadata_t standard_metadata) {
52
+ action drop() {
53
+ mark_to_drop(standard_metadata);
54
+ }
55
+
56
+ action portfwd(egressSpec_t port) {
57
+ standard_metadata.egress_spec = port;
58
+ }
59
+
60
+
61
+ table port_exact {
62
+ key = {
63
+ standard_metadata.ingress_port: exact;
64
+ }
65
+ actions = {
66
+ portfwd;
67
+ drop;
68
+ }
69
+ size = 10;
70
+ default_action = drop;
71
+ }
72
+
73
+
74
+ apply {
75
+ port_exact.apply();
76
+
77
+ }
78
+ }
79
+
80
+
81
+
82
+ control MyEgress(inout headers hdr,
83
+ inout metadata meta,
84
+ inout standard_metadata_t standard_metadata) {
85
+ apply { }
86
+ }
87
+
88
+
89
+
90
+ control MyComputeChecksum(inout headers hdr, inout metadata meta) {
91
+ apply { }
92
+
93
+ }
94
+
95
+
96
+
97
+
98
+ control MyDeparser(packet_out packet, in headers hdr) {
99
+ apply {
100
+ packet.emit(hdr.ethernet);
101
+
102
+ }
103
+ }
104
+
105
+
106
+
107
+ V1Switch(
108
+ MyParser(),
109
+ MyVerifyChecksum(),
110
+ MyIngress(),
111
+ MyEgress(),
112
+ MyComputeChecksum(),
113
+ MyDeparser()
114
+ ) main;
individual_files/000049__raw-repositories__dcomp-leris__VR-AR-CG-network-telemetry.p4 ADDED
@@ -0,0 +1,252 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <core.p4>
2
+ #include <v1model.p4>
3
+
4
+ const bit<16> TYPE_IPV4 = 0x0800;
5
+ const bit<8> IP_PROTO = 253;
6
+
7
+
8
+ #define PKT_INSTANCE_TYPE_NORMAL 0
9
+ #define PKT_INSTANCE_TYPE_INGRESS_CLONE 1
10
+ #define PKT_INSTANCE_TYPE_EGRESS_CLONE 2
11
+ #define PKT_INSTANCE_TYPE_COALESCED 3
12
+ #define PKT_INSTANCE_TYPE_INGRESS_RECIRC 4
13
+
14
+
15
+ #define MAX_HOPS 10
16
+
17
+
18
+
19
+ typedef bit<9> egressSpec_t;
20
+ typedef bit<48> macAddr_t;
21
+ typedef bit<32> ip4Addr_t;
22
+
23
+ typedef bit<31> switchID_v;
24
+ typedef bit<9> ingress_port_v;
25
+ typedef bit<9> egress_port_v;
26
+ typedef bit<9> egressSpec_v;
27
+ typedef bit<48> ingress_global_timestamp_v;
28
+ typedef bit<48> egress_global_timestamp_v;
29
+ typedef bit<32> enq_timestamp_v;
30
+ typedef bit<19> enq_qdepth_v;
31
+ typedef bit<32> deq_timedelta_v;
32
+ typedef bit<19> deq_qdepth_v;
33
+
34
+ header ethernet_t {
35
+ macAddr_t dstAddr;
36
+ macAddr_t srcAddr;
37
+ bit<16> etherType;
38
+ }
39
+
40
+ header ipv4_t {
41
+ bit<4> version;
42
+ bit<4> ihl;
43
+ bit<8> diffserv;
44
+ bit<16> totalLen;
45
+ bit<16> identification;
46
+ bit<3> flags;
47
+ bit<13> fragOffset;
48
+ bit<8> ttl;
49
+ bit<8> protocol;
50
+ bit<16> hdrChecksum;
51
+ ip4Addr_t srcAddr;
52
+ ip4Addr_t dstAddr;
53
+ }
54
+
55
+ header nodeCount_h{
56
+ bit<16> count;
57
+ }
58
+
59
+ header InBandNetworkTelemetry_h {
60
+ switchID_v swid;
61
+ ingress_port_v ingress_port;
62
+ egress_port_v egress_port;
63
+ egressSpec_v egress_spec;
64
+ ingress_global_timestamp_v ingress_global_timestamp;
65
+ egress_global_timestamp_v egress_global_timestamp;
66
+ enq_timestamp_v enq_timestamp;
67
+ enq_qdepth_v enq_qdepth;
68
+ deq_timedelta_v deq_timedelta;
69
+ deq_qdepth_v deq_qdepth;
70
+ }
71
+
72
+
73
+ struct ingress_metadata_t {
74
+ bit<16> count;
75
+ }
76
+
77
+ struct parser_metadata_t {
78
+ bit<16> remaining;
79
+ }
80
+
81
+
82
+ struct metadata {
83
+ ingress_metadata_t ingress_metadata;
84
+ parser_metadata_t parser_metadata;
85
+ }
86
+
87
+ struct headers {
88
+ ethernet_t ethernet;
89
+ ipv4_t ipv4;
90
+ nodeCount_h nodeCount;
91
+ InBandNetworkTelemetry_h[MAX_HOPS] INT;
92
+ }
93
+
94
+
95
+
96
+ parser MyParser(packet_in packet,
97
+ out headers hdr,
98
+ inout metadata meta,
99
+ inout standard_metadata_t standard_metadata) {
100
+
101
+ state start {
102
+ packet.extract(hdr.ethernet);
103
+ transition select(hdr.ethernet.etherType) {
104
+ TYPE_IPV4: parse_ipv4;
105
+ default: accept;
106
+ }
107
+ }
108
+
109
+ state parse_ipv4 {
110
+ packet.extract(hdr.ipv4);
111
+ transition select(hdr.ipv4.protocol) {
112
+ IP_PROTO: parse_count;
113
+ default: accept;
114
+ }
115
+ }
116
+
117
+ state parse_count{
118
+ packet.extract(hdr.nodeCount);
119
+ meta.parser_metadata.remaining = hdr.nodeCount.count;
120
+ transition select(meta.parser_metadata.remaining) {
121
+ 0 : accept;
122
+ default: parse_int;
123
+ }
124
+ }
125
+
126
+ state parse_int {
127
+ packet.extract(hdr.INT.next);
128
+ meta.parser_metadata.remaining = meta.parser_metadata.remaining - 1;
129
+ transition select(meta.parser_metadata.remaining) {
130
+ 0 : accept;
131
+ default: parse_int;
132
+ }
133
+ }
134
+ }
135
+
136
+
137
+
138
+
139
+ control MyVerifyChecksum(inout headers hdr, inout metadata meta) {
140
+ apply { }
141
+ }
142
+
143
+
144
+
145
+
146
+ control MyIngress(inout headers hdr,
147
+ inout metadata meta,
148
+ inout standard_metadata_t standard_metadata) {
149
+
150
+ action drop() {
151
+ mark_to_drop(standard_metadata);
152
+ }
153
+
154
+ action send_back() {
155
+ standard_metadata.egress_spec = standard_metadata.ingress_port;
156
+ bit<48> tmp_mac;
157
+ bit<32> tmp_ip;
158
+
159
+ tmp_mac = hdr.ethernet.srcAddr;
160
+ hdr.ethernet.srcAddr = hdr.ethernet.dstAddr;
161
+ hdr.ethernet.dstAddr = tmp_mac;
162
+
163
+ tmp_ip = hdr.ipv4.srcAddr;
164
+ hdr.ipv4.srcAddr = hdr.ipv4.dstAddr;
165
+ hdr.ipv4.dstAddr = tmp_ip;
166
+ }
167
+
168
+ apply {
169
+ if (hdr.nodeCount.isValid() && standard_metadata.instance_type == PKT_INSTANCE_TYPE_INGRESS_RECIRC) {
170
+ send_back();
171
+ } else {
172
+ standard_metadata.egress_spec = (standard_metadata.ingress_port+1)%2;
173
+ }
174
+
175
+ }
176
+ }
177
+
178
+
179
+
180
+ control MyEgress(inout headers hdr,
181
+ inout metadata meta,
182
+ inout standard_metadata_t standard_metadata) {
183
+
184
+ action my_recirculate() {
185
+ recirculate_preserving_field_list(0);
186
+ }
187
+
188
+ action add_swtrace() {
189
+ hdr.nodeCount.count = hdr.nodeCount.count + 1;
190
+ hdr.INT.push_front(1);
191
+ hdr.INT[0].setValid();
192
+
193
+ //1 para downlink, 2 para uplink
194
+ if (hdr.nodeCount.count == 2){
195
+ hdr.INT[0].swid = 1;
196
+ } else {
197
+ hdr.INT[0].swid = 2;
198
+ }
199
+ hdr.INT[0].ingress_port = (ingress_port_v)standard_metadata.ingress_port;
200
+ hdr.INT[0].egress_port = (egress_port_v)standard_metadata.egress_port;
201
+ hdr.INT[0].egress_spec = (egressSpec_v)standard_metadata.egress_spec;
202
+ hdr.INT[0].ingress_global_timestamp = (ingress_global_timestamp_v)standard_metadata.ingress_global_timestamp;
203
+ hdr.INT[0].egress_global_timestamp = (egress_global_timestamp_v)standard_metadata.egress_global_timestamp;
204
+ hdr.INT[0].enq_timestamp = (enq_timestamp_v)standard_metadata.enq_timestamp;
205
+ hdr.INT[0].enq_qdepth = (enq_qdepth_v)standard_metadata.enq_qdepth;
206
+ hdr.INT[0].deq_timedelta = (deq_timedelta_v)standard_metadata.deq_timedelta;
207
+ hdr.INT[0].deq_qdepth = (deq_qdepth_v)standard_metadata.deq_qdepth;
208
+
209
+ hdr.ipv4.totalLen = hdr.ipv4.totalLen + 32;
210
+
211
+ }
212
+
213
+ apply {
214
+
215
+ if (hdr.nodeCount.isValid()) {
216
+ add_swtrace();
217
+ if (hdr.nodeCount.count < 2){
218
+ my_recirculate();
219
+ }
220
+ }
221
+ }
222
+ }
223
+
224
+
225
+
226
+ control MyComputeChecksum(inout headers hdr, inout metadata meta) {
227
+ apply {
228
+ }
229
+ }
230
+
231
+
232
+
233
+
234
+ control MyDeparser(packet_out packet, in headers hdr) {
235
+ apply {
236
+ packet.emit(hdr.ethernet);
237
+ packet.emit(hdr.ipv4);
238
+ packet.emit(hdr.nodeCount);
239
+ packet.emit(hdr.INT);
240
+ }
241
+ }
242
+
243
+
244
+
245
+ V1Switch(
246
+ MyParser(),
247
+ MyVerifyChecksum(),
248
+ MyIngress(),
249
+ MyEgress(),
250
+ MyComputeChecksum(),
251
+ MyDeparser()
252
+ ) main;
individual_files/000050__raw-repositories__DETERMINISTIC6G__det6g-blog-prog-soft-tsn-switch.p4 ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <core.p4>
2
+ #include <v1model.p4>
3
+
4
+ const bit<16> TYPE_IPV4 = 0x0800;
5
+ const bit<16> TYPE_VLAN = 0x8100;
6
+
7
+ const bit<8> TYPE_UDP = 0x11;
8
+
9
+ typedef bit<48> macAddr_t;
10
+ typedef bit<32> ip4Addr_t;
11
+
12
+ header ethernet_t {
13
+ macAddr_t dstAddr;
14
+ macAddr_t srcAddr;
15
+ bit<16> etherType;
16
+ }
17
+
18
+ header vlan_h {
19
+ bit<3> pcp;
20
+ bit<1> dei;
21
+ bit<12> vid;
22
+ bit<16> etherType;
23
+ }
24
+
25
+
26
+ header ipv4_t {
27
+ bit<4> version;
28
+ bit<4> ihl;
29
+ bit<8> diffserv;
30
+ bit<16> totalLen;
31
+ bit<16> identification;
32
+ bit<3> flags;
33
+ bit<13> fragOffset;
34
+ bit<8> ttl;
35
+ bit<8> protocol;
36
+ bit<16> hdrChecksum;
37
+ ip4Addr_t srcAddr;
38
+ ip4Addr_t dstAddr;
39
+ }
40
+
41
+ header udp_t {
42
+ bit<16> srcPort;
43
+ bit<16> dstPort;
44
+ bit<16> udpTotalLen;
45
+ bit<16> checksum;
46
+ }
47
+
48
+ struct metadata {
49
+
50
+ /* empty */
51
+ }
52
+
53
+ struct headers {
54
+ ethernet_t ethernet;
55
+ vlan_h vlan;
56
+ ipv4_t ipv4;
57
+ udp_t udp;
58
+ }
59
+
60
+ parser myParser(packet_in packet, out headers hdr,
61
+ inout metadata meta, inout standard_metadata_t std_data) {
62
+
63
+ state start {
64
+
65
+ packet.extract(hdr.ethernet);
66
+ transition select(hdr.ethernet.etherType){
67
+ TYPE_VLAN: parse_vlan;
68
+ TYPE_IPV4: parse_ipv4;
69
+ default: accept;
70
+ }
71
+ }
72
+
73
+ state parse_vlan {
74
+ packet.extract(hdr.vlan);
75
+ transition select(hdr.vlan.etherType){
76
+ TYPE_IPV4: parse_ipv4;
77
+ default: accept;
78
+ }
79
+ }
80
+
81
+ state parse_ipv4 {
82
+ packet.extract(hdr.ipv4);
83
+ transition select(hdr.ipv4.protocol) {
84
+ TYPE_UDP: parse_udp;
85
+ default : accept;
86
+ }
87
+ }
88
+ state parse_udp {
89
+ packet.extract(hdr.udp);
90
+ transition accept;
91
+ }
92
+ }
93
+
94
+
95
+ control myVerifyChecksum(inout headers hdr, inout metadata meta) {
96
+ apply { }
97
+ }
98
+
99
+ control myIngress(inout headers hdr, inout metadata meta,
100
+ inout standard_metadata_t std_data) {
101
+ apply {
102
+
103
+ // naif routing
104
+ if( std_data.ingress_port == 1 )
105
+ std_data.egress_spec = 2;
106
+ else
107
+ std_data.egress_spec = 1;
108
+ }
109
+ }
110
+
111
+
112
+
113
+ register <bit<48>>(1) last_tc0_packet_ts;
114
+
115
+ control myEgress(inout headers hdr, inout metadata meta,
116
+ inout standard_metadata_t std_data) {
117
+ bit<48> ts;
118
+ bit<48> last_ts;
119
+ apply {
120
+
121
+ //enable VLAN if it is not existing
122
+ if( ! hdr.vlan.isValid() ){
123
+ hdr.vlan.setValid();
124
+ hdr.vlan.etherType = hdr.ethernet.etherType;
125
+ hdr.ethernet.etherType = TYPE_VLAN;
126
+ }
127
+
128
+ @atomic {
129
+
130
+ //get ingress timestamp (in microsecond) of the current packet
131
+ ts = std_data.ingress_global_timestamp;
132
+
133
+ //dynamically adjust VLAN PCP
134
+ if( hdr.udp.isValid() && hdr.udp.dstPort == 1000 ){
135
+ hdr.vlan.pcp = 0;
136
+
137
+ last_tc0_packet_ts.write( 0, ts);
138
+ } else {
139
+
140
+ // get the timestamp from the first element of the array
141
+ last_tc0_packet_ts.read( last_ts, 0 );
142
+ if( ts - last_ts > 1*1000*1000 )
143
+ hdr.vlan.pcp = 0;
144
+ else
145
+ hdr.vlan.pcp = 1;
146
+ }
147
+ }
148
+ }
149
+ }
150
+
151
+ control myComputeChecksum(inout headers hdr, inout metadata meta) {
152
+ apply {}
153
+ }
154
+
155
+ control myDeparser(packet_out packet, in headers hdr) {
156
+ apply {
157
+ packet.emit(hdr.ethernet);
158
+ packet.emit(hdr.vlan);
159
+ packet.emit(hdr.ipv4);
160
+ packet.emit(hdr.udp);
161
+ }
162
+ }
163
+
164
+
165
+ //switch architecture
166
+ V1Switch(
167
+ myParser(), myVerifyChecksum(), myIngress(), myEgress(), myComputeChecksum(), myDeparser()
168
+ ) main;
individual_files/000051__raw-repositories__emdneto__dh-aes-p4.p4 ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Standard headers
2
+ #include <core.p4>
3
+ #include <v1model.p4>
4
+
5
+
6
+
7
+ // useful for DH
8
+ typedef bit<256> keys_t;
9
+ typedef bit<48> macAddr_t;
10
+
11
+ header ethernet_t {
12
+ macAddr_t dstAddr;
13
+ macAddr_t srcAddr;
14
+ bit<16> etherType;
15
+ }
16
+
17
+ header ipv4_t {
18
+ bit<4> version;
19
+ bit<4> ihl;
20
+ bit<8> diffserv;
21
+ bit<16> totalLen;
22
+ bit<16> identification;
23
+ bit<3> flags;
24
+ bit<13> fragOffset;
25
+ bit<8> ttl;
26
+ bit<8> protocol;
27
+ bit<16> hdrChecksum;
28
+ macAddr_t srcAddr;
29
+ macAddr_t dstAddr;
30
+ }
31
+
32
+ header tcp_t{
33
+ bit<16> srcPort;
34
+ bit<16> dstPort;
35
+ bit<32> seqNo;
36
+ bit<32> ackNo;
37
+ bit<4> dataOffset;
38
+ bit<4> res;
39
+ bit<1> cwr;
40
+ bit<1> ece;
41
+ bit<1> urg;
42
+ bit<1> ack;
43
+ bit<1> psh;
44
+ bit<1> rst;
45
+ bit<1> syn;
46
+ bit<1> fin;
47
+ bit<16> window;
48
+ bit<16> checksum;
49
+ bit<16> urgentPtr;
50
+ }
51
+
52
+ #define ETHERTYPE_AES_TOY 0x9999
53
+
54
+ header aes_inout_t {
55
+ bit<128> value;
56
+ }
57
+
58
+ struct my_headers_t {
59
+ ethernet_t ethernet;
60
+ aes_inout_t aes_inout;
61
+ }
62
+
63
+ header aes_meta_t {
64
+
65
+ // internal state, 4 rows
66
+ }
67
+
68
+ header dh_meta_t {
69
+ bit<256> secrect;
70
+ bit<256> pu;
71
+ }
72
+ struct my_metadata_t {
73
+ aes_meta_t aes;
74
+ }
75
+
76
+ parser MyParser(
77
+ packet_in packet,
78
+ out my_headers_t hdr,
79
+ inout my_metadata_t meta,
80
+ inout standard_metadata_t standard_metadata)
81
+ {
82
+ state start {
83
+ packet.extract(hdr.ethernet);
84
+ transition select(hdr.ethernet.etherType) {
85
+ ETHERTYPE_AES_TOY : parse_aes;
86
+ default : accept;
87
+ }
88
+ }
89
+
90
+ state parse_aes {
91
+ packet.extract(hdr.aes_inout);
92
+ transition accept;
93
+ }
94
+ }
95
+
96
+ control MyVerifyChecksum(inout my_headers_t hdr, inout my_metadata_t meta) {
97
+ apply { }
98
+ }
99
+
100
+ control MyIngress(
101
+ inout my_headers_t hdr,
102
+ inout my_metadata_t meta,
103
+ inout standard_metadata_t standard_metadata)
104
+ {
105
+
106
+ action l2_fwd() {
107
+ hdr.aes_inout.setValid();
108
+ }
109
+
110
+ action set_egress_spec(bit<9> port) {
111
+ standard_metadata.egress_spec = port;
112
+ }
113
+
114
+ table forward {
115
+ key = {
116
+ standard_metadata.ingress_port: exact;
117
+ }
118
+ actions = {
119
+ set_egress_spec;
120
+ NoAction;
121
+ }
122
+ size = 1024;
123
+ default_action = NoAction();
124
+ }
125
+
126
+ apply {
127
+
128
+ if (forward.apply().hit) {
129
+
130
+ if (hdr.ethernet.etherType == 0x9999) {
131
+ l2_fwd();
132
+ }
133
+ }
134
+ }
135
+ }
136
+
137
+ control MyEgress(
138
+ inout my_headers_t hdr,
139
+ inout my_metadata_t meta,
140
+ inout standard_metadata_t standard_metadata) {
141
+
142
+ apply {
143
+
144
+ }
145
+ }
146
+
147
+ control MyComputeChecksum(
148
+ inout my_headers_t hdr,
149
+ inout my_metadata_t meta)
150
+ {
151
+ apply { }
152
+ }
153
+
154
+ control MyDeparser(
155
+ packet_out packet,
156
+ in my_headers_t hdr)
157
+ {
158
+
159
+ apply {
160
+ packet.emit(hdr.ethernet);
161
+ packet.emit(hdr.aes_inout);
162
+ }
163
+ }
164
+
165
+ V1Switch(
166
+ MyParser(),
167
+ MyVerifyChecksum(),
168
+ MyIngress(),
169
+ MyEgress(),
170
+ MyComputeChecksum(),
171
+ MyDeparser()
172
+ ) main;
individual_files/000052__raw-repositories__epap011__P4Lang-SimpleLoadBalancer.p4 ADDED
@@ -0,0 +1,416 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <core.p4>
2
+ #include <v1model.p4>
3
+
4
+
5
+
6
+ const bit<16> TYPE_IPV4 = 0x800;
7
+ const bit<16> TYPE_ARP = 0x806;
8
+ const bit<32> serviceIP = 0xa010203;
9
+ const bit<48> lbMAC = 0xa0000000001;
10
+
11
+
12
+
13
+
14
+ /* type definitions for ease of reference */
15
+ typedef bit<9> egressSpec_t;
16
+ typedef bit<48> macAddr_t;
17
+ typedef bit<32> ip4Addr_t;
18
+
19
+
20
+ /* ethernet frame header */
21
+ header ethernet_t {
22
+ macAddr_t dstAddr;
23
+ macAddr_t srcAddr;
24
+ bit<16> etherType;
25
+ }
26
+
27
+
28
+ /* ARP packet header */
29
+ header arp_t {
30
+ bit<16> hwType;
31
+ bit<16> protoType;
32
+ bit<8> hwAddrLen;
33
+ bit<8> protoAddrLen;
34
+ bit<16> opCode;
35
+ macAddr_t hwSrcAddr;
36
+ ip4Addr_t protoSrcAddr;
37
+ macAddr_t hwDstAddr;
38
+ ip4Addr_t protoDstAddr;
39
+ }
40
+
41
+
42
+ /* IP packet header */
43
+ header ipv4_t {
44
+ bit<4> version;
45
+ bit<4> ihl;
46
+ bit<8> diffserv;
47
+ bit<16> totalLen;
48
+ bit<16> identification;
49
+ bit<3> flags;
50
+ bit<13> fragOffset;
51
+ bit<8> ttl;
52
+ bit<8> protocol;
53
+ bit<16> hdrChecksum;
54
+ ip4Addr_t srcAddr;
55
+ ip4Addr_t dstAddr;
56
+ }
57
+
58
+
59
+ /* metadata carried by the packet through the processing pipelines */
60
+ struct metadata {
61
+ macAddr_t dstMAC;
62
+
63
+ // the dst MAC to which the packet should be directed on L2
64
+ bit<1> isClient;
65
+
66
+ // whether the src IP of the packet belongs to a client
67
+ bit<1> isServer;
68
+
69
+ // whether the src IP of the packet belongs to a server
70
+ bit<8> srcGroup;
71
+
72
+ // the group of the src host
73
+ bit<8> dstGroup;
74
+
75
+ // the group of the dst host
76
+ }
77
+
78
+ struct headers {
79
+ ethernet_t ethernet;
80
+ arp_t arp;
81
+ ipv4_t ipv4;
82
+ }
83
+
84
+
85
+
86
+ parser SLBParser(packet_in packet,
87
+ out headers hdr,
88
+ inout metadata meta,
89
+ inout standard_metadata_t standard_metadata) {
90
+
91
+
92
+ /* begin with pointing to Ethernet frame parser */
93
+ state start {
94
+ transition parse_ethernet;
95
+ }
96
+
97
+
98
+ /* parser ethernet frame */
99
+ state parse_ethernet {
100
+
101
+ /* WRITE YOUR CODE HERE */
102
+ packet.extract(hdr.ethernet);
103
+ transition select(hdr.ethernet.etherType) {
104
+ TYPE_ARP: parse_arp;
105
+ TYPE_IPV4: parse_ipv4;
106
+ default:accept;
107
+ }
108
+
109
+ }
110
+
111
+ state parse_arp {
112
+ packet.extract(hdr.arp);
113
+ transition accept;
114
+
115
+ // accept; the ARP packet will be pushed to ingress pipeline
116
+ }
117
+
118
+ state parse_ipv4 {
119
+ packet.extract(hdr.ipv4);
120
+
121
+ // accept; the IP packet will be pushed to ingress pipeline
122
+ transition accept;
123
+ }
124
+
125
+ }
126
+
127
+
128
+
129
+ control SLBVerifyChecksum(inout headers hdr, inout metadata meta) {
130
+ apply { }
131
+ }
132
+
133
+
134
+
135
+
136
+
137
+ control SLBIngress(inout headers hdr,
138
+ inout metadata meta,
139
+ inout standard_metadata_t standard_metadata) {
140
+
141
+
142
+ /* Action that instructs the pipeline to drop a packet */
143
+ action drop() {
144
+ mark_to_drop(standard_metadata);
145
+ }
146
+
147
+
148
+ /* Action that transforms an ARP request into a suitable ARP reply */
149
+ action arp_request_to_reply(macAddr_t srcMAC, macAddr_t dstMAC, ip4Addr_t srcIP, ip4Addr_t dstIP) {
150
+
151
+ /* WRITE YOUR CODE HERE */
152
+ hdr.ethernet.srcAddr = dstMAC;
153
+ hdr.ethernet.dstAddr = srcMAC;
154
+
155
+ hdr.arp.hwSrcAddr = dstMAC;
156
+ hdr.arp.hwDstAddr = srcMAC;
157
+ hdr.arp.protoSrcAddr = dstIP;
158
+ hdr.arp.protoDstAddr = srcIP;
159
+ hdr.arp.opCode = 2;
160
+
161
+ standard_metadata.egress_spec = standard_metadata.ingress_port;
162
+
163
+ // the reply should be sent out of the in-port
164
+ }
165
+
166
+
167
+ action set_egress_metadata(macAddr_t dstMAC, egressSpec_t port) {
168
+ meta.dstMAC = dstMAC;
169
+ standard_metadata.egress_spec = port;
170
+ }
171
+
172
+
173
+ action set_client_metadata(ip4Addr_t firstAllowedReplica, ip4Addr_t lastAllowedReplica) {
174
+ meta.isClient = 1;
175
+ meta.isServer = 0;
176
+
177
+ /* WRITE YOUR CODE HERE */
178
+ random(hdr.ipv4.dstAddr, firstAllowedReplica, lastAllowedReplica);
179
+ }
180
+
181
+
182
+ /* Action that updates metadata with the info that the src IP does not belong to a client */
183
+ action unset_client_metadata() {
184
+ meta.isClient = 0;
185
+ }
186
+
187
+
188
+ /* Action that updates metadata with the info that the src IP belongs to a server */
189
+ action set_server_metadata() {
190
+ meta.isServer = 1;
191
+ meta.isClient = 0;
192
+ }
193
+
194
+
195
+ /* Action that updates metadata with the info that the src IP does not belong to a server */
196
+ action unset_server_metadata() {
197
+ meta.isServer = 0;
198
+ }
199
+
200
+
201
+ /* Action that sets the group membership for a src host */
202
+ action set_src_membership(bit<8> group) {
203
+ meta.srcGroup = group;
204
+ }
205
+
206
+
207
+ /* Action that sets the group membership for a dst host */
208
+ action set_dst_membership(bit<8> group) {
209
+ meta.dstGroup = group;
210
+ }
211
+
212
+
213
+ /* Table that stores the mapping between dst IP and dst MAC and egress port */
214
+ table arpmap {
215
+
216
+ /* WRITE YOUR CODE HERE */
217
+ key = {
218
+ hdr.ipv4.dstAddr: lpm;
219
+ }
220
+ actions = {
221
+ set_egress_metadata;
222
+ }
223
+ }
224
+
225
+
226
+ /* Table that stores the info that a certain IP belongs to a client */
227
+ table ipv4_clients {
228
+ key = {
229
+ hdr.ipv4.srcAddr: lpm;
230
+ }
231
+ actions = {
232
+ set_client_metadata;
233
+ unset_client_metadata;
234
+ }
235
+ }
236
+
237
+
238
+ /* Table that stores the info that a certain IP belongs to a server */
239
+ table ipv4_servers {
240
+
241
+ /* WRITE YOUR CODE HERE */
242
+ key = {
243
+ hdr.ipv4.srcAddr: lpm;
244
+ }
245
+ actions = {
246
+ set_server_metadata;
247
+ unset_server_metadata;
248
+ }
249
+ }
250
+
251
+
252
+ /* Table that stores the info about which src IP is member of which group */
253
+ table src_group_membership {
254
+
255
+ /* WRITE YOUR CODE HERE */
256
+ key = {
257
+ hdr.ipv4.srcAddr: lpm;
258
+ }
259
+ actions = {
260
+ set_src_membership;
261
+ }
262
+ }
263
+
264
+
265
+ /* Table that stores the info about which dst IP is member of which group */
266
+ table dst_group_membership {
267
+
268
+ /* WRITE YOUR CODE HERE */
269
+ key = {
270
+ hdr.ipv4.dstAddr: lpm;
271
+ }
272
+ actions = {
273
+ set_dst_membership;
274
+ }
275
+ }
276
+
277
+
278
+ /* Apply ingress workflow */
279
+ apply {
280
+ if (!(hdr.arp.isValid() || hdr.ipv4.isValid())) {
281
+ drop();
282
+
283
+ // drop irrelevant/invalid traffic
284
+ }
285
+ else if (hdr.arp.isValid() && hdr.arp.opCode == 1) {
286
+
287
+ // handle incoming ARP requests
288
+ /* WRITE YOUR CODE HERE */
289
+ arp_request_to_reply(hdr.ethernet.srcAddr, lbMAC, hdr.arp.protoSrcAddr, hdr.arp.protoDstAddr);
290
+ }
291
+ else if (hdr.ipv4.isValid()) {
292
+
293
+ /* WRITE YOUR CODE HERE */
294
+ ipv4_clients.apply();
295
+ ipv4_servers.apply();
296
+ src_group_membership.apply();
297
+ dst_group_membership.apply();
298
+
299
+ if (!((meta.isClient == 1) || meta.isServer == 1) || meta.srcGroup != meta.dstGroup) {
300
+ drop();
301
+
302
+ // drop if not coming from client or server
303
+ }
304
+
305
+ // of if the src/dst groups differ
306
+ else {
307
+ arpmap.apply();
308
+
309
+ // prepare for egress
310
+ }
311
+ }
312
+ }
313
+ }
314
+
315
+
316
+
317
+ control SLBEgress(inout headers hdr,
318
+ inout metadata meta,
319
+ inout standard_metadata_t standard_metadata) {
320
+
321
+
322
+ /* Action that rewrites the header of client-to-server packets */
323
+ action rewrite_client_to_server() {
324
+
325
+ /* WRITE YOUR CODE HERE */
326
+ hdr.ethernet.srcAddr = lbMAC;
327
+ hdr.ethernet.dstAddr = meta.dstMAC;
328
+ }
329
+
330
+
331
+ /* Action that rewrites the header of server-to-client packets */
332
+ action rewrite_server_to_client() {
333
+
334
+ /* WRITE YOUR CODE HERE */
335
+ hdr.ipv4.srcAddr = serviceIP;
336
+
337
+ hdr.ethernet.srcAddr = lbMAC;
338
+ hdr.ethernet.dstAddr = meta.dstMAC;
339
+ }
340
+
341
+
342
+ /* Apply egress workflow */
343
+ apply {
344
+ if (hdr.ipv4.isValid()) {
345
+
346
+ /* WRITE YOUR CODE HERE */
347
+ if(meta.isClient == 1) {
348
+ rewrite_client_to_server();
349
+ }
350
+ else if(meta.isServer == 1) {
351
+ rewrite_server_to_client();
352
+ }
353
+ }
354
+ }
355
+ }
356
+
357
+
358
+
359
+ control SLBComputeChecksum(inout headers hdr, inout metadata meta) {
360
+ apply {
361
+ update_checksum(
362
+ hdr.ipv4.isValid(),
363
+ { hdr.ipv4.version,
364
+ hdr.ipv4.ihl,
365
+ hdr.ipv4.diffserv,
366
+ hdr.ipv4.totalLen,
367
+ hdr.ipv4.identification,
368
+ hdr.ipv4.flags,
369
+ hdr.ipv4.fragOffset,
370
+ hdr.ipv4.ttl,
371
+ hdr.ipv4.protocol,
372
+ hdr.ipv4.srcAddr,
373
+ hdr.ipv4.dstAddr },
374
+ hdr.ipv4.hdrChecksum,
375
+ HashAlgorithm.csum16);
376
+ }
377
+ }
378
+
379
+
380
+
381
+ control SLBDeparser(packet_out packet, in headers hdr) {
382
+ apply {
383
+ packet.emit(hdr.ethernet);
384
+
385
+ // emit ethernet frame
386
+ packet.emit(hdr.arp);
387
+
388
+ // emit ARP packet
389
+ packet.emit(hdr.ipv4);
390
+
391
+ // emit IP packet
392
+ }
393
+ }
394
+
395
+
396
+
397
+ V1Switch(
398
+ SLBParser(),
399
+
400
+ // parse packet headers
401
+ SLBVerifyChecksum(),
402
+
403
+ // verify thet the packet is valid
404
+ SLBIngress(),
405
+
406
+ // apply ingress logic
407
+ SLBEgress(),
408
+
409
+ // apply egress logic
410
+ SLBComputeChecksum(),
411
+
412
+ // compute the new checksum for the IP packet
413
+ SLBDeparser()
414
+
415
+ // deparse (serialize) the packet
416
+ ) main;
individual_files/000053__raw-repositories__ebiken__p4srv6.p4 ADDED
@@ -0,0 +1,1067 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <core.p4>
2
+ #include <v1model.p4>
3
+
4
+
5
+ #ifdef _V1_MODEL_P4_
6
+ typedef bit<9> PortId_t;
7
+
8
+ #endif /* _V1_MODEL_P4_ */
9
+
10
+
11
+
12
+
13
+
14
+ #ifndef _HEADERS_
15
+ #define _HEADERS_
16
+
17
+
18
+ typedef bit<48> EthernetAddress;
19
+ typedef bit<32> IPv4Address;
20
+ typedef bit<128> IPv6Address;
21
+
22
+ typedef bit<16> EthernetType;
23
+ const EthernetType ETH_P_IPV4 = 16w0x0800;
24
+ const EthernetType ETH_P_ARP = 16w0x0806;
25
+ const EthernetType ETH_P_VLAN = 16w0x8100;
26
+ const EthernetType ETH_P_IPV6 = 16w0x86dd;
27
+
28
+
29
+ typedef bit<8> IPProtocol;
30
+ const IPProtocol IPPROTO_HOPOPT = 0;
31
+
32
+ // IPv6 Hop-by-Hop Option
33
+ const IPProtocol IPPROTO_ICMP = 1;
34
+ const IPProtocol IPPROTO_IPV4 = 4;
35
+ const IPProtocol IPPROTO_TCP = 6;
36
+ const IPProtocol IPPROTO_UDP = 17;
37
+ const IPProtocol IPPROTO_IPV6 = 41;
38
+ const IPProtocol IPPROTO_ROUTE = 43;
39
+
40
+ // Routing Header for IPv6
41
+ const IPProtocol IPPROTO_FRAG = 44;
42
+
43
+ // Fragment Header for IPv6
44
+ const IPProtocol IPPROTO_GRE = 47;
45
+ const IPProtocol IPPROTO_ICMPv6 = 58;
46
+
47
+ // ICMP for IPv6
48
+ const IPProtocol IPPROTO_NONXT = 59;
49
+
50
+ // No Next Header for IPv6
51
+
52
+ typedef bit<16> UDPPort;
53
+ const UDPPort UDP_PORT_GTPC = 2123;
54
+ const UDPPort UDP_PORT_GTPU = 2152;
55
+
56
+ header Ethernet_h {
57
+ EthernetAddress dstAddr;
58
+ EthernetAddress srcAddr;
59
+ EthernetType etherType;
60
+ }
61
+
62
+ header IPv4_h {
63
+ bit<4> version;
64
+ bit<4> ihl;
65
+ bit<8> diffserv;
66
+ bit<16> totalLen;
67
+ bit<16> identification;
68
+ bit<3> flags;
69
+ bit<13> fragOffset;
70
+ bit<8> ttl;
71
+ IPProtocol protocol;
72
+ bit<16> hdrChecksum;
73
+ IPv4Address srcAddr;
74
+ IPv4Address dstAddr;
75
+ }
76
+
77
+ header IPv6_h {
78
+ bit<4> version;
79
+ bit<8> trafficClass;
80
+ bit<20> flowLabel;
81
+ bit<16> payloadLen;
82
+ bit<8> nextHdr;
83
+ bit<8> hopLimit;
84
+ IPv6Address srcAddr;
85
+ IPv6Address dstAddr;
86
+ }
87
+
88
+ header TCP_h {
89
+ bit<16> srcPort;
90
+ bit<16> dstPort;
91
+ bit<32> seq;
92
+ bit<32> ack;
93
+ bit<4> dataOffset;
94
+ bit<4> res;
95
+ bit<8> flags;
96
+ bit<16> window;
97
+ bit<16> checksum;
98
+ bit<16> urgentPtr;
99
+ }
100
+
101
+ header UDP_h {
102
+ bit<16> srcPort;
103
+ bit<16> dstPort;
104
+ bit<16> length;
105
+ bit<16> checksum;
106
+ }
107
+
108
+ header ICMP_h {
109
+ bit<8> type;
110
+ bit<8> code;
111
+ bit<16> hdrChecksum;
112
+ bit<32> restOfHeader;
113
+
114
+ }
115
+
116
+
117
+ header SRH_h {
118
+ bit<8> nextHdr;
119
+ bit<8> hdrExtLen;
120
+ bit<8> routingType;
121
+ bit<8> segmentsLeft;
122
+ bit<8> lastEntry;
123
+ bit<8> flags;
124
+ bit<12> tag;
125
+ bit<4> gtpMessageType;
126
+
127
+ // least significant 4 bits of tag field
128
+ }
129
+
130
+ header SRH_SegmentList_h {
131
+ bit<128> sid;
132
+ }
133
+
134
+
135
+ typedef bit<8> GTPv1Type;
136
+ const GTPv1Type GTPV1_ECHO = 1;
137
+
138
+ // Echo Request
139
+ const GTPv1Type GTPV1_ECHORES = 2;
140
+
141
+ // Echo Response
142
+ const GTPv1Type GTPV1_ERROR = 26;
143
+
144
+ // Error Indication
145
+ const GTPv1Type GTPV1_END = 254;
146
+
147
+ // End Marker
148
+ const GTPv1Type GTPV1_GPDU = 255;
149
+
150
+ // G-PDU
151
+
152
+
153
+ // 3GPP TS 29.060 V15.3.0 (2018-12) "6 GTP Header"
154
+ header GTPU_h {
155
+ bit<3> version;
156
+
157
+ // Version field: always 1 for GTPv1
158
+ bit<1> pt;
159
+
160
+ // Protocol Type (PT): GTP(1), GTP'(0)
161
+ bit<1> reserved;
162
+
163
+ // always zero (0)
164
+ bit<1> e;
165
+
166
+ // Extension Header flag (E)
167
+ bit<1> s;
168
+
169
+ // Sequence number flag (S): not present(0), present(1)
170
+ bit<1> pn;
171
+
172
+ // N-PDU Number flag (PN)
173
+ GTPv1Type messageType;
174
+ bit<16> messageLen;
175
+ bit<32> teid;
176
+
177
+ bit<16> seq;
178
+
179
+ // Sequence Number
180
+ bit<8> npdu;
181
+
182
+ // N-PDU number
183
+ bit<8> nextExtHdr;
184
+
185
+ // Next Extention Header Type
186
+ }
187
+
188
+
189
+
190
+ #endif /* _HEADERS_ */
191
+
192
+
193
+ #define SRH_SID_MAX 4
194
+
195
+ // Max number of SIDs in SRH Segment List
196
+ struct Header {
197
+ Ethernet_h ether;
198
+ IPv6_h ipv6;
199
+ SRH_h srh;
200
+ SRH_SegmentList_h[SRH_SID_MAX] srh_sid;
201
+
202
+ IPv4_h ipv4;
203
+ ICMP_h icmp;
204
+ TCP_h tcp;
205
+ UDP_h udp;
206
+ GTPU_h gtpu;
207
+
208
+ // inner headers
209
+ Ethernet_h inner_ether;
210
+ IPv6_h inner_ipv6;
211
+ IPv4_h inner_ipv4;
212
+
213
+ TCP_h inner_tcp;
214
+ UDP_h inner_udp;
215
+ }
216
+
217
+
218
+
219
+
220
+ // Generic ingress metadata (architecture independent)
221
+ struct IngressMetadata {
222
+
223
+ // none defined yet
224
+ }
225
+
226
+ // Generic egress metadata (architecture independent)
227
+ struct EgressMetadata {
228
+
229
+ }
230
+ struct SRv6Metadata {
231
+ bit<128> nextsid;
232
+ bit<4> gtp_message_type;
233
+
234
+ bit<8> gtpv1_type;
235
+
236
+ }
237
+
238
+ // User Metadata (for v1model)
239
+ struct UserMetadata {
240
+ IngressMetadata ig_md;
241
+ EgressMetadata eg_md;
242
+ SRv6Metadata srv6;
243
+ }
244
+
245
+
246
+
247
+
248
+ #ifndef _PARSER_
249
+ #define _PARSER_
250
+
251
+
252
+
253
+ parser SwitchParser(
254
+ packet_in pkt,
255
+ out Header hdr,
256
+ inout UserMetadata user_md,
257
+ inout standard_metadata_t st_md) {
258
+
259
+ state start {
260
+ transition parse_ethernet;
261
+ }
262
+ state parse_ethernet {
263
+ pkt.extract(hdr.ether);
264
+ transition select(hdr.ether.etherType) {
265
+ ETH_P_IPV4 : parse_ipv4;
266
+ ETH_P_IPV6 : parse_ipv6;
267
+
268
+ default : accept;
269
+ }
270
+ }
271
+ state parse_ipv4 {
272
+ pkt.extract(hdr.ipv4);
273
+ transition select(hdr.ipv4.protocol) {
274
+ IPPROTO_TCP : parse_tcp;
275
+ IPPROTO_UDP : parse_udp;
276
+ default : accept;
277
+ }
278
+ }
279
+ state parse_ipv6 {
280
+ pkt.extract(hdr.ipv6);
281
+ transition select(hdr.ipv6.nextHdr) {
282
+ IPPROTO_TCP : parse_tcp;
283
+ IPPROTO_UDP : parse_udp;
284
+ IPPROTO_ROUTE : parse_srh;
285
+ IPPROTO_IPV4 : parse_inner_ipv4;
286
+ IPPROTO_IPV6 : parse_inner_ipv6;
287
+ default : accept;
288
+ }
289
+ }
290
+ state parse_tcp {
291
+ pkt.extract(hdr.tcp);
292
+ transition accept;
293
+ }
294
+ state parse_udp {
295
+ pkt.extract(hdr.udp);
296
+ transition select(hdr.udp.dstPort) {
297
+ UDP_PORT_GTPU: parse_gtpu;
298
+ default: accept;
299
+ }
300
+ }
301
+ state parse_gtpu {
302
+ pkt.extract(hdr.gtpu);
303
+ user_md.srv6.gtpv1_type = hdr.gtpu.messageType;
304
+ bit<4> ip_ver = pkt.lookahead<bit<4>>();
305
+ transition select(ip_ver) {
306
+ 4w4 : parse_inner_ipv4;
307
+ 4w6 : parse_inner_ipv6;
308
+ default : parse_inner_ether;
309
+ }
310
+ }
311
+ state parse_inner_ipv4 {
312
+ pkt.extract(hdr.inner_ipv4);
313
+ transition select(hdr.inner_ipv4.protocol) {
314
+ IPPROTO_TCP : parse_inner_tcp;
315
+ IPPROTO_UDP : parse_inner_udp;
316
+ default : accept;
317
+ }
318
+ }
319
+ state parse_inner_ipv6 {
320
+ pkt.extract(hdr.inner_ipv6);
321
+ transition select(hdr.inner_ipv6.nextHdr) {
322
+ IPPROTO_TCP : parse_inner_tcp;
323
+ IPPROTO_UDP : parse_inner_udp;
324
+ default : accept;
325
+ }
326
+ }
327
+ state parse_inner_ether {
328
+ pkt.extract(hdr.inner_ether);
329
+ transition accept;
330
+ }
331
+
332
+ /*** PARSE SRH (SRv6) ***/
333
+ state parse_srh {
334
+ pkt.extract(hdr.srh);
335
+ user_md.srv6.gtp_message_type = hdr.srh.gtpMessageType;
336
+ transition parse_srh_sid_0;
337
+ }
338
+ #define PARSE_SRH_SID(curr, next) \
339
+ state parse_srh_sid_##curr { \
340
+ pkt.extract(hdr.srh_sid[curr]); \
341
+ transition select(hdr.srh.lastEntry) { \
342
+ curr : parse_srh_next_header; \
343
+ default : parse_srh_sid_##next; \
344
+ } \
345
+ } \
346
+
347
+ PARSE_SRH_SID(0, 1)
348
+ PARSE_SRH_SID(1, 2)
349
+ PARSE_SRH_SID(2, 3)
350
+ state parse_srh_sid_3 {
351
+ pkt.extract(hdr.srh_sid[3]);
352
+ transition select(hdr.srh.lastEntry) {
353
+ 3 : parse_srh_next_header;
354
+
355
+ // v1model: no default rule: all other packets rejected
356
+ #ifndef _V1_MODEL_P4_
357
+ default : reject;
358
+
359
+ // Too many SIDs
360
+ #endif /* _V1_MODEL_P4_ */
361
+ }
362
+ }
363
+ state parse_srh_next_header {
364
+ transition select(hdr.srh.nextHdr) {
365
+ IPPROTO_TCP : parse_tcp;
366
+ IPPROTO_UDP : parse_udp;
367
+ IPPROTO_IPV4 : parse_inner_ipv4;
368
+ IPPROTO_IPV6 : parse_inner_ipv6;
369
+ default : accept;
370
+ }
371
+ }
372
+ state parse_inner_udp {
373
+ pkt.extract(hdr.inner_udp);
374
+ transition accept;
375
+ }
376
+ state parse_inner_tcp {
377
+ pkt.extract(hdr.inner_tcp);
378
+ transition accept;
379
+ }
380
+ }
381
+
382
+
383
+
384
+
385
+ control SwitchDeparser(
386
+ packet_out pkt,
387
+ in Header hdr) {
388
+
389
+ apply {
390
+ pkt.emit(hdr.ether);
391
+ pkt.emit(hdr.ipv6);
392
+ pkt.emit(hdr.srh);
393
+ pkt.emit(hdr.srh_sid);
394
+ pkt.emit(hdr.ipv4);
395
+
396
+ pkt.emit(hdr.tcp);
397
+ pkt.emit(hdr.udp);
398
+ pkt.emit(hdr.gtpu);
399
+ pkt.emit(hdr.inner_ether);
400
+ pkt.emit(hdr.inner_ipv6);
401
+ pkt.emit(hdr.inner_ipv4);
402
+ pkt.emit(hdr.inner_tcp);
403
+ pkt.emit(hdr.inner_udp);
404
+ }
405
+ }
406
+ #endif /* _PARSER_ */
407
+
408
+
409
+
410
+ #ifndef _SRV6_
411
+ #define _SRV6_
412
+
413
+ control SRv6(
414
+ inout Header hdr,
415
+ inout UserMetadata user_md,
416
+ in PortId_t in_port,
417
+ inout PortId_t egress_port) {
418
+
419
+
420
+ // Counters for actions in transit and end (localsid) behaviors.
421
+ #ifdef _V1_MODEL_P4_
422
+
423
+ // see v1model.p4 for counter definitions.
424
+ direct_counter(CounterType.packets_and_bytes) cnt_srv6_t_v4;
425
+ direct_counter(CounterType.packets_and_bytes) cnt_srv6_t_v6;
426
+ direct_counter(CounterType.packets_and_bytes) cnt_srv6_t_udp;
427
+ direct_counter(CounterType.packets_and_bytes) cnt_srv6_e;
428
+ direct_counter(CounterType.packets_and_bytes) cnt_srv6_e_iif;
429
+ #endif /* _V1_MODEL_P4_ */
430
+
431
+
432
+ /*** HELPER ACTIONS */
433
+ action remove_srh_header() {
434
+ hdr.srh.setInvalid();
435
+
436
+ hdr.srh_sid[0].setInvalid();
437
+ hdr.srh_sid[1].setInvalid();
438
+ hdr.srh_sid[2].setInvalid();
439
+ hdr.srh_sid[3].setInvalid();
440
+ hdr.srh.setInvalid();
441
+ }
442
+
443
+
444
+ /*** HELPER ACTIONS : PUSH SRH/SID */
445
+ action push_srh(bit<8> nextHdr, bit<8> hdrExtLen, bit<8> segmentsLeft, bit<8> lastEntry) {
446
+ hdr.srh.setValid();
447
+ hdr.srh.nextHdr = nextHdr;
448
+ hdr.srh.hdrExtLen = hdrExtLen;
449
+ hdr.srh.routingType = 4;
450
+
451
+ // TBD, to be assigned by IANA (suggested value: 4)
452
+ hdr.srh.segmentsLeft = segmentsLeft;
453
+ hdr.srh.lastEntry = lastEntry;
454
+ hdr.srh.flags = 0;
455
+ hdr.srh.tag = 0;
456
+ }
457
+ action push_srh_sid1(
458
+ bit<8> nextHdr,
459
+ bit<8> segmentsLeft,
460
+ bit<128> sid1) {
461
+
462
+ // SID List <sid1>
463
+ hdr.ipv6.payloadLen = hdr.ipv6.payloadLen + 16w24;
464
+
465
+ // SRH(8) + SID(16)
466
+ push_srh(nextHdr, 8w2, segmentsLeft, 8w0);
467
+ hdr.srh_sid[0].setValid();
468
+ hdr.srh_sid[0].sid = sid1;
469
+ }
470
+ action push_srh_sid2(
471
+ bit<8> nextHdr,
472
+ bit<8> segmentsLeft,
473
+ bit<128> sid1, bit<128> sid2) {
474
+
475
+ // SID List <sid1, sid2>
476
+ hdr.ipv6.payloadLen = hdr.ipv6.payloadLen + 16w40;
477
+
478
+ // SRH(8) + SID(16)*2
479
+ push_srh(nextHdr, 8w4, segmentsLeft, 8w1);
480
+ hdr.srh_sid[0].setValid();
481
+ hdr.srh_sid[0].sid = sid2;
482
+ hdr.srh_sid[1].setValid();
483
+ hdr.srh_sid[1].sid = sid1;
484
+ }
485
+ action push_srh_sid3(
486
+ bit<8> nextHdr,
487
+ bit<8> segmentsLeft,
488
+ bit<128> sid1, bit<128> sid2, bit<128> sid3) {
489
+
490
+ // SID List <sid1, sid2, sid3>
491
+ hdr.ipv6.payloadLen = hdr.ipv6.payloadLen + 16w56;
492
+
493
+ // SRH(8) + SID(16)*3
494
+ push_srh(nextHdr, 8w6, segmentsLeft, 8w2);
495
+ hdr.srh_sid[0].setValid();
496
+ hdr.srh_sid[0].sid = sid3;
497
+ hdr.srh_sid[1].setValid();
498
+ hdr.srh_sid[1].sid = sid2;
499
+ hdr.srh_sid[2].setValid();
500
+ hdr.srh_sid[2].sid = sid1;
501
+ }
502
+ action push_srh_sid4(
503
+ bit<8> nextHdr,
504
+ bit<8> segmentsLeft,
505
+ bit<128> sid1, bit<128> sid2, bit<128> sid3, bit<128> sid4) {
506
+
507
+ // SID List <sid1, sid2, sid3, sid4>
508
+ hdr.ipv6.payloadLen = hdr.ipv6.payloadLen + 16w72;
509
+
510
+ // SRH(8) + SID(16)*4
511
+ push_srh(nextHdr, 8w8, segmentsLeft, 8w3);
512
+ hdr.srh_sid[0].setValid();
513
+ hdr.srh_sid[0].sid = sid4;
514
+ hdr.srh_sid[1].setValid();
515
+ hdr.srh_sid[1].sid = sid3;
516
+ hdr.srh_sid[2].setValid();
517
+ hdr.srh_sid[2].sid = sid2;
518
+ hdr.srh_sid[3].setValid();
519
+ hdr.srh_sid[3].sid = sid1;
520
+ }
521
+
522
+
523
+ /*** TRANSIT ACTION & TABLES */
524
+
525
+
526
+ // T.Insert will use ipv6.dstAddr as 1st SID. Thus, will have +1 SIDs.
527
+ action t_insert_sid1(bit<128> sid1) {
528
+ push_srh_sid2(hdr.ipv6.nextHdr, 1, sid1, hdr.ipv6.dstAddr);
529
+ hdr.ipv6.nextHdr = IPPROTO_ROUTE;
530
+ hdr.ipv6.dstAddr = sid1;
531
+ cnt_srv6_t_v6.count();
532
+ }
533
+ action t_insert_sid2(bit<128> sid1, bit<128> sid2) {
534
+ push_srh_sid3(hdr.ipv6.nextHdr, 2, sid1, sid2, hdr.ipv6.dstAddr);
535
+ hdr.ipv6.nextHdr = IPPROTO_ROUTE;
536
+ hdr.ipv6.dstAddr = sid1;
537
+ cnt_srv6_t_v6.count();
538
+ }
539
+ action t_insert_sid3(bit<128> sid1, bit<128> sid2, bit<128> sid3) {
540
+ push_srh_sid4(hdr.ipv6.nextHdr, 3, sid1, sid2, sid3, hdr.ipv6.dstAddr);
541
+ hdr.ipv6.nextHdr = IPPROTO_ROUTE;
542
+ hdr.ipv6.dstAddr = sid1;
543
+ cnt_srv6_t_v6.count();
544
+ }
545
+
546
+
547
+ action t_m_gtp4_d_synthesize(bit<32> iw_prefix, bit<64> src_prefix) {
548
+
549
+ hdr.ether.etherType = ETH_P_IPV6;
550
+ hdr.ipv6.setValid();
551
+ hdr.ipv6.version = 4w6;
552
+ hdr.ipv6.trafficClass = 8w0;
553
+ hdr.ipv6.flowLabel = 20w0;
554
+ hdr.ipv6.payloadLen = hdr.ipv4.totalLen - 16w40;
555
+ hdr.ipv6.nextHdr = 8w4;
556
+
557
+ hdr.ipv6.hopLimit = hdr.ipv4.ttl;
558
+
559
+ // Synthesize IPv6 SA from GTP packet
560
+ hdr.ipv6.srcAddr[127:64] = src_prefix;
561
+
562
+ // Local SRGW Src Prefix (64)
563
+ hdr.ipv6.srcAddr[63:32] = hdr.ipv4.srcAddr;
564
+
565
+ // IPv4 SA (32)
566
+ hdr.ipv6.srcAddr[31:0] = 32w0;
567
+
568
+ hdr.ipv6.dstAddr[127:96] = iw_prefix;
569
+
570
+ // GTP SRv6 InterWork prefix
571
+ hdr.ipv6.dstAddr[95:64] = hdr.ipv4.dstAddr;
572
+
573
+ hdr.ipv6.dstAddr[63:56] = 8w0;
574
+
575
+ // GTP QFI/RQI (0 for now)
576
+ hdr.ipv6.dstAddr[55:24] = hdr.gtpu.teid;
577
+ hdr.ipv6.dstAddr[23:0] = 24w0;
578
+
579
+ hdr.gtpu.setInvalid();
580
+ hdr.udp.setInvalid();
581
+ hdr.ipv4.setInvalid();
582
+ }
583
+
584
+ action t_m_gtp4_d(bit<32> iw_prefix, bit<64> src_prefix) {
585
+ t_m_gtp4_d_synthesize(iw_prefix, src_prefix);
586
+ cnt_srv6_t_udp.count();
587
+ }
588
+
589
+ action t_m_gtp4_d_sid1(bit<32> iw_prefix, bit<64> src_prefix,
590
+ bit<128> sid1) {
591
+ t_m_gtp4_d_synthesize(iw_prefix, src_prefix);
592
+ push_srh_sid2(hdr.ipv6.nextHdr, 1, sid1, hdr.ipv6.dstAddr);
593
+ hdr.ipv6.nextHdr = IPPROTO_ROUTE;
594
+ hdr.ipv6.dstAddr = sid1;
595
+ cnt_srv6_t_udp.count();
596
+ }
597
+ action t_m_gtp4_d_sid2(bit<32> iw_prefix, bit<64> src_prefix,
598
+ bit<128> sid1, bit<128> sid2) {
599
+ t_m_gtp4_d_synthesize(iw_prefix, src_prefix);
600
+ push_srh_sid3(hdr.ipv6.nextHdr, 2, sid1, sid2, hdr.ipv6.dstAddr);
601
+ hdr.ipv6.nextHdr = IPPROTO_ROUTE;
602
+ hdr.ipv6.dstAddr = sid1;
603
+ cnt_srv6_t_udp.count();
604
+ }
605
+ action t_m_gtp4_d_sid3(bit<32> iw_prefix, bit<64> src_prefix,
606
+ bit<128> sid1, bit<128> sid2, bit<128> sid3) {
607
+ t_m_gtp4_d_synthesize(iw_prefix, src_prefix);
608
+ push_srh_sid4(hdr.ipv6.nextHdr, 3, sid1, sid2, sid3, hdr.ipv6.dstAddr);
609
+ hdr.ipv6.nextHdr = IPPROTO_ROUTE;
610
+ hdr.ipv6.dstAddr = sid1;
611
+ cnt_srv6_t_udp.count();
612
+ }
613
+ action srv6_debug_v6() {
614
+
615
+ cnt_srv6_t_v6.count();
616
+ }
617
+ table srv6_transit_v6 {
618
+ key = {
619
+ hdr.ipv6.dstAddr: exact;
620
+
621
+ }
622
+ actions = {
623
+ @defaultonly NoAction;
624
+ t_insert_sid1;
625
+
626
+ // T.Insert with 2 SIDs (DA + sid1)
627
+ t_insert_sid2;
628
+
629
+ // T.Insert with 3 SIDs (DA + sid1/2)
630
+ t_insert_sid3;
631
+
632
+ }
633
+ const default_action = NoAction;
634
+ counters = cnt_srv6_t_v6;
635
+ }
636
+ table srv6_transit_v4 {
637
+ key = {
638
+ hdr.ipv4.dstAddr: exact;
639
+
640
+ }
641
+ actions = {
642
+ @defaultonly NoAction;
643
+
644
+ }
645
+ const default_action = NoAction;
646
+ counters = cnt_srv6_t_v4;
647
+ }
648
+ table srv6_transit_udp {
649
+ key = {
650
+ hdr.udp.dstPort : exact;
651
+ }
652
+ actions = {
653
+ @defaultonly NoAction;
654
+
655
+ // SRv6 Mobile Userplane : draft-ietf-dmm-srv6-mobile-uplane
656
+ t_m_gtp4_d;
657
+ t_m_gtp4_d_sid1;
658
+
659
+ // 2 SIDs (DA + sid1)
660
+ t_m_gtp4_d_sid2;
661
+
662
+ // 3 SIDs (DA + sid1/2)
663
+ t_m_gtp4_d_sid3;
664
+
665
+ // 4 SIDs (DA + sid1/2/3)
666
+ }
667
+ const default_action = NoAction;
668
+ counters = cnt_srv6_t_udp;
669
+ }
670
+
671
+ action end() {
672
+
673
+ hdr.srh.segmentsLeft = hdr.srh.segmentsLeft - 1;
674
+
675
+ hdr.ipv6.dstAddr = user_md.srv6.nextsid;
676
+
677
+ }
678
+ action end_m_gtp4_e() {
679
+ hdr.ether.etherType = ETH_P_IPV4;
680
+ hdr.ipv4.setValid();
681
+ hdr.ipv4.version = 4w4;
682
+ hdr.ipv4.ihl = 4w5;
683
+ hdr.ipv4.diffserv = 8w0;
684
+
685
+ hdr.ipv4.totalLen = hdr.ipv6.payloadLen - 16w8 - (bit<16>)hdr.srh.hdrExtLen*8 + 16w40;
686
+
687
+ hdr.ipv4.identification = 16w0;
688
+ hdr.ipv4.flags = 3w0;
689
+ hdr.ipv4.fragOffset = 13w0;
690
+ hdr.ipv4.ttl = hdr.ipv6.hopLimit;
691
+ hdr.ipv4.protocol = IPPROTO_UDP;
692
+
693
+ // IPv4 header checksum will be calculated later.
694
+ hdr.ipv4.srcAddr = hdr.ipv6.srcAddr[63:32];
695
+ hdr.ipv4.dstAddr = hdr.ipv6.dstAddr[95:64];
696
+ hdr.udp.setValid();
697
+ hdr.udp.srcPort = UDP_PORT_GTPU;
698
+
699
+ hdr.udp.dstPort = UDP_PORT_GTPU;
700
+
701
+ hdr.udp.length = hdr.ipv6.payloadLen + 16w20 -16w40;
702
+
703
+ hdr.gtpu.setValid();
704
+ hdr.gtpu.version = 3w1;
705
+ hdr.gtpu.pt = 1w1;
706
+ hdr.gtpu.reserved = 1w0;
707
+ hdr.gtpu.e = 1w0;
708
+
709
+ // No Extention Header
710
+ hdr.gtpu.s = 1w1;
711
+
712
+ // YES Sequence number
713
+ hdr.gtpu.pn = 1w0;
714
+ hdr.gtpu.messageType = GTPV1_GPDU;
715
+
716
+ hdr.gtpu.messageLen = hdr.ipv6.payloadLen - 16w8 - (bit<16>)hdr.srh.hdrExtLen*8 + 16w4;
717
+ hdr.gtpu.teid = hdr.ipv6.dstAddr[55:24];
718
+
719
+ hdr.gtpu.seq = 16w0;
720
+
721
+ hdr.gtpu.npdu = 8w0;
722
+ hdr.gtpu.nextExtHdr = 8w0;
723
+
724
+ // remove IPv6/SRH headers
725
+ remove_srh_header();
726
+ hdr.ipv6.setInvalid();
727
+
728
+ cnt_srv6_e.count();
729
+ }
730
+
731
+ action end_am(PortId_t oif, EthernetAddress dmac) {
732
+
733
+ hdr.ipv6.dstAddr = hdr.srh_sid[0].sid;
734
+ hdr.ether.dstAddr = dmac;
735
+ egress_port = oif;
736
+ }
737
+
738
+ action end_am_d(PortId_t oif) {
739
+
740
+ hdr.srh.segmentsLeft = hdr.srh.segmentsLeft - 1;
741
+ hdr.ipv6.dstAddr = user_md.srv6.nextsid;
742
+ egress_port = oif;
743
+
744
+ }
745
+ table srv6_end {
746
+
747
+ // localsid
748
+ key = {
749
+ hdr.ipv6.dstAddr : ternary;
750
+
751
+ }
752
+ actions = {
753
+ @defaultonly NoAction;
754
+
755
+ // SRv6 Network Program : draft-filsfils-spring-srv6-network-programming
756
+ end;
757
+
758
+
759
+
760
+ // SRv6 Mobile Userplane : draft-ietf-dmm-srv6-mobile-uplane
761
+ end_m_gtp4_e;
762
+
763
+ // End.M.GTP4.E
764
+
765
+
766
+ // Proxy Functions : draft-xuclad-spring-sr-service-programming
767
+ end_am;
768
+ }
769
+ const default_action = NoAction;
770
+ counters = cnt_srv6_e;
771
+ }
772
+ table srv6_end_iif {
773
+
774
+ // Input Interface based SRv6 End.* table
775
+ key = {
776
+ in_port : exact;
777
+
778
+ }
779
+ actions = {
780
+ @defaultonly NoAction;
781
+
782
+ // Proxy Functions : draft-xuclad-spring-sr-service-programming
783
+ end_am_d;
784
+ }
785
+ const default_action = NoAction;
786
+ counters = cnt_srv6_e_iif;
787
+ }
788
+
789
+
790
+
791
+ /*** HELPER TABLE TO SET NEXT SID */
792
+ action set_nextsid_1() {
793
+ user_md.srv6.nextsid = hdr.srh_sid[0].sid;
794
+ }
795
+ action set_nextsid_2() {
796
+ user_md.srv6.nextsid = hdr.srh_sid[1].sid;
797
+ }
798
+ action set_nextsid_3() {
799
+ user_md.srv6.nextsid = hdr.srh_sid[2].sid;
800
+ }
801
+ action set_nextsid_4() {
802
+ user_md.srv6.nextsid = hdr.srh_sid[3].sid;
803
+ }
804
+ table srv6_set_nextsid {
805
+
806
+ // helper table
807
+ key = {
808
+ hdr.srh.segmentsLeft : exact;
809
+ }
810
+ actions = {
811
+ NoAction;
812
+ set_nextsid_1;
813
+ set_nextsid_2;
814
+ set_nextsid_3;
815
+ set_nextsid_4;
816
+ }
817
+ const default_action = NoAction;
818
+ const entries = {
819
+ (1) : set_nextsid_1();
820
+ (2) : set_nextsid_2();
821
+ (3) : set_nextsid_3();
822
+ (4) : set_nextsid_4();
823
+ }
824
+ }
825
+
826
+ action set_gtpu_type(bit<8> type) {
827
+ hdr.gtpu.messageType = type;
828
+ }
829
+ action set_srv6_GTPV1_END() {
830
+ hdr.srh.gtpMessageType = 1;
831
+ }
832
+ action set_srv6_GTPV1_ERROR() {
833
+ hdr.srh.gtpMessageType = 2;
834
+ }
835
+ action set_srv6_GTPV1_ECHO() {
836
+ hdr.srh.gtpMessageType = 4;
837
+ }
838
+ action set_srv6_GTPV1_ECHORES() {
839
+ hdr.srh.gtpMessageType = 8;
840
+ }
841
+ apply {
842
+ if (hdr.srh.isValid()) {
843
+ srv6_set_nextsid.apply();
844
+ }
845
+ if (hdr.ipv6.isValid()) {
846
+ if(!srv6_end_iif.apply().hit) {
847
+ if(srv6_end.apply().hit) {
848
+
849
+ // draft-murakami-dmm-user-plane-message-encoding
850
+ if (user_md.srv6.gtp_message_type == 1) {
851
+
852
+ set_gtpu_type(GTPV1_END);
853
+ } else if (user_md.srv6.gtp_message_type == 2) {
854
+ set_gtpu_type(GTPV1_ERROR);
855
+ } else if (user_md.srv6.gtp_message_type == 4) {
856
+ set_gtpu_type(GTPV1_ECHO);
857
+ } else if (user_md.srv6.gtp_message_type == 8) {
858
+ set_gtpu_type(GTPV1_ECHORES);
859
+ }
860
+ } else {
861
+ srv6_transit_v6.apply();
862
+ }
863
+ }
864
+ } else if (hdr.ipv4.isValid()) {
865
+ if(srv6_transit_udp.apply().hit) {
866
+
867
+ // Assuming this is GTP/SRv6 translation
868
+ if (user_md.srv6.gtpv1_type == GTPV1_END) {
869
+ set_srv6_GTPV1_END();
870
+ } else if (user_md.srv6.gtpv1_type == GTPV1_ERROR){
871
+ set_srv6_GTPV1_ERROR();
872
+ } else if (user_md.srv6.gtpv1_type == GTPV1_ECHO){
873
+ set_srv6_GTPV1_ECHO();
874
+ } else if (user_md.srv6.gtpv1_type == GTPV1_ECHORES){
875
+ set_srv6_GTPV1_ECHORES();
876
+ }
877
+ } else {
878
+ srv6_transit_v4.apply();
879
+ }
880
+ }
881
+ }
882
+ }
883
+
884
+
885
+ #endif /* _SRV6_ */
886
+
887
+
888
+
889
+
890
+ control L2Fwd(
891
+ in EthernetAddress ether_dst_addr,
892
+ inout IngressMetadata ig_md,
893
+ inout PortId_t egress_port)
894
+ (bit<32> table_size_dmac) {
895
+
896
+ action dmac_miss() {
897
+
898
+ }
899
+ action dmac_hit(PortId_t port) {
900
+ egress_port = port;
901
+ }
902
+
903
+ table dmac {
904
+ key = {
905
+ ether_dst_addr : exact;
906
+ }
907
+ actions = {
908
+ dmac_miss;
909
+ dmac_hit;
910
+ }
911
+ const default_action = dmac_miss;
912
+ size = table_size_dmac;
913
+ }
914
+
915
+ apply {
916
+ dmac.apply();
917
+ }
918
+ }
919
+ control PortFwd(
920
+ in PortId_t in_port,
921
+ inout PortId_t egress_port) {
922
+
923
+ action set_egress_port(PortId_t port) {
924
+ egress_port = port;
925
+ }
926
+
927
+ table portfwd {
928
+ key = {
929
+ in_port : exact;
930
+
931
+ // ingress phy port
932
+ }
933
+
934
+ actions = {
935
+ set_egress_port;
936
+ }
937
+ }
938
+
939
+ apply {
940
+ portfwd.apply();
941
+ }
942
+ }
943
+
944
+
945
+ // CONTROL: INGRESS
946
+
947
+ control SwitchIngress(
948
+ inout Header hdr,
949
+ inout UserMetadata user_md,
950
+ inout standard_metadata_t st_md) {
951
+
952
+
953
+ // Instantiate controlls
954
+ PortFwd() port_fwd;
955
+ SRv6() srv6;
956
+ L2Fwd(1024) l2fwd;
957
+
958
+
959
+ // Local MAC address. Apply Layer 3 tables when hit.
960
+ action local_mac_hit() {}
961
+ table local_mac {
962
+ key = {
963
+ hdr.ether.dstAddr : exact;
964
+ }
965
+ actions = {
966
+ NoAction;
967
+ local_mac_hit();
968
+ }
969
+ const default_action = NoAction;
970
+ size = 512;
971
+
972
+ // number of Layer 3 interfaces
973
+ }
974
+
975
+ apply {
976
+
977
+ mark_to_drop(st_md);
978
+
979
+ // set default action to drop to avoid unexpected packets going out.
980
+
981
+
982
+ // policy L1 (port) forwarding table useful untill l2fwd is implemented.
983
+ port_fwd.apply(st_md.ingress_port, st_md.egress_spec);
984
+
985
+
986
+ srv6.apply(hdr, user_md, st_md.ingress_port, st_md.egress_spec);
987
+
988
+
989
+ l2fwd.apply(hdr.ether.dstAddr, user_md.ig_md, st_md.egress_spec);
990
+ }
991
+ }
992
+
993
+
994
+
995
+
996
+ // CONTROL: EGRESS
997
+
998
+ control SwitchEgress(
999
+ inout Header hdr,
1000
+ inout UserMetadata user_md,
1001
+ inout standard_metadata_t st_md) {
1002
+
1003
+ // do nothing
1004
+ apply { }
1005
+ }
1006
+
1007
+
1008
+
1009
+ // CONTROL: CHECKSUM
1010
+
1011
+ control NoSwitchVerifyChecksum(
1012
+ inout Header hdr,
1013
+ inout UserMetadata user_md) {
1014
+
1015
+ // dummy control to skip checkum
1016
+ apply { }
1017
+ }
1018
+ control SwitchVerifyChecksum(
1019
+ inout Header hdr,
1020
+ inout UserMetadata user_md) {
1021
+ apply {
1022
+ verify_checksum(hdr.ipv4.isValid() && hdr.ipv4.ihl == 5,
1023
+ { hdr.ipv4.version,
1024
+ hdr.ipv4.ihl,
1025
+ hdr.ipv4.diffserv,
1026
+ hdr.ipv4.totalLen,
1027
+ hdr.ipv4.identification,
1028
+ hdr.ipv4.flags,
1029
+ hdr.ipv4.fragOffset,
1030
+ hdr.ipv4.ttl,
1031
+ hdr.ipv4.protocol,
1032
+ hdr.ipv4.srcAddr,
1033
+ hdr.ipv4.dstAddr },
1034
+ hdr.ipv4.hdrChecksum, HashAlgorithm.csum16);
1035
+ }
1036
+ }
1037
+
1038
+ /*****************************************************
1039
+
1040
+ control SwitchComputeChecksum(
1041
+ inout Header hdr,
1042
+ inout UserMetadata user_md) {
1043
+ apply {
1044
+ update_checksum(hdr.ipv4.isValid() && hdr.ipv4.ihl == 5,
1045
+ { hdr.ipv4.version,
1046
+ hdr.ipv4.ihl,
1047
+ hdr.ipv4.diffserv,
1048
+ hdr.ipv4.totalLen,
1049
+ hdr.ipv4.identification,
1050
+ hdr.ipv4.flags,
1051
+ hdr.ipv4.fragOffset,
1052
+ hdr.ipv4.ttl,
1053
+ hdr.ipv4.protocol,
1054
+ hdr.ipv4.srcAddr,
1055
+ hdr.ipv4.dstAddr },
1056
+ hdr.ipv4.hdrChecksum, HashAlgorithm.csum16);
1057
+ }
1058
+ }
1059
+
1060
+ V1Switch(SwitchParser(),
1061
+
1062
+ NoSwitchVerifyChecksum(),
1063
+ SwitchIngress(),
1064
+ SwitchEgress(),
1065
+ SwitchComputeChecksum(),
1066
+
1067
+ SwitchDeparser()) main;
individual_files/000054__raw-repositories__ElhNoah__INT.p4 ADDED
@@ -0,0 +1,1277 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <core.p4>
2
+ #include <v1model.p4>
3
+
4
+
5
+
6
+ #define MAX_PORTS 511
7
+ #define CLONE_PKT 1
8
+
9
+ const bit<6> HW_ID = 1;
10
+
11
+ const bit<16> TYPE_IPV4 = 0x0800;
12
+ const bit<8> IP_PROTO_UDP = 0x11;
13
+ const bit<8> IP_PROTO_TCP = 0x6;
14
+
15
+ const bit<6> DSCP_INT = 0x17;
16
+ const bit<6> DSCP_MASK = 0x3F;
17
+
18
+ typedef bit<48> mac_t;
19
+ typedef bit<32> ip_address_t;
20
+ typedef bit<16> l4_port_t;
21
+ typedef bit<9> port_t;
22
+ typedef bit<32> node_id_t;
23
+
24
+ const bit<32> REPORT_MIRROR_SESSION_ID = 500;
25
+
26
+
27
+ header ethernet_t {
28
+ bit<48> dst_addr;
29
+ bit<48> src_addr;
30
+ bit<16> ether_type;
31
+ }
32
+
33
+ const bit<8> ETH_HEADER_LEN = 14;
34
+
35
+
36
+ header ipv4_t {
37
+ bit<4> version;
38
+ bit<4> ihl;
39
+ bit<6> dscp;
40
+ bit<2> ecn;
41
+ bit<16> len;
42
+ bit<16> identification;
43
+ bit<3> flags;
44
+ bit<13> frag_offset;
45
+ bit<8> ttl;
46
+ bit<8> protocol;
47
+ bit<16> hdr_checksum;
48
+ bit<32> src_addr;
49
+ bit<32> dst_addr;
50
+ }
51
+
52
+ const bit<8> IPV4_MIN_HEAD_LEN = 20;
53
+
54
+
55
+ header udp_t {
56
+ bit<16> src_port;
57
+ bit<16> dst_port;
58
+ bit<16> length_;
59
+ bit<16> checksum;
60
+ }
61
+
62
+ const bit<8> UDP_HEADER_LEN = 8;
63
+
64
+
65
+ header tcp_t {
66
+ bit<16> src_port;
67
+ bit<16> dst_port;
68
+ bit<32> seq_no;
69
+ bit<32> ack_no;
70
+ bit<4> data_offset;
71
+ bit<3> res;
72
+ bit<3> ecn;
73
+ bit<6> ctrl;
74
+ bit<16> window;
75
+ bit<16> checksum;
76
+ bit<16> urgent_ptr;
77
+ }
78
+
79
+ const bit<8> TCP_HEADER_LEN = 20;
80
+
81
+
82
+
83
+ // INT shim header for INT over TCP/UDP
84
+ header intl4_shim_t {
85
+ bit<4> int_type;
86
+
87
+ // Type of INT Header
88
+ bit<2> npt;
89
+
90
+ // Next protocol type
91
+ bit<2> rsvd1;
92
+
93
+ // Reserved
94
+ bit<8> len;
95
+
96
+ // Length of INT Metadata header and INT stack in 4-byte words, not including the shim header (1 word)
97
+ bit<8> rsvd2;
98
+
99
+ // Reserved
100
+ bit<6> original_dscp;
101
+
102
+ // Original DSCP value
103
+ bit<2> rsvd3;
104
+
105
+ // Reserved
106
+ }
107
+
108
+ const bit<16> INT_SHIM_HEADER_SIZE = 4;
109
+
110
+
111
+ // INT header
112
+ header int_header_t {
113
+ bit<4> ver;
114
+
115
+ // Version
116
+ bit<1> d;
117
+
118
+ // Discard
119
+ bit<1> e;
120
+ bit<1> m;
121
+ bit<12> rsvd1;
122
+ bit<5> hop_metadata_len;
123
+ bit<8> remaining_hop_cnt;
124
+ bit<4> instruction_mask_0003;
125
+
126
+ // Split the bits for lookup
127
+ bit<4> instruction_mask_0407;
128
+ bit<4> instruction_mask_0811;
129
+ bit<4> instruction_mask_1215;
130
+ bit<16> domain_specific_id;
131
+
132
+ // Unique INT Domain ID
133
+ bit<16> ds_instruction;
134
+
135
+ // Instruction bitmap specific to the INT Domain identified by the Domain specific ID
136
+ bit<16> ds_flags;
137
+
138
+ // Domain specific flags
139
+ }
140
+
141
+ const bit<16> INT_HEADER_SIZE = 12;
142
+ const bit<8> INT_HEADER_WORD = 3;
143
+ const bit<16> INT_TOTAL_HEADER_SIZE = INT_HEADER_SIZE + INT_SHIM_HEADER_SIZE;
144
+
145
+
146
+
147
+ // INT meta-value headers - different header for each value type to monitor
148
+ header int_node_id_t {
149
+ bit<32> node_id;
150
+ }
151
+ header int_level1_port_ids_t {
152
+ bit<16> ingress_port_id;
153
+ bit<16> egress_port_id;
154
+ }
155
+ header int_hop_latency_t {
156
+ bit<32> hop_latency;
157
+ }
158
+ header int_q_occupancy_t {
159
+ bit<8> q_id;
160
+ bit<24> q_occupancy;
161
+ }
162
+ header int_ingress_tstamp_t {
163
+ bit<64> ingress_tstamp;
164
+ }
165
+ header int_egress_tstamp_t {
166
+ bit<64> egress_tstamp;
167
+ }
168
+ header int_level2_port_ids_t {
169
+ bit<32> ingress_port_id;
170
+ bit<32> egress_port_id;
171
+ }
172
+
173
+
174
+ // These two are not implemented yet
175
+ header int_egress_port_tx_util_t {
176
+ bit<32> egress_port_tx_util;
177
+
178
+ // This is used but the queue latency is gathered instead
179
+ }
180
+
181
+ header int_buffer_t {
182
+ bit<8> buffer_id;
183
+ bit<24> buffer_occupancy;
184
+ }
185
+
186
+ header int_data_t {
187
+
188
+ varbit<1920> data;
189
+ }
190
+
191
+
192
+ // Report Telemetry Headers - Group Header
193
+ header report_group_header_t {
194
+ bit<4> ver;
195
+ bit<6> hw_id;
196
+ bit<22> seq_no;
197
+ bit<32> node_id;
198
+ }
199
+ const bit<8> REPORT_GROUP_HEADER_LEN = 8;
200
+
201
+
202
+ // Report Telemetry Headers - Individual Header
203
+ header report_individual_header_t {
204
+ bit<4> rep_type;
205
+ bit<4> in_type;
206
+ bit<8> len;
207
+ bit<8> rep_md_len;
208
+ bit<1> d;
209
+ bit<1> q;
210
+ bit<1> f;
211
+ bit<1> i;
212
+ bit<4> rsvd;
213
+
214
+ bit<16> rep_md_bits;
215
+ bit<16> domain_specific_id;
216
+ bit<16> domain_specific_md_bits;
217
+ bit<16> domain_specific_md_status;
218
+ }
219
+ const bit<8> REPORT_INDIVIDUAL_HEADER_LEN = 12;
220
+
221
+
222
+ // Preserving metadata header for the cloned packet
223
+ struct preserving_metadata_t {
224
+ @field_list(1)
225
+ bit<9> ingress_port;
226
+ @field_list(1)
227
+ bit<9> egress_port;
228
+ @field_list(1)
229
+ bit<32> deq_timedelta;
230
+ @field_list(1)
231
+ bit<19> deq_qdepth;
232
+ @field_list(1)
233
+ bit<48> ingress_global_timestamp;
234
+ @field_list(1)
235
+ bit<48> egress_global_timestamp;
236
+ }
237
+
238
+ struct headers {
239
+
240
+
241
+ // Original Packet Headers
242
+ ethernet_t ethernet;
243
+ ipv4_t ipv4;
244
+ udp_t udp;
245
+ tcp_t tcp;
246
+
247
+
248
+ // INT Report Encapsulation
249
+ ethernet_t report_ethernet;
250
+ ipv4_t report_ipv4;
251
+ udp_t report_udp;
252
+
253
+
254
+ // INT Headers
255
+ int_header_t int_header;
256
+ intl4_shim_t intl4_shim;
257
+
258
+
259
+ //INT Metadata
260
+ int_data_t int_data;
261
+ int_node_id_t int_node_id;
262
+ int_level1_port_ids_t int_level1_port_ids;
263
+ int_hop_latency_t int_hop_latency;
264
+ int_q_occupancy_t int_q_occupancy;
265
+ int_ingress_tstamp_t int_ingress_tstamp;
266
+ int_egress_tstamp_t int_egress_tstamp;
267
+ int_level2_port_ids_t int_level2_port_ids;
268
+ int_egress_port_tx_util_t int_egress_tx_util;
269
+
270
+
271
+ // INT Report Headers
272
+ report_group_header_t report_group_header;
273
+ report_individual_header_t report_individual_header;
274
+ }
275
+
276
+ struct int_metadata_t {
277
+ node_id_t node_id;
278
+ bit<16> new_bytes;
279
+ bit<8> new_words;
280
+ bool source;
281
+ bool sink;
282
+ bit<8> intl4_shim_len;
283
+ }
284
+
285
+ struct local_metadata_t {
286
+ bit<16> l4_src_port;
287
+ bit<16> l4_dst_port;
288
+ int_metadata_t int_meta;
289
+ preserving_metadata_t perserv_meta;
290
+ }
291
+
292
+
293
+
294
+ parser MyParser( packet_in packet,
295
+ out headers hdr,
296
+ inout local_metadata_t local_metadata,
297
+ inout standard_metadata_t standard_metadata) {
298
+
299
+ state start {
300
+ transition parse_ethernet;
301
+ }
302
+
303
+ state parse_ethernet {
304
+ packet.extract(hdr.ethernet);
305
+ transition select(hdr.ethernet.ether_type) {
306
+ TYPE_IPV4: parse_ipv4;
307
+ default: accept;
308
+ }
309
+ }
310
+
311
+ state parse_ipv4 {
312
+ packet.extract(hdr.ipv4);
313
+ transition select(hdr.ipv4.protocol) {
314
+ IP_PROTO_UDP: parse_udp;
315
+ IP_PROTO_TCP: parse_tcp;
316
+ default: accept;
317
+ }
318
+ }
319
+
320
+ state parse_udp {
321
+ packet.extract(hdr.udp);
322
+ local_metadata.l4_src_port = hdr.udp.src_port;
323
+ local_metadata.l4_dst_port = hdr.udp.dst_port;
324
+ transition select(hdr.ipv4.dscp) {
325
+ DSCP_INT &&& DSCP_MASK: parse_shim;
326
+ default: accept;
327
+ }
328
+ }
329
+
330
+ state parse_tcp {
331
+ packet.extract(hdr.tcp);
332
+ local_metadata.l4_src_port = hdr.tcp.src_port;
333
+ local_metadata.l4_dst_port = hdr.tcp.dst_port;
334
+ transition select(hdr.ipv4.dscp) {
335
+ DSCP_INT &&& DSCP_MASK: parse_shim;
336
+ default: accept;
337
+ }
338
+ }
339
+
340
+ state parse_shim {
341
+ packet.extract(hdr.intl4_shim);
342
+ local_metadata.int_meta.intl4_shim_len = hdr.intl4_shim.len;
343
+ transition parse_int_hdr;
344
+ }
345
+
346
+ state parse_int_hdr {
347
+ packet.extract(hdr.int_header);
348
+ transition parse_int_data;
349
+ }
350
+
351
+ state parse_int_data {
352
+ packet.extract(hdr.int_data, ((bit<32>) (local_metadata.int_meta.intl4_shim_len - INT_HEADER_WORD)) << 5);
353
+ transition accept;
354
+ }
355
+ }
356
+
357
+
358
+
359
+
360
+ control MyDeparser(packet_out packet,
361
+ in headers hdr) {
362
+
363
+ apply {
364
+
365
+ packet.emit(hdr.report_ethernet);
366
+ packet.emit(hdr.report_ipv4);
367
+ packet.emit(hdr.report_udp);
368
+
369
+ packet.emit(hdr.report_group_header);
370
+ packet.emit(hdr.report_individual_header);
371
+
372
+ packet.emit(hdr.ethernet);
373
+ packet.emit(hdr.ipv4);
374
+ packet.emit(hdr.udp);
375
+ packet.emit(hdr.tcp);
376
+
377
+ packet.emit(hdr.intl4_shim);
378
+ packet.emit(hdr.int_header);
379
+
380
+ packet.emit(hdr.int_node_id);
381
+ packet.emit(hdr.int_level1_port_ids);
382
+ packet.emit(hdr.int_hop_latency);
383
+ packet.emit(hdr.int_q_occupancy);
384
+ packet.emit(hdr.int_ingress_tstamp);
385
+ packet.emit(hdr.int_egress_tstamp);
386
+ packet.emit(hdr.int_level2_port_ids);
387
+ packet.emit(hdr.int_egress_tx_util);
388
+
389
+ packet.emit(hdr.int_data);
390
+ }
391
+ }
392
+
393
+ control MyVerifyChecksum(inout headers hdr, inout local_metadata_t local_metadata) {
394
+ apply {
395
+ verify_checksum(
396
+ hdr.ipv4.isValid(),
397
+ { hdr.ipv4.version,
398
+ hdr.ipv4.ihl,
399
+ hdr.ipv4.dscp,
400
+ hdr.ipv4.ecn,
401
+ hdr.ipv4.len,
402
+ hdr.ipv4.identification,
403
+ hdr.ipv4.flags,
404
+ hdr.ipv4.frag_offset,
405
+ hdr.ipv4.ttl,
406
+ hdr.ipv4.protocol,
407
+ hdr.ipv4.src_addr,
408
+ hdr.ipv4.dst_addr },
409
+ hdr.ipv4.hdr_checksum,
410
+ HashAlgorithm.csum16
411
+ );
412
+ }
413
+ }
414
+
415
+ control MyComputeChecksum(inout headers hdr, inout local_metadata_t local_metadata){
416
+ apply{
417
+ update_checksum(
418
+ hdr.ipv4.isValid(),
419
+ { hdr.ipv4.version,
420
+ hdr.ipv4.ihl,
421
+ hdr.ipv4.dscp,
422
+ hdr.ipv4.ecn,
423
+ hdr.ipv4.len,
424
+ hdr.ipv4.identification,
425
+ hdr.ipv4.flags,
426
+ hdr.ipv4.frag_offset,
427
+ hdr.ipv4.ttl,
428
+ hdr.ipv4.protocol,
429
+ hdr.ipv4.src_addr,
430
+ hdr.ipv4.dst_addr },
431
+ hdr.ipv4.hdr_checksum,
432
+ HashAlgorithm.csum16
433
+ );
434
+
435
+ }
436
+
437
+ }
438
+
439
+ control process_int_sink (
440
+ inout headers hdr) {
441
+
442
+ action restore_header () {
443
+ hdr.ipv4.dscp = hdr.intl4_shim.original_dscp;
444
+ bit<16> len_bytes = (((bit<16>)hdr.intl4_shim.len) << 2) + INT_SHIM_HEADER_SIZE;
445
+ hdr.ipv4.len = hdr.ipv4.len - len_bytes;
446
+ if(hdr.udp.isValid()) {
447
+ hdr.udp.length_ = hdr.udp.length_ - len_bytes;
448
+ }
449
+ }
450
+
451
+
452
+ action int_sink() {
453
+
454
+ // remove all the INT information from the packet
455
+ hdr.intl4_shim.setInvalid();
456
+ hdr.int_header.setInvalid();
457
+ hdr.int_node_id.setInvalid();
458
+ hdr.int_level1_port_ids.setInvalid();
459
+ hdr.int_hop_latency.setInvalid();
460
+ hdr.int_q_occupancy.setInvalid();
461
+ hdr.int_ingress_tstamp.setInvalid();
462
+ hdr.int_egress_tstamp.setInvalid();
463
+ hdr.int_level2_port_ids.setInvalid();
464
+ hdr.int_egress_tx_util.setInvalid();
465
+ hdr.int_data.setInvalid();
466
+ }
467
+
468
+ apply {
469
+ restore_header();
470
+ int_sink();
471
+ }
472
+ }
473
+
474
+
475
+ // Action for the INT telemetry report, as it is encapsulated with new Ethernet, IP and UDP headers
476
+ control process_int_report (inout headers hdr,
477
+ inout local_metadata_t local_metadata,
478
+ inout standard_metadata_t standard_metadata) {
479
+
480
+
481
+ // Register for sequence number
482
+ register<bit<22>>(1) seq_number;
483
+
484
+ action increment_counter() {
485
+ bit<22> tmp;
486
+ seq_number.read(tmp, 0);
487
+ tmp = tmp + 1;
488
+ seq_number.write(0, tmp);
489
+ }
490
+
491
+ action do_report_encapsulation(mac_t src_mac,
492
+ mac_t mon_mac,
493
+ ip_address_t src_ip,
494
+ ip_address_t mon_ip,
495
+ l4_port_t src_port,
496
+ l4_port_t mon_port) {
497
+
498
+
499
+ // Report Ethernet Header
500
+ hdr.report_ethernet.setValid();
501
+ hdr.report_ethernet.dst_addr = mon_mac;
502
+ hdr.report_ethernet.src_addr = src_mac;
503
+ hdr.report_ethernet.ether_type = 0x0800;
504
+
505
+
506
+ // Report IPV4 Header
507
+ hdr.report_ipv4.setValid();
508
+ hdr.report_ipv4.version = 4w4;
509
+ hdr.report_ipv4.ihl = 4w5;
510
+ hdr.report_ipv4.dscp = 6w0;
511
+ hdr.report_ipv4.ecn = 2w0;
512
+
513
+ if (hdr.udp.isValid()) {
514
+ hdr.report_ipv4.len = (bit<16>) IPV4_MIN_HEAD_LEN + (bit<16>) UDP_HEADER_LEN + (bit<16>) REPORT_GROUP_HEADER_LEN + (bit<16>) REPORT_INDIVIDUAL_HEADER_LEN +
515
+ local_metadata.int_meta.new_bytes + (bit<16>) IPV4_MIN_HEAD_LEN + (bit<16>) UDP_HEADER_LEN + (bit<16>) INT_SHIM_HEADER_SIZE + (((bit<16>) hdr.intl4_shim.len) << 2);
516
+ } else if (hdr.tcp.isValid()) {
517
+ hdr.report_ipv4.len = (bit<16>) IPV4_MIN_HEAD_LEN + (bit<16>) UDP_HEADER_LEN + (bit<16>) REPORT_GROUP_HEADER_LEN + (bit<16>) REPORT_INDIVIDUAL_HEADER_LEN +
518
+ local_metadata.int_meta.new_bytes + (bit<16>) IPV4_MIN_HEAD_LEN + (bit<16>) TCP_HEADER_LEN + (bit<16>) INT_SHIM_HEADER_SIZE + (((bit<16>) hdr.intl4_shim.len) << 2);
519
+ }
520
+
521
+ hdr.report_ipv4.identification = 0;
522
+ hdr.report_ipv4.flags = 0;
523
+ hdr.report_ipv4.frag_offset = 0;
524
+ hdr.report_ipv4.ttl = 64;
525
+ hdr.report_ipv4.protocol = IP_PROTO_UDP;
526
+ hdr.report_ipv4.src_addr = src_ip;
527
+ hdr.report_ipv4.dst_addr = mon_ip;
528
+
529
+
530
+ //Report UDP Header
531
+ hdr.report_udp.setValid();
532
+ hdr.report_udp.src_port = src_port;
533
+ hdr.report_udp.dst_port = mon_port;
534
+
535
+ if (hdr.udp.isValid()) {
536
+ hdr.report_udp.length_ = (bit<16>) UDP_HEADER_LEN + (bit<16>) REPORT_GROUP_HEADER_LEN + (bit<16>) REPORT_INDIVIDUAL_HEADER_LEN +
537
+ local_metadata.int_meta.new_bytes + (bit<16>) IPV4_MIN_HEAD_LEN + (bit<16>) UDP_HEADER_LEN + (bit<16>) INT_SHIM_HEADER_SIZE + (((bit<16>) hdr.intl4_shim.len) << 2);
538
+ } else if (hdr.tcp.isValid()) {
539
+ hdr.report_udp.length_ = (bit<16>) UDP_HEADER_LEN + (bit<16>) REPORT_GROUP_HEADER_LEN + (bit<16>) REPORT_INDIVIDUAL_HEADER_LEN +
540
+ local_metadata.int_meta.new_bytes + (bit<16>) IPV4_MIN_HEAD_LEN + (bit<16>) TCP_HEADER_LEN + (bit<16>) INT_SHIM_HEADER_SIZE + (((bit<16>) hdr.intl4_shim.len) << 2);
541
+ }
542
+
543
+
544
+ // Telemetry Group Header
545
+ hdr.report_group_header.setValid();
546
+ hdr.report_group_header.ver = 2;
547
+
548
+ // Version 2.0
549
+ hdr.report_group_header.hw_id = HW_ID;
550
+
551
+ // Default Value 1
552
+ seq_number.read(hdr.report_group_header.seq_no, 0);
553
+ increment_counter();
554
+ hdr.report_group_header.node_id = local_metadata.int_meta.node_id;
555
+
556
+
557
+
558
+ // Telemetry Report Individual Header
559
+ hdr.report_individual_header.setValid();
560
+ hdr.report_individual_header.rep_type = 1;
561
+
562
+ // INT Report
563
+ hdr.report_individual_header.in_type = 4;
564
+
565
+ // Individual Report Inner Content is an IPv4 packet
566
+ if (hdr.udp.isValid()) {
567
+ hdr.report_individual_header.len = 2 + local_metadata.int_meta.new_words + 5 + 2 + 4;
568
+ } else if (hdr.tcp.isValid()) {
569
+ hdr.report_individual_header.len = 2 + local_metadata.int_meta.new_words + 5 + 5 + 4;
570
+ }
571
+ hdr.report_individual_header.rep_md_len = local_metadata.int_meta.new_words;
572
+ hdr.report_individual_header.d = 0;
573
+ hdr.report_individual_header.q = 0;
574
+ hdr.report_individual_header.f = 1;
575
+ hdr.report_individual_header.i = 0;
576
+ hdr.report_individual_header.rsvd = 0;
577
+
578
+
579
+ // Individual report main contents
580
+ hdr.report_individual_header.rep_md_bits = hdr.int_header.instruction_mask_0003 ++ hdr.int_header.instruction_mask_0407 ++
581
+ hdr.int_header.instruction_mask_0811 ++ hdr.int_header.instruction_mask_1215;
582
+ hdr.report_individual_header.domain_specific_id = 0;
583
+ hdr.report_individual_header.domain_specific_md_bits = 0;
584
+ hdr.report_individual_header.domain_specific_md_status = 0;
585
+
586
+ hdr.ethernet.setInvalid();
587
+ }
588
+
589
+ table tb_generate_report {
590
+ actions = {
591
+ do_report_encapsulation;
592
+ NoAction();
593
+ }
594
+ default_action = do_report_encapsulation(0, 0, 0, 0, 0, 0);
595
+ }
596
+
597
+ apply {
598
+ tb_generate_report.apply();
599
+ }
600
+ }
601
+
602
+ control process_int_transit (
603
+ inout headers hdr,
604
+ inout local_metadata_t local_metadata,
605
+ inout standard_metadata_t standard_metadata) {
606
+
607
+ action init_metadata(node_id_t node_id) {
608
+ local_metadata.int_meta.node_id = node_id;
609
+ }
610
+
611
+
612
+ // Node ID
613
+ action int_set_header_0() {
614
+ hdr.int_node_id.setValid();
615
+ hdr.int_node_id.node_id = local_metadata.int_meta.node_id;
616
+ }
617
+
618
+
619
+ // Level 1 ingress interface ID + Egress interface ID
620
+ action int_set_header_1() {
621
+ hdr.int_level1_port_ids.setValid();
622
+ hdr.int_level1_port_ids.ingress_port_id = (bit<16>) standard_metadata.ingress_port;
623
+ hdr.int_level1_port_ids.egress_port_id = (bit<16>) standard_metadata.egress_port;
624
+ }
625
+
626
+
627
+ // Hop latency
628
+ action int_set_header_2() {
629
+ hdr.int_hop_latency.setValid();
630
+ hdr.int_hop_latency.hop_latency = (bit<32>) standard_metadata.egress_global_timestamp - (bit<32>) standard_metadata.ingress_global_timestamp;
631
+ }
632
+
633
+
634
+ // Queue ID and queue occupancy
635
+ action int_set_header_3() {
636
+ hdr.int_q_occupancy.setValid();
637
+
638
+ hdr.int_q_occupancy.q_id = 0;
639
+ hdr.int_q_occupancy.q_occupancy = (bit<24>) standard_metadata.deq_qdepth;
640
+ }
641
+
642
+
643
+ // Ingress timestamp
644
+ action int_set_header_4() {
645
+ hdr.int_ingress_tstamp.setValid();
646
+ hdr.int_ingress_tstamp.ingress_tstamp = (bit<64>) standard_metadata.ingress_global_timestamp;
647
+ }
648
+
649
+
650
+ // Egress timestamp
651
+ action int_set_header_5() {
652
+ hdr.int_egress_tstamp.setValid();
653
+ hdr.int_egress_tstamp.egress_tstamp = (bit<64>) standard_metadata.egress_global_timestamp;
654
+ }
655
+
656
+
657
+ // Level 2 Ingress Interface ID + Egress Interface ID
658
+ action int_set_header_6() {
659
+ hdr.int_level2_port_ids.setValid();
660
+ hdr.int_level2_port_ids.ingress_port_id = (bit<32>) local_metadata.l4_src_port;
661
+ hdr.int_level2_port_ids.egress_port_id = (bit<32>) local_metadata.l4_dst_port;
662
+ }
663
+
664
+
665
+ // Egress interface TX utilization
666
+ action int_set_header_7() {
667
+ hdr.int_egress_tx_util.setValid();
668
+ hdr.int_egress_tx_util.egress_port_tx_util = (bit<32>) standard_metadata.deq_timedelta;
669
+ }
670
+
671
+
672
+ // Actions to keep track of the new metadata added
673
+ action add_1() {
674
+ local_metadata.int_meta.new_words = local_metadata.int_meta.new_words + 1;
675
+ local_metadata.int_meta.new_bytes = local_metadata.int_meta.new_bytes + 4;
676
+ }
677
+
678
+
679
+ action add_2() {
680
+ local_metadata.int_meta.new_words = local_metadata.int_meta.new_words + 2;
681
+ local_metadata.int_meta.new_bytes = local_metadata.int_meta.new_bytes + 8;
682
+ }
683
+
684
+
685
+ action add_3() {
686
+ local_metadata.int_meta.new_words = local_metadata.int_meta.new_words + 3;
687
+ local_metadata.int_meta.new_bytes = local_metadata.int_meta.new_bytes + 12;
688
+ }
689
+
690
+
691
+ action add_4() {
692
+ local_metadata.int_meta.new_words = local_metadata.int_meta.new_words + 4;
693
+ local_metadata.int_meta.new_bytes = local_metadata.int_meta.new_bytes + 16;
694
+ }
695
+
696
+
697
+ action add_5() {
698
+ local_metadata.int_meta.new_words = local_metadata.int_meta.new_words + 5;
699
+ local_metadata.int_meta.new_bytes = local_metadata.int_meta.new_bytes + 20;
700
+ }
701
+
702
+ action add_6() {
703
+ local_metadata.int_meta.new_words = local_metadata.int_meta.new_words + 6;
704
+ local_metadata.int_meta.new_bytes = local_metadata.int_meta.new_bytes + 24;
705
+ }
706
+
707
+ action add_7() {
708
+ local_metadata.int_meta.new_words = local_metadata.int_meta.new_words + 7;
709
+ local_metadata.int_meta.new_bytes = local_metadata.int_meta.new_bytes + 28;
710
+ }
711
+
712
+
713
+ // Action to process instruction bits 0-3
714
+ action int_set_header_0003_i0() {
715
+ }
716
+
717
+ action int_set_header_0003_i1() {
718
+ int_set_header_3();
719
+ add_1();
720
+ }
721
+
722
+ action int_set_header_0003_i2() {
723
+ int_set_header_2();
724
+ add_1();
725
+ }
726
+
727
+ action int_set_header_0003_i3() {
728
+ int_set_header_3();
729
+ int_set_header_2();
730
+ add_2();
731
+ }
732
+
733
+ action int_set_header_0003_i4() {
734
+ int_set_header_1();
735
+ add_1();
736
+ }
737
+
738
+ action int_set_header_0003_i5() {
739
+ int_set_header_3();
740
+ int_set_header_1();
741
+ add_2();
742
+ }
743
+
744
+ action int_set_header_0003_i6() {
745
+ int_set_header_2();
746
+ int_set_header_1();
747
+ add_2();
748
+ }
749
+
750
+ action int_set_header_0003_i7() {
751
+ int_set_header_3();
752
+ int_set_header_2();
753
+ int_set_header_1();
754
+ add_3();
755
+ }
756
+
757
+ action int_set_header_0003_i8() {
758
+ int_set_header_0();
759
+ add_1();
760
+ }
761
+
762
+ action int_set_header_0003_i9() {
763
+ int_set_header_3();
764
+ int_set_header_0();
765
+ add_2();
766
+ }
767
+
768
+ action int_set_header_0003_i10() {
769
+ int_set_header_2();
770
+ int_set_header_0();
771
+ add_2();
772
+ }
773
+
774
+ action int_set_header_0003_i11() {
775
+ int_set_header_3();
776
+ int_set_header_2();
777
+ int_set_header_0();
778
+ add_3();
779
+ }
780
+
781
+ action int_set_header_0003_i12() {
782
+ int_set_header_1();
783
+ int_set_header_0();
784
+ add_2();
785
+ }
786
+
787
+ action int_set_header_0003_i13() {
788
+ int_set_header_3();
789
+ int_set_header_1();
790
+ int_set_header_0();
791
+ add_3();
792
+ }
793
+
794
+ action int_set_header_0003_i14() {
795
+ int_set_header_2();
796
+ int_set_header_1();
797
+ int_set_header_0();
798
+ add_3();
799
+ }
800
+
801
+ action int_set_header_0003_i15() {
802
+ int_set_header_3();
803
+ int_set_header_2();
804
+ int_set_header_1();
805
+ int_set_header_0();
806
+ add_4();
807
+ }
808
+
809
+
810
+ // Action to process instruction bits 4-7
811
+ action int_set_header_0407_i0() {
812
+ }
813
+
814
+ action int_set_header_0407_i1() {
815
+ int_set_header_7();
816
+ add_1();
817
+ }
818
+
819
+ action int_set_header_0407_i2() {
820
+ int_set_header_6();
821
+ add_2();
822
+ }
823
+
824
+ action int_set_header_0407_i3() {
825
+ int_set_header_7();
826
+ int_set_header_6();
827
+ add_3();
828
+ }
829
+
830
+ action int_set_header_0407_i4() {
831
+ int_set_header_5();
832
+ add_2();
833
+ }
834
+
835
+ action int_set_header_0407_i5() {
836
+ int_set_header_7();
837
+ int_set_header_5();
838
+ add_3();
839
+ }
840
+
841
+ action int_set_header_0407_i6() {
842
+ int_set_header_6();
843
+ int_set_header_5();
844
+ add_4();
845
+ }
846
+
847
+ action int_set_header_0407_i7() {
848
+ int_set_header_7();
849
+ int_set_header_6();
850
+ int_set_header_5();
851
+ add_5();
852
+ }
853
+
854
+ action int_set_header_0407_i8() {
855
+ int_set_header_4();
856
+ add_2();
857
+ }
858
+
859
+ action int_set_header_0407_i9() {
860
+ int_set_header_7();
861
+ int_set_header_4();
862
+ add_3();
863
+ }
864
+
865
+ action int_set_header_0407_i10() {
866
+ int_set_header_6();
867
+ int_set_header_4();
868
+ add_4();
869
+ }
870
+
871
+ action int_set_header_0407_i11() {
872
+ int_set_header_7();
873
+ int_set_header_6();
874
+ int_set_header_4();
875
+ add_5();
876
+ }
877
+
878
+ action int_set_header_0407_i12() {
879
+ int_set_header_5();
880
+ int_set_header_4();
881
+ add_4();
882
+ }
883
+
884
+ action int_set_header_0407_i13() {
885
+ int_set_header_7();
886
+ int_set_header_5();
887
+ int_set_header_4();
888
+ add_5();
889
+ }
890
+
891
+ action int_set_header_0407_i14() {
892
+ int_set_header_6();
893
+ int_set_header_5();
894
+ int_set_header_4();
895
+ add_6();
896
+ }
897
+
898
+ action int_set_header_0407_i15() {
899
+ int_set_header_7();
900
+ int_set_header_6();
901
+ int_set_header_5();
902
+ int_set_header_4();
903
+ add_7();
904
+ }
905
+
906
+
907
+ // Default action used to set node ID.
908
+ table tb_int_insert {
909
+ actions = {
910
+ init_metadata;
911
+ NoAction;
912
+ }
913
+ default_action = init_metadata(0);
914
+ size = 1;
915
+ }
916
+
917
+
918
+ // Table to process instruction bits 0-3
919
+ table tb_int_inst_0003 {
920
+ key = {
921
+ hdr.int_header.instruction_mask_0003 : exact;
922
+ }
923
+ actions = {
924
+ int_set_header_0003_i0;
925
+ int_set_header_0003_i1;
926
+ int_set_header_0003_i2;
927
+ int_set_header_0003_i3;
928
+ int_set_header_0003_i4;
929
+ int_set_header_0003_i5;
930
+ int_set_header_0003_i6;
931
+ int_set_header_0003_i7;
932
+ int_set_header_0003_i8;
933
+ int_set_header_0003_i9;
934
+ int_set_header_0003_i10;
935
+ int_set_header_0003_i11;
936
+ int_set_header_0003_i12;
937
+ int_set_header_0003_i13;
938
+ int_set_header_0003_i14;
939
+ int_set_header_0003_i15;
940
+ }
941
+
942
+ const entries = {
943
+ (0x0) : int_set_header_0003_i0();
944
+ (0x1) : int_set_header_0003_i1();
945
+ (0x2) : int_set_header_0003_i2();
946
+ (0x3) : int_set_header_0003_i3();
947
+ (0x4) : int_set_header_0003_i4();
948
+ (0x5) : int_set_header_0003_i5();
949
+ (0x6) : int_set_header_0003_i6();
950
+ (0x7) : int_set_header_0003_i7();
951
+ (0x8) : int_set_header_0003_i8();
952
+ (0x9) : int_set_header_0003_i9();
953
+ (0xA) : int_set_header_0003_i10();
954
+ (0xB) : int_set_header_0003_i11();
955
+ (0xC) : int_set_header_0003_i12();
956
+ (0xD) : int_set_header_0003_i13();
957
+ (0xE) : int_set_header_0003_i14();
958
+ (0xF) : int_set_header_0003_i15();
959
+ }
960
+ }
961
+
962
+
963
+ // Table to process instruction bits 4-7
964
+ table tb_int_inst_0407 {
965
+ key = {
966
+ hdr.int_header.instruction_mask_0407 : exact;
967
+ }
968
+ actions = {
969
+ int_set_header_0407_i0;
970
+ int_set_header_0407_i1;
971
+ int_set_header_0407_i2;
972
+ int_set_header_0407_i3;
973
+ int_set_header_0407_i4;
974
+ int_set_header_0407_i5;
975
+ int_set_header_0407_i6;
976
+ int_set_header_0407_i7;
977
+ int_set_header_0407_i8;
978
+ int_set_header_0407_i9;
979
+ int_set_header_0407_i10;
980
+ int_set_header_0407_i11;
981
+ int_set_header_0407_i12;
982
+ int_set_header_0407_i13;
983
+ int_set_header_0407_i14;
984
+ int_set_header_0407_i15;
985
+ }
986
+
987
+ const entries = {
988
+ (0x0) : int_set_header_0407_i0();
989
+ (0x1) : int_set_header_0407_i1();
990
+ (0x2) : int_set_header_0407_i2();
991
+ (0x3) : int_set_header_0407_i3();
992
+ (0x4) : int_set_header_0407_i4();
993
+ (0x5) : int_set_header_0407_i5();
994
+ (0x6) : int_set_header_0407_i6();
995
+ (0x7) : int_set_header_0407_i7();
996
+ (0x8) : int_set_header_0407_i8();
997
+ (0x9) : int_set_header_0407_i9();
998
+ (0xA) : int_set_header_0407_i10();
999
+ (0xB) : int_set_header_0407_i11();
1000
+ (0xC) : int_set_header_0407_i12();
1001
+ (0xD) : int_set_header_0407_i13();
1002
+ (0xE) : int_set_header_0407_i14();
1003
+ (0xF) : int_set_header_0407_i15();
1004
+ }
1005
+ }
1006
+
1007
+ apply {
1008
+ tb_int_insert.apply();
1009
+
1010
+ tb_int_inst_0003.apply();
1011
+ tb_int_inst_0407.apply();
1012
+
1013
+
1014
+ // Decrement remaining hop cnt
1015
+ hdr.int_header.remaining_hop_cnt = hdr.int_header.remaining_hop_cnt - 1;
1016
+
1017
+
1018
+ // Update headers lengths.
1019
+ if (hdr.ipv4.isValid()) {
1020
+ hdr.ipv4.len = hdr.ipv4.len + local_metadata.int_meta.new_bytes;
1021
+ }
1022
+ if (hdr.udp.isValid()) {
1023
+ hdr.udp.length_ = hdr.udp.length_ + local_metadata.int_meta.new_bytes;
1024
+ }
1025
+ if (hdr.intl4_shim.isValid()) {
1026
+ hdr.intl4_shim.len = hdr.intl4_shim.len + local_metadata.int_meta.new_words;
1027
+ }
1028
+ }
1029
+ }
1030
+
1031
+ control process_int_source_sink (
1032
+ inout headers hdr,
1033
+ inout local_metadata_t local_metadata,
1034
+ inout standard_metadata_t standard_metadata) {
1035
+
1036
+ action int_set_source () {
1037
+ local_metadata.int_meta.source = true;
1038
+ }
1039
+
1040
+ action int_set_sink () {
1041
+ local_metadata.int_meta.sink = true;
1042
+ }
1043
+
1044
+ table tb_set_source {
1045
+ key = {
1046
+ standard_metadata.ingress_port: exact;
1047
+ }
1048
+ actions = {
1049
+ int_set_source;
1050
+ NoAction();
1051
+ }
1052
+ const default_action = NoAction();
1053
+ size = MAX_PORTS;
1054
+ }
1055
+
1056
+ table tb_set_sink {
1057
+ key = {
1058
+ standard_metadata.egress_port: exact;
1059
+ }
1060
+ actions = {
1061
+ int_set_sink;
1062
+ NoAction();
1063
+ }
1064
+ const default_action = NoAction();
1065
+ size = MAX_PORTS;
1066
+ }
1067
+
1068
+ apply {
1069
+ tb_set_source.apply();
1070
+ tb_set_sink.apply();
1071
+ }
1072
+ }
1073
+
1074
+
1075
+ // Insert INT header to the packet
1076
+ control process_int_source (
1077
+ inout headers hdr,
1078
+ inout local_metadata_t local_metadata) {
1079
+
1080
+ action int_source(bit<5> hop_metadata_len, bit<8> remaining_hop_cnt, bit<4> ins_mask0003, bit<4> ins_mask0407) {
1081
+
1082
+ hdr.intl4_shim.setValid();
1083
+
1084
+ // insert INT shim header
1085
+ hdr.intl4_shim.int_type = 1;
1086
+
1087
+ // INT type: MD-type (1) , destination type (2), MX-type (3)
1088
+ hdr.intl4_shim.npt = 0;
1089
+
1090
+ // next protocol type: 0
1091
+ hdr.intl4_shim.len = 3;
1092
+
1093
+ hdr.intl4_shim.original_dscp = hdr.ipv4.dscp;
1094
+
1095
+ // original DSCP
1096
+
1097
+
1098
+ // insert INT header
1099
+ hdr.int_header.setValid();
1100
+ hdr.int_header.ver = 2;
1101
+
1102
+ // INT 2.1
1103
+ hdr.int_header.d = 0;
1104
+ hdr.int_header.hop_metadata_len = hop_metadata_len;
1105
+ hdr.int_header.remaining_hop_cnt = remaining_hop_cnt;
1106
+ hdr.int_header.instruction_mask_0003 = ins_mask0003;
1107
+ hdr.int_header.instruction_mask_0407 = ins_mask0407;
1108
+ hdr.int_header.instruction_mask_0811 = 0;
1109
+
1110
+ // bit 8 is buffer related (not yet implemented), rest are reserved
1111
+ hdr.int_header.instruction_mask_1215 = 0;
1112
+
1113
+ // reserved
1114
+
1115
+ hdr.int_header.domain_specific_id = 0;
1116
+
1117
+ // Unique INT Domain ID (not yet implemented)
1118
+ hdr.int_header.ds_instruction = 0;
1119
+
1120
+ // Instruction bitmap specific to the INT Domain identified by the Domain specific ID (not yet implemented)
1121
+ hdr.int_header.ds_flags = 0;
1122
+
1123
+ // Domain specific flags (not yet implemented)
1124
+
1125
+
1126
+ // add the header len (3 words) to total len
1127
+ hdr.ipv4.len = hdr.ipv4.len + INT_TOTAL_HEADER_SIZE;
1128
+ if(hdr.udp.isValid()) {
1129
+ hdr.udp.length_ = hdr.udp.length_ + INT_TOTAL_HEADER_SIZE;
1130
+ }
1131
+
1132
+ hdr.ipv4.dscp = DSCP_INT;
1133
+ }
1134
+
1135
+ table tb_int_source {
1136
+ key = {
1137
+
1138
+ hdr.ipv4.dst_addr: lpm;
1139
+ }
1140
+ actions = {
1141
+ int_source;
1142
+ NoAction;
1143
+ }
1144
+ const default_action = NoAction();
1145
+ }
1146
+
1147
+ apply {
1148
+ tb_int_source.apply();
1149
+ }
1150
+ }
1151
+
1152
+ control l3_forward(inout headers hdr,
1153
+ inout local_metadata_t local_metadata,
1154
+ inout standard_metadata_t standard_metadata) {
1155
+
1156
+ action drop() {
1157
+ mark_to_drop(standard_metadata);
1158
+ }
1159
+
1160
+ action ipv4_forward(mac_t dstAddr, mac_t srcAddr, port_t port) {
1161
+ standard_metadata.egress_spec = port;
1162
+ standard_metadata.egress_port = port;
1163
+ hdr.ethernet.src_addr = srcAddr;
1164
+ hdr.ethernet.dst_addr = dstAddr;
1165
+ hdr.ipv4.ttl = hdr.ipv4.ttl - 1;
1166
+ }
1167
+
1168
+ table ipv4_lpm {
1169
+ key = {
1170
+ hdr.ipv4.dst_addr : lpm;
1171
+ }
1172
+ actions = {
1173
+ ipv4_forward;
1174
+ drop;
1175
+ }
1176
+ size = 1024;
1177
+ const default_action = drop();
1178
+ }
1179
+
1180
+ apply {
1181
+ if(hdr.ipv4.ttl == 0) {
1182
+ drop();
1183
+ }
1184
+ if(hdr.ipv4.isValid()) {
1185
+ ipv4_lpm.apply();
1186
+ }
1187
+
1188
+ }
1189
+ }
1190
+
1191
+
1192
+
1193
+
1194
+ control MyIngress(inout headers hdr,
1195
+ inout local_metadata_t local_metadata,
1196
+ inout standard_metadata_t standard_metadata) {
1197
+
1198
+ apply {
1199
+ if(hdr.ipv4.isValid()) {
1200
+
1201
+
1202
+ // Perform L2 forwarding based on IPv4 destination address
1203
+ l3_forward.apply(hdr, local_metadata, standard_metadata);
1204
+
1205
+ if (hdr.udp.isValid() || hdr.tcp.isValid()) {
1206
+
1207
+
1208
+ // Setting source and sink local metadata
1209
+ process_int_source_sink.apply(hdr, local_metadata, standard_metadata);
1210
+
1211
+
1212
+ // In case of source add the INT header
1213
+ if (local_metadata.int_meta.source == true) {
1214
+ process_int_source.apply(hdr, local_metadata);
1215
+ }
1216
+
1217
+
1218
+ // Clone packet for Telemetry Report
1219
+ if (local_metadata.int_meta.sink == true && hdr.int_header.isValid()) {
1220
+ local_metadata.perserv_meta.ingress_port = standard_metadata.ingress_port;
1221
+ local_metadata.perserv_meta.egress_port = standard_metadata.egress_port;
1222
+ local_metadata.perserv_meta.deq_qdepth = standard_metadata.deq_qdepth;
1223
+ local_metadata.perserv_meta.deq_timedelta = standard_metadata.deq_timedelta;
1224
+ local_metadata.perserv_meta.ingress_global_timestamp = standard_metadata.ingress_global_timestamp;
1225
+ local_metadata.perserv_meta.egress_global_timestamp = standard_metadata.egress_global_timestamp;
1226
+ clone_preserving_field_list(CloneType.I2E, REPORT_MIRROR_SESSION_ID, 1);
1227
+
1228
+ }
1229
+ }
1230
+ }
1231
+ }
1232
+ }
1233
+
1234
+
1235
+
1236
+ control MyEgress(inout headers hdr,
1237
+ inout local_metadata_t local_metadata,
1238
+ inout standard_metadata_t standard_metadata) {
1239
+
1240
+ apply {
1241
+
1242
+ // Insert old packet metadata into the cloned packet
1243
+ if(hdr.int_header.isValid() && standard_metadata.instance_type == CLONE_PKT) {
1244
+ standard_metadata.ingress_port = local_metadata.perserv_meta.ingress_port;
1245
+ standard_metadata.egress_port = local_metadata.perserv_meta.egress_port;
1246
+ standard_metadata.deq_qdepth = local_metadata.perserv_meta.deq_qdepth;
1247
+ standard_metadata.deq_timedelta = local_metadata.perserv_meta.deq_timedelta;
1248
+ standard_metadata.ingress_global_timestamp = local_metadata.perserv_meta.ingress_global_timestamp;
1249
+ standard_metadata.egress_global_timestamp = local_metadata.perserv_meta.egress_global_timestamp;
1250
+ }
1251
+
1252
+ process_int_transit.apply(hdr, local_metadata, standard_metadata);
1253
+
1254
+
1255
+ // In case of cloned packet, send telemetry report
1256
+ if (standard_metadata.instance_type == CLONE_PKT) {
1257
+ process_int_report.apply(hdr, local_metadata, standard_metadata);
1258
+ }
1259
+
1260
+
1261
+ // In case of sink, remove INT header from original packet
1262
+ if (hdr.int_header.isValid() && local_metadata.int_meta.sink == true && standard_metadata.instance_type != CLONE_PKT) {
1263
+ process_int_sink.apply(hdr);
1264
+ }
1265
+ }
1266
+ }
1267
+
1268
+
1269
+
1270
+ V1Switch(
1271
+ MyParser(),
1272
+ MyVerifyChecksum(),
1273
+ MyIngress(),
1274
+ MyEgress(),
1275
+ MyComputeChecksum(),
1276
+ MyDeparser()
1277
+ ) main;
individual_files/000055__raw-repositories__felipejrampazzo__Projeto-IA376C.p4 ADDED
@@ -0,0 +1,618 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ #include <core.p4>
3
+ #include <v1model.p4>
4
+
5
+ #define DIMENSION 4
6
+
7
+ register<bit<32>>(20) register_pub_matrix;
8
+ register<bit<32>>(10) register_secret_vector;
9
+ register<bit<32>>(10) register_noise_vector;
10
+ register<bit<32>>(10) register_public_vector;
11
+ register<bit<32>>(36) register_public_vector_full;
12
+ register<bit<32>>(18) register_mod_public_vector;
13
+ register <bit<32>>(4) register_seed;
14
+
15
+
16
+ header ethernet_t {
17
+ bit<48> dstAddr;
18
+ bit<48> srcAddr;
19
+ bit<16> etherType;
20
+ }
21
+
22
+
23
+ const bit<16> P4CALC_ETYPE = 0x1234;
24
+ const bit<8> P4CALC_P = 0x4B;
25
+
26
+ // K - KYBER
27
+ const bit<8> GEN = 0x47;
28
+
29
+ // 'G'
30
+ const bit<8> ENC = 0x45;
31
+
32
+ // 'E'
33
+ const bit<8> DEC = 0x44;
34
+
35
+ // 'D'
36
+ const bit<32> PARAM_Q = 3329;
37
+
38
+ header p4calc_t {
39
+ bit<8> p;
40
+ bit<8> op;
41
+
42
+ bit<32> t_0;
43
+ bit<32> t_1;
44
+ bit<32> t_2;
45
+ bit<32> t_3;
46
+ bit<32> t_4;
47
+ bit<32> t_5;
48
+ bit<32> t_6;
49
+ bit<32> t_7;
50
+ bit<32> t_8;
51
+ bit<32> t_9;
52
+
53
+ bit<32> seed;
54
+ }
55
+
56
+
57
+ struct headers {
58
+ ethernet_t ethernet;
59
+ p4calc_t p4calc;
60
+ }
61
+
62
+
63
+ struct metadata {
64
+
65
+ /* In our case it is empty */
66
+ }
67
+
68
+
69
+ parser MyParser(packet_in packet,
70
+ out headers hdr,
71
+ inout metadata meta,
72
+ inout standard_metadata_t standard_metadata) {
73
+
74
+ state start {
75
+ packet.extract(hdr.ethernet);
76
+ transition select(hdr.ethernet.etherType) {
77
+ P4CALC_ETYPE : check_p4calc;
78
+ default : accept;
79
+ }
80
+ }
81
+
82
+ state check_p4calc {
83
+ transition select(packet.lookahead<p4calc_t>().p) {
84
+ (P4CALC_P) : parse_p4calc;
85
+ default : accept;
86
+ }
87
+ }
88
+
89
+ state parse_p4calc {
90
+ packet.extract(hdr.p4calc);
91
+ transition accept;
92
+ }
93
+ }
94
+
95
+
96
+ control MyVerifyChecksum(inout headers hdr,
97
+ inout metadata meta) {
98
+ apply { }
99
+ }
100
+
101
+
102
+ control MyIngress(inout headers hdr,
103
+ inout metadata meta,
104
+ inout standard_metadata_t standard_metadata) {
105
+
106
+ action send_back() {
107
+ bit<48> tmp;
108
+
109
+ tmp = hdr.ethernet.dstAddr;
110
+ hdr.ethernet.dstAddr = hdr.ethernet.srcAddr;
111
+ hdr.ethernet.srcAddr = tmp;
112
+
113
+
114
+ /* Send the packet back to the port it came from */
115
+ standard_metadata.egress_spec = standard_metadata.ingress_port;
116
+ }
117
+
118
+ #define gen_matrix(INDEX, ROUND) action gen_matrix_i##INDEX##_r##ROUND##() { \
119
+ bit<32> coef; \
120
+ register_seed.read(coef, 0); \
121
+ hash(coef, HashAlgorithm.crc32, (bit<32>) 0, {coef}, (bit<32>) PARAM_Q); \
122
+ register_pub_matrix.write(##INDEX##, coef); \
123
+ register_seed.write(0, coef); \
124
+ }
125
+ gen_matrix(0, 1)
126
+ gen_matrix(1, 1)
127
+ gen_matrix(2, 1)
128
+ gen_matrix(3, 1)
129
+ gen_matrix(4, 1)
130
+ gen_matrix(5, 1)
131
+ gen_matrix(6, 1)
132
+ gen_matrix(7, 1)
133
+ gen_matrix(8, 1)
134
+ gen_matrix(9, 1)
135
+ gen_matrix(10, 1)
136
+ gen_matrix(11, 1)
137
+ gen_matrix(12, 1)
138
+ gen_matrix(13, 1)
139
+ gen_matrix(14, 1)
140
+ gen_matrix(15, 1)
141
+ gen_matrix(16, 1)
142
+ gen_matrix(17, 1)
143
+ gen_matrix(18, 1)
144
+ gen_matrix(19, 1)
145
+
146
+
147
+ #define gen_secret_vector(INDEX) action gen_secret_vector_i##INDEX##() { \
148
+ bit<32> coef; \
149
+ random(coef, 1, 4); \
150
+ register_secret_vector.write(##INDEX##, coef); \
151
+ }
152
+ gen_secret_vector(0)
153
+ gen_secret_vector(1)
154
+ gen_secret_vector(2)
155
+ gen_secret_vector(3)
156
+ gen_secret_vector(4)
157
+ gen_secret_vector(5)
158
+ gen_secret_vector(6)
159
+ gen_secret_vector(7)
160
+ gen_secret_vector(8)
161
+ gen_secret_vector(9)
162
+
163
+
164
+ #define gen_noise_vector(INDEX) action gen_noise_vector_i##INDEX##() { \
165
+ bit<32> coef; \
166
+ random(coef, 1, 4); \
167
+ register_noise_vector.write(##INDEX##, coef); \
168
+ }
169
+ gen_noise_vector(0)
170
+ gen_noise_vector(1)
171
+ gen_noise_vector(2)
172
+ gen_noise_vector(3)
173
+ gen_noise_vector(4)
174
+ gen_noise_vector(5)
175
+ gen_noise_vector(6)
176
+ gen_noise_vector(7)
177
+ gen_noise_vector(8)
178
+ gen_noise_vector(9)
179
+
180
+
181
+ #define matrix_mult(I_A, I_SU, I_TU) action matrix_mult_ia##I_A##_isr##I_SU##_itu##I_TU##() { \
182
+ bit<32> a; \
183
+ bit<32> s_r; \
184
+ bit<32> t_u; \
185
+ bit<32> temp; \
186
+ register_pub_matrix.read(a, ##I_A##); \
187
+ register_secret_vector.read(s_r, ##I_SU##); \
188
+ register_public_vector_full.read(t_u, ##I_TU##); \
189
+ temp = (a * s_r) + t_u; \
190
+ register_public_vector_full.write(##I_TU##, temp); \
191
+ }
192
+ matrix_mult(0, 0, 0)
193
+ matrix_mult(0, 1, 1)
194
+ matrix_mult(0, 2, 2)
195
+ matrix_mult(0, 3, 3)
196
+ matrix_mult(0, 4, 4)
197
+ matrix_mult(1, 0, 1)
198
+ matrix_mult(1, 1, 2)
199
+ matrix_mult(1, 2, 3)
200
+ matrix_mult(1, 3, 4)
201
+ matrix_mult(1, 4, 5)
202
+ matrix_mult(2, 0, 2)
203
+ matrix_mult(2, 1, 3)
204
+ matrix_mult(2, 2, 4)
205
+ matrix_mult(2, 3, 5)
206
+ matrix_mult(2, 4, 6)
207
+ matrix_mult(3, 0, 3)
208
+ matrix_mult(3, 1, 4)
209
+ matrix_mult(3, 2, 5)
210
+ matrix_mult(3, 3, 6)
211
+ matrix_mult(3, 4, 7)
212
+ matrix_mult(4, 0, 4)
213
+ matrix_mult(4, 1, 5)
214
+ matrix_mult(4, 2, 6)
215
+ matrix_mult(4, 3, 7)
216
+ matrix_mult(4, 4, 8)
217
+ matrix_mult(5, 5, 9)
218
+ matrix_mult(5, 6, 10)
219
+ matrix_mult(5, 7, 11)
220
+ matrix_mult(5, 8, 12)
221
+ matrix_mult(5, 9, 13)
222
+ matrix_mult(6, 5, 10)
223
+ matrix_mult(6, 6, 11)
224
+ matrix_mult(6, 7, 12)
225
+ matrix_mult(6, 8, 13)
226
+ matrix_mult(6, 9, 14)
227
+ matrix_mult(7, 5, 11)
228
+ matrix_mult(7, 6, 12)
229
+ matrix_mult(7, 7, 13)
230
+ matrix_mult(7, 8, 14)
231
+ matrix_mult(7, 9, 15)
232
+ matrix_mult(8, 5, 12)
233
+ matrix_mult(8, 6, 13)
234
+ matrix_mult(8, 7, 14)
235
+ matrix_mult(8, 8, 15)
236
+ matrix_mult(8, 9, 16)
237
+ matrix_mult(9, 5, 13)
238
+ matrix_mult(9, 6, 14)
239
+ matrix_mult(9, 7, 15)
240
+ matrix_mult(9, 8, 16)
241
+ matrix_mult(9, 9, 17)
242
+ matrix_mult(10, 0, 18)
243
+ matrix_mult(10, 1, 19)
244
+ matrix_mult(10, 2, 20)
245
+ matrix_mult(10, 3, 21)
246
+ matrix_mult(10, 4, 22)
247
+ matrix_mult(11, 0, 19)
248
+ matrix_mult(11, 1, 20)
249
+ matrix_mult(11, 2, 21)
250
+ matrix_mult(11, 3, 22)
251
+ matrix_mult(11, 4, 23)
252
+ matrix_mult(12, 0, 20)
253
+ matrix_mult(12, 1, 21)
254
+ matrix_mult(12, 2, 22)
255
+ matrix_mult(12, 3, 23)
256
+ matrix_mult(12, 4, 24)
257
+ matrix_mult(13, 0, 21)
258
+ matrix_mult(13, 1, 22)
259
+ matrix_mult(13, 2, 23)
260
+ matrix_mult(13, 3, 24)
261
+ matrix_mult(13, 4, 25)
262
+ matrix_mult(14, 0, 22)
263
+ matrix_mult(14, 1, 23)
264
+ matrix_mult(14, 2, 24)
265
+ matrix_mult(14, 3, 25)
266
+ matrix_mult(14, 4, 26)
267
+ matrix_mult(15, 5, 27)
268
+ matrix_mult(15, 6, 28)
269
+ matrix_mult(15, 7, 29)
270
+ matrix_mult(15, 8, 30)
271
+ matrix_mult(15, 9, 31)
272
+ matrix_mult(16, 5, 28)
273
+ matrix_mult(16, 6, 29)
274
+ matrix_mult(16, 7, 30)
275
+ matrix_mult(16, 8, 31)
276
+ matrix_mult(16, 9, 32)
277
+ matrix_mult(17, 5, 29)
278
+ matrix_mult(17, 6, 30)
279
+ matrix_mult(17, 7, 31)
280
+ matrix_mult(17, 8, 32)
281
+ matrix_mult(17, 9, 33)
282
+ matrix_mult(18, 5, 30)
283
+ matrix_mult(18, 6, 31)
284
+ matrix_mult(18, 7, 32)
285
+ matrix_mult(18, 8, 33)
286
+ matrix_mult(18, 9, 34)
287
+ matrix_mult(19, 5, 31)
288
+ matrix_mult(19, 6, 32)
289
+ matrix_mult(19, 7, 33)
290
+ matrix_mult(19, 8, 34)
291
+ matrix_mult(19, 9, 35)
292
+
293
+
294
+ #define poly_pub_add(X, Y, Z) action poly_pub_add_##X##_##Y##_##Z##() { \
295
+ bit<32> x; \
296
+ bit<32> y; \
297
+ bit<32> sum; \
298
+ register_public_vector_full.read(x, ##X##); \
299
+ register_public_vector_full.read(y, ##Y##); \
300
+ sum = x + y; \
301
+ register_mod_public_vector.write(##Z##, sum); \
302
+ }
303
+ poly_pub_add(0, 9, 0)
304
+ poly_pub_add(1, 10, 1)
305
+ poly_pub_add(2, 11, 2)
306
+ poly_pub_add(3, 12, 3)
307
+ poly_pub_add(4, 13, 4)
308
+ poly_pub_add(5, 14, 5)
309
+ poly_pub_add(6, 15, 6)
310
+ poly_pub_add(7, 16, 7)
311
+ poly_pub_add(8, 17, 8)
312
+ poly_pub_add(18, 27, 9)
313
+ poly_pub_add(19, 28, 10)
314
+ poly_pub_add(20, 29, 11)
315
+ poly_pub_add(21, 30, 12)
316
+ poly_pub_add(22, 31, 13)
317
+ poly_pub_add(23, 32, 14)
318
+ poly_pub_add(24, 33, 15)
319
+ poly_pub_add(25, 34, 16)
320
+ poly_pub_add(26, 35, 17)
321
+
322
+ #define poly_mod(X, Y, Z) action poly_mod_##X##_##Y##_##Z##() { \
323
+ bit<32> x; \
324
+ bit<32> y; \
325
+ bit<32> e; \
326
+ bit<32> minus; \
327
+ register_mod_public_vector.read(x, ##X##); \
328
+ if (##Y## == 100){ \
329
+ y = 0; \
330
+ } \
331
+ else{ \
332
+ register_mod_public_vector.read(y, ##Y##); \
333
+ } \
334
+ hash(x, HashAlgorithm.identity, (bit<32>) 0, {x}, (bit<32>) PARAM_Q); \
335
+ hash(y, HashAlgorithm.identity, (bit<32>) 0, {y}, (bit<32>) PARAM_Q); \
336
+ if (x < y){ \
337
+ x = x + PARAM_Q; \
338
+ } \
339
+ minus = x - y; \
340
+ register_noise_vector.read(e, ##Z##); \
341
+ minus = minus + e; \
342
+ hash(minus, HashAlgorithm.identity, (bit<32>) 0, {minus}, (bit<32>) PARAM_Q); \
343
+ register_public_vector.write(##Z##, minus); \
344
+ hdr.p4calc.t_##Z## = minus; \
345
+ }
346
+ poly_mod(4, 100, 0)
347
+ poly_mod(5, 0, 1)
348
+ poly_mod(6, 1, 2)
349
+ poly_mod(7, 2, 3)
350
+ poly_mod(8, 3, 4)
351
+ poly_mod(13, 100, 5)
352
+ poly_mod(14, 9, 6)
353
+ poly_mod(15, 10, 7)
354
+ poly_mod(16, 11, 8)
355
+ poly_mod(17, 12, 9)
356
+
357
+
358
+ action gen_keys() {
359
+ register_seed.write(0, hdr.p4calc.seed);
360
+ gen_matrix_i0_r1();
361
+ gen_matrix_i1_r1();
362
+ gen_matrix_i2_r1();
363
+ gen_matrix_i3_r1();
364
+ gen_matrix_i4_r1();
365
+ gen_matrix_i5_r1();
366
+ gen_matrix_i6_r1();
367
+ gen_matrix_i7_r1();
368
+ gen_matrix_i8_r1();
369
+ gen_matrix_i9_r1();
370
+ gen_matrix_i10_r1();
371
+ gen_matrix_i11_r1();
372
+ gen_matrix_i12_r1();
373
+ gen_matrix_i13_r1();
374
+ gen_matrix_i14_r1();
375
+ gen_matrix_i15_r1();
376
+ gen_matrix_i16_r1();
377
+ gen_matrix_i17_r1();
378
+ gen_matrix_i18_r1();
379
+ gen_matrix_i19_r1();
380
+
381
+ gen_secret_vector_i0();
382
+ gen_secret_vector_i1();
383
+ gen_secret_vector_i2();
384
+ gen_secret_vector_i3();
385
+ gen_secret_vector_i4();
386
+ gen_secret_vector_i5();
387
+ gen_secret_vector_i6();
388
+ gen_secret_vector_i7();
389
+ gen_secret_vector_i8();
390
+ gen_secret_vector_i9();
391
+
392
+ gen_noise_vector_i0();
393
+ gen_noise_vector_i1();
394
+ gen_noise_vector_i2();
395
+ gen_noise_vector_i3();
396
+ gen_noise_vector_i4();
397
+ gen_noise_vector_i5();
398
+ gen_noise_vector_i6();
399
+ gen_noise_vector_i7();
400
+ gen_noise_vector_i8();
401
+ gen_noise_vector_i9();
402
+
403
+ matrix_mult_ia0_isr0_itu0();
404
+ matrix_mult_ia0_isr1_itu1();
405
+ matrix_mult_ia0_isr2_itu2();
406
+ matrix_mult_ia0_isr3_itu3();
407
+ matrix_mult_ia0_isr4_itu4();
408
+ matrix_mult_ia1_isr0_itu1();
409
+ matrix_mult_ia1_isr1_itu2();
410
+ matrix_mult_ia1_isr2_itu3();
411
+ matrix_mult_ia1_isr3_itu4();
412
+ matrix_mult_ia1_isr4_itu5();
413
+ matrix_mult_ia2_isr0_itu2();
414
+ matrix_mult_ia2_isr1_itu3();
415
+ matrix_mult_ia2_isr2_itu4();
416
+ matrix_mult_ia2_isr3_itu5();
417
+ matrix_mult_ia2_isr4_itu6();
418
+ matrix_mult_ia3_isr0_itu3();
419
+ matrix_mult_ia3_isr1_itu4();
420
+ matrix_mult_ia3_isr2_itu5();
421
+ matrix_mult_ia3_isr3_itu6();
422
+ matrix_mult_ia3_isr4_itu7();
423
+ matrix_mult_ia4_isr0_itu4();
424
+ matrix_mult_ia4_isr1_itu5();
425
+ matrix_mult_ia4_isr2_itu6();
426
+ matrix_mult_ia4_isr3_itu7();
427
+ matrix_mult_ia4_isr4_itu8();
428
+
429
+ matrix_mult_ia5_isr5_itu9();
430
+ matrix_mult_ia5_isr6_itu10();
431
+ matrix_mult_ia5_isr7_itu11();
432
+ matrix_mult_ia5_isr8_itu12();
433
+ matrix_mult_ia5_isr9_itu13();
434
+ matrix_mult_ia6_isr5_itu10();
435
+ matrix_mult_ia6_isr6_itu11();
436
+ matrix_mult_ia6_isr7_itu12();
437
+ matrix_mult_ia6_isr8_itu13();
438
+ matrix_mult_ia6_isr9_itu14();
439
+ matrix_mult_ia7_isr5_itu11();
440
+ matrix_mult_ia7_isr6_itu12();
441
+ matrix_mult_ia7_isr7_itu13();
442
+ matrix_mult_ia7_isr8_itu14();
443
+ matrix_mult_ia7_isr9_itu15();
444
+ matrix_mult_ia8_isr5_itu12();
445
+ matrix_mult_ia8_isr6_itu13();
446
+ matrix_mult_ia8_isr7_itu14();
447
+ matrix_mult_ia8_isr8_itu15();
448
+ matrix_mult_ia8_isr9_itu16();
449
+ matrix_mult_ia9_isr5_itu13();
450
+ matrix_mult_ia9_isr6_itu14();
451
+ matrix_mult_ia9_isr7_itu15();
452
+ matrix_mult_ia9_isr8_itu16();
453
+ matrix_mult_ia9_isr9_itu17();
454
+
455
+ matrix_mult_ia10_isr0_itu18();
456
+ matrix_mult_ia10_isr1_itu19();
457
+ matrix_mult_ia10_isr2_itu20();
458
+ matrix_mult_ia10_isr3_itu21();
459
+ matrix_mult_ia10_isr4_itu22();
460
+ matrix_mult_ia11_isr0_itu19();
461
+ matrix_mult_ia11_isr1_itu20();
462
+ matrix_mult_ia11_isr2_itu21();
463
+ matrix_mult_ia11_isr3_itu22();
464
+ matrix_mult_ia11_isr4_itu23();
465
+ matrix_mult_ia12_isr0_itu20();
466
+ matrix_mult_ia12_isr1_itu21();
467
+ matrix_mult_ia12_isr2_itu22();
468
+ matrix_mult_ia12_isr3_itu23();
469
+ matrix_mult_ia12_isr4_itu24();
470
+ matrix_mult_ia13_isr0_itu21();
471
+ matrix_mult_ia13_isr1_itu22();
472
+ matrix_mult_ia13_isr2_itu23();
473
+ matrix_mult_ia13_isr3_itu24();
474
+ matrix_mult_ia13_isr4_itu25();
475
+ matrix_mult_ia14_isr0_itu22();
476
+ matrix_mult_ia14_isr1_itu23();
477
+ matrix_mult_ia14_isr2_itu24();
478
+ matrix_mult_ia14_isr3_itu25();
479
+ matrix_mult_ia14_isr4_itu26();
480
+
481
+ matrix_mult_ia15_isr5_itu27();
482
+ matrix_mult_ia15_isr6_itu28();
483
+ matrix_mult_ia15_isr7_itu29();
484
+ matrix_mult_ia15_isr8_itu30();
485
+ matrix_mult_ia15_isr9_itu31();
486
+ matrix_mult_ia16_isr5_itu28();
487
+ matrix_mult_ia16_isr6_itu29();
488
+ matrix_mult_ia16_isr7_itu30();
489
+ matrix_mult_ia16_isr8_itu31();
490
+ matrix_mult_ia16_isr9_itu32();
491
+ matrix_mult_ia17_isr5_itu29();
492
+ matrix_mult_ia17_isr6_itu30();
493
+ matrix_mult_ia17_isr7_itu31();
494
+ matrix_mult_ia17_isr8_itu32();
495
+ matrix_mult_ia17_isr9_itu33();
496
+ matrix_mult_ia18_isr5_itu30();
497
+ matrix_mult_ia18_isr6_itu31();
498
+ matrix_mult_ia18_isr7_itu32();
499
+ matrix_mult_ia18_isr8_itu33();
500
+ matrix_mult_ia18_isr9_itu34();
501
+ matrix_mult_ia19_isr5_itu31();
502
+ matrix_mult_ia19_isr6_itu32();
503
+ matrix_mult_ia19_isr7_itu33();
504
+ matrix_mult_ia19_isr8_itu34();
505
+ matrix_mult_ia19_isr9_itu35();
506
+
507
+ poly_pub_add_0_9_0();
508
+ poly_pub_add_1_10_1();
509
+ poly_pub_add_2_11_2();
510
+ poly_pub_add_3_12_3();
511
+ poly_pub_add_4_13_4();
512
+ poly_pub_add_5_14_5();
513
+ poly_pub_add_6_15_6();
514
+ poly_pub_add_7_16_7();
515
+ poly_pub_add_8_17_8();
516
+
517
+ poly_pub_add_18_27_9();
518
+ poly_pub_add_19_28_10();
519
+ poly_pub_add_20_29_11();
520
+ poly_pub_add_21_30_12();
521
+ poly_pub_add_22_31_13();
522
+ poly_pub_add_23_32_14();
523
+ poly_pub_add_24_33_15();
524
+ poly_pub_add_25_34_16();
525
+ poly_pub_add_26_35_17();
526
+
527
+ poly_mod_4_100_0();
528
+ poly_mod_5_0_1();
529
+ poly_mod_6_1_2();
530
+ poly_mod_7_2_3();
531
+ poly_mod_8_3_4();
532
+ poly_mod_13_100_5();
533
+ poly_mod_14_9_6();
534
+ poly_mod_15_10_7();
535
+ poly_mod_16_11_8();
536
+ poly_mod_17_12_9();
537
+
538
+ send_back();
539
+ }
540
+
541
+ action enc() {
542
+
543
+ bit<32> e2;
544
+ random(e2, 0, 4);
545
+ bit<32> m;
546
+ random(m, 0, 2);
547
+
548
+ send_back();
549
+ }
550
+
551
+ action dec() {
552
+
553
+ send_back();
554
+ }
555
+
556
+ action operation_drop() {
557
+ mark_to_drop(standard_metadata);
558
+ }
559
+
560
+ table calculate {
561
+ key = {
562
+ hdr.p4calc.op : exact;
563
+ }
564
+ actions = {
565
+ gen_keys;
566
+ enc;
567
+ dec;
568
+ operation_drop;
569
+ }
570
+ const default_action = operation_drop();
571
+ const entries = {
572
+ GEN : gen_keys();
573
+ ENC: enc();
574
+ DEC : dec();
575
+ }
576
+ }
577
+
578
+
579
+ apply {
580
+ if (hdr.p4calc.isValid()) {
581
+ calculate.apply();
582
+ } else {
583
+ operation_drop();
584
+ }
585
+ }
586
+ }
587
+
588
+
589
+ control MyEgress(inout headers hdr,
590
+ inout metadata meta,
591
+ inout standard_metadata_t standard_metadata) {
592
+ apply { }
593
+ }
594
+
595
+
596
+
597
+ control MyComputeChecksum(inout headers hdr, inout metadata meta) {
598
+ apply { }
599
+ }
600
+
601
+
602
+ control MyDeparser(packet_out packet, in headers hdr) {
603
+ apply {
604
+ packet.emit(hdr.ethernet);
605
+ packet.emit(hdr.p4calc);
606
+ }
607
+ }
608
+
609
+
610
+
611
+ V1Switch(
612
+ MyParser(),
613
+ MyVerifyChecksum(),
614
+ MyIngress(),
615
+ MyEgress(),
616
+ MyComputeChecksum(),
617
+ MyDeparser()
618
+ ) main;
individual_files/000056__raw-repositories__f-555__Lemon.p4 ADDED
@@ -0,0 +1,278 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <core.p4>
2
+ #include <v1model.p4>
3
+
4
+ #define HASH_THRESHOLD 1288490189
5
+
6
+ #define BLOOM_SIZE 65536
7
+ #define PKT_INSTANCE_TYPE_NORMAL 0
8
+ #define PKT_INSTANCE_TYPE_INGRESS_CLONE 1
9
+ #define PKT_INSTANCE_TYPE_EGRESS_CLONE 2
10
+ #define PKT_INSTANCE_TYPE_COALESCED 3
11
+ #define PKT_INSTANCE_TYPE_INGRESS_RECIRC 4
12
+ #define PKT_INSTANCE_TYPE_REPLICATION 5
13
+ #define PKT_INSTANCE_TYPE_RESUBMIT 6
14
+
15
+ const bit<16> TYPE_IPV4 = 0x0800;
16
+ const bit<16> VirtualLAN= 0x8100;
17
+
18
+ typedef bit<9> egressSpec_t;
19
+ typedef bit<48> macAddr_t;
20
+ typedef bit<32> ip4Addr_t;
21
+
22
+ typedef bit<16> ether_type_t;
23
+ const ether_type_t ETHERTYPE_IPV4 = 16w0x0800;
24
+ const ether_type_t ETHERTYPE_ARP = 16w0x0806;
25
+ const ether_type_t ETHERTYPE_IPV6 = 16w0x86dd;
26
+ const ether_type_t ETHERTYPE_VLAN = 16w0x8100;
27
+
28
+ typedef bit<8> ip_protocol_t;
29
+ const ip_protocol_t IP_PROTOCOLS_ICMP = 1;
30
+ const ip_protocol_t IP_PROTOCOLS_TCP = 6;
31
+ const ip_protocol_t IP_PROTOCOLS_UDP = 17;
32
+
33
+ header ethernet_t {
34
+ macAddr_t dstAddr;
35
+ macAddr_t srcAddr;
36
+ bit<16> etherType;
37
+ }
38
+
39
+ header ipv4_t {
40
+ bit<4> version;
41
+ bit<4> ihl;
42
+ bit<8> tos;
43
+ bit<16> totalLen;
44
+ bit<16> identification;
45
+ bit<3> flags;
46
+ bit<13> fragOffset;
47
+ bit<8> ttl;
48
+ bit<8> protocol;
49
+ bit<16> hdrChecksum;
50
+ ip4Addr_t srcAddr;
51
+ ip4Addr_t dstAddr;
52
+ }
53
+
54
+ header tcp_t {
55
+ bit<16> src_port;
56
+ bit<16> dst_port;
57
+ bit<32> seq_no;
58
+ bit<32> ack_no;
59
+ bit<4> data_offset;
60
+ bit<4> res;
61
+ bit<8> flags;
62
+ bit<16> window;
63
+ bit<16> checksum;
64
+ bit<16> urgent_ptr;
65
+ }
66
+
67
+ header udp_t {
68
+ bit<16> src_port;
69
+ bit<16> dst_port;
70
+ bit<16> hdr_length;
71
+ bit<16> checksum;
72
+ }
73
+
74
+ header icmp_t {
75
+ bit<8> type;
76
+ bit<8> code;
77
+ bit<16> checksum;
78
+ }
79
+
80
+ header vlan_tag_h {
81
+ bit<3> pcp;
82
+ bit<1> cfi;
83
+ bit<12> vid;
84
+ bit<16> type;
85
+ }
86
+
87
+ struct metadata {
88
+ bit<32> dstip;
89
+ bit<32> srcip;
90
+ bit<16> srcport;
91
+ bit<16> dstport;
92
+ bit<8> protocol;
93
+ bit<8> kmvflag;
94
+ bit<32> khash;
95
+ bit<32> counter;
96
+ bit<16> epoch;
97
+ }
98
+
99
+
100
+ struct headers {
101
+ ethernet_t ethernet;
102
+ ipv4_t ipv4;
103
+ udp_t udp;
104
+ tcp_t tcp;
105
+ icmp_t icmp;
106
+ vlan_tag_h vlan;
107
+ }
108
+
109
+
110
+
111
+
112
+
113
+
114
+ parser MyParser(packet_in packet,
115
+ out headers hdr,
116
+ inout metadata meta,
117
+ inout standard_metadata_t standard_metadata) {
118
+
119
+ state start {
120
+ packet.extract(hdr.ethernet);
121
+ transition select(hdr.ethernet.etherType){
122
+ TYPE_IPV4: ipv4;
123
+ VirtualLAN:vlan;
124
+ default: accept;
125
+ }
126
+ }
127
+
128
+ state vlan{
129
+ packet.extract(hdr.vlan);
130
+ transition select(hdr.vlan.type){
131
+ TYPE_IPV4: ipv4;
132
+ default: accept;
133
+ }
134
+ }
135
+
136
+ state ipv4 {
137
+ packet.extract(hdr.ipv4);
138
+ transition select(hdr.ipv4.protocol){
139
+ IP_PROTOCOLS_TCP : parse_tcp;
140
+ IP_PROTOCOLS_UDP : parse_udp;
141
+ IP_PROTOCOLS_ICMP : parse_icmp;
142
+ default : accept;
143
+ }
144
+ }
145
+
146
+ state parse_tcp {
147
+ packet.extract(hdr.tcp);
148
+ transition accept;
149
+ }
150
+
151
+ state parse_udp {
152
+ packet.extract(hdr.udp);
153
+ transition accept;
154
+ }
155
+ state parse_icmp {
156
+ packet.extract(hdr.icmp);
157
+ transition accept;
158
+ }
159
+ }
160
+
161
+
162
+
163
+
164
+
165
+
166
+
167
+ control MyVerifyChecksum(inout headers hdr, inout metadata meta) {
168
+ apply { }
169
+ }
170
+
171
+
172
+
173
+
174
+
175
+ control MyIngress(inout headers hdr,
176
+ inout metadata meta,
177
+ inout standard_metadata_t standard_metadata) {
178
+
179
+
180
+ action routehash(in bit<32> ipv4_src, in bit<32> ipv4_dst, in bit<16> srcport, in bit<16> dstport, in bit<8> protocol, out bit<32> rhash) {
181
+ hash(rhash, HashAlgorithm.crc16, 32w00000000, {ipv4_src, ipv4_dst,srcport,dstport,protocol}, 32w12);
182
+ }
183
+
184
+ action forward(in bit<32> rhash){
185
+ bit<9> finalport = 1;
186
+ finalport=rhash[8:0] +1;
187
+ if( finalport >= 12)
188
+ finalport = 12;
189
+ if( finalport < 1)
190
+ finalport = 1;
191
+ if(standard_metadata.ingress_port != 14) {
192
+ finalport = 0;
193
+ }
194
+ standard_metadata.egress_spec = finalport;
195
+ }
196
+
197
+ apply {
198
+ bit<32> rhash=1;
199
+ if (hdr.tcp.isValid()) {
200
+ routehash(hdr.ipv4.srcAddr, hdr.ipv4.dstAddr, hdr.tcp.src_port, hdr.tcp.dst_port,hdr.ipv4.protocol, rhash);
201
+ forward(rhash);
202
+ }
203
+ else if (hdr.udp.isValid()) {
204
+ routehash(hdr.ipv4.srcAddr, hdr.ipv4.dstAddr, hdr.udp.src_port, hdr.udp.dst_port,hdr.ipv4.protocol, rhash);
205
+ forward(rhash);
206
+ }else{
207
+ standard_metadata.egress_spec = 0;
208
+ }
209
+
210
+ if(standard_metadata.ingress_port != 14) {
211
+ standard_metadata.egress_spec = 0;
212
+ }
213
+ }
214
+ }
215
+
216
+
217
+
218
+
219
+ control MyEgress(inout headers hdr,
220
+ inout metadata meta,
221
+ inout standard_metadata_t standard_metadata) {
222
+ apply {
223
+ }
224
+ }
225
+
226
+
227
+
228
+
229
+ control MyComputeChecksum(inout headers hdr, inout metadata meta) {
230
+ apply {
231
+ update_checksum(
232
+ hdr.ipv4.isValid(),
233
+ { hdr.ipv4.version,
234
+ hdr.ipv4.ihl,
235
+ hdr.ipv4.tos,
236
+ hdr.ipv4.totalLen,
237
+ hdr.ipv4.identification,
238
+ hdr.ipv4.flags,
239
+ hdr.ipv4.fragOffset,
240
+ hdr.ipv4.ttl,
241
+ hdr.ipv4.protocol,
242
+ hdr.ipv4.srcAddr,
243
+ hdr.ipv4.dstAddr },
244
+ hdr.ipv4.hdrChecksum,
245
+ HashAlgorithm.csum16);
246
+ }
247
+ }
248
+
249
+
250
+
251
+
252
+ control MyDeparser(packet_out packet, in headers hdr) {
253
+ apply {
254
+
255
+ //parsed headers have to be added again into the packet.
256
+ packet.emit(hdr.ethernet);
257
+ packet.emit(hdr.vlan);
258
+ packet.emit(hdr.ipv4);
259
+ packet.emit(hdr.tcp);
260
+ packet.emit(hdr.udp);
261
+ packet.emit(hdr.icmp);
262
+ }
263
+ }
264
+
265
+
266
+
267
+
268
+
269
+ //switch architecture
270
+
271
+ V1Switch(
272
+ MyParser(),
273
+ MyVerifyChecksum(),
274
+ MyIngress(),
275
+ MyEgress(),
276
+ MyComputeChecksum(),
277
+ MyDeparser()
278
+ ) main;
individual_files/000057__raw-repositories__f-555__Lemon.p4 ADDED
@@ -0,0 +1,471 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*Lemon sketch for packets counting per-dstIP */
2
+ #include <core.p4>
3
+ #include <v1model.p4>
4
+
5
+ #define PKT_INSTANCE_TYPE_NORMAL 0
6
+ #define PKT_INSTANCE_TYPE_INGRESS_CLONE 1
7
+ #define PKT_INSTANCE_TYPE_EGRESS_CLONE 2
8
+ #define PKT_INSTANCE_TYPE_COALESCED 3
9
+ #define PKT_INSTANCE_TYPE_INGRESS_RECIRC 4
10
+ #define PKT_INSTANCE_TYPE_REPLICATION 5
11
+ #define PKT_INSTANCE_TYPE_RESUBMIT 6
12
+ #define HEAVY_T 100
13
+
14
+ #define T1 16384
15
+ #define T2 8192
16
+ #define T3 1024
17
+ #define T4 256
18
+ #define Th 256
19
+
20
+ #define layer1_size 32w524288
21
+ #define layer2_size 32w65536
22
+ #define layer3_size 32w8192
23
+ #define layer4_size 32w2048
24
+ #define layer5_size 32w1024
25
+
26
+ #define layer1_size_bit1 32w4194304
27
+ #define layer2_size_bit1 32w2097152
28
+ #define layer3_size_bit1 32w262144
29
+ #define layer4_size_bit1 32w65536
30
+ #define layer5_size_bit1 32w524288
31
+
32
+ #define l1_bitmap 32w8
33
+ #define l2_bitmap 32w32
34
+ #define l3_bitmap 32w32
35
+ #define l4_bitmap 32w32
36
+ #define l5_bitmap 32w512
37
+
38
+ #define Hsize 32w8192
39
+
40
+ const bit<16> TYPE_IPV4 = 0x0800;
41
+ const bit<16> VirtualLAN= 0x8100;
42
+
43
+ typedef bit<9> egressSpec_t;
44
+ typedef bit<48> macAddr_t;
45
+ typedef bit<32> ip4Addr_t;
46
+
47
+ typedef bit<16> ether_type_t;
48
+ const ether_type_t ETHERTYPE_IPV4 = 16w0x0800;
49
+ const ether_type_t ETHERTYPE_ARP = 16w0x0806;
50
+ const ether_type_t ETHERTYPE_IPV6 = 16w0x86dd;
51
+ const ether_type_t ETHERTYPE_VLAN = 16w0x8100;
52
+
53
+ typedef bit<8> ip_protocol_t;
54
+ const ip_protocol_t IP_PROTOCOLS_ICMP = 1;
55
+ const ip_protocol_t IP_PROTOCOLS_TCP = 6;
56
+ const ip_protocol_t IP_PROTOCOLS_UDP = 17;
57
+
58
+
59
+ header cpu_t {
60
+ bit<32> hash;
61
+ bit<32> hash1;
62
+ bit<32> srcip;
63
+ bit<32> dstip;
64
+ bit<16> srcport;
65
+ bit<16> dstport;
66
+ bit<8> protocol;
67
+ bit<32> counter;
68
+ bit<16> epoch;
69
+ bit <8> outputport;
70
+ }
71
+
72
+ header ethernet_t {
73
+ macAddr_t dstAddr;
74
+ macAddr_t srcAddr;
75
+ bit<16> etherType;
76
+ }
77
+
78
+ header ipv4_t {
79
+ bit<4> version;
80
+ bit<4> ihl;
81
+ bit<8> tos;
82
+ bit<16> totalLen;
83
+ bit<16> identification;
84
+ bit<3> flags;
85
+ bit<13> fragOffset;
86
+ bit<8> ttl;
87
+ bit<8> protocol;
88
+ bit<16> hdrChecksum;
89
+ ip4Addr_t srcAddr;
90
+ ip4Addr_t dstAddr;
91
+ }
92
+
93
+ header tcp_t {
94
+ bit<16> src_port;
95
+ bit<16> dst_port;
96
+ bit<32> seq_no;
97
+ bit<32> ack_no;
98
+ bit<4> data_offset;
99
+ bit<4> res;
100
+ bit<8> flags;
101
+ bit<16> window;
102
+ bit<16> checksum;
103
+ bit<16> urgent_ptr;
104
+ bit<16> payload;
105
+ }
106
+
107
+ header udp_t {
108
+ bit<16> src_port;
109
+ bit<16> dst_port;
110
+ bit<16> hdr_length;
111
+ bit<16> checksum;
112
+ bit<16> payload;
113
+ }
114
+
115
+ header icmp_t {
116
+ bit<8> type;
117
+ bit<8> code;
118
+ bit<16> checksum;
119
+ }
120
+
121
+ header vlan_tag_h {
122
+ bit<3> pcp;
123
+ bit<1> cfi;
124
+ bit<12> vid;
125
+ bit<16> type;
126
+ }
127
+
128
+ struct metadata {
129
+ bit<32> dstip;
130
+ bit<32> srcip;
131
+ bit<16> srcport;
132
+ bit<16> dstport;
133
+ bit<8> protocol;
134
+ bit<8> kmvflag;
135
+ bit<32> khash;
136
+ bit<32> khash1;
137
+ bit<32> counter;
138
+ bit<16> epoch;
139
+ }
140
+
141
+ struct headers {
142
+ ethernet_t ethernet;
143
+ ipv4_t ipv4;
144
+ cpu_t cpu;
145
+ udp_t udp;
146
+ tcp_t tcp;
147
+ icmp_t icmp;
148
+ vlan_tag_h vlan;
149
+ }
150
+
151
+
152
+
153
+
154
+ parser MyParser(packet_in packet,
155
+ out headers hdr,
156
+ inout metadata meta,
157
+ inout standard_metadata_t standard_metadata) {
158
+
159
+ state start {
160
+ packet.extract(hdr.ethernet);
161
+ transition select(hdr.ethernet.etherType){
162
+ TYPE_IPV4: ipv4;
163
+ VirtualLAN:vlan;
164
+ default: accept;
165
+ }
166
+ }
167
+
168
+ state vlan{
169
+ packet.extract(hdr.vlan);
170
+ transition select(hdr.vlan.type){
171
+ TYPE_IPV4: ipv4;
172
+ default: accept;
173
+ }
174
+ }
175
+
176
+ state ipv4 {
177
+ packet.extract(hdr.ipv4);
178
+ transition select(hdr.ipv4.protocol){
179
+ IP_PROTOCOLS_TCP : parse_tcp;
180
+ IP_PROTOCOLS_UDP : parse_udp;
181
+
182
+ default : reject;
183
+ }
184
+ }
185
+
186
+ state parse_tcp {
187
+ packet.extract(hdr.tcp);
188
+ transition accept;
189
+ }
190
+
191
+ state parse_udp {
192
+ packet.extract(hdr.udp);
193
+ transition accept;
194
+ }
195
+ state parse_icmp {
196
+ packet.extract(hdr.icmp);
197
+ transition accept;
198
+ }
199
+ }
200
+
201
+
202
+
203
+
204
+ control MyVerifyChecksum(inout headers hdr, inout metadata meta) {
205
+ apply { }
206
+ }
207
+
208
+
209
+
210
+
211
+
212
+ control MyIngress(inout headers hdr,
213
+ inout metadata meta,
214
+ inout standard_metadata_t standard_metadata) {
215
+
216
+ action drop() {
217
+ mark_to_drop(standard_metadata);
218
+ }
219
+
220
+ register<bit<1>>(layer1_size_bit1) lemon_layer1;
221
+ register<bit<1>>(layer2_size_bit1) lemon_layer2;
222
+ register<bit<1>>(layer3_size_bit1) lemon_layer3;
223
+ register<bit<1>>(layer4_size_bit1) lemon_layer4;
224
+ register<bit<1>>(layer5_size_bit1) lemon_layer5;
225
+
226
+ register<bit<16>>(4) hash_deep_threshold;
227
+
228
+ register<bit<32>>(layer1_size) counter;
229
+
230
+ register<bit<32>>(8192) lemon_heavy_id;
231
+
232
+ register<bit<32>>(8192) lemon_heavy_tag;
233
+
234
+
235
+ register<bit<32>>(1) sip_mask_f;
236
+ register<bit<32>>(1) dip_mask_f;
237
+ register<bit<16>>(1) sport_mask_f;
238
+ register<bit<16>>(1) dport_mask_f;
239
+ register<bit<8>>(1) protol_f;
240
+
241
+ register<bit<32>>(1) sip_mask;
242
+ register<bit<32>>(1) dip_mask;
243
+ register<bit<16>>(1) sport_mask;
244
+ register<bit<16>>(1) dport_mask;
245
+ register<bit<8>>(1) protol;
246
+ register<bit<16>>(1) ip_checksum;
247
+ register<bit<16>>(1) transport_checksum;
248
+ register<bit<16>>(1) perpkt_tag;
249
+
250
+ action deep_hash(in bit<32> ipv4_src, in bit<32> ipv4_dst, in bit<16> srcport, in bit<16> dstport, in bit<8> protocol, in bit<16> ipsum, in bit<16> checksum, in bit<32> seq_no, in bit<16> hdlen, in bit<16> payload,out bit<16> dhash){
251
+ hash(dhash, HashAlgorithm.crc32_custom, 16w0, {ipv4_src, ipv4_dst,srcport,dstport,protocol,ipsum,checksum,seq_no,hdlen,payload}, 16w65535);
252
+ }
253
+
254
+ action slot_hash(in bit<32> ipv4_src, in bit<32> ipv4_dst, in bit<16> srcport, in bit<16> dstport, in bit<8> protocol, out bit<32> shash) {
255
+ hash(shash, HashAlgorithm.crc32_custom, 32w0, {ipv4_src, ipv4_dst,srcport,dstport,protocol}, layer1_size);
256
+ }
257
+
258
+ action bitmap_hash(in bit<32> ipv4_src, in bit<32> ipv4_dst, in bit<16> srcport, in bit<16> dstport, in bit<8> protocol, in bit<16> ipsum, in bit<16> checksum, in bit<32> seq_no, in bit<16> hdlen, in bit<16> payload,out bit<32> bhash) {
259
+ hash(bhash, HashAlgorithm.crc32_custom, 32w0, {ipv4_src, ipv4_dst,srcport,dstport,protocol,ipsum,checksum,seq_no,hdlen,payload}, l5_bitmap);
260
+ }
261
+
262
+ action routehash(in bit<32> ipv4_src, in bit<32> ipv4_dst, in bit<16> srcport, in bit<16> dstport, in bit<8> protocol, out bit<32> rhash) {
263
+ hash(rhash, HashAlgorithm.crc32_custom, 32w00000000, {ipv4_src, ipv4_dst,srcport,dstport,protocol}, 32w3);
264
+ }
265
+
266
+ action slot_hash2(in bit<32> ipv4_src, in bit<32> ipv4_dst, in bit<16> srcport, in bit<16> dstport, in bit<8> protocol, out bit<32> shash) {
267
+ hash(shash, HashAlgorithm.identity, 32w0, {ipv4_src, ipv4_dst,srcport,dstport,protocol}, layer1_size);
268
+ }
269
+
270
+ register<bit<32>>(Hsize) Heavy_dst;
271
+
272
+ action forward(in bit<32> rhash){
273
+ bit<9> finalport = 1;
274
+ hdr.ipv4.ttl = hdr.ipv4.ttl - 1;
275
+
276
+ if(hdr.ipv4.ttl == 0)
277
+ finalport = 10;
278
+
279
+ standard_metadata.egress_spec = 1;
280
+
281
+ // for chuanxing
282
+ }
283
+
284
+ apply {
285
+
286
+ bit<32> rhash;
287
+
288
+ //only if IPV4 the rule is applied. Therefore other packets will not be forwarded.
289
+ if (hdr.ipv4.isValid()){
290
+
291
+ meta.srcip=hdr.ipv4.srcAddr;
292
+ meta.dstip=hdr.ipv4.dstAddr;
293
+ meta.protocol=hdr.ipv4.protocol;
294
+ }
295
+
296
+ bit<16> deep_h = 0;
297
+ bit<32> slot_h = 0;
298
+ bit<32> slot_h2 = 0;
299
+ bit<32> bitmap_h = 0;
300
+
301
+
302
+ bit<32> sip_mask_f = 0;
303
+
304
+ bit<32> dip_mask_f = 0xffffffff;
305
+ bit<16> sport_mask_f = 0;
306
+ bit<16> dport_mask_f = 0;
307
+ bit<8> protocol_mask_f = 0;
308
+
309
+ bit<32> sip_mask = 0xffffffff;
310
+ bit<32> dip_mask = 0xffffffff;
311
+ bit<16> sport_mask = 0xffff;
312
+ bit<16> dport_mask = 0xffff;
313
+ bit<8> protocol_mask = 0xff;
314
+ bit<16> ip_checksum_mask = 0xffff;
315
+ bit<16> transport_checksum_mask = 0xffff;
316
+ bit<16> payload_mask = 0xffff;
317
+
318
+ if (hdr.tcp.isValid()) {
319
+ deep_hash(hdr.ipv4.srcAddr, hdr.ipv4.dstAddr, hdr.tcp.src_port, hdr.tcp.dst_port,hdr.ipv4.protocol,hdr.ipv4.hdrChecksum, hdr.tcp.checksum,hdr.tcp.seq_no, 0, hdr.tcp.payload, deep_h);
320
+ slot_hash(hdr.ipv4.srcAddr & sip_mask_f, hdr.ipv4.dstAddr & dip_mask_f, hdr.tcp.src_port & sport_mask_f, hdr.tcp.dst_port & dport_mask_f,hdr.ipv4.protocol & protocol_mask_f, slot_h);
321
+ bitmap_hash(hdr.ipv4.srcAddr, hdr.ipv4.dstAddr, hdr.tcp.src_port, hdr.tcp.dst_port,hdr.ipv4.protocol,hdr.ipv4.hdrChecksum, hdr.tcp.checksum,hdr.tcp.seq_no, 0, 0, bitmap_h);
322
+ routehash(hdr.ipv4.srcAddr, hdr.ipv4.dstAddr, hdr.tcp.src_port, hdr.tcp.dst_port,hdr.ipv4.protocol, rhash);
323
+
324
+ //forward(rhash);
325
+ }
326
+ else if (hdr.udp.isValid()) {
327
+ deep_hash(hdr.ipv4.srcAddr, hdr.ipv4.dstAddr, hdr.udp.src_port, hdr.udp.dst_port, hdr.ipv4.protocol,hdr.ipv4.hdrChecksum, hdr.udp.checksum, 0,hdr.udp.hdr_length,hdr.udp.payload, deep_h);
328
+ slot_hash(hdr.ipv4.srcAddr & sip_mask_f, hdr.ipv4.dstAddr & dip_mask_f, hdr.udp.src_port & sport_mask_f, hdr.udp.dst_port & dport_mask_f,hdr.ipv4.protocol & protocol_mask_f, slot_h);
329
+ bitmap_hash(hdr.ipv4.srcAddr, hdr.ipv4.dstAddr, hdr.udp.src_port, hdr.udp.dst_port, hdr.ipv4.protocol,hdr.ipv4.hdrChecksum, hdr.udp.checksum, 0,hdr.udp.hdr_length,hdr.udp.payload, bitmap_h);
330
+ routehash(hdr.ipv4.srcAddr, hdr.ipv4.dstAddr, hdr.udp.src_port, hdr.udp.dst_port,hdr.ipv4.protocol, rhash);
331
+
332
+ //forward(rhash);
333
+ }
334
+
335
+
336
+
337
+ bit<16> deep1;
338
+ bit<16> deep2;
339
+ bit<16> deep3;
340
+ bit<16> deep4;
341
+
342
+ hash_deep_threshold.write(0, T1);
343
+ hash_deep_threshold.write(1, T2);
344
+ hash_deep_threshold.write(2, T3);
345
+ hash_deep_threshold.write(3, T4);
346
+
347
+ hash_deep_threshold.read(deep1,0);
348
+ hash_deep_threshold.read(deep2,1);
349
+ hash_deep_threshold.read(deep3,2);
350
+ hash_deep_threshold.read(deep4,3);
351
+
352
+
353
+ bit<32> counter_hash = 0;
354
+ bit<32> counter_val = 0;
355
+ counter_hash[18:0] = slot_h[18:0];
356
+ counter.read(counter_val, counter_hash);
357
+ counter_val = counter_val + 1;
358
+ counter.write(counter_hash,counter_val);
359
+
360
+ bit<16> roll = 0;
361
+ if(deep_h<=deep4){
362
+ bit<32> slot = 0;
363
+ slot[18:9] = slot_h[9:0];
364
+ slot[8:0] = bitmap_h[8:0];
365
+
366
+ lemon_layer5.write(slot,1);
367
+ }
368
+ if(deep_h<=deep3 && deep_h>deep4){
369
+ bit<32> slot = 0;
370
+ slot[15:5] = slot_h[10:0];
371
+ slot[4:0] = bitmap_h[4:0];
372
+
373
+ lemon_layer4.write(slot,1);
374
+ }
375
+ if(deep_h<=deep2 && deep_h>deep3){
376
+
377
+ bit<32> slot = 0;
378
+ slot[17:5] = slot_h[12:0];
379
+ slot[4:0] = bitmap_h[4:0];
380
+
381
+ lemon_layer3.write(slot,1);
382
+ }
383
+ if(deep_h<=deep1 && deep_h>deep2){
384
+
385
+ bit<32> slot = 0;
386
+ slot[20:5] = slot_h[15:0];
387
+ slot[4:0] = bitmap_h[4:0];
388
+
389
+ lemon_layer2.write(slot,1);
390
+ }
391
+ if(deep_h > deep1){
392
+
393
+ bit<32> slot = 0;
394
+ slot[21:3] = slot_h[18:0];
395
+ slot[2:0] = bitmap_h[2:0];
396
+
397
+ lemon_layer1.write(slot,1);
398
+ }
399
+ if(deep_h < deep3){
400
+ bit<32> slot = 0;
401
+ slot[12:0] = slot_h[12:0];
402
+ lemon_heavy_id.write(slot,hdr.ipv4.dstAddr);
403
+ lemon_heavy_tag.write(slot,slot_h);
404
+ }
405
+ hdr.ipv4.srcAddr[31:0] = 0;
406
+
407
+ hdr.ipv4.identification[15:0] = deep_h;
408
+ standard_metadata.egress_spec = 1;
409
+ }
410
+ }
411
+
412
+
413
+
414
+
415
+ control MyEgress(inout headers hdr,
416
+ inout metadata meta,
417
+ inout standard_metadata_t standard_metadata) {
418
+ apply {
419
+
420
+ }
421
+
422
+ }
423
+
424
+
425
+
426
+
427
+ control MyComputeChecksum(inout headers hdr, inout metadata meta) {
428
+ apply {
429
+ update_checksum(
430
+ hdr.ipv4.isValid(),
431
+ { hdr.ipv4.version,
432
+ hdr.ipv4.ihl,
433
+ hdr.ipv4.tos,
434
+ hdr.ipv4.totalLen,
435
+ hdr.ipv4.identification,
436
+ hdr.ipv4.flags,
437
+ hdr.ipv4.fragOffset,
438
+ hdr.ipv4.ttl,
439
+ hdr.ipv4.protocol,
440
+ hdr.ipv4.srcAddr,
441
+ hdr.ipv4.dstAddr },
442
+ hdr.ipv4.hdrChecksum,
443
+ HashAlgorithm.csum16);
444
+ }
445
+ }
446
+
447
+
448
+
449
+
450
+ control MyDeparser(packet_out packet, in headers hdr) {
451
+ apply {
452
+
453
+ //parsed headers have to be added again into the packet.
454
+
455
+ }
456
+ }
457
+
458
+
459
+
460
+
461
+
462
+ //switch architecture
463
+
464
+ V1Switch(
465
+ MyParser(),
466
+ MyVerifyChecksum(),
467
+ MyIngress(),
468
+ MyEgress(),
469
+ MyComputeChecksum(),
470
+ MyDeparser()
471
+ ) main;
individual_files/000058__raw-repositories__f-555__Lemon.p4 ADDED
@@ -0,0 +1,454 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <core.p4>
2
+ #include <v1model.p4>
3
+
4
+ #define PKT_INSTANCE_TYPE_NORMAL 0
5
+ #define PKT_INSTANCE_TYPE_INGRESS_CLONE 1
6
+ #define PKT_INSTANCE_TYPE_EGRESS_CLONE 2
7
+ #define PKT_INSTANCE_TYPE_COALESCED 3
8
+ #define PKT_INSTANCE_TYPE_INGRESS_RECIRC 4
9
+ #define PKT_INSTANCE_TYPE_REPLICATION 5
10
+ #define PKT_INSTANCE_TYPE_RESUBMIT 6
11
+ #define HEAVY_T 25
12
+
13
+ #define Lsize 32w524288
14
+
15
+ // 8*8192 256 bitmap
16
+ #define Lsize_bitmap 32w16
17
+
18
+ #define Lsize_totle 32w8388608
19
+
20
+ #define Hsize 32w1024
21
+
22
+ // size of heavy part
23
+ #define Hsize_hll 32w32
24
+
25
+ //
26
+ #define Hsize_totle 32w524288
27
+
28
+
29
+ const bit<16> TYPE_IPV4 = 0x0800;
30
+ const bit<16> VirtualLAN= 0x8100;
31
+
32
+ typedef bit<9> egressSpec_t;
33
+ typedef bit<48> macAddr_t;
34
+ typedef bit<32> ip4Addr_t;
35
+
36
+ typedef bit<16> ether_type_t;
37
+ const ether_type_t ETHERTYPE_IPV4 = 16w0x0800;
38
+ const ether_type_t ETHERTYPE_ARP = 16w0x0806;
39
+ const ether_type_t ETHERTYPE_IPV6 = 16w0x86dd;
40
+ const ether_type_t ETHERTYPE_VLAN = 16w0x8100;
41
+
42
+ typedef bit<8> ip_protocol_t;
43
+ const ip_protocol_t IP_PROTOCOLS_ICMP = 1;
44
+ const ip_protocol_t IP_PROTOCOLS_TCP = 6;
45
+ const ip_protocol_t IP_PROTOCOLS_UDP = 17;
46
+
47
+
48
+ header cpu_t {
49
+ bit<32> hash;
50
+ bit<32> hash1;
51
+ bit<32> srcip;
52
+ bit<32> dstip;
53
+ bit<16> srcport;
54
+ bit<16> dstport;
55
+ bit<8> protocol;
56
+ bit<32> counter;
57
+ bit<16> epoch;
58
+ bit <8> outputport;
59
+ }
60
+
61
+ header ethernet_t {
62
+ macAddr_t dstAddr;
63
+ macAddr_t srcAddr;
64
+ bit<16> etherType;
65
+ }
66
+
67
+ header ipv4_t {
68
+ bit<4> version;
69
+ bit<4> ihl;
70
+ bit<8> tos;
71
+ bit<16> totalLen;
72
+ bit<16> identification;
73
+ bit<3> flags;
74
+ bit<13> fragOffset;
75
+ bit<8> ttl;
76
+ bit<8> protocol;
77
+ bit<16> hdrChecksum;
78
+ ip4Addr_t srcAddr;
79
+ ip4Addr_t dstAddr;
80
+ }
81
+
82
+ header tcp_t {
83
+ bit<16> src_port;
84
+ bit<16> dst_port;
85
+ bit<32> seq_no;
86
+ bit<32> ack_no;
87
+ bit<4> data_offset;
88
+ bit<4> res;
89
+ bit<8> flags;
90
+ bit<16> window;
91
+ bit<16> checksum;
92
+ bit<16> urgent_ptr;
93
+ }
94
+
95
+ header udp_t {
96
+ bit<16> src_port;
97
+ bit<16> dst_port;
98
+ bit<16> hdr_length;
99
+ bit<16> checksum;
100
+ bit<48> payload;
101
+ }
102
+
103
+ header icmp_t {
104
+ bit<8> type;
105
+ bit<8> code;
106
+ bit<16> checksum;
107
+ }
108
+
109
+ header vlan_tag_h {
110
+ bit<3> pcp;
111
+ bit<1> cfi;
112
+ bit<12> vid;
113
+ bit<16> type;
114
+ }
115
+
116
+ struct metadata {
117
+ bit<32> dstip;
118
+ bit<32> srcip;
119
+ bit<16> srcport;
120
+ bit<16> dstport;
121
+ bit<8> protocol;
122
+ bit<8> hllflag;
123
+ bit<32> khash;
124
+ bit<32> khash1;
125
+ bit<32> counter;
126
+ bit<16> epoch;
127
+ }
128
+
129
+
130
+ struct headers {
131
+ ethernet_t ethernet;
132
+ ipv4_t ipv4;
133
+ cpu_t cpu;
134
+ udp_t udp;
135
+ tcp_t tcp;
136
+ icmp_t icmp;
137
+ vlan_tag_h vlan;
138
+ }
139
+
140
+
141
+
142
+
143
+ parser MyParser(packet_in packet,
144
+ out headers hdr,
145
+ inout metadata meta,
146
+ inout standard_metadata_t standard_metadata) {
147
+
148
+ state start {
149
+ packet.extract(hdr.ethernet);
150
+ transition select(hdr.ethernet.etherType){
151
+ TYPE_IPV4: ipv4;
152
+ VirtualLAN:vlan;
153
+ default: accept;
154
+ }
155
+ }
156
+
157
+ state vlan{
158
+ packet.extract(hdr.vlan);
159
+ transition select(hdr.vlan.type){
160
+ TYPE_IPV4: ipv4;
161
+ default: accept;
162
+ }
163
+ }
164
+
165
+ state ipv4 {
166
+ packet.extract(hdr.ipv4);
167
+ transition select(hdr.ipv4.protocol){
168
+ IP_PROTOCOLS_TCP : parse_tcp;
169
+ IP_PROTOCOLS_UDP : parse_udp;
170
+ IP_PROTOCOLS_ICMP : parse_icmp;
171
+ default : accept;
172
+ }
173
+ }
174
+
175
+ state parse_tcp {
176
+ packet.extract(hdr.tcp);
177
+ transition accept;
178
+ }
179
+
180
+ state parse_udp {
181
+ packet.extract(hdr.udp);
182
+ transition accept;
183
+ }
184
+ state parse_icmp {
185
+ packet.extract(hdr.icmp);
186
+ transition accept;
187
+ }
188
+ }
189
+
190
+
191
+
192
+
193
+ control MyVerifyChecksum(inout headers hdr, inout metadata meta) {
194
+ apply { }
195
+ }
196
+
197
+
198
+
199
+
200
+
201
+ control MyIngress(inout headers hdr,
202
+ inout metadata meta,
203
+ inout standard_metadata_t standard_metadata) {
204
+
205
+ action drop() {
206
+ mark_to_drop(standard_metadata);
207
+ }
208
+
209
+ register<bit<16>>(Lsize) Light_counter1;
210
+ register<bit<1>>(Lsize_totle) Light_1;
211
+
212
+
213
+ register<bit<16>>(Hsize_totle) Heavy;
214
+ register<bit<32>>(Hsize) Heavy_sip;
215
+ register<bit<32>>(Hsize) Heavy_dip;
216
+ register<bit<16>>(Hsize) Heavy_sp;
217
+ register<bit<16>>(Hsize) Heavy_dp;
218
+ register<bit<8>>(Hsize) Heavy_prot;
219
+ register<bit<32>>(Hsize) Heavy_lhash1;
220
+ register<bit<32>>(Hsize) Heavy_lhash2;
221
+
222
+ register<bit<32>>(1) pkgcounter;
223
+ register<bit<16>>(1) epoch;
224
+
225
+ action bloom_hash(in bit<32> ipv4_src, in bit<32> ipv4_dst, in bit<16> srcport, in bit<16> dstport, in bit<8> protocol, in bit<16> checksum, in bit<32> seq_no, in bit<16> hdlen, in bit<48> payload, out bit<32> h1, out bit<32> h2, out bit<32> h3) {
226
+ hash(h1, HashAlgorithm.crc32_custom, 32w0, {ipv4_src, ipv4_dst,srcport,dstport,checksum,seq_no,hdlen,payload}, 32w0x0003ffff);
227
+ hash(h2, HashAlgorithm.crc32_custom, 32w0, {ipv4_src, ipv4_dst,srcport,dstport,checksum,seq_no,hdlen,payload}, 32w0x0003ffff);
228
+ hash(h3, HashAlgorithm.crc32_custom, 32w0, {ipv4_src, ipv4_dst,srcport,dstport,checksum,seq_no,hdlen,payload}, 32w0x0003ffff);
229
+ }
230
+
231
+ action light_slot_hash1(in bit<32> ipv4_src, in bit<32> ipv4_dst, in bit<16> srcport, in bit<16> dstport, in bit<8> protocol, out bit<32> khash) {
232
+ hash(khash, HashAlgorithm.crc32, 32w0, {ipv4_src, ipv4_dst,srcport,dstport,protocol}, Lsize);
233
+ }
234
+ action light_slot_hash2(in bit<32> ipv4_src, in bit<32> ipv4_dst, in bit<16> srcport, in bit<16> dstport, in bit<8> protocol, out bit<32> khash) {
235
+ hash(khash, HashAlgorithm.identity, 32w0, {ipv4_src, ipv4_dst,srcport,dstport,protocol}, Lsize);
236
+ }
237
+ action bitmap_hash(in bit<32> ipv4_src, in bit<32> ipv4_dst, in bit<16> srcport, in bit<16> dstport, in bit<8> protocol, in bit<16> checksum, in bit<32> seq_no, in bit<16> hdlen, in bit<48> payload,out bit<32> khash) {
238
+ hash(khash, HashAlgorithm.crc32, 32w0, {ipv4_src, ipv4_dst,srcport,dstport,protocol,checksum,seq_no,hdlen,payload}, Lsize_bitmap);
239
+ }
240
+
241
+ action heavy_slot_hash(in bit<32> ipv4_src, in bit<32> ipv4_dst, in bit<16> srcport, in bit<16> dstport, in bit<8> protocol, out bit<32> khash) {
242
+ hash(khash, HashAlgorithm.crc32, 32w0, {ipv4_src, ipv4_dst,srcport,dstport,protocol}, Hsize);
243
+ }
244
+ action heavy_slot_armoma_hash(in bit<32> ipv4_src, in bit<32> ipv4_dst, in bit<16> srcport, in bit<16> dstport, in bit<8> protocol, in bit<16> checksum, in bit<32> seq_no, in bit<16> hdlen, in bit<48> payload, out bit<32> khash) {
245
+ hash(khash, HashAlgorithm.crc32, 32w0, {ipv4_src, ipv4_dst,srcport,dstport,protocol,checksum,seq_no,hdlen,payload}, Hsize_hll);
246
+ }
247
+ action hll_hash1(in bit<32> ipv4_src, in bit<32> ipv4_dst, in bit<16> srcport, in bit<16> dstport, in bit<8> protocol, in bit<16> checksum, in bit<32> seq_no, in bit<16> hdlen, in bit<48> payload, out bit<16> khash) {
248
+ hash(khash, HashAlgorithm.crc32_custom, 16w0, {ipv4_src, ipv4_dst,srcport,dstport,protocol,checksum,seq_no,hdlen,payload}, 16w0xffff);
249
+ }
250
+ action hll_hash2(in bit<32> ipv4_src, in bit<32> ipv4_dst, in bit<16> srcport, in bit<16> dstport, in bit<8> protocol, in bit<16> checksum, in bit<32> seq_no, in bit<16> hdlen, in bit<48> payload, out bit<16> khash) {
251
+ hash(khash, HashAlgorithm.crc32_custom, 16w0, {ipv4_src, ipv4_dst,srcport,dstport,protocol,checksum,seq_no,hdlen,payload}, 16w0xffff);
252
+ }
253
+
254
+
255
+ action routehash(in bit<32> ipv4_src, in bit<32> ipv4_dst, in bit<16> srcport, in bit<16> dstport, in bit<8> protocol, out bit<32> rhash) {
256
+ hash(rhash, HashAlgorithm.crc32, 32w00000000, {ipv4_src, ipv4_dst,srcport,dstport,protocol}, 32w3);
257
+ }
258
+
259
+ action forward(in bit<32> rhash){
260
+ bit<9> finalport = 1;
261
+ hdr.ipv4.ttl = hdr.ipv4.ttl - 1;
262
+
263
+ if(hdr.ipv4.ttl == 0)
264
+ finalport = 10;
265
+ standard_metadata.egress_spec = finalport+1;
266
+ }
267
+
268
+ apply {
269
+
270
+ bit<32> rhash;
271
+
272
+ //only if IPV4 the rule is applied. Therefore other packets will not be forwarded.
273
+ if (hdr.ipv4.isValid()){
274
+ meta.srcip=hdr.ipv4.srcAddr;
275
+ meta.dstip=hdr.ipv4.dstAddr;
276
+ meta.protocol=hdr.ipv4.protocol;
277
+ }
278
+
279
+
280
+ bit<32> h1=0;
281
+ bit<32> h2=0;
282
+ bit<32> h3=0;
283
+
284
+ bit<32> light_slot_h1=0;
285
+ bit<32> bitmap_h=0;
286
+
287
+ bit<32> heavy_slot_h=0;
288
+ bit<32> heavy_slot_armoma_h=0;
289
+ bit<16> khash1=0;
290
+ bit<16> khash2=0;
291
+
292
+ if (hdr.tcp.isValid()) {
293
+ bloom_hash(hdr.ipv4.srcAddr, hdr.ipv4.dstAddr, hdr.tcp.src_port, hdr.tcp.dst_port,hdr.ipv4.protocol, hdr.tcp.checksum,hdr.tcp.seq_no,0,0, h1, h2, h3);
294
+
295
+ light_slot_hash1(0, hdr.ipv4.dstAddr, 0, 0, 0, light_slot_h1);
296
+
297
+ bitmap_hash(hdr.ipv4.srcAddr, hdr.ipv4.dstAddr, hdr.tcp.src_port, hdr.tcp.dst_port,hdr.ipv4.protocol, hdr.tcp.checksum,hdr.tcp.seq_no , 0,0 , bitmap_h);
298
+
299
+ heavy_slot_hash(0, hdr.ipv4.dstAddr, 0, 0, 0, heavy_slot_h);
300
+ heavy_slot_armoma_hash(hdr.ipv4.srcAddr, hdr.ipv4.dstAddr, hdr.tcp.src_port, hdr.tcp.dst_port,hdr.ipv4.protocol, hdr.tcp.checksum,hdr.tcp.seq_no,0,0, heavy_slot_armoma_h);
301
+ hll_hash1(hdr.ipv4.srcAddr, hdr.ipv4.dstAddr, hdr.tcp.src_port, hdr.tcp.dst_port,hdr.ipv4.protocol, hdr.tcp.checksum,hdr.tcp.seq_no,0,0, khash1);
302
+ hll_hash2(hdr.ipv4.srcAddr, hdr.ipv4.dstAddr, hdr.tcp.src_port, hdr.tcp.dst_port,hdr.ipv4.protocol, hdr.tcp.checksum,hdr.tcp.seq_no,0,0, khash2);
303
+ routehash(hdr.ipv4.srcAddr, hdr.ipv4.dstAddr, hdr.tcp.src_port, hdr.tcp.dst_port,hdr.ipv4.protocol, rhash);
304
+
305
+ khash1[7:4]=khash2[7:4];
306
+ forward(rhash);
307
+ }
308
+ else if (hdr.udp.isValid()) {
309
+ bloom_hash(hdr.ipv4.srcAddr, hdr.ipv4.dstAddr, hdr.udp.src_port, hdr.udp.dst_port,hdr.ipv4.protocol, hdr.udp.checksum, 0,hdr.udp.hdr_length,hdr.udp.payload,h1, h2, h3);
310
+
311
+ light_slot_hash1(0, hdr.ipv4.dstAddr, 0, 0, 0, light_slot_h1);
312
+
313
+ bitmap_hash(hdr.ipv4.srcAddr, hdr.ipv4.dstAddr, hdr.udp.src_port, hdr.udp.dst_port, hdr.ipv4.protocol, hdr.udp.checksum, 0,hdr.udp.hdr_length,hdr.udp.payload, bitmap_h);
314
+
315
+ heavy_slot_hash(0, hdr.ipv4.dstAddr, 0, 0, 0, heavy_slot_h);
316
+ heavy_slot_armoma_hash(hdr.ipv4.srcAddr, hdr.ipv4.dstAddr, hdr.udp.src_port, hdr.udp.dst_port, hdr.ipv4.protocol, hdr.udp.checksum, 0,hdr.udp.hdr_length,hdr.udp.payload, heavy_slot_armoma_h);
317
+ hll_hash1(hdr.ipv4.srcAddr, hdr.ipv4.dstAddr, hdr.udp.src_port, hdr.udp.dst_port,hdr.ipv4.protocol, hdr.udp.checksum, 0,hdr.udp.hdr_length,hdr.udp.payload, khash1);
318
+ hll_hash2(hdr.ipv4.srcAddr, hdr.ipv4.dstAddr, hdr.udp.src_port, hdr.udp.dst_port,hdr.ipv4.protocol, hdr.udp.checksum, 0,hdr.udp.hdr_length,hdr.udp.payload, khash2);
319
+ routehash(hdr.ipv4.srcAddr, hdr.ipv4.dstAddr, hdr.udp.src_port, hdr.udp.dst_port,hdr.ipv4.protocol, rhash);
320
+
321
+ khash1[7:4]=khash2[7:4];
322
+ forward(rhash);
323
+ }else{
324
+ standard_metadata.egress_spec =0;
325
+ }
326
+
327
+
328
+ bit<16> counternow1 = 0;
329
+ bit<16> counternow2 = 0;
330
+ bit<16> heavy_flag = 0;
331
+ Light_counter1.read(counternow1,light_slot_h1);
332
+ counternow1 = counternow1 +1;
333
+ Light_counter1.write(light_slot_h1,counternow1);
334
+
335
+ if(counternow1 >= HEAVY_T)
336
+ heavy_flag = 1;
337
+
338
+ if(heavy_flag == 0){
339
+ bit<32> l_index = 0;
340
+ bit<32> bitmap1 = 0;
341
+ bit<8> roll = 0;
342
+
343
+ // for bitmap
344
+ l_index[22:4] = light_slot_h1[18:0];
345
+ l_index[3:0] = bitmap_h[3:0];
346
+ Light_1.write(l_index,1);
347
+ }
348
+
349
+ bit<16> hashnow;
350
+ bit<32> h_index;
351
+ h_index[14:5]=heavy_slot_h[9:0];
352
+ h_index[4:0]=heavy_slot_armoma_h[4:0];
353
+ if(heavy_flag == 1){
354
+ Heavy.read(hashnow,h_index);
355
+ if((hashnow > khash1 || hashnow==0)){
356
+ Heavy.write(h_index,khash1);
357
+ }
358
+ Heavy_sip.write(heavy_slot_h,hdr.ipv4.srcAddr);
359
+ Heavy_dip.write(heavy_slot_h,hdr.ipv4.dstAddr);
360
+ Heavy_prot.write(heavy_slot_h,hdr.ipv4.protocol);
361
+ Heavy_lhash1.write(heavy_slot_h, light_slot_h1);
362
+ if(hdr.tcp.isValid()){
363
+ Heavy_sp.write(heavy_slot_h,hdr.tcp.src_port);
364
+ Heavy_dp.write(heavy_slot_h,hdr.tcp.dst_port);
365
+ }
366
+ if(hdr.udp.isValid()){
367
+ Heavy_sp.write(heavy_slot_h,hdr.udp.src_port);
368
+ Heavy_dp.write(heavy_slot_h,hdr.udp.dst_port);
369
+ }
370
+ }
371
+ }
372
+ }
373
+
374
+
375
+
376
+
377
+ control MyEgress(inout headers hdr,
378
+ inout metadata meta,
379
+ inout standard_metadata_t standard_metadata) {
380
+ apply {
381
+
382
+ if (standard_metadata.instance_type != 0){
383
+ hdr.ethernet.etherType =0x1234;
384
+ hdr.cpu.setValid();
385
+ hdr.vlan.setInvalid();
386
+ hdr.cpu.hash = meta.khash;
387
+ hdr.cpu.hash1 = meta.khash1;
388
+ hdr.cpu.srcip = meta.srcip;
389
+ hdr.cpu.dstip = meta.dstip;
390
+ hdr.cpu.srcport = meta.srcport;
391
+ hdr.cpu.dstport = meta.dstport;
392
+ hdr.cpu.protocol = meta.protocol;
393
+ hdr.cpu.counter = meta.counter;
394
+ hdr.cpu.epoch= meta.epoch;
395
+ hdr.cpu.outputport = standard_metadata.egress_spec[7:0];
396
+ }
397
+ }
398
+
399
+ }
400
+
401
+
402
+
403
+
404
+ control MyComputeChecksum(inout headers hdr, inout metadata meta) {
405
+ apply {
406
+ update_checksum(
407
+ hdr.ipv4.isValid(),
408
+ { hdr.ipv4.version,
409
+ hdr.ipv4.ihl,
410
+ hdr.ipv4.tos,
411
+ hdr.ipv4.totalLen,
412
+ hdr.ipv4.identification,
413
+ hdr.ipv4.flags,
414
+ hdr.ipv4.fragOffset,
415
+ hdr.ipv4.ttl,
416
+ hdr.ipv4.protocol,
417
+ hdr.ipv4.srcAddr,
418
+ hdr.ipv4.dstAddr },
419
+ hdr.ipv4.hdrChecksum,
420
+ HashAlgorithm.csum16);
421
+ }
422
+ }
423
+
424
+
425
+
426
+
427
+ control MyDeparser(packet_out packet, in headers hdr) {
428
+ apply {
429
+
430
+ //parsed headers have to be added again into the packet.
431
+ packet.emit(hdr.ethernet);
432
+ packet.emit(hdr.vlan);
433
+ packet.emit(hdr.cpu);
434
+ packet.emit(hdr.ipv4);
435
+ packet.emit(hdr.tcp);
436
+ packet.emit(hdr.udp);
437
+ packet.emit(hdr.icmp);
438
+ }
439
+ }
440
+
441
+
442
+
443
+
444
+
445
+ //switch architecture
446
+
447
+ V1Switch(
448
+ MyParser(),
449
+ MyVerifyChecksum(),
450
+ MyIngress(),
451
+ MyEgress(),
452
+ MyComputeChecksum(),
453
+ MyDeparser()
454
+ ) main;
individual_files/000059__raw-repositories__diogocampos__p4-data-flow.p4 ADDED
@@ -0,0 +1,287 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <v1model.p4>
2
+
3
+
4
+ typedef bit<48> mac_addr_t;
5
+ typedef bit<128> ipv6_addr_t;
6
+ typedef bit<9> port_t;
7
+ const bit<16> TYPE_IPV6 = 0x86dd;
8
+ const bit<9> TYPE_CPU = 9w192;
9
+ const bit<8> PROTO_TCP = 6;
10
+ const bit<8> PROTO_UDP = 17;
11
+ const bit<8> PROTO_ICMP6 = 58;
12
+ const bit<8> TCP_SEQ_LEN = 4;
13
+ const bit<8> ICMP6_ECHO_REQUEST = 128;
14
+ const bit<8> ICMP6_ECHO_REPLY = 129;
15
+
16
+ header ethernet_t {
17
+ mac_addr_t dstAddr;
18
+ mac_addr_t srcAddr;
19
+ bit<16> etherType;
20
+ }
21
+
22
+ header ipv6_t {
23
+ bit<4> version;
24
+ bit<8> traffic_class;
25
+ bit<20> flow_label;
26
+ bit<16> payload_length;
27
+ bit<8> nextHdr;
28
+ bit<8> hopLimit;
29
+ ipv6_addr_t srcAddr;
30
+ ipv6_addr_t dstAddr;
31
+ }
32
+
33
+ header tcp_t {
34
+ bit<16> srcPort;
35
+ bit<16> dstPort;
36
+ int<32> seqNo;
37
+ int<32> ackNo;
38
+ bit<4> data_offset;
39
+ bit<4> res;
40
+ bit<1> cwr;
41
+ bit<1> ece;
42
+ bit<1> urg;
43
+ bit<1> ack;
44
+ bit<1> psh;
45
+ bit<1> rst;
46
+ bit<1> syn;
47
+ bit<1> fin;
48
+ bit<16> window;
49
+ bit<16> checksum;
50
+ bit<16> urgentPtr;
51
+ }
52
+
53
+ header udp_t {
54
+ bit<16> srcPort;
55
+ bit<16> dstPort;
56
+ bit<16> length_;
57
+ bit<16> checksum;
58
+ }
59
+
60
+ header icmp6_t {
61
+ bit<8> type;
62
+ bit<8> code;
63
+ bit<16> checksum;
64
+ }
65
+
66
+ struct headers {
67
+ ethernet_t inner_ethernet;
68
+ icmp6_t inner_icmp6;
69
+ ipv6_t inner_ipv6;
70
+ tcp_t inner_tcp;
71
+ udp_t inner_udp;
72
+ ethernet_t ethernet;
73
+ icmp6_t icmp6;
74
+ ipv6_t ipv6;
75
+ tcp_t tcp;
76
+ udp_t udp;
77
+ }
78
+
79
+ struct l3_metadata_t {
80
+ bit<2> lkp_ip_type;
81
+ bit<4> lkp_ip_version;
82
+ bit<8> lkp_ip_proto;
83
+ bit<8> lkp_dscp;
84
+ bit<8> lkp_ip_ttl;
85
+ bit<16> lkp_l4_sport;
86
+ bit<16> lkp_l4_dport;
87
+ bit<16> lkp_outer_l4_sport;
88
+ bit<16> lkp_outer_l4_dport;
89
+ bit<16> vrf;
90
+ bit<10> rmac_group;
91
+ bit<1> rmac_hit;
92
+ bit<2> urpf_mode;
93
+ bit<1> urpf_hit;
94
+ bit<1> urpf_check_fail;
95
+ bit<16> urpf_bd_group;
96
+ bit<1> fib_hit;
97
+ bit<16> fib_nexthop;
98
+ bit<2> fib_nexthop_type;
99
+ bit<16> same_bd_check;
100
+ bit<16> nexthop_index;
101
+ bit<1> routed;
102
+ bit<1> outer_routed;
103
+ bit<8> mtu_index;
104
+ bit<1> l3_copy;
105
+ bit<16> l3_mtu_check;
106
+ bit<16> egress_l4_sport;
107
+ bit<16> egress_l4_dport;
108
+ }
109
+
110
+ struct tunnel_metadata_t {
111
+ bit<5> ingress_tunnel_type;
112
+ bit<24> tunnel_vni;
113
+ bit<5> egress_tunnel_type;
114
+ bit<14> tunnel_index;
115
+ bit<9> tunnel_src_index;
116
+ bit<9> tunnel_smac_index;
117
+ bit<14> tunnel_dst_index;
118
+ bit<14> tunnel_dmac_index;
119
+ bit<24> vnid;
120
+ bit<1> tunnel_terminate;
121
+ bit<1> tunnel_if_check;
122
+ bit<4> egress_header_count;
123
+ bit<8> inner_ip_proto;
124
+ bit<1> skip_encap_inner;
125
+ }
126
+
127
+ struct l2_metadata_t {
128
+ bit<48> lkp_mac_sa;
129
+ bit<48> lkp_mac_da;
130
+ bit<3> lkp_pkt_type;
131
+ bit<16> lkp_mac_type;
132
+ bit<3> lkp_pcp;
133
+ bit<16> l2_nexthop;
134
+ bit<2> l2_nexthop_type;
135
+ bit<1> l2_redirect;
136
+ bit<1> l2_src_miss;
137
+ bit<16> l2_src_move;
138
+ bit<10> stp_group;
139
+ bit<3> stp_state;
140
+ bit<16> bd_stats_idx;
141
+ bit<1> learning_enabled;
142
+ bit<1> port_vlan_mapping_miss;
143
+ bit<16> same_if_check;
144
+ }
145
+
146
+ struct ipv6_metadata_t {
147
+ bit<128> lkp_ipv6_sa;
148
+ bit<128> lkp_ipv6_da;
149
+ bit<1> ipv6_unicast_enabled;
150
+ bit<1> ipv6_src_is_link_local;
151
+ bit<2> ipv6_urpf_mode;
152
+ }
153
+
154
+ struct acl_metadata_t {
155
+ bit<1> acl_deny; /* ifacl/vacl deny action */
156
+ bit<24> vnid; /* vnid for acls */
157
+ bit<14> acl_stats_index; /* acl stats index */
158
+ bit<16> egress_if_label; /* if label for egress acls */
159
+ bit<16> egress_bd_label; /* bd label for egress acls */
160
+ }
161
+
162
+ struct fwd_meta_t {
163
+ bit<32> l2ptr;
164
+ bit<24> out_bd;
165
+ }
166
+
167
+ struct metadata_t {
168
+ port_t ingress_port;
169
+ port_t egress_port;
170
+ bit<16> tcp_length;
171
+ bit<32> cast_length;
172
+ bit<1> do_cksum;
173
+ l2_metadata_t l2_metadata;
174
+ l3_metadata_t l3_metadata;
175
+ ipv6_metadata_t ipv6_metadata;
176
+ tunnel_metadata_t tunnel_metadata;
177
+ fwd_meta_t fwd;
178
+ }
179
+
180
+
181
+ const bit<32> BMV2_V1MODEL_INSTANCE_TYPE_REPLICATION = 5;
182
+ #define IS_REPLICATED(std_meta) (std_meta.instance_type == BMV2_V1MODEL_INSTANCE_TYPE_REPLICATION)
183
+
184
+ parser MyParser(packet_in packet, out headers hdr, inout metadata_t meta,
185
+ inout standard_metadata_t standard_metadata) {
186
+ state start {
187
+ packet.extract(hdr.ethernet);
188
+ transition select(hdr.ethernet.etherType) {
189
+ TYPE_IPV6: ipv6;
190
+ default: accept;
191
+ }
192
+ }
193
+ state ipv6 {
194
+ packet.extract(hdr.ipv6);
195
+ transition select(hdr.ipv6.nextHdr) {
196
+ PROTO_UDP: parse_udp;
197
+ PROTO_ICMP6: icmp6;
198
+ default: accept;
199
+ }
200
+ }
201
+ state icmp6 {
202
+ packet.extract(hdr.icmp6);
203
+ transition accept;
204
+ }
205
+ state parse_udp {
206
+ packet.extract(hdr.udp);
207
+ transition accept;
208
+ }
209
+ }
210
+
211
+
212
+ control ingress(inout headers hdr, inout metadata_t meta,
213
+ inout standard_metadata_t standard_metadata) {
214
+ action set_mcast_grp(bit<16> mcast_grp, bit<9> port) {
215
+ standard_metadata.mcast_grp = mcast_grp;
216
+ meta.egress_port = port;
217
+ }
218
+ table ipv6_tbl {
219
+ key = {
220
+ (hdr.ipv6.dstAddr[127:120] == 8w0xff) : exact @name("mcast_key");
221
+ }
222
+ actions = {set_mcast_grp;}
223
+ }
224
+
225
+ apply {
226
+ if (hdr.ipv6.isValid()) {
227
+ ipv6_tbl.apply();
228
+ }
229
+ }
230
+ }
231
+
232
+ control egress(inout headers hdr, inout metadata_t meta,
233
+ inout standard_metadata_t standard_metadata) {
234
+ action set_out_bd (bit<24> bd) {
235
+ meta.fwd.out_bd = bd;
236
+ }
237
+ table get_multicast_copy_out_bd {
238
+ key = {
239
+ standard_metadata.mcast_grp : exact;
240
+ standard_metadata.egress_rid : exact;
241
+ }
242
+ actions = { set_out_bd; }
243
+ }
244
+
245
+ action drop() {
246
+ mark_to_drop(standard_metadata);
247
+ }
248
+ action rewrite_mac(bit<48> smac) {
249
+ hdr.ethernet.srcAddr = smac;
250
+ }
251
+ table send_frame {
252
+ key = {
253
+ meta.fwd.out_bd: exact;
254
+ }
255
+ actions = {rewrite_mac; drop;}
256
+ default_action = drop;
257
+ }
258
+
259
+ apply {
260
+ if (IS_REPLICATED(standard_metadata)) {
261
+ get_multicast_copy_out_bd.apply();
262
+ send_frame.apply();
263
+ }
264
+ }
265
+ }
266
+
267
+ control MyDeparser(packet_out packet, in headers hdr) {
268
+ apply {
269
+ packet.emit(hdr.ethernet);
270
+ packet.emit(hdr.ipv6);
271
+ packet.emit(hdr.icmp6);
272
+ packet.emit(hdr.udp);
273
+ }
274
+ }
275
+
276
+ control MyVerifyChecksum(inout headers hdr, inout metadata_t meta) {
277
+ apply {
278
+ }
279
+ }
280
+
281
+ control MyComputeChecksum(inout headers hdr, inout metadata_t meta) {
282
+ apply {
283
+ }
284
+ }
285
+
286
+ V1Switch(MyParser(), MyVerifyChecksum(), ingress(), egress(),
287
+ MyComputeChecksum(), MyDeparser()) main;
individual_files/000060__raw-repositories__cornell-netlab__capisce.p4 ADDED
@@ -0,0 +1,285 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <core.p4>
2
+ #include <v1model.p4>
3
+
4
+ // HEADERS
5
+
6
+
7
+ // Define header types
8
+
9
+ header arp_t {
10
+ bit<16> ptype;
11
+ bit<8> plen;
12
+ bit<16> oper;
13
+ bit<16> htype;
14
+ bit<8> hlen;
15
+ }
16
+ header arp_ipv4_t {
17
+ bit<32> tpa;
18
+ bit<48> tha;
19
+ bit<32> spa;
20
+ bit<48> sha;
21
+ }
22
+ header ethernet_t {
23
+ bit<48> srcAddr;
24
+ bit<16> etherType;
25
+ bit<48> dstAddr;
26
+ }
27
+ header icmp_t {
28
+ bit<8> type;
29
+ bit<16> checksum;
30
+ }
31
+ header ipv4_t {
32
+ bit<8> ttl;
33
+ bit<32> srcAddr;
34
+ bit<8> protocol;
35
+ bit<32> dstAddr;
36
+ }
37
+
38
+ // Assemble headers in a single struct
39
+ struct my_headers_t {
40
+ arp_t arp;
41
+ arp_ipv4_t arp_ipv4;
42
+ ethernet_t ethernet;
43
+ icmp_t icmp;
44
+ ipv4_t ipv4;
45
+ }
46
+
47
+
48
+
49
+ // METADATA
50
+
51
+
52
+ struct my_metadata_t {
53
+
54
+ bit<48> my_mac;
55
+ bit<48> mac_sa;
56
+ bit<48> mac_da;
57
+ bit<9> egress_port;
58
+ bit<32> dst_ipv4;
59
+
60
+ }
61
+
62
+ // PARSER
63
+
64
+ parser MyParser(
65
+ packet_in packet,
66
+ out my_headers_t hdr,
67
+ inout my_metadata_t meta,
68
+ inout standard_metadata_t standard_metadata)
69
+ {
70
+
71
+ // Variable Definitions
72
+
73
+
74
+ // Parser state machine
75
+
76
+
77
+ state parse_arp {
78
+ packet.extract(hdr.arp);
79
+ transition select(hdr.arp.htype,hdr.arp.ptype,hdr.arp.hlen,hdr.arp.plen){
80
+ (16w1,16w2048,8w6,8w4) : parse_arp_ipv4;
81
+ default : accept;
82
+ }
83
+
84
+ }
85
+
86
+
87
+ state parse_arp_ipv4 {
88
+ packet.extract(hdr.arp_ipv4);
89
+ meta.dst_ipv4 = hdr.arp_ipv4.tpa;
90
+ transition accept;
91
+ }
92
+
93
+
94
+ state parse_icmp {
95
+ packet.extract(hdr.icmp);
96
+ transition accept;
97
+ }
98
+
99
+
100
+ state parse_ipv4 {
101
+ packet.extract(hdr.ipv4);
102
+ meta.dst_ipv4 = hdr.ipv4.dstAddr;
103
+ transition select(hdr.ipv4.protocol){
104
+ (8w1) : parse_icmp;
105
+ default : accept;
106
+ }
107
+
108
+ }
109
+
110
+
111
+ state start {
112
+ packet.extract(hdr.ethernet);
113
+ transition select(hdr.ethernet.etherType){
114
+ (16w2048) : parse_ipv4;
115
+ (16w2054) : parse_arp;
116
+ default : accept;
117
+ }
118
+
119
+ }
120
+
121
+ }
122
+
123
+
124
+ // INGRESS
125
+
126
+ control MyIngress (
127
+ inout my_headers_t hdr,
128
+ inout my_metadata_t meta,
129
+ inout standard_metadata_t standard_metadata)
130
+ {
131
+
132
+ // Variable Definitions
133
+ bit<9> egress_port;
134
+ bit<1> exited;
135
+ bit<48> mac_da;
136
+ bit<48> mac_sa;
137
+ bit<32> tmp_ip;
138
+ bit<48> tmp_mac;
139
+
140
+
141
+ // Action Definitions
142
+ action forward_action_0(){
143
+ hdr.ethernet.dstAddr = meta.mac_da;
144
+ hdr.ethernet.srcAddr = meta.mac_sa;
145
+ hdr.ipv4.ttl = (hdr.ipv4.ttl - 8w1);
146
+ standard_metadata.egress_spec = meta.egress_port;
147
+ }
148
+
149
+ action forward_action_1(){
150
+ hdr.ethernet.dstAddr = hdr.arp_ipv4.sha;
151
+ hdr.ethernet.srcAddr = meta.mac_da;
152
+ hdr.arp.oper = 16w2;
153
+ hdr.arp_ipv4.tha = hdr.arp_ipv4.sha;
154
+ hdr.arp_ipv4.tpa = hdr.arp_ipv4.spa;
155
+ hdr.arp_ipv4.sha = meta.mac_da;
156
+ hdr.arp_ipv4.spa = meta.dst_ipv4;
157
+ standard_metadata.egress_spec = standard_metadata.ingress_port;
158
+ }
159
+
160
+ action forward_action_2(){
161
+ tmp_mac = hdr.ethernet.dstAddr;
162
+ hdr.ethernet.dstAddr = hdr.ethernet.srcAddr;
163
+ hdr.ethernet.srcAddr = tmp_mac;
164
+ tmp_ip = hdr.ipv4.dstAddr;
165
+ hdr.ipv4.dstAddr = hdr.ipv4.srcAddr;
166
+ hdr.ipv4.srcAddr = tmp_ip;
167
+ hdr.icmp.type = 8w0;
168
+ hdr.icmp.checksum = 16w0;
169
+ standard_metadata.egress_spec = standard_metadata.ingress_port;
170
+ }
171
+
172
+ action forward_action_3(){
173
+ standard_metadata.egress_spec = 9w511;
174
+ exited = 1w1;
175
+ }
176
+
177
+ action ipv4_lpm_action_0(bit<48> mac_da,bit<48> mac_sa,bit<9> egress_port){
178
+ meta.mac_da = mac_da;
179
+ meta.mac_sa = mac_sa;
180
+ meta.egress_port = egress_port;
181
+ }
182
+
183
+ action ipv4_lpm_action_1(){
184
+ standard_metadata.egress_spec = 9w511;
185
+ exited = 1w1;
186
+ }
187
+
188
+
189
+ // Table Definitions
190
+
191
+ table forward {
192
+ key = {
193
+ hdr.arp.isValid() : exact;
194
+ hdr.arp.oper : exact;
195
+ hdr.arp_ipv4.isValid() : exact;
196
+ hdr.ipv4.isValid() : exact;
197
+ hdr.icmp.isValid() : exact;
198
+ hdr.icmp.type : ternary;
199
+ }
200
+ actions = {
201
+ forward_action_0;
202
+ forward_action_1;
203
+ forward_action_2;
204
+ forward_action_3;
205
+ }
206
+ }
207
+
208
+ table ipv4_lpm {
209
+ key = {
210
+ meta.dst_ipv4 : exact;
211
+ }
212
+ actions = {
213
+ ipv4_lpm_action_0;
214
+ ipv4_lpm_action_1;
215
+ }
216
+ }
217
+
218
+
219
+ apply {
220
+
221
+ // Pipeline
222
+ meta.my_mac = 48w102030405;
223
+ if ((1w1 == exited)) {} else {
224
+ ipv4_lpm.apply();
225
+ forward.apply();
226
+ }
227
+
228
+ }
229
+ }
230
+
231
+
232
+ // EGRESS
233
+
234
+ control MyEgress (
235
+ inout my_headers_t hdr,
236
+ inout my_metadata_t meta,
237
+ inout standard_metadata_t standard_metadata)
238
+ {
239
+
240
+ // Variable Definitions
241
+
242
+
243
+ // Action Definitions
244
+
245
+
246
+ // Table Definitions
247
+
248
+
249
+ apply {
250
+
251
+ // Pipeline
252
+
253
+ }
254
+ }
255
+
256
+
257
+ // OTHER
258
+ control MyVerifyChecksum(
259
+ inout my_headers_t hdr,
260
+ inout my_metadata_t meta)
261
+ {
262
+ apply { }
263
+ }
264
+
265
+ control MyComputeChecksum(
266
+ inout my_headers_t hdr,
267
+ inout my_metadata_t meta)
268
+ {
269
+ apply { }
270
+ }
271
+ control MyDeparser(
272
+ packet_out packet,
273
+ in my_headers_t hdr)
274
+ {
275
+ apply {
276
+ }
277
+ }
278
+ V1Switch(
279
+ MyParser(),
280
+ MyVerifyChecksum(),
281
+ MyIngress(),
282
+ MyEgress(),
283
+ MyComputeChecksum(),
284
+ MyDeparser()
285
+ ) main;
individual_files/000061__raw-repositories__cornell-netlab__capisce.p4 ADDED
@@ -0,0 +1,243 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <core.p4>
2
+ #include <v1model.p4>
3
+
4
+ // HEADERS
5
+
6
+
7
+ // Define header types
8
+
9
+ header ethernet_t {
10
+ bit<48> srcAddr;
11
+ bit<16> etherType;
12
+ bit<48> dstAddr;
13
+ }
14
+ header ipv4_t {
15
+ bit<8> ttl;
16
+ bit<8> protocol;
17
+ bit<32> dstAddr;
18
+ }
19
+ header tcp_t {
20
+
21
+ }
22
+
23
+ // Assemble headers in a single struct
24
+ struct my_headers_t {
25
+ ethernet_t ethernet;
26
+ ipv4_t ipv4;
27
+ tcp_t tcp;
28
+ }
29
+
30
+
31
+
32
+ // METADATA
33
+
34
+
35
+
36
+ struct routing_metadata_t {
37
+
38
+ bit<32> nhop_ipv4;
39
+
40
+ }
41
+ struct my_metadata_t {
42
+ routing_metadata_t routing_metadata;
43
+
44
+
45
+ }
46
+
47
+ // PARSER
48
+
49
+ parser MyParser(
50
+ packet_in packet,
51
+ out my_headers_t hdr,
52
+ inout my_metadata_t meta,
53
+ inout standard_metadata_t standard_metadata)
54
+ {
55
+
56
+ // Variable Definitions
57
+
58
+
59
+ // Parser state machine
60
+
61
+
62
+ state parse_ipv4 {
63
+ packet.extract(hdr.ipv4);
64
+ transition select(hdr.ipv4.protocol){
65
+ (8w6) : parse_tcp;
66
+ default : accept;
67
+ }
68
+
69
+ }
70
+
71
+
72
+ state parse_tcp {
73
+ packet.extract(hdr.tcp);
74
+ transition accept;
75
+ }
76
+
77
+
78
+ state start {
79
+ packet.extract(hdr.ethernet);
80
+ transition select(hdr.ethernet.etherType){
81
+ (16w2048) : parse_ipv4;
82
+ default : accept;
83
+ }
84
+
85
+ }
86
+
87
+ }
88
+
89
+
90
+ // INGRESS
91
+
92
+ control MyIngress (
93
+ inout my_headers_t hdr,
94
+ inout my_metadata_t meta,
95
+ inout standard_metadata_t standard_metadata)
96
+ {
97
+
98
+ // Variable Definitions
99
+ bit<48> dmac;
100
+ bit<32> nhop_ipv4;
101
+ bit<9> port;
102
+
103
+
104
+ // Action Definitions
105
+ action ecmp_group_action_0(){
106
+ standard_metadata.egress_spec = 9w511;
107
+ }
108
+
109
+ action ecmp_group_action_1(bit<32> nhop_ipv4,bit<9> port){
110
+ meta.routing_metadata.nhop_ipv4 = nhop_ipv4;
111
+ standard_metadata.egress_spec = port;
112
+ hdr.ipv4.ttl = (hdr.ipv4.ttl + 8w255);
113
+ }
114
+
115
+ action ecmp_group_action_2(){
116
+
117
+ }
118
+
119
+ action forward_action_0(bit<48> dmac){
120
+ hdr.ethernet.dstAddr = dmac;
121
+ }
122
+
123
+ action forward_action_1(){
124
+ standard_metadata.egress_spec = 9w511;
125
+ }
126
+
127
+ action forward_action_2(){
128
+
129
+ }
130
+
131
+
132
+ // Table Definitions
133
+
134
+ table ecmp_group {
135
+ key = {
136
+ hdr.ipv4.dstAddr : ternary;
137
+ }
138
+ actions = {
139
+ ecmp_group_action_0;
140
+ ecmp_group_action_1;
141
+ ecmp_group_action_2;
142
+ }
143
+ }
144
+
145
+ table forward {
146
+ key = {
147
+ meta.routing_metadata.nhop_ipv4 : exact;
148
+ }
149
+ actions = {
150
+ forward_action_0;
151
+ forward_action_1;
152
+ forward_action_2;
153
+ }
154
+ }
155
+
156
+
157
+ apply {
158
+
159
+ // Pipeline
160
+ if (!((hdr.ipv4.isValid() ? 1w1 : 1w0) == 1w1)) {} else {
161
+ if (!(hdr.ipv4.ttl > 8w0)) {} else {
162
+ ecmp_group.apply();
163
+ forward.apply();
164
+ }
165
+
166
+ }
167
+
168
+ }
169
+ }
170
+
171
+
172
+ // EGRESS
173
+
174
+ control MyEgress (
175
+ inout my_headers_t hdr,
176
+ inout my_metadata_t meta,
177
+ inout standard_metadata_t standard_metadata)
178
+ {
179
+
180
+ // Variable Definitions
181
+ bit<48> smac;
182
+
183
+
184
+ // Action Definitions
185
+ action send_frame_action_0(bit<48> smac){
186
+ hdr.ethernet.srcAddr = smac;
187
+ }
188
+
189
+ action send_frame_action_1(){
190
+ standard_metadata.egress_spec = 9w511;
191
+ }
192
+
193
+
194
+ // Table Definitions
195
+
196
+ table send_frame {
197
+ key = {
198
+ standard_metadata.egress_port : exact;
199
+ }
200
+ actions = {
201
+ send_frame_action_0;
202
+ send_frame_action_1;
203
+ }
204
+ }
205
+
206
+
207
+ apply {
208
+
209
+ // Pipeline
210
+ send_frame.apply();
211
+ }
212
+ }
213
+
214
+
215
+ // OTHER
216
+ control MyVerifyChecksum(
217
+ inout my_headers_t hdr,
218
+ inout my_metadata_t meta)
219
+ {
220
+ apply { }
221
+ }
222
+
223
+ control MyComputeChecksum(
224
+ inout my_headers_t hdr,
225
+ inout my_metadata_t meta)
226
+ {
227
+ apply { }
228
+ }
229
+ control MyDeparser(
230
+ packet_out packet,
231
+ in my_headers_t hdr)
232
+ {
233
+ apply {
234
+ }
235
+ }
236
+ V1Switch(
237
+ MyParser(),
238
+ MyVerifyChecksum(),
239
+ MyIngress(),
240
+ MyEgress(),
241
+ MyComputeChecksum(),
242
+ MyDeparser()
243
+ ) main;
individual_files/000062__raw-repositories__cornell-netlab__capisce.p4 ADDED
@@ -0,0 +1,374 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <core.p4>
2
+ #include <v1model.p4>
3
+
4
+ // HEADERS
5
+
6
+
7
+ // Define header types
8
+
9
+ header ethernet_t {
10
+ bit<48> srcAddr;
11
+ bit<16> etherType;
12
+ bit<48> dstAddr;
13
+ }
14
+ header ipv4_t {
15
+ bit<8> ttl;
16
+ bit<32> srcAddr;
17
+ bit<8> protocol;
18
+ bit<32> dstAddr;
19
+ }
20
+ header tcp_t {
21
+ bit<16> srcPort;
22
+ bit<16> dstPort;
23
+ }
24
+
25
+ // Assemble headers in a single struct
26
+ struct my_headers_t {
27
+ ethernet_t ethernet;
28
+ ipv4_t ipv4;
29
+ tcp_t tcp;
30
+ }
31
+
32
+
33
+
34
+ // METADATA
35
+
36
+
37
+
38
+ struct ingress_metadata_t {
39
+
40
+ bit<32> nhop_ipv4;
41
+ bit<13> flowlet_map_index;
42
+ bit<32> flowlet_lasttime;
43
+ bit<16> flowlet_id;
44
+ bit<32> flow_ipg;
45
+ bit<14> ecmp_offset;
46
+
47
+ }
48
+
49
+ struct intrinsic_metadata_t {
50
+
51
+ bit<48> ingress_global_timestamp;
52
+
53
+ }
54
+ struct my_metadata_t {
55
+ ingress_metadata_t ingress_metadata;
56
+ intrinsic_metadata_t intrinsic_metadata;
57
+
58
+
59
+ }
60
+
61
+ // PARSER
62
+
63
+ parser MyParser(
64
+ packet_in packet,
65
+ out my_headers_t hdr,
66
+ inout my_metadata_t meta,
67
+ inout standard_metadata_t standard_metadata)
68
+ {
69
+
70
+ // Variable Definitions
71
+
72
+
73
+ // Parser state machine
74
+
75
+
76
+ state parse_ethernet {
77
+ packet.extract(hdr.ethernet);
78
+ transition select(hdr.ethernet.etherType){
79
+ (16w2048) : parse_ipv4;
80
+ default : accept;
81
+ }
82
+
83
+ }
84
+
85
+
86
+ state parse_ipv4 {
87
+ packet.extract(hdr.ipv4);
88
+ transition select(hdr.ipv4.protocol){
89
+ (8w6) : parse_tcp;
90
+ default : accept;
91
+ }
92
+
93
+ }
94
+
95
+
96
+ state parse_tcp {
97
+ packet.extract(hdr.tcp);
98
+ transition accept;
99
+ }
100
+
101
+
102
+ state start {
103
+ packet.extract(hdr.ethernet);
104
+ transition accept;
105
+ }
106
+
107
+ }
108
+
109
+
110
+ // INGRESS
111
+
112
+ control MyIngress (
113
+ inout my_headers_t hdr,
114
+ inout my_metadata_t meta,
115
+ inout standard_metadata_t standard_metadata)
116
+ {
117
+
118
+ // Variable Definitions
119
+ bit<13> DEVNULL_flowlet_id_lookup_flowlet_map;
120
+ bit<13> DEVNULL_flowlet_id_update_flowlet_id_index;
121
+ bit<16> DEVNULL_flowlet_id_update_flowlet_id_value;
122
+ bit<13> DEVNULL_flowlet_lasttime_lookup_flowlet_map;
123
+ bit<13> DEVNULL_flowlet_lasttime_lookup_flowlet_map_index;
124
+ bit<48> DEVNULL_flowlet_lasttime_lookup_flowlet_map_value;
125
+ bit<48> dmac;
126
+ bit<8> ecmp_base;
127
+ bit<8> ecmp_count;
128
+ bit<16> flowlet_id_lookup_flowlet_map;
129
+ bit<32> flowlet_lasttime_lookup_flowlet_map;
130
+ bit<13> lookup_flowlet_map_hash_crc16_meta__ingress_metadata__flowlet_map_index;
131
+ bit<32> lookup_flowlet_map_hash_crc16_meta__ingress_metadata__flowlet_map_index_0;
132
+ bit<32> lookup_flowlet_map_hash_crc16_meta__ingress_metadata__flowlet_map_index_1;
133
+ bit<8> lookup_flowlet_map_hash_crc16_meta__ingress_metadata__flowlet_map_index_2;
134
+ bit<16> lookup_flowlet_map_hash_crc16_meta__ingress_metadata__flowlet_map_index_3;
135
+ bit<16> lookup_flowlet_map_hash_crc16_meta__ingress_metadata__flowlet_map_index_4;
136
+ bit<32> nhop_ipv4;
137
+ bit<9> port;
138
+ bit<14> set_ecmp_select_hash_crc16_meta__ingress_metadata__ecmp_offset;
139
+ bit<32> set_ecmp_select_hash_crc16_meta__ingress_metadata__ecmp_offset_0;
140
+ bit<32> set_ecmp_select_hash_crc16_meta__ingress_metadata__ecmp_offset_1;
141
+ bit<8> set_ecmp_select_hash_crc16_meta__ingress_metadata__ecmp_offset_2;
142
+ bit<16> set_ecmp_select_hash_crc16_meta__ingress_metadata__ecmp_offset_3;
143
+ bit<16> set_ecmp_select_hash_crc16_meta__ingress_metadata__ecmp_offset_4;
144
+ bit<16> set_ecmp_select_hash_crc16_meta__ingress_metadata__ecmp_offset_5;
145
+
146
+
147
+ // Action Definitions
148
+ action ecmp_group_action_0(){
149
+ standard_metadata.egress_spec = 9w511;
150
+ }
151
+
152
+ action ecmp_group_action_1(bit<8> ecmp_base,bit<8> ecmp_count){
153
+ set_ecmp_select_hash_crc16_meta__ingress_metadata__ecmp_offset_0 = hdr.ipv4.srcAddr;
154
+ set_ecmp_select_hash_crc16_meta__ingress_metadata__ecmp_offset_1 = hdr.ipv4.dstAddr;
155
+ set_ecmp_select_hash_crc16_meta__ingress_metadata__ecmp_offset_2 = hdr.ipv4.protocol;
156
+ set_ecmp_select_hash_crc16_meta__ingress_metadata__ecmp_offset_3 = hdr.tcp.srcPort;
157
+ set_ecmp_select_hash_crc16_meta__ingress_metadata__ecmp_offset_4 = hdr.tcp.dstPort;
158
+ set_ecmp_select_hash_crc16_meta__ingress_metadata__ecmp_offset_5 = meta.ingress_metadata.flowlet_id;
159
+
160
+
161
+ meta.ingress_metadata.ecmp_offset = set_ecmp_select_hash_crc16_meta__ingress_metadata__ecmp_offset;
162
+ }
163
+
164
+ action ecmp_group_action_2(){
165
+
166
+ }
167
+
168
+ action ecmp_nhop_action_0(){
169
+ standard_metadata.egress_spec = 9w511;
170
+ }
171
+
172
+ action ecmp_nhop_action_1(bit<32> nhop_ipv4,bit<9> port){
173
+ meta.ingress_metadata.nhop_ipv4 = nhop_ipv4;
174
+ standard_metadata.egress_spec = port;
175
+ hdr.ipv4.ttl = (hdr.ipv4.ttl + 8w255);
176
+ }
177
+
178
+ action ecmp_nhop_action_2(){
179
+
180
+ }
181
+
182
+ action flowlet_action_0(){
183
+ lookup_flowlet_map_hash_crc16_meta__ingress_metadata__flowlet_map_index_0 = hdr.ipv4.srcAddr;
184
+ lookup_flowlet_map_hash_crc16_meta__ingress_metadata__flowlet_map_index_1 = hdr.ipv4.dstAddr;
185
+ lookup_flowlet_map_hash_crc16_meta__ingress_metadata__flowlet_map_index_2 = hdr.ipv4.protocol;
186
+ lookup_flowlet_map_hash_crc16_meta__ingress_metadata__flowlet_map_index_3 = hdr.tcp.srcPort;
187
+ lookup_flowlet_map_hash_crc16_meta__ingress_metadata__flowlet_map_index_4 = hdr.tcp.dstPort;
188
+
189
+
190
+ meta.ingress_metadata.flowlet_map_index = lookup_flowlet_map_hash_crc16_meta__ingress_metadata__flowlet_map_index;
191
+ DEVNULL_flowlet_id_lookup_flowlet_map = meta.ingress_metadata.flowlet_map_index;
192
+ meta.ingress_metadata.flowlet_id = flowlet_id_lookup_flowlet_map;
193
+ meta.ingress_metadata.flow_ipg = meta.intrinsic_metadata.ingress_global_timestamp[31:0];
194
+ DEVNULL_flowlet_lasttime_lookup_flowlet_map = meta.ingress_metadata.flowlet_map_index;
195
+ meta.ingress_metadata.flowlet_lasttime = flowlet_lasttime_lookup_flowlet_map;
196
+ meta.ingress_metadata.flow_ipg = (meta.ingress_metadata.flow_ipg - meta.ingress_metadata.flowlet_lasttime);
197
+ DEVNULL_flowlet_lasttime_lookup_flowlet_map_index = meta.ingress_metadata.flowlet_map_index;
198
+ DEVNULL_flowlet_lasttime_lookup_flowlet_map_value = meta.intrinsic_metadata.ingress_global_timestamp;
199
+ }
200
+
201
+ action flowlet_action_1(){
202
+
203
+ }
204
+
205
+ action forward_action_0(){
206
+ hdr.ethernet.dstAddr = dmac;
207
+ }
208
+
209
+ action forward_action_1(){
210
+ standard_metadata.egress_spec = 9w511;
211
+ }
212
+
213
+ action forward_action_2(){
214
+
215
+ }
216
+
217
+ action new_flowlet_action_0(){
218
+ meta.ingress_metadata.flowlet_id = (meta.ingress_metadata.flowlet_id + 16w1);
219
+ DEVNULL_flowlet_id_update_flowlet_id_index = meta.ingress_metadata.flowlet_map_index;
220
+ DEVNULL_flowlet_id_update_flowlet_id_value = meta.ingress_metadata.flowlet_id;
221
+ }
222
+
223
+ action new_flowlet_action_1(){
224
+
225
+ }
226
+
227
+
228
+ // Table Definitions
229
+
230
+ table ecmp_group {
231
+ key = {
232
+ hdr.ipv4.dstAddr : ternary;
233
+ }
234
+ actions = {
235
+ ecmp_group_action_0;
236
+ ecmp_group_action_1;
237
+ ecmp_group_action_2;
238
+ }
239
+ }
240
+
241
+ table ecmp_nhop {
242
+ key = {
243
+ meta.ingress_metadata.ecmp_offset : exact;
244
+ }
245
+ actions = {
246
+ ecmp_nhop_action_0;
247
+ ecmp_nhop_action_1;
248
+ ecmp_nhop_action_2;
249
+ }
250
+ }
251
+
252
+ table flowlet {
253
+ key = {
254
+ }
255
+ actions = {
256
+ flowlet_action_0;
257
+ flowlet_action_1;
258
+ }
259
+ }
260
+
261
+ table forward {
262
+ key = {
263
+ meta.ingress_metadata.nhop_ipv4 : exact;
264
+ }
265
+ actions = {
266
+ forward_action_0;
267
+ forward_action_1;
268
+ forward_action_2;
269
+ }
270
+ }
271
+
272
+ table new_flowlet {
273
+ key = {
274
+ }
275
+ actions = {
276
+ new_flowlet_action_0;
277
+ new_flowlet_action_1;
278
+ }
279
+ }
280
+
281
+
282
+ apply {
283
+
284
+ // Pipeline
285
+
286
+ flowlet.apply();
287
+ if (!(meta.ingress_metadata.flow_ipg > 32w50000)) {} else {
288
+ new_flowlet.apply();
289
+ }
290
+
291
+ ecmp_group.apply();
292
+ ecmp_nhop.apply();
293
+ forward.apply();
294
+ }
295
+ }
296
+
297
+
298
+ // EGRESS
299
+
300
+ control MyEgress (
301
+ inout my_headers_t hdr,
302
+ inout my_metadata_t meta,
303
+ inout standard_metadata_t standard_metadata)
304
+ {
305
+
306
+ // Variable Definitions
307
+ bit<48> smac;
308
+
309
+
310
+ // Action Definitions
311
+ action send_frame_action_0(bit<48> smac){
312
+ hdr.ethernet.srcAddr = smac;
313
+ }
314
+
315
+ action send_frame_action_1(){
316
+ standard_metadata.egress_spec = 9w511;
317
+ }
318
+
319
+ action send_frame_action_2(){
320
+
321
+ }
322
+
323
+
324
+ // Table Definitions
325
+
326
+ table send_frame {
327
+ key = {
328
+ standard_metadata.egress_port : exact;
329
+ }
330
+ actions = {
331
+ send_frame_action_0;
332
+ send_frame_action_1;
333
+ send_frame_action_2;
334
+ }
335
+ }
336
+
337
+
338
+ apply {
339
+
340
+ // Pipeline
341
+ send_frame.apply();
342
+ }
343
+ }
344
+
345
+
346
+ // OTHER
347
+ control MyVerifyChecksum(
348
+ inout my_headers_t hdr,
349
+ inout my_metadata_t meta)
350
+ {
351
+ apply { }
352
+ }
353
+
354
+ control MyComputeChecksum(
355
+ inout my_headers_t hdr,
356
+ inout my_metadata_t meta)
357
+ {
358
+ apply { }
359
+ }
360
+ control MyDeparser(
361
+ packet_out packet,
362
+ in my_headers_t hdr)
363
+ {
364
+ apply {
365
+ }
366
+ }
367
+ V1Switch(
368
+ MyParser(),
369
+ MyVerifyChecksum(),
370
+ MyIngress(),
371
+ MyEgress(),
372
+ MyComputeChecksum(),
373
+ MyDeparser()
374
+ ) main;
individual_files/000063__raw-repositories__cornell-netlab__capisce.p4 ADDED
@@ -0,0 +1,274 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <core.p4>
2
+ #include <v1model.p4>
3
+
4
+ // HEADERS
5
+
6
+
7
+ // Define header types
8
+
9
+ header ethernet_t {
10
+ bit<48> srcAddr;
11
+ bit<16> etherType;
12
+ bit<48> dstAddr;
13
+ }
14
+ header ipv4_t {
15
+ bit<8> ttl;
16
+ bit<32> srcAddr;
17
+ bit<8> protocol;
18
+ bit<32> dstAddr;
19
+ }
20
+ header tcp_t {
21
+
22
+ }
23
+
24
+ // Assemble headers in a single struct
25
+ struct my_headers_t {
26
+ ethernet_t ethernet;
27
+ ipv4_t ipv4;
28
+ tcp_t tcp;
29
+ }
30
+
31
+
32
+
33
+ // METADATA
34
+
35
+
36
+
37
+ struct routing_metadata_t {
38
+
39
+ bit<32> nhop_ipv4;
40
+
41
+ }
42
+ struct my_metadata_t {
43
+ routing_metadata_t routing_metadata;
44
+
45
+
46
+ }
47
+
48
+ // PARSER
49
+
50
+ parser MyParser(
51
+ packet_in packet,
52
+ out my_headers_t hdr,
53
+ inout my_metadata_t meta,
54
+ inout standard_metadata_t standard_metadata)
55
+ {
56
+
57
+ // Variable Definitions
58
+
59
+
60
+ // Parser state machine
61
+
62
+
63
+ state parse_ethernet {
64
+ packet.extract(hdr.ethernet);
65
+ transition select(hdr.ethernet.etherType){
66
+ (16w2048) : parse_ipv4;
67
+ default : accept;
68
+ }
69
+
70
+ }
71
+
72
+
73
+ state parse_ipv4 {
74
+ packet.extract(hdr.ipv4);
75
+ transition select(hdr.ipv4.protocol){
76
+ (8w6) : parse_tcp;
77
+ default : accept;
78
+ }
79
+
80
+ }
81
+
82
+
83
+ state parse_tcp {
84
+ packet.extract(hdr.tcp);
85
+ transition accept;
86
+ }
87
+
88
+
89
+ state start {
90
+
91
+ transition parse_ethernet;
92
+ }
93
+
94
+ }
95
+
96
+
97
+ // INGRESS
98
+
99
+ control MyIngress (
100
+ inout my_headers_t hdr,
101
+ inout my_metadata_t meta,
102
+ inout standard_metadata_t standard_metadata)
103
+ {
104
+
105
+ // Variable Definitions
106
+ bit<48> dmac;
107
+ bit<32> idx;
108
+ bit<9> port;
109
+ bit<32> set_nhop;
110
+
111
+
112
+ // Action Definitions
113
+ action count_table_action_0(bit<32> idx){
114
+
115
+ }
116
+
117
+ action count_table_action_1(){
118
+ standard_metadata.egress_spec = 9w511;
119
+ }
120
+
121
+ action count_table_action_2(){
122
+
123
+ }
124
+
125
+ action forward_action_0(bit<48> dmac){
126
+ hdr.ethernet.dstAddr = dmac;
127
+ }
128
+
129
+ action forward_action_1(){
130
+ standard_metadata.egress_spec = 9w511;
131
+ }
132
+
133
+ action forward_action_2(){
134
+
135
+ }
136
+
137
+ action ipv4_lpm_action_0(bit<32> set_nhop,bit<9> port){
138
+ meta.routing_metadata.nhop_ipv4 = set_nhop;
139
+ standard_metadata.egress_spec = port;
140
+ hdr.ipv4.ttl = (hdr.ipv4.ttl + 8w255);
141
+ }
142
+
143
+ action ipv4_lpm_action_1(){
144
+ standard_metadata.egress_spec = 9w511;
145
+ }
146
+
147
+ action ipv4_lpm_action_2(){
148
+
149
+ }
150
+
151
+
152
+ // Table Definitions
153
+
154
+ table count_table {
155
+ key = {
156
+ hdr.ipv4.srcAddr : ternary;
157
+ }
158
+ actions = {
159
+ count_table_action_0;
160
+ count_table_action_1;
161
+ count_table_action_2;
162
+ }
163
+ }
164
+
165
+ table forward {
166
+ key = {
167
+ meta.routing_metadata.nhop_ipv4 : exact;
168
+ }
169
+ actions = {
170
+ forward_action_0;
171
+ forward_action_1;
172
+ forward_action_2;
173
+ }
174
+ }
175
+
176
+ table ipv4_lpm {
177
+ key = {
178
+ hdr.ipv4.dstAddr : ternary;
179
+ }
180
+ actions = {
181
+ ipv4_lpm_action_0;
182
+ ipv4_lpm_action_1;
183
+ ipv4_lpm_action_2;
184
+ }
185
+ }
186
+
187
+
188
+ apply {
189
+
190
+ // Pipeline
191
+ count_table.apply();
192
+ ipv4_lpm.apply();
193
+ forward.apply();
194
+ }
195
+ }
196
+
197
+
198
+ // EGRESS
199
+
200
+ control MyEgress (
201
+ inout my_headers_t hdr,
202
+ inout my_metadata_t meta,
203
+ inout standard_metadata_t standard_metadata)
204
+ {
205
+
206
+ // Variable Definitions
207
+ bit<48> smac;
208
+
209
+
210
+ // Action Definitions
211
+ action send_frame_action_0(bit<48> smac){
212
+ hdr.ethernet.srcAddr = smac;
213
+ }
214
+
215
+ action send_frame_action_1(){
216
+ standard_metadata.egress_spec = 9w511;
217
+ }
218
+
219
+ action send_frame_action_2(){
220
+
221
+ }
222
+
223
+
224
+ // Table Definitions
225
+
226
+ table send_frame {
227
+ key = {
228
+ standard_metadata.egress_port : exact;
229
+ }
230
+ actions = {
231
+ send_frame_action_0;
232
+ send_frame_action_1;
233
+ send_frame_action_2;
234
+ }
235
+ }
236
+
237
+
238
+ apply {
239
+
240
+ // Pipeline
241
+ send_frame.apply();
242
+ }
243
+ }
244
+
245
+
246
+ // OTHER
247
+ control MyVerifyChecksum(
248
+ inout my_headers_t hdr,
249
+ inout my_metadata_t meta)
250
+ {
251
+ apply { }
252
+ }
253
+
254
+ control MyComputeChecksum(
255
+ inout my_headers_t hdr,
256
+ inout my_metadata_t meta)
257
+ {
258
+ apply { }
259
+ }
260
+ control MyDeparser(
261
+ packet_out packet,
262
+ in my_headers_t hdr)
263
+ {
264
+ apply {
265
+ }
266
+ }
267
+ V1Switch(
268
+ MyParser(),
269
+ MyVerifyChecksum(),
270
+ MyIngress(),
271
+ MyEgress(),
272
+ MyComputeChecksum(),
273
+ MyDeparser()
274
+ ) main;
individual_files/000064__raw-repositories__cornell-netlab__capisce.p4 ADDED
@@ -0,0 +1,340 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <core.p4>
2
+ #include <v1model.p4>
3
+
4
+ // HEADERS
5
+
6
+
7
+ // Define header types
8
+
9
+ header ethernet_t {
10
+ bit<48> srcAddr;
11
+ bit<16> etherType;
12
+ bit<48> dstAddr;
13
+ }
14
+ header ipv4_t {
15
+ bit<8> ttl;
16
+ bit<32> srcAddr;
17
+ bit<8> protocol;
18
+ bit<32> dstAddr;
19
+ }
20
+ header tcp_t {
21
+ bit<16> srcPort;
22
+ bit<16> dstPort;
23
+ }
24
+
25
+ // Assemble headers in a single struct
26
+ struct my_headers_t {
27
+ ethernet_t ethernet;
28
+ ipv4_t ipv4;
29
+ tcp_t tcp;
30
+ }
31
+
32
+
33
+
34
+ // METADATA
35
+
36
+
37
+
38
+ struct custom_metadata_t {
39
+
40
+ bit<32> nhop_ipv4;
41
+ bit<16> hash_val2;
42
+ bit<16> hash_val1;
43
+ bit<16> count_val2;
44
+ bit<16> count_val1;
45
+
46
+ }
47
+ struct my_metadata_t {
48
+ custom_metadata_t custom_metadata;
49
+
50
+
51
+ }
52
+
53
+ // PARSER
54
+
55
+ parser MyParser(
56
+ packet_in packet,
57
+ out my_headers_t hdr,
58
+ inout my_metadata_t meta,
59
+ inout standard_metadata_t standard_metadata)
60
+ {
61
+
62
+ // Variable Definitions
63
+
64
+
65
+ // Parser state machine
66
+
67
+
68
+ state parse_ethernet {
69
+ packet.extract(hdr.ethernet);
70
+ transition select(hdr.ethernet.etherType){
71
+ (16w2048) : parse_ipv4;
72
+ default : accept;
73
+ }
74
+
75
+ }
76
+
77
+
78
+ state parse_ipv4 {
79
+ packet.extract(hdr.ipv4);
80
+ transition select(hdr.ipv4.protocol){
81
+ (8w6) : parse_tcp;
82
+ default : accept;
83
+ }
84
+
85
+ }
86
+
87
+
88
+ state parse_tcp {
89
+ packet.extract(hdr.tcp);
90
+ transition accept;
91
+ }
92
+
93
+
94
+ state start {
95
+
96
+ transition parse_ethernet;
97
+ }
98
+
99
+ }
100
+
101
+
102
+ // INGRESS
103
+
104
+ control MyIngress (
105
+ inout my_headers_t hdr,
106
+ inout my_metadata_t meta,
107
+ inout standard_metadata_t standard_metadata)
108
+ {
109
+
110
+ // Variable Definitions
111
+ bit<16> DEVNULL_heavy_hitter_counter1_set_heavy_hitter_count;
112
+ bit<16> DEVNULL_heavy_hitter_counter1_set_heavy_hitter_count_index;
113
+ bit<16> DEVNULL_heavy_hitter_counter1_set_heavy_hitter_count_value;
114
+ bit<16> DEVNULL_heavy_hitter_counter2_set_heavy_hitter_count;
115
+ bit<16> DEVNULL_heavy_hitter_counter2_set_heavy_hitter_count_index;
116
+ bit<16> DEVNULL_heavy_hitter_counter2_set_heavy_hitter_count_value;
117
+ bit<48> dmac;
118
+ bit<16> heavy_hitter_counter1_set_heavy_hitter_count;
119
+ bit<16> heavy_hitter_counter2_set_heavy_hitter_count;
120
+ bit<32> nhop_ipv4;
121
+ bit<9> port;
122
+ bit<16> set_heavy_hitter_count_hash_crc16_meta__custom_metadata__hash_val2;
123
+ bit<32> set_heavy_hitter_count_hash_crc16_meta__custom_metadata__hash_val2_0;
124
+ bit<32> set_heavy_hitter_count_hash_crc16_meta__custom_metadata__hash_val2_1;
125
+ bit<8> set_heavy_hitter_count_hash_crc16_meta__custom_metadata__hash_val2_2;
126
+ bit<16> set_heavy_hitter_count_hash_crc16_meta__custom_metadata__hash_val2_3;
127
+ bit<16> set_heavy_hitter_count_hash_crc16_meta__custom_metadata__hash_val2_4;
128
+ bit<16> set_heavy_hitter_count_hash_csum16_meta__custom_metadata__hash_val1;
129
+ bit<32> set_heavy_hitter_count_hash_csum16_meta__custom_metadata__hash_val1_0;
130
+ bit<32> set_heavy_hitter_count_hash_csum16_meta__custom_metadata__hash_val1_1;
131
+ bit<8> set_heavy_hitter_count_hash_csum16_meta__custom_metadata__hash_val1_2;
132
+ bit<16> set_heavy_hitter_count_hash_csum16_meta__custom_metadata__hash_val1_3;
133
+ bit<16> set_heavy_hitter_count_hash_csum16_meta__custom_metadata__hash_val1_4;
134
+
135
+
136
+ // Action Definitions
137
+ action drop_heavy_hitter_table_action_0(){
138
+ standard_metadata.egress_spec = 9w511;
139
+ }
140
+
141
+ action drop_heavy_hitter_table_action_1(){
142
+
143
+ }
144
+
145
+ action forward_action_0(bit<48> dmac){
146
+ hdr.ethernet.dstAddr = dmac;
147
+ }
148
+
149
+ action forward_action_1(){
150
+ standard_metadata.egress_spec = 9w511;
151
+ }
152
+
153
+ action forward_action_2(){
154
+
155
+ }
156
+
157
+ action ipv4_lpm_action_0(bit<32> nhop_ipv4,bit<9> port){
158
+ meta.custom_metadata.nhop_ipv4 = nhop_ipv4;
159
+ standard_metadata.egress_spec = port;
160
+ hdr.ipv4.ttl = (hdr.ipv4.ttl + 8w255);
161
+ }
162
+
163
+ action ipv4_lpm_action_1(){
164
+ standard_metadata.egress_spec = 9w511;
165
+ }
166
+
167
+ action ipv4_lpm_action_2(){
168
+
169
+ }
170
+
171
+ action set_heavy_hitter_count_table_action_0(){
172
+ set_heavy_hitter_count_hash_csum16_meta__custom_metadata__hash_val1_0 = hdr.ipv4.srcAddr;
173
+ set_heavy_hitter_count_hash_csum16_meta__custom_metadata__hash_val1_1 = hdr.ipv4.dstAddr;
174
+ set_heavy_hitter_count_hash_csum16_meta__custom_metadata__hash_val1_2 = hdr.ipv4.protocol;
175
+ set_heavy_hitter_count_hash_csum16_meta__custom_metadata__hash_val1_3 = hdr.tcp.srcPort;
176
+ set_heavy_hitter_count_hash_csum16_meta__custom_metadata__hash_val1_4 = hdr.tcp.dstPort;
177
+
178
+
179
+ meta.custom_metadata.hash_val1 = set_heavy_hitter_count_hash_csum16_meta__custom_metadata__hash_val1;
180
+ DEVNULL_heavy_hitter_counter1_set_heavy_hitter_count = meta.custom_metadata.hash_val1;
181
+ meta.custom_metadata.count_val2 = heavy_hitter_counter1_set_heavy_hitter_count;
182
+ meta.custom_metadata.count_val2 = (meta.custom_metadata.count_val2 + 16w1);
183
+ DEVNULL_heavy_hitter_counter1_set_heavy_hitter_count_index = meta.custom_metadata.hash_val1;
184
+ DEVNULL_heavy_hitter_counter1_set_heavy_hitter_count_value = meta.custom_metadata.count_val2;
185
+ set_heavy_hitter_count_hash_crc16_meta__custom_metadata__hash_val2_0 = hdr.ipv4.srcAddr;
186
+ set_heavy_hitter_count_hash_crc16_meta__custom_metadata__hash_val2_1 = hdr.ipv4.dstAddr;
187
+ set_heavy_hitter_count_hash_crc16_meta__custom_metadata__hash_val2_2 = hdr.ipv4.protocol;
188
+ set_heavy_hitter_count_hash_crc16_meta__custom_metadata__hash_val2_3 = hdr.tcp.srcPort;
189
+ set_heavy_hitter_count_hash_crc16_meta__custom_metadata__hash_val2_4 = hdr.tcp.dstPort;
190
+
191
+
192
+ meta.custom_metadata.hash_val2 = set_heavy_hitter_count_hash_crc16_meta__custom_metadata__hash_val2;
193
+ DEVNULL_heavy_hitter_counter2_set_heavy_hitter_count = meta.custom_metadata.hash_val2;
194
+ meta.custom_metadata.count_val1 = heavy_hitter_counter2_set_heavy_hitter_count;
195
+ meta.custom_metadata.count_val1 = (meta.custom_metadata.count_val1 + 16w1);
196
+ DEVNULL_heavy_hitter_counter2_set_heavy_hitter_count_index = meta.custom_metadata.hash_val2;
197
+ DEVNULL_heavy_hitter_counter2_set_heavy_hitter_count_value = meta.custom_metadata.count_val1;
198
+ }
199
+
200
+ action set_heavy_hitter_count_table_action_1(){
201
+
202
+ }
203
+
204
+
205
+ // Table Definitions
206
+
207
+ table drop_heavy_hitter_table {
208
+ key = {
209
+ }
210
+ actions = {
211
+ drop_heavy_hitter_table_action_0;
212
+ drop_heavy_hitter_table_action_1;
213
+ }
214
+ }
215
+
216
+ table forward {
217
+ key = {
218
+ meta.custom_metadata.nhop_ipv4 : exact;
219
+ }
220
+ actions = {
221
+ forward_action_0;
222
+ forward_action_1;
223
+ forward_action_2;
224
+ }
225
+ }
226
+
227
+ table ipv4_lpm {
228
+ key = {
229
+ hdr.ipv4.dstAddr : ternary;
230
+ }
231
+ actions = {
232
+ ipv4_lpm_action_0;
233
+ ipv4_lpm_action_1;
234
+ ipv4_lpm_action_2;
235
+ }
236
+ }
237
+
238
+ table set_heavy_hitter_count_table {
239
+ key = {
240
+ }
241
+ actions = {
242
+ set_heavy_hitter_count_table_action_0;
243
+ set_heavy_hitter_count_table_action_1;
244
+ }
245
+ }
246
+
247
+
248
+ apply {
249
+
250
+ // Pipeline
251
+
252
+ set_heavy_hitter_count_table.apply();
253
+ if (!((meta.custom_metadata.count_val2 > 16w100) && (meta.custom_metadata.count_val1 > 16w100))) {
254
+ ipv4_lpm.apply();
255
+ forward.apply();
256
+ } else {
257
+ drop_heavy_hitter_table.apply();
258
+ }
259
+
260
+ }
261
+ }
262
+
263
+
264
+ // EGRESS
265
+
266
+ control MyEgress (
267
+ inout my_headers_t hdr,
268
+ inout my_metadata_t meta,
269
+ inout standard_metadata_t standard_metadata)
270
+ {
271
+
272
+ // Variable Definitions
273
+ bit<48> smac;
274
+
275
+
276
+ // Action Definitions
277
+ action send_frame_action_0(bit<48> smac){
278
+ hdr.ethernet.srcAddr = smac;
279
+ }
280
+
281
+ action send_frame_action_1(){
282
+ standard_metadata.egress_spec = 9w511;
283
+ }
284
+
285
+ action send_frame_action_2(){
286
+
287
+ }
288
+
289
+
290
+ // Table Definitions
291
+
292
+ table send_frame {
293
+ key = {
294
+ standard_metadata.egress_port : exact;
295
+ }
296
+ actions = {
297
+ send_frame_action_0;
298
+ send_frame_action_1;
299
+ send_frame_action_2;
300
+ }
301
+ }
302
+
303
+
304
+ apply {
305
+
306
+ // Pipeline
307
+ send_frame.apply();
308
+ }
309
+ }
310
+
311
+
312
+ // OTHER
313
+ control MyVerifyChecksum(
314
+ inout my_headers_t hdr,
315
+ inout my_metadata_t meta)
316
+ {
317
+ apply { }
318
+ }
319
+
320
+ control MyComputeChecksum(
321
+ inout my_headers_t hdr,
322
+ inout my_metadata_t meta)
323
+ {
324
+ apply { }
325
+ }
326
+ control MyDeparser(
327
+ packet_out packet,
328
+ in my_headers_t hdr)
329
+ {
330
+ apply {
331
+ }
332
+ }
333
+ V1Switch(
334
+ MyParser(),
335
+ MyVerifyChecksum(),
336
+ MyIngress(),
337
+ MyEgress(),
338
+ MyComputeChecksum(),
339
+ MyDeparser()
340
+ ) main;
individual_files/000065__raw-repositories__cornell-netlab__capisce.p4 ADDED
@@ -0,0 +1,222 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <core.p4>
2
+ #include <v1model.p4>
3
+
4
+ // HEADERS
5
+
6
+
7
+ // Define header types
8
+
9
+ header ethernet_t {
10
+ bit<16> etherType;
11
+ }
12
+ header ipv4_t {
13
+ bit<8> ttl;
14
+ bit<8> protocol;
15
+ bit<32> dstAddr;
16
+ }
17
+ header udp_t {
18
+
19
+ }
20
+
21
+ // Assemble headers in a single struct
22
+ struct my_headers_t {
23
+ ethernet_t ethernet;
24
+ ipv4_t ipv4;
25
+ udp_t udp;
26
+ }
27
+
28
+
29
+
30
+ // METADATA
31
+
32
+
33
+
34
+ struct intrinsic_metadata_t {
35
+
36
+ bit<16> mcast_grp;
37
+ bit<16> egress_rid;
38
+
39
+ }
40
+ struct my_metadata_t {
41
+ intrinsic_metadata_t intrinsic_metadata;
42
+
43
+
44
+ }
45
+
46
+ // PARSER
47
+
48
+ parser MyParser(
49
+ packet_in packet,
50
+ out my_headers_t hdr,
51
+ inout my_metadata_t meta,
52
+ inout standard_metadata_t standard_metadata)
53
+ {
54
+
55
+ // Variable Definitions
56
+
57
+
58
+ // Parser state machine
59
+
60
+
61
+ state parse_ethernet {
62
+ packet.extract(hdr.ethernet);
63
+ transition select(hdr.ethernet.etherType){
64
+ (16w2048) : parse_ipv4;
65
+ default : accept;
66
+ }
67
+
68
+ }
69
+
70
+
71
+ state parse_ipv4 {
72
+ packet.extract(hdr.ipv4);
73
+ transition select(hdr.ipv4.protocol){
74
+ (8w17) : parse_udp;
75
+ default : accept;
76
+ }
77
+
78
+ }
79
+
80
+
81
+ state parse_udp {
82
+ packet.extract(hdr.udp);
83
+ transition accept;
84
+ }
85
+
86
+
87
+ state start {
88
+
89
+ transition parse_ethernet;
90
+ }
91
+
92
+ }
93
+
94
+
95
+ // INGRESS
96
+
97
+ control MyIngress (
98
+ inout my_headers_t hdr,
99
+ inout my_metadata_t meta,
100
+ inout standard_metadata_t standard_metadata)
101
+ {
102
+
103
+ // Variable Definitions
104
+ bit<16> mcast_group;
105
+
106
+
107
+ // Action Definitions
108
+ action set_mcg_action_0(bit<16> mcast_group){
109
+ meta.intrinsic_metadata.mcast_grp = mcast_group;
110
+ }
111
+
112
+ action set_mcg_action_1(){
113
+ standard_metadata.egress_spec = 9w511;
114
+ }
115
+
116
+ action set_mcg_action_2(){
117
+
118
+ }
119
+
120
+
121
+ // Table Definitions
122
+
123
+ table set_mcg {
124
+ key = {
125
+ hdr.ipv4.dstAddr : exact;
126
+ }
127
+ actions = {
128
+ set_mcg_action_0;
129
+ set_mcg_action_1;
130
+ set_mcg_action_2;
131
+ }
132
+ }
133
+
134
+
135
+ apply {
136
+
137
+ // Pipeline
138
+
139
+ set_mcg.apply();
140
+ }
141
+ }
142
+
143
+
144
+ // EGRESS
145
+
146
+ control MyEgress (
147
+ inout my_headers_t hdr,
148
+ inout my_metadata_t meta,
149
+ inout standard_metadata_t standard_metadata)
150
+ {
151
+
152
+ // Variable Definitions
153
+ bit<32> dst_ip;
154
+
155
+
156
+ // Action Definitions
157
+ action nat_table_action_0(bit<32> dst_ip){
158
+ hdr.ipv4.dstAddr = dst_ip;
159
+ hdr.ipv4.ttl = (hdr.ipv4.ttl + 8w255);
160
+ }
161
+
162
+ action nat_table_action_1(){
163
+ standard_metadata.egress_spec = 9w511;
164
+ }
165
+
166
+ action nat_table_action_2(){
167
+
168
+ }
169
+
170
+
171
+ // Table Definitions
172
+
173
+ table nat_table {
174
+ key = {
175
+ meta.intrinsic_metadata.egress_rid : exact;
176
+ hdr.ipv4.dstAddr : exact;
177
+ }
178
+ actions = {
179
+ nat_table_action_0;
180
+ nat_table_action_1;
181
+ nat_table_action_2;
182
+ }
183
+ }
184
+
185
+
186
+ apply {
187
+
188
+ // Pipeline
189
+ nat_table.apply();
190
+ }
191
+ }
192
+
193
+
194
+ // OTHER
195
+ control MyVerifyChecksum(
196
+ inout my_headers_t hdr,
197
+ inout my_metadata_t meta)
198
+ {
199
+ apply { }
200
+ }
201
+
202
+ control MyComputeChecksum(
203
+ inout my_headers_t hdr,
204
+ inout my_metadata_t meta)
205
+ {
206
+ apply { }
207
+ }
208
+ control MyDeparser(
209
+ packet_out packet,
210
+ in my_headers_t hdr)
211
+ {
212
+ apply {
213
+ }
214
+ }
215
+ V1Switch(
216
+ MyParser(),
217
+ MyVerifyChecksum(),
218
+ MyIngress(),
219
+ MyEgress(),
220
+ MyComputeChecksum(),
221
+ MyDeparser()
222
+ ) main;
individual_files/000066__raw-repositories__cornell-netlab__capisce.p4 ADDED
@@ -0,0 +1,387 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <core.p4>
2
+ #include <v1model.p4>
3
+
4
+ // HEADERS
5
+
6
+
7
+ // Define header types
8
+
9
+ header ethernet_t {
10
+ bit<48> srcAddr;
11
+ bit<16> etherType;
12
+ bit<48> dstAddr;
13
+ }
14
+ header ipv4_t {
15
+ bit<8> ttl;
16
+ bit<16> totalLen;
17
+ bit<8> protocol;
18
+ bit<32> dstAddr;
19
+ }
20
+ header ndp_t {
21
+ bit<16> flags;
22
+ }
23
+
24
+ // Assemble headers in a single struct
25
+ struct my_headers_t {
26
+ ethernet_t ethernet;
27
+ ipv4_t ipv4;
28
+ ndp_t ndp;
29
+ }
30
+
31
+
32
+
33
+ // METADATA
34
+
35
+
36
+
37
+ struct meta_t {
38
+
39
+ bit<16> register_tmp;
40
+ bit<16> ndpflags;
41
+
42
+ }
43
+
44
+ struct routing_metadata_t {
45
+
46
+ bit<32> nhop_ipv4;
47
+
48
+ }
49
+ struct my_metadata_t {
50
+ meta_t meta;
51
+ routing_metadata_t routing_metadata;
52
+
53
+
54
+ }
55
+
56
+ // PARSER
57
+
58
+ parser MyParser(
59
+ packet_in packet,
60
+ out my_headers_t hdr,
61
+ inout my_metadata_t meta,
62
+ inout standard_metadata_t standard_metadata)
63
+ {
64
+
65
+ // Variable Definitions
66
+
67
+
68
+ // Parser state machine
69
+
70
+
71
+ state parse_ethernet {
72
+ packet.extract(hdr.ethernet);
73
+ transition select(hdr.ethernet.etherType){
74
+ (16w2048) : parse_ipv4;
75
+ default : accept;
76
+ }
77
+
78
+ }
79
+
80
+
81
+ state parse_ipv4 {
82
+ packet.extract(hdr.ipv4);
83
+ transition select(hdr.ipv4.protocol){
84
+ (8w199) : parse_ndp;
85
+ default : accept;
86
+ }
87
+
88
+ }
89
+
90
+
91
+ state parse_ndp {
92
+ packet.extract(hdr.ndp);
93
+ transition accept;
94
+ }
95
+
96
+
97
+ state start {
98
+
99
+ transition parse_ethernet;
100
+ }
101
+
102
+ }
103
+
104
+
105
+ // INGRESS
106
+
107
+ control MyIngress (
108
+ inout my_headers_t hdr,
109
+ inout my_metadata_t meta,
110
+ inout standard_metadata_t standard_metadata)
111
+ {
112
+
113
+ // Variable Definitions
114
+ bit<9> DEVNULL_buffersense_readbuffer;
115
+ bit<9> DEVNULL_buffersense_set_dmac;
116
+ bit<9> DEVNULL_buffersense_setpriolow;
117
+ bit<9> DEVNULL_buffersense_setpriolow_index;
118
+ bit<16> DEVNULL_buffersense_setpriolow_value;
119
+ bit<16> buffersense_readbuffer;
120
+ bit<16> buffersense_set_dmac;
121
+ bit<16> buffersense_setpriolow;
122
+ bit<48> dmac;
123
+ bit<32> nhop_ipv4;
124
+ bit<9> port;
125
+
126
+
127
+ // Action Definitions
128
+ action directtoprio_action_0(){
129
+ standard_metadata.egress_spec = 9w1;
130
+ meta.meta.ndpflags = hdr.ndp.flags;
131
+ }
132
+
133
+ action directtoprio_action_1(){
134
+
135
+ }
136
+
137
+ action forward_action_0(bit<48> dmac){
138
+ hdr.ethernet.dstAddr = dmac;
139
+ DEVNULL_buffersense_set_dmac = standard_metadata.egress_port;
140
+ meta.meta.register_tmp = buffersense_set_dmac;
141
+ }
142
+
143
+ action forward_action_1(){
144
+ standard_metadata.egress_spec = 9w511;
145
+ }
146
+
147
+ action forward_action_2(){
148
+
149
+ }
150
+
151
+ action ipv4_lpm_action_0(bit<32> nhop_ipv4,bit<9> port){
152
+ meta.routing_metadata.nhop_ipv4 = nhop_ipv4;
153
+ standard_metadata.egress_port = port;
154
+ hdr.ipv4.ttl = (hdr.ipv4.ttl + 8w255);
155
+ }
156
+
157
+ action ipv4_lpm_action_1(){
158
+ standard_metadata.egress_spec = 9w511;
159
+ }
160
+
161
+ action ipv4_lpm_action_2(){
162
+
163
+ }
164
+
165
+ action readbuffersense_action_0(){
166
+ DEVNULL_buffersense_readbuffer = standard_metadata.egress_port;
167
+ meta.meta.register_tmp = buffersense_readbuffer;
168
+ }
169
+
170
+ action readbuffersense_action_1(){
171
+
172
+ }
173
+
174
+ action setprio_action_0(){
175
+ standard_metadata.egress_spec = 9w0;
176
+ DEVNULL_buffersense_setpriolow = standard_metadata.egress_port;
177
+ meta.meta.register_tmp = buffersense_setpriolow;
178
+ DEVNULL_buffersense_setpriolow_index = standard_metadata.egress_port;
179
+ DEVNULL_buffersense_setpriolow_value = (meta.meta.register_tmp + 16w1);
180
+ }
181
+
182
+ action setprio_action_1(){
183
+ hdr.ipv4.totalLen = 16w20;
184
+ standard_metadata.egress_spec = 9w1;
185
+ }
186
+
187
+ action setprio_action_2(){
188
+
189
+ }
190
+
191
+
192
+ // Table Definitions
193
+
194
+ table directtoprio {
195
+ key = {
196
+ meta.meta.register_tmp : exact;
197
+ }
198
+ actions = {
199
+ directtoprio_action_0;
200
+ directtoprio_action_1;
201
+ }
202
+ }
203
+
204
+ table forward {
205
+ key = {
206
+ meta.routing_metadata.nhop_ipv4 : exact;
207
+ }
208
+ actions = {
209
+ forward_action_0;
210
+ forward_action_1;
211
+ forward_action_2;
212
+ }
213
+ }
214
+
215
+ table ipv4_lpm {
216
+ key = {
217
+ hdr.ipv4.dstAddr : ternary;
218
+ }
219
+ actions = {
220
+ ipv4_lpm_action_0;
221
+ ipv4_lpm_action_1;
222
+ ipv4_lpm_action_2;
223
+ }
224
+ }
225
+
226
+ table readbuffersense {
227
+ key = {
228
+ meta.meta.register_tmp : exact;
229
+ }
230
+ actions = {
231
+ readbuffersense_action_0;
232
+ readbuffersense_action_1;
233
+ }
234
+ }
235
+
236
+ table setprio {
237
+ key = {
238
+ meta.meta.register_tmp : exact;
239
+ }
240
+ actions = {
241
+ setprio_action_0;
242
+ setprio_action_1;
243
+ setprio_action_2;
244
+ }
245
+ }
246
+
247
+
248
+ apply {
249
+
250
+ // Pipeline
251
+ if (!(1w1 == (hdr.ipv4.isValid() ? 1w1 : 1w0))) {
252
+ standard_metadata.egress_spec = 9w511;
253
+ } else {
254
+ if (!(hdr.ipv4.ttl > 8w0)) {
255
+ standard_metadata.egress_spec = 9w511;
256
+ } else {
257
+ ipv4_lpm.apply();
258
+ if (!(1w1 == (hdr.ndp.isValid() ? 1w1 : 1w0))) {
259
+ readbuffersense.apply();
260
+ setprio.apply();
261
+ } else {
262
+ if (!(hdr.ndp.flags > 16w1)) {
263
+ readbuffersense.apply();
264
+ setprio.apply();
265
+ } else {
266
+ directtoprio.apply();
267
+ }
268
+
269
+ }
270
+
271
+ forward.apply();
272
+ }
273
+
274
+ }
275
+
276
+ }
277
+ }
278
+
279
+
280
+ // EGRESS
281
+
282
+ control MyEgress (
283
+ inout my_headers_t hdr,
284
+ inout my_metadata_t meta,
285
+ inout standard_metadata_t standard_metadata)
286
+ {
287
+
288
+ // Variable Definitions
289
+ bit<9> DEVNULL_buffersense_decreasereg;
290
+ bit<9> DEVNULL_buffersense_decreasereg_index;
291
+ bit<16> DEVNULL_buffersense_decreasereg_value;
292
+ bit<16> buffersense_decreasereg;
293
+ bit<48> smac;
294
+
295
+
296
+ // Action Definitions
297
+ action dec_counter_action_0(){
298
+ DEVNULL_buffersense_decreasereg = standard_metadata.egress_port;
299
+ meta.meta.register_tmp = buffersense_decreasereg;
300
+ DEVNULL_buffersense_decreasereg_index = standard_metadata.egress_port;
301
+ DEVNULL_buffersense_decreasereg_value = ((meta.meta.register_tmp - 16w1) + (7w0 ++ standard_metadata.egress_spec));
302
+ }
303
+
304
+ action dec_counter_action_1(){
305
+
306
+ }
307
+
308
+ action dec_counter_action_2(){
309
+
310
+ }
311
+
312
+ action send_frame_action_0(bit<48> smac){
313
+ hdr.ethernet.srcAddr = smac;
314
+ }
315
+
316
+ action send_frame_action_1(){
317
+ standard_metadata.egress_spec = 9w511;
318
+ }
319
+
320
+ action send_frame_action_2(){
321
+
322
+ }
323
+
324
+
325
+ // Table Definitions
326
+
327
+ table dec_counter {
328
+ key = {
329
+ meta.meta.ndpflags : exact;
330
+ }
331
+ actions = {
332
+ dec_counter_action_0;
333
+ dec_counter_action_1;
334
+ dec_counter_action_2;
335
+ }
336
+ }
337
+
338
+ table send_frame {
339
+ key = {
340
+ standard_metadata.egress_port : exact;
341
+ }
342
+ actions = {
343
+ send_frame_action_0;
344
+ send_frame_action_1;
345
+ send_frame_action_2;
346
+ }
347
+ }
348
+
349
+
350
+ apply {
351
+
352
+ // Pipeline
353
+ dec_counter.apply();
354
+ send_frame.apply();
355
+ }
356
+ }
357
+
358
+
359
+ // OTHER
360
+ control MyVerifyChecksum(
361
+ inout my_headers_t hdr,
362
+ inout my_metadata_t meta)
363
+ {
364
+ apply { }
365
+ }
366
+
367
+ control MyComputeChecksum(
368
+ inout my_headers_t hdr,
369
+ inout my_metadata_t meta)
370
+ {
371
+ apply { }
372
+ }
373
+ control MyDeparser(
374
+ packet_out packet,
375
+ in my_headers_t hdr)
376
+ {
377
+ apply {
378
+ }
379
+ }
380
+ V1Switch(
381
+ MyParser(),
382
+ MyVerifyChecksum(),
383
+ MyIngress(),
384
+ MyEgress(),
385
+ MyComputeChecksum(),
386
+ MyDeparser()
387
+ ) main;
individual_files/000067__raw-repositories__cornell-netlab__capisce.p4 ADDED
@@ -0,0 +1,323 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <core.p4>
2
+ #include <v1model.p4>
3
+
4
+ // HEADERS
5
+
6
+
7
+ // Define header types
8
+
9
+ header ethernet_t {
10
+ bit<16> etherType;
11
+ }
12
+ header ipv4_t {
13
+ bit<8> protocol;
14
+ }
15
+ header paxos_t {
16
+ bit<16> vproposal;
17
+ bit<32> val;
18
+ bit<16> proposal;
19
+ bit<16> msgtype;
20
+ bit<32> inst;
21
+ bit<16> acpt;
22
+ }
23
+ header udp_t {
24
+ bit<16> dstPort;
25
+ bit<16> checksum;
26
+ }
27
+
28
+ // Assemble headers in a single struct
29
+ struct my_headers_t {
30
+ ethernet_t ethernet;
31
+ ipv4_t ipv4;
32
+ paxos_t paxos;
33
+ udp_t udp;
34
+ }
35
+
36
+
37
+
38
+ // METADATA
39
+
40
+
41
+
42
+ struct local_metadata_t {
43
+
44
+ bit<16> proposal;
45
+
46
+ }
47
+ struct my_metadata_t {
48
+ local_metadata_t local_metadata;
49
+
50
+
51
+ }
52
+
53
+ // PARSER
54
+
55
+ parser MyParser(
56
+ packet_in packet,
57
+ out my_headers_t hdr,
58
+ inout my_metadata_t meta,
59
+ inout standard_metadata_t standard_metadata)
60
+ {
61
+
62
+ // Variable Definitions
63
+
64
+
65
+ // Parser state machine
66
+
67
+
68
+ state parse_ethernet {
69
+ packet.extract(hdr.ethernet);
70
+ transition select(hdr.ethernet.etherType){
71
+ (16w2048) : parse_ipv4;
72
+ default : accept;
73
+ }
74
+
75
+ }
76
+
77
+
78
+ state parse_ipv4 {
79
+ packet.extract(hdr.ipv4);
80
+ transition select(hdr.ipv4.protocol){
81
+ (8w17) : parse_udp;
82
+ default : accept;
83
+ }
84
+
85
+ }
86
+
87
+
88
+ state parse_paxos {
89
+ packet.extract(hdr.paxos);
90
+ transition accept;
91
+ }
92
+
93
+
94
+ state parse_udp {
95
+ packet.extract(hdr.udp);
96
+ transition select(hdr.udp.dstPort){
97
+ (16w34952) : parse_paxos;
98
+ default : accept;
99
+ }
100
+
101
+ }
102
+
103
+
104
+ state start {
105
+
106
+ transition parse_ethernet;
107
+ }
108
+
109
+ }
110
+
111
+
112
+ // INGRESS
113
+
114
+ control MyIngress (
115
+ inout my_headers_t hdr,
116
+ inout my_metadata_t meta,
117
+ inout standard_metadata_t standard_metadata)
118
+ {
119
+
120
+ // Variable Definitions
121
+ bit<32> DEVNULL_acceptor_id;
122
+ bit<32> DEVNULL_acceptor_id_1a;
123
+ bit<32> DEVNULL_proposal_register_1a_index;
124
+ bit<16> DEVNULL_proposal_register_1a_value;
125
+ bit<32> DEVNULL_proposal_register_2a_index;
126
+ bit<16> DEVNULL_proposal_register_2a_value;
127
+ bit<32> DEVNULL_proposal_register_read_round;
128
+ bit<32> DEVNULL_val_register_1a;
129
+ bit<32> DEVNULL_val_register_index;
130
+ bit<32> DEVNULL_val_register_value;
131
+ bit<32> DEVNULL_vproposal_register_1a;
132
+ bit<32> DEVNULL_vproposal_register_2a_index;
133
+ bit<16> DEVNULL_vproposal_register_2a_value;
134
+ bit<16> acceptor_id;
135
+ bit<16> acceptor_id_1a;
136
+ bit<9> port;
137
+ bit<16> proposal_register_read_round;
138
+ bit<32> val_register_1a;
139
+ bit<16> vproposal_register_1a;
140
+
141
+
142
+ // Action Definitions
143
+ action drop_tbl_action_0(){
144
+ standard_metadata.egress_spec = 9w511;
145
+ }
146
+
147
+ action drop_tbl_action_1(){
148
+
149
+ }
150
+
151
+ action fwd_tbl_action_0(bit<9> port){
152
+ standard_metadata.egress_spec = port;
153
+ }
154
+
155
+ action fwd_tbl_action_1(){
156
+ standard_metadata.egress_spec = 9w511;
157
+ }
158
+
159
+ action fwd_tbl_action_2(){
160
+
161
+ }
162
+
163
+ action paxos_tbl_action_0(){
164
+ DEVNULL_proposal_register_1a_index = hdr.paxos.inst;
165
+ DEVNULL_proposal_register_1a_value = hdr.paxos.proposal;
166
+ DEVNULL_vproposal_register_1a = hdr.paxos.inst;
167
+ hdr.paxos.vproposal = vproposal_register_1a;
168
+ DEVNULL_val_register_1a = hdr.paxos.inst;
169
+ hdr.paxos.val = val_register_1a;
170
+ DEVNULL_acceptor_id_1a = 32w0;
171
+ hdr.paxos.acpt = acceptor_id_1a;
172
+ hdr.udp.checksum = 16w0;
173
+ }
174
+
175
+ action paxos_tbl_action_1(){
176
+ DEVNULL_proposal_register_2a_index = hdr.paxos.inst;
177
+ DEVNULL_proposal_register_2a_value = hdr.paxos.proposal;
178
+ DEVNULL_vproposal_register_2a_index = hdr.paxos.inst;
179
+ DEVNULL_vproposal_register_2a_value = hdr.paxos.proposal;
180
+ DEVNULL_val_register_index = hdr.paxos.inst;
181
+ DEVNULL_val_register_value = hdr.paxos.val;
182
+ hdr.paxos.msgtype = 16w4;
183
+ hdr.paxos.vproposal = hdr.paxos.proposal;
184
+ DEVNULL_acceptor_id = 32w0;
185
+ hdr.paxos.acpt = acceptor_id;
186
+ hdr.udp.checksum = 16w0;
187
+ }
188
+
189
+ action paxos_tbl_action_2(){
190
+
191
+ }
192
+
193
+ action round_tbl_action_0(){
194
+ DEVNULL_proposal_register_read_round = hdr.paxos.inst;
195
+ meta.local_metadata.proposal = proposal_register_read_round;
196
+ }
197
+
198
+ action round_tbl_action_1(){
199
+
200
+ }
201
+
202
+
203
+ // Table Definitions
204
+
205
+ table drop_tbl {
206
+ key = {
207
+ }
208
+ actions = {
209
+ drop_tbl_action_0;
210
+ drop_tbl_action_1;
211
+ }
212
+ }
213
+
214
+ table fwd_tbl {
215
+ key = {
216
+ standard_metadata.ingress_port : exact;
217
+ }
218
+ actions = {
219
+ fwd_tbl_action_0;
220
+ fwd_tbl_action_1;
221
+ fwd_tbl_action_2;
222
+ }
223
+ }
224
+
225
+ table paxos_tbl {
226
+ key = {
227
+ hdr.paxos.msgtype : exact;
228
+ }
229
+ actions = {
230
+ paxos_tbl_action_0;
231
+ paxos_tbl_action_1;
232
+ paxos_tbl_action_2;
233
+ }
234
+ }
235
+
236
+ table round_tbl {
237
+ key = {
238
+ }
239
+ actions = {
240
+ round_tbl_action_0;
241
+ round_tbl_action_1;
242
+ }
243
+ }
244
+
245
+
246
+ apply {
247
+
248
+ // Pipeline
249
+ if (!((hdr.ipv4.isValid() ? 1w1 : 1w0) == 1w1)) {
250
+ if (!((hdr.paxos.isValid() ? 1w1 : 1w0) == 1w1)) {
251
+ standard_metadata.egress_spec = 9w511;
252
+ } else {
253
+ round_tbl.apply();
254
+ if (!(meta.local_metadata.proposal <= hdr.paxos.proposal)) {
255
+ drop_tbl.apply();
256
+ } else {
257
+ paxos_tbl.apply();
258
+ }
259
+
260
+ }
261
+
262
+ } else {
263
+ fwd_tbl.apply();
264
+ }
265
+
266
+ }
267
+ }
268
+
269
+
270
+ // EGRESS
271
+
272
+ control MyEgress (
273
+ inout my_headers_t hdr,
274
+ inout my_metadata_t meta,
275
+ inout standard_metadata_t standard_metadata)
276
+ {
277
+
278
+ // Variable Definitions
279
+
280
+
281
+ // Action Definitions
282
+
283
+
284
+ // Table Definitions
285
+
286
+
287
+ apply {
288
+
289
+ // Pipeline
290
+
291
+ }
292
+ }
293
+
294
+
295
+ // OTHER
296
+ control MyVerifyChecksum(
297
+ inout my_headers_t hdr,
298
+ inout my_metadata_t meta)
299
+ {
300
+ apply { }
301
+ }
302
+
303
+ control MyComputeChecksum(
304
+ inout my_headers_t hdr,
305
+ inout my_metadata_t meta)
306
+ {
307
+ apply { }
308
+ }
309
+ control MyDeparser(
310
+ packet_out packet,
311
+ in my_headers_t hdr)
312
+ {
313
+ apply {
314
+ }
315
+ }
316
+ V1Switch(
317
+ MyParser(),
318
+ MyVerifyChecksum(),
319
+ MyIngress(),
320
+ MyEgress(),
321
+ MyComputeChecksum(),
322
+ MyDeparser()
323
+ ) main;
individual_files/000068__raw-repositories__cornell-netlab__capisce.p4 ADDED
@@ -0,0 +1,180 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <core.p4>
2
+ #include <v1model.p4>
3
+
4
+ // HEADERS
5
+
6
+
7
+ // Define header types
8
+
9
+ header ethernet_t {
10
+
11
+ }
12
+
13
+ // Assemble headers in a single struct
14
+ struct my_headers_t {
15
+ ethernet_t ethernet;
16
+ }
17
+
18
+
19
+
20
+ // METADATA
21
+
22
+
23
+
24
+ struct mymeta_t {
25
+
26
+ bit<8> f2;
27
+ bit<8> f1;
28
+
29
+ }
30
+ struct my_metadata_t {
31
+ mymeta_t mymeta;
32
+
33
+
34
+ }
35
+
36
+ // PARSER
37
+
38
+ parser MyParser(
39
+ packet_in packet,
40
+ out my_headers_t hdr,
41
+ inout my_metadata_t meta,
42
+ inout standard_metadata_t standard_metadata)
43
+ {
44
+
45
+ // Variable Definitions
46
+
47
+
48
+ // Parser state machine
49
+
50
+
51
+ state parse_ethernet {
52
+ packet.extract(hdr.ethernet);
53
+ transition accept;
54
+ }
55
+
56
+
57
+ state start {
58
+
59
+ transition parse_ethernet;
60
+ }
61
+
62
+ }
63
+
64
+
65
+ // INGRESS
66
+
67
+ control MyIngress (
68
+ inout my_headers_t hdr,
69
+ inout my_metadata_t meta,
70
+ inout standard_metadata_t standard_metadata)
71
+ {
72
+
73
+ // Variable Definitions
74
+ bit<9> port;
75
+
76
+
77
+ // Action Definitions
78
+ action t_ingress_1_action_0(){
79
+
80
+ }
81
+
82
+ action t_ingress_1_action_1(){
83
+ standard_metadata.egress_spec = port;
84
+ }
85
+
86
+ action t_ingress_2_action_0(){
87
+
88
+ }
89
+
90
+ action t_ingress_2_action_1(){
91
+ meta.mymeta.f1 = 8w1;
92
+ }
93
+
94
+
95
+ // Table Definitions
96
+
97
+ table t_ingress_1 {
98
+ key = {
99
+ meta.mymeta.f1 : exact;
100
+ }
101
+ actions = {
102
+ t_ingress_1_action_0;
103
+ t_ingress_1_action_1;
104
+ }
105
+ }
106
+
107
+ table t_ingress_2 {
108
+ key = {
109
+ meta.mymeta.f2 : exact;
110
+ }
111
+ actions = {
112
+ t_ingress_2_action_0;
113
+ t_ingress_2_action_1;
114
+ }
115
+ }
116
+
117
+
118
+ apply {
119
+
120
+ // Pipeline
121
+ t_ingress_1.apply();
122
+ t_ingress_2.apply();
123
+ }
124
+ }
125
+
126
+
127
+ // EGRESS
128
+
129
+ control MyEgress (
130
+ inout my_headers_t hdr,
131
+ inout my_metadata_t meta,
132
+ inout standard_metadata_t standard_metadata)
133
+ {
134
+
135
+ // Variable Definitions
136
+
137
+
138
+ // Action Definitions
139
+
140
+
141
+ // Table Definitions
142
+
143
+
144
+ apply {
145
+
146
+ // Pipeline
147
+
148
+ }
149
+ }
150
+
151
+
152
+ // OTHER
153
+ control MyVerifyChecksum(
154
+ inout my_headers_t hdr,
155
+ inout my_metadata_t meta)
156
+ {
157
+ apply { }
158
+ }
159
+
160
+ control MyComputeChecksum(
161
+ inout my_headers_t hdr,
162
+ inout my_metadata_t meta)
163
+ {
164
+ apply { }
165
+ }
166
+ control MyDeparser(
167
+ packet_out packet,
168
+ in my_headers_t hdr)
169
+ {
170
+ apply {
171
+ }
172
+ }
173
+ V1Switch(
174
+ MyParser(),
175
+ MyVerifyChecksum(),
176
+ MyIngress(),
177
+ MyEgress(),
178
+ MyComputeChecksum(),
179
+ MyDeparser()
180
+ ) main;
individual_files/000069__raw-repositories__cornell-netlab__capisce.p4 ADDED
@@ -0,0 +1,392 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <core.p4>
2
+ #include <v1model.p4>
3
+
4
+ // HEADERS
5
+
6
+
7
+ // Define header types
8
+
9
+ header cpu_header_t {
10
+ bit<8> reason;
11
+ bit<64> preamble;
12
+ bit<8> if_index;
13
+ bit<8> device;
14
+ }
15
+ header ethernet_t {
16
+ bit<48> srcAddr;
17
+ bit<16> etherType;
18
+ bit<48> dstAddr;
19
+ }
20
+ header ipv4_t {
21
+ bit<8> ttl;
22
+ bit<16> totalLen;
23
+ bit<32> srcAddr;
24
+ bit<8> protocol;
25
+ bit<32> dstAddr;
26
+ }
27
+ header tcp_t {
28
+ bit<16> srcPort;
29
+ bit<16> dstPort;
30
+ }
31
+
32
+ // Assemble headers in a single struct
33
+ struct my_headers_t {
34
+ cpu_header_t cpu_header;
35
+ ethernet_t ethernet;
36
+ ipv4_t ipv4;
37
+ tcp_t tcp;
38
+ }
39
+
40
+
41
+
42
+ // METADATA
43
+
44
+
45
+
46
+ struct meta_t {
47
+
48
+ bit<16> tcp_sp;
49
+ bit<16> tcp_dp;
50
+ bit<16> tcpLength;
51
+ bit<32> nhop_ipv4;
52
+ bit<1> is_ext_if;
53
+ bit<32> ipv4_sa;
54
+ bit<32> ipv4_da;
55
+ bit<48> if_mac_addr;
56
+ bit<32> if_ipv4_addr;
57
+ bit<8> if_index;
58
+ bit<1> do_forward;
59
+
60
+ }
61
+ struct my_metadata_t {
62
+ meta_t meta;
63
+
64
+
65
+ }
66
+
67
+ // PARSER
68
+
69
+ parser MyParser(
70
+ packet_in packet,
71
+ out my_headers_t hdr,
72
+ inout my_metadata_t meta,
73
+ inout standard_metadata_t standard_metadata)
74
+ {
75
+
76
+ // Variable Definitions
77
+
78
+
79
+ // Parser state machine
80
+
81
+
82
+ state parse_ethernet {
83
+ packet.extract(hdr.ethernet);
84
+ transition select(hdr.ethernet.etherType){
85
+ (16w2048) : parse_ipv4;
86
+ default : accept;
87
+ }
88
+
89
+ }
90
+
91
+
92
+ state parse_ipv4 {
93
+ packet.extract(hdr.ipv4);
94
+ meta.meta.ipv4_sa = hdr.ipv4.srcAddr;
95
+ meta.meta.ipv4_da = hdr.ipv4.dstAddr;
96
+ meta.meta.tcpLength = (hdr.ipv4.totalLen - 16w20);
97
+ transition select(hdr.ipv4.protocol){
98
+ (8w6) : parse_tcp;
99
+ default : accept;
100
+ }
101
+
102
+ }
103
+
104
+
105
+ state parse_tcp {
106
+ packet.extract(hdr.tcp);
107
+ transition accept;
108
+ }
109
+
110
+
111
+ state start {
112
+
113
+ transition parse_ethernet;
114
+ }
115
+
116
+ }
117
+
118
+
119
+ // INGRESS
120
+
121
+ control MyIngress (
122
+ inout my_headers_t hdr,
123
+ inout my_metadata_t meta,
124
+ inout standard_metadata_t standard_metadata)
125
+ {
126
+
127
+ // Variable Definitions
128
+ bit<48> dmac;
129
+ bit<32> dstAddr;
130
+ bit<16> dstPort;
131
+ bit<32> ipv4_addr;
132
+ bit<1> is_ext;
133
+ bit<48> mac_addr;
134
+ bit<32> nhop_ipv4;
135
+ bit<9> port;
136
+
137
+
138
+ // Action Definitions
139
+ action forward_action_0(bit<48> dmac){
140
+ hdr.ethernet.dstAddr = dmac;
141
+ }
142
+
143
+ action forward_action_1(){
144
+ standard_metadata.egress_spec = 9w511;
145
+ }
146
+
147
+ action forward_action_2(){
148
+
149
+ }
150
+
151
+ action if_info_action_0(bit<32> ipv4_addr,bit<48> mac_addr,bit<1> is_ext){
152
+ meta.meta.if_ipv4_addr = ipv4_addr;
153
+ meta.meta.if_mac_addr = mac_addr;
154
+ meta.meta.is_ext_if = is_ext;
155
+ }
156
+
157
+ action if_info_action_1(){
158
+ standard_metadata.egress_spec = 9w511;
159
+ }
160
+
161
+ action if_info_action_2(){
162
+
163
+ }
164
+
165
+ action ipv4_lpm_action_0(bit<32> nhop_ipv4,bit<9> port){
166
+ meta.meta.nhop_ipv4 = nhop_ipv4;
167
+ standard_metadata.egress_spec = port;
168
+ hdr.ipv4.ttl = (hdr.ipv4.ttl - 8w1);
169
+ }
170
+
171
+ action ipv4_lpm_action_1(){
172
+ standard_metadata.egress_spec = 9w511;
173
+ }
174
+
175
+ action ipv4_lpm_action_2(){
176
+
177
+ }
178
+
179
+ action nat_action_0(){
180
+ standard_metadata.egress_spec = 9w511;
181
+ }
182
+
183
+ action nat_action_1(){
184
+
185
+ }
186
+
187
+ action nat_action_2(){
188
+ meta.meta.do_forward = 1w0;
189
+ standard_metadata.egress_spec = 9w511;
190
+ }
191
+
192
+ action nat_action_3(){
193
+
194
+ }
195
+
196
+ action nat_action_4(bit<32> dstAddr,bit<16> dstPort){
197
+ meta.meta.do_forward = 1w1;
198
+ meta.meta.ipv4_da = dstAddr;
199
+ meta.meta.tcp_dp = dstPort;
200
+ }
201
+
202
+ action nat_action_5(){
203
+ meta.meta.do_forward = 1w1;
204
+ }
205
+
206
+ action nat_action_6(){
207
+
208
+ }
209
+
210
+
211
+ // Table Definitions
212
+
213
+ table forward {
214
+ key = {
215
+ meta.meta.nhop_ipv4 : exact;
216
+ }
217
+ actions = {
218
+ forward_action_0;
219
+ forward_action_1;
220
+ forward_action_2;
221
+ }
222
+ }
223
+
224
+ table if_info {
225
+ key = {
226
+ meta.meta.if_index : exact;
227
+ }
228
+ actions = {
229
+ if_info_action_0;
230
+ if_info_action_1;
231
+ if_info_action_2;
232
+ }
233
+ }
234
+
235
+ table ipv4_lpm {
236
+ key = {
237
+ meta.meta.ipv4_da : exact;
238
+ }
239
+ actions = {
240
+ ipv4_lpm_action_0;
241
+ ipv4_lpm_action_1;
242
+ ipv4_lpm_action_2;
243
+ }
244
+ }
245
+
246
+ table nat {
247
+ key = {
248
+ meta.meta.is_ext_if : exact;
249
+ hdr.ipv4.isValid() : exact;
250
+ hdr.tcp.isValid() : exact;
251
+ hdr.ipv4.srcAddr : ternary;
252
+ hdr.ipv4.dstAddr : ternary;
253
+ hdr.tcp.srcPort : ternary;
254
+ hdr.tcp.dstPort : ternary;
255
+ }
256
+ actions = {
257
+ nat_action_0;
258
+ nat_action_1;
259
+ nat_action_2;
260
+ nat_action_3;
261
+ nat_action_4;
262
+ nat_action_5;
263
+ nat_action_6;
264
+ }
265
+ }
266
+
267
+
268
+ apply {
269
+
270
+ // Pipeline
271
+ if_info.apply();
272
+ nat.apply();
273
+ if (!(meta.meta.do_forward == 1w1)) {} else {
274
+ if ((hdr.ipv4.ttl == 8w0)) {} else {
275
+ ipv4_lpm.apply();
276
+ forward.apply();
277
+ }
278
+
279
+ }
280
+
281
+ }
282
+ }
283
+
284
+
285
+ // EGRESS
286
+
287
+ control MyEgress (
288
+ inout my_headers_t hdr,
289
+ inout my_metadata_t meta,
290
+ inout standard_metadata_t standard_metadata)
291
+ {
292
+
293
+ // Variable Definitions
294
+ bit<48> smac;
295
+
296
+
297
+ // Action Definitions
298
+ action send_frame_action_0(bit<48> smac){
299
+ hdr.cpu_header.setInvalid();
300
+ hdr.ethernet.srcAddr = smac;
301
+ hdr.ipv4.srcAddr = meta.meta.ipv4_sa;
302
+ hdr.ipv4.dstAddr = meta.meta.ipv4_da;
303
+ hdr.tcp.srcPort = meta.meta.tcp_sp;
304
+ hdr.tcp.dstPort = meta.meta.tcp_dp;
305
+ }
306
+
307
+ action send_frame_action_1(){
308
+ standard_metadata.egress_spec = 9w511;
309
+ }
310
+
311
+ action send_frame_action_2(){
312
+
313
+ }
314
+
315
+ action send_to_cpu_action_0(){
316
+ hdr.cpu_header.setValid();
317
+ hdr.cpu_header.preamble = 64w0;
318
+ hdr.cpu_header.device = 8w0;
319
+ hdr.cpu_header.reason = 8w171;
320
+ hdr.cpu_header.if_index = meta.meta.if_index;
321
+ }
322
+
323
+ action send_to_cpu_action_1(){
324
+
325
+ }
326
+
327
+
328
+ // Table Definitions
329
+
330
+ table send_frame {
331
+ key = {
332
+ standard_metadata.egress_port : exact;
333
+ }
334
+ actions = {
335
+ send_frame_action_0;
336
+ send_frame_action_1;
337
+ send_frame_action_2;
338
+ }
339
+ }
340
+
341
+ table send_to_cpu {
342
+ key = {
343
+ }
344
+ actions = {
345
+ send_to_cpu_action_0;
346
+ send_to_cpu_action_1;
347
+ }
348
+ }
349
+
350
+
351
+ apply {
352
+
353
+ // Pipeline
354
+ if (!(standard_metadata.instance_type == 32w0)) {
355
+ send_to_cpu.apply();
356
+ } else {
357
+ send_frame.apply();
358
+ }
359
+
360
+ }
361
+ }
362
+
363
+
364
+ // OTHER
365
+ control MyVerifyChecksum(
366
+ inout my_headers_t hdr,
367
+ inout my_metadata_t meta)
368
+ {
369
+ apply { }
370
+ }
371
+
372
+ control MyComputeChecksum(
373
+ inout my_headers_t hdr,
374
+ inout my_metadata_t meta)
375
+ {
376
+ apply { }
377
+ }
378
+ control MyDeparser(
379
+ packet_out packet,
380
+ in my_headers_t hdr)
381
+ {
382
+ apply {
383
+ }
384
+ }
385
+ V1Switch(
386
+ MyParser(),
387
+ MyVerifyChecksum(),
388
+ MyIngress(),
389
+ MyEgress(),
390
+ MyComputeChecksum(),
391
+ MyDeparser()
392
+ ) main;
individual_files/000070__raw-repositories__cornell-netlab__capisce.p4 ADDED
@@ -0,0 +1,200 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <core.p4>
2
+ #include <v1model.p4>
3
+
4
+ // HEADERS
5
+
6
+
7
+ // Define header types
8
+
9
+ header ethernet_t {
10
+ bit<16> etherType;
11
+ }
12
+ header ipv4_t {
13
+ bit<8> protocol;
14
+ bit<32> dstAddr;
15
+ }
16
+ header rtp_t {
17
+ bit<32> timestamp;
18
+ }
19
+ header udp_t {
20
+
21
+ }
22
+
23
+ // Assemble headers in a single struct
24
+ struct my_headers_t {
25
+ ethernet_t ethernet;
26
+ ipv4_t ipv4;
27
+ rtp_t rtp;
28
+ udp_t udp;
29
+ }
30
+
31
+
32
+
33
+ // METADATA
34
+
35
+
36
+ struct my_metadata_t {
37
+
38
+
39
+ }
40
+
41
+ // PARSER
42
+
43
+ parser MyParser(
44
+ packet_in packet,
45
+ out my_headers_t hdr,
46
+ inout my_metadata_t meta,
47
+ inout standard_metadata_t standard_metadata)
48
+ {
49
+
50
+ // Variable Definitions
51
+
52
+
53
+ // Parser state machine
54
+
55
+
56
+ state parse_ethernet {
57
+ packet.extract(hdr.ethernet);
58
+ transition select(hdr.ethernet.etherType){
59
+ (16w2048) : parse_ipv4;
60
+ default : accept;
61
+ }
62
+
63
+ }
64
+
65
+
66
+ state parse_ipv4 {
67
+ packet.extract(hdr.ipv4);
68
+ transition select(hdr.ipv4.protocol){
69
+ (8w17) : parse_udp;
70
+ default : accept;
71
+ }
72
+
73
+ }
74
+
75
+
76
+ state parse_rtp {
77
+ packet.extract(hdr.rtp);
78
+ transition accept;
79
+ }
80
+
81
+
82
+ state parse_udp {
83
+ packet.extract(hdr.udp);
84
+ transition parse_rtp;
85
+ }
86
+
87
+
88
+ state start {
89
+
90
+ transition parse_ethernet;
91
+ }
92
+
93
+ }
94
+
95
+
96
+ // INGRESS
97
+
98
+ control MyIngress (
99
+ inout my_headers_t hdr,
100
+ inout my_metadata_t meta,
101
+ inout standard_metadata_t standard_metadata)
102
+ {
103
+
104
+ // Variable Definitions
105
+ bit<32> dst_ip;
106
+
107
+
108
+ // Action Definitions
109
+ action schedule_table_action_0(){
110
+ standard_metadata.egress_spec = 9w1;
111
+ hdr.ipv4.dstAddr = dst_ip;
112
+ }
113
+
114
+ action schedule_table_action_1(){
115
+ standard_metadata.egress_spec = 9w511;
116
+ }
117
+
118
+ action schedule_table_action_2(){
119
+
120
+ }
121
+
122
+
123
+ // Table Definitions
124
+
125
+ table schedule_table {
126
+ key = {
127
+ hdr.ipv4.dstAddr : exact;
128
+ hdr.rtp.timestamp : ternary;
129
+ }
130
+ actions = {
131
+ schedule_table_action_0;
132
+ schedule_table_action_1;
133
+ schedule_table_action_2;
134
+ }
135
+ }
136
+
137
+
138
+ apply {
139
+
140
+ // Pipeline
141
+
142
+ schedule_table.apply();
143
+ }
144
+ }
145
+
146
+
147
+ // EGRESS
148
+
149
+ control MyEgress (
150
+ inout my_headers_t hdr,
151
+ inout my_metadata_t meta,
152
+ inout standard_metadata_t standard_metadata)
153
+ {
154
+
155
+ // Variable Definitions
156
+
157
+
158
+ // Action Definitions
159
+
160
+
161
+ // Table Definitions
162
+
163
+
164
+ apply {
165
+
166
+ // Pipeline
167
+
168
+ }
169
+ }
170
+
171
+
172
+ // OTHER
173
+ control MyVerifyChecksum(
174
+ inout my_headers_t hdr,
175
+ inout my_metadata_t meta)
176
+ {
177
+ apply { }
178
+ }
179
+
180
+ control MyComputeChecksum(
181
+ inout my_headers_t hdr,
182
+ inout my_metadata_t meta)
183
+ {
184
+ apply { }
185
+ }
186
+ control MyDeparser(
187
+ packet_out packet,
188
+ in my_headers_t hdr)
189
+ {
190
+ apply {
191
+ }
192
+ }
193
+ V1Switch(
194
+ MyParser(),
195
+ MyVerifyChecksum(),
196
+ MyIngress(),
197
+ MyEgress(),
198
+ MyComputeChecksum(),
199
+ MyDeparser()
200
+ ) main;
individual_files/000071__raw-repositories__cornell-netlab__capisce.p4 ADDED
@@ -0,0 +1,213 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <core.p4>
2
+ #include <v1model.p4>
3
+
4
+ struct custom_metadata_t {
5
+ bit<32> nhop_ipv4;
6
+ bit<16> hash_val1;
7
+ bit<16> hash_val2;
8
+ bit<16> count_val1;
9
+ bit<16> count_val2;
10
+ }
11
+
12
+ header ethernet_t {
13
+ bit<48> dstAddr;
14
+ bit<48> srcAddr;
15
+ bit<16> etherType;
16
+ }
17
+
18
+ header ipv4_t {
19
+ bit<4> version;
20
+ bit<4> ihl;
21
+ bit<8> diffserv;
22
+ bit<16> totalLen;
23
+ bit<16> identification;
24
+ bit<3> flags;
25
+ bit<13> fragOffset;
26
+ bit<8> ttl;
27
+ bit<8> protocol;
28
+ bit<16> hdrChecksum;
29
+ bit<32> srcAddr;
30
+ bit<32> dstAddr;
31
+ }
32
+
33
+ header tcp_t {
34
+ bit<16> srcPort;
35
+ bit<16> dstPort;
36
+ bit<32> seqNo;
37
+ bit<32> ackNo;
38
+ bit<4> dataOffset;
39
+ bit<3> res;
40
+ bit<3> ecn;
41
+ bit<6> ctrl;
42
+ bit<16> window;
43
+ bit<16> checksum;
44
+ bit<16> urgentPtr;
45
+ }
46
+
47
+ struct metadata {
48
+ custom_metadata_t custom_metadata;
49
+ }
50
+
51
+ struct headers {
52
+
53
+ ethernet_t ethernet;
54
+ ipv4_t ipv4;
55
+ tcp_t tcp;
56
+ }
57
+
58
+ parser ParserImpl(packet_in packet, out headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
59
+ state parse_ethernet {
60
+ packet.extract(hdr.ethernet);
61
+ transition select(hdr.ethernet.etherType) {
62
+ 16w0x800: parse_ipv4;
63
+ default: accept;
64
+ }
65
+ }
66
+ state parse_ipv4 {
67
+ packet.extract(hdr.ipv4);
68
+ transition select(hdr.ipv4.protocol) {
69
+ 8w6: parse_tcp;
70
+ default: accept;
71
+ }
72
+ }
73
+ state parse_tcp {
74
+ packet.extract(hdr.tcp);
75
+ transition accept;
76
+ }
77
+ state start {
78
+ transition parse_ethernet;
79
+ }
80
+ }
81
+
82
+ control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
83
+ action rewrite_mac(bit<48> smac) {
84
+ hdr.ethernet.srcAddr = smac;
85
+ }
86
+ action _drop() {
87
+ mark_to_drop(standard_metadata);
88
+ }
89
+ table send_frame {
90
+ actions = {
91
+ rewrite_mac;
92
+ _drop;
93
+ }
94
+ key = {
95
+ standard_metadata.egress_port: exact;
96
+ }
97
+ size = 256;
98
+ }
99
+ apply {
100
+ send_frame.apply();
101
+ }
102
+ }
103
+
104
+ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
105
+ register<bit<16>>(32w16) heavy_hitter_counter1;
106
+ register<bit<16>>(32w16) heavy_hitter_counter2;
107
+
108
+ action _drop() {
109
+ mark_to_drop(standard_metadata);
110
+ }
111
+
112
+ action set_dmac(bit<48> dmac) {
113
+ hdr.ethernet.dstAddr = dmac;
114
+ }
115
+
116
+ action set_nhop(bit<32> nhop_ipv4, bit<9> port) {
117
+ meta.custom_metadata.nhop_ipv4 = nhop_ipv4;
118
+ standard_metadata.egress_spec = port;
119
+ hdr.ipv4.ttl = hdr.ipv4.ttl + 8w255;
120
+ }
121
+ action set_heavy_hitter_count() {
122
+
123
+ // Count the hash 1 for indexing
124
+ hash(meta.custom_metadata.hash_val1, HashAlgorithm.csum16, (bit<16>)0, { hdr.ipv4.srcAddr, hdr.ipv4.dstAddr, hdr.ipv4.protocol, hdr.tcp.srcPort, hdr.tcp.dstPort }, (bit<32>)16);
125
+
126
+ // Read the value in the register with that index
127
+ heavy_hitter_counter1.read(meta.custom_metadata.count_val1, (bit<32>)meta.custom_metadata.hash_val1);
128
+
129
+ // Incremet the value with 1
130
+ meta.custom_metadata.count_val1 = meta.custom_metadata.count_val1 + 16w1;
131
+
132
+ // Write the value back to the register with that index
133
+ heavy_hitter_counter1.write((bit<32>)meta.custom_metadata.hash_val1, (bit<16>)meta.custom_metadata.count_val1);
134
+
135
+ // Count the hash 2 for another indexing, similar to the first hash
136
+ hash(meta.custom_metadata.hash_val2, HashAlgorithm.crc16, (bit<16>)0, { hdr.ipv4.srcAddr, hdr.ipv4.dstAddr, hdr.ipv4.protocol, hdr.tcp.srcPort, hdr.tcp.dstPort }, (bit<32>)16);
137
+ heavy_hitter_counter2.read(meta.custom_metadata.count_val2, (bit<32>)meta.custom_metadata.hash_val2);
138
+ meta.custom_metadata.count_val2 = meta.custom_metadata.count_val2 + 16w1;
139
+ heavy_hitter_counter2.write((bit<32>)meta.custom_metadata.hash_val2, (bit<16>)meta.custom_metadata.count_val2);
140
+ }
141
+
142
+ table drop_heavy_hitter_table {
143
+ actions = {
144
+ _drop;
145
+ }
146
+ size = 1;
147
+ }
148
+
149
+ table forward {
150
+ actions = {
151
+ set_dmac;
152
+ _drop;
153
+ }
154
+ key = {
155
+ meta.custom_metadata.nhop_ipv4: exact;
156
+ }
157
+ size = 512;
158
+ }
159
+
160
+ table ipv4_lpm {
161
+ actions = {
162
+ set_nhop;
163
+
164
+ // Set next hop
165
+ _drop;
166
+ }
167
+ key = {
168
+ hdr.ipv4.dstAddr: lpm;
169
+ }
170
+ size = 1024;
171
+ }
172
+
173
+ table set_heavy_hitter_count_table {
174
+ actions = {
175
+ set_heavy_hitter_count;
176
+ }
177
+ size = 1;
178
+ }
179
+
180
+ apply {
181
+ set_heavy_hitter_count_table.apply();
182
+
183
+ if (meta.custom_metadata.count_val1 > 16w100 && meta.custom_metadata.count_val2 > 16w100) {
184
+ drop_heavy_hitter_table.apply();
185
+ }
186
+ else {
187
+ ipv4_lpm.apply();
188
+ forward.apply();
189
+ }
190
+ }
191
+ }
192
+
193
+ control DeparserImpl(packet_out packet, in headers hdr) {
194
+ apply {
195
+ packet.emit(hdr.ethernet);
196
+ packet.emit(hdr.ipv4);
197
+ packet.emit(hdr.tcp);
198
+ }
199
+ }
200
+
201
+ control verifyChecksum(inout headers hdr, inout metadata meta) {
202
+ apply {
203
+ 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);
204
+ }
205
+ }
206
+
207
+ control computeChecksum(inout headers hdr, inout metadata meta) {
208
+ apply {
209
+ 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);
210
+ }
211
+ }
212
+
213
+ V1Switch(ParserImpl(), verifyChecksum(), ingress(), egress(), computeChecksum(), DeparserImpl()) main;
individual_files/000072__raw-repositories__cornell-netlab__capisce.p4 ADDED
@@ -0,0 +1,177 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <core.p4>
2
+ #define V1MODEL_VERSION 20200408
3
+ #include <v1model.p4>
4
+
5
+ struct ghost_t {
6
+ bit<1> assign;
7
+ bit<1> alloc;
8
+ bit<1> deref;
9
+ }
10
+
11
+ header ethernet_t {
12
+ bit<48> dstAddr;
13
+ bit<48> srcAddr;
14
+ bit<16> etherType;
15
+ }
16
+
17
+ header icmp_t {
18
+ bit<16> typeCode;
19
+ bit<16> hdrChecksum;
20
+ }
21
+
22
+ header ipv4_t {
23
+ bit<4> version;
24
+ bit<4> ihl;
25
+ bit<8> diffserv;
26
+ bit<16> totalLen;
27
+ bit<16> identification;
28
+ bit<3> flags;
29
+ bit<13> fragOffset;
30
+ bit<8> ttl;
31
+ bit<8> protocol;
32
+ bit<16> hdrChecksum;
33
+ bit<32> srcAddr;
34
+ bit<32> dstAddr;
35
+ }
36
+
37
+ header ipv6_t {
38
+ bit<4> version;
39
+ bit<8> trafficClass;
40
+ bit<20> flowLabel;
41
+ bit<16> payloadLen;
42
+ bit<8> nextHdr;
43
+ bit<8> hopLimit;
44
+ bit<128> srcAddr;
45
+ bit<128> dstAddr;
46
+ }
47
+
48
+ header tcp_t {
49
+ bit<16> srcPort;
50
+ bit<16> dstPort;
51
+ bit<32> seqNo;
52
+ bit<32> ackNo;
53
+ bit<4> dataOffset;
54
+ bit<4> res;
55
+ bit<8> flags;
56
+ bit<16> window;
57
+ bit<16> checksum;
58
+ bit<16> urgentPtr;
59
+ }
60
+
61
+ header udp_t {
62
+ bit<16> srcPort;
63
+ bit<16> dstPort;
64
+ bit<16> length_;
65
+ bit<16> checksum;
66
+ }
67
+
68
+ header vlan_tag_t {
69
+ bit<3> pcp;
70
+ bit<1> cfi;
71
+ bit<12> vid;
72
+ bit<16> etherType;
73
+ }
74
+
75
+ struct metadata {
76
+ bit<16> ptr;
77
+ ghost_t spec;
78
+ }
79
+
80
+ struct headers {
81
+ ethernet_t ethernet;
82
+ icmp_t icmp;
83
+ ipv4_t ipv4;
84
+ ipv6_t ipv6;
85
+ tcp_t tcp;
86
+ udp_t udp;
87
+ vlan_tag_t vlan_tag;
88
+ }
89
+
90
+ parser ParserImpl(packet_in packet, out headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
91
+ @name(".start") state start {
92
+ packet.extract(hdr.ethernet);
93
+ transition accept;
94
+ }
95
+ }
96
+
97
+ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
98
+ action alloc () {
99
+ meta.spec.alloc = 1w1;
100
+ }
101
+ action unalloc () {
102
+ meta.spec.alloc = 1w0;
103
+ }
104
+ action drop_ () {
105
+ mark_to_drop(standard_metadata);
106
+ }
107
+ action fwd (bit<9> port) {
108
+ standard_metadata.egress_spec = port;
109
+ meta.spec.deref = 1w1;
110
+ }
111
+ action assign_(bit<16> ptr){
112
+ meta.ptr = ptr;
113
+ meta.spec.assign = 1w1;
114
+ }
115
+ table assign {
116
+ key = {
117
+ hdr.ethernet.dstAddr : exact;
118
+ }
119
+ actions = {
120
+ assign_;
121
+ drop_;
122
+ }
123
+ }
124
+ table allocator {
125
+ key = {
126
+ meta.ptr : exact;
127
+ }
128
+ actions = {
129
+ alloc;
130
+ @defaultonly unalloc;
131
+ }
132
+ const default_action = unalloc;
133
+ }
134
+ table deref {
135
+ key = {
136
+ meta.ptr : exact;
137
+ }
138
+ actions = {
139
+ fwd;
140
+ @defaultonly drop_;
141
+ }
142
+ const default_action = drop_;
143
+ }
144
+
145
+ apply {
146
+ meta.spec.assign = 1w0;
147
+ meta.spec.alloc = 1w0;
148
+ meta.spec.deref = 1w0;
149
+
150
+ assign.apply();
151
+ allocator.apply();
152
+ deref.apply();
153
+ assert(meta.spec.assign == 1w0 || meta.spec.alloc == 1w1);
154
+ assert(meta.spec.deref == 1w0 || meta.spec.alloc == 1w1);
155
+ standard_metadata.egress_spec = 9w511;
156
+ }
157
+ }
158
+
159
+ control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
160
+ apply {}
161
+ }
162
+
163
+ control DeparserImpl(packet_out packet, in headers hdr) {
164
+ apply {
165
+ packet.emit(hdr.ethernet);
166
+ }
167
+ }
168
+
169
+ control verifyChecksum(inout headers hdr, inout metadata meta) {
170
+ apply {}
171
+ }
172
+
173
+ control computeChecksum(inout headers hdr, inout metadata meta) {
174
+ apply {}
175
+ }
176
+
177
+ V1Switch(ParserImpl(), verifyChecksum(), ingress(), egress(), computeChecksum(), DeparserImpl()) main;
individual_files/000073__raw-repositories__cornell-netlab__capisce.p4 ADDED
@@ -0,0 +1,279 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ #include <core.p4>
3
+ #include <v1model.p4>
4
+
5
+
6
+
7
+
8
+ /* Define the headers the program will recognize */
9
+
10
+
11
+ typedef bit<48> mac_addr_t;
12
+ typedef bit<32> ipv4_addr_t;
13
+ typedef bit<9> port_id_t;
14
+
15
+ header ethernet_t {
16
+ mac_addr_t dstAddr;
17
+ mac_addr_t srcAddr;
18
+ bit<16> etherType;
19
+ }
20
+
21
+ header ipv4_t {
22
+ bit<4> version;
23
+ bit<4> ihl;
24
+ bit<8> diffserv;
25
+ bit<16> totalLen;
26
+ bit<16> identification;
27
+ bit<3> flags;
28
+ bit<13> fragOffset;
29
+ bit<8> ttl;
30
+ bit<8> protocol;
31
+ bit<16> hdrChecksum;
32
+ ipv4_addr_t srcAddr;
33
+ ipv4_addr_t dstAddr;
34
+ }
35
+
36
+
37
+
38
+ header arp_t {
39
+ bit<16> htype;
40
+ bit<16> ptype;
41
+ bit<8> hlen;
42
+ bit<8> plen;
43
+ bit<16> oper;
44
+ }
45
+
46
+ header arp_ipv4_t {
47
+ mac_addr_t sha;
48
+ ipv4_addr_t spa;
49
+ mac_addr_t tha;
50
+ ipv4_addr_t tpa;
51
+ }
52
+
53
+
54
+
55
+ header icmp_t {
56
+ bit<8> type;
57
+ bit<8> code;
58
+ bit<16> checksum;
59
+ }
60
+
61
+
62
+ /* Assemble headers in a single struct */
63
+ struct my_headers_t {
64
+ ethernet_t ethernet;
65
+ arp_t arp;
66
+ arp_ipv4_t arp_ipv4;
67
+ ipv4_t ipv4;
68
+ icmp_t icmp;
69
+ }
70
+
71
+
72
+ /* Define the global metadata for your program */
73
+
74
+ struct my_metadata_t {
75
+ ipv4_addr_t dst_ipv4;
76
+ mac_addr_t mac_da;
77
+ mac_addr_t mac_sa;
78
+ port_id_t egress_port;
79
+ mac_addr_t my_mac;
80
+ }
81
+
82
+
83
+ parser MyParser(
84
+ packet_in packet,
85
+ out my_headers_t hdr,
86
+ inout my_metadata_t meta,
87
+ inout standard_metadata_t standard_metadata)
88
+ {
89
+ state start {
90
+ packet.extract(hdr.ethernet);
91
+ transition select(hdr.ethernet.etherType) {
92
+ 16w0x0800 : parse_ipv4;
93
+ 16w0x0806 : parse_arp;
94
+ default : accept;
95
+ }
96
+ }
97
+
98
+ state parse_arp {
99
+ packet.extract(hdr.arp);
100
+ transition select(hdr.arp.htype, hdr.arp.ptype,
101
+ hdr.arp.hlen, hdr.arp.plen) {
102
+ (16w0x0001, 16w0x0800,
103
+ 8w6, 8w4) : parse_arp_ipv4;
104
+ default : accept;
105
+ }
106
+ }
107
+
108
+ state parse_arp_ipv4 {
109
+ packet.extract(hdr.arp_ipv4);
110
+ meta.dst_ipv4 = hdr.arp_ipv4.tpa;
111
+ transition accept;
112
+ }
113
+
114
+ state parse_ipv4 {
115
+ packet.extract(hdr.ipv4);
116
+ meta.dst_ipv4 = hdr.ipv4.dstAddr;
117
+ transition select(hdr.ipv4.protocol) {
118
+ 8w0x01 : parse_icmp;
119
+ default : accept;
120
+ }
121
+ }
122
+
123
+ state parse_icmp {
124
+ packet.extract(hdr.icmp);
125
+ transition accept;
126
+ }
127
+ }
128
+
129
+
130
+ control MyVerifyChecksum(
131
+ inout my_headers_t hdr,
132
+ inout my_metadata_t meta)
133
+ {
134
+ apply { }
135
+ }
136
+
137
+
138
+ control MyIngress(
139
+ inout my_headers_t hdr,
140
+ inout my_metadata_t meta,
141
+ inout standard_metadata_t standard_metadata)
142
+ {
143
+ action drop() {
144
+ mark_to_drop(standard_metadata);
145
+ exit;
146
+ }
147
+
148
+ action set_dst_info(mac_addr_t mac_da,
149
+ mac_addr_t mac_sa,
150
+ port_id_t egress_port)
151
+ {
152
+ meta.mac_da = mac_da;
153
+ meta.mac_sa = mac_sa;
154
+ meta.egress_port = egress_port;
155
+ }
156
+
157
+ table ipv4_lpm {
158
+ key = { meta.dst_ipv4 : lpm; }
159
+ actions = { set_dst_info; drop; }
160
+ default_action = drop();
161
+ }
162
+
163
+ action forward_ipv4() {
164
+ hdr.ethernet.dstAddr = meta.mac_da;
165
+ hdr.ethernet.srcAddr = meta.mac_sa;
166
+ hdr.ipv4.ttl = hdr.ipv4.ttl - 8w1;
167
+
168
+ standard_metadata.egress_spec = meta.egress_port;
169
+ }
170
+
171
+ action send_arp_reply() {
172
+ hdr.ethernet.dstAddr = hdr.arp_ipv4.sha;
173
+ hdr.ethernet.srcAddr = meta.mac_da;
174
+
175
+ hdr.arp.oper = 16w2;
176
+
177
+ hdr.arp_ipv4.tha = hdr.arp_ipv4.sha;
178
+ hdr.arp_ipv4.tpa = hdr.arp_ipv4.spa;
179
+ hdr.arp_ipv4.sha = meta.mac_da;
180
+ hdr.arp_ipv4.spa = meta.dst_ipv4;
181
+
182
+ standard_metadata.egress_spec = standard_metadata.ingress_port;
183
+ }
184
+
185
+ action send_icmp_reply() {
186
+ mac_addr_t tmp_mac;
187
+ ipv4_addr_t tmp_ip;
188
+
189
+ tmp_mac = hdr.ethernet.dstAddr;
190
+ hdr.ethernet.dstAddr = hdr.ethernet.srcAddr;
191
+ hdr.ethernet.srcAddr = tmp_mac;
192
+
193
+ tmp_ip = hdr.ipv4.dstAddr;
194
+ hdr.ipv4.dstAddr = hdr.ipv4.srcAddr;
195
+ hdr.ipv4.srcAddr = tmp_ip;
196
+
197
+ hdr.icmp.type = 8w0;
198
+ hdr.icmp.checksum = 16w0;
199
+
200
+ // For now
201
+
202
+ standard_metadata.egress_spec = standard_metadata.ingress_port;
203
+ }
204
+
205
+ table forward {
206
+ key = {
207
+ hdr.arp.isValid() : exact;
208
+ hdr.arp.oper : ternary;
209
+ hdr.arp_ipv4.isValid() : exact;
210
+ hdr.ipv4.isValid() : exact;
211
+ hdr.icmp.isValid() : exact;
212
+ hdr.icmp.type : ternary;
213
+ }
214
+ actions = {
215
+ forward_ipv4;
216
+ send_arp_reply;
217
+ send_icmp_reply;
218
+ drop;
219
+ }
220
+ const default_action = drop();
221
+ const entries = {
222
+ ( true, 16w1, true, false, false, _ ) :
223
+ send_arp_reply();
224
+ ( false, _, false, true, false, _ ) :
225
+ forward_ipv4();
226
+ ( false, _, false, true, true, 8w8 ) :
227
+ send_icmp_reply();
228
+ }
229
+ }
230
+
231
+ apply {
232
+ meta.my_mac = 48w0x000102030405;
233
+ ipv4_lpm.apply();
234
+ forward.apply();
235
+ }
236
+ }
237
+
238
+
239
+ control MyEgress(
240
+ inout my_headers_t hdr,
241
+ inout my_metadata_t meta,
242
+ inout standard_metadata_t standard_metadata) {
243
+ apply { }
244
+ }
245
+
246
+
247
+ control MyComputeChecksum(
248
+ inout my_headers_t hdr,
249
+ inout my_metadata_t meta)
250
+ {
251
+ apply { }
252
+ }
253
+
254
+
255
+ control MyDeparser(
256
+ packet_out packet,
257
+ in my_headers_t hdr)
258
+ {
259
+ apply {
260
+ packet.emit(hdr.ethernet);
261
+
262
+ /* ARP Case */
263
+ packet.emit(hdr.arp);
264
+ packet.emit(hdr.arp_ipv4);
265
+
266
+ /* IPv4 case */
267
+ packet.emit(hdr.ipv4);
268
+ packet.emit(hdr.icmp);
269
+ }
270
+ }
271
+
272
+ V1Switch(
273
+ MyParser(),
274
+ MyVerifyChecksum(),
275
+ MyIngress(),
276
+ MyEgress(),
277
+ MyComputeChecksum(),
278
+ MyDeparser()
279
+ ) main;
individual_files/000074__raw-repositories__cornell-netlab__capisce.p4 ADDED
@@ -0,0 +1,246 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <core.p4>
2
+ #include <v1model.p4>
3
+
4
+
5
+
6
+ struct meta_t {
7
+ bit<16> register_tmp;
8
+ bit<16> ndpflags;
9
+ }
10
+
11
+ struct routing_metadata_t {
12
+ bit<32> nhop_ipv4;
13
+ }
14
+
15
+ header ethernet_t {
16
+ bit<48> dstAddr;
17
+ bit<48> srcAddr;
18
+ bit<16> etherType;
19
+ }
20
+
21
+ header ipv4_t {
22
+ bit<4> version;
23
+ bit<4> ihl;
24
+ bit<8> diffserv;
25
+ bit<16> totalLen;
26
+ bit<16> identification;
27
+ bit<3> flags;
28
+ bit<13> fragOffset;
29
+ bit<8> ttl;
30
+ bit<8> protocol;
31
+ bit<16> hdrChecksum;
32
+ bit<32> srcAddr;
33
+ bit<32> dstAddr;
34
+ }
35
+
36
+ header ndp_t {
37
+ bit<16> flags;
38
+ bit<16> checksum;
39
+ bit<32> sport;
40
+ bit<32> dport;
41
+ bit<32> seqpull;
42
+ bit<32> pacerecho;
43
+ }
44
+
45
+ struct metadata {
46
+ @name(".meta")
47
+ meta_t meta;
48
+ @name(".routing_metadata")
49
+ routing_metadata_t routing_metadata;
50
+ }
51
+
52
+ struct headers {
53
+ @name(".ethernet")
54
+ ethernet_t ethernet;
55
+ @name(".ipv4")
56
+ ipv4_t ipv4;
57
+ @name(".ndp")
58
+ ndp_t ndp;
59
+ }
60
+
61
+ parser ParserImpl(packet_in packet, out headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
62
+ @name(".parse_ethernet") state parse_ethernet {
63
+ packet.extract(hdr.ethernet);
64
+ transition select(hdr.ethernet.etherType) {
65
+ 16w0x800: parse_ipv4;
66
+ default: accept;
67
+ }
68
+ }
69
+ @name(".parse_ipv4") state parse_ipv4 {
70
+ packet.extract(hdr.ipv4);
71
+ transition select(hdr.ipv4.protocol) {
72
+ 8w199: parse_ndp;
73
+ default: accept;
74
+ }
75
+ }
76
+ @name(".parse_ndp") state parse_ndp {
77
+ packet.extract(hdr.ndp);
78
+ transition accept;
79
+ }
80
+ @name(".start") state start {
81
+ transition parse_ethernet;
82
+ }
83
+ }
84
+
85
+ control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
86
+ @name(".buffersense") register<bit<16>>(32w4) buffersense;
87
+ @name(".decreasereg") action decreasereg() {
88
+ buffersense.read(meta.meta.register_tmp, (bit<32>)standard_metadata.egress_port);
89
+ buffersense.write((bit<32>)standard_metadata.egress_port, (bit<16>)(meta.meta.register_tmp - 16w1 + (bit<16>)standard_metadata.egress_spec));
90
+ }
91
+ @name(".cont") action cont() {
92
+ }
93
+ @name(".rewrite_mac") action rewrite_mac(bit<48> smac) {
94
+ hdr.ethernet.srcAddr = smac;
95
+ }
96
+ @name("._drop") action _drop() {
97
+ mark_to_drop(standard_metadata);
98
+ }
99
+ @name(".dec_counter") table dec_counter {
100
+ actions = {
101
+ decreasereg;
102
+ cont;
103
+ }
104
+ key = {
105
+ meta.meta.ndpflags: ternary;
106
+ }
107
+ size = 2;
108
+ }
109
+ @name(".send_frame") table send_frame {
110
+ actions = {
111
+ rewrite_mac;
112
+ _drop;
113
+ }
114
+ key = {
115
+ standard_metadata.egress_port: exact;
116
+ }
117
+ size = 256;
118
+ }
119
+ apply {
120
+ dec_counter.apply();
121
+ send_frame.apply();
122
+ }
123
+ }
124
+
125
+ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
126
+ @name(".buffersense") register<bit<16>>(32w4) buffersense;
127
+ @name(".directpriohigh") action directpriohigh() {
128
+ standard_metadata.egress_spec = 9w1;
129
+ meta.meta.ndpflags = hdr.ndp.flags;
130
+ }
131
+ @name(".set_dmac") action set_dmac(bit<48> dmac) {
132
+ hdr.ethernet.dstAddr = dmac;
133
+ buffersense.read(meta.meta.register_tmp, (bit<32>)standard_metadata.egress_port);
134
+ }
135
+ @name("._drop") action _drop() {
136
+ mark_to_drop(standard_metadata);
137
+ }
138
+ @name(".set_nhop") action set_nhop(bit<32> nhop_ipv4, bit<9> port) {
139
+ meta.routing_metadata.nhop_ipv4 = nhop_ipv4;
140
+ standard_metadata.egress_port = port;
141
+ hdr.ipv4.ttl = hdr.ipv4.ttl + 8w255;
142
+ }
143
+ @name(".readbuffer") action readbuffer() {
144
+ buffersense.read(meta.meta.register_tmp, (bit<32>)standard_metadata.egress_port);
145
+ }
146
+ @name(".setpriolow") action setpriolow() {
147
+ standard_metadata.egress_spec = 9w0;
148
+ buffersense.read(meta.meta.register_tmp, (bit<32>)standard_metadata.egress_port);
149
+ buffersense.write((bit<32>)standard_metadata.egress_port, (bit<16>)(meta.meta.register_tmp + 16w1));
150
+ }
151
+ @name(".setpriohigh") action setpriohigh() {
152
+ truncate((bit<32>)32w54);
153
+ hdr.ipv4.totalLen = 16w20;
154
+ standard_metadata.egress_spec = 9w1;
155
+ }
156
+ @name(".directtoprio") table directtoprio {
157
+ actions = {
158
+ directpriohigh;
159
+ }
160
+ key = {
161
+ meta.meta.register_tmp: ternary;
162
+ }
163
+ size = 2;
164
+ }
165
+ @name(".forward") table forward {
166
+ actions = {
167
+ set_dmac;
168
+ _drop;
169
+ }
170
+ key = {
171
+ meta.routing_metadata.nhop_ipv4: exact;
172
+ }
173
+ size = 512;
174
+ }
175
+ @name(".ipv4_lpm") table ipv4_lpm {
176
+ actions = {
177
+ set_nhop;
178
+ _drop;
179
+ }
180
+ key = {
181
+ hdr.ipv4.dstAddr: lpm;
182
+ }
183
+ size = 1024;
184
+ }
185
+ @name(".readbuffersense") table readbuffersense {
186
+ actions = {
187
+ readbuffer;
188
+ }
189
+ key = {
190
+ meta.meta.register_tmp: ternary;
191
+ }
192
+ size = 2;
193
+ }
194
+ @name(".setprio") table setprio {
195
+ actions = {
196
+ setpriolow;
197
+ setpriohigh;
198
+ }
199
+ key = {
200
+ meta.meta.register_tmp: ternary;
201
+ }
202
+ size = 2;
203
+ }
204
+ apply {
205
+ if (hdr.ipv4.isValid()) {
206
+ if (hdr.ipv4.ttl > 8w0) {
207
+ ipv4_lpm.apply();
208
+ if (hdr.ndp.isValid()) {
209
+ if (hdr.ndp.flags > 16w1) {
210
+ directtoprio.apply();
211
+ } else {
212
+ readbuffersense.apply();
213
+ setprio.apply();
214
+ }
215
+ }
216
+ else {
217
+ readbuffersense.apply();
218
+ setprio.apply();
219
+ }
220
+ forward.apply();
221
+ }
222
+ }
223
+ }
224
+ }
225
+
226
+ control DeparserImpl(packet_out packet, in headers hdr) {
227
+ apply {
228
+ packet.emit(hdr.ethernet);
229
+ packet.emit(hdr.ipv4);
230
+ packet.emit(hdr.ndp);
231
+ }
232
+ }
233
+
234
+ control verifyChecksum(inout headers hdr, inout metadata meta) {
235
+ apply {
236
+ 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);
237
+ }
238
+ }
239
+
240
+ control computeChecksum(inout headers hdr, inout metadata meta) {
241
+ apply {
242
+ 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);
243
+ }
244
+ }
245
+
246
+ V1Switch(ParserImpl(), verifyChecksum(), ingress(), egress(), computeChecksum(), DeparserImpl()) main;
individual_files/000075__raw-repositories__cornell-netlab__capisce.p4 ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <core.p4>
2
+ #include <v1model.p4>
3
+
4
+ struct intrinsic_metadata_t {
5
+ bit<4> mcast_grp;
6
+ bit<4> egress_rid;
7
+ bit<32> lf_field_list;
8
+ bit<16> resubmit_flag;
9
+ }
10
+
11
+ struct mymeta_t {
12
+ bit<8> f1;
13
+ }
14
+
15
+ header ethernet_t {
16
+ bit<48> dstAddr;
17
+ bit<48> srcAddr;
18
+ bit<16> etherType;
19
+ }
20
+
21
+ struct metadata {
22
+ @name(".mymeta")
23
+ mymeta_t mymeta;
24
+ }
25
+
26
+ struct headers {
27
+ @name(".ethernet")
28
+ ethernet_t ethernet;
29
+ }
30
+
31
+ parser ParserImpl(packet_in packet, out headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
32
+ @name(".parse_ethernet") state parse_ethernet {
33
+ packet.extract(hdr.ethernet);
34
+ transition accept;
35
+ }
36
+ @name(".start") state start {
37
+ transition parse_ethernet;
38
+ }
39
+ }
40
+
41
+ control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
42
+ apply {
43
+ }
44
+ }
45
+
46
+ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
47
+ @name("._nop") action _nop() {
48
+ }
49
+ @name(".set_port") action set_port(bit<9> port) {
50
+ standard_metadata.egress_spec = port;
51
+ }
52
+ @name("._resubmit") action _resubmit() {
53
+ meta.mymeta.f1 = 8w1;
54
+
55
+ }
56
+ @name(".t_ingress_1") table t_ingress_1 {
57
+ actions = {
58
+ _nop;
59
+ set_port;
60
+ }
61
+ key = {
62
+ meta.mymeta.f1: exact;
63
+ }
64
+ size = 128;
65
+ }
66
+ @name(".t_ingress_2") table t_ingress_2 {
67
+ actions = {
68
+ _nop;
69
+ _resubmit;
70
+ }
71
+ key = {
72
+ meta.mymeta.f1: exact;
73
+ }
74
+ size = 128;
75
+ }
76
+ apply {
77
+ t_ingress_1.apply();
78
+ t_ingress_2.apply();
79
+ }
80
+ }
81
+
82
+ control DeparserImpl(packet_out packet, in headers hdr) {
83
+ apply {
84
+ packet.emit(hdr.ethernet);
85
+ }
86
+ }
87
+
88
+ control verifyChecksum(inout headers hdr, inout metadata meta) {
89
+ apply {
90
+ }
91
+ }
92
+
93
+ control computeChecksum(inout headers hdr, inout metadata meta) {
94
+ apply {
95
+ }
96
+ }
97
+
98
+ V1Switch(ParserImpl(), verifyChecksum(), ingress(), egress(), computeChecksum(), DeparserImpl()) main;
individual_files/000076__raw-repositories__cornell-netlab__capisce.p4 ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <core.p4>
2
+ #define V1MODEL_VERSION 20200408
3
+ #include <v1model.p4>
4
+
5
+ struct ingress_metadata_t {
6
+ }
7
+
8
+ header h_t {
9
+ bit<16> value;
10
+ }
11
+
12
+ struct metadata {
13
+ ingress_metadata_t ing_metadata;
14
+ }
15
+
16
+ struct headers {
17
+ h_t h0;
18
+ h_t h1;
19
+ h_t h2;
20
+ h_t h3;
21
+ h_t h4;
22
+ }
23
+
24
+ parser ParserImpl(packet_in packet, out headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
25
+ @name(".start") state start {
26
+ packet.extract(hdr.h0);
27
+ }
28
+ }
29
+
30
+ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
31
+ action drop_() {
32
+ mark_to_drop(standard_metadata);
33
+ }
34
+ action validate_h1(bit<16> value) {
35
+ hdr.h1.setValid();
36
+ hdr.h1.value = value;
37
+ }
38
+ action validate_h2(bit<16> value) {
39
+ hdr.h2.setValid();
40
+ hdr.h2.value = value;
41
+ }
42
+ action validate_h3(bit<16> value) {
43
+ hdr.h3.setValid();
44
+ hdr.h3.value = value;
45
+ }
46
+ action use_h1_h2_h3() {
47
+ hdr.h4.setValid();
48
+ hdr.h4.value =
49
+ (hdr.h1.value & (hdr.h2.value | hdr.h3.value)) -
50
+ ((hdr.h1.value | (hdr.h2.value & hdr.h3.value)));
51
+ assert(hdr.h4.value <= (hdr.h1.value & (hdr.h2.value | hdr.h3.value)));
52
+
53
+ // underflow protection
54
+
55
+ }
56
+ table t1 {
57
+ key = {
58
+ hdr.h0.value: exact;
59
+ }
60
+ actions = {
61
+ validate_h1;
62
+ drop_;
63
+ }
64
+ }
65
+ table t2 {
66
+ key = {
67
+ hdr.h0.value: exact;
68
+ }
69
+ actions = {
70
+ validate_h2;
71
+ drop_;
72
+ }
73
+ }
74
+ table t3 {
75
+ key = {
76
+ hdr.h0.value: exact;
77
+ }
78
+ actions = {
79
+ validate_h3;
80
+ drop_;
81
+ }
82
+ }
83
+ table t4 {
84
+ key = {
85
+ hdr.h0.value: exact;
86
+ }
87
+ actions = {
88
+ use_h1_h2_h3;
89
+ drop_;
90
+ }
91
+ }
92
+ apply {
93
+ hdr.h1.setInvalid();
94
+ hdr.h2.setInvalid();
95
+ hdr.h3.setInvalid();
96
+ hdr.h4.setInvalid();
97
+ t1.apply();
98
+ t2.apply();
99
+ t3.apply();
100
+ t4.apply();
101
+ standard_metadata.egress_spec = 9w511;
102
+ }
103
+ }
104
+
105
+ control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
106
+ apply {}
107
+ }
108
+
109
+ control DeparserImpl(packet_out packet, in headers hdr) {
110
+ apply {
111
+ }
112
+ }
113
+
114
+ control verifyChecksum(inout headers hdr, inout metadata meta) {
115
+ apply {}
116
+ }
117
+
118
+ control computeChecksum(inout headers hdr, inout metadata meta) {
119
+ apply {}
120
+ }
121
+
122
+ V1Switch(ParserImpl(), verifyChecksum(), ingress(), egress(), computeChecksum(), DeparserImpl()) main;
individual_files/000077__raw-repositories__cornell-netlab__capisce.p4 ADDED
@@ -0,0 +1,186 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <core.p4>
2
+ #include <v1model.p4>
3
+
4
+ #define TYPE_IPV4 16w0x800;
5
+
6
+
7
+
8
+ typedef bit<9> egressSpec_t;
9
+ typedef bit<48> macAddr_t;
10
+ typedef bit<32> ip4Addr_t;
11
+
12
+ header ethernet_t {
13
+ macAddr_t dstAddr;
14
+ macAddr_t srcAddr;
15
+ bit<16> etherType;
16
+ }
17
+
18
+ header ipv4_t {
19
+ bit<4> version;
20
+ bit<4> ihl;
21
+ bit<8> diffserv;
22
+ bit<16> totalLen;
23
+ bit<16> identification;
24
+ bit<3> flags;
25
+ bit<13> fragOffset;
26
+ bit<8> ttl;
27
+ bit<8> protocol;
28
+ bit<16> hdrChecksum;
29
+ ip4Addr_t srcAddr;
30
+ ip4Addr_t dstAddr;
31
+ }
32
+
33
+ header ipv6_t {
34
+ bit<4> version;
35
+ bit<8> trafficClass;
36
+ bit<20> flowLabel;
37
+ bit<16> payloadLen;
38
+ bit<8> nextHdr;
39
+ bit<8> hopLimit;
40
+ bit<128> srcAddr;
41
+ bit<128> dstAddr;
42
+ }
43
+
44
+ struct metadata {
45
+ bit<1> l3_admit;
46
+ }
47
+
48
+ struct headers {
49
+ ethernet_t ethernet;
50
+ ipv4_t ipv4;
51
+ ipv6_t ipv6;
52
+ }
53
+
54
+
55
+
56
+ parser MyParser(packet_in packet,
57
+ out headers hdr,
58
+ inout metadata meta,
59
+ inout standard_metadata_t standard_metadata) {
60
+ state parse_ipv4 {
61
+ packet.extract(hdr.ipv4);
62
+ transition accept;
63
+ }
64
+
65
+ state parse_ipv6 {
66
+ packet.extract(hdr.ipv6);
67
+ transition accept;
68
+ }
69
+
70
+ state start {
71
+ packet.extract(hdr.ethernet);
72
+ transition select(hdr.ethernet.etherType) {
73
+ 16w0x0800: parse_ipv4;
74
+ default : reject;
75
+ }
76
+ }
77
+ }
78
+
79
+
80
+
81
+
82
+ control MyVerifyChecksum(inout headers hdr, inout metadata meta) {
83
+ apply { }
84
+ }
85
+
86
+
87
+
88
+
89
+ control MyIngress(inout headers hdr,
90
+ inout metadata meta,
91
+ inout standard_metadata_t standard_metadata) {
92
+ action drop() {
93
+ mark_to_drop(standard_metadata);
94
+ }
95
+
96
+ action packet_type(bit<1> is_l3) {
97
+ meta.l3_admit = is_l3;
98
+ }
99
+
100
+ table l2 {
101
+ key = {
102
+ hdr.ethernet.srcAddr: exact;
103
+ }
104
+ actions = {
105
+ drop;
106
+ NoAction;
107
+ }
108
+ }
109
+
110
+ action ctrl() {
111
+ standard_metadata.egress_spec = 9w510;
112
+
113
+ // or whatever the controller port number is
114
+ }
115
+
116
+ table l3 {
117
+ key = { hdr.ipv4.ttl : exact; }
118
+ actions = { drop; NoAction; }
119
+ }
120
+
121
+ table punt {
122
+ key = { hdr.ethernet.srcAddr: exact;
123
+ hdr.ethernet.dstAddr: exact;
124
+ hdr.ipv4.srcAddr: exact;
125
+ hdr.ipv4.ttl : exact;
126
+ hdr.ipv4.dstAddr : exact; }
127
+ actions = { ctrl; NoAction; }
128
+ }
129
+
130
+ apply {
131
+ standard_metadata.egress_spec = 9w0;
132
+ l2.apply();
133
+ l3.apply();
134
+ punt.apply();
135
+ }
136
+ }
137
+
138
+
139
+
140
+ control MyEgress(inout headers hdr,
141
+ inout metadata meta,
142
+ inout standard_metadata_t standard_metadata) {
143
+ apply { }
144
+ }
145
+
146
+
147
+
148
+ control MyComputeChecksum(inout headers hdr, inout metadata meta) {
149
+ apply {
150
+ update_checksum(
151
+ hdr.ipv4.isValid(),
152
+ { hdr.ipv4.version,
153
+ hdr.ipv4.ihl,
154
+ hdr.ipv4.diffserv,
155
+ hdr.ipv4.totalLen,
156
+ hdr.ipv4.identification,
157
+ hdr.ipv4.flags,
158
+ hdr.ipv4.fragOffset,
159
+ hdr.ipv4.ttl,
160
+ hdr.ipv4.protocol,
161
+ hdr.ipv4.srcAddr,
162
+ hdr.ipv4.dstAddr },
163
+ hdr.ipv4.hdrChecksum,
164
+ HashAlgorithm.csum16);
165
+ }
166
+ }
167
+
168
+
169
+
170
+
171
+ control MyDeparser(packet_out packet, in headers hdr) {
172
+ apply {
173
+
174
+ }
175
+ }
176
+
177
+
178
+
179
+ V1Switch(
180
+ MyParser(),
181
+ MyVerifyChecksum(),
182
+ MyIngress(),
183
+ MyEgress(),
184
+ MyComputeChecksum(),
185
+ MyDeparser()
186
+ ) main;
individual_files/000078__raw-repositories__cornell-netlab__capisce.p4 ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <core.p4>
2
+ #include <v1model.p4>
3
+
4
+ #define TYPE_IPV4 16w0x800;
5
+
6
+
7
+
8
+ typedef bit<9> egressSpec_t;
9
+ typedef bit<48> macAddr_t;
10
+ typedef bit<32> ip4Addr_t;
11
+
12
+ header ethernet_t {
13
+ macAddr_t dstAddr;
14
+ macAddr_t srcAddr;
15
+ bit<16> etherType;
16
+ }
17
+
18
+ header ipv4_t {
19
+ bit<4> version;
20
+ bit<4> ihl;
21
+ bit<8> diffserv;
22
+ bit<16> totalLen;
23
+ bit<16> identification;
24
+ bit<3> flags;
25
+ bit<13> fragOffset;
26
+ bit<8> ttl;
27
+ bit<8> protocol;
28
+ bit<16> hdrChecksum;
29
+ ip4Addr_t srcAddr;
30
+ ip4Addr_t dstAddr;
31
+ }
32
+
33
+ header ipv6_t {
34
+ bit<4> version;
35
+ bit<8> trafficClass;
36
+ bit<20> flowLabel;
37
+ bit<16> payloadLen;
38
+ bit<8> nextHdr;
39
+ bit<8> hopLimit;
40
+ bit<128> srcAddr;
41
+ bit<128> dstAddr;
42
+ }
43
+
44
+ struct metadata {
45
+ bit<1> l3_admit;
46
+ }
47
+
48
+ struct headers {
49
+ ethernet_t ethernet;
50
+ ipv4_t ipv4;
51
+ ipv6_t ipv6;
52
+ }
53
+
54
+
55
+
56
+ parser MyParser(packet_in packet,
57
+ out headers hdr,
58
+ inout metadata meta,
59
+ inout standard_metadata_t standard_metadata) {
60
+ state parse_ipv4 {
61
+ packet.extract(hdr.ipv4);
62
+ transition accept;
63
+ }
64
+
65
+ state parse_ipv6 {
66
+ packet.extract(hdr.ipv6);
67
+ transition accept;
68
+ }
69
+
70
+ state start {
71
+ packet.extract(hdr.ethernet);
72
+ transition select(hdr.ethernet.etherType) {
73
+ 16w0x0800: parse_ipv4;
74
+ default : reject;
75
+ }
76
+ }
77
+ }
78
+
79
+
80
+
81
+
82
+ control MyVerifyChecksum(inout headers hdr, inout metadata meta) {
83
+ apply { }
84
+ }
85
+
86
+
87
+
88
+
89
+ control MyIngress(inout headers hdr,
90
+ inout metadata meta,
91
+ inout standard_metadata_t standard_metadata) {
92
+ action drop() {
93
+ mark_to_drop(standard_metadata);
94
+ }
95
+
96
+ action packet_type(bit<1> is_l3) {
97
+ meta.l3_admit = is_l3;
98
+ }
99
+
100
+ table get_type {
101
+ key = {
102
+ hdr.ethernet.etherType: exact;
103
+ }
104
+ actions = {
105
+ packet_type;
106
+ drop;
107
+ }
108
+ }
109
+
110
+ action fwd_(bit<9> port) {
111
+ standard_metadata.egress_spec = port;
112
+ }
113
+
114
+ table fwd {
115
+ key = { meta.l3_admit : exact ; hdr.ipv4.dstAddr : lpm; }
116
+ actions = { fwd_; drop; NoAction; }
117
+ }
118
+ apply {
119
+ get_type.apply();
120
+ fwd.apply();
121
+ }
122
+ }
123
+
124
+
125
+
126
+ control MyEgress(inout headers hdr,
127
+ inout metadata meta,
128
+ inout standard_metadata_t standard_metadata) {
129
+ apply { }
130
+ }
131
+
132
+
133
+
134
+ control MyComputeChecksum(inout headers hdr, inout metadata meta) {
135
+ apply {
136
+ update_checksum(
137
+ hdr.ipv4.isValid(),
138
+ { hdr.ipv4.version,
139
+ hdr.ipv4.ihl,
140
+ hdr.ipv4.diffserv,
141
+ hdr.ipv4.totalLen,
142
+ hdr.ipv4.identification,
143
+ hdr.ipv4.flags,
144
+ hdr.ipv4.fragOffset,
145
+ hdr.ipv4.ttl,
146
+ hdr.ipv4.protocol,
147
+ hdr.ipv4.srcAddr,
148
+ hdr.ipv4.dstAddr },
149
+ hdr.ipv4.hdrChecksum,
150
+ HashAlgorithm.csum16);
151
+ }
152
+ }
153
+
154
+
155
+
156
+
157
+ control MyDeparser(packet_out packet, in headers hdr) {
158
+ apply {
159
+
160
+ }
161
+ }
162
+
163
+
164
+
165
+ V1Switch(
166
+ MyParser(),
167
+ MyVerifyChecksum(),
168
+ MyIngress(),
169
+ MyEgress(),
170
+ MyComputeChecksum(),
171
+ MyDeparser()
172
+ ) main;
individual_files/000079__raw-repositories__cornell-netlab__capisce.p4 ADDED
@@ -0,0 +1,191 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <core.p4>
2
+ #include <v1model.p4>
3
+
4
+ #define TYPE_IPV4 16w0x800;
5
+
6
+
7
+
8
+ typedef bit<9> egressSpec_t;
9
+ typedef bit<48> macAddr_t;
10
+ typedef bit<32> ip4Addr_t;
11
+
12
+ header ethernet_t {
13
+ macAddr_t dstAddr;
14
+ macAddr_t srcAddr;
15
+ bit<16> etherType;
16
+ }
17
+
18
+ header ipv4_t {
19
+ bit<4> version;
20
+ bit<4> ihl;
21
+ bit<8> diffserv;
22
+ bit<16> totalLen;
23
+ bit<16> identification;
24
+ bit<3> flags;
25
+ bit<13> fragOffset;
26
+ bit<8> ttl;
27
+ bit<8> protocol;
28
+ bit<16> hdrChecksum;
29
+ ip4Addr_t srcAddr;
30
+ ip4Addr_t dstAddr;
31
+ }
32
+
33
+ header ipv6_t {
34
+ bit<4> version;
35
+ bit<8> trafficClass;
36
+ bit<20> flowLabel;
37
+ bit<16> payloadLen;
38
+ bit<8> nextHdr;
39
+ bit<8> hopLimit;
40
+ bit<128> srcAddr;
41
+ bit<128> dstAddr;
42
+ }
43
+
44
+ struct metadata {
45
+ bit<1> is_v4;
46
+ }
47
+
48
+ struct headers {
49
+ ethernet_t ethernet;
50
+ ipv4_t ipv4;
51
+ ipv6_t ipv6;
52
+ ipv4_t inner_ipv4;
53
+ ipv6_t inner_ipv6;
54
+ }
55
+
56
+
57
+
58
+ parser MyParser(packet_in packet,
59
+ out headers hdr,
60
+ inout metadata meta,
61
+ inout standard_metadata_t standard_metadata) {
62
+ state parse_ipv4 {
63
+ packet.extract(hdr.ipv4);
64
+ transition accept;
65
+ }
66
+
67
+ state parse_ipv6 {
68
+ packet.extract(hdr.ipv6);
69
+ transition accept;
70
+ }
71
+
72
+ state start {
73
+ packet.extract(hdr.ethernet);
74
+ transition select(hdr.ethernet.etherType) {
75
+ 16w0x0800: parse_ipv4;
76
+ 16w0x86DD: parse_ipv6;
77
+ default : reject;
78
+ }
79
+ }
80
+ }
81
+
82
+
83
+
84
+
85
+ control MyVerifyChecksum(inout headers hdr, inout metadata meta) {
86
+ apply { }
87
+ }
88
+
89
+
90
+
91
+
92
+ control MyIngress(inout headers hdr,
93
+ inout metadata meta,
94
+ inout standard_metadata_t standard_metadata) {
95
+ action drop() {
96
+ mark_to_drop(standard_metadata);
97
+ }
98
+
99
+ action packet_type(bit<1> version) {
100
+ meta.is_v4 = version;
101
+ }
102
+
103
+ action encap_v4(){
104
+ hdr.inner_ipv4.setValid();
105
+
106
+ }
107
+
108
+ action encap_v6() {
109
+ hdr.inner_ipv6.setValid();
110
+
111
+ }
112
+
113
+ table get_type {
114
+ key = {
115
+ hdr.ethernet.etherType: exact;
116
+ }
117
+ actions = {
118
+ packet_type;
119
+ }
120
+ }
121
+
122
+ table ipv4_encap {
123
+ key = { hdr.ethernet.etherType : exact; }
124
+ actions = { encap_v4; NoAction; }
125
+ }
126
+
127
+ table ipv6_encap {
128
+ key = { hdr.ethernet.etherType : exact; }
129
+ actions = { encap_v6; NoAction; }
130
+ }
131
+ apply {
132
+ hdr.inner_ipv6.setInvalid();
133
+ hdr.inner_ipv4.setInvalid();
134
+ ipv4_encap.apply();
135
+ ipv6_encap.apply();
136
+
137
+ assert((!hdr.ipv4.isValid()) || (!hdr.inner_ipv6.isValid()));
138
+ assert((!hdr.ipv6.isValid()) || (!hdr.inner_ipv4.isValid()));
139
+ standard_metadata.egress_spec = 9w511;
140
+ }
141
+ }
142
+
143
+
144
+
145
+ control MyEgress(inout headers hdr,
146
+ inout metadata meta,
147
+ inout standard_metadata_t standard_metadata) {
148
+ apply { }
149
+ }
150
+
151
+
152
+
153
+ control MyComputeChecksum(inout headers hdr, inout metadata meta) {
154
+ apply {
155
+ update_checksum(
156
+ hdr.ipv4.isValid(),
157
+ { hdr.ipv4.version,
158
+ hdr.ipv4.ihl,
159
+ hdr.ipv4.diffserv,
160
+ hdr.ipv4.totalLen,
161
+ hdr.ipv4.identification,
162
+ hdr.ipv4.flags,
163
+ hdr.ipv4.fragOffset,
164
+ hdr.ipv4.ttl,
165
+ hdr.ipv4.protocol,
166
+ hdr.ipv4.srcAddr,
167
+ hdr.ipv4.dstAddr },
168
+ hdr.ipv4.hdrChecksum,
169
+ HashAlgorithm.csum16);
170
+ }
171
+ }
172
+
173
+
174
+
175
+
176
+ control MyDeparser(packet_out packet, in headers hdr) {
177
+ apply {
178
+
179
+ }
180
+ }
181
+
182
+
183
+
184
+ V1Switch(
185
+ MyParser(),
186
+ MyVerifyChecksum(),
187
+ MyIngress(),
188
+ MyEgress(),
189
+ MyComputeChecksum(),
190
+ MyDeparser()
191
+ ) main;