SimpleForwardingModule::SimpleForwardingModule(
        uint64_t instanceId)
        :
        AbstractModule(zmf::data::ModuleUniqueId(MODULE_TYPE_ID, instanceId),
                       MODULE_VERSION,
                       "SimpleForwardingModule",
                       {{deviceMgrDependencyType_, deviceMgrDependencyVersion_}}) {
    tempPacketOut_OF_1_0 = of_packet_out_new(OF_VERSION_1_0);
    tempPacketOut_OF_1_3 = of_packet_out_new(OF_VERSION_1_3);

    of_packet_out_buffer_id_set(tempPacketOut_OF_1_0, OF_BUFFER_ID_NO_BUFFER);
    of_packet_out_buffer_id_set(tempPacketOut_OF_1_3, OF_BUFFER_ID_NO_BUFFER);


    tempActionList_OF_1_0 = of_list_action_new(OF_VERSION_1_0);
    tempActionList_OF_1_3 = of_list_action_new(OF_VERSION_1_3);
    tempOutPut_OF_1_0 = of_action_output_new(OF_VERSION_1_0);
    tempOutPut_OF_1_3 = of_action_output_new(OF_VERSION_1_3);
    of_list_action_append_bind(tempActionList_OF_1_0, tempOutPut_OF_1_0);
    of_list_action_append_bind(tempActionList_OF_1_3, tempOutPut_OF_1_3);
    //of_port_no_t port_no = destinationDevice->switchPort;
    //of_action_output_port_set(output, port_no);
    of_packet_out_actions_set(tempPacketOut_OF_1_0, tempActionList_OF_1_0);
    of_packet_out_actions_set(tempPacketOut_OF_1_3, tempActionList_OF_1_3);
};
Exemplo n.º 2
0
static int
test_of_list_action_OF_VERSION_1_2(void)
{
    of_list_action_t *list;
    int value = 1;

    list = of_list_action_new(OF_VERSION_1_2);
    TEST_ASSERT(list != NULL);
    TEST_ASSERT(list->version == OF_VERSION_1_2);
    TEST_ASSERT(list->length == 0);
    TEST_ASSERT(list->parent == NULL);
    TEST_ASSERT(list->object_id == OF_LIST_ACTION);

    value = list_setup_of_list_action_OF_VERSION_1_2(list, value);
    TEST_ASSERT(value != 0);

    /* Now check values */
    value = 1;
    value = list_check_of_list_action_OF_VERSION_1_2(list, value);
    TEST_ASSERT(value != 0);

    of_list_action_delete(list);

    return TEST_PASS;
}
Exemplo n.º 3
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;
}
/*
 * icmp_send_packet_out
 *
 * Send the ICMP message out
 */
