test-csum: add IPv6 pseudo header csum test
authorThadeu Lima de Souza Cascardo <cascardo@redhat.com>
Fri, 4 Mar 2016 18:36:50 +0000 (15:36 -0300)
committerThadeu Lima de Souza Cascardo <cascardo@redhat.com>
Thu, 10 Mar 2016 17:04:17 +0000 (14:04 -0300)
tests/library.at
tests/test-csum.c

index d82113f..114bf16 100644 (file)
@@ -7,7 +7,7 @@ AT_CHECK([ovstest test-flows flows pcap], [0], [checked 247 packets, 0 errors
 AT_CLEANUP
 
 AT_SETUP([test TCP/IP checksumming])
-AT_CHECK([ovstest test-csum], [0], [....#....#....####................................#................................#
+AT_CHECK([ovstest test-csum], [0], [....#....#....#####................................#................................#
 ])
 AT_CLEANUP
 
index 97638b9..f504457 100644 (file)
@@ -21,6 +21,7 @@
 #include <inttypes.h>
 #include <netinet/in.h>
 #include <netinet/ip.h>
+#include <netinet/ip6.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -209,6 +210,44 @@ test_pseudo(void)
     mark('#');
 }
 
+/* Check the IPv6 pseudoheader calculation. */
+static void
+test_pseudov6(void)
+{
+    ovs_be16 csum;
+    /* Try an IPv6 header similar to one that the tunnel code
+     * might generate. */
+    struct ovs_16aligned_ip6_hdr ip6 = {
+        .ip6_vfc = 0x60,
+        .ip6_hlim = 64,
+        .ip6_nxt = IPPROTO_UDP,
+        .ip6_plen = htons(1410),
+        .ip6_src = { .be16 = { htons(0x2001), htons(0xcafe), 0, 0, 0, 0, 0, htons(0x92) } },
+        .ip6_dst = { .be16 = { htons(0x2001), htons(0xcafe), 0, 0, 0, 0, 0, htons(0x91) } }
+    };
+
+    csum = csum_finish(packet_csum_pseudoheader6(&ip6, htonl(1410)));
+    assert(csum == htons(0x234a));
+
+    /* And also test something totally different to check for
+     * corner cases. */
+    memset(&ip6, 0xff, sizeof ip6);
+    csum = csum_finish(packet_csum_pseudoheader6(&ip6, htonl(0xffff)));
+    assert(csum == htons(0xff00));
+
+    /* Test 0 sum */
+    memset(&ip6, 0x00, sizeof ip6);
+    csum = csum_finish(packet_csum_pseudoheader6(&ip6, htonl(0x0000)));
+    assert(csum == htons(0xffff));
+
+    /* Test 0xffff sum */
+    memset(&ip6, 0x00, sizeof ip6);
+    csum = csum_finish(packet_csum_pseudoheader6(&ip6, htonl(0xffff)));
+    assert(csum == htons(0x0000));
+
+    mark('#');
+}
+
 static void
 test_csum_main(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
 {
@@ -273,6 +312,7 @@ test_csum_main(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
     test_rfc1624();
     test_crc32c();
     test_pseudo();
+    test_pseudov6();
 
     /* Test recalc_csum16(). */
     for (i = 0; i < 32; i++) {