[delta checksum] in theory finish for v4-udp => v6-udp

This commit is contained in:
Nico Schottelius 2019-07-10 13:38:59 +02:00
parent 2839b8e4b2
commit ae8ce224fc
4 changed files with 111 additions and 98 deletions

View file

@ -1,41 +1,40 @@
#ifndef NICO_DELTA_CHECKSUM
#define NICO_DELTA_CHECKSUM
action v4sum() {
bit<16> localsum = 0;
action v4sum() {
hdr.meta.v4sum = 0;
localsum = localsum + hdr.ipv4.src_addr[15:0]; // 16 bit
localsum = localsum + hdr.ipv4.src_addr[31:16]; // 16 bit
localsum = localsum + hdr.ipv4.dst_addr[15:0]; // 16 bit
localsum = localsum + hdr.ipv4.dst_addr[31:16]; // 16 bit
hdr.meta.v4sum = hdr.meta.v4sum + hdr.ipv4.src_addr[15:0]; // 16 bit
hdr.meta.v4sum = hdr.meta.v4sum + hdr.ipv4.src_addr[31:16]; // 16 bit
hdr.meta.v4sum = hdr.meta.v4sum + hdr.ipv4.dst_addr[15:0]; // 16 bit
hdr.meta.v4sum = hdr.meta.v4sum + hdr.ipv4.dst_addr[31:16]; // 16 bit
localsum = localsum + hdr.ipv4.totalLen -20; // 16 bit
localsum = localsum + (bit<16>) hdr.ipv4.protocol; // 8 bit
}
hdr.meta.v4sum = hdr.meta.v4sum + hdr.ipv4.totalLen -20; // 16 bit
hdr.meta.v4sum = hdr.meta.v4sum + (bit<16>) hdr.ipv4.protocol; // 8 bit
}
action v6sum() {
bit<16> localsum = 0;
action v6sum() {
hdr.meta.v6sum = 0;
hdr.meta.v6sum = hdr.meta.v6sum + hdr.ipv6.src_addr[15:0]; // 16 bit
hdr.meta.v6sum = hdr.meta.v6sum + hdr.ipv6.src_addr[31:16]; // 16 bit
hdr.meta.v6sum = hdr.meta.v6sum + hdr.ipv6.src_addr[47:32]; // 16 bit
hdr.meta.v6sum = hdr.meta.v6sum + hdr.ipv6.src_addr[63:48]; // 16 bit
hdr.meta.v6sum = hdr.meta.v6sum + hdr.ipv6.src_addr[79:64]; // 16 bit
hdr.meta.v6sum = hdr.meta.v6sum + hdr.ipv6.src_addr[95:80]; // 16 bit
hdr.meta.v6sum = hdr.meta.v6sum + hdr.ipv6.src_addr[111:96]; // 16 bit
hdr.meta.v6sum = hdr.meta.v6sum + hdr.ipv6.src_addr[127:112]; // 16 bit
localsum = localsum + hdr.ipv6.src_addr[15:0]; // 16 bit
localsum = localsum + hdr.ipv6.src_addr[31:16]; // 16 bit
localsum = localsum + hdr.ipv6.src_addr[47:32]; // 16 bit
localsum = localsum + hdr.ipv6.src_addr[63:48]; // 16 bit
localsum = localsum + hdr.ipv6.src_addr[79:64]; // 16 bit
localsum = localsum + hdr.ipv6.src_addr[95:80]; // 16 bit
localsum = localsum + hdr.ipv6.src_addr[111:96]; // 16 bit
localsum = localsum + hdr.ipv6.src_addr[127:112]; // 16 bit
hdr.meta.v6sum = hdr.meta.v6sum + hdr.ipv6.dst_addr[15:0]; // 16 bit
hdr.meta.v6sum = hdr.meta.v6sum + hdr.ipv6.dst_addr[31:16]; // 16 bit
hdr.meta.v6sum = hdr.meta.v6sum + hdr.ipv6.dst_addr[47:32]; // 16 bit
hdr.meta.v6sum = hdr.meta.v6sum + hdr.ipv6.dst_addr[63:48]; // 16 bit
hdr.meta.v6sum = hdr.meta.v6sum + hdr.ipv6.dst_addr[79:64]; // 16 bit
hdr.meta.v6sum = hdr.meta.v6sum + hdr.ipv6.dst_addr[95:80]; // 16 bit
hdr.meta.v6sum = hdr.meta.v6sum + hdr.ipv6.dst_addr[111:96]; // 16 bit
hdr.meta.v6sum = hdr.meta.v6sum + hdr.ipv6.dst_addr[127:112]; // 16 bit
localsum = localsum + hdr.ipv6.dst_addr[15:0]; // 16 bit
localsum = localsum + hdr.ipv6.dst_addr[31:16]; // 16 bit
localsum = localsum + hdr.ipv6.dst_addr[47:32]; // 16 bit
localsum = localsum + hdr.ipv6.dst_addr[63:48]; // 16 bit
localsum = localsum + hdr.ipv6.dst_addr[79:64]; // 16 bit
localsum = localsum + hdr.ipv6.dst_addr[95:80]; // 16 bit
localsum = localsum + hdr.ipv6.dst_addr[111:96]; // 16 bit
localsum = localsum + hdr.ipv6.dst_addr[127:112]; // 16 bit
localsum = localsum + hdr.ipv6.payload_length; // 16 bit
localsum = localsum + (bit<16>) hdr.ipv6.next_header; // 8 bit
}
hdr.meta.v6sum = hdr.meta.v6sum + hdr.ipv6.payload_length; // 16 bit
hdr.meta.v6sum = hdr.meta.v6sum + (bit<16>) hdr.ipv6.next_header; // 8 bit
}
#endif

