Ejemplo n.º 1
0
static int
test_stats_entry_setup_from_add(void)
{
    of_flow_add_t *add;
    of_flow_stats_entry_t *entry;
    of_match_t m1, m2;
    of_list_action_t *list;
    of_list_action_t list_out;

    TEST_ASSERT((add = of_flow_add_new(OF_VERSION_1_0)) != NULL);
    TEST_ASSERT((entry = of_flow_stats_entry_new(OF_VERSION_1_0)) != NULL);

    TEST_ASSERT(of_flow_add_OF_VERSION_1_0_populate(add, 1) != 0);
    TEST_ASSERT(of_flow_add_match_get(add, &m1) == 0);

    TEST_ASSERT(of_flow_stats_entry_setup_from_flow_add(entry, add, NULL) == 0);
    TEST_ASSERT(of_flow_stats_entry_match_get(entry, &m2) == 0);
    TEST_ASSERT(memcmp(&m1, &m2, sizeof(m1)) == 0);

    of_flow_add_delete(add);
    of_flow_stats_entry_delete(entry);

    /* @todo check action lists agree */

    /* Same with an external action list */

    TEST_ASSERT((add = of_flow_add_new(OF_VERSION_1_0)) != NULL);
    TEST_ASSERT((entry = of_flow_stats_entry_new(OF_VERSION_1_0)) != NULL);

    TEST_ASSERT(of_flow_add_OF_VERSION_1_0_populate(add, 1) != 0);
    TEST_ASSERT(of_flow_add_match_get(add, &m1) == 0);

    list = of_list_action_new(OF_VERSION_1_0);
    TEST_ASSERT(list != NULL);
    TEST_ASSERT(of_list_action_OF_VERSION_1_0_populate(list, 1) != 0);

    /* Verify matches agree */
    TEST_ASSERT(of_flow_stats_entry_setup_from_flow_add(entry, add, list) == 0);
    TEST_ASSERT(of_flow_stats_entry_match_get(entry, &m2) == 0);
    TEST_ASSERT(memcmp(&m1, &m2, sizeof(m1)) == 0);

    of_list_action_init(&list_out, OF_VERSION_1_0, 0, 1);
    of_flow_stats_entry_actions_bind(entry, &list_out);

    /* Verify lists agree */
    TEST_ASSERT(list->length == list_out.length);
    TEST_ASSERT(memcmp(WBUF_BUF(list->wire_object.wbuf),
                       WBUF_BUF(list_out.wire_object.wbuf),
                       list->length));

    of_flow_add_delete(add);
    of_list_action_delete(list);
    of_flow_stats_entry_delete(entry);

    return TEST_PASS;
}
Ejemplo n.º 2
0
static int
populate_table(ft_instance_t ft, int count, of_match_t *match)
{
    int idx;
    of_flow_add_t *flow_add_base;
    of_flow_add_t *flow_add;
    ft_entry_t    *entry;

    flow_add_base = of_flow_add_new(OF_VERSION_1_0);
    TEST_ASSERT(of_flow_add_OF_VERSION_1_0_populate(flow_add_base, 1) != 0);
    of_flow_add_flags_set(flow_add_base, 0);
    TEST_OK(of_flow_add_match_get(flow_add_base, match));

    for (idx = 0; idx < count; ++idx) {
        TEST_ASSERT((flow_add = of_object_dup((of_object_t *)flow_add_base))
                    != NULL);
        match->fields.eth_type = TEST_ETH_TYPE(idx);
        TEST_OK(of_flow_add_match_set(flow_add, match));
        TEST_INDIGO_OK(FT_ADD(ft, TEST_KEY(idx), flow_add, &entry));
        TEST_ASSERT(check_table_entry_states(ft) == 0);
    }

    CHECK_FLOW_COUNT(&ft->status, TEST_FLOW_COUNT);
    of_flow_add_delete(flow_add_base);

    return 0;
}
Ejemplo n.º 3
0
static int
test_removed_setup_from_add(void)
{
    of_flow_removed_t *removed;
    of_flow_add_t *add;
    of_match_t m1, m2;

    TEST_ASSERT((add = of_flow_add_new(OF_VERSION_1_0)) != NULL);
    TEST_ASSERT((removed = of_flow_removed_new(OF_VERSION_1_0)) != NULL);

    TEST_ASSERT(of_flow_add_OF_VERSION_1_0_populate(add, 1) != 0);
    TEST_ASSERT(of_flow_add_match_get(add, &m1) == 0);

    TEST_ASSERT(of_flow_removed_setup_from_flow_add(removed, add) == 0);
    TEST_ASSERT(of_flow_removed_match_get(removed, &m2) == 0);
    TEST_ASSERT(memcmp(&m1, &m2, sizeof(m1)) == 0);

    of_flow_add_delete(add);
    of_flow_removed_delete(removed);

    return TEST_PASS;
}
Ejemplo n.º 4
0
/* Generated from of10/echo_request.data */
static int
test_of10_echo_request(void) {
    uint8_t binary[] = {
        0x01, 0x02, 0x00, 0x0b, 0x12, 0x34, 0x56, 0x78, 
        0x61, 0x62, 0x01, 
    };

    of_object_t *obj;

    obj = of_echo_request_new(OF_VERSION_1_0);
    of_echo_request_xid_set(obj, 0x12345678);
    {
        of_octets_t data = { .data=(uint8_t *)"ab\x01", .bytes=3 };
        of_echo_request_data_set(obj, &data);
    }

    if (sizeof(binary) != WBUF_CURRENT_BYTES(OF_OBJECT_TO_WBUF(obj))
        || memcmp(binary, WBUF_BUF(OF_OBJECT_TO_WBUF(obj)), sizeof(binary))) {
	show_failure(binary, sizeof(binary),
		     WBUF_BUF(OF_OBJECT_TO_WBUF(obj)),
		     WBUF_CURRENT_BYTES(OF_OBJECT_TO_WBUF(obj)));
	of_object_delete(obj);
	return TEST_FAIL;
    }

    of_object_delete(obj);
    return TEST_PASS;
}

