static int test_validate_tlv16_list(void) { of_flow_modify_t *obj = of_flow_modify_new(OF_VERSION_1_0); of_list_action_t list; of_action_set_tp_dst_t element1; of_action_output_t element2; of_message_t msg; of_flow_modify_actions_bind(obj, &list); of_action_set_tp_dst_init(&element1, OF_VERSION_1_0, -1, 1); of_list_action_append_bind(&list, (of_action_t *)&element1); of_action_output_init(&element2, OF_VERSION_1_0, -1, 1); of_list_action_append_bind(&list, (of_action_t *)&element2); msg = OF_OBJECT_TO_MESSAGE(obj); TEST_ASSERT(of_validate_message(msg, of_message_length_get(msg)) == 0); of_message_length_set(msg, of_message_length_get(msg) - 1); TEST_ASSERT(of_validate_message(msg, of_message_length_get(msg)) == -1); of_message_length_set(msg, of_message_length_get(msg) + 2); TEST_ASSERT(of_validate_message(msg, of_message_length_get(msg)) == -1); of_flow_modify_delete(obj); return TEST_PASS; }
:: import of_g :: from loxi_utils import loxi_utils :: from loxi_front_end import type_maps /** * Test message validator * * Run the message validator on corrupt messages to ensure it catches them. */ #include "loci_log.h" #include <locitest/test_common.h> #include <loci/loci_validator.h> static int test_validate_fixed_length(void) { of_table_stats_request_t *obj = of_table_stats_request_new(OF_VERSION_1_0); of_message_t msg = OF_OBJECT_TO_MESSAGE(obj); TEST_ASSERT(of_validate_message(msg, of_message_length_get(msg)) == 0); of_message_length_set(msg, of_message_length_get(msg) - 1); TEST_ASSERT(of_validate_message(msg, of_message_length_get(msg)) == -1); of_table_stats_request_delete(obj); return TEST_PASS; }
static int test_validate_fixed_length(void) { of_table_stats_request_t *obj = of_table_stats_request_new(OF_VERSION_1_0); of_message_t msg = OF_OBJECT_TO_MESSAGE(obj); TEST_ASSERT(of_validate_message(msg, of_message_length_get(msg)) == 0); of_message_length_set(msg, of_message_length_get(msg) - 1); TEST_ASSERT(of_validate_message(msg, of_message_length_get(msg)) == -1); of_table_stats_request_delete(obj); return TEST_PASS; }
of_object_t * of_object_new_from_message_preallocated(of_object_storage_t *storage, uint8_t *buf, int len) { of_object_t *obj = &storage->obj; of_wire_buffer_t *wbuf = &storage->wbuf; of_message_t msg = buf; of_version_t version; of_object_id_t object_id; memset(storage, 0, sizeof(*storage)); version = of_message_version_get(msg); if (!OF_VERSION_OKAY(version)) { return NULL; } if (of_validate_message(msg, len) != 0) { LOCI_LOG_ERROR("message validation failed\n"); return NULL; } obj->version = version; obj->wbuf = wbuf; wbuf->buf = msg; wbuf->alloc_bytes = len; wbuf->current_bytes = len; of_header_wire_object_id_get(obj, &object_id); of_object_init_map[object_id](obj, version, len, 0); return obj; }
of_object_t * of_object_new_from_message(of_message_t msg, int len) { of_object_id_t object_id; of_object_t *obj; of_version_t version; version = of_message_version_get(msg); if (!OF_VERSION_OKAY(version)) { return NULL; } if (of_validate_message(msg, len) != 0) { LOCI_LOG_ERROR("message validation failed\n"); return NULL; } if ((obj = of_object_new(-1)) == NULL) { return NULL; } if (of_object_buffer_bind(obj, OF_MESSAGE_TO_BUFFER(msg), len, OF_MESSAGE_FREE_FUNCTION) < 0) { FREE(obj); return NULL; } obj->version = version; of_header_wire_object_id_get(obj, &object_id); of_object_init_map[object_id](obj, version, len, 0); return obj; }
static int test_validate_fixed_length_list(void) { of_table_stats_reply_t *obj = of_table_stats_reply_new(OF_VERSION_1_0); of_list_table_stats_entry_t list; of_table_stats_entry_t element; of_message_t msg; of_table_stats_reply_entries_bind(obj, &list); of_table_stats_entry_init(&element, OF_VERSION_1_0, -1, 1); of_list_table_stats_entry_append_bind(&list, &element); of_list_table_stats_entry_append_bind(&list, &element); msg = OF_OBJECT_TO_MESSAGE(obj); TEST_ASSERT(of_validate_message(msg, of_message_length_get(msg)) == 0); of_message_length_set(msg, of_message_length_get(msg) - 1); TEST_ASSERT(of_validate_message(msg, of_message_length_get(msg)) == -1); of_table_stats_reply_delete(obj); return TEST_PASS; }