View file

@ -5,15 +5,16 @@
/********************** NAT64 / NAT46 ACTIONS GENERIC ***********************************/
/* changes for icmp6 -> icmp */
action nat64_icmp6_generic()
{
/* changes for icmp6 -> icmp */
action nat64_icmp6_generic()
{
hdr.icmp.setValid();
hdr.ipv4.protocol = PROTO_ICMP; // overwrite generic same protocol assumption
/* trigger checksumming */
meta.switch_task = TASK_CHECKSUM_ICMP;
/* FIXME: for delta */
meta.chk_icmp = 1;
hdr.icmp6.setInvalid();
@ -21,11 +22,12 @@
/* not needed, as we don't translate them (yet/ever) */
hdr.icmp6_na_ns.setInvalid();
hdr.icmp6_option_link_layer_addr.setInvalid();
}
}
/* NAT64 protocol unspecific changes */
action nat64_generic(ipv4_addr_t src, ipv4_addr_t dst) {
/* NAT64 protocol unspecific changes */
action nat64_generic(ipv4_addr_t src, ipv4_addr_t dst) {
hdr.ipv4.setValid();
meta.chk_ipv4 = 1; /* need to calculate the hdrchecksum */
/* Stuff that might need to be fixed */
@ -53,19 +55,19 @@
hdr.ipv4.protocol = hdr.ipv6.next_header;
hdr.ipv6.setInvalid();
}
}
/* nat64_prefix is the same as the matching key, but without the mask */
action nat64_static(ipv6_addr_t v6_src, ipv4_addr_t v4_dst, ipv6_addr_t nat64_prefix) {
/* nat64_prefix is the same as the matching key, but without the mask */
action nat64_static(ipv6_addr_t v6_src, ipv4_addr_t v4_dst, ipv6_addr_t nat64_prefix) {
ipv6_addr_t src_offset = hdr.ipv6.src_addr - v6_src;
ipv4_addr_t src = v4_dst + (ipv4_addr_t) src_offset;
ipv4_addr_t dst = (ipv4_addr_t) (hdr.ipv6.dst_addr - nat64_prefix);
nat64_generic(src, dst);
}
}
/* From https://tools.ietf.org/html/rfc792 (IPv4)
/* From https://tools.ietf.org/html/rfc792 (IPv4)
Echo or Echo Reply Message
@ -112,9 +114,9 @@ Echo or Echo Reply Message
*/
/* changes for icmp6 -> icmp */
action nat46_icmp_generic()
{
/* changes for icmp6 -> icmp */
action nat46_icmp_generic()
{
hdr.icmp6.setValid();
hdr.ipv6.next_header = PROTO_ICMP6;
@ -122,7 +124,7 @@ Echo or Echo Reply Message
meta.cast_length = (bit<32>) hdr.ipv6.payload_length;
hdr.icmp.setInvalid();
}
}
/* NAT46: protocol unspecific changes */
action nat46_generic(ipv6_addr_t src, ipv6_addr_t dst) {
@ -133,15 +135,12 @@ Echo or Echo Reply Message
hdr.ipv6.dst_addr = dst;
hdr.ipv6.src_addr = src;
hdr.ipv6.version = (bit<4>)6;
hdr.ipv6.version = (bit<4>) 6;
hdr.ipv6.traffic_class = (bit<8>) hdr.ipv4.diff_serv;
hdr.ipv6.flow_label = (bit<20>) 0;
hdr.ipv6.payload_length = (bit<16>) hdr.ipv4.totalLen - 20;
hdr.ipv6.next_header = hdr.ipv4.protocol;
hdr.ipv6.hop_limit = hdr.ipv4.ttl;
}

View file

@ -22,6 +22,8 @@ parser MyParser(packet_in packet,
meta.chk_udp_v4 = 0;
meta.chk_tcp_v6 = 0;
meta.chk_tcp_v4 = 0;
meta.v4sum = 0;
meta.v6sum = 0;
packet.extract(hdr.ethernet);
transition select(hdr.ethernet.ethertype){
@ -141,9 +143,9 @@ control MyIngress(inout headers hdr,
#include "actions_egress.p4"
#include "actions_icmp6_ndp_icmp.p4"
#include "actions_arp.p4"
#include "actions_delta_checksum.p4" /* only used if enabled at compile time */
/********************** APPLYING TABLES ***********************************/
/********************** APPLYING TABLES / MAIN LOGIC **************************/
apply {
if(hdr.ipv6.isValid()) {
if(nat64.apply().hit) { /* generic / static nat64 done */
@ -189,7 +191,15 @@ control MyIngress(inout headers hdr,
}
}
if(hdr.udp.isValid()) {
#ifdef NICO_DELTA_CHECKSUM
v4sum();
v6sum();
bit<16> diff = hdr.meta.v6sum - hdr.meta.v4sum;
hdr.udp.checksum = hdr.udp.checksum + diff;
#else
meta.chk_udp_v6 = 1;
#endif
}
if(hdr.tcp.isValid()) {
meta.chk_tcp_v6 = 1;

View file

@ -230,6 +230,11 @@ struct metadata {
bit<16> length_without_ip_header;
bit<32> cast_length;
/* for delta checksums */
bit<16> v4sum;
bit<16> v6sum;
table_t table_id;
}