From 018e4cc9ffcd689a02672ee7be0953f4453a8d71 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 21 Jul 2019 10:23:49 +0200 Subject: [PATCH] In theory: implement NAT64 from v6 to v4 without externs --- doc/plan.org | 28 +++++++++++++++++++++++++++- p4src/actions_delta_checksum.p4 | 25 ++++++++++++------------- p4src/actions_nat64_generic.p4 | 26 ++++++++++++++------------ 3 files changed, 53 insertions(+), 26 deletions(-) diff --git a/doc/plan.org b/doc/plan.org index 362e56e..e3aa2f7 100644 --- a/doc/plan.org +++ b/doc/plan.org @@ -5632,7 +5632,33 @@ PCAP files to prove it works: create mode 100644 pcap/tcp-udp-delta-2019-07-17-1558-h3.pcap #+END_CENTER -*** +*** TODO 2019-07-21: fix "compilation error" on minip4 / netpfga +#+BEGIN_CENTER +source tcl/export_hardware.tcl +# set design [lindex $argv 0] +# puts "\nOpening $design XPR project\n" + +Opening simple_sume_switch XPR project + +# open_project project/$design.xpr +Scanning sources... +Finished scanning sources +INFO: [IP_Flow 19-234] Refreshing IP repositories +INFO: [IP_Flow 19-1700] Loaded user IP repository '/home/nico/projects/P4-NetFPGA/contrib-projects/sume-sdnet-switch/projects/minip4/simple_sume_switch/hw/ip_repo'. +INFO: [IP_Flow 19-2313] Loaded Vivado IP repository '/opt/Xilinx/Vivado/2018.2/data/ip'. +WARNING: [IP_Flow 19-3664] IP 'bd_7ad4_xpcs_0' generated file not found '/home/nico/projects/P4-NetFPGA/contrib-projects/sume-sdnet-switch/projects/minip4/simple_sume_switch/hw/.Xil/Vivado-10327-nsg-System/coregen/bd_7ad4_xpcs_0_1/elaborate/configure_gt.tcl'. Please regenerate to continue. +WARNING: [IP_Flow 19-3664] IP 'bd_a1aa_xpcs_0' generated file not found '/home/nico/projects/P4-NetFPGA/contrib-projects/sume-sdnet-switch/projects/minip4/simple_sume_switch/hw/.Xil/Vivado-10327-nsg-System/coregen/bd_a1aa_xpcs_0_2/elaborate/configure_gt.tcl'. Please regenerate to continue. +open_project: Time (s): cpu = 00:00:05 ; elapsed = 00:00:05 . Memory (MB): peak = 1365.707 ; gain = 188.977 ; free physical = 10151 ; free virtual = 15581 +# puts "\nOpening $design Implementation design\n" + +Opening simple_sume_switch Implementation design + +# open_run impl_1 +ERROR: [Common 17-69] Command failed: Run 'impl_1' has not been launched. Unable to open +Vivado% +Vivado% +#+END_CENTER +*** TODO 2019-07-21: whether or not to handle icmp(6) checksums ** The NetPFGA saga Problems encountered: - The logfile for a compile run is 10k+ lines diff --git a/p4src/actions_delta_checksum.p4 b/p4src/actions_delta_checksum.p4 index c705e19..0e6fcc7 100644 --- a/p4src/actions_delta_checksum.p4 +++ b/p4src/actions_delta_checksum.p4 @@ -1,8 +1,6 @@ #ifndef NICO_DELTA_CHECKSUM #define NICO_DELTA_CHECKSUM - - #include "headers.p4" action v4sum() { @@ -128,6 +126,10 @@ action delta_ipv4_from_v6_to_v4() { bit<16> tmp = 0; + /* we don't have ANY checksum, but tcp or udp: we can + base on that ones for calculating the diff for IPv4 + + Does NOT contain payload! -> can be done manually */ tmp = tmp + (bit<16>) hdr.ipv4.version; /* 4 bit */ tmp = tmp + (bit<16>) hdr.ipv4.ihl; /* 4 bit */ @@ -136,18 +138,15 @@ action delta_ipv4_from_v6_to_v4() tmp = tmp + (bit<16>) hdr.ipv4.totalLen; /* 16 bit */ tmp = tmp + (bit<16>) hdr.ipv4.identification; /* 16 bit */ tmp = tmp + (bit<16>) hdr.ipv4.flags; /* 3 bit */ - /* we don't have ANY checksum, but tcp or udp: we can - base on that ones for calculating the diff for IPv4 + tmp = tmp + (bit<16>) hdr.ipv4.fragOffset; /* 13 bit */ + tmp = tmp + (bit<16>) hdr.ipv4.ttl; /* 8 bit */ + tmp = tmp + (bit<16>) hdr.ipv4.protocol; /* 8 bit */ + tmp = tmp + (bit<16>) hdr.ipv4.src_addr[15:0]; /* 16 bit */ + tmp = tmp + (bit<16>) hdr.ipv4.src_addr[31:16]; /* 16 bit */ + tmp = tmp + (bit<16>) hdr.ipv4.dst_addr[15:0]; /* 16 bit */ + tmp = tmp + (bit<16>) hdr.ipv4.dst_addr[31:16]; /* 16 bit */ - Does NOT contain payload! -> can be done manually - tmp = tmp + (bit<16>) hdr.ipv4.fragOffset; - tmp = tmp + (bit<16>) hdr.ipv4.ttl, - tmp = tmp + (bit<16>) hdr.ipv4.protocol, - tmp = tmp + (bit<16>) hdr.ipv4.src_addr, - tmp = tmp + (bit<16>) hdr.ipv4.dst_addr - - */ - hdr.ipv4.checksum = 0; /* TO BE DONE! */ + hdr.ipv4.checksum = ~tmp; } diff --git a/p4src/actions_nat64_generic.p4 b/p4src/actions_nat64_generic.p4 index 1a68d51..ef753ed 100644 --- a/p4src/actions_nat64_generic.p4 +++ b/p4src/actions_nat64_generic.p4 @@ -2,6 +2,7 @@ #define NICO_NAT64_GENERIC #include "actions_controller.p4" +#include "actions_delta_checksum.p4" /********************** NAT64 / NAT46 ACTIONS GENERIC ***********************************/ @@ -28,31 +29,32 @@ action nat64_icmp6_generic() 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 */ hdr.ipv4.version = (bit<4>)4; + hdr.ipv4.ihl = (bit<4>)5; // internet header length: 4*5 = 20 + /* 5 is ok as long as + we don't use options / padding / + anything after the destination address */ hdr.ipv4.diff_serv = (bit<6>)0; // no ToS hdr.ipv4.ecn = (bit<2>)0; // unsupported - - /* 5 is ok as long as we don't use options / padding / - anything after the destination address */ - hdr.ipv4.ihl = (bit<4>) 5; // internet header length: 4*5 = 20 hdr.ipv4.totalLen = (bit<16>) hdr.ipv6.payload_length + 20; // ok under above constraints - hdr.ipv4.identification = (bit<16>) 0; // no support for fragments hdr.ipv4.flags = (bit<3>) 0; // DF bit and more fragments hdr.ipv4.fragOffset = (bit<13>) 0; // 0 as there are no fragments + hdr.ipv4.ttl = hdr.ipv6.hop_limit; + hdr.ipv4.protocol = hdr.ipv6.next_header; + hdr.ipv4.src_addr = src; + hdr.ipv4.dst_addr = dst; /* Stuff that should be fine */ hdr.ethernet.ethertype = TYPE_IPV4; - hdr.ipv4.dst_addr = dst; - hdr.ipv4.src_addr = src; - - hdr.ipv4.ttl = hdr.ipv6.hop_limit; - - hdr.ipv4.protocol = hdr.ipv6.next_header; + #ifdef USE_NICO_DELTA_CHECKSUM + delta_ipv4_from_v6_to_v4(); + #else + meta.chk_ipv4 = 1; /* need to calculate the hdrchecksum */ + #endif hdr.ipv6.setInvalid(); }