diff --git a/README.md b/README.md index c8411132f..cc8801ca5 100644 --- a/README.md +++ b/README.md @@ -170,8 +170,6 @@ option and which are reproduced below: -M, --port-max=INT Highest port to use for RTP -r, --redis=IP:PORT Connect to Redis database -R, --redis-db=INT Which Redis DB to use - -z, --redis-read=IP:PORT Connect to Redis read database - -Z, --redis-read-db=INT Which Redis read DB to use -w, --redis-write=IP:PORT Connect to Redis write database -W, --redis-write-db=INT Which Redis write DB to use -b, --b2b-url=STRING XMLRPC URL of B2B UA @@ -334,11 +332,6 @@ The options are described in more detail below. Log to stderr instead of syslog. Only useful in combination with `--foreground`. -* -x, --xmlrpc-format - - Selects the internal format of the XMLRPC callback message for B2BUA call teardown. 0 is for SEMS, - 1 is for a generic format containing the call-ID only. - * --num-threads How many worker threads to create, must be at least one. The default is to create as many threads @@ -361,9 +354,36 @@ The options are described in more detail below. Delete the call from memory after the specified delay from memory. Can be set to zero for immediate call deletion. -* -r, --redis, -R, --redis-db, -z, --redis-read, -Z, --redis-read-db, -w, --redis-write, -W, --redis-write-db, -b, --b2b-url +* -r, --redis, -R, --redis-db + + Connect to specified Redis database (with the given database number) and use it for persistence + storage. On startup, *rtpengine* will read the contents of this database and restore all calls + stored therein. During runtime operation, *rtpengine* will continually update the database's + contents to keep it current, so that in case of a service disruption, the last state can be restored + upon a restart. + + When this option is given, *rtpengine* will delay startup until the Redis database adopts the + master role (but see below). + +* -w, --redis-write, -W, --redis-write-db + + Configures a second Redis database for write operations. If this option is given in addition to the + first one, then the first database will be used for read operations (i.e. to restore calls from) while + the second one will be used for write operations (to update states in the database). + + When both options are given, *rtpengine* will start and use the Redis database regardless of the + database's role (master or slave). - NGCP-specific options +* -b, --b2b-url + + Enables and sets the URI for an XMLRPC callback to be made when a call is torn down due to packet + timeout. The special code `%%` can be used in place of an IP address, in which case the source address + of the originating request will be used. + +* -x, --xmlrpc-format + + Selects the internal format of the XMLRPC callback message for B2BUA call teardown. 0 is for SEMS, + 1 is for a generic format containing the call-ID only. * -g, --graphite @@ -557,26 +577,6 @@ then the start-up sequence might look like this: With this setup, the SIP proxy can choose which instance of *rtpengine* to talk to and thus which local interface to use by sending its control messages to either port 2223 or port 2224. -REDIS Database interaction -------------------------- - -Rtpengine is able to write call details in redis database and retore the calls from the same database. -To configure the redis parameters have a look on -r/-R, -z/-Z, -w/-W parameters. - -The three REDIS params could be specified in rtpengine's config file: -* REDIS -> specify the redis database for both read and write ops; expected role of redis is checked to be master and won't start if it is not -* REDIS_READ -> specify the redis database for read ops; expected role of redis may be any, master or slave -* REDIS_WRITE -> specify the redis database for write ops; expected role of redis could be any, master or slave - -One can specify combinations of REDIS/REDIS_READ/WRITE at the same time. For example: -* REDIS=IP1 -> will use IP1 for read and write operations -* REDIS=IP1, REDIS_READ=IP2 -> will use IP1 for write and IP2 for read operations -* REDIS=IP1, REDIS_WRITE=IP2 -> will use IP1 for read and IP2 for write operations -* REDIS=IP1, REDIS_READ=IP2, REDIS_WRITE=IP3 -> will use IP2 for read and IP3 for write operations -* REDIS_READ=IP1, REDIS_WRITE=IP2 -> will use IP1 for read and IP2 for write operations -* REDIS_READ=IP1 -> will use IP1 for read operations; write operations are ignored -* REDIS_WRITE=IP1 -> will use IP1 for write operations; read operations are ignored - The *ng* Control Protocol ========================= diff --git a/daemon/call.c b/daemon/call.c index 5e30c2d34..f4eb3fe71 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -566,13 +566,8 @@ static void callmaster_timer(void *ptr) { rwlock_unlock_r(&sfd->call->master_lock); - if (update) { - if (m->conf.redis_write) { - redis_update(ps->call, m->conf.redis_write); - } else if (m->conf.redis) { - redis_update(ps->call, m->conf.redis); - } - } + if (update) + redis_update(ps->call, m->conf.redis_write); next: g_hash_table_remove(hlp.addr_sfd, &ep); @@ -1846,11 +1841,7 @@ void call_destroy(struct call *c) { obj_put(c); - if (m->conf.redis_write) { - redis_delete(c, m->conf.redis_write); - } else if (m->conf.redis) { - redis_delete(c, m->conf.redis); - } + redis_delete(c, m->conf.redis_write); rwlock_lock_w(&c->master_lock); /* at this point, no more packet streams can be added */ @@ -2708,6 +2699,9 @@ void callmaster_get_all_calls(struct callmaster *m, GQueue *q) { } +#if 0 +// unused +// simplifty redis_write <> redis if put back into use static void calls_dump_iterator(void *key, void *val, void *ptr) { struct call *c = val; struct callmaster *m = c->callmaster; @@ -2748,6 +2742,7 @@ void calls_dump_redis_write(struct callmaster *m) { g_hash_table_foreach(m->callhash, calls_dump_iterator, NULL); ilog(LOG_DEBUG, "Finished dumping all call data to write Redis\n"); } +#endif const struct transport_protocol *transport_protocol(const str *s) { int i; diff --git a/daemon/call.h b/daemon/call.h index f035a826c..937fa60dd 100644 --- a/daemon/call.h +++ b/daemon/call.h @@ -424,7 +424,6 @@ struct callmaster_config { unsigned int silent_timeout; unsigned int delete_delay; struct redis *redis; - struct redis *redis_read; struct redis *redis_write; char *b2b_url; unsigned char default_tos; @@ -473,9 +472,9 @@ void callmaster_get_all_calls(struct callmaster *m, GQueue *q); struct timeval add_ongoing_calls_dur_in_interval(struct callmaster *m, struct timeval *iv_start, struct timeval *iv_duration); -void calls_dump_redis(struct callmaster *); -void calls_dump_redis_read(struct callmaster *); -void calls_dump_redis_write(struct callmaster *); +//void calls_dump_redis(struct callmaster *); +//void calls_dump_redis_read(struct callmaster *); +//void calls_dump_redis_write(struct callmaster *); struct call_monologue *__monologue_create(struct call *call); void __monologue_tag(struct call_monologue *ml, const str *tag); void __monologue_viabranch(struct call_monologue *ml, const str *viabranch); diff --git a/daemon/call_interfaces.c b/daemon/call_interfaces.c index 9b2468174..c7b4fd5ec 100644 --- a/daemon/call_interfaces.c +++ b/daemon/call_interfaces.c @@ -186,11 +186,7 @@ static str *call_update_lookup_udp(char **out, struct callmaster *m, enum call_o sp.index, sp.index, out[RE_UDP_COOKIE], SAF_UDP); rwlock_unlock_w(&c->master_lock); - if (m->conf.redis_write) { - redis_update(c, m->conf.redis_write); - } else if (m->conf.redis) { - redis_update(c, m->conf.redis); - } + redis_update(c, m->conf.redis_write); gettimeofday(&(monologue->started), NULL); @@ -338,11 +334,7 @@ out2: rwlock_unlock_w(&c->master_lock); streams_free(&s); - if (m->conf.redis_write) { - redis_update(c, m->conf.redis_write); - } else if (m->conf.redis) { - redis_update(c, m->conf.redis); - } + redis_update(c, m->conf.redis_write); ilog(LOG_INFO, "Returning to SIP proxy: "STR_FORMAT"", STR_FMT0(ret)); obj_put(c); @@ -719,11 +711,7 @@ static const char *call_offer_answer_ng(bencode_item_t *input, struct callmaster ret = sdp_replace(chopper, &parsed, monologue->active_dialogue, &flags); rwlock_unlock_w(&call->master_lock); - if (m->conf.redis_write) { - redis_update(call, m->conf.redis_write); - } else if (m->conf.redis) { - redis_update(call, m->conf.redis); - } + redis_update(call, m->conf.redis_write); obj_put(call); gettimeofday(&(monologue->started), NULL); diff --git a/daemon/main.c b/daemon/main.c index d0dfcf545..8d0e0321a 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -32,11 +32,6 @@ -#define REDIS_MODULE_VERSION "redis/9" - - - - #define die(x...) do { \ fprintf(stderr, x); \ fprintf(stderr, "\n"); \ @@ -65,7 +60,6 @@ endpoint_t ng_listen_ep; endpoint_t cli_listen_ep; endpoint_t graphite_ep; endpoint_t redis_ep; -endpoint_t redis_read_ep; endpoint_t redis_write_ep; static int tos; static int table = -1; @@ -76,7 +70,6 @@ static int port_min = 30000; static int port_max = 40000; static int max_sessions = -1; static int redis_db = -1; -static int redis_read_db = -1; static int redis_write_db = -1; static char *b2b_url; static enum xmlrpc_format xmlrpc_fmt = XF_SEMS; @@ -233,7 +226,7 @@ static void options(int *argc, char ***argv) { char *graphitep = NULL; char *graphite_prefix_s = NULL; char *redisps = NULL; - char *redisps_read = NULL, *redisps_write = NULL; + char *redisps_write = NULL; char *log_facility_s = NULL; char *log_facility_cdr_s = NULL; char *log_facility_rtcp_s = NULL; @@ -261,8 +254,6 @@ static void options(int *argc, char ***argv) { { "port-max", 'M', 0, G_OPTION_ARG_INT, &port_max, "Highest port to use for RTP", "INT" }, { "redis", 'r', 0, G_OPTION_ARG_STRING, &redisps, "Connect to Redis database", "IP:PORT" }, { "redis-db", 'R', 0, G_OPTION_ARG_INT, &redis_db, "Which Redis DB to use", "INT" }, - { "redis-read", 'z', 0, G_OPTION_ARG_STRING, &redisps_read, "Connect to Redis read database", "IP:PORT" }, - { "redis-read-db", 'Z', 0, G_OPTION_ARG_INT, &redis_read_db, "Which Redis read DB to use", "INT" }, { "redis-write",'w', 0, G_OPTION_ARG_STRING, &redisps_write, "Connect to Redis write database", "IP:PORT" }, { "redis-write-db", 'W', 0, G_OPTION_ARG_INT, &redis_write_db,"Which Redis write DB to use", "INT" }, { "b2b-url", 'b', 0, G_OPTION_ARG_STRING, &b2b_url, "XMLRPC URL of B2B UA" , "STRING" }, @@ -276,7 +267,7 @@ static void options(int *argc, char ***argv) { { "delete-delay", 'd', 0, G_OPTION_ARG_INT, &delete_delay, "Delay for deleting a session from memory.", "INT" }, { "sip-source", 0, 0, G_OPTION_ARG_NONE, &sip_source, "Use SIP source address by default", NULL }, { "dtls-passive", 0, 0, G_OPTION_ARG_NONE, &dtls_passive_def,"Always prefer DTLS passive role", NULL }, - { "max-sessions", 0, 0, G_OPTION_ARG_INT, &max_sessions, "Limit of maximum number of sessions", NULL }, + { "max-sessions", 0, 0, G_OPTION_ARG_INT, &max_sessions, "Limit of maximum number of sessions", "INT" }, { NULL, } }; @@ -342,13 +333,6 @@ static void options(int *argc, char ***argv) { die("Must specify Redis DB number (--redis-db) when using Redis"); } - if (redisps_read) { - if (endpoint_parse_any(&redis_read_ep, redisps_read)) - die("Invalid Redis read IP or port (--redis-read)"); - if (redis_read_db < 0) - die("Must specify Redis read DB number (--redis-read-db) when using Redis"); - } - if (redisps_write) { if (endpoint_parse_any(&redis_write_ep, redisps_write)) die("Invalid Redis write IP or port (--redis-write)"); @@ -558,22 +542,19 @@ no_kernel: die("Failed to open UDP CLI connection port"); } + if (!is_addr_unspecified(&redis_write_ep.address)) { + mc.redis_write = redis_new(&redis_write_ep, redis_write_db, ANY_REDIS_ROLE); + if (!mc.redis_write) + die("Cannot start up without Redis write database"); + } + if (!is_addr_unspecified(&redis_ep.address)) { - mc.redis = redis_new(&redis_ep, redis_db, MASTER_REDIS_ROLE); + mc.redis = redis_new(&redis_ep, redis_db, mc.redis_write ? ANY_REDIS_ROLE : MASTER_REDIS_ROLE); if (!mc.redis) die("Cannot start up without Redis database"); - } - - if (!is_addr_unspecified(&redis_read_ep.address)) { - mc.redis_read = redis_new(&redis_read_ep, redis_read_db, ANY_REDIS_ROLE); - if (!mc.redis_read) - die("Cannot start up without Redis read database"); - } - if (!is_addr_unspecified(&redis_write_ep.address)) { - mc.redis_write = redis_new(&redis_write_ep, redis_write_db, ANY_REDIS_ROLE); if (!mc.redis_write) - die("Cannot start up without Redis write database"); + mc.redis_write = mc.redis; } ctx->m->conf = mc; @@ -586,13 +567,8 @@ no_kernel: gettimeofday(&redis_start, NULL); // restore - if (mc.redis_read) { - if (redis_restore(ctx->m, mc.redis_read)) - die("Refusing to continue without working Redis read database"); - } else if (mc.redis) { - if (redis_restore(ctx->m, mc.redis)) - die("Refusing to continue without working Redis database"); - } + if (redis_restore(ctx->m, mc.redis)) + die("Refusing to continue without working Redis database"); // stop redis restore timer gettimeofday(&redis_stop, NULL); diff --git a/daemon/media_socket.c b/daemon/media_socket.c index 59886e1bc..b9e1e7328 100644 --- a/daemon/media_socket.c +++ b/daemon/media_socket.c @@ -1395,13 +1395,8 @@ static void stream_fd_readable(int fd, void *p, uintptr_t u) { out: ca = sfd->call ? : NULL; - if (ca && update) { - if (ca->callmaster->conf.redis_write) { - redis_update(ca, ca->callmaster->conf.redis); - } else if (ca->callmaster->conf.redis) { - redis_update(ca, ca->callmaster->conf.redis); - } - } + if (ca && update) + redis_update(ca, ca->callmaster->conf.redis_write); done: log_info_clear(); } diff --git a/debian/ngcp-rtpengine-daemon.default b/debian/ngcp-rtpengine-daemon.default index e950f8f00..b341e198f 100644 --- a/debian/ngcp-rtpengine-daemon.default +++ b/debian/ngcp-rtpengine-daemon.default @@ -17,8 +17,6 @@ TABLE=0 # PORT_MAX=50000 # REDIS=127.0.0.1:6379 # REDIS_DB=1 -# REDIS_READ=127.0.0.1:6379 -# REDIS_READ_DB=1 # REDIS_WRITE=127.0.0.1:6379 # REDIS_WRITE_DB=1 # B2B_URL=http://127.0.0.1:8090/ diff --git a/debian/ngcp-rtpengine-daemon.init b/debian/ngcp-rtpengine-daemon.init index 7fbabc63f..8d586af98 100755 --- a/debian/ngcp-rtpengine-daemon.init +++ b/debian/ngcp-rtpengine-daemon.init @@ -64,8 +64,6 @@ fi [ -z "$PORT_MAX" ] || OPTIONS="$OPTIONS --port-max=$PORT_MAX" [ -z "$REDIS" ] || OPTIONS="$OPTIONS --redis=$REDIS" [ -z "$REDIS_DB" ] || OPTIONS="$OPTIONS --redis-db=$REDIS_DB" -[ -z "$REDIS_READ" ] || OPTIONS="$OPTIONS --redis-read=$REDIS_READ" -[ -z "$REDIS_READ_DB" ] || OPTIONS="$OPTIONS --redis-read-db=$REDIS_READ_DB" [ -z "$REDIS_WRITE" ] || OPTIONS="$OPTIONS --redis-write=$REDIS_WRITE" [ -z "$REDIS_WRITE_DB" ] || OPTIONS="$OPTIONS --redis-write-db=$REDIS_WRITE_DB" [ -z "$B2B_URL" ] || OPTIONS="$OPTIONS --b2b-url=$B2B_URL"