master-thesis/p4src/headers.p4

242 lines
5.5 KiB
Text
Raw Normal View History

2019-02-21 22:11:02 +00:00
/* -*- P4_16 -*- */
#ifndef HEADERS_P4
#define HEADERS_P4
#include <core.p4>
/**************************************** NetPFGA ****************************************/
/* already defined in sume_switch.p4 */
#ifndef _SUME_SWITCH_P4_
typedef bit<9> port_t;
#endif
2019-03-31 13:48:00 +00:00
/**************************************** types ****************************************/
2019-02-21 22:11:02 +00:00
typedef bit<48> mac_addr_t;
typedef bit<32> ipv4_addr_t;
typedef bit<128> ipv6_addr_t;
typedef bit<16> mcast_t;
2019-03-04 17:19:01 +00:00
typedef bit<16> task_t;
2019-03-25 13:03:04 +00:00
typedef bit<16> table_t; /* to map debug messages - 16 bit to match shortenumfield */
2019-03-31 13:48:00 +00:00
/**************************************** constants ****************************************/
2019-03-25 13:04:11 +00:00
const bit<16> TABLE_NAT64 = 1;
const bit<16> TABLE_ICMP6 = 2;
const bit<16> TABLE_V6_NETWORKS = 3;
const bit<16> TABLE_NAT46 = 4;
const bit<16> TABLE_V4_NETWORKS = 5;
2019-03-31 13:48:00 +00:00
const bit<16> TABLE_ARP = 6;
2019-04-02 15:13:05 +00:00
const bit<16> TABLE_ARP_EGRESS = 7;
2019-04-03 08:52:25 +00:00
const bit<16> TABLE_ICMP = 8;
const bit<16> TABLE_NAT64_TCP = 9;
const bit<16> TABLE_NAT64_UDP = 10;
const bit<16> TABLE_NAT64_ICMP6 = 11;
const bit<16> TABLE_NAT64_SESSION = 12;
2019-02-21 22:11:02 +00:00
const bit<16> TYPE_IPV4 = 0x0800;
const bit<16> TYPE_IPV6 = 0x86DD;
const bit<16> TYPE_CPU = 0x4242;
const bit<16> TYPE_DEBUG = 0x2323;
2019-03-31 14:37:21 +00:00
const bit<16> TYPE_ARP = 0x0806;
2019-02-21 22:48:04 +00:00
const bit<8> PROTO_ICMP = 1;
const bit<8> PROTO_TCP = 6;
const bit<8> PROTO_UDP = 17;
const bit<8> PROTO_ICMP6 = 58;
const bit<8> TCP_SEQ_LEN = 4;
2019-02-21 22:11:02 +00:00
const bit<8> ICMP6_ECHO_REQUEST = 128;
const bit<8> ICMP6_ECHO_REPLY = 129;
2019-02-28 09:56:22 +00:00
const bit<8> ICMP6_NS = 135;
const bit<8> ICMP6_NA = 136;
2019-03-27 17:01:11 +00:00
const bit<8> ICMP_ECHO_REPLY = 0;
const bit<8> ICMP_ECHO_REQUEST = 8;
2019-03-31 13:48:00 +00:00
const bit<16> ARP_REQUEST = 1;
const bit<16> ARP_REPLY = 2;
2019-03-27 17:01:11 +00:00
/* RFC4861, Section 4.6 */
const bit<8> ICMP6_NDP_OPT_SOURCE_LL = 1;
const bit<8> ICMP6_NDP_OPT_TARGET_LL = 2;
const bit<8> ICMP6_NDP_OPT_PREFIX_INFO = 3;
const bit<8> ICMP6_NDP_OPT_REDIR_HEADER = 4;
const bit<8> ICMP6_NDP_OPT_MTU = 5;
/* Tasks from switch to controller - no RFC, internal */
2019-03-04 17:54:00 +00:00
const task_t TASK_ICMP6_NS = 1;
const task_t TASK_ICMP6_GENERAL = 2;
const task_t TASK_DEBUG = 3;
2019-03-05 21:31:05 +00:00
const task_t TASK_ICMP6_REPLY = 4;
2019-03-23 13:39:56 +00:00
const task_t TASK_CHECKSUM_ICMP6 = 5; /* data plane */
const task_t TASK_CHECKSUM_ICMP6_NA = 6; /* data plane */
2019-03-27 17:01:11 +00:00
const task_t TASK_CHECKSUM_ICMP = 7; /* data plane */
const task_t TASK_NAT64_TCP_SESSION = 8; /* control plane */
2019-03-23 13:39:56 +00:00
2019-03-31 13:48:00 +00:00
/**************************************** header ****************************************/
2019-03-23 12:33:25 +00:00
/* 48+48+16 = 112 */
2019-02-21 22:11:02 +00:00
header ethernet_t {
mac_addr_t dst_addr;
mac_addr_t src_addr;
bit<16> ethertype;
}
header ipv4_t {
bit<4> version;
bit<4> ihl;
bit<6> diff_serv;
bit<2> ecn;
bit<16> totalLen;
bit<16> identification;
bit<3> flags;
bit<13> fragOffset;
bit<8> ttl;
bit<8> protocol;
2019-07-16 10:06:26 +00:00
bit<16> checksum;
2019-02-21 22:11:02 +00:00
ipv4_addr_t src_addr;
ipv4_addr_t dst_addr;
}
2019-03-23 12:33:25 +00:00
/*
https://en.wikipedia.org/wiki/IPv6_packet
64 + 256 = 320
*/
2019-02-21 22:11:02 +00:00
header ipv6_t {
bit<4> version;
bit<8> traffic_class;
bit<20> flow_label;
bit<16> payload_length;
bit<8> next_header;
bit<8> hop_limit;
ipv6_addr_t src_addr;
ipv6_addr_t dst_addr;
}
header tcp_t{
bit<16> src_port;
bit<16> dst_port;
int<32> seqNo;
int<32> ackNo;
bit<4> data_offset;
bit<4> res;
bit<1> cwr;
bit<1> ece;
bit<1> urg;
bit<1> ack;
bit<1> psh;
bit<1> rst;
bit<1> syn;
bit<1> fin;
bit<16> window;
bit<16> checksum;
bit<16> urgentPtr;
}
2019-02-21 23:01:53 +00:00
header udp_t {
bit<16> src_port;
bit<16> dst_port;
bit<16> payload_length;
bit<16> checksum;
}
header icmp6_t {
bit<8> type;
bit<8> code;
bit<16> checksum;
}
2019-03-23 12:33:25 +00:00
/*
https://tools.ietf.org/html/rfc4861#section-4.4
*/
header icmp6_na_ns_t {
bit<1> router;
bit<1> solicitated;
bit<1> override;
bit<29> reserved;
ipv6_addr_t target_addr;
}
header icmp6_option_link_layer_addr_t {
bit<8> type;
bit<8> ll_length;
mac_addr_t mac_addr;
}
2019-02-21 23:01:53 +00:00
header icmp_t {
bit<8> type;
bit<8> code;
bit<16> checksum;
}
2019-03-31 13:48:00 +00:00
header arp_t {
bit<16> hw_type;
bit<16> protocol;
bit<8> hw_size;
bit<8> protocol_size;
bit<16> opcode;
mac_addr_t src_mac_addr;
ipv4_addr_t src_ipv4_addr;
mac_addr_t dst_mac_addr;
ipv4_addr_t dst_ipv4_addr;
}
2019-03-23 12:33:25 +00:00
header cpu_t {
task_t task;
2019-03-04 17:13:34 +00:00
bit<16> ingress_port;
2019-03-04 17:05:56 +00:00
bit<16> ethertype;
table_t table_id;
}
2019-02-21 23:01:53 +00:00
2019-03-31 13:48:00 +00:00
/**************************************** struct ****************************************/
2019-02-21 22:11:02 +00:00
struct headers {
ethernet_t ethernet;
ipv4_t ipv4;
ipv6_t ipv6;
tcp_t tcp;
2019-02-21 23:01:53 +00:00
udp_t udp;
icmp_t icmp;
cpu_t cpu;
2019-03-23 12:33:25 +00:00
icmp6_t icmp6;
icmp6_na_ns_t icmp6_na_ns;
icmp6_option_link_layer_addr_t icmp6_option_link_layer_addr;
2019-03-31 13:50:07 +00:00
arp_t arp;
2019-02-21 22:11:02 +00:00
}
2019-03-31 13:48:00 +00:00
2019-02-21 22:25:27 +00:00
struct metadata {
2019-03-04 17:05:56 +00:00
port_t ingress_port;
task_t task;
task_t switch_task;
/* migrate tasks to bool */
2019-03-30 16:01:04 +00:00
bit<1> chk_icmp6_na_ns;
bit<1> chk_icmp6;
bit<1> chk_icmp;
bit<1> chk_ipv4;
bit<1> chk_udp_v4;
bit<1> chk_udp_v6;
bit<1> chk_tcp_v4;
bit<1> chk_tcp_v6;
bit<16> length_without_ip_header;
bit<32> cast_length;
/* for delta checksums */
bit<16> v4sum;
bit<16> v6sum;
bit<16> headerdiff;
table_t table_id;
2019-02-21 22:25:27 +00:00
}
2019-02-21 22:11:02 +00:00
#endif