/* Generated from of10/flow_add.data */
static int
test_of10_flow_add(void) {
    uint8_t binary[] = {
        0x01, 0x0e, 0x00, 0x70, 0x12, 0x34, 0x56, 0x78, 
        0x00, 0x30, 0x00, 0xe2, 0x00, 0x03, 0x01, 0x23, 
        0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23, 
        0x45, 0x67, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 
        0x00, 0x00, 0x00, 0x00, 0xc0, 0xa8, 0x03, 0x7f, 
        0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 
        0x00, 0x00, 0x00, 0x08, 0xff, 0xfb, 0x00, 0x00, 
        0xff, 0xff, 0x00, 0x10, 0x00, 0x00, 0x23, 0x20, 
        0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
        0xff, 0xff, 0x00, 0x10, 0x00, 0x5c, 0x16, 0xc7, 
        0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 
        
    };

    of_object_t *obj;

    obj = of_flow_add_new(OF_VERSION_1_0);
    of_flow_add_xid_set(obj, 0x12345678);
    of_flow_add_idle_timeout_set(obj, 5);
    of_flow_add_flags_set(obj, 2);
    {
        of_match_t match = { OF_VERSION_1_0 };
        match.fields.in_port = 3;
        match.fields.eth_src = (of_mac_addr_t) { { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab } };
        match.fields.eth_dst = (of_mac_addr_t) { { 0xcd, 0xef, 0x01, 0x23, 0x45, 0x67 } };
        match.fields.eth_type = 0x800;
        match.fields.ipv4_src = 0xc0a8037f;
        match.fields.ipv4_dst = 0xffffffff;
        OF_MATCH_MASK_IN_PORT_EXACT_SET(&match);
        OF_MATCH_MASK_ETH_SRC_EXACT_SET(&match);
        OF_MATCH_MASK_ETH_DST_EXACT_SET(&match);
        OF_MATCH_MASK_ETH_TYPE_EXACT_SET(&match);
        //OF_MATCH_MASK_VLAN_VID_EXACT_SET(&match);
        //OF_MATCH_MASK_VLAN_PCP_EXACT_SET(&match);
        OF_MATCH_MASK_ETH_TYPE_EXACT_SET(&match);
        //OF_MATCH_MASK_IP_DSCP_EXACT_SET(&match);
        //OF_MATCH_MASK_IP_PROTO_EXACT_SET(&match);
        OF_MATCH_MASK_IPV4_SRC_EXACT_SET(&match);
        OF_MATCH_MASK_IPV4_DST_EXACT_SET(&match);
        //OF_MATCH_MASK_TCP_SRC_EXACT_SET(&match);
        //OF_MATCH_MASK_TCP_DST_EXACT_SET(&match);
        of_flow_add_match_set(obj, &match);
    }
    {
        of_list_action_t actions;
        of_flow_add_actions_bind(obj, &actions);
        {
            of_action_t action;
            of_action_output_init(&action.output, OF_VERSION_1_0, -1, 1);
            of_list_action_append_bind(&actions, &action);
            of_action_output_port_set(&action.output, OF_PORT_DEST_FLOOD);
        }
        {
            of_action_t action;
            of_action_nicira_dec_ttl_init(&action.nicira_dec_ttl, OF_VERSION_1_0, -1, 1);
            of_list_action_append_bind(&actions, &action);
        }
        {
            of_action_t action;
            of_action_bsn_set_tunnel_dst_init(&action.bsn_set_tunnel_dst, OF_VERSION_1_0, -1, 1);
            of_list_action_append_bind(&actions, &action);
        }
    }

    if (sizeof(binary) != WBUF_CURRENT_BYTES(OF_OBJECT_TO_WBUF(obj))
        || memcmp(binary, WBUF_BUF(OF_OBJECT_TO_WBUF(obj)), sizeof(binary))) {
	show_failure(binary, sizeof(binary),
		     WBUF_BUF(OF_OBJECT_TO_WBUF(obj)),
		     WBUF_CURRENT_BYTES(OF_OBJECT_TO_WBUF(obj)));
	of_object_delete(obj);
	return TEST_FAIL;
    }

    of_object_delete(obj);
    return TEST_PASS;
}