Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 1 | :: # Copyright 2013, Big Switch Networks, Inc. |
| 2 | :: # |
| 3 | :: # LoxiGen is licensed under the Eclipse Public License, version 1.0 (EPL), with |
| 4 | :: # the following special exception: |
| 5 | :: # |
| 6 | :: # LOXI Exception |
| 7 | :: # |
| 8 | :: # As a special exception to the terms of the EPL, you may distribute libraries |
| 9 | :: # generated by LoxiGen (LoxiGen Libraries) under the terms of your choice, provided |
| 10 | :: # that copyright and licensing notices generated by LoxiGen are not altered or removed |
| 11 | :: # from the LoxiGen Libraries and the notice provided below is (i) included in |
| 12 | :: # the LoxiGen Libraries, if distributed in source code form and (ii) included in any |
| 13 | :: # documentation for the LoxiGen Libraries, if distributed in binary form. |
| 14 | :: # |
| 15 | :: # Notice: "Copyright 2013, Big Switch Networks, Inc. This library was generated by the LoxiGen Compiler." |
| 16 | :: # |
| 17 | :: # You may not use this file except in compliance with the EPL or LOXI Exception. You may obtain |
| 18 | :: # a copy of the EPL at: |
| 19 | :: # |
| 20 | :: # http://www.eclipse.org/legal/epl-v10.html |
| 21 | :: # |
| 22 | :: # Unless required by applicable law or agreed to in writing, software |
| 23 | :: # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 24 | :: # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 25 | :: # EPL for the specific language governing permissions and limitations |
| 26 | :: # under the EPL. |
| 27 | :: |
| 28 | /* Copyright 2013, Big Switch Networks, Inc. */ |
| 29 | |
| 30 | /** |
| 31 | * Test message validator |
| 32 | * |
| 33 | * Run the message validator on corrupt messages to ensure it catches them. |
| 34 | */ |
| 35 | |
| 36 | #include "loci_log.h" |
| 37 | |
| 38 | #include <locitest/test_common.h> |
| 39 | #include <loci/loci_validator.h> |
| 40 | |
| 41 | static int |
| 42 | test_validate_fixed_length(void) |
| 43 | { |
| 44 | of_table_stats_request_t *obj = of_table_stats_request_new(OF_VERSION_1_0); |
| 45 | of_message_t msg = OF_OBJECT_TO_MESSAGE(obj); |
| 46 | |
| 47 | TEST_ASSERT(of_validate_message(msg, of_message_length_get(msg)) == 0); |
| 48 | |
| 49 | of_message_length_set(msg, of_message_length_get(msg) - 1); |
| 50 | TEST_ASSERT(of_validate_message(msg, of_message_length_get(msg)) == -1); |
| 51 | |
| 52 | of_table_stats_request_delete(obj); |
| 53 | return TEST_PASS; |
| 54 | } |
| 55 | |
| 56 | static int |
| 57 | test_validate_fixed_length_list(void) |
| 58 | { |
| 59 | of_table_stats_reply_t *obj = of_table_stats_reply_new(OF_VERSION_1_0); |
| 60 | of_list_table_stats_entry_t list; |
| 61 | of_table_stats_entry_t element; |
| 62 | of_message_t msg; |
| 63 | of_table_stats_reply_entries_bind(obj, &list); |
| 64 | of_table_stats_entry_init(&element, OF_VERSION_1_0, -1, 1); |
| 65 | of_list_table_stats_entry_append_bind(&list, &element); |
| 66 | of_list_table_stats_entry_append_bind(&list, &element); |
| 67 | msg = OF_OBJECT_TO_MESSAGE(obj); |
| 68 | |
| 69 | TEST_ASSERT(of_validate_message(msg, of_message_length_get(msg)) == 0); |
| 70 | |
| 71 | of_message_length_set(msg, of_message_length_get(msg) - 1); |
| 72 | TEST_ASSERT(of_validate_message(msg, of_message_length_get(msg)) == -1); |
| 73 | |
| 74 | of_table_stats_reply_delete(obj); |
| 75 | return TEST_PASS; |
| 76 | } |
| 77 | |
| 78 | static int |
| 79 | test_validate_tlv16_list(void) |
| 80 | { |
| 81 | of_flow_modify_t *obj = of_flow_modify_new(OF_VERSION_1_0); |
| 82 | of_list_action_t list; |
| 83 | of_action_set_tp_dst_t element1; |
| 84 | of_action_output_t element2; |
| 85 | of_message_t msg; |
| 86 | of_flow_modify_actions_bind(obj, &list); |
| 87 | of_action_set_tp_dst_init(&element1, OF_VERSION_1_0, -1, 1); |
| 88 | of_list_action_append_bind(&list, (of_action_t *)&element1); |
| 89 | of_action_output_init(&element2, OF_VERSION_1_0, -1, 1); |
| 90 | of_list_action_append_bind(&list, (of_action_t *)&element2); |
| 91 | msg = OF_OBJECT_TO_MESSAGE(obj); |
| 92 | |
| 93 | TEST_ASSERT(of_validate_message(msg, of_message_length_get(msg)) == 0); |
| 94 | |
| 95 | of_message_length_set(msg, of_message_length_get(msg) - 1); |
| 96 | TEST_ASSERT(of_validate_message(msg, of_message_length_get(msg)) == -1); |
| 97 | |
| 98 | of_message_length_set(msg, of_message_length_get(msg) + 2); |
| 99 | TEST_ASSERT(of_validate_message(msg, of_message_length_get(msg)) == -1); |
| 100 | |
| 101 | of_flow_modify_delete(obj); |
| 102 | return TEST_PASS; |
| 103 | } |
| 104 | |
| 105 | int |
| 106 | run_validator_tests(void) |
| 107 | { |
| 108 | RUN_TEST(validate_fixed_length); |
| 109 | RUN_TEST(validate_fixed_length_list); |
| 110 | RUN_TEST(validate_tlv16_list); |
| 111 | |
| 112 | return TEST_PASS; |
| 113 | } |