[ALTS] Add testing of AV with GRH.
[mirror/winof/.git] / tests / alts / createdestroyav.c
1 /*\r
2  * Copyright (c) 2005 SilverStorm Technologies.  All rights reserved.\r
3  * Copyright (c) 1996-2003 Intel Corporation. All rights reserved. \r
4  *\r
5  * This software is available to you under the OpenIB.org BSD license\r
6  * below:\r
7  *\r
8  *     Redistribution and use in source and binary forms, with or\r
9  *     without modification, are permitted provided that the following\r
10  *     conditions are met:\r
11  *\r
12  *      - Redistributions of source code must retain the above\r
13  *        copyright notice, this list of conditions and the following\r
14  *        disclaimer.\r
15  *\r
16  *      - Redistributions in binary form must reproduce the above\r
17  *        copyright notice, this list of conditions and the following\r
18  *        disclaimer in the documentation and/or other materials\r
19  *        provided with the distribution.\r
20  *\r
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
22  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
23  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
24  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
25  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
26  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
27  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
28  * SOFTWARE.\r
29  *\r
30  * $Id$\r
31  */\r
32 \r
33 \r
34 #include <iba/ib_types.h>\r
35 #include <iba/ib_al.h>\r
36 #include <complib/cl_memory.h>\r
37 #include <alts_debug.h>\r
38 #include <alts_common.h>\r
39 \r
40 /*\r
41  * Function prototypes\r
42  */\r
43 ib_api_status_t\r
44 alts_av(\r
45         boolean_t modify_av_attr\r
46         );\r
47 \r
48 \r
49 /*\r
50  * Test Case CrateDestroyAV\r
51  */\r
52 \r
53 ib_api_status_t\r
54 al_test_create_destroy_av(void)\r
55 {\r
56         boolean_t modify_av_attr = FALSE;\r
57 \r
58         return alts_av(modify_av_attr);\r
59 }\r
60 \r
61 ib_api_status_t\r
62 al_test_query_modify_av(void)\r
63 {\r
64         boolean_t modify_av_attr = TRUE;\r
65 \r
66         return alts_av(modify_av_attr);\r
67 }\r
68 \r
69 \r
70 /* Internal Functions */\r
71 \r
72 ib_api_status_t\r
73 alts_av(\r
74         boolean_t modify_av_attr\r
75         )\r
76 {\r
77         ib_api_status_t ib_status = IB_SUCCESS;\r
78         ib_al_handle_t h_al = NULL;\r
79         size_t guid_count;\r
80         ib_port_attr_t *p_alts_port_attr;\r
81         ib_av_attr_t alts_av_attr, query_av_attr;\r
82         ib_ca_handle_t h_ca;\r
83         ib_pd_handle_t h_pd, h_pd1;\r
84         ib_av_handle_t h_av;\r
85         ib_net64_t ca_guid_array[ALTS_MAX_CA];\r
86         uint32_t bsize;\r
87         ib_ca_attr_t *alts_ca_attr = NULL;\r
88         uint8_t i;\r
89 \r
90         ALTS_ENTER( ALTS_DBG_VERBOSE );\r
91 \r
92         while(1)\r
93         {\r
94                 /* Step 1: Open AL */\r
95                 ib_status = alts_open_al(&h_al);\r
96 \r
97                 if(ib_status != IB_SUCCESS)\r
98                 {\r
99                         ALTS_PRINT( ALTS_DBG_ERROR, \\r
100                                 ("Open AL failed\n"));\r
101                                 break;\r
102                 }\r
103 \r
104                 CL_ASSERT(h_al);\r
105 \r
106                 /*\r
107                  * Step 2: Open the first available CA\r
108                  */\r
109 \r
110                 ib_status = ib_get_ca_guids(h_al, NULL, &guid_count);\r
111                 if(ib_status != IB_INSUFFICIENT_MEMORY)\r
112                 {\r
113                         ALTS_PRINT( ALTS_DBG_ERROR,\r
114                                 ("ib_get_ca_guids failed status = %s\n",ib_get_err_str(ib_status)) );\r
115                         break;\r
116 \r
117                 }\r
118 \r
119                 ALTS_PRINT(ALTS_DBG_INFO, \\r
120                         ("Total number of CA in the sytem is %d\n",(uint32_t)guid_count));\r
121 \r
122                 if(guid_count == 0)\r
123                 {\r
124                         ib_status = IB_ERROR;\r
125                         break;\r
126                 }\r
127 \r
128                 ib_status = ib_get_ca_guids(h_al, ca_guid_array, &guid_count);\r
129                 if(ib_status != IB_SUCCESS)\r
130                 {\r
131                         ALTS_PRINT( ALTS_DBG_ERROR,\r
132                                 ("ib_get_ca_guids failed with status = %s\n", ib_get_err_str(ib_status)) );\r
133                         break;\r
134                 }\r
135 \r
136                 ib_status = ib_open_ca(h_al,\r
137                         ca_guid_array[0],       //Default open the first CA\r
138                         alts_ca_err_cb,\r
139                         (void *)1234,   //ca_context\r
140                         &h_ca);\r
141 \r
142                 if(ib_status != IB_SUCCESS)\r
143                 {\r
144                         ALTS_PRINT( ALTS_DBG_ERROR,\r
145                                 ("ib_open_ca failed with status = %s\n", ib_get_err_str(ib_status)) );\r
146                         break;\r
147 \r
148                 }\r
149                 CL_ASSERT(h_ca);\r
150 \r
151                 /*\r
152                  * Step 3: Query for the CA Attributes\r
153                  */\r
154 \r
155                 /* Query the CA */\r
156                 bsize = 0;\r
157                 ib_status = ib_query_ca(h_ca, NULL, &bsize);\r
158                 if(ib_status != IB_INSUFFICIENT_MEMORY)\r
159                 {\r
160                         ALTS_PRINT(ALTS_DBG_ERROR,\r
161                                 ("ib_query_ca failed with status = %s\n",ib_get_err_str(ib_status)) );\r
162 \r
163                         ib_close_ca(h_ca, alts_ca_destroy_cb);\r
164                         break;\r
165                 }\r
166                 CL_ASSERT(bsize);\r
167 \r
168                 /* Allocate the memory needed for query_ca */\r
169 \r
170                 alts_ca_attr = (ib_ca_attr_t *)cl_zalloc(bsize);\r
171                 CL_ASSERT(alts_ca_attr);\r
172 \r
173                 ib_status = ib_query_ca(h_ca, alts_ca_attr, &bsize);\r
174 \r
175                 if(ib_status != IB_SUCCESS)\r
176                 {\r
177                         ALTS_PRINT( ALTS_DBG_ERROR,\r
178                                 ("ib_query_ca failed with status = %s\n", ib_get_err_str(ib_status)) );\r
179                         ib_close_ca(h_ca, alts_ca_destroy_cb);\r
180                         break;\r
181                 }\r
182 \r
183                 p_alts_port_attr = alts_ca_attr->p_port_attr;\r
184 \r
185                 /*\r
186                  * Step 4: Get the active port\r
187                  */\r
188                 ALTS_PRINT( ALTS_DBG_INFO,      \\r
189                         ("Get the active Port\n"));\r
190 //#if 0\r
191                 for(i=0;i < alts_ca_attr->num_ports; i++)\r
192                 {\r
193                         p_alts_port_attr = &alts_ca_attr->p_port_attr[i];\r
194                         if(p_alts_port_attr->link_state == IB_LINK_ACTIVE)\r
195                                 break;\r
196                 }\r
197 \r
198                 if(p_alts_port_attr->link_state != IB_LINK_ACTIVE)\r
199                 {\r
200                         ALTS_PRINT(ALTS_DBG_ERROR,\r
201                                 ("port attribute link state is not active\n") );\r
202                         ib_close_ca(h_ca, alts_ca_destroy_cb);\r
203                         break;\r
204                 }\r
205 \r
206 \r
207                 ALTS_PRINT(ALTS_DBG_INFO, \\r
208                         ("Active port number is %d\n",p_alts_port_attr->port_num));\r
209 //#endif\r
210 \r
211                 /*\r
212                  * Step 5: Construct the AV structure\r
213                  */\r
214 \r
215                 alts_av_attr.port_num = p_alts_port_attr->port_num;\r
216                 //DLID is SM LID\r
217                 alts_av_attr.dlid = p_alts_port_attr->sm_lid;\r
218 \r
219                 alts_av_attr.sl = 0;\r
220                 alts_av_attr.static_rate = IB_PATH_RECORD_RATE_10_GBS;\r
221                 alts_av_attr.path_bits = 0;\r
222                 alts_av_attr.grh_valid = TRUE;\r
223 \r
224                 alts_av_attr.grh.dest_gid.unicast.interface_id= ca_guid_array[0];\r
225                 alts_av_attr.grh.src_gid.unicast.interface_id = ca_guid_array[0];\r
226                 alts_av_attr.grh.hop_limit = 0;\r
227                 alts_av_attr.grh.ver_class_flow = 0;\r
228                 /*\r
229                  * step 6: Create a PD\r
230                  */\r
231 \r
232                 /* NOTE Try creating PD for IB_PDT_ALIAS type */\r
233 \r
234                 ib_status = ib_alloc_pd(h_ca, IB_PDT_NORMAL, (void *)1234, &h_pd);\r
235                 if(ib_status != IB_SUCCESS)\r
236                 {\r
237                         ALTS_PRINT( ALTS_DBG_ERROR,\r
238                                 ("ib_alloc_pd failed with status = %s\n",ib_get_err_str(ib_status)) );\r
239                         ib_close_ca(h_ca, alts_ca_destroy_cb);\r
240                         break;\r
241                 }\r
242 \r
243 \r
244 \r
245                 /*\r
246                  * Step 7: Create the Address Vector\r
247                  */\r
248                 ib_status =     ib_create_av(h_pd, &alts_av_attr, &h_av);\r
249                 if(ib_status != IB_SUCCESS)\r
250                 {\r
251                         ALTS_PRINT( ALTS_DBG_ERROR,\r
252                                 ("ib_create_av failed with status = %s\n",ib_get_err_str(ib_status)) );\r
253                         ib_status = ib_dealloc_pd(h_pd,alts_pd_destroy_cb);\r
254                         ib_close_ca(h_ca, alts_ca_destroy_cb);\r
255                         break;\r
256                 }\r
257                 if(modify_av_attr == TRUE)\r
258                 {\r
259                         /*\r
260                          * Query the AV fromt the handle\r
261                          */\r
262                         ib_status = ib_query_av(h_av, &query_av_attr, &h_pd1);\r
263                         if(ib_status != IB_SUCCESS)\r
264                         {\r
265                                 ALTS_PRINT( ALTS_DBG_ERROR,\r
266                                         ("ib_query_av failed with status = %s\n",ib_get_err_str(ib_status)) );\r
267 \r
268                                 ib_destroy_av(h_av);\r
269                                 ib_status = ib_dealloc_pd(h_pd,alts_pd_destroy_cb);\r
270                                 ib_close_ca(h_ca, alts_ca_destroy_cb);\r
271                                 break;\r
272                         }\r
273 \r
274                         query_av_attr.dlid = p_alts_port_attr->lid; //DLID is local lid;\r
275 \r
276                         ib_status = ib_modify_av(h_av, &query_av_attr);\r
277                         if(ib_status != IB_SUCCESS)\r
278                         {\r
279                                 ALTS_PRINT( ALTS_DBG_ERROR,\r
280                                         ("ib_modify_av failed with status = %s\n",ib_get_err_str(ib_status)) );\r
281                                 ib_destroy_av(h_av);\r
282                                 ib_status = ib_dealloc_pd(h_pd,alts_pd_destroy_cb);\r
283                                 ib_close_ca(h_ca, alts_ca_destroy_cb);\r
284                                 break;\r
285                         }\r
286                         /* Again query the AV to verify the modified value*/\r
287                         ib_status = ib_query_av(h_av, &query_av_attr, &h_pd1);\r
288                         if(ib_status != IB_SUCCESS)\r
289                         {\r
290                                 ALTS_PRINT( ALTS_DBG_ERROR,\r
291                                         ("ib_query_av failed with status = %s\n", ib_get_err_str(ib_status)) );\r
292 \r
293                                 ib_destroy_av(h_av);\r
294                                 ib_status = ib_dealloc_pd(h_pd,alts_pd_destroy_cb);\r
295                                 ib_close_ca(h_ca, alts_ca_destroy_cb);\r
296                                 break;\r
297                         }\r
298                         CL_ASSERT(query_av_attr.dlid == p_alts_port_attr->lid);\r
299                         ALTS_PRINT( ALTS_DBG_INFO,\r
300                                         ("ib_modify_av PASSED\n") );\r
301 \r
302 \r
303 \r
304                 }\r
305 \r
306 \r
307                 /*\r
308                  * Destroy the address Vector\r
309                  */\r
310                 ib_status = ib_destroy_av(h_av);\r
311                 if(ib_status != IB_SUCCESS)\r
312                 {\r
313                         ALTS_PRINT( ALTS_DBG_ERROR,\r
314                                 ("ib_destroy_av failed with status = %s\n", ib_get_err_str(ib_status)) );\r
315                         ib_status = ib_dealloc_pd(h_pd,alts_pd_destroy_cb);\r
316                         ib_close_ca(h_ca, alts_ca_destroy_cb);\r
317                         break;\r
318                 }\r
319 \r
320                 ib_status = ib_dealloc_pd(h_pd,alts_pd_destroy_cb);\r
321                 ib_close_ca(h_ca, alts_ca_destroy_cb);\r
322                 break; //End of while\r
323         }\r
324 \r
325         /* Close AL */\r
326         if(h_al)\r
327                 alts_close_al(h_al);\r
328         if(alts_ca_attr)\r
329                 cl_free(alts_ca_attr);\r
330 \r
331         ALTS_EXIT( ALTS_DBG_VERBOSE);\r
332         return ib_status;\r
333 }\r