2019-02-21 22:19:17 +00:00
|
|
|
/* -*- P4_16 -*- */
|
|
|
|
#include <core.p4>
|
|
|
|
#include <v1model.p4>
|
|
|
|
|
|
|
|
#include "headers.p4"
|
|
|
|
#include "parsers.p4"
|
|
|
|
#include "checksums.p4"
|
|
|
|
#include "settings.p4"
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
************** I N G R E S S P R O C E S S I N G *******************
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
control MyIngress(inout headers hdr,
|
2019-02-23 13:22:46 +00:00
|
|
|
inout metadata meta,
|
|
|
|
inout standard_metadata_t standard_metadata) {
|
2019-02-21 22:19:17 +00:00
|
|
|
|
2019-02-24 14:53:10 +00:00
|
|
|
/* use for debugging and controlling flows */
|
|
|
|
action send_to_controller() {
|
|
|
|
clone3(CloneType.I2E, 100, meta);
|
|
|
|
}
|
|
|
|
|
2019-02-26 14:30:47 +00:00
|
|
|
/********************** NDP support ***********************************/
|
|
|
|
|
|
|
|
/* map port to group */
|
|
|
|
action multicast_pkg(mcast_t mcast_grp) {
|
|
|
|
standard_metadata.mcast_grp = mcast_grp;
|
|
|
|
}
|
|
|
|
|
|
|
|
table ndp {
|
|
|
|
key = {
|
|
|
|
hdr.ipv6.dst_addr: lpm;
|
|
|
|
standard_metadata.ingress_port : exact;
|
|
|
|
}
|
|
|
|
actions = {
|
|
|
|
multicast_pkg;
|
|
|
|
NoAction;
|
|
|
|
}
|
|
|
|
size = NDP_TABLE_SIZE;
|
|
|
|
default_action = NoAction;
|
|
|
|
}
|
|
|
|
|
2019-02-24 14:53:10 +00:00
|
|
|
|
2019-02-23 17:58:04 +00:00
|
|
|
/********************** ADDRESS TABLES ***********************************/
|
2019-02-23 18:52:01 +00:00
|
|
|
action icmp6_answer() {
|
|
|
|
|
|
|
|
if(hdr.icmp6.isValid()) {
|
|
|
|
if(hdr.icmp6.code == ICMP6_ECHO_REQUEST) {
|
|
|
|
ipv6_addr_t tmp = hdr.ipv6.src_addr;
|
|
|
|
hdr.ipv6.src_addr = hdr.ipv6.dst_addr;
|
|
|
|
hdr.ipv6.dst_addr = tmp;
|
|
|
|
hdr.icmp6.code = ICMP6_ECHO_REPLY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-23 17:58:04 +00:00
|
|
|
/* do something:
|
|
|
|
- change src/dst
|
|
|
|
- change type
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
table v6_addresses {
|
|
|
|
key = {
|
|
|
|
hdr.ipv6.dst_addr: exact;
|
2019-02-23 18:52:01 +00:00
|
|
|
// hdr.ipv6.next_header: exact;
|
2019-02-23 17:58:04 +00:00
|
|
|
}
|
|
|
|
actions = {
|
|
|
|
icmp6_answer;
|
2019-02-24 14:53:10 +00:00
|
|
|
send_to_controller;
|
2019-02-23 17:58:04 +00:00
|
|
|
NoAction;
|
|
|
|
}
|
|
|
|
size = ADDRESS_TABLE_SIZE;
|
2019-02-24 14:53:10 +00:00
|
|
|
default_action = send_to_controller;
|
2019-02-23 17:58:04 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-02-23 13:22:46 +00:00
|
|
|
/********************** ROUTING (egress definiton) TABLES ***********************************/
|
|
|
|
action set_egress_port (port_t out_port) {
|
|
|
|
standard_metadata.egress_spec = out_port;
|
|
|
|
}
|
|
|
|
table v6_routing {
|
|
|
|
key = {
|
|
|
|
hdr.ipv6.dst_addr: lpm;
|
|
|
|
}
|
|
|
|
actions = {
|
|
|
|
set_egress_port;
|
|
|
|
NoAction;
|
|
|
|
}
|
|
|
|
size = ROUTING_TABLE_SIZE;
|
|
|
|
default_action = NoAction;
|
|
|
|
}
|
2019-02-21 22:19:17 +00:00
|
|
|
|
2019-02-23 13:22:46 +00:00
|
|
|
table v4_routing {
|
|
|
|
key = {
|
|
|
|
hdr.ipv4.dst_addr: lpm;
|
|
|
|
}
|
|
|
|
actions = {
|
|
|
|
set_egress_port;
|
|
|
|
NoAction;
|
|
|
|
}
|
|
|
|
size = ROUTING_TABLE_SIZE;
|
|
|
|
default_action = NoAction;
|
|
|
|
}
|
|
|
|
|
|
|
|
apply {
|
2019-02-23 13:29:36 +00:00
|
|
|
if(hdr.ipv6.isValid()) {
|
2019-02-26 14:33:37 +00:00
|
|
|
|
|
|
|
ndp.apply(); /* flood or if it is us - answer */
|
2019-02-23 17:59:46 +00:00
|
|
|
v6_addresses.apply();
|
2019-02-23 13:29:36 +00:00
|
|
|
v6_routing.apply();
|
|
|
|
}
|
|
|
|
if(hdr.ipv4.isValid()) {
|
|
|
|
v4_routing.apply();
|
|
|
|
}
|
2019-02-21 22:19:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
**************** E G R E S S P R O C E S S I N G *******************
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
control MyEgress(inout headers hdr,
|
|
|
|
inout metadata meta,
|
|
|
|
inout standard_metadata_t standard_metadata) {
|
|
|
|
apply {
|
|
|
|
/* set tcp header valid after modifying it -- keep this in mind*/
|
|
|
|
// hdr.tcp.setValid();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
*********************** S W I T C H *******************************
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
V1Switch(
|
|
|
|
MyParser(),
|
|
|
|
MyVerifyChecksum(),
|
|
|
|
MyIngress(),
|
|
|
|
MyEgress(),
|
|
|
|
MyComputeChecksum(),
|
|
|
|
MyDeparser()
|
|
|
|
) main;
|