فهرست منبع

dispatcher: new dispatching algorithm 14

- serial or round-robin if the priority is the same for all destinations
  in the group and it is greater than 0
Daniel-Constantin Mierla 2 ماه پیش
والد
کامیت
883f9cd0bf
2فایلهای تغییر یافته به همراه21 افزوده شده و 1 حذف شده
  1. 20 1
      src/modules/dispatcher/dispatch.c
  2. 1 0
      src/modules/dispatcher/dispatch.h

+ 20 - 1
src/modules/dispatcher/dispatch.c

@@ -82,6 +82,7 @@
 #define DS_ALG_RELWEIGHT 11
 #define DS_ALG_RELWEIGHT 11
 #define DS_ALG_PARALLEL 12
 #define DS_ALG_PARALLEL 12
 #define DS_ALG_LATENCY 13
 #define DS_ALG_LATENCY 13
+#define DS_ALG_RRSERIAL 14
 #define DS_ALG_OVERLOAD 64 /* 2^6 - can be also used as a flag */
 #define DS_ALG_OVERLOAD 64 /* 2^6 - can be also used as a flag */
 
 
 #define DS_HN_SIZE 256
 #define DS_HN_SIZE 256
@@ -778,7 +779,13 @@ ds_dest_t *add_dest2list(int id, str uri, int flags, int priority, str *attrs,
 
 
 	if(sp->dlist == NULL) {
 	if(sp->dlist == NULL) {
 		sp->dlist = dp;
 		sp->dlist = dp;
+		if(priority > 0) {
+			sp->rrserial = priority;
+		}
 	} else {
 	} else {
+		if(sp->rrserial > 0 && sp->rrserial != priority) {
+			sp->rrserial = 0;
+		}
 		dp1 = NULL;
 		dp1 = NULL;
 		dp0 = sp->dlist;
 		dp0 = sp->dlist;
 		/* highest priority last -> reindex will copy backwards */
 		/* highest priority last -> reindex will copy backwards */
@@ -2563,6 +2570,7 @@ int ds_manage_routes(sip_msg_t *msg, ds_select_state_t *rstate)
 	ds_set_t *idx = NULL;
 	ds_set_t *idx = NULL;
 	int ulast = 0;
 	int ulast = 0;
 	int vlast = 0;
 	int vlast = 0;
+	int valg = 0;
 	int xavp_filled = 0;
 	int xavp_filled = 0;
 
 
 	if(msg == NULL) {
 	if(msg == NULL) {
@@ -2589,10 +2597,20 @@ int ds_manage_routes(sip_msg_t *msg, ds_select_state_t *rstate)
 		return -1;
 		return -1;
 	}
 	}
 
 
+	if(rstate->alg == DS_ALG_RRSERIAL) {
+		/* decide on round-robin or serial dispatching */
+		if(idx->rrserial != 0) {
+			valg = DS_ALG_ROUNDROBIN;
+		} else {
+			valg = DS_ALG_SERIAL;
+		}
+	} else {
+		valg = rstate->alg;
+	}
 	LM_DBG("set [%d]\n", rstate->setid);
 	LM_DBG("set [%d]\n", rstate->setid);
 
 
 	hash = 0;
 	hash = 0;
-	switch(rstate->alg) {
+	switch(valg) {
 		case DS_ALG_HASHCALLID: /* 0 - hash call-id */
 		case DS_ALG_HASHCALLID: /* 0 - hash call-id */
 			if(ds_hash_callid(msg, &hash) != 0) {
 			if(ds_hash_callid(msg, &hash) != 0) {
 				LM_ERR("can't get callid hash\n");
 				LM_ERR("can't get callid hash\n");
@@ -2707,6 +2725,7 @@ int ds_manage_routes(sip_msg_t *msg, ds_select_state_t *rstate)
 				return -1;
 				return -1;
 			xavp_filled = 1;
 			xavp_filled = 1;
 			break;
 			break;
+		/* case DS_ALG_RRSERIAL: // 14 - round-robin or serial decided above */
 		case DS_ALG_OVERLOAD: /* 64 - round robin with overload control */
 		case DS_ALG_OVERLOAD: /* 64 - round robin with overload control */
 			lock_get(&idx->lock);
 			lock_get(&idx->lock);
 			hash = idx->last;
 			hash = idx->last;

+ 1 - 0
src/modules/dispatcher/dispatch.h

@@ -270,6 +270,7 @@ typedef struct _ds_set {
 	unsigned int rwlist[100];
 	unsigned int rwlist[100];
 	struct _ds_set *next[2];
 	struct _ds_set *next[2];
 	int longer;
 	int longer;
+	int rrserial;		/*!< round-robin or serial flag */
 	gen_lock_t lock;
 	gen_lock_t lock;
 } ds_set_t;
 } ds_set_t;