2019-02-21 22:09:03 +00:00
|
|
|
/* -*- P4_16 -*- */
|
|
|
|
#ifndef PARSERS_P4
|
|
|
|
#define PARSERS_P4
|
|
|
|
|
|
|
|
#include <core.p4>
|
|
|
|
#include <v1model.p4>
|
|
|
|
|
|
|
|
#include "headers.p4"
|
|
|
|
|
|
|
|
parser MyParser(packet_in packet,
|
2019-03-23 13:30:20 +00:00
|
|
|
out headers hdr,
|
|
|
|
inout metadata meta,
|
|
|
|
inout standard_metadata_t standard_metadata) {
|
2019-02-21 22:09:03 +00:00
|
|
|
|
|
|
|
state start {
|
2019-03-30 13:59:46 +00:00
|
|
|
|
2019-03-30 16:02:18 +00:00
|
|
|
meta.chk_icmp = 0;
|
|
|
|
meta.chk_icmp6 = 0;
|
2019-03-30 16:01:04 +00:00
|
|
|
meta.chk_icmp6_na_ns = 0;
|
2019-04-11 08:08:11 +00:00
|
|
|
meta.chk_ipv4 = 0;
|
|
|
|
meta.chk_udp_v6 = 0;
|
2019-04-11 08:13:54 +00:00
|
|
|
meta.chk_udp_v4 = 0;
|
|
|
|
meta.chk_tcp_v6 = 0;
|
|
|
|
meta.chk_tcp_v4 = 0;
|
2019-03-30 13:59:46 +00:00
|
|
|
|
2019-02-21 22:09:03 +00:00
|
|
|
packet.extract(hdr.ethernet);
|
|
|
|
transition select(hdr.ethernet.ethertype){
|
|
|
|
TYPE_IPV4: ipv4;
|
|
|
|
TYPE_IPV6: ipv6;
|
2019-03-31 14:37:21 +00:00
|
|
|
TYPE_ARP: arp;
|
2019-03-23 13:30:20 +00:00
|
|
|
|
2019-02-21 22:09:03 +00:00
|
|
|
default: accept;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
state ipv4 {
|
|
|
|
packet.extract(hdr.ipv4);
|
2019-04-11 08:08:11 +00:00
|
|
|
meta.length_without_ip_header = hdr.ipv4.totalLen - 16w20;
|
2019-02-21 22:09:03 +00:00
|
|
|
|
|
|
|
transition select(hdr.ipv4.protocol){
|
2019-02-21 23:01:53 +00:00
|
|
|
PROTO_TCP: tcp;
|
|
|
|
PROTO_UDP: udp;
|
|
|
|
PROTO_ICMP: icmp;
|
|
|
|
|
2019-02-21 22:09:03 +00:00
|
|
|
default: accept;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
state ipv6 {
|
|
|
|
packet.extract(hdr.ipv6);
|
2019-04-11 08:08:11 +00:00
|
|
|
meta.length_without_ip_header = hdr.ipv6.payload_length;
|
2019-02-21 22:09:03 +00:00
|
|
|
|
|
|
|
transition select(hdr.ipv6.next_header){
|
2019-02-21 23:01:53 +00:00
|
|
|
PROTO_TCP: tcp;
|
|
|
|
PROTO_UDP: udp;
|
|
|
|
PROTO_ICMP6: icmp6;
|
2019-02-21 22:09:03 +00:00
|
|
|
default: accept;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-21 19:48:56 +00:00
|
|
|
state icmp6 {
|
|
|
|
packet.extract(hdr.icmp6);
|
2019-03-23 13:30:20 +00:00
|
|
|
transition select(hdr.icmp6.type) {
|
2019-03-23 12:33:25 +00:00
|
|
|
ICMP6_NS: icmp6_neighbor_solicitation;
|
2019-03-21 19:48:56 +00:00
|
|
|
default: accept;
|
|
|
|
}
|
|
|
|
}
|
2019-03-23 12:33:25 +00:00
|
|
|
|
2019-03-21 19:48:56 +00:00
|
|
|
state icmp6_neighbor_solicitation {
|
2019-03-23 13:15:31 +00:00
|
|
|
packet.extract(hdr.icmp6_na_ns);
|
|
|
|
|
|
|
|
/* BUG: This MIGHT fail */
|
|
|
|
packet.extract(hdr.icmp6_option_link_layer_addr);
|
2019-03-23 12:33:25 +00:00
|
|
|
|
2019-03-23 13:15:31 +00:00
|
|
|
transition accept;
|
2019-03-23 12:33:25 +00:00
|
|
|
}
|
2019-03-21 19:48:56 +00:00
|
|
|
|
|
|
|
|
2019-02-21 23:01:53 +00:00
|
|
|
/* Leaf */
|
2019-02-21 22:09:03 +00:00
|
|
|
state tcp {
|
2019-03-23 13:30:20 +00:00
|
|
|
packet.extract(hdr.tcp);
|
|
|
|
transition accept;
|
2019-02-21 22:09:03 +00:00
|
|
|
}
|
|
|
|
|
2019-02-21 23:01:53 +00:00
|
|
|
state udp {
|
2019-03-23 13:30:20 +00:00
|
|
|
packet.extract(hdr.udp);
|
|
|
|
transition accept;
|
2019-02-21 23:01:53 +00:00
|
|
|
}
|
|
|
|
|
2019-03-23 12:33:25 +00:00
|
|
|
// state icmp6 {
|
2019-03-23 13:30:20 +00:00
|
|
|
// packet.extract(hdr.icmp6);
|
|
|
|
// transition accept;
|
|
|
|
// }
|
2019-02-21 23:01:53 +00:00
|
|
|
|
|
|
|
state icmp {
|
2019-03-23 13:30:20 +00:00
|
|
|
packet.extract(hdr.icmp);
|
|
|
|
transition accept;
|
2019-02-21 23:01:53 +00:00
|
|
|
}
|
|
|
|
|
2019-03-31 14:37:21 +00:00
|
|
|
state arp {
|
|
|
|
packet.extract(hdr.arp);
|
|
|
|
transition accept;
|
|
|
|
}
|
|
|
|
|
2019-02-21 22:09:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
************************ D E P A R S E R *******************************
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
control MyDeparser(packet_out packet, in headers hdr) {
|
|
|
|
apply {
|
2019-03-04 15:23:28 +00:00
|
|
|
/* always */
|
2019-02-21 22:09:03 +00:00
|
|
|
packet.emit(hdr.ethernet);
|
|
|
|
|
2019-03-04 15:38:06 +00:00
|
|
|
/* only if information is sent to the controller */
|
|
|
|
packet.emit(hdr.cpu);
|
|
|
|
|
2019-02-21 22:09:03 +00:00
|
|
|
/* either */
|
|
|
|
packet.emit(hdr.ipv4);
|
|
|
|
packet.emit(hdr.ipv6);
|
2019-04-02 15:16:17 +00:00
|
|
|
packet.emit(hdr.arp);
|
2019-02-21 22:09:03 +00:00
|
|
|
|
|
|
|
/* either */
|
|
|
|
packet.emit(hdr.tcp);
|
2019-02-23 20:15:10 +00:00
|
|
|
packet.emit(hdr.udp);
|
|
|
|
packet.emit(hdr.icmp);
|
2019-03-23 12:33:25 +00:00
|
|
|
|
|
|
|
/* might be more than one subtype */
|
2019-02-23 20:15:47 +00:00
|
|
|
packet.emit(hdr.icmp6);
|
2019-03-23 13:20:11 +00:00
|
|
|
packet.emit(hdr.icmp6_na_ns);
|
|
|
|
packet.emit(hdr.icmp6_option_link_layer_addr);
|
2019-02-21 22:09:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|