Browse code

dispatcher: algorithm 13 (#2493)

- latency optimized round-robin with failover
- optionally congestion can be use instead of latency

- thanks to Salman Ali (asalman18) for the review

Julien Chavanton authored on 19/11/2020 15:51:06 • GitHub committed on 19/11/2020 15:51:06
Showing 1 changed files
... ...
@@ -190,6 +190,7 @@ typedef struct _ds_attrs {
190 190
 	int congestion_control;
191 191
 	str ping_from;
192 192
 	str obproxy;
193
+	int rpriority;
193 194
 } ds_attrs_t;
194 195
 
195 196
 typedef struct _ds_latency_stats {
Browse code

dispatcher: add an attribute to preset the

latency estimator

Julien Chavanton authored on 01/10/2020 15:21:37
Showing 1 changed files
... ...
@@ -204,6 +204,8 @@ typedef struct _ds_latency_stats {
204 204
 	uint32_t timeout;
205 205
 } ds_latency_stats_t;
206 206
 
207
+void latency_stats_init(ds_latency_stats_t *latency_stats, int latency, int count);
208
+
207 209
 typedef struct _ds_dest {
208 210
 	str uri;          /*!< address/uri */
209 211
 	int flags;        /*!< flags */
Browse code

dispatcher: add attrs param to rpc 'add' call

Federico Cabiddu authored on 26/05/2020 08:24:58
Showing 1 changed files
... ...
@@ -140,7 +140,7 @@ int ds_select_dst_limit(sip_msg_t *msg, int set, int alg, uint32_t limit,
140 140
 		int mode);
141 141
 int ds_select_dst(struct sip_msg *msg, int set, int alg, int mode);
142 142
 int ds_update_dst(struct sip_msg *msg, int upos, int mode);
143
-int ds_add_dst(int group, str *address, int flags);
143
+int ds_add_dst(int group, str *address, int flags, str *attrs);
144 144
 int ds_remove_dst(int group, str *address);
145 145
 int ds_update_state(sip_msg_t *msg, int group, str *address, int state,
146 146
 		ds_rctx_t *rctx);
Browse code

dispatcher: new rpc command dispatcher.set_duid_state

- set the state of a destination by matching on duid attribute
kamctl rpc dispatcher.set_duid_state <state> <setid> <duid>
- example: kamctl rpc dispatcher.set_duid_state i 1 xyz
- GH #2085

Daniel-Constantin Mierla authored on 22/05/2020 19:25:48
Showing 1 changed files
... ...
@@ -146,6 +146,7 @@ int ds_update_state(sip_msg_t *msg, int group, str *address, int state,
146 146
 		ds_rctx_t *rctx);
147 147
 int ds_reinit_state(int group, str *address, int state);
148 148
 int ds_reinit_state_all(int group, int state);
149
+int ds_reinit_duid_state(int group, str *vduid, int state);
149 150
 int ds_mark_dst(struct sip_msg *msg, int mode);
150 151
 int ds_print_list(FILE *fout);
151 152
 int ds_log_sets(void);
Browse code

dispatcher: added rpc command dispatcher.hash

- prototype: dispatcher.hash nslots val1 [val2]
- compute the hash id of the value and do modulo operation if first
parameter is not 0
- val2 is optional

Daniel-Constantin Mierla authored on 20/05/2020 19:33:17
Showing 1 changed files
... ...
@@ -271,5 +271,6 @@ void ds_avl_destroy(ds_set_t **node);
271 271
 int ds_manage_routes(sip_msg_t *msg, ds_select_state_t *rstate);
272 272
 
273 273
 ds_rctx_t* ds_get_rctx(void);
274
+unsigned int ds_get_hash(str *x, str *y);
274 275
 
275 276
 #endif
Browse code

dispatcher: add new gateway attr "obproxy"

Federico Cabiddu authored on 07/04/2020 12:37:29
Showing 1 changed files
... ...
@@ -188,6 +188,7 @@ typedef struct _ds_attrs {
188 188
 	int rweight;
189 189
 	int congestion_control;
190 190
 	str ping_from;
191
+	str obproxy;
191 192
 } ds_attrs_t;
192 193
 
193 194
 typedef struct _ds_latency_stats {
Browse code

dispatcher: support for per destination address socket name attribute

- attribute name is: sockname
- if set to a socket name, enforce the send socket per destination
address

Daniel-Constantin Mierla authored on 05/04/2020 12:35:40
Showing 1 changed files
... ...
@@ -68,6 +68,7 @@
68 68
 
69 69
 #define DS_XAVP_DST_SKIP_ATTRS	1
70 70
 #define DS_XAVP_DST_ADD_SOCKSTR	(1<<1)
71
+#define DS_XAVP_DST_ADD_SOCKNAME	(1<<2)
71 72
 
72 73
 #define DS_XAVP_CTX_SKIP_CNT	1
73 74
 
... ...
@@ -102,6 +103,7 @@ extern str ds_xavp_dst_dstid;
102 103
 extern str ds_xavp_dst_attrs;
103 104
 extern str ds_xavp_dst_sock;
104 105
 extern str ds_xavp_dst_socket;
106
+extern str ds_xavp_dst_sockname;
105 107
 
106 108
 extern str ds_xavp_ctx_cnt;
107 109
 
... ...
@@ -123,6 +125,7 @@ extern int inactive_threshold; /*!< number of successful requests,
123 125
 extern int ds_probing_mode;
124 126
 extern str ds_outbound_proxy;
125 127
 extern str ds_default_socket;
128
+extern str ds_default_sockname;
126 129
 extern struct socket_info *ds_default_sockinfo;
127 130
 
128 131
 int ds_init_data(void);
... ...
@@ -179,6 +182,7 @@ typedef struct _ds_attrs {
179 182
 	str body;
180 183
 	str duid;
181 184
 	str socket;
185
+	str sockname;
182 186
 	int maxload;
183 187
 	int weight;
184 188
 	int rweight;
Browse code

dispatcher: new variable $dsv(...)

- access attributes related to response code when executing event routes
- $dsv(code) - the response code that triggered execution of the
event_route dispatcher:dst-up or dispatcher:dst-down
- $dsv(reason) - the response reason; $dsv(flags) - internal flags set
during event route execution

Daniel-Constantin Mierla authored on 19/11/2019 09:15:15
Showing 1 changed files
... ...
@@ -72,9 +72,14 @@
72 72
 #define DS_XAVP_CTX_SKIP_CNT	1
73 73
 
74 74
 #define DS_IRMODE_NOIPADDR	1
75
-
76 75
 /* clang-format on */
77 76
 
77
+typedef struct ds_rctx {
78
+	int flags;
79
+	int code;
80
+	str reason;
81
+} ds_rctx_t;
82
+
78 83
 extern str ds_db_url;
79 84
 extern str ds_table_name;
80 85
 extern str ds_set_id_col;
... ...
@@ -134,7 +139,8 @@ int ds_select_dst(struct sip_msg *msg, int set, int alg, int mode);
134 139
 int ds_update_dst(struct sip_msg *msg, int upos, int mode);
135 140
 int ds_add_dst(int group, str *address, int flags);
136 141
 int ds_remove_dst(int group, str *address);
137
-int ds_update_state(sip_msg_t *msg, int group, str *address, int state);
142
+int ds_update_state(sip_msg_t *msg, int group, str *address, int state,
143
+		ds_rctx_t *rctx);
138 144
 int ds_reinit_state(int group, str *address, int state);
139 145
 int ds_reinit_state_all(int group, int state);
140 146
 int ds_mark_dst(struct sip_msg *msg, int mode);
... ...
@@ -259,4 +265,6 @@ void ds_avl_destroy(ds_set_t **node);
259 265
 
260 266
 int ds_manage_routes(sip_msg_t *msg, ds_select_state_t *rstate);
261 267
 
268
+ds_rctx_t* ds_get_rctx(void);
269
+
262 270
 #endif
Browse code

dispatcher: option to set add socket as string in the dst xavp

- bit 2 has to be set for xavp_dst_mode modparam

Daniel-Constantin Mierla authored on 15/11/2019 19:52:02
Showing 1 changed files
... ...
@@ -67,6 +67,7 @@
67 67
 #define DS_USE_NEXT			1
68 68
 
69 69
 #define DS_XAVP_DST_SKIP_ATTRS	1
70
+#define DS_XAVP_DST_ADD_SOCKSTR	(1<<1)
70 71
 
71 72
 #define DS_XAVP_CTX_SKIP_CNT	1
72 73
 
... ...
@@ -95,6 +96,7 @@ extern str ds_xavp_dst_grp;
95 96
 extern str ds_xavp_dst_dstid;
96 97
 extern str ds_xavp_dst_attrs;
97 98
 extern str ds_xavp_dst_sock;
99
+extern str ds_xavp_dst_socket;
98 100
 
99 101
 extern str ds_xavp_ctx_cnt;
100 102
 
Browse code

dispatcher: add state to mode in ds_list_exists

adds Bit 3 to allow the check of active/inactive entries in ds_list

lazedo authored on 31/10/2019 14:41:53
Showing 1 changed files
... ...
@@ -57,6 +57,7 @@
57 57
 #define DS_MATCH_ALL		0
58 58
 #define DS_MATCH_NOPORT		1
59 59
 #define DS_MATCH_NOPROTO	2
60
+#define DS_MATCH_ACTIVE 	4
60 61
 
61 62
 #define DS_SETOP_DSTURI		0
62 63
 #define DS_SETOP_RURI		1
Browse code

dispatcher: remove destination from in-memory dispatcher set

- add dispatcher.remove call to remove entry from in-memory dispatcher
list
- allow arguments to callback in ds_iter_set()

Timmo Verlaan authored on 08/03/2019 20:19:22
Showing 1 changed files
... ...
@@ -130,6 +130,7 @@ int ds_select_dst_limit(sip_msg_t *msg, int set, int alg, uint32_t limit,
130 130
 int ds_select_dst(struct sip_msg *msg, int set, int alg, int mode);
131 131
 int ds_update_dst(struct sip_msg *msg, int upos, int mode);
132 132
 int ds_add_dst(int group, str *address, int flags);
133
+int ds_remove_dst(int group, str *address);
133 134
 int ds_update_state(sip_msg_t *msg, int group, str *address, int state);
134 135
 int ds_reinit_state(int group, str *address, int state);
135 136
 int ds_reinit_state_all(int group, int state);
... ...
@@ -228,6 +229,12 @@ typedef struct _ds_select_state {
228 229
 	sr_xavp_t *lxavp;
229 230
 } ds_select_state_t;
230 231
 
232
+struct ds_filter_dest_cb_arg {
233
+	int setid;
234
+	ds_dest_t *dest;
235
+	int *setn;
236
+};
237
+
231 238
 /* clang-format on */
232 239
 
233 240
 #define AVL_LEFT 0
Browse code

dispatcher: add destination to in-memory dispatcher list

- add dispatcher.add rpc call to add destinations to in-memory
dispatcher list
- refactored ds_log_set to allow for re-use of loop over all
destinations

Timmo Verlaan authored on 02/01/2019 21:46:45
Showing 1 changed files
... ...
@@ -129,6 +129,7 @@ int ds_select_dst_limit(sip_msg_t *msg, int set, int alg, uint32_t limit,
129 129
 		int mode);
130 130
 int ds_select_dst(struct sip_msg *msg, int set, int alg, int mode);
131 131
 int ds_update_dst(struct sip_msg *msg, int upos, int mode);
132
+int ds_add_dst(int group, str *address, int flags);
132 133
 int ds_update_state(sip_msg_t *msg, int group, str *address, int state);
133 134
 int ds_reinit_state(int group, str *address, int state);
134 135
 int ds_reinit_state_all(int group, int state);
Browse code

dispatcher: flag 16 (1<<4) for destinations with host not having A/AAAA record

- use it for addresses that should not be resolved with an A/AAAA query
at startup (e.g., it is a NAPTR or SRV only record for that specific
hostname)
- such addresses will not match when using ds_is_from_list(...)
- GH #1743

Daniel-Constantin Mierla authored on 29/11/2018 17:20:24
Showing 1 changed files
... ...
@@ -44,7 +44,8 @@
44 44
 #define DS_TRYING_DST		2  /*!< temporary trying destination */
45 45
 #define DS_DISABLED_DST		4  /*!< admin disabled destination */
46 46
 #define DS_PROBING_DST		8  /*!< checking destination */
47
-#define DS_STATES_ALL		15  /*!< all bits for the states of destination */
47
+#define DS_NODNSARES_DST	16 /*!< no DNS A/AAAA resolve for host in uri */
48
+#define DS_STATES_ALL		31 /*!< all bits for the states of destination */
48 49
 
49 50
 #define ds_skip_dst(flags)	((flags) & (DS_INACTIVE_DST|DS_DISABLED_DST))
50 51
 
... ...
@@ -68,6 +69,8 @@
68 69
 
69 70
 #define DS_XAVP_CTX_SKIP_CNT	1
70 71
 
72
+#define DS_IRMODE_NOIPADDR	1
73
+
71 74
 /* clang-format on */
72 75
 
73 76
 extern str ds_db_url;
... ...
@@ -185,16 +188,17 @@ typedef struct _ds_latency_stats {
185 188
 } ds_latency_stats_t;
186 189
 
187 190
 typedef struct _ds_dest {
188
-	str uri;
189
-	int flags;
190
-	int priority;
191
-	int dload;
192
-	ds_attrs_t attrs;
193
-	ds_latency_stats_t latency_stats;
194
-	struct socket_info * sock;
195
-	struct ip_addr ip_address; 	/*!< IP-Address of the entry */
196
-	unsigned short int port; 	/*!< Port of the URI */
197
-	unsigned short int proto; 	/*!< Protocol of the URI */
191
+	str uri;          /*!< address/uri */
192
+	int flags;        /*!< flags */
193
+	int priority;     /*!< priority */
194
+	int dload;        /*!< load */
195
+	ds_attrs_t attrs; /*!< the atttributes */
196
+	ds_latency_stats_t latency_stats; /*!< latency statistics */
197
+	int irmode;       /*!< internal runtime mode (flags) */
198
+	struct socket_info *sock; /*!< pointer to local socket */
199
+	struct ip_addr ip_address; 	/*!< IP of the address */
200
+	unsigned short int port; 	/*!< port of the URI */
201
+	unsigned short int proto; 	/*!< protocol of the URI */
198 202
 	int message_count;
199 203
 	struct _ds_dest *next;
200 204
 } ds_dest_t;
Browse code

dispatcher: rename internal functions to match the module pattern

Daniel-Constantin Mierla authored on 29/11/2018 16:34:42
Showing 1 changed files
... ...
@@ -114,8 +114,8 @@ extern str ds_outbound_proxy;
114 114
 extern str ds_default_socket;
115 115
 extern struct socket_info *ds_default_sockinfo;
116 116
 
117
-int init_data(void);
118
-int init_ds_db(void);
117
+int ds_init_data(void);
118
+int ds_init_db(void);
119 119
 int ds_load_list(char *lfile);
120 120
 int ds_connect_db(void);
121 121
 void ds_disconnect_db(void);
Browse code

dispatcher: ds_select_routes() - set r-uri/d-uri even when first group has no available dst

- GH #1728

Daniel-Constantin Mierla authored on 22/11/2018 07:56:54
Showing 1 changed files
... ...
@@ -214,11 +214,12 @@ typedef struct _ds_set {
214 214
 } ds_set_t;
215 215
 
216 216
 typedef struct _ds_select_state {
217
-	int setid;
218
-	int alg;
219
-	int umode;
220
-	uint32_t limit;
221
-	int cnt;
217
+	int setid;  /* dispatcher set id (group id) */
218
+	int alg;    /* algorithm to select destionations */
219
+	int umode;  /* update mode - push to: r-uri, d-uri, xavp */
220
+	uint32_t limit; /* limit of destination addresses to be selected */
221
+	int cnt;    /* output: number of xavps set with destination addresses */
222
+	int emode;  /* output: update operation was executed or not */
222 223
 	sr_xavp_t *lxavp;
223 224
 } ds_select_state_t;
224 225
 
Browse code

dispatcher: add ping_from attribute

Giacomo Vacca authored on 05/09/2018 12:35:52
Showing 1 changed files
... ...
@@ -169,6 +169,7 @@ typedef struct _ds_attrs {
169 169
 	int weight;
170 170
 	int rweight;
171 171
 	int congestion_control;
172
+	str ping_from;
172 173
 } ds_attrs_t;
173 174
 
174 175
 typedef struct _ds_latency_stats {
Browse code

dispatcher: new function ds_select_routing(rules, mode, [limit])

- select target addresses from a combination of groups and algorithms,
control where the first destination is pushed and optionally set a limit

Daniel-Constantin Mierla authored on 19/06/2018 16:34:00
Showing 1 changed files
... ...
@@ -30,6 +30,7 @@
30 30
 
31 31
 #include <stdio.h>
32 32
 #include "../../core/pvar.h"
33
+#include "../../core/xavp.h"
33 34
 #include "../../core/parser/msg_parser.h"
34 35
 #include "../../core/rand/kam_rand.h"
35 36
 #include "../../modules/tm/tm_load.h"
... ...
@@ -121,8 +122,8 @@ void ds_disconnect_db(void);
121 122
 int ds_load_db(void);
122 123
 int ds_reload_db(void);
123 124
 int ds_destroy_list(void);
124
-int ds_select_dst_limit(
125
-		struct sip_msg *msg, int set, int alg, unsigned int limit, int mode);
125
+int ds_select_dst_limit(sip_msg_t *msg, int set, int alg, uint32_t limit,
126
+		int mode);
126 127
 int ds_select_dst(struct sip_msg *msg, int set, int alg, int mode);
127 128
 int ds_update_dst(struct sip_msg *msg, int upos, int mode);
128 129
 int ds_update_state(sip_msg_t *msg, int group, str *address, int state);
... ...
@@ -210,6 +211,16 @@ typedef struct _ds_set {
210 211
 	int longer;
211 212
 	gen_lock_t lock;
212 213
 } ds_set_t;
214
+
215
+typedef struct _ds_select_state {
216
+	int setid;
217
+	int alg;
218
+	int umode;
219
+	uint32_t limit;
220
+	int cnt;
221
+	sr_xavp_t *lxavp;
222
+} ds_select_state_t;
223
+
213 224
 /* clang-format on */
214 225
 
215 226
 #define AVL_LEFT 0
... ...
@@ -229,4 +240,6 @@ ds_set_t *ds_avl_insert(ds_set_t **root, int id, int *setn);
229 240
 ds_set_t *ds_avl_find(ds_set_t *node, int id);
230 241
 void ds_avl_destroy(ds_set_t **node);
231 242
 
243
+int ds_manage_routes(sip_msg_t *msg, ds_select_state_t *rstate);
244
+
232 245
 #endif
Browse code

dispatcher: added ds_set_dst() and dst_set_domain()

- unlike the ds_next_...() variants, these functions just push to
destination the current xavp_dst, without consuming it

Daniel-Constantin Mierla authored on 15/06/2018 06:54:02
Showing 1 changed files
... ...
@@ -60,7 +60,11 @@
60 60
 #define DS_SETOP_RURI		1
61 61
 #define DS_SETOP_XAVP		2
62 62
 
63
+#define DS_USE_CRT			0
64
+#define DS_USE_NEXT			1
65
+
63 66
 #define DS_XAVP_DST_SKIP_ATTRS	1
67
+
64 68
 #define DS_XAVP_CTX_SKIP_CNT	1
65 69
 
66 70
 /* clang-format on */
... ...
@@ -120,7 +124,7 @@ int ds_destroy_list(void);
120 124
 int ds_select_dst_limit(
121 125
 		struct sip_msg *msg, int set, int alg, unsigned int limit, int mode);
122 126
 int ds_select_dst(struct sip_msg *msg, int set, int alg, int mode);
123
-int ds_next_dst(struct sip_msg *msg, int mode);
127
+int ds_update_dst(struct sip_msg *msg, int upos, int mode);
124 128
 int ds_update_state(sip_msg_t *msg, int group, str *address, int state);
125 129
 int ds_reinit_state(int group, str *address, int state);
126 130
 int ds_reinit_state_all(int group, int state);
Browse code

dispatcher: added defines for dst address update operations

Daniel-Constantin Mierla authored on 12/06/2018 07:01:18
Showing 1 changed files
... ...
@@ -56,6 +56,10 @@
56 56
 #define DS_MATCH_NOPORT		1
57 57
 #define DS_MATCH_NOPROTO	2
58 58
 
59
+#define DS_SETOP_DSTURI		0
60
+#define DS_SETOP_RURI		1
61
+#define DS_SETOP_XAVP		2
62
+
59 63
 #define DS_XAVP_DST_SKIP_ATTRS	1
60 64
 #define DS_XAVP_CTX_SKIP_CNT	1
61 65
 
Browse code

dispatcher: use xavps instead of avps

- removed avp names parameters
- new parameters:
- xavp_dst - name of the xavp to store destination records
- xavp_dst_mode - control the fields added to xavp_dst
- xavp_ctx - name of the xavp to store context attributes
- xavp_ctx_mode - control the fields added to xavp_ctx

Daniel-Constantin Mierla authored on 12/06/2018 06:35:15
Showing 1 changed files
... ...
@@ -55,6 +55,10 @@
55 55
 #define DS_MATCH_ALL		0
56 56
 #define DS_MATCH_NOPORT		1
57 57
 #define DS_MATCH_NOPROTO	2
58
+
59
+#define DS_XAVP_DST_SKIP_ATTRS	1
60
+#define DS_XAVP_CTX_SKIP_CNT	1
61
+
58 62
 /* clang-format on */
59 63
 
60 64
 extern str ds_db_url;
... ...
@@ -68,18 +72,18 @@ extern str ds_dest_attrs_col;
68 72
 extern int ds_flags;
69 73
 extern int ds_use_default;
70 74
 
71
-extern int_str dst_avp_name;
72
-extern unsigned short dst_avp_type;
73
-extern int_str grp_avp_name;
74
-extern unsigned short grp_avp_type;
75
-extern int_str cnt_avp_name;
76
-extern unsigned short cnt_avp_type;
77
-extern int_str dstid_avp_name;
78
-extern unsigned short dstid_avp_type;
79
-extern int_str attrs_avp_name;
80
-extern unsigned short attrs_avp_type;
81
-extern int_str sock_avp_name;
82
-extern unsigned short sock_avp_type;
75
+extern str ds_xavp_dst;
76
+extern int ds_xavp_dst_mode;
77
+extern str ds_xavp_ctx;
78
+extern int ds_xavp_ctx_mode;
79
+
80
+extern str ds_xavp_dst_addr;
81
+extern str ds_xavp_dst_grp;
82
+extern str ds_xavp_dst_dstid;
83
+extern str ds_xavp_dst_attrs;
84
+extern str ds_xavp_dst_sock;
85
+
86
+extern str ds_xavp_ctx_cnt;
83 87
 
84 88
 extern pv_elem_t *hash_param_model;
85 89
 
Browse code

dispatcher: congestion detection load balancing

Thanks to Amy Meyers for her help !

Julien Chavanton authored on 29/03/2018 23:14:21
Showing 1 changed files
... ...
@@ -155,6 +155,7 @@ typedef struct _ds_attrs {
155 155
 	int maxload;
156 156
 	int weight;
157 157
 	int rweight;
158
+	int congestion_control;
158 159
 } ds_attrs_t;
159 160
 
160 161
 typedef struct _ds_latency_stats {
... ...
@@ -195,6 +196,7 @@ typedef struct _ds_set {
195 196
 	unsigned int rwlist[100];
196 197
 	struct _ds_set *next[2];
197 198
 	int longer;
199
+	gen_lock_t lock;
198 200
 } ds_set_t;
199 201
 /* clang-format on */
200 202
 
Browse code

dispatcher: add method to reinit state for all destinations in group

Timmo Verlaan authored on 14/01/2018 15:27:07
Showing 1 changed files
... ...
@@ -115,6 +115,7 @@ int ds_select_dst(struct sip_msg *msg, int set, int alg, int mode);
115 115
 int ds_next_dst(struct sip_msg *msg, int mode);
116 116
 int ds_update_state(sip_msg_t *msg, int group, str *address, int state);
117 117
 int ds_reinit_state(int group, str *address, int state);
118
+int ds_reinit_state_all(int group, int state);
118 119
 int ds_mark_dst(struct sip_msg *msg, int mode);
119 120
 int ds_print_list(FILE *fout);
120 121
 int ds_log_sets(void);
Browse code

dispatcher: latency fix stdev calculation

- adding linking to lm library

Julien Chavanton authored on 15/09/2017 16:34:19
Showing 1 changed files
... ...
@@ -163,7 +163,7 @@ typedef struct _ds_latency_stats {
163 163
 	float average;  // weigthed average, estimate of the last few weeks
164 164
 	float stdev;    // last standard deviation
165 165
 	float estimate; // short term estimate, EWMA exponential weighted moving average
166
-	float last_q;   // q for N-1
166
+	double m2;      // sum of squares, used for recursive variance calculation
167 167
 	int32_t count;
168 168
 	uint32_t timeout;
169 169
 } ds_latency_stats_t;
Browse code

dispatcher: latency statistics

Julien Chavanton authored on 11/09/2017 22:15:49
Showing 1 changed files
... ...
@@ -156,12 +156,25 @@ typedef struct _ds_attrs {
156 156
 	int rweight;
157 157
 } ds_attrs_t;
158 158
 
159
+typedef struct _ds_latency_stats {
160
+	struct timeval start;
161
+	int min;
162
+	int max;
163
+	float average;  // weigthed average, estimate of the last few weeks
164
+	float stdev;    // last standard deviation
165
+	float estimate; // short term estimate, EWMA exponential weighted moving average
166
+	float last_q;   // q for N-1
167
+	int32_t count;
168
+	uint32_t timeout;
169
+} ds_latency_stats_t;
170
+
159 171
 typedef struct _ds_dest {
160 172
 	str uri;
161 173
 	int flags;
162 174
 	int priority;
163 175
 	int dload;
164 176
 	ds_attrs_t attrs;
177
+	ds_latency_stats_t latency_stats;
165 178
 	struct socket_info * sock;
166 179
 	struct ip_addr ip_address; 	/*!< IP-Address of the entry */
167 180
 	unsigned short int port; 	/*!< Port of the URI */
Browse code

modules/dispatcher: comment typo [skip ci]

Mikko Lehto authored on 21/06/2017 17:03:28
Showing 1 changed files
... ...
@@ -175,7 +175,7 @@ typedef struct _ds_set {
175 175
 	int nr;				/*!< number of items in dst set */
176 176
 	int last;			/*!< last used item in dst set (round robin) */
177 177
 	int wlast;			/*!< last used item in dst set (by weight) */
178
-	int rwlast;			/*!< last used item in dst set (by relaitive weight) */
178
+	int rwlast;			/*!< last used item in dst set (by relative weight) */
179 179
 	ds_dest_t *dlist;
180 180
 	unsigned int wlist[100];
181 181
 	unsigned int rwlist[100];
Browse code

dispatcher: use clang format across the module

Daniel-Constantin Mierla authored on 10/01/2017 22:36:18
Showing 1 changed files
... ...
@@ -35,6 +35,7 @@
35 35
 #include "../../modules/tm/tm_load.h"
36 36
 
37 37
 
38
+/* clang-format off */
38 39
 #define DS_HASH_USER_ONLY	1  /*!< use only the uri user part for hashing */
39 40
 #define DS_FAILOVER_ON		2  /*!< store the other dest in avps */
40 41
 
... ...
@@ -54,6 +55,7 @@
54 55
 #define DS_MATCH_ALL		0
55 56
 #define DS_MATCH_NOPORT		1
56 57
 #define DS_MATCH_NOPROTO	2
58
+/* clang-format on */
57 59
 
58 60
 extern str ds_db_url;
59 61
 extern str ds_table_name;
... ...
@@ -79,7 +81,7 @@ extern unsigned short attrs_avp_type;
79 81
 extern int_str sock_avp_name;
80 82
 extern unsigned short sock_avp_type;
81 83
 
82
-extern pv_elem_t * hash_param_model;
84
+extern pv_elem_t *hash_param_model;
83 85
 
84 86
 extern str ds_setid_pvname;
85 87
 extern pv_spec_t ds_setid_pv;
... ...
@@ -90,14 +92,14 @@ extern pv_spec_t ds_attrs_pv;
90 92
 extern struct tm_binds tmb;
91 93
 extern str ds_ping_method;
92 94
 extern str ds_ping_from;
93
-extern int probing_threshold; /*!< number of failed requests,
95
+extern int probing_threshold;  /*!< number of failed requests,
94 96
 								before a destination is taken into probing */
95 97
 extern int inactive_threshold; /*!< number of successful requests,
96 98
 								before a destination is taken into active */
97 99
 extern int ds_probing_mode;
98 100
 extern str ds_outbound_proxy;
99 101
 extern str ds_default_socket;
100
-extern struct socket_info * ds_default_sockinfo;
102
+extern struct socket_info *ds_default_sockinfo;
101 103
 
102 104
 int init_data(void);
103 105
 int init_ds_db(void);
... ...
@@ -107,7 +109,8 @@ void ds_disconnect_db(void);
107 109
 int ds_load_db(void);
108 110
 int ds_reload_db(void);
109 111
 int ds_destroy_list(void);
110
-int ds_select_dst_limit(struct sip_msg *msg, int set, int alg, unsigned int limit, int mode);
112
+int ds_select_dst_limit(
113
+		struct sip_msg *msg, int set, int alg, unsigned int limit, int mode);
111 114
 int ds_select_dst(struct sip_msg *msg, int set, int alg, int mode);
112 115
 int ds_next_dst(struct sip_msg *msg, int mode);
113 116
 int ds_update_state(sip_msg_t *msg, int group, str *address, int state);
... ...
@@ -130,7 +133,7 @@ int ds_is_addr_from_list(sip_msg_t *_m, int group, str *uri, int mode);
130 133
 /*! \brief
131 134
  * Timer for checking inactive destinations
132 135
  */
133
-void ds_check_timer(unsigned int ticks, void* param);
136
+void ds_check_timer(unsigned int ticks, void *param);
134 137
 
135 138
 
136 139
 /*! \brief
... ...
@@ -143,8 +146,8 @@ void ds_ht_timer(unsigned int ticks, void *param);
143 146
  */
144 147
 int ds_ping_check_rplcode(int);
145 148
 
146
-typedef struct _ds_attrs
147
-{
149
+/* clang-format off */
150
+typedef struct _ds_attrs {
148 151
 	str body;
149 152
 	str duid;
150 153
 	str socket;
... ...
@@ -153,8 +156,7 @@ typedef struct _ds_attrs
153 156
 	int rweight;
154 157
 } ds_attrs_t;
155 158
 
156
-typedef struct _ds_dest
157
-{
159
+typedef struct _ds_dest {
158 160
 	str uri;
159 161
 	int flags;
160 162
 	int priority;
... ...
@@ -168,8 +170,7 @@ typedef struct _ds_dest
168 170
 	struct _ds_dest *next;
169 171
 } ds_dest_t;
170 172
 
171
-typedef struct _ds_set
172
-{
173
+typedef struct _ds_set {
173 174
 	int id;				/*!< id of dst set */
174 175
 	int nr;				/*!< number of items in dst set */
175 176
 	int last;			/*!< last used item in dst set (round robin) */
... ...
@@ -181,6 +182,8 @@ typedef struct _ds_set
181 182
 	struct _ds_set *next[2];
182 183
 	int longer;
183 184
 } ds_set_t;
185
+/* clang-format on */
186
+
184 187
 #define AVL_LEFT 0
185 188
 #define AVL_RIGHT 1
186 189
 #define AVL_NEITHER -1
... ...
@@ -193,9 +196,9 @@ int ds_ping_active_init(void);
193 196
 int ds_ping_active_get(void);
194 197
 int ds_ping_active_set(int v);
195 198
 
196
-ds_set_t* ds_avl_insert( ds_set_t** root, int id, int* setn ); /// Create if not exist and return ds_set_t by id
197
-ds_set_t* ds_avl_find( ds_set_t* node, int id );
198
-void ds_avl_destroy( ds_set_t** node );
199
+/* Create if not exist and return ds_set_t by id */
200
+ds_set_t *ds_avl_insert(ds_set_t **root, int id, int *setn);
201
+ds_set_t *ds_avl_find(ds_set_t *node, int id);
202
+void ds_avl_destroy(ds_set_t **node);
199 203
 
200 204
 #endif
201
-
Browse code

dispatcher: removed unused mi related prototype

Daniel-Constantin Mierla authored on 04/01/2017 14:26:23
Showing 1 changed files
... ...
@@ -1,6 +1,6 @@
1 1
 /**
2 2
  * dispatcher module
3
- * 
3
+ *
4 4
  * Copyright (C) 2004-2006 FhG Fokus
5 5
  *
6 6
  * This file is part of Kamailio, a free SIP server.
... ...
@@ -15,8 +15,8 @@
15 15
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 16
  * GNU General Public License for more details.
17 17
  *
18
- * You should have received a copy of the GNU General Public License 
19
- * along with this program; if not, write to the Free Software 
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program; if not, write to the Free Software
20 20
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21 21
  */
22 22
 
... ...
@@ -63,7 +63,7 @@ extern str ds_dest_flags_col;
63 63
 extern str ds_dest_priority_col;
64 64
 extern str ds_dest_attrs_col;
65 65
 
66
-extern int ds_flags; 
66
+extern int ds_flags;
67 67
 extern int ds_use_default;
68 68
 
69 69
 extern int_str dst_avp_name;
... ...
@@ -92,7 +92,7 @@ extern str ds_ping_method;
92 92
 extern str ds_ping_from;
93 93
 extern int probing_threshold; /*!< number of failed requests,
94 94
 								before a destination is taken into probing */
95
-extern int inactive_threshold; /*!< number of successful requests, 
95
+extern int inactive_threshold; /*!< number of successful requests,
96 96
 								before a destination is taken into active */
97 97
 extern int ds_probing_mode;
98 98
 extern str ds_outbound_proxy;
... ...
@@ -114,7 +114,6 @@ int ds_update_state(sip_msg_t *msg, int group, str *address, int state);
114 114
 int ds_reinit_state(int group, str *address, int state);
115 115
 int ds_mark_dst(struct sip_msg *msg, int mode);
116 116
 int ds_print_list(FILE *fout);
117
-int ds_print_mi_list(struct mi_node* rpl);
118 117
 int ds_log_sets(void);
119 118
 int ds_list_exist(int set);
120 119
 
Browse code

core, lib, modules: updated include paths for header files

Daniel-Constantin Mierla authored on 07/12/2016 11:07:22
Showing 1 changed files
... ...
@@ -29,9 +29,9 @@
29 29
 #define _DISPATCH_H_
30 30
 
31 31
 #include <stdio.h>
32
-#include "../../pvar.h"
33
-#include "../../parser/msg_parser.h"
34
-#include "../../rand/kam_rand.h"
32
+#include "../../core/pvar.h"
33
+#include "../../core/parser/msg_parser.h"
34
+#include "../../core/rand/kam_rand.h"
35 35
 #include "../../modules/tm/tm_load.h"
36 36
 
37 37
 
Browse code

core, lib, modules: restructured source code tree

- new folder src/ to hold the source code for main project applications
- main.c is in src/
- all core files are subfolder are in src/core/
- modules are in src/modules/
- libs are in src/lib/
- application Makefiles are in src/
- application binary is built in src/ (src/kamailio)

Daniel-Constantin Mierla authored on 07/12/2016 11:03:51
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,202 @@
1
+/**
2
+ * dispatcher module
3
+ * 
4
+ * Copyright (C) 2004-2006 FhG Fokus
5
+ *
6
+ * This file is part of Kamailio, a free SIP server.
7
+ *
8
+ * Kamailio is free software; you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation; either version 2 of the License, or
11
+ * (at your option) any later version
12
+ *
13
+ * Kamailio is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License 
19
+ * along with this program; if not, write to the Free Software 
20
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21
+ */
22
+
23
+/*! \file
24
+ * \ingroup dispatcher
25
+ * \brief Dispatcher :: Dispatch
26
+ */
27
+
28
+#ifndef _DISPATCH_H_
29
+#define _DISPATCH_H_
30
+
31
+#include <stdio.h>
32
+#include "../../pvar.h"
33
+#include "../../parser/msg_parser.h"
34
+#include "../../rand/kam_rand.h"
35
+#include "../../modules/tm/tm_load.h"
36
+
37
+
38
+#define DS_HASH_USER_ONLY	1  /*!< use only the uri user part for hashing */
39
+#define DS_FAILOVER_ON		2  /*!< store the other dest in avps */
40
+
41
+#define DS_INACTIVE_DST		1  /*!< inactive destination */
42
+#define DS_TRYING_DST		2  /*!< temporary trying destination */
43
+#define DS_DISABLED_DST		4  /*!< admin disabled destination */
44
+#define DS_PROBING_DST		8  /*!< checking destination */
45
+#define DS_STATES_ALL		15  /*!< all bits for the states of destination */
46
+
47
+#define ds_skip_dst(flags)	((flags) & (DS_INACTIVE_DST|DS_DISABLED_DST))
48
+
49
+#define DS_PROBE_NONE		0
50
+#define DS_PROBE_ALL		1
51
+#define DS_PROBE_INACTIVE	2
52
+#define DS_PROBE_ONLYFLAGGED	3
53
+
54
+#define DS_MATCH_ALL		0
55
+#define DS_MATCH_NOPORT		1
56
+#define DS_MATCH_NOPROTO	2
57
+
58
+extern str ds_db_url;
59
+extern str ds_table_name;
60
+extern str ds_set_id_col;
61
+extern str ds_dest_uri_col;
62
+extern str ds_dest_flags_col;
63
+extern str ds_dest_priority_col;
64
+extern str ds_dest_attrs_col;
65
+
66
+extern int ds_flags; 
67
+extern int ds_use_default;
68
+
69
+extern int_str dst_avp_name;
70
+extern unsigned short dst_avp_type;
71
+extern int_str grp_avp_name;
72
+extern unsigned short grp_avp_type;
73
+extern int_str cnt_avp_name;
74
+extern unsigned short cnt_avp_type;
75
+extern int_str dstid_avp_name;
76
+extern unsigned short dstid_avp_type;
77
+extern int_str attrs_avp_name;
78
+extern unsigned short attrs_avp_type;
79
+extern int_str sock_avp_name;
80
+extern unsigned short sock_avp_type;
81
+
82
+extern pv_elem_t * hash_param_model;
83
+
84
+extern str ds_setid_pvname;
85
+extern pv_spec_t ds_setid_pv;
86
+extern str ds_attrs_pvname;
87
+extern pv_spec_t ds_attrs_pv;
88
+
89
+/* Structure containing pointers to TM-functions */
90
+extern struct tm_binds tmb;
91
+extern str ds_ping_method;
92
+extern str ds_ping_from;
93
+extern int probing_threshold; /*!< number of failed requests,
94
+								before a destination is taken into probing */
95
+extern int inactive_threshold; /*!< number of successful requests, 
96
+								before a destination is taken into active */
97
+extern int ds_probing_mode;
98
+extern str ds_outbound_proxy;
99
+extern str ds_default_socket;
100
+extern struct socket_info * ds_default_sockinfo;
101
+
102
+int init_data(void);
103
+int init_ds_db(void);
104
+int ds_load_list(char *lfile);
105
+int ds_connect_db(void);
106
+void ds_disconnect_db(void);
107
+int ds_load_db(void);
108
+int ds_reload_db(void);
109
+int ds_destroy_list(void);
110
+int ds_select_dst_limit(struct sip_msg *msg, int set, int alg, unsigned int limit, int mode);
111
+int ds_select_dst(struct sip_msg *msg, int set, int alg, int mode);
112
+int ds_next_dst(struct sip_msg *msg, int mode);
113
+int ds_update_state(sip_msg_t *msg, int group, str *address, int state);
114
+int ds_reinit_state(int group, str *address, int state);
115
+int ds_mark_dst(struct sip_msg *msg, int mode);
116
+int ds_print_list(FILE *fout);
117
+int ds_print_mi_list(struct mi_node* rpl);
118
+int ds_log_sets(void);
119
+int ds_list_exist(int set);
120
+
121
+
122
+int ds_load_unset(struct sip_msg *msg);
123
+int ds_load_update(struct sip_msg *msg);
124
+
125
+int ds_hash_load_init(unsigned int htsize, int expire, int initexpire);
126
+int ds_hash_load_destroy(void);
127
+
128
+int ds_is_from_list(struct sip_msg *_m, int group);
129
+int ds_is_addr_from_list(sip_msg_t *_m, int group, str *uri, int mode);
130
+
131
+/*! \brief
132
+ * Timer for checking inactive destinations
133
+ */
134
+void ds_check_timer(unsigned int ticks, void* param);
135
+
136
+
137
+/*! \brief
138
+ * Timer for checking active calls load
139
+ */
140
+void ds_ht_timer(unsigned int ticks, void *param);
141
+
142
+/*! \brief
143
+ * Check if the reply-code is valid:
144
+ */
145
+int ds_ping_check_rplcode(int);
146
+
147
+typedef struct _ds_attrs
148
+{
149
+	str body;
150
+	str duid;
151
+	str socket;
152
+	int maxload;
153
+	int weight;
154
+	int rweight;
155
+} ds_attrs_t;
156
+
157
+typedef struct _ds_dest
158
+{
159
+	str uri;
160
+	int flags;
161
+	int priority;
162
+	int dload;
163
+	ds_attrs_t attrs;
164
+	struct socket_info * sock;
165
+	struct ip_addr ip_address; 	/*!< IP-Address of the entry */
166
+	unsigned short int port; 	/*!< Port of the URI */
167
+	unsigned short int proto; 	/*!< Protocol of the URI */
168
+	int message_count;
169
+	struct _ds_dest *next;
170
+} ds_dest_t;
171
+
172
+typedef struct _ds_set
173
+{
174
+	int id;				/*!< id of dst set */
175
+	int nr;				/*!< number of items in dst set */
176
+	int last;			/*!< last used item in dst set (round robin) */
177
+	int wlast;			/*!< last used item in dst set (by weight) */
178
+	int rwlast;			/*!< last used item in dst set (by relaitive weight) */
179
+	ds_dest_t *dlist;
180
+	unsigned int wlist[100];
181
+	unsigned int rwlist[100];
182
+	struct _ds_set *next[2];
183
+	int longer;
184
+} ds_set_t;
185
+#define AVL_LEFT 0
186
+#define AVL_RIGHT 1
187
+#define AVL_NEITHER -1
188
+#define AVL_BALANCED(n) (n->longer < 0)
189
+
190
+ds_set_t *ds_get_list(void);
191
+int ds_get_list_nr(void);
192
+
193
+int ds_ping_active_init(void);
194
+int ds_ping_active_get(void);
195
+int ds_ping_active_set(int v);
196
+
197
+ds_set_t* ds_avl_insert( ds_set_t** root, int id, int* setn ); /// Create if not exist and return ds_set_t by id
198
+ds_set_t* ds_avl_find( ds_set_t* node, int id );
199
+void ds_avl_destroy( ds_set_t** node );
200
+
201
+#endif
202
+