indigo_error_t
icmpa_send_packet_out (of_octets_t *octets)
{
    of_packet_out_t    *obj;
    of_list_action_t   *list;
    of_action_output_t *action;
    indigo_error_t     rv;

    if (!octets) return INDIGO_ERROR_PARAM;

    obj = of_packet_out_new(OF_VERSION_1_3);
    AIM_TRUE_OR_DIE(obj != NULL);

    list = of_list_action_new(OF_VERSION_1_3);
    AIM_TRUE_OR_DIE(list != NULL);

    action = of_action_output_new(OF_VERSION_1_3);
    AIM_TRUE_OR_DIE(action != NULL);

    of_packet_out_buffer_id_set(obj, -1);
    of_packet_out_in_port_set(obj, OF_PORT_DEST_CONTROLLER);
    of_action_output_port_set(action, OF_PORT_DEST_USE_TABLE);
    of_list_append(list, action);
    of_object_delete(action);
    rv = of_packet_out_actions_set(obj, list);
    AIM_ASSERT(rv == 0);
    of_object_delete(list);

    rv = of_packet_out_data_set(obj, octets);
    if (rv < 0) {
        AIM_LOG_ERROR("ICMPA: Failed to set data on packet out");
        of_packet_out_delete(obj);
        return rv;
    }

    rv = indigo_fwd_packet_out(obj);
    of_packet_out_delete(obj);
    return rv;
}
Exemplo n.º 5
0
/* Generated from of10/packet_in.data */
static int
test_of10_packet_in(void) {
    uint8_t binary[] = {
        0x01, 0x0a, 0x00, 0x15, 0x12, 0x34, 0x56, 0x78, 
        0xab, 0xcd, 0xef, 0x01, 0x00, 0x09, 0xff, 0xfe, 
        0x01, 0x00, 0x61, 0x62, 0x63, 
    };

    of_object_t *obj;

    obj = of_packet_in_new(OF_VERSION_1_0);
    of_packet_in_buffer_id_set(obj, 2882400001);
    {
        of_octets_t data = { .bytes=3, .data=(uint8_t *)"\x61\x62\x63" };
        of_packet_in_data_set(obj, &data);
    }
    of_packet_in_in_port_set(obj, 65534);
    of_packet_in_reason_set(obj, 1);
    of_packet_in_total_len_set(obj, 9);
    of_packet_in_xid_set(obj, 305419896);

    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/packet_out.data */
static int
test_of10_packet_out(void) {
    uint8_t binary[] = {
        0x01, 0x0d, 0x00, 0x23, 0x12, 0x34, 0x56, 0x78, 
        0xab, 0xcd, 0xef, 0x01, 0xff, 0xfe, 0x00, 0x10, 
        0x00, 0x00, 0x00, 0x08, 0x00, 0x01, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x08, 0x00, 0x02, 0x00, 0x00, 
        0x61, 0x62, 0x63, 
    };

    of_object_t *obj;

    obj = of_packet_out_new(OF_VERSION_1_0);
    of_packet_out_buffer_id_set(obj, 2882400001);
    of_packet_out_in_port_set(obj, 65534);
    of_packet_out_xid_set(obj, 305419896);
    {
        of_object_t *list = of_list_action_new(OF_VERSION_1_0);
        {
            of_object_t *obj = of_action_output_new(OF_VERSION_1_0);
            of_action_output_max_len_set(obj, 0);
            of_action_output_port_set(obj, 1);
            of_list_append(list, obj);
            of_object_delete(obj);
        }
        {
            of_object_t *obj = of_action_output_new(OF_VERSION_1_0);
            of_action_output_max_len_set(obj, 0);
            of_action_output_port_set(obj, 2);
            of_list_append(list, obj);
            of_object_delete(obj);
        }
        of_packet_out_actions_set(obj, list);
        of_object_delete(list);
    }
    {
        of_octets_t data = { .bytes=3, .data=(uint8_t *)"\x61\x62\x63" };
        of_packet_out_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/port_desc.data */
static int
test_of10_port_desc(void) {
    uint8_t binary[] = {
        0xff, 0xfd, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 
        0x66, 0x6f, 0x6f, 0x00, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x02, 0x00, 
        0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, 
        0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x08, 0x00, 
        
    };

    of_object_t *obj;

    obj = of_port_desc_new(OF_VERSION_1_0);
    of_port_desc_advertised_set(obj, 32);
    of_port_desc_config_set(obj, 16);
    of_port_desc_curr_set(obj, 1);
    {
        of_mac_addr_t hw_addr = { { 1, 2, 3, 4, 5, 6 } };
        of_port_desc_hw_addr_set(obj, hw_addr);
    }
    {
        of_port_name_t name = "foo";
        of_port_desc_name_set(obj, name);
    }
    of_port_desc_peer_set(obj, 2048);
    of_port_desc_port_no_set(obj, 65533);
    of_port_desc_state_set(obj, 512);
    of_port_desc_supported_set(obj, 512);

    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;
}
Exemplo n.º 6
0
/* Generated from of10/flow_stats_reply.data */
static int
test_of10_flow_stats_reply(void) {
    uint8_t binary[] = {
        0x01, 0x11, 0x00, 0xe4, 0x00, 0x00, 0x00, 0x06, 
        0x00, 0x01, 0x00, 0x00, 0x00, 0x68, 0x03, 0x00, 
        0x00, 0x3f, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 
        0x00, 0x64, 0x00, 0x05, 0x00, 0x0a, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x00, 0x01, 0x23, 0x45, 0x67, 
        0x89, 0xab, 0xcd, 0xef, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x03, 0xe8, 0x00, 0x00, 0x00, 0x08, 
        0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 
        0x00, 0x02, 0x00, 0x00, 0x00, 0x70, 0x04, 0x00, 
        0x00, 0x3f, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 
        0x00, 0x64, 0x00, 0x05, 0x00, 0x0a, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x00, 0x01, 0x23, 0x45, 0x67, 
        0x89, 0xab, 0xcd, 0xef, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x03, 0xe8, 0x00, 0x00, 0x00, 0x08, 
        0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 
        0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 
        0x00, 0x03, 0x00, 0x00, 
    };

    of_object_t *obj;

    obj = of_flow_stats_reply_new(OF_VERSION_1_0);
    of_flow_stats_reply_flags_set(obj, 0);
    of_flow_stats_reply_xid_set(obj, 6);
    {
        of_object_t *entries = of_list_flow_stats_entry_new(OF_VERSION_1_0);
        {
            of_object_t *elem = of_flow_stats_entry_new(OF_VERSION_1_0);
            of_flow_stats_entry_byte_count_set(elem, 1000);
            of_flow_stats_entry_cookie_set(elem, 81985529216486895);
            of_flow_stats_entry_duration_nsec_set(elem, 2);
            of_flow_stats_entry_duration_sec_set(elem, 1);
            of_flow_stats_entry_hard_timeout_set(elem, 10);
            of_flow_stats_entry_idle_timeout_set(elem, 5);
            of_flow_stats_entry_packet_count_set(elem, 10);
            of_flow_stats_entry_priority_set(elem, 100);
            of_flow_stats_entry_table_id_set(elem, 3);
            {
                of_match_t match = { OF_VERSION_1_0 };
                of_flow_stats_entry_match_set(elem, &match);
            }
            {
                of_object_t *actions = of_list_action_new(OF_VERSION_1_0);
                {
                    of_object_t *elem = of_action_output_new(OF_VERSION_1_0);
                    of_action_output_max_len_set(elem, 0);
                    of_action_output_port_set(elem, 1);
                    of_list_append(actions, elem);
                    of_object_delete(elem);
                }
                {
                    of_object_t *elem = of_action_output_new(OF_VERSION_1_0);
                    of_action_output_max_len_set(elem, 0);
                    of_action_output_port_set(elem, 2);
                    of_list_append(actions, elem);
                    of_object_delete(elem);
                }
                of_flow_stats_entry_actions_set(elem, actions);
                of_object_delete(actions);
            }
            of_list_append(entries, elem);
            of_object_delete(elem);
        }
        {
            of_object_t *elem = of_flow_stats_entry_new(OF_VERSION_1_0);
            of_flow_stats_entry_byte_count_set(elem, 1000);
            of_flow_stats_entry_cookie_set(elem, 81985529216486895);
            of_flow_stats_entry_duration_nsec_set(elem, 2);
            of_flow_stats_entry_duration_sec_set(elem, 1);
            of_flow_stats_entry_hard_timeout_set(elem, 10);
            of_flow_stats_entry_idle_timeout_set(elem, 5);
            of_flow_stats_entry_packet_count_set(elem, 10);
            of_flow_stats_entry_priority_set(elem, 100);
            of_flow_stats_entry_table_id_set(elem, 4);
            {
                of_match_t match = { OF_VERSION_1_0 };
                of_flow_stats_entry_match_set(elem, &match);
            }
            {
                of_object_t *actions = of_list_action_new(OF_VERSION_1_0);
                {
                    of_object_t *elem = of_action_output_new(OF_VERSION_1_0);
                    of_action_output_max_len_set(elem, 0);
                    of_action_output_port_set(elem, 1);
                    of_list_append(actions, elem);
                    of_object_delete(elem);
                }
                {
                    of_object_t *elem = of_action_output_new(OF_VERSION_1_0);
                    of_action_output_max_len_set(elem, 0);
                    of_action_output_port_set(elem, 2);
                    of_list_append(actions, elem);
                    of_object_delete(elem);
                }
                {
                    of_object_t *elem = of_action_output_new(OF_VERSION_1_0);
                    of_action_output_max_len_set(elem, 0);
                    of_action_output_port_set(elem, 3);
                    of_list_append(actions, elem);
                    of_object_delete(elem);
                }
                of_flow_stats_entry_actions_set(elem, actions);
                of_object_delete(actions);
            }
            of_list_append(entries, elem);
            of_object_delete(elem);
        }
        of_flow_stats_reply_entries_set(obj, entries);
        of_object_delete(entries);
    }

    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;
}