xref: /freebsd/contrib/ofed/opensm/libvendor/osm_pkt_randomizer.c (revision 87181516ef48be852d5e5fee53c6e0dbfc62f21e)
1*d6b92ffaSHans Petter Selasky /*
2*d6b92ffaSHans Petter Selasky  * Copyright (c) 2004-2008 Voltaire, Inc. All rights reserved.
3*d6b92ffaSHans Petter Selasky  * Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved.
4*d6b92ffaSHans Petter Selasky  * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
5*d6b92ffaSHans Petter Selasky  *
6*d6b92ffaSHans Petter Selasky  * This software is available to you under a choice of one of two
7*d6b92ffaSHans Petter Selasky  * licenses.  You may choose to be licensed under the terms of the GNU
8*d6b92ffaSHans Petter Selasky  * General Public License (GPL) Version 2, available from the file
9*d6b92ffaSHans Petter Selasky  * COPYING in the main directory of this source tree, or the
10*d6b92ffaSHans Petter Selasky  * OpenIB.org BSD license below:
11*d6b92ffaSHans Petter Selasky  *
12*d6b92ffaSHans Petter Selasky  *     Redistribution and use in source and binary forms, with or
13*d6b92ffaSHans Petter Selasky  *     without modification, are permitted provided that the following
14*d6b92ffaSHans Petter Selasky  *     conditions are met:
15*d6b92ffaSHans Petter Selasky  *
16*d6b92ffaSHans Petter Selasky  *      - Redistributions of source code must retain the above
17*d6b92ffaSHans Petter Selasky  *        copyright notice, this list of conditions and the following
18*d6b92ffaSHans Petter Selasky  *        disclaimer.
19*d6b92ffaSHans Petter Selasky  *
20*d6b92ffaSHans Petter Selasky  *      - Redistributions in binary form must reproduce the above
21*d6b92ffaSHans Petter Selasky  *        copyright notice, this list of conditions and the following
22*d6b92ffaSHans Petter Selasky  *        disclaimer in the documentation and/or other materials
23*d6b92ffaSHans Petter Selasky  *        provided with the distribution.
24*d6b92ffaSHans Petter Selasky  *
25*d6b92ffaSHans Petter Selasky  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26*d6b92ffaSHans Petter Selasky  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27*d6b92ffaSHans Petter Selasky  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28*d6b92ffaSHans Petter Selasky  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29*d6b92ffaSHans Petter Selasky  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30*d6b92ffaSHans Petter Selasky  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31*d6b92ffaSHans Petter Selasky  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32*d6b92ffaSHans Petter Selasky  * SOFTWARE.
33*d6b92ffaSHans Petter Selasky  *
34*d6b92ffaSHans Petter Selasky  */
35*d6b92ffaSHans Petter Selasky 
36*d6b92ffaSHans Petter Selasky /*
37*d6b92ffaSHans Petter Selasky  * Abstract:
38*d6b92ffaSHans Petter Selasky  *    Implementation of osm_pkt_randomizer_t.
39*d6b92ffaSHans Petter Selasky  *
40*d6b92ffaSHans Petter Selasky  */
41*d6b92ffaSHans Petter Selasky 
42*d6b92ffaSHans Petter Selasky #if HAVE_CONFIG_H
43*d6b92ffaSHans Petter Selasky #  include <config.h>
44*d6b92ffaSHans Petter Selasky #endif				/* HAVE_CONFIG_H */
45*d6b92ffaSHans Petter Selasky 
46*d6b92ffaSHans Petter Selasky #include <vendor/osm_pkt_randomizer.h>
47*d6b92ffaSHans Petter Selasky #include <stdlib.h>
48*d6b92ffaSHans Petter Selasky #include <string.h>
49*d6b92ffaSHans Petter Selasky 
50*d6b92ffaSHans Petter Selasky #ifndef __WIN__
51*d6b92ffaSHans Petter Selasky #include <sys/time.h>
52*d6b92ffaSHans Petter Selasky #include <unistd.h>
53*d6b92ffaSHans Petter Selasky #endif
54*d6b92ffaSHans Petter Selasky 
55*d6b92ffaSHans Petter Selasky /**********************************************************************
56*d6b92ffaSHans Petter Selasky  * Return TRUE if the path is in a fault path, and FALSE otherwise.
57*d6b92ffaSHans Petter Selasky  * By in a fault path the meaning is that there is a path in the fault
58*d6b92ffaSHans Petter Selasky  * paths that the given path includes it.
59*d6b92ffaSHans Petter Selasky  * E.g: if there is a fault path: 0,1,4
60*d6b92ffaSHans Petter Selasky  * For the given path: 0,1,4,7 the return value will be TRUE, also for
61*d6b92ffaSHans Petter Selasky  * the given path: 0,1,4 the return value will be TRUE, but for
62*d6b92ffaSHans Petter Selasky  * the given paths: 0,1 or 0,3,1,4 - the return value will be FALSE.
63*d6b92ffaSHans Petter Selasky  **********************************************************************/
64*d6b92ffaSHans Petter Selasky boolean_t
__osm_pkt_randomizer_is_path_in_fault_paths(IN osm_log_t * p_log,IN osm_dr_path_t * p_dr_path,IN osm_pkt_randomizer_t * p_pkt_rand)65*d6b92ffaSHans Petter Selasky __osm_pkt_randomizer_is_path_in_fault_paths(IN osm_log_t * p_log,
66*d6b92ffaSHans Petter Selasky 					    IN osm_dr_path_t * p_dr_path,
67*d6b92ffaSHans Petter Selasky 					    IN osm_pkt_randomizer_t *
68*d6b92ffaSHans Petter Selasky 					    p_pkt_rand)
69*d6b92ffaSHans Petter Selasky {
70*d6b92ffaSHans Petter Selasky 	boolean_t res = FALSE, found_path;
71*d6b92ffaSHans Petter Selasky 	osm_dr_path_t *p_found_dr_path;
72*d6b92ffaSHans Petter Selasky 	uint8_t ind1, ind2;
73*d6b92ffaSHans Petter Selasky 
74*d6b92ffaSHans Petter Selasky 	OSM_LOG_ENTER(p_log);
75*d6b92ffaSHans Petter Selasky 
76*d6b92ffaSHans Petter Selasky 	for (ind1 = 0; ind1 < p_pkt_rand->num_paths_initialized; ind1++) {
77*d6b92ffaSHans Petter Selasky 		found_path = TRUE;
78*d6b92ffaSHans Petter Selasky 		p_found_dr_path = &(p_pkt_rand->fault_dr_paths[ind1]);
79*d6b92ffaSHans Petter Selasky 		/* if the hop count of the found path is greater than the
80*d6b92ffaSHans Petter Selasky 		   hop count of the input path - then it is not part of it.
81*d6b92ffaSHans Petter Selasky 		   Check the next path. */
82*d6b92ffaSHans Petter Selasky 		if (p_found_dr_path->hop_count > p_dr_path->hop_count)
83*d6b92ffaSHans Petter Selasky 			continue;
84*d6b92ffaSHans Petter Selasky 
85*d6b92ffaSHans Petter Selasky 		/* go over all the ports in the found path and see if they match
86*d6b92ffaSHans Petter Selasky 		   the ports in the input path */
87*d6b92ffaSHans Petter Selasky 		for (ind2 = 0; ind2 <= p_found_dr_path->hop_count; ind2++)
88*d6b92ffaSHans Petter Selasky 			if (p_found_dr_path->path[ind2] !=
89*d6b92ffaSHans Petter Selasky 			    p_dr_path->path[ind2])
90*d6b92ffaSHans Petter Selasky 				found_path = FALSE;
91*d6b92ffaSHans Petter Selasky 
92*d6b92ffaSHans Petter Selasky 		/* If found_path is TRUE  then there is a full match of the path */
93*d6b92ffaSHans Petter Selasky 		if (found_path == TRUE) {
94*d6b92ffaSHans Petter Selasky 			OSM_LOG(p_log, OSM_LOG_VERBOSE,
95*d6b92ffaSHans Petter Selasky 				"Given path is in a fault path\n");
96*d6b92ffaSHans Petter Selasky 			res = TRUE;
97*d6b92ffaSHans Petter Selasky 			break;
98*d6b92ffaSHans Petter Selasky 		}
99*d6b92ffaSHans Petter Selasky 	}
100*d6b92ffaSHans Petter Selasky 
101*d6b92ffaSHans Petter Selasky 	OSM_LOG_EXIT(p_log);
102*d6b92ffaSHans Petter Selasky 	return res;
103*d6b92ffaSHans Petter Selasky }
104*d6b92ffaSHans Petter Selasky 
105*d6b92ffaSHans Petter Selasky /**********************************************************************
106*d6b92ffaSHans Petter Selasky  * For a given dr_path - return TRUE if the path should be dropped,
107*d6b92ffaSHans Petter Selasky  * return FALSE otherwise.
108*d6b92ffaSHans Petter Selasky  * The check uses random criteria in order to determine whether or not
109*d6b92ffaSHans Petter Selasky  * the path should be dropped.
110*d6b92ffaSHans Petter Selasky  * First - if not all paths are initialized, it randomally chooses if
111*d6b92ffaSHans Petter Selasky  * to use this path as a fault path or not.
112*d6b92ffaSHans Petter Selasky  * Second - if the path is in the fault paths (meaning - it is equal
113*d6b92ffaSHans Petter Selasky  * to or includes one of the fault paths) - then it randomally chooses
114*d6b92ffaSHans Petter Selasky  * if to drop it or not.
115*d6b92ffaSHans Petter Selasky  **********************************************************************/
116*d6b92ffaSHans Petter Selasky boolean_t
__osm_pkt_randomizer_process_path(IN osm_log_t * p_log,IN osm_pkt_randomizer_t * p_pkt_rand,IN osm_dr_path_t * p_dr_path)117*d6b92ffaSHans Petter Selasky __osm_pkt_randomizer_process_path(IN osm_log_t * p_log,
118*d6b92ffaSHans Petter Selasky 				  IN osm_pkt_randomizer_t * p_pkt_rand,
119*d6b92ffaSHans Petter Selasky 				  IN osm_dr_path_t * p_dr_path)
120*d6b92ffaSHans Petter Selasky {
121*d6b92ffaSHans Petter Selasky 	boolean_t res = FALSE;
122*d6b92ffaSHans Petter Selasky 	static boolean_t rand_value_init = FALSE;
123*d6b92ffaSHans Petter Selasky 	static int rand_value;
124*d6b92ffaSHans Petter Selasky 	boolean_t in_fault_paths;
125*d6b92ffaSHans Petter Selasky 	uint8_t i;
126*d6b92ffaSHans Petter Selasky 	char buf[BUF_SIZE];
127*d6b92ffaSHans Petter Selasky 	char line[BUF_SIZE];
128*d6b92ffaSHans Petter Selasky 
129*d6b92ffaSHans Petter Selasky 	OSM_LOG_ENTER(p_log);
130*d6b92ffaSHans Petter Selasky 
131*d6b92ffaSHans Petter Selasky 	if (rand_value_init == FALSE) {
132*d6b92ffaSHans Petter Selasky 		int seed;
133*d6b92ffaSHans Petter Selasky #ifdef __WIN__
134*d6b92ffaSHans Petter Selasky 		SYSTEMTIME st;
135*d6b92ffaSHans Petter Selasky #else
136*d6b92ffaSHans Petter Selasky 		struct timeval tv;
137*d6b92ffaSHans Petter Selasky 		struct timezone tz;
138*d6b92ffaSHans Petter Selasky #endif				/*  __WIN__ */
139*d6b92ffaSHans Petter Selasky 
140*d6b92ffaSHans Petter Selasky 		/* initiate the rand_value according to timeofday */
141*d6b92ffaSHans Petter Selasky 		rand_value_init = TRUE;
142*d6b92ffaSHans Petter Selasky 
143*d6b92ffaSHans Petter Selasky #ifdef __WIN__
144*d6b92ffaSHans Petter Selasky 		GetLocalTime(&st);
145*d6b92ffaSHans Petter Selasky 		seed = st.wMilliseconds;
146*d6b92ffaSHans Petter Selasky #else
147*d6b92ffaSHans Petter Selasky 		gettimeofday(&tv, &tz);
148*d6b92ffaSHans Petter Selasky 		seed = tv.tv_usec;
149*d6b92ffaSHans Petter Selasky #endif				/*  __WIN__ */
150*d6b92ffaSHans Petter Selasky 
151*d6b92ffaSHans Petter Selasky 		srand(seed);
152*d6b92ffaSHans Petter Selasky 	}
153*d6b92ffaSHans Petter Selasky 
154*d6b92ffaSHans Petter Selasky 	/* If the hop_count is 1 - then this is a mad down to our local port - don't drop it */
155*d6b92ffaSHans Petter Selasky 	if (p_dr_path->hop_count <= 1)
156*d6b92ffaSHans Petter Selasky 		goto Exit;
157*d6b92ffaSHans Petter Selasky 
158*d6b92ffaSHans Petter Selasky 	rand_value = rand();
159*d6b92ffaSHans Petter Selasky 
160*d6b92ffaSHans Petter Selasky 	sprintf(buf, "Path: ");
161*d6b92ffaSHans Petter Selasky 	/* update the dr_path into the buf */
162*d6b92ffaSHans Petter Selasky 	for (i = 0; i <= p_dr_path->hop_count; i++) {
163*d6b92ffaSHans Petter Selasky 		sprintf(line, "[%X]", p_dr_path->path[i]);
164*d6b92ffaSHans Petter Selasky 		strcat(buf, line);
165*d6b92ffaSHans Petter Selasky 	}
166*d6b92ffaSHans Petter Selasky 
167*d6b92ffaSHans Petter Selasky 	/* Check if the path given is in one of the fault paths */
168*d6b92ffaSHans Petter Selasky 	in_fault_paths =
169*d6b92ffaSHans Petter Selasky 	    __osm_pkt_randomizer_is_path_in_fault_paths(p_log, p_dr_path,
170*d6b92ffaSHans Petter Selasky 							p_pkt_rand);
171*d6b92ffaSHans Petter Selasky 
172*d6b92ffaSHans Petter Selasky 	/* Check if all paths are initialized */
173*d6b92ffaSHans Petter Selasky 	if (p_pkt_rand->num_paths_initialized <
174*d6b92ffaSHans Petter Selasky 	    p_pkt_rand->osm_pkt_num_unstable_links) {
175*d6b92ffaSHans Petter Selasky 		/* Not all packets are initialized. */
176*d6b92ffaSHans Petter Selasky 		if (in_fault_paths == FALSE) {
177*d6b92ffaSHans Petter Selasky 			/* the path is not in the false paths. Check using the rand value
178*d6b92ffaSHans Petter Selasky 			   if to update it there or not. */
179*d6b92ffaSHans Petter Selasky 			if (rand_value %
180*d6b92ffaSHans Petter Selasky 			    (p_pkt_rand->osm_pkt_unstable_link_rate) == 0) {
181*d6b92ffaSHans Petter Selasky 				OSM_LOG(p_log, OSM_LOG_VERBOSE,
182*d6b92ffaSHans Petter Selasky 					"%s added to the fault_dr_paths list\n"
183*d6b92ffaSHans Petter Selasky 					"\t\t\t rand_value:%u, unstable_link_rate:%u \n",
184*d6b92ffaSHans Petter Selasky 					buf, rand_value,
185*d6b92ffaSHans Petter Selasky 					p_pkt_rand->osm_pkt_unstable_link_rate);
186*d6b92ffaSHans Petter Selasky 
187*d6b92ffaSHans Petter Selasky 				/* update the path in the fault paths */
188*d6b92ffaSHans Petter Selasky 				memcpy(&
189*d6b92ffaSHans Petter Selasky 				       (p_pkt_rand->
190*d6b92ffaSHans Petter Selasky 					fault_dr_paths[p_pkt_rand->
191*d6b92ffaSHans Petter Selasky 						       num_paths_initialized]),
192*d6b92ffaSHans Petter Selasky 				       p_dr_path, sizeof(osm_dr_path_t));
193*d6b92ffaSHans Petter Selasky 				p_pkt_rand->num_paths_initialized++;
194*d6b92ffaSHans Petter Selasky 				in_fault_paths = TRUE;
195*d6b92ffaSHans Petter Selasky 			}
196*d6b92ffaSHans Petter Selasky 		}
197*d6b92ffaSHans Petter Selasky 	}
198*d6b92ffaSHans Petter Selasky 
199*d6b92ffaSHans Petter Selasky 	if (in_fault_paths == FALSE) {
200*d6b92ffaSHans Petter Selasky 		/* If in_fault_paths is FALSE - just ignore the path */
201*d6b92ffaSHans Petter Selasky 		OSM_LOG(p_log, OSM_LOG_VERBOSE, "%s not in fault paths\n", buf);
202*d6b92ffaSHans Petter Selasky 		goto Exit;
203*d6b92ffaSHans Petter Selasky 	}
204*d6b92ffaSHans Petter Selasky 
205*d6b92ffaSHans Petter Selasky 	/* The path is in the fault paths. Need to choose (randomally if to drop it
206*d6b92ffaSHans Petter Selasky 	   or not. */
207*d6b92ffaSHans Petter Selasky 	rand_value = rand();
208*d6b92ffaSHans Petter Selasky 
209*d6b92ffaSHans Petter Selasky 	if (rand_value % (p_pkt_rand->osm_pkt_drop_rate) == 0) {
210*d6b92ffaSHans Petter Selasky 		/* drop the current packet */
211*d6b92ffaSHans Petter Selasky 		res = TRUE;
212*d6b92ffaSHans Petter Selasky 		OSM_LOG(p_log, OSM_LOG_VERBOSE, "Dropping path:%s\n", buf);
213*d6b92ffaSHans Petter Selasky 	}
214*d6b92ffaSHans Petter Selasky 
215*d6b92ffaSHans Petter Selasky Exit:
216*d6b92ffaSHans Petter Selasky 	OSM_LOG_EXIT(p_log);
217*d6b92ffaSHans Petter Selasky 	return res;
218*d6b92ffaSHans Petter Selasky }
219*d6b92ffaSHans Petter Selasky 
220*d6b92ffaSHans Petter Selasky boolean_t
osm_pkt_randomizer_mad_drop(IN osm_log_t * p_log,IN osm_pkt_randomizer_t * p_pkt_randomizer,IN const ib_mad_t * p_mad)221*d6b92ffaSHans Petter Selasky osm_pkt_randomizer_mad_drop(IN osm_log_t * p_log,
222*d6b92ffaSHans Petter Selasky 			    IN osm_pkt_randomizer_t * p_pkt_randomizer,
223*d6b92ffaSHans Petter Selasky 			    IN const ib_mad_t * p_mad)
224*d6b92ffaSHans Petter Selasky {
225*d6b92ffaSHans Petter Selasky 	const ib_smp_t *p_smp;
226*d6b92ffaSHans Petter Selasky 	boolean_t res = FALSE;
227*d6b92ffaSHans Petter Selasky 	osm_dr_path_t dr_path;
228*d6b92ffaSHans Petter Selasky 
229*d6b92ffaSHans Petter Selasky 	OSM_LOG_ENTER(p_log);
230*d6b92ffaSHans Petter Selasky 
231*d6b92ffaSHans Petter Selasky 	p_smp = (ib_smp_t *) p_mad;
232*d6b92ffaSHans Petter Selasky 
233*d6b92ffaSHans Petter Selasky 	if (p_smp->mgmt_class != IB_MCLASS_SUBN_DIR)
234*d6b92ffaSHans Petter Selasky 		/* This is a lid route mad. Don't drop it */
235*d6b92ffaSHans Petter Selasky 		goto Exit;
236*d6b92ffaSHans Petter Selasky 
237*d6b92ffaSHans Petter Selasky 	osm_dr_path_init(&dr_path, p_smp->hop_count, p_smp->initial_path);
238*d6b92ffaSHans Petter Selasky 
239*d6b92ffaSHans Petter Selasky 	if (__osm_pkt_randomizer_process_path
240*d6b92ffaSHans Petter Selasky 	    (p_log, p_pkt_randomizer, &dr_path)) {
241*d6b92ffaSHans Petter Selasky 		/* the mad should be dropped o */
242*d6b92ffaSHans Petter Selasky 		OSM_LOG(p_log, OSM_LOG_VERBOSE,
243*d6b92ffaSHans Petter Selasky 			"mad TID: 0x%" PRIx64 " is being dropped\n",
244*d6b92ffaSHans Petter Selasky 			cl_ntoh64(p_smp->trans_id));
245*d6b92ffaSHans Petter Selasky 		res = TRUE;
246*d6b92ffaSHans Petter Selasky 	}
247*d6b92ffaSHans Petter Selasky 
248*d6b92ffaSHans Petter Selasky Exit:
249*d6b92ffaSHans Petter Selasky 	OSM_LOG_EXIT(p_log);
250*d6b92ffaSHans Petter Selasky 	return res;
251*d6b92ffaSHans Petter Selasky }
252*d6b92ffaSHans Petter Selasky 
253*d6b92ffaSHans Petter Selasky ib_api_status_t
osm_pkt_randomizer_init(IN OUT osm_pkt_randomizer_t ** pp_pkt_randomizer,IN osm_log_t * p_log)254*d6b92ffaSHans Petter Selasky osm_pkt_randomizer_init(IN OUT osm_pkt_randomizer_t ** pp_pkt_randomizer,
255*d6b92ffaSHans Petter Selasky 			IN osm_log_t * p_log)
256*d6b92ffaSHans Petter Selasky {
257*d6b92ffaSHans Petter Selasky 	uint8_t tmp;
258*d6b92ffaSHans Petter Selasky 	ib_api_status_t res = IB_SUCCESS;
259*d6b92ffaSHans Petter Selasky 
260*d6b92ffaSHans Petter Selasky 	OSM_LOG_ENTER(p_log);
261*d6b92ffaSHans Petter Selasky 
262*d6b92ffaSHans Petter Selasky 	*pp_pkt_randomizer = malloc(sizeof(osm_pkt_randomizer_t));
263*d6b92ffaSHans Petter Selasky 	if (*pp_pkt_randomizer == NULL) {
264*d6b92ffaSHans Petter Selasky 		res = IB_INSUFFICIENT_MEMORY;
265*d6b92ffaSHans Petter Selasky 		goto Exit;
266*d6b92ffaSHans Petter Selasky 	}
267*d6b92ffaSHans Petter Selasky 	memset(*pp_pkt_randomizer, 0, sizeof(osm_pkt_randomizer_t));
268*d6b92ffaSHans Petter Selasky 	(*pp_pkt_randomizer)->num_paths_initialized = 0;
269*d6b92ffaSHans Petter Selasky 
270*d6b92ffaSHans Petter Selasky 	tmp = atol(getenv("OSM_PKT_DROP_RATE"));
271*d6b92ffaSHans Petter Selasky 	(*pp_pkt_randomizer)->osm_pkt_drop_rate = tmp;
272*d6b92ffaSHans Petter Selasky 
273*d6b92ffaSHans Petter Selasky 	if (getenv("OSM_PKT_NUM_UNSTABLE_LINKS") != NULL
274*d6b92ffaSHans Petter Selasky 	    && (tmp = atol(getenv("OSM_PKT_NUM_UNSTABLE_LINKS"))) > 0)
275*d6b92ffaSHans Petter Selasky 		(*pp_pkt_randomizer)->osm_pkt_num_unstable_links = tmp;
276*d6b92ffaSHans Petter Selasky 	else
277*d6b92ffaSHans Petter Selasky 		(*pp_pkt_randomizer)->osm_pkt_num_unstable_links = 1;
278*d6b92ffaSHans Petter Selasky 
279*d6b92ffaSHans Petter Selasky 	if (getenv("OSM_PKT_UNSTABLE_LINK_RATE") != NULL
280*d6b92ffaSHans Petter Selasky 	    && (tmp = atol(getenv("OSM_PKT_UNSTABLE_LINK_RATE"))) > 0)
281*d6b92ffaSHans Petter Selasky 		(*pp_pkt_randomizer)->osm_pkt_unstable_link_rate = tmp;
282*d6b92ffaSHans Petter Selasky 	else
283*d6b92ffaSHans Petter Selasky 		(*pp_pkt_randomizer)->osm_pkt_unstable_link_rate = 20;
284*d6b92ffaSHans Petter Selasky 
285*d6b92ffaSHans Petter Selasky 	OSM_LOG(p_log, OSM_LOG_VERBOSE, "Using OSM_PKT_DROP_RATE=%u \n"
286*d6b92ffaSHans Petter Selasky 		"\t\t\t\t OSM_PKT_NUM_UNSTABLE_LINKS=%u \n"
287*d6b92ffaSHans Petter Selasky 		"\t\t\t\t OSM_PKT_UNSTABLE_LINK_RATE=%u \n",
288*d6b92ffaSHans Petter Selasky 		(*pp_pkt_randomizer)->osm_pkt_drop_rate,
289*d6b92ffaSHans Petter Selasky 		(*pp_pkt_randomizer)->osm_pkt_num_unstable_links,
290*d6b92ffaSHans Petter Selasky 		(*pp_pkt_randomizer)->osm_pkt_unstable_link_rate);
291*d6b92ffaSHans Petter Selasky 
292*d6b92ffaSHans Petter Selasky 	/* allocate the fault_dr_paths variable */
293*d6b92ffaSHans Petter Selasky 	/* It is the number of the paths that will be saved as fault = osm_pkt_num_unstable_links */
294*d6b92ffaSHans Petter Selasky 	(*pp_pkt_randomizer)->fault_dr_paths = malloc(sizeof(osm_dr_path_t) *
295*d6b92ffaSHans Petter Selasky 						      (*pp_pkt_randomizer)->
296*d6b92ffaSHans Petter Selasky 						      osm_pkt_num_unstable_links);
297*d6b92ffaSHans Petter Selasky 	if ((*pp_pkt_randomizer)->fault_dr_paths == NULL) {
298*d6b92ffaSHans Petter Selasky 		res = IB_INSUFFICIENT_MEMORY;
299*d6b92ffaSHans Petter Selasky 		goto Exit;
300*d6b92ffaSHans Petter Selasky 	}
301*d6b92ffaSHans Petter Selasky 
302*d6b92ffaSHans Petter Selasky 	memset((*pp_pkt_randomizer)->fault_dr_paths, 0,
303*d6b92ffaSHans Petter Selasky 	       sizeof(osm_dr_path_t) *
304*d6b92ffaSHans Petter Selasky 	       (*pp_pkt_randomizer)->osm_pkt_num_unstable_links);
305*d6b92ffaSHans Petter Selasky 
306*d6b92ffaSHans Petter Selasky Exit:
307*d6b92ffaSHans Petter Selasky 	OSM_LOG_EXIT(p_log);
308*d6b92ffaSHans Petter Selasky 	return (res);
309*d6b92ffaSHans Petter Selasky }
310*d6b92ffaSHans Petter Selasky 
311*d6b92ffaSHans Petter Selasky void
osm_pkt_randomizer_destroy(IN OUT osm_pkt_randomizer_t ** pp_pkt_randomizer,IN osm_log_t * p_log)312*d6b92ffaSHans Petter Selasky osm_pkt_randomizer_destroy(IN OUT osm_pkt_randomizer_t ** pp_pkt_randomizer,
313*d6b92ffaSHans Petter Selasky 			   IN osm_log_t * p_log)
314*d6b92ffaSHans Petter Selasky {
315*d6b92ffaSHans Petter Selasky 	OSM_LOG_ENTER(p_log);
316*d6b92ffaSHans Petter Selasky 
317*d6b92ffaSHans Petter Selasky 	if (*pp_pkt_randomizer != NULL) {
318*d6b92ffaSHans Petter Selasky 		free((*pp_pkt_randomizer)->fault_dr_paths);
319*d6b92ffaSHans Petter Selasky 		free(*pp_pkt_randomizer);
320*d6b92ffaSHans Petter Selasky 	}
321*d6b92ffaSHans Petter Selasky 	OSM_LOG_EXIT(p_log);
322*d6b92ffaSHans Petter Selasky }
323