bool test_allocate_ipv4_transport_address( void )
{
    struct tuple tuple;
    struct ipv4_tuple_address tuple_addr;
    struct in_addr expected_addr;
    bool success = true;

    success &= str_to_addr4_verbose(IPV4_ALLOCATED_ADDR, &expected_addr);
    success &= inject_bib_entry( IPPROTO_ICMP );
    success &= inject_bib_entry( IPPROTO_TCP );
    success &= inject_bib_entry( IPPROTO_UDP );
    if (!success)
    	return false;

    init_tuple_for_test_ipv6(&tuple, IPPROTO_ICMP);
	success &= assert_true(allocate_ipv4_transport_address(&tuple, IPPROTO_ICMP, &tuple_addr),
		"Function result for ICMP");
	success &= assert_equals_ipv4(&expected_addr , &tuple_addr.address, "IPv4 address for ICMP");

	init_tuple_for_test_ipv6(&tuple, IPPROTO_TCP);
	success &= assert_true(allocate_ipv4_transport_address(&tuple, IPPROTO_TCP, &tuple_addr),
		"Function result for TCP");
	success &= assert_equals_ipv4(&expected_addr , &tuple_addr.address, "IPv4 address for TCP");
	success &= assert_true(tuple_addr.l4_id > 1023, "Port range for TCP");

	init_tuple_for_test_ipv6(&tuple, IPPROTO_UDP);
	success &= assert_true(allocate_ipv4_transport_address(&tuple, IPPROTO_UDP, &tuple_addr),
		"Function result for UDP");
	success &= assert_equals_ipv4(&expected_addr , &tuple_addr.address, "IPv4 address for UDP");
	success &= assert_true(tuple_addr.l4_id % 2 == 0, "Port parity for UDP");
	success &= assert_true( tuple_addr.l4_id > 1023, "Port range for UDP");

    return success;
}
bool test_allocate_ipv4_transport_address( void )
{
	u_int8_t protocols[] = { IPPROTO_ICMP, IPPROTO_TCP, IPPROTO_UDP };
	__u16 expected_ports[] = { IPV6_ALLOCATE_PORT, IPV6_ALLOCATE_PORT, IPV6_ALLOCATE_PORT };

    struct in_addr expected_addr;
    
    struct tuple tuple;
    struct ipv4_tuple_address new_ipv4_transport_address;

    bool success = true;
    int i;

    success &= pool6_init();
    success &= pool4_init(true);
    success &= bib_init();
    success &= str_to_addr4_verbose(IPV4_ALLOCATED_ADDR, &expected_addr);
    success &= inject_bib_entry( IPPROTO_ICMP );
    success &= inject_bib_entry( IPPROTO_TCP );
    success &= inject_bib_entry( IPPROTO_UDP );
    if (!success)
    	return false;

    for (i = 0; i < ARRAY_SIZE(protocols); i++)
    {
		init_tuple_for_test_ipv6(&tuple, protocols[i]);

		success &= assert_true(allocate_ipv4_transport_address(&tuple, protocols[i], &new_ipv4_transport_address),
			"Check that we can allocate a brand new IPv4 transport address.");
		success &= assert_equals_ipv4(&expected_addr , &new_ipv4_transport_address.address,
			"Check that the allocated IPv4 address is correct.");
		success &= assert_equals_u16( expected_ports[i], new_ipv4_transport_address.l4_id,
			"Check that the allocated IPv4 port is correct.");
    }

    bib_destroy();
    pool4_destroy();
    pool6_destroy();

    return success;
}