-
Notifications
You must be signed in to change notification settings - Fork 0
/
l2switch.p4
111 lines (88 loc) · 2.07 KB
/
l2switch.p4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include <core.p4>
#include <v1model.p4>
header ethernet_t {
bit<48> dstAddr;
bit<48> srcAddr;
bit<16> etherType;
}
struct metadata {
}
struct headers {
ethernet_t ethernet;
}
parser ParserImpl(packet_in packet, out headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
state start {
transition parse_ethernet;
}
state parse_ethernet {
packet.extract(hdr.ethernet);
transition accept;
}
}
control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
apply {
}
}
struct mac_learn_digest {
bit<48> srcAddr;
bit<9> ingress_port;
}
control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
action forward(bit<9> port) {
standard_metadata.egress_spec = port;
}
action bcast() {
standard_metadata.mcast_grp = 1;
}
action mac_learn() {
digest<mac_learn_digest>((bit<32>)1024, { hdr.ethernet.srcAddr, standard_metadata.ingress_port });
}
action drop() {
mark_to_drop( standard_metadata );
exit;
}
action _nop() {
}
table dmac {
actions = {
forward;
bcast;
drop;
}
key = {
hdr.ethernet.dstAddr: exact;
}
default_action = bcast();
size = 512;
}
table smac {
actions = {
mac_learn;
_nop;
drop;
}
key = {
hdr.ethernet.srcAddr: exact;
}
default_action = mac_learn();
size = 512;
}
apply {
smac.apply();
dmac.apply();
}
}
control DeparserImpl(packet_out packet, in headers hdr) {
apply {
packet.emit(hdr.ethernet);
}
}
control verifyChecksum(inout headers hdr, inout metadata meta) {
apply {
}
}
control computeChecksum(inout headers hdr, inout metadata meta) {
apply {
}
}
V1Switch(ParserImpl(), verifyChecksum(), ingress(), egress(), computeChecksum(), DeparserImpl()) main;