test-ovn: Add help output for parse-actions command.
[cascardo/ovs.git] / tests / test-csum.c
index ef126de..97638b9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, 2010, 2011 Nicira, Inc.
+ * Copyright (c) 2009, 2010, 2011, 2014 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  */
 
 #include <config.h>
+#undef NDEBUG
 #include "csum.h"
-#include "crc32c.h"
+#include <assert.h>
 #include <inttypes.h>
 #include <netinet/in.h>
+#include <netinet/ip.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include "crc32c.h"
+#include "ovstest.h"
+#include "packets.h"
 #include "random.h"
 #include "unaligned.h"
 #include "util.h"
 
-#undef NDEBUG
-#include <assert.h>
-
 struct test_case {
     char *data;
     size_t size;                /* Test requires a multiple of 4. */
@@ -175,8 +177,40 @@ test_crc32c(void)
     mark('#');
 }
 
-int
-main(void)
+/* Check the IP pseudoheader calculation. */
+static void
+test_pseudo(void)
+{
+    ovs_be16 csum;
+    /* Try an IP header similar to one that the tunnel code
+     * might generate. */
+    struct ip_header ip = {
+        .ip_ihl_ver = IP_IHL_VER(5, 4),
+        .ip_tos = 0,
+        .ip_tot_len = htons(134),
+        .ip_id = 0,
+        .ip_frag_off = htons(IP_DF),
+        .ip_ttl = 64,
+        .ip_proto = IPPROTO_UDP,
+        .ip_csum = htons(0x1265),
+        .ip_src = { .hi = htons(0x1400), .lo = htons(0x0002) },
+        .ip_dst = { .hi = htons(0x1400), .lo = htons(0x0001) }
+    };
+
+    csum = csum_finish(packet_csum_pseudoheader(&ip));
+    assert(csum == htons(0xd779));
+
+    /* And also test something totally different to check for
+     * corner cases. */
+    memset(&ip, 0xff, sizeof ip);
+    csum = csum_finish(packet_csum_pseudoheader(&ip));
+    assert(csum == htons(0xff3c));
+
+    mark('#');
+}
+
+static void
+test_csum_main(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
 {
     const struct test_case *tc;
     int i;
@@ -238,6 +272,7 @@ main(void)
 
     test_rfc1624();
     test_crc32c();
+    test_pseudo();
 
     /* Test recalc_csum16(). */
     for (i = 0; i < 32; i++) {
@@ -280,6 +315,6 @@ main(void)
     mark('#');
 
     putchar('\n');
-
-    return 0;
 }
+
+OVSTEST_REGISTER("test-csum", test_csum_main);