Browse code

dispatcher: fix alog13 gateway selections

(cherry picked from commit d56d65b8daac072a4726d9124072151d0d3fbb79)

Julien Chavanton authored on 06/09/2022 14:45:12 • Henning Westerholt committed on 18/09/2022 22:33:38
Showing 1 changed files
... ...
@@ -2112,16 +2112,20 @@ int ds_select_dst_limit(sip_msg_t *msg, int set, int alg, uint32_t limit,
2112 2112
 typedef struct sorted_ds {
2113 2113
 	int idx;
2114 2114
 	int priority;
2115
+	int flags;
2116
+	ds_dest_t *dest;
2115 2117
 } sorted_ds_t;
2116 2118
 
2117
-int ds_manage_routes_fill_reodered_xavp(sorted_ds_t *ds_sorted, ds_set_t *idx, ds_select_state_t *rstate)
2119
+int ds_manage_routes_fill_reordered_xavp(sorted_ds_t *ds_sorted, ds_set_t *idx, ds_select_state_t *rstate)
2118 2120
 {
2119 2121
 	int i;
2120 2122
 	if(!(ds_flags & DS_FAILOVER_ON))
2121 2123
 		return 1;
2122 2124
 	for(i=0; i < idx->nr && rstate->cnt < rstate->limit; i++) {
2123
-		if(ds_sorted[i].idx < 0 || ds_skip_dst(idx->dlist[i].flags)
2124
-				|| (ds_use_default != 0 && ds_sorted[i].idx == (idx->nr - 1))) {
2125
+
2126
+		if(ds_sorted[i].idx < 0 || ds_skip_dst(ds_sorted[i].flags) || (ds_use_default != 0 && ds_sorted[i].idx == (idx->nr - 1))) {
2127
+			LM_DBG("[%d|%.*s|idx:%d]skipped %d || %d\n", i, ds_sorted[i].dest->uri.len, ds_sorted[i].dest->uri.s, ds_sorted[i].idx,
2128
+				ds_sorted[i].idx < 0, ds_skip_dst(ds_sorted[i].flags));
2125 2129
 			continue;
2126 2130
 		}
2127 2131
 		if(ds_add_xavp_record(idx, ds_sorted[i].idx, rstate->setid, rstate->alg,
... ...
@@ -2199,16 +2203,23 @@ int ds_manage_routes_fill_xavp(unsigned int hash, ds_set_t *idx, ds_select_state
2199 2203
 
2200 2204
 void ds_sorted_by_priority(sorted_ds_t * sorted_ds, int size) {
2201 2205
 	int i,ii;
2206
+
2202 2207
 	for(i=0;i<size;++i) {
2203 2208
 		for(ii=1;ii<size;++ii) {
2204 2209
 			sorted_ds_t temp;
2205 2210
 			if(sorted_ds[ii-1].priority < sorted_ds[ii].priority) {
2206 2211
 				temp.idx = sorted_ds[ii].idx;
2207 2212
 				temp.priority = sorted_ds[ii].priority;
2213
+				temp.flags = sorted_ds[ii].flags;
2214
+				temp.dest = sorted_ds[ii].dest;
2208 2215
 				sorted_ds[ii].idx = sorted_ds[ii-1].idx;
2209 2216
 				sorted_ds[ii].priority = sorted_ds[ii-1].priority;
2217
+				sorted_ds[ii].flags = sorted_ds[ii-1].flags;
2218
+				sorted_ds[ii].dest = sorted_ds[ii-1].dest;
2210 2219
 				sorted_ds[ii-1].idx = temp.idx;
2211 2220
 				sorted_ds[ii-1].priority = temp.priority;
2221
+				sorted_ds[ii-1].flags = temp.flags;
2222
+				sorted_ds[ii-1].dest = temp.dest;
2212 2223
 			}
2213 2224
 		}
2214 2225
 	}
... ...
@@ -2232,7 +2243,7 @@ int ds_manage_route_algo13(ds_set_t *idx, ds_select_state_t *rstate) {
2232 2243
 		int gw_latency = ds_dest->latency_stats.estimate;
2233 2244
 		int gw_inactive = ds_skip_dst(ds_dest->flags);
2234 2245
 		// if cc is enabled, the latency is the congestion ms instead of the estimated latency.
2235
-		if (ds_dest->attrs.congestion_control)
2246
+		if(ds_dest->attrs.congestion_control)
2236 2247
 			gw_latency = ds_dest->latency_stats.estimate - ds_dest->latency_stats.average;
2237 2248
 		if(!gw_inactive) {
2238 2249
 			if(gw_latency > gw_priority && gw_priority > 0)
... ...
@@ -2242,17 +2253,20 @@ int ds_manage_route_algo13(ds_set_t *idx, ds_select_state_t *rstate) {
2242 2253
 				ds_dest->attrs.rpriority = 1;
2243 2254
 			ds_sorted[y].idx = z;
2244 2255
 			ds_sorted[y].priority = ds_dest->attrs.rpriority;
2245
-			LM_DBG("[active]idx[%d]uri[%.*s]priority[%d-%d=%d]latency[%dms]flag[%d]\n",
2246
-				z, ds_dest->uri.len, ds_dest->uri.s,
2256
+			LM_DBG("[active][%d]idx[%d]uri[%.*s]priority[%d-%d=%d]latency[%dms]flag[%d]\n",
2257
+				y,z, ds_dest->uri.len, ds_dest->uri.s,
2247 2258
 				gw_priority, latency_priority_handicap,
2248 2259
 				ds_dest->attrs.rpriority, gw_latency, ds_dest->flags);
2249 2260
 		} else {
2250 2261
 			ds_sorted[y].idx = -1;
2251 2262
 			ds_sorted[y].priority = -1;
2252
-			LM_DBG("[inactive]idx[%d]uri[%.*s]priority[%d]latency[%dms]flag[%d]",
2253
-				z, ds_dest->uri.len, ds_dest->uri.s,
2263
+			LM_DBG("[inactive][%d]idx[%d]uri[%.*s]priority[%d]latency[%dms]flag[%d]\n",
2264
+				y,-1, ds_dest->uri.len, ds_dest->uri.s,
2254 2265
 				gw_priority, gw_latency, ds_dest->flags);
2255 2266
 		}
2267
+		ds_sorted[y].flags = ds_dest->flags;
2268
+		ds_sorted[y].dest = ds_dest;
2269
+
2256 2270
 		if(ds_use_default != 0 && idx->nr != 1)
2257 2271
 			z = (z + 1) % (idx->nr - 1);
2258 2272
 		else
... ...
@@ -2264,7 +2278,7 @@ int ds_manage_route_algo13(ds_set_t *idx, ds_select_state_t *rstate) {
2264 2278
 		hash = ds_sorted[0].idx;
2265 2279
 		active_priority = ds_sorted[0].priority;
2266 2280
 	}
2267
-	ds_manage_routes_fill_reodered_xavp(ds_sorted, idx, rstate);
2281
+	ds_manage_routes_fill_reordered_xavp(ds_sorted, idx, rstate);
2268 2282
 	idx->last = (hash + 1) % idx->nr;
2269 2283
 	LM_DBG("priority[%d]gateway_selected[%d]next_index[%d]\n", active_priority, hash, idx->last);
2270 2284
 	pkg_free(ds_sorted);