From d31f1109f10e5ffb9bf266306b913ebf23781666 Mon Sep 17 00:00:00 2001 From: Justin Pettit Date: Wed, 29 Dec 2010 19:03:46 -0800 Subject: nicira-ext: Support matching IPv6 traffic. Provides ability to match over IPv6 traffic in the same manner as IPv4. Currently, the matching fields include: - IPv6 source and destination addresses (ipv6_src and ipv6_dst) - Traffic Class (nw_tos) - Next Header (nw_proto) - ICMPv6 Type and Code (icmp_type and icmp_code) - TCP and UDP Ports over IPv6 (tp_src and tp_dst) When defining IPv6 rules, the Nicira Extensible Match (NXM) extension to OVS must be used. Signed-off-by: Justin Pettit Acked-by: Ben Pfaff --- tests/test-packets.c | 116 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) (limited to 'tests/test-packets.c') diff --git a/tests/test-packets.c b/tests/test-packets.c index 464a8eb7..dda4797f 100644 --- a/tests/test-packets.c +++ b/tests/test-packets.c @@ -39,10 +39,126 @@ test_ipv4_cidr(void) assert(!ip_is_cidr(htonl(0xffffffd0))); } +static void +test_ipv6_static_masks(void) +{ + /* The 'exact' and 'any' addresses should be identical to + * 'in6addr_exact' and 'in6addr_any' definitions, but we redefine + * them here since the pre-defined ones are used in the functions + * we're testing. */ + struct in6_addr exact = {{{ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, \ + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff }}}; + + struct in6_addr any = {{{ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, \ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }}}; + + struct in6_addr neither = {{{ 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef, \ + 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef }}}; + + assert(ipv6_mask_is_exact(&exact)); + assert(!ipv6_mask_is_exact(&any)); + assert(!ipv6_mask_is_exact(&neither)); + + assert(!ipv6_mask_is_any(&exact)); + assert(ipv6_mask_is_any(&any)); + assert(!ipv6_mask_is_any(&neither)); + +} + +static void +test_ipv6_cidr(void) +{ + struct in6_addr dest; + + struct in6_addr src = {{{ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, \ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }}}; + + dest = ipv6_create_mask(0); + assert(ipv6_mask_is_any(&dest)); + assert(ipv6_count_cidr_bits(&dest) == 0); + assert(ipv6_is_cidr(&dest)); + + dest = ipv6_create_mask(128); + assert(ipv6_mask_is_exact(&dest)); + assert(ipv6_count_cidr_bits(&dest) == 128); + assert(ipv6_is_cidr(&dest)); + + dest = ipv6_create_mask(1); + assert(ipv6_count_cidr_bits(&dest) == 1); + assert(ipv6_is_cidr(&dest)); + + dest = ipv6_create_mask(13); + assert(ipv6_count_cidr_bits(&dest) == 13); + assert(ipv6_is_cidr(&dest)); + + dest = ipv6_create_mask(64); + assert(ipv6_count_cidr_bits(&dest) == 64); + assert(ipv6_is_cidr(&dest)); + + dest = ipv6_create_mask(95); + assert(ipv6_count_cidr_bits(&dest) == 95); + assert(ipv6_is_cidr(&dest)); + + dest = ipv6_create_mask(96); + assert(ipv6_count_cidr_bits(&dest) == 96); + assert(ipv6_is_cidr(&dest)); + + dest = ipv6_create_mask(97); + assert(ipv6_count_cidr_bits(&dest) == 97); + assert(ipv6_is_cidr(&dest)); + + dest = ipv6_create_mask(127); + assert(ipv6_count_cidr_bits(&dest) == 127); + assert(ipv6_is_cidr(&dest)); + + src.s6_addr[8] = 0xf0; + assert(ipv6_is_cidr(&src)); + assert(ipv6_count_cidr_bits(&src) == 68); + + src.s6_addr[15] = 0x01; + assert(!ipv6_is_cidr(&src)); + src.s6_addr[15] = 0x00; + assert(ipv6_is_cidr(&src)); + + src.s6_addr[8] = 0x0f; + assert(!ipv6_is_cidr(&src)); +} + + +static void +test_ipv6_masking(void) +{ + struct in6_addr dest; + struct in6_addr mask; + + mask = ipv6_create_mask(0); + dest = ipv6_addr_bitand(&in6addr_exact, &mask); + assert(ipv6_count_cidr_bits(&dest) == 0); + + mask = ipv6_create_mask(1); + dest = ipv6_addr_bitand(&in6addr_exact, &mask); + assert(ipv6_count_cidr_bits(&dest) == 1); + + mask = ipv6_create_mask(13); + dest = ipv6_addr_bitand(&in6addr_exact, &mask); + assert(ipv6_count_cidr_bits(&dest) == 13); + + mask = ipv6_create_mask(127); + dest = ipv6_addr_bitand(&in6addr_exact, &mask); + assert(ipv6_count_cidr_bits(&dest) == 127); + + mask = ipv6_create_mask(128); + dest = ipv6_addr_bitand(&in6addr_exact, &mask); + assert(ipv6_count_cidr_bits(&dest) == 128); +} + int main(void) { test_ipv4_cidr(); + test_ipv6_static_masks(); + test_ipv6_cidr(); + test_ipv6_masking(); return 0; } -- cgit v1.2.3