blob: 10a6b3d168fa2bf36ebec72655db5c903206770b [file] [log] [blame]
Rich Lanea06d0c32013-03-25 08:52:03 -07001:: # 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 Laned983aa52013-06-13 11:48:37 -070028:: include('_copyright.c')
Rich Lanea06d0c32013-03-25 08:52:03 -070029
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 */
42int
43test_has_outport(void)
44{
45 of_list_action_t *list;
46 of_action_t elt;
47 of_action_set_dl_src_t *set_dl_src;
48 of_action_output_t *output;
49
50 set_dl_src = &elt.set_dl_src;
51 output = &elt.output;
52
53 list = of_list_action_new(OF_VERSION_1_0);
54 TEST_ASSERT(list != NULL);
55
56 TEST_ASSERT(of_action_list_has_out_port(list, OF_PORT_DEST_WILDCARD));
57 TEST_ASSERT(!of_action_list_has_out_port(list, 1));
58
59 /* Add some other action */
60 of_action_set_dl_src_init(set_dl_src, OF_VERSION_1_0, -1, 1);
61 TEST_OK(of_list_action_append_bind(list, (of_action_t *)set_dl_src));
62
63 TEST_ASSERT(of_action_list_has_out_port(list, OF_PORT_DEST_WILDCARD));
64 TEST_ASSERT(!of_action_list_has_out_port(list, 1));
65
66 /* Add port 2 */
67 of_action_output_init(output, OF_VERSION_1_0, -1, 1);
68 TEST_OK(of_list_action_append_bind(list, (of_action_t *)output));
69 of_action_output_port_set(output, 2);
70
71 TEST_ASSERT(of_action_list_has_out_port(list, OF_PORT_DEST_WILDCARD));
72 TEST_ASSERT(!of_action_list_has_out_port(list, 1));
73 TEST_ASSERT(of_action_list_has_out_port(list, 2));
74
75 /* Add port 1 */
76 of_action_output_init(output, OF_VERSION_1_0, -1, 1);
77 TEST_OK(of_list_action_append_bind(list, (of_action_t *)output));
78 of_action_output_port_set(output, 1);
79
80 TEST_ASSERT(of_action_list_has_out_port(list, OF_PORT_DEST_WILDCARD));
81 TEST_ASSERT(of_action_list_has_out_port(list, 1));
82 TEST_ASSERT(of_action_list_has_out_port(list, 2));
83
84 /* Start over and put action at front of list */
85 of_list_action_delete(list);
86
87 list = of_list_action_new(OF_VERSION_1_0);
88 TEST_ASSERT(list != NULL);
89
90 /* Add port 2 */
91 of_action_output_init(output, OF_VERSION_1_0, -1, 1);
92 TEST_OK(of_list_action_append_bind(list, (of_action_t *)output));
93 of_action_output_port_set(output, 2);
94
95 TEST_ASSERT(of_action_list_has_out_port(list, OF_PORT_DEST_WILDCARD));
96 TEST_ASSERT(!of_action_list_has_out_port(list, 1));
97 TEST_ASSERT(of_action_list_has_out_port(list, 2));
98
99 /* Add some other action */
100 of_action_set_dl_src_init(set_dl_src, OF_VERSION_1_0, -1, 1);
101 TEST_OK(of_list_action_append_bind(list, (of_action_t *)set_dl_src));
102
103 TEST_ASSERT(of_action_list_has_out_port(list, OF_PORT_DEST_WILDCARD));
104 TEST_ASSERT(!of_action_list_has_out_port(list, 1));
105 TEST_ASSERT(of_action_list_has_out_port(list, 2));
106
107 /* Add port 1 */
108 of_action_output_init(output, OF_VERSION_1_0, -1, 1);
109 TEST_OK(of_list_action_append_bind(list, (of_action_t *)output));
110 of_action_output_port_set(output, 1);
111
112 TEST_ASSERT(of_action_list_has_out_port(list, OF_PORT_DEST_WILDCARD));
113 TEST_ASSERT(of_action_list_has_out_port(list, 1));
114 TEST_ASSERT(of_action_list_has_out_port(list, 2));
115
116 of_list_action_delete(list);
117
118 return TEST_PASS;
119}
120
Rich Lanec73680c2014-02-22 10:44:28 -0800121static int
Rich Lane85aaa652014-03-05 10:12:55 -0800122test_of_object_new_from_message(void)
123{
124 /* v1 OFPT_HELLO, xid=0x12345678 */
125 uint8_t data[] = { 0x01, 0x00, 0x00, 0x08, 0x12, 0x34, 0x56, 0x78 };
126 uint8_t *buf = malloc(sizeof(data));
127 memcpy(buf, data, sizeof(data));
128
129 of_object_t *obj = of_object_new_from_message(buf, sizeof(data));
130
131 TEST_ASSERT(obj != NULL);
132 TEST_ASSERT(obj->version == OF_VERSION_1_0);
133 TEST_ASSERT(obj->object_id == OF_HELLO);
134
135 uint32_t xid;
136 of_hello_xid_get(obj, &xid);
137 TEST_ASSERT(xid == 0x12345678);
138
139 of_object_delete(obj);
140
141 return TEST_PASS;
142}
143
144static int
Rich Lanec73680c2014-02-22 10:44:28 -0800145test_of_object_new_from_message_preallocated(void)
146{
147 /* v1 OFPT_HELLO, xid=0x12345678 */
148 uint8_t buf[] = { 0x01, 0x00, 0x00, 0x08, 0x12, 0x34, 0x56, 0x78 };
149
150 of_object_storage_t storage;
151 of_object_t *obj = of_object_new_from_message_preallocated(
152 &storage, buf, sizeof(buf));
153
154 TEST_ASSERT(obj != NULL);
Rich Lane85aaa652014-03-05 10:12:55 -0800155 TEST_ASSERT(obj->version == OF_VERSION_1_0);
156 TEST_ASSERT(obj->object_id == OF_HELLO);
Rich Lanec73680c2014-02-22 10:44:28 -0800157
158 uint32_t xid;
159 of_hello_xid_get(obj, &xid);
160 TEST_ASSERT(xid == 0x12345678);
161
162 return TEST_PASS;
163}
164
Rich Lanea06d0c32013-03-25 08:52:03 -0700165int
166run_utility_tests(void)
167{
168 RUN_TEST(has_outport);
Rich Lane85aaa652014-03-05 10:12:55 -0800169 RUN_TEST(of_object_new_from_message);
Rich Lanec73680c2014-02-22 10:44:28 -0800170 RUN_TEST(of_object_new_from_message_preallocated);
Rich Lanea06d0c32013-03-25 08:52:03 -0700171 RUN_TEST(dump_objs);
172
173 return TEST_PASS;
174}