From 1a39c35e3bf286008c73e019cea3a65f6fb352b2 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 16 Jul 2019 11:53:00 +0200 Subject: [PATCH] Check how wrapping is done in P4 --- doc/plan.org | 34 ++++++++++++++++++++++ p4app/wraptest.json | 48 +++++++++++++++++++++++++++++++ p4src/actions_delta_checksum.p4 | 2 +- p4src/wraptest.p4 | 50 +++++++++++++++++++++++++++++++++ 4 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 p4app/wraptest.json create mode 100644 p4src/wraptest.p4 diff --git a/doc/plan.org b/doc/plan.org index b1b2588..a0f05b2 100644 --- a/doc/plan.org +++ b/doc/plan.org @@ -5274,6 +5274,40 @@ Still using scapy + adjusted diff: gets sum 0xc5f2 (incorrect -> 0xe7cf) +*** 2019-07-16: pcap for debugging tcp + pcap/tcp-udp-delta-2019-07-15-1454-h3.pcap + pcap/tcp-udp-delta-2019-07-15-1454-h1.pcap +*** 2019-07-16: pcap for debugging udp + pcap/tcp-udp-delta-2019-07-16-0856-h3.pcap + pcap/tcp-udp-delta-2019-07-16-0856-h1.pcap +*** 2019-07-16: testing with udp + - suspicion: missing some cases in tcp6 + +#+BEGIN_CENTER +p4@ubuntu:~$ mx h1 "echo V6-OK | socat - UDP6-LISTEN:2342" +p4@ubuntu:~/master-thesis/bin$ mx h3 "echo V4-OK | socat - UDP:10.1.1.1:2342" +#+END_CENTER + +08:57:19.998299 IP6 (hlim 64, next-header UDP (17) payload length: 14) +2001:db8:1::a00:1.59997 > 2001:db8::1.2342: [bad udp cksum 0xd84c -> +0xd84b!] UDP, length 6 + +**** DONE Result: arp (partly?) missing? + CLOSED: [2019-07-16 Tue 11:00] + +**** TODO Result: udp checksum wrong + - should be: 0xd84b + - is: 0xd84c + +My code is +1 too high + +*** DONE 2019-07-16: understood scapy code + CLOSED: [2019-07-16 Tue 11:25] +meta.v6sum = (bit<16>) ((((tmp>>8) & 0xff)|tmp<<8) & 0xffff) ; + +This is used to correct endianness! + +-> not needed in our case ** The NetPFGA saga Problems encountered: diff --git a/p4app/wraptest.json b/p4app/wraptest.json new file mode 100644 index 0000000..1e1ef16 --- /dev/null +++ b/p4app/wraptest.json @@ -0,0 +1,48 @@ +{ + "program": "../p4src/wraptest.p4", + "switch": "simple_switch", + "compiler": "p4c", + "options": "--target bmv2 --arch v1model --std p4-16", + "switch_cli": "simple_switch_CLI", + "cli": true, + "pcap_dump": true, + "enable_log": true, + "topo_module": { + "file_path": "", + "module_name": "p4utils.mininetlib.apptopo", + "object_name": "AppTopoStrategies" + }, + "controller_module": null, + "topodb_module": { + "file_path": "", + "module_name": "p4utils.utils.topology", + "object_name": "Topology" + }, + "mininet_module": { + "file_path": "", + "module_name": "p4utils.mininetlib.p4net", + "object_name": "P4Mininet" + }, + "topology": { + "assignment_strategy": "l2", + "auto_arp_tables": false, + "links": [["h1", "s1"], ["h2", "s1"], ["h3", "s1"], ["h4","s1"]], + "hosts": { + "h1": { + }, + "h2": { + } + , + "h3": { + } + , + "h4": { + } + }, + "switches": { + "s1": { + "cpu_port" : true + } + } + } +} diff --git a/p4src/actions_delta_checksum.p4 b/p4src/actions_delta_checksum.p4 index 0a48541..0697360 100644 --- a/p4src/actions_delta_checksum.p4 +++ b/p4src/actions_delta_checksum.p4 @@ -52,7 +52,7 @@ action v6sum() { tmp = (tmp >> 16) + (tmp & 0xffff); // tmp = tmp + (tmp >> 16); tmp = ~tmp; -// meta.v6sum = (bit<16>) ((((tmp>>8) & 0xff)|tmp<<8) & 0xffff) ; + meta.v6sum = (bit<16>) tmp; } diff --git a/p4src/wraptest.p4 b/p4src/wraptest.p4 new file mode 100644 index 0000000..3508cef --- /dev/null +++ b/p4src/wraptest.p4 @@ -0,0 +1,50 @@ +/* -*- P4_16 -*- */ +#include +#include + +#include "headers.p4" +#include "parsers.p4" + +control MyIngress(inout headers hdr, + inout metadata meta, + inout standard_metadata_t standard_metadata) { + + /********************** APPLYING TABLES ***********************************/ + apply { + if(hdr.tcp.isValid()) { + /* test wrap around */ + hdr.tcp.checksum = 0xffff; + hdr.tcp.checksum = checksum + 2; + } + standard_metadata.egress_spec = 1; + } +} + +control MyEgress(inout headers hdr, + inout metadata meta, + inout standard_metadata_t standard_metadata) { + apply { + } +} + +control MyVerifyChecksum(inout headers hdr, inout metadata meta) { + apply {} +} + + +control MyComputeChecksum(inout headers hdr, inout metadata meta) { + apply {} +} + +/************************************************************************* +*********************** S W I T C H ******************************* +*************************************************************************/ + +V1Switch( + MyParser(), + MyVerifyChecksum(), + MyIngress(), + MyEgress(), + MyComputeChecksum(), + MyDeparser() +) main; \ No newline at end of file