From 51bf8b9acea362518c17661db9e0d5a8862b4fad Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 15 Jul 2019 14:18:35 +0200 Subject: [PATCH] netfpga: update test packet generator; checksum: implement carry over --- netpfga/minip4/testdata/gen_testdata-port1.py | 36 ---------- p4src/actions_delta_checksum.p4 | 69 ++++++++++++------- 2 files changed, 43 insertions(+), 62 deletions(-) diff --git a/netpfga/minip4/testdata/gen_testdata-port1.py b/netpfga/minip4/testdata/gen_testdata-port1.py index 5dc8548..99cca0d 100755 --- a/netpfga/minip4/testdata/gen_testdata-port1.py +++ b/netpfga/minip4/testdata/gen_testdata-port1.py @@ -115,42 +115,6 @@ def test_port1(): pktCnt += 1 -# Test that packets are being mirrored -def test_mirror(): - pktCnt = 0 - - # First ethernet - pktCnt += 1 - pkt = Ether(dst=MAC2, src=MAC1) - pkt = pad_pkt(pkt, 64) - applyPkt(pkt, 'nf0', pktCnt) - - pktCnt += 1 - pkt = Ether(dst=MAC1, src=MAC2) - pkt = pad_pkt(pkt, 64) - expPkt(pkt, 'nf0') - - # # Second IP - # pktCnt += 1 - # pkt = Ether(dst=MAC2, src=MAC1) / IPv6(src="fe80::1", dst="fe80::2") - # pkt = pad_pkt(pkt, 64) - # applyPkt(pkt, 'nf0', pktCnt) - # pktCnt += 1 - # pkt = Ether(dst=MAC1, src=MAC2) / IPv6(src="fe80::2", dst="fe80::1") - # pkt = pad_pkt(pkt, 64) - # expPkt(pkt, 'nf0') - - # # Third tcp - # pktCnt += 1 - # pkt = Ether(dst=MAC2, src=MAC1) / IPv6(src="fe80::1", dst="fe80::2") / TCP(sport=42, dport=23) - # pkt = pad_pkt(pkt, 64) - # applyPkt(pkt, 'nf0', pktCnt) - # pktCnt += 1 - # pkt = Ether(dst=MAC1, src=MAC2) / IPv6(src="fe80::2", dst="fe80::1") / TCP(sport=23, dport=42) - # pkt = pad_pkt(pkt, 64) - # expPkt(pkt, 'nf0') - -#test_mirror() test_port1() write_pcap_files() diff --git a/p4src/actions_delta_checksum.p4 b/p4src/actions_delta_checksum.p4 index 0a1b9de..ad7eb44 100644 --- a/p4src/actions_delta_checksum.p4 +++ b/p4src/actions_delta_checksum.p4 @@ -2,39 +2,56 @@ #define NICO_DELTA_CHECKSUM action v4sum() { - meta.v4sum = 0; + bit<32> tmp = 0; + bit<32> carryover = 0; - meta.v4sum = meta.v4sum + hdr.ipv4.src_addr[15:0]; // 16 bit - meta.v4sum = meta.v4sum + hdr.ipv4.src_addr[31:16]; // 16 bit - meta.v4sum = meta.v4sum + hdr.ipv4.dst_addr[15:0]; // 16 bit - meta.v4sum = meta.v4sum + hdr.ipv4.dst_addr[31:16]; // 16 bit + tmp = tmp + (bit<32>) hdr.ipv4.src_addr[15:0]; // 16 bit + tmp = tmp + (bit<32>) hdr.ipv4.src_addr[31:16]; // 16 bit + tmp = tmp + (bit<32>) hdr.ipv4.dst_addr[15:0]; // 16 bit + tmp = tmp + (bit<32>) hdr.ipv4.dst_addr[31:16]; // 16 bit - meta.v4sum = meta.v4sum + hdr.ipv4.totalLen -20; // 16 bit - meta.v4sum = meta.v4sum + (bit<16>) hdr.ipv4.protocol; // 8 bit + tmp = tmp + (bit<32>) hdr.ipv4.totalLen -20; // 16 bit + tmp = tmp + (bit<32>) hdr.ipv4.protocol; // 8 bit + + carryover = tmp >> 16; /* maximum is 6*(2**16) >> 16 == 6 */ + tmp = (tmp & 0xffff) + carryover; /* Now tmp contains at maximum 65541 */ + carryover = tmp >> 16; /* Now carryover contains at maximum 1 */ + tmp = (tmp & 0xffff) + carryover; /* No overrun possible anymore */ + + meta.v4sum = (bit<16>) tmp; } action v6sum() { - meta.v6sum = 0; - meta.v6sum = meta.v6sum + hdr.ipv6.src_addr[15:0]; // 16 bit - meta.v6sum = meta.v6sum + hdr.ipv6.src_addr[31:16]; // 16 bit - meta.v6sum = meta.v6sum + hdr.ipv6.src_addr[47:32]; // 16 bit - meta.v6sum = meta.v6sum + hdr.ipv6.src_addr[63:48]; // 16 bit - meta.v6sum = meta.v6sum + hdr.ipv6.src_addr[79:64]; // 16 bit - meta.v6sum = meta.v6sum + hdr.ipv6.src_addr[95:80]; // 16 bit - meta.v6sum = meta.v6sum + hdr.ipv6.src_addr[111:96]; // 16 bit - meta.v6sum = meta.v6sum + hdr.ipv6.src_addr[127:112]; // 16 bit + bit<32> tmp = 0; + bit<32> carryover = 0; - meta.v6sum = meta.v6sum + hdr.ipv6.dst_addr[15:0]; // 16 bit - meta.v6sum = meta.v6sum + hdr.ipv6.dst_addr[31:16]; // 16 bit - meta.v6sum = meta.v6sum + hdr.ipv6.dst_addr[47:32]; // 16 bit - meta.v6sum = meta.v6sum + hdr.ipv6.dst_addr[63:48]; // 16 bit - meta.v6sum = meta.v6sum + hdr.ipv6.dst_addr[79:64]; // 16 bit - meta.v6sum = meta.v6sum + hdr.ipv6.dst_addr[95:80]; // 16 bit - meta.v6sum = meta.v6sum + hdr.ipv6.dst_addr[111:96]; // 16 bit - meta.v6sum = meta.v6sum + hdr.ipv6.dst_addr[127:112]; // 16 bit + tmp = tmp + (bit<32>) hdr.ipv6.src_addr[15:0]; // 16 bit + tmp = tmp + (bit<32>) hdr.ipv6.src_addr[31:16]; // 16 bit + tmp = tmp + (bit<32>) hdr.ipv6.src_addr[47:32]; // 16 bit + tmp = tmp + (bit<32>) hdr.ipv6.src_addr[63:48]; // 16 bit + tmp = tmp + (bit<32>) hdr.ipv6.src_addr[79:64]; // 16 bit + tmp = tmp + (bit<32>) hdr.ipv6.src_addr[95:80]; // 16 bit + tmp = tmp + (bit<32>) hdr.ipv6.src_addr[111:96]; // 16 bit + tmp = tmp + (bit<32>) hdr.ipv6.src_addr[127:112]; // 16 bit - meta.v6sum = meta.v6sum + hdr.ipv6.payload_length; // 16 bit - meta.v6sum = meta.v6sum + (bit<16>) hdr.ipv6.next_header; // 8 bit + tmp = tmp + (bit<32>) hdr.ipv6.dst_addr[15:0]; // 16 bit + tmp = tmp + (bit<32>) hdr.ipv6.dst_addr[31:16]; // 16 bit + tmp = tmp + (bit<32>) hdr.ipv6.dst_addr[47:32]; // 16 bit + tmp = tmp + (bit<32>) hdr.ipv6.dst_addr[63:48]; // 16 bit + tmp = tmp + (bit<32>) hdr.ipv6.dst_addr[79:64]; // 16 bit + tmp = tmp + (bit<32>) hdr.ipv6.dst_addr[95:80]; // 16 bit + tmp = tmp + (bit<32>) hdr.ipv6.dst_addr[111:96]; // 16 bit + tmp = tmp + (bit<32>) hdr.ipv6.dst_addr[127:112]; // 16 bit + + tmp = tmp + (bit<32>) hdr.ipv6.payload_length; // 16 bit + tmp = tmp + (bit<32>) hdr.ipv6.next_header; // 8 bit + + carryover = tmp >> 16; /* maximum is 18*(2**16) >> 16 == 18 */ + tmp = (tmp & 0xffff) + carryover; /* Now tmp contains at maximum 65554*/ + carryover = tmp >> 16; /* Now carryover contains at maximum 1 */ + tmp = (tmp & 0xffff) + carryover; /* No overrun possible anymore */ + + meta.v6sum = (bit<16>) tmp; } action delta_prepare()