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 | :: |
Rich Lane | d983aa5 | 2013-06-13 11:48:37 -0700 | [diff] [blame] | 28 | :: include('_copyright.c') |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 29 | |
| 30 | /** |
| 31 | * |
| 32 | * Test utility functions |
| 33 | * |
| 34 | */ |
| 35 | |
| 36 | #include <locitest/test_common.h> |
| 37 | #include <loci/of_utils.h> |
| 38 | |
| 39 | /** |
| 40 | * Test has output port utility function |
| 41 | */ |
| 42 | int |
| 43 | test_has_outport(void) |
| 44 | { |
| 45 | of_list_action_t *list; |
Rich Lane | e499bd1 | 2014-10-28 15:25:09 -0700 | [diff] [blame] | 46 | of_object_t set_dl_src; |
| 47 | of_object_t output; |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 48 | |
| 49 | list = of_list_action_new(OF_VERSION_1_0); |
| 50 | TEST_ASSERT(list != NULL); |
| 51 | |
| 52 | TEST_ASSERT(of_action_list_has_out_port(list, OF_PORT_DEST_WILDCARD)); |
| 53 | TEST_ASSERT(!of_action_list_has_out_port(list, 1)); |
| 54 | |
| 55 | /* Add some other action */ |
Rich Lane | e499bd1 | 2014-10-28 15:25:09 -0700 | [diff] [blame] | 56 | of_action_set_dl_src_init(&set_dl_src, OF_VERSION_1_0, -1, 1); |
| 57 | TEST_OK(of_list_action_append_bind(list, &set_dl_src)); |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 58 | |
| 59 | TEST_ASSERT(of_action_list_has_out_port(list, OF_PORT_DEST_WILDCARD)); |
| 60 | TEST_ASSERT(!of_action_list_has_out_port(list, 1)); |
| 61 | |
| 62 | /* Add port 2 */ |
Rich Lane | e499bd1 | 2014-10-28 15:25:09 -0700 | [diff] [blame] | 63 | of_action_output_init(&output, OF_VERSION_1_0, -1, 1); |
| 64 | TEST_OK(of_list_action_append_bind(list, &output)); |
| 65 | of_action_output_port_set(&output, 2); |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 66 | |
| 67 | TEST_ASSERT(of_action_list_has_out_port(list, OF_PORT_DEST_WILDCARD)); |
| 68 | TEST_ASSERT(!of_action_list_has_out_port(list, 1)); |
| 69 | TEST_ASSERT(of_action_list_has_out_port(list, 2)); |
| 70 | |
| 71 | /* Add port 1 */ |
Rich Lane | e499bd1 | 2014-10-28 15:25:09 -0700 | [diff] [blame] | 72 | of_action_output_init(&output, OF_VERSION_1_0, -1, 1); |
| 73 | TEST_OK(of_list_action_append_bind(list, &output)); |
| 74 | of_action_output_port_set(&output, 1); |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 75 | |
| 76 | TEST_ASSERT(of_action_list_has_out_port(list, OF_PORT_DEST_WILDCARD)); |
| 77 | TEST_ASSERT(of_action_list_has_out_port(list, 1)); |
| 78 | TEST_ASSERT(of_action_list_has_out_port(list, 2)); |
| 79 | |
| 80 | /* Start over and put action at front of list */ |
| 81 | of_list_action_delete(list); |
| 82 | |
| 83 | list = of_list_action_new(OF_VERSION_1_0); |
| 84 | TEST_ASSERT(list != NULL); |
| 85 | |
| 86 | /* Add port 2 */ |
Rich Lane | e499bd1 | 2014-10-28 15:25:09 -0700 | [diff] [blame] | 87 | of_action_output_init(&output, OF_VERSION_1_0, -1, 1); |
| 88 | TEST_OK(of_list_action_append_bind(list, &output)); |
| 89 | of_action_output_port_set(&output, 2); |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 90 | |
| 91 | TEST_ASSERT(of_action_list_has_out_port(list, OF_PORT_DEST_WILDCARD)); |
| 92 | TEST_ASSERT(!of_action_list_has_out_port(list, 1)); |
| 93 | TEST_ASSERT(of_action_list_has_out_port(list, 2)); |
| 94 | |
| 95 | /* Add some other action */ |
Rich Lane | e499bd1 | 2014-10-28 15:25:09 -0700 | [diff] [blame] | 96 | of_action_set_dl_src_init(&set_dl_src, OF_VERSION_1_0, -1, 1); |
| 97 | TEST_OK(of_list_action_append_bind(list, &set_dl_src)); |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 98 | |
| 99 | TEST_ASSERT(of_action_list_has_out_port(list, OF_PORT_DEST_WILDCARD)); |
| 100 | TEST_ASSERT(!of_action_list_has_out_port(list, 1)); |
| 101 | TEST_ASSERT(of_action_list_has_out_port(list, 2)); |
| 102 | |
| 103 | /* Add port 1 */ |
Rich Lane | e499bd1 | 2014-10-28 15:25:09 -0700 | [diff] [blame] | 104 | of_action_output_init(&output, OF_VERSION_1_0, -1, 1); |
| 105 | TEST_OK(of_list_action_append_bind(list, &output)); |
| 106 | of_action_output_port_set(&output, 1); |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 107 | |
| 108 | TEST_ASSERT(of_action_list_has_out_port(list, OF_PORT_DEST_WILDCARD)); |
| 109 | TEST_ASSERT(of_action_list_has_out_port(list, 1)); |
| 110 | TEST_ASSERT(of_action_list_has_out_port(list, 2)); |
| 111 | |
| 112 | of_list_action_delete(list); |
| 113 | |
| 114 | return TEST_PASS; |
| 115 | } |
| 116 | |
Rich Lane | c73680c | 2014-02-22 10:44:28 -0800 | [diff] [blame] | 117 | static int |
Rich Lane | 85aaa65 | 2014-03-05 10:12:55 -0800 | [diff] [blame] | 118 | test_of_object_new_from_message(void) |
| 119 | { |
| 120 | /* v1 OFPT_HELLO, xid=0x12345678 */ |
| 121 | uint8_t data[] = { 0x01, 0x00, 0x00, 0x08, 0x12, 0x34, 0x56, 0x78 }; |
| 122 | uint8_t *buf = malloc(sizeof(data)); |
| 123 | memcpy(buf, data, sizeof(data)); |
| 124 | |
| 125 | of_object_t *obj = of_object_new_from_message(buf, sizeof(data)); |
| 126 | |
| 127 | TEST_ASSERT(obj != NULL); |
| 128 | TEST_ASSERT(obj->version == OF_VERSION_1_0); |
| 129 | TEST_ASSERT(obj->object_id == OF_HELLO); |
| 130 | |
| 131 | uint32_t xid; |
| 132 | of_hello_xid_get(obj, &xid); |
| 133 | TEST_ASSERT(xid == 0x12345678); |
| 134 | |
| 135 | of_object_delete(obj); |
| 136 | |
| 137 | return TEST_PASS; |
| 138 | } |
| 139 | |
| 140 | static int |
Rich Lane | c73680c | 2014-02-22 10:44:28 -0800 | [diff] [blame] | 141 | test_of_object_new_from_message_preallocated(void) |
| 142 | { |
| 143 | /* v1 OFPT_HELLO, xid=0x12345678 */ |
| 144 | uint8_t buf[] = { 0x01, 0x00, 0x00, 0x08, 0x12, 0x34, 0x56, 0x78 }; |
| 145 | |
| 146 | of_object_storage_t storage; |
| 147 | of_object_t *obj = of_object_new_from_message_preallocated( |
| 148 | &storage, buf, sizeof(buf)); |
| 149 | |
| 150 | TEST_ASSERT(obj != NULL); |
Rich Lane | 85aaa65 | 2014-03-05 10:12:55 -0800 | [diff] [blame] | 151 | TEST_ASSERT(obj->version == OF_VERSION_1_0); |
| 152 | TEST_ASSERT(obj->object_id == OF_HELLO); |
Rich Lane | c73680c | 2014-02-22 10:44:28 -0800 | [diff] [blame] | 153 | |
| 154 | uint32_t xid; |
| 155 | of_hello_xid_get(obj, &xid); |
| 156 | TEST_ASSERT(xid == 0x12345678); |
| 157 | |
| 158 | return TEST_PASS; |
| 159 | } |
| 160 | |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 161 | int |
| 162 | run_utility_tests(void) |
| 163 | { |
| 164 | RUN_TEST(has_outport); |
Rich Lane | 85aaa65 | 2014-03-05 10:12:55 -0800 | [diff] [blame] | 165 | RUN_TEST(of_object_new_from_message); |
Rich Lane | c73680c | 2014-02-22 10:44:28 -0800 | [diff] [blame] | 166 | RUN_TEST(of_object_new_from_message_preallocated); |
Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 167 | RUN_TEST(dump_objs); |
| 168 | |
| 169 | return TEST_PASS; |
| 170 | } |