[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

@ -2,40 +2,39 @@
#define NICO_DELTA_CHECKSUM
action v4sum() {
bit<16> localsum = 0;
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;
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

@ -14,6 +14,7 @@
/* trigger checksumming */
meta.switch_task = TASK_CHECKSUM_ICMP;
/* FIXME: for delta */
meta.chk_icmp = 1;
hdr.icmp6.setInvalid();
@ -26,6 +27,7 @@
/* 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 */
@ -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.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;
}