Last active
August 26, 2021 16:58
-
-
Save tudang/bc2cf0bdc6b806f5a38e1843cc3b5a3a to your computer and use it in GitHub Desktop.
An input P4 program for PISCES
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ovs-ofctl --protocols=OpenFlow15 del-flows br0 | |
ovs-ofctl --protocols=OpenFlow15 add-flow br0 "table=0,priority=32768,ethernet_dstAddr=0x0CC47AA32534 \ | |
actions=set_field:1->reg0, \ | |
resubmit(,1)" | |
ovs-ofctl --protocols=OpenFlow15 add-flow br0 "table=0,priority=32768,ethernet_dstAddr=0x0CC47AA32535 \ | |
actions=set_field:2->reg0, \ | |
resubmit(,1)" | |
ovs-ofctl --protocols=OpenFlow15 add-flow br0 "table=0,priority=0 actions=set_field:2->reg0, \ | |
deparse,output:NXM_NX_REG0[]" | |
ovs-ofctl --protocols=OpenFlow15 add-flow br0 "table=1,priority=0 actions=set_field:1->header_0_field_0, \ | |
set_field:1->header_1_field_0, \ | |
set_field:1->header_2_field_0, \ | |
set_field:1->header_3_field_0, \ | |
deparse,output:NXM_NX_REG0[]" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define ETHERTYPE_IPV4 0x0800 | |
#define TCP_PROTOCOL 0x06 | |
#define UDP_PROTOCOL 0x11 | |
#define GENERIC_PROTOCOL 0x9091 | |
header_type ethernet_t { | |
fields { | |
dstAddr : 48; | |
srcAddr : 48; | |
etherType : 16; | |
} | |
} | |
header ethernet_t ethernet; | |
parser start { | |
return parse_ethernet; | |
} | |
parser parse_ethernet { | |
extract(ethernet); | |
return select(latest.etherType) { | |
ETHERTYPE_IPV4 : parse_ipv4; | |
default : ingress; | |
} | |
} | |
header_type ipv4_t { | |
fields { | |
version : 4; | |
ihl : 4; | |
diffserv : 8; | |
totalLen : 16; | |
identification : 16; | |
flags : 3; | |
fragOffset : 13; | |
ttl : 8; | |
protocol : 8; | |
hdrChecksum : 16; | |
srcAddr : 32; | |
dstAddr : 32; | |
} | |
} | |
header ipv4_t ipv4; | |
parser parse_ipv4 { | |
extract(ipv4); | |
return select(latest.protocol) { | |
TCP_PROTOCOL : parse_tcp; | |
UDP_PROTOCOL : parse_udp; | |
default : ingress; | |
} | |
} | |
header_type tcp_t { | |
fields { | |
srcPort : 16; | |
dstPort : 16; | |
seqNo : 32; | |
ackNo : 32; | |
dataOffset : 4; | |
res : 3; | |
ecn : 3; | |
ctrl : 6; | |
window : 16; | |
checksum : 16; | |
urgentPtr : 16; | |
} | |
} | |
header tcp_t tcp; | |
parser parse_tcp { | |
extract(tcp); | |
return ingress; | |
} | |
header_type udp_t { | |
fields { | |
srcPort : 16; | |
dstPort : 16; | |
length_ : 16; | |
checksum : 16; | |
} | |
} | |
header udp_t udp; | |
parser parse_udp { | |
extract(udp); | |
return select(latest.dstPort) { | |
37009 : parse_header_0; | |
default : ingress; | |
} | |
} | |
header_type header_0_t { | |
fields { | |
field_0 : 16; | |
field_1 : 16; | |
field_2 : 16; | |
field_3 : 16; | |
} | |
} | |
header header_0_t header_0; | |
parser parse_header_0 { | |
extract(header_0); | |
return select(latest.field_0) { | |
default : ingress; | |
} | |
} | |
action mod_headers() { | |
modify_field(header_0.field_0, 1); | |
modify_field(header_0.field_1, 1); | |
modify_field(header_0.field_2, 1); | |
modify_field(header_0.field_3, 1); | |
} | |
action _drop() { | |
drop(); | |
} | |
action forward(port) { | |
modify_field(standard_metadata.egress_spec, port); | |
} | |
table forward_table { | |
reads { | |
ethernet.dstAddr : exact; | |
} actions { | |
forward; | |
_drop; | |
} | |
size : 4; | |
} | |
table test_tbl { | |
actions { | |
mod_headers; | |
} | |
size : 1; | |
} | |
control ingress { | |
apply(forward_table); | |
apply(test_tbl); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment