/*
- * Copyright (c) 2011 Nicira, Inc.
+ * Copyright (c) 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 "packets.h"
+#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-
-#undef NDEBUG
-#include <assert.h>
-
+#include "ovstest.h"
static void
test_ipv4_cidr(void)
assert(ipv6_count_cidr_bits(&dest) == 128);
}
-int
-main(void)
+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)
{
test_ipv4_cidr();
test_ipv6_static_masks();
test_ipv6_cidr();
test_ipv6_masking();
-
- return 0;
+ test_ipv6_parsing();
}
+
+OVSTEST_REGISTER("test-packets", test_packets_main);