-
Notifications
You must be signed in to change notification settings - Fork 1
/
switch.p4
51 lines (38 loc) · 1.22 KB
/
switch.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
#include <core.p4>
#include <v1model.p4>
#include "includes/header.p4"
#include "includes/parser.p4"
control MyIngress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
action _drop() {
mark_to_drop(standard_metadata);
}
action ipv4_forward(EthernetAddress dstAddr, egressSpec_t port) {
standard_metadata.egress_spec = port;
hdr.ethernet.srcAddr = hdr.ethernet.dstAddr;
hdr.ethernet.dstAddr = dstAddr;
hdr.ipv4.ttl = hdr.ipv4.ttl - 1;
}
table ipv4_lpm { //ipv4 longest prefix
key = {
hdr.ipv4.dstAddr: lpm;
}
actions = {
ipv4_forward;
_drop;
NoAction;
}
size = 1024;
default_action = _drop();
}
apply {
if (hdr.ipv4.isValid()) { //Layer 3 handling
ipv4_lpm.apply();
}
}
}
//////////////////EGRESS////////////////////////////////
control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
apply {}
}
/////////////////////////SWITCH/////////////////////////
V1Switch(TopParser(), verifyChecksum(), MyIngress(), egress(), computeChecksum(), TopDeparser()) main;