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:57
Showing 1 changed files
... ...
@@ -2087,16 +2087,20 @@ int ds_select_dst_limit(sip_msg_t *msg, int set, int alg, uint32_t limit,
2087 2087
 typedef struct sorted_ds {
2088 2088
 	int idx;
2089 2089
 	int priority;
2090
+	int flags;
2091
+	ds_dest_t *dest;
2090 2092
 } sorted_ds_t;
2091 2093
 
2092
-int ds_manage_routes_fill_reodered_xavp(sorted_ds_t *ds_sorted, ds_set_t *idx, ds_select_state_t *rstate)
2094
+int ds_manage_routes_fill_reordered_xavp(sorted_ds_t *ds_sorted, ds_set_t *idx, ds_select_state_t *rstate)
2093 2095
 {
2094 2096
 	int i;
2095 2097
 	if(!(ds_flags & DS_FAILOVER_ON))
2096 2098
 		return 1;
2097 2099
 	for(i=0; i < idx->nr && rstate->cnt < rstate->limit; i++) {
2098
-		if(ds_sorted[i].idx < 0 || ds_skip_dst(idx->dlist[i].flags)
2099
-				|| (ds_use_default != 0 && ds_sorted[i].idx == (idx->nr - 1))) {
2100
+
2101
+		if(ds_sorted[i].idx < 0 || ds_skip_dst(ds_sorted[i].flags) || (ds_use_default != 0 && ds_sorted[i].idx == (idx->nr - 1))) {
2102
+			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,
2103
+				ds_sorted[i].idx < 0, ds_skip_dst(ds_sorted[i].flags));
2100 2104
 			continue;
2101 2105
 		}
2102 2106
 		if(ds_add_xavp_record(idx, ds_sorted[i].idx, rstate->setid, rstate->alg,
... ...
@@ -2174,16 +2178,23 @@ int ds_manage_routes_fill_xavp(unsigned int hash, ds_set_t *idx, ds_select_state
2174 2178
 
2175 2179
 void ds_sorted_by_priority(sorted_ds_t * sorted_ds, int size) {
2176 2180
 	int i,ii;
2181
+
2177 2182
 	for(i=0;i<size;++i) {
2178 2183
 		for(ii=1;ii<size;++ii) {
2179 2184
 			sorted_ds_t temp;
2180 2185
 			if(sorted_ds[ii-1].priority < sorted_ds[ii].priority) {
2181 2186
 				temp.idx = sorted_ds[ii].idx;
2182 2187
 				temp.priority = sorted_ds[ii].priority;
2188
+				temp.flags = sorted_ds[ii].flags;
2189
+				temp.dest = sorted_ds[ii].dest;
2183 2190
 				sorted_ds[ii].idx = sorted_ds[ii-1].idx;
2184 2191
 				sorted_ds[ii].priority = sorted_ds[ii-1].priority;
2192
+				sorted_ds[ii].flags = sorted_ds[ii-1].flags;
2193
+				sorted_ds[ii].dest = sorted_ds[ii-1].dest;
2185 2194
 				sorted_ds[ii-1].idx = temp.idx;
2186 2195
 				sorted_ds[ii-1].priority = temp.priority;
2196
+				sorted_ds[ii-1].flags = temp.flags;
2197
+				sorted_ds[ii-1].dest = temp.dest;
2187 2198
 			}
2188 2199
 		}
2189 2200
 	}
... ...
@@ -2207,7 +2218,7 @@ int ds_manage_route_algo13(ds_set_t *idx, ds_select_state_t *rstate) {
2207 2218
 		int gw_latency = ds_dest->latency_stats.estimate;
2208 2219
 		int gw_inactive = ds_skip_dst(ds_dest->flags);
2209 2220
 		// if cc is enabled, the latency is the congestion ms instead of the estimated latency.
2210
-		if (ds_dest->attrs.congestion_control)
2221
+		if(ds_dest->attrs.congestion_control)
2211 2222
 			gw_latency = ds_dest->latency_stats.estimate - ds_dest->latency_stats.average;
2212 2223
 		if(!gw_inactive) {
2213 2224
 			if(gw_latency > gw_priority && gw_priority > 0)
... ...
@@ -2217,17 +2228,20 @@ int ds_manage_route_algo13(ds_set_t *idx, ds_select_state_t *rstate) {
2217 2228
 				ds_dest->attrs.rpriority = 1;
2218 2229
 			ds_sorted[y].idx = z;
2219 2230
 			ds_sorted[y].priority = ds_dest->attrs.rpriority;
2220
-			LM_DBG("[active]idx[%d]uri[%.*s]priority[%d-%d=%d]latency[%dms]flag[%d]\n",
2221
-				z, ds_dest->uri.len, ds_dest->uri.s,
2231
+			LM_DBG("[active][%d]idx[%d]uri[%.*s]priority[%d-%d=%d]latency[%dms]flag[%d]\n",
2232
+				y,z, ds_dest->uri.len, ds_dest->uri.s,
2222 2233
 				gw_priority, latency_priority_handicap,
2223 2234
 				ds_dest->attrs.rpriority, gw_latency, ds_dest->flags);
2224 2235
 		} else {
2225 2236
 			ds_sorted[y].idx = -1;
2226 2237
 			ds_sorted[y].priority = -1;
2227
-			LM_DBG("[inactive]idx[%d]uri[%.*s]priority[%d]latency[%dms]flag[%d]",
2228
-				z, ds_dest->uri.len, ds_dest->uri.s,
2238
+			LM_DBG("[inactive][%d]idx[%d]uri[%.*s]priority[%d]latency[%dms]flag[%d]\n",
2239
+				y,-1, ds_dest->uri.len, ds_dest->uri.s,
2229 2240
 				gw_priority, gw_latency, ds_dest->flags);
2230 2241
 		}
2242
+		ds_sorted[y].flags = ds_dest->flags;
2243
+		ds_sorted[y].dest = ds_dest;
2244
+
2231 2245
 		if(ds_use_default != 0 && idx->nr != 1)
2232 2246
 			z = (z + 1) % (idx->nr - 1);
2233 2247
 		else
... ...
@@ -2239,7 +2253,7 @@ int ds_manage_route_algo13(ds_set_t *idx, ds_select_state_t *rstate) {
2239 2253
 		hash = ds_sorted[0].idx;
2240 2254
 		active_priority = ds_sorted[0].priority;
2241 2255
 	}
2242
-	ds_manage_routes_fill_reodered_xavp(ds_sorted, idx, rstate);
2256
+	ds_manage_routes_fill_reordered_xavp(ds_sorted, idx, rstate);
2243 2257
 	idx->last = (hash + 1) % idx->nr;
2244 2258
 	LM_DBG("priority[%d]gateway_selected[%d]next_index[%d]\n", active_priority, hash, idx->last);
2245 2259
 	pkg_free(ds_sorted);