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-28 09:56:22 +00:00
|
|
|
/********************** ACTIONS ***********************************/
|
|
|
|
|
|
|
|
action drop() {
|
|
|
|
mark_to_drop();
|
|
|
|
}
|
|
|
|
|
2019-03-04 13:07:05 +00:00
|
|
|
action set_egress_port (port_t out_port) {
|
|
|
|
standard_metadata.egress_spec = out_port;
|
|
|
|
}
|
|
|
|
|
|
|
|
action controller_debug() {
|
2019-03-04 15:23:28 +00:00
|
|
|
meta.task = TASK_DEBUG;
|
2019-03-04 17:10:24 +00:00
|
|
|
meta.ingress_port = standard_metadata.ingress_port;
|
2019-02-24 14:53:10 +00:00
|
|
|
clone3(CloneType.I2E, 100, meta);
|
|
|
|
}
|
|
|
|
|
2019-03-04 15:23:28 +00:00
|
|
|
action controller_reply(task_t task) {
|
|
|
|
meta.task = task;
|
2019-03-04 17:10:24 +00:00
|
|
|
meta.ingress_port = standard_metadata.ingress_port;
|
2019-03-03 21:36:25 +00:00
|
|
|
clone3(CloneType.I2E, 100, meta);
|
|
|
|
}
|
|
|
|
|
2019-03-04 13:07:05 +00:00
|
|
|
action multicast_pkg(mcast_t mcast_grp) { /* Output PKG on correct ports (plural) */
|
2019-02-26 14:30:47 +00:00
|
|
|
standard_metadata.mcast_grp = mcast_grp;
|
|
|
|
}
|
|
|
|
|
2019-02-28 09:56:22 +00:00
|
|
|
action icmp6_neighbor_solicitation(ipv6_addr_t addr) {
|
|
|
|
/* egress = ingress */
|
|
|
|
standard_metadata.egress_spec = standard_metadata.ingress_port;
|
|
|
|
|
|
|
|
hdr.ipv6.dst_addr = hdr.ipv6.src_addr;
|
|
|
|
hdr.ipv6.src_addr = addr;
|
|
|
|
hdr.icmp6.type = ICMP6_NA;
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************** Reply to NDP for US ***********************************/
|
|
|
|
table ndp_answer {
|
|
|
|
key = {
|
|
|
|
hdr.ipv6.dst_addr: exact; /* our multicast embedded mac address */
|
|
|
|
hdr.icmp6.type: exact;
|
|
|
|
}
|
|
|
|
actions = {
|
2019-03-04 13:07:05 +00:00
|
|
|
controller_debug;
|
2019-02-28 09:57:00 +00:00
|
|
|
icmp6_neighbor_solicitation;
|
2019-02-28 09:56:22 +00:00
|
|
|
NoAction;
|
|
|
|
}
|
|
|
|
size = NDP_TABLE_SIZE;
|
|
|
|
default_action = NoAction;
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************** debugging / general support ***********************************/
|
|
|
|
|
|
|
|
table port2mcast {
|
|
|
|
key = {
|
|
|
|
standard_metadata.ingress_port : exact;
|
|
|
|
}
|
|
|
|
actions = {
|
|
|
|
multicast_pkg;
|
2019-03-04 13:07:05 +00:00
|
|
|
controller_debug;
|
2019-02-28 09:56:22 +00:00
|
|
|
NoAction;
|
|
|
|
}
|
|
|
|
size = NDP_TABLE_SIZE;
|
|
|
|
default_action = NoAction;
|
2019-03-04 13:07:05 +00:00
|
|
|
// default_action = controller_debug;
|
2019-02-28 09:56:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle multicast registration of NDP */
|
|
|
|
table addr2mcast {
|
|
|
|
key = {
|
|
|
|
hdr.ipv6.dst_addr: exact;
|
|
|
|
}
|
|
|
|
actions = {
|
|
|
|
multicast_pkg;
|
2019-03-04 13:07:05 +00:00
|
|
|
controller_debug;
|
2019-02-28 09:56:22 +00:00
|
|
|
NoAction;
|
|
|
|
}
|
|
|
|
size = NDP_TABLE_SIZE;
|
|
|
|
default_action = NoAction;
|
2019-03-04 13:07:05 +00:00
|
|
|
// default_action = controller_debug;
|
2019-02-28 09:56:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************** NDP support ***********************************/
|
|
|
|
|
|
|
|
|
2019-02-26 14:30:47 +00:00
|
|
|
table ndp {
|
|
|
|
key = {
|
|
|
|
hdr.ipv6.dst_addr: lpm;
|
|
|
|
standard_metadata.ingress_port : exact;
|
|
|
|
}
|
|
|
|
actions = {
|
|
|
|
multicast_pkg;
|
2019-03-04 13:07:05 +00:00
|
|
|
controller_debug;
|
2019-02-26 14:30:47 +00:00
|
|
|
NoAction;
|
|
|
|
}
|
|
|
|
size = NDP_TABLE_SIZE;
|
2019-02-26 14:53:48 +00:00
|
|
|
// default_action = NoAction;
|
2019-03-04 13:07:05 +00:00
|
|
|
default_action = controller_debug;
|
2019-02-26 14:30:47 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2019-03-04 13:07:05 +00:00
|
|
|
|
|
|
|
/********************** ROUTING (egress definiton) TABLES ***********************************/
|
|
|
|
|
2019-02-23 17:58:04 +00:00
|
|
|
table v6_addresses {
|
|
|
|
key = {
|
|
|
|
hdr.ipv6.dst_addr: exact;
|
|
|
|
}
|
|
|
|
actions = {
|
2019-03-04 13:07:05 +00:00
|
|
|
controller_debug;
|
2019-03-03 21:37:58 +00:00
|
|
|
controller_reply;
|
2019-02-23 17:58:04 +00:00
|
|
|
NoAction;
|
|
|
|
}
|
|
|
|
size = ADDRESS_TABLE_SIZE;
|
2019-02-26 14:53:48 +00:00
|
|
|
default_action = NoAction;
|
2019-02-23 17:58:04 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-03-04 13:07:05 +00:00
|
|
|
table v6_networks {
|
2019-02-23 13:22:46 +00:00
|
|
|
key = {
|
|
|
|
hdr.ipv6.dst_addr: lpm;
|
|
|
|
}
|
|
|
|
actions = {
|
|
|
|
set_egress_port;
|
2019-03-04 13:10:11 +00:00
|
|
|
controller_debug;
|
|
|
|
controller_reply;
|
2019-02-23 13:22:46 +00:00
|
|
|
NoAction;
|
|
|
|
}
|
|
|
|
size = ROUTING_TABLE_SIZE;
|
|
|
|
default_action = NoAction;
|
|
|
|
}
|
2019-02-21 22:19:17 +00:00
|
|
|
|
2019-03-04 13:07:05 +00:00
|
|
|
|
2019-03-04 15:38:06 +00:00
|
|
|
table v4_networks {
|
2019-02-23 13:22:46 +00:00
|
|
|
key = {
|
|
|
|
hdr.ipv4.dst_addr: lpm;
|
|
|
|
}
|
|
|
|
actions = {
|
|
|
|
set_egress_port;
|
|
|
|
NoAction;
|
|
|
|
}
|
|
|
|
size = ROUTING_TABLE_SIZE;
|
|
|
|
default_action = NoAction;
|
|
|
|
}
|
|
|
|
|
2019-02-28 09:56:22 +00:00
|
|
|
/********************** APPLYING TABLES ***********************************/
|
2019-02-23 13:22:46 +00:00
|
|
|
apply {
|
2019-02-23 13:29:36 +00:00
|
|
|
if(hdr.ipv6.isValid()) {
|
2019-02-26 14:33:37 +00:00
|
|
|
|
2019-02-28 09:56:22 +00:00
|
|
|
/* FIXME: structure / use .hit to do logic */
|
2019-03-04 13:08:09 +00:00
|
|
|
// ndp_answer.apply();
|
2019-02-28 09:56:22 +00:00
|
|
|
|
2019-03-04 13:08:09 +00:00
|
|
|
//ndp.apply(); /* flood or if it is us - answer */
|
2019-02-23 17:59:46 +00:00
|
|
|
v6_addresses.apply();
|
2019-03-04 13:08:09 +00:00
|
|
|
v6_networks.apply();
|
2019-02-23 13:29:36 +00:00
|
|
|
}
|
|
|
|
if(hdr.ipv4.isValid()) {
|
2019-03-04 15:38:45 +00:00
|
|
|
v4_networks.apply();
|
2019-02-23 13:29:36 +00:00
|
|
|
}
|
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 {
|
2019-03-04 13:27:12 +00:00
|
|
|
// ingress clone
|
2019-03-04 15:24:37 +00:00
|
|
|
if (standard_metadata.instance_type == 1){
|
2019-03-04 15:23:28 +00:00
|
|
|
hdr.cpu.setValid();
|
|
|
|
hdr.cpu.task = meta.task;
|
2019-03-04 17:05:56 +00:00
|
|
|
hdr.cpu.ethertype = hdr.ethernet.ethertype;
|
2019-03-04 17:10:24 +00:00
|
|
|
hdr.cpu.ingress_port = (bit<16>)meta.ingress_port;
|
2019-03-04 17:05:56 +00:00
|
|
|
|
|
|
|
hdr.ethernet.ethertype = TYPE_CPU;
|
2019-03-03 21:36:25 +00:00
|
|
|
}
|
2019-02-21 22:19:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
*********************** S W I T C H *******************************
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
V1Switch(
|
|
|
|
MyParser(),
|
|
|
|
MyVerifyChecksum(),
|
|
|
|
MyIngress(),
|
|
|
|
MyEgress(),
|
|
|
|
MyComputeChecksum(),
|
|
|
|
MyDeparser()
|
|
|
|
) main;
|
2019-03-04 13:27:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
// truncate((bit<32>)22); //ether+cpu header
|