bool test_allocate_ipv4_transport_address_digger( void ) { struct in_addr expected_addr; struct tuple tuple; struct ipv4_tuple_address new_ipv4_transport_address; bool success = true; success &= inject_bib_entry( IPPROTO_ICMP ); success &= inject_bib_entry( IPPROTO_TCP ); success &= init_tuple_for_test_ipv6(&tuple, IPPROTO_UDP); success &= str_to_addr4_verbose(IPV4_ALLOCATED_ADDR, &expected_addr); if (!success) return false; success &= assert_true( allocate_ipv4_transport_address_digger(&tuple, IPPROTO_UDP, &new_ipv4_transport_address), "Check that we can allocate a brand new IPv4 transport address for UDP."); success &= assert_true( ipv4_addr_equals(&new_ipv4_transport_address.address, &expected_addr) , "Check that the allocated IPv4 address is correct for UDP."); success &= assert_true( new_ipv4_transport_address.l4_id % 2 == 0, "Check that the allocated IPv4 port is even."); success &= assert_true( new_ipv4_transport_address.l4_id > 1023, "Check that the allocated IPv4 port is in the upper range."); return success; }
bool test_allocate_ipv4_transport_address_digger( void ) { struct in_addr expected_addr; struct tuple tuple; struct ipv4_tuple_address new_ipv4_transport_address; bool success = true; bib_init(); pool4_init(true); success &= inject_bib_entry( IPPROTO_ICMP ); success &= inject_bib_entry( IPPROTO_TCP ); success &= init_tuple_for_test_ipv6(&tuple, IPPROTO_UDP); success &= str_to_addr4_verbose(IPV4_ALLOCATED_ADDR, &expected_addr); if (!success) return false; success &= assert_true( allocate_ipv4_transport_address_digger(&tuple, IPPROTO_UDP, &new_ipv4_transport_address), "Check that we can allocate a brand new IPv4 transport address for UDP."); success &= assert_true( ipv4_addr_equals(&new_ipv4_transport_address.address, &expected_addr) , "Check that the allocated IPv4 address is correct for UDP."); success &= assert_equals_u16( IPV4_ALLOCATED_PORT_DIGGER, new_ipv4_transport_address.l4_id, "Check that the allocated IPv4 port is correct for UDP."); pool4_destroy(); bib_destroy(); return success; }