ofpbuf: Fix trivial spelling typo.
[cascardo/ovs.git] / tests / test-packets.c
index a9fafd5..c4494cf 100644 (file)
  */
 
 #include <config.h>
+#undef NDEBUG
 #include "packets.h"
+#include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include "ovstest.h"
 
-#undef NDEBUG
-#include <assert.h>
-
-
 static void
 test_ipv4_cidr(void)
 {
@@ -153,6 +151,28 @@ test_ipv6_masking(void)
     assert(ipv6_count_cidr_bits(&dest) == 128);
 }
 
+static void
+test_ipv6_parsing(void)
+{
+    struct in6_addr o_ipv6, p_ipv6;
+    struct in6_addr mask;
+
+    inet_pton(AF_INET6, "2001:db8:0:0:0:0:2:1", &o_ipv6);
+
+    ipv6_parse_masked("2001:db8:0:0:0:0:2:1/64", &p_ipv6, &mask);
+    assert(ipv6_addr_equals(&o_ipv6, &p_ipv6));
+    assert(ipv6_count_cidr_bits(&mask) == 64);
+
+    ipv6_parse_masked("2001:db8:0:0:0:0:2:1/ffff:ffff:ffff:ffff::",
+                      &p_ipv6, &mask);
+    assert(ipv6_addr_equals(&o_ipv6, &p_ipv6));
+    assert(ipv6_count_cidr_bits(&mask) == 64);
+
+    ipv6_parse_masked("2001:db8:0:0:0:0:2:1", &p_ipv6, &mask);
+    assert(ipv6_addr_equals(&o_ipv6, &p_ipv6));
+    assert(ipv6_count_cidr_bits(&mask) == 128);
+}
+
 static void
 test_packets_main(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
 {
@@ -160,6 +180,7 @@ test_packets_main(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
     test_ipv6_static_masks();
     test_ipv6_cidr();
     test_ipv6_masking();
+    test_ipv6_parsing();
 }
 
 OVSTEST_REGISTER("test-packets", test_packets_main);