-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpuport_finder.p4
97 lines (82 loc) · 1.9 KB
/
cpuport_finder.p4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <core.p4>
#include <v1model.p4>
typedef bit<48> macAddr_t;
@controller_header("packet_out")
header packet_out_header_t {
bit<9> egress_port;
bit<7> _pad;
}
@controller_header("packet_in")
header packet_in_header_t {
bit<9> ingress_port;
bit<7> _pad;
}
header ethernet_t {
macAddr_t dstAddr;
macAddr_t srcAddr;
bit<16> etherType;
}
header cpuport_header_t {
bit<9> port;
bit<7> _pad;
}
struct metadata {
/* empty */
}
struct headers {
ethernet_t ethernet;
cpuport_header_t cpuport;
packet_out_header_t packet_out;
packet_in_header_t packet_in;
}
parser MyParser(packet_in packet, out headers hdr, inout metadata meta,
inout standard_metadata_t standard_metadata)
{
state start {
packet.extract(hdr.packet_out);
transition parse_ethernet;
}
state parse_ethernet {
packet.extract(hdr.ethernet);
transition accept;
}
}
control MyVerifyChecksum(inout headers hdr, inout metadata meta) {
apply { }
}
control MyIngress(inout headers hdr, inout metadata meta,
inout standard_metadata_t standard_metadata)
{
apply {
standard_metadata.egress_spec = hdr.packet_out.egress_port;
hdr.packet_out.setInvalid();
hdr.cpuport.setValid();
hdr.cpuport.port = standard_metadata.ingress_port;
}
}
control MyEgress(inout headers hdr, inout metadata meta,
inout standard_metadata_t standard_metadata)
{
apply { }
}
control MyComputeChecksum(inout headers hdr, inout metadata meta)
{
apply { }
}
control MyDeparser(packet_out packet, in headers hdr)
{
apply {
packet.emit(hdr.packet_out);
packet.emit(hdr.packet_in);
packet.emit(hdr.ethernet);
packet.emit(hdr.cpuport);
}
}
V1Switch(
MyParser(),
MyVerifyChecksum(),
MyIngress(),
MyEgress(),
MyComputeChecksum(),
MyDeparser()
) main;