]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/ofed/management/opensm/osmtest/include/osmtest_subnet.h
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / ofed / management / opensm / osmtest / include / osmtest_subnet.h
1 /*
2  * Copyright (c) 2006 Voltaire, Inc. All rights reserved.
3  * Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved.
4  * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
5  *
6  * This software is available to you under a choice of one of two
7  * licenses.  You may choose to be licensed under the terms of the GNU
8  * General Public License (GPL) Version 2, available from the file
9  * COPYING in the main directory of this source tree, or the
10  * OpenIB.org BSD license below:
11  *
12  *     Redistribution and use in source and binary forms, with or
13  *     without modification, are permitted provided that the following
14  *     conditions are met:
15  *
16  *      - Redistributions of source code must retain the above
17  *        copyright notice, this list of conditions and the following
18  *        disclaimer.
19  *
20  *      - Redistributions in binary form must reproduce the above
21  *        copyright notice, this list of conditions and the following
22  *        disclaimer in the documentation and/or other materials
23  *        provided with the distribution.
24  *
25  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32  * SOFTWARE.
33  *
34  */
35
36 /*
37  * Abstract:
38  *      Declaration of osmtest_t.
39  *      This object represents the OSMTest Test object.
40  *
41  */
42
43 #ifndef _OSMTEST_SUBNET_H_
44 #define _OSMTEST_SUBNET_H_
45
46 #include <stdlib.h>
47 #include <complib/cl_qmap.h>
48 #include <opensm/osm_log.h>
49 #include <vendor/osm_vendor_api.h>
50 #include <opensm/osm_mad_pool.h>
51 #include <opensm/osm_helper.h>
52
53 /****s* Subnet Database/generic_t
54 * NAME
55 *       generic_t
56 *
57 * DESCRIPTION
58 *       Subnet database object for fields common to all record types.
59 *       All other database types must be castable to this type.
60 *
61 * SYNOPSIS
62 */
63 typedef struct _generic {
64         cl_map_item_t map_item; /* must be first element! */
65         uint32_t count;         /* must be second element! */
66 } generic_t;
67
68 /*
69 * FIELDS
70 *
71 * SEE ALSO
72 *********/
73
74 /****s* Subnet Database/node_t
75 * NAME
76 *       node_t
77 *
78 * DESCRIPTION
79 *       Subnet database object for nodes.
80 *       Must be castable to generic_t.
81 *
82 * SYNOPSIS
83 */
84 typedef struct _node {
85         cl_map_item_t map_item; /* must be first element! */
86         uint32_t count;         /* must be second element! */
87         ib_node_record_t rec;
88         ib_node_record_t comp;
89 } node_t;
90
91 /*
92 * FIELDS
93 * map_item
94 *       Provides linkage for the qmap container.
95 *
96 * rec
97 *       NodeRecord for this node as read from the database file.
98 *
99 * comp
100 *       NodeRecord indicating which fields should be compared against rec.
101 *       Bits set in the comp NodeRecord indicate that bit in the rec structure
102 *       should be compared against real-time data from the SA.
103 *
104 * count
105 *       Utility counter used by the validation logic.  Typically used to
106 *       to indicate the number of times a matching node was received from
107 *       the SA.
108 *
109 * SEE ALSO
110 *********/
111
112 static inline node_t *node_new(void)
113 {
114         node_t *p_obj;
115
116         p_obj = malloc(sizeof(*p_obj));
117         if (p_obj)
118                 memset(p_obj, 0, sizeof(*p_obj));
119         return (p_obj);
120 }
121
122 static inline void node_delete(IN node_t * p_obj)
123 {
124         free(p_obj);
125 }
126
127 /****s* Subnet Database/port_t
128 * NAME
129 *       port_t
130 *
131 * DESCRIPTION
132 *       Subnet database object for ports.
133 *       Must be castable to generic_t.
134 *
135 * SYNOPSIS
136 */
137 typedef struct _port {
138         cl_map_item_t map_item; /* must be first element! */
139         uint32_t count;         /* must be second element! */
140         /* Since there is no unique identifier for all ports we
141            must be able to have such a key by the lid and port num */
142         uint64_t port_id;
143         ib_portinfo_record_t rec;
144         ib_portinfo_record_t comp;
145 } port_t;
146
147 /*
148 * FIELDS
149 *
150 * map_item
151 *       Provides linkage for the qmap container.
152 *
153 * rec
154 *       PortInfoRecord for this port as read from the database file.
155 *
156 * comp
157 *       PortInfoRecord indicating which fields should be compared against rec.
158 *       Bits set in the comp NodeRecord indicate that bit in the rec structure
159 *       should be compared against real-time data from the SA.
160 *
161 * count
162 *       Utility counter used by the validation logic.  Typically used to
163 *       to indicate the number of times a matching node was received from
164 *       the SA.
165 *
166 * SEE ALSO
167 *********/
168
169 static inline port_t *port_new(void)
170 {
171         port_t *p_obj;
172
173         p_obj = malloc(sizeof(*p_obj));
174         if (p_obj)
175                 memset(p_obj, 0, sizeof(*p_obj));
176         return (p_obj);
177 }
178
179 static inline void port_delete(IN port_t * p_obj)
180 {
181         free(p_obj);
182 }
183
184 static inline uint64_t
185 port_gen_id(IN ib_net16_t const lid, IN uint8_t const port_num)
186 {
187         return (lid << 8 | port_num);
188 }
189
190 static inline void
191 port_ext_id(IN uint64_t id, IN ib_net16_t * p_lid, IN uint8_t * p_port_num)
192 {
193         CL_ASSERT((id & 0xFF) < 0x100);
194         *p_port_num = (uint8_t) (id & 0xFF);
195         CL_ASSERT(((id >> 8) & 0xFFFF) < 0x10000);
196         *p_lid = (uint16_t) ((id >> 8) & 0xFFFF);
197 }
198
199 static inline void
200 port_set_id(IN port_t * p_obj,
201             IN ib_net16_t const lid, IN uint8_t const port_num)
202 {
203         p_obj->port_id = port_gen_id(lid, port_num);
204 }
205
206 static inline void
207 port_get_id(IN port_t * p_obj, IN ib_net16_t * p_lid, IN uint8_t * p_port_num)
208 {
209         port_ext_id(p_obj->port_id, p_lid, p_port_num);
210 }
211
212 /****s* Subnet Database/path_t
213 * NAME
214 *       node_t
215 *
216 * DESCRIPTION
217 *       Subnet database object for paths.
218 *       Must be castable to generic_t.
219 *
220 * SYNOPSIS
221 */
222 typedef struct _path {
223         cl_map_item_t map_item; /* must be first element! */
224         uint32_t count;         /* must be second element! */
225         ib_path_rec_t rec;
226         ib_path_rec_t comp;
227 } path_t;
228
229 /*
230 * FIELDS
231 * map_item
232 *       Provides linkage for the qmap container.
233 *
234 * rec
235 *       PathRecord for this path as read from the database file.
236 *
237 * comp
238 *       PathRecord indicating which fields should be compared against rec.
239 *       Bits set in the comp PathRecord indicate that bit in the rec structure
240 *       should be compared against real-time data from the SA.
241 *
242 * count
243 *       Utility counter used by the validation logic.  Typically used to
244 *       to indicate the number of times a matching node was received from
245 *       the SA.
246 *
247 * SEE ALSO
248 *********/
249
250 static inline path_t *path_new(void)
251 {
252         path_t *p_obj;
253
254         p_obj = malloc(sizeof(*p_obj));
255         if (p_obj)
256                 memset(p_obj, 0, sizeof(*p_obj));
257         return (p_obj);
258 }
259
260 static inline void path_delete(IN path_t * p_obj)
261 {
262         free(p_obj);
263 }
264
265 /****s* Subnet Database/subnet_t
266 * NAME
267 *       subnet_t
268 *
269 * DESCRIPTION
270 *       Subnet database object.
271 *
272 * SYNOPSIS
273 */
274 typedef struct _subnet {
275         cl_qmap_t node_lid_tbl;
276         cl_qmap_t node_guid_tbl;
277         cl_qmap_t mgrp_mlid_tbl;
278         /* cl_qmap_t port_lid_tbl; */
279         /* cl_qmap_t port_guid_tbl; */
280         cl_qmap_t port_key_tbl;
281         cl_qmap_t link_tbl;
282         cl_qmap_t path_tbl;
283 } subnet_t;
284
285 /*
286 * FIELDS
287 *
288 * SEE ALSO
289 *********/
290
291 /****f* Subnet Database/subnet_construct
292 * NAME
293 *       subnet_construct
294 *
295 * DESCRIPTION
296 *       This function constructs an subnet database object.
297 *       This function cannot fail.
298 *
299 * SYNOPSIS
300 */
301 void subnet_construct(IN subnet_t * const p_subn);
302
303 /*
304 * FIELDS
305 *
306 * SEE ALSO
307 *********/
308
309 /****f* Subnet Database/subnet_init
310 * NAME
311 *       subnet_init
312 *
313 * DESCRIPTION
314 *       This function initializes an subnet database object.
315 *
316 * SYNOPSIS
317 */
318 cl_status_t subnet_init(IN subnet_t * const p_subn);
319
320 /*
321 * FIELDS
322 *
323 * SEE ALSO
324 *********/
325
326 #endif