diff --git a/README.md b/README.md index 9ead94c14..0e368e47e 100644 --- a/README.md +++ b/README.md @@ -801,6 +801,11 @@ Optionally included keys are: The SIP `Via` branch as string. Used to additionally refine the matching logic between media streams and calls and call branches. +* `label` + + A custom free-form string which *rtpengine* remembers for this participating endpoint and reports + back in logs and statistics output. + * `flags` The value of the `flags` key is a list. The list contains zero or more of the following strings. @@ -1165,6 +1170,10 @@ The response dictionary contains the following keys: Identical to the corresponding key of the `tags` dictionary. Provided to allow for easy traversing of the dictionary values without paying attention to the keys. + - `label` + + The label assigned to this endpoint in the `offer` or `answer` message. + - `in dialogue with` Contains the SIP tag of the other side of this dialogue. May be missing in case of a diff --git a/daemon/call.c b/daemon/call.c index 840a3e2ec..833477c85 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -1853,9 +1853,12 @@ void call_destroy(struct call *c) { for (l = c->monologues.head; l; l = l->next) { ml = l->data; - ilog(LOG_INFO, "--- Tag '"STR_FORMAT"', created " + ilog(LOG_INFO, "--- Tag '"STR_FORMAT"'%s"STR_FORMAT"%s, created " "%u:%02u ago for branch '"STR_FORMAT"', in dialogue with '"STR_FORMAT"'", STR_FMT(&ml->tag), + ml->label.s ? " (label '" : "", + STR_FMT(ml->label.s ? &ml->label : &STR_EMPTY), + ml->label.s ? "')" : "", (unsigned int) (poller_now - ml->created) / 60, (unsigned int) (poller_now - ml->created) % 60, STR_FMT(&ml->viabranch), @@ -2238,14 +2241,22 @@ static int monologue_destroy(struct call_monologue *ml) { __monologue_destroy(ml); if (!g_hash_table_size(c->tags)) { - ilog(LOG_INFO, "Call branch '"STR_FORMAT"' (via-branch '"STR_FORMAT"') " + ilog(LOG_INFO, "Call branch '"STR_FORMAT"' (%s"STR_FORMAT"%svia-branch '"STR_FORMAT"') " "deleted, no more branches remaining", - STR_FMT(&ml->tag), STR_FMT0(&ml->viabranch)); + STR_FMT(&ml->tag), + ml->label.s ? "label '" : "", + STR_FMT(ml->label.s ? &ml->label : &STR_EMPTY), + ml->label.s ? "', " : "", + STR_FMT0(&ml->viabranch)); return 1; /* destroy call */ } - ilog(LOG_INFO, "Call branch '"STR_FORMAT"' (via-branch '"STR_FORMAT"') deleted", - STR_FMT(&ml->tag), STR_FMT0(&ml->viabranch)); + ilog(LOG_INFO, "Call branch '"STR_FORMAT"' (%s"STR_FORMAT"%svia-branch '"STR_FORMAT"') deleted", + STR_FMT(&ml->tag), + ml->label.s ? "label '" : "", + STR_FMT(ml->label.s ? &ml->label : &STR_EMPTY), + ml->label.s ? "', " : "", + STR_FMT0(&ml->viabranch)); return 0; } diff --git a/daemon/call.h b/daemon/call.h index be41e8982..6c2cec72e 100644 --- a/daemon/call.h +++ b/daemon/call.h @@ -340,7 +340,8 @@ struct call_monologue { str tag; str viabranch; - enum tag_type tagtype; + enum tag_type tagtype; + str label; time_t created; /* RO */ time_t deleted; struct timeval started; /* for CDR */ diff --git a/daemon/call_interfaces.c b/daemon/call_interfaces.c index 8e50eb82e..8d7eab73b 100644 --- a/daemon/call_interfaces.c +++ b/daemon/call_interfaces.c @@ -656,6 +656,7 @@ static const char *call_offer_answer_ng(bencode_item_t *input, struct callmaster const endpoint_t *sin) { str sdp, fromtag, totag = STR_NULL, callid, viabranch; + str label = STR_NULL; char *errstr; GQueue parsed = G_QUEUE_INIT; GQueue streams = G_QUEUE_INIT; @@ -678,6 +679,7 @@ static const char *call_offer_answer_ng(bencode_item_t *input, struct callmaster str_swap(&totag, &fromtag); } bencode_dictionary_get_str(input, "via-branch", &viabranch); + bencode_dictionary_get_str(input, "label", &label); if (sdp_parse(&sdp, &parsed)) return "Failed to parse SDP"; @@ -737,6 +739,8 @@ static const char *call_offer_answer_ng(bencode_item_t *input, struct callmaster } else { monologue->tagtype = TO_TAG; } + if (label.s && !monologue->label.s) + call_str_cpy(call, &monologue->label, &label); chopper = sdp_chopper_new(&sdp); bencode_buffer_destroy_add(output->buffer, (free_func_t) sdp_chopper_destroy, chopper); @@ -999,6 +1003,8 @@ static void ng_stats_monologue(bencode_item_t *dict, const struct call_monologue bencode_dictionary_add_str(sub, "tag", &ml->tag); if (ml->viabranch.s) bencode_dictionary_add_str(sub, "via-branch", &ml->viabranch); + if (ml->label.s) + bencode_dictionary_add_str(sub, "label", &ml->label); bencode_dictionary_add_integer(sub, "created", ml->created); if (ml->active_dialogue) bencode_dictionary_add_str(sub, "in dialogue with", &ml->active_dialogue->tag); diff --git a/daemon/redis.c b/daemon/redis.c index b22b9ceaf..f09e6b069 100644 --- a/daemon/redis.c +++ b/daemon/redis.c @@ -1129,6 +1129,8 @@ static int redis_tags(struct call *c, struct redis_list *tags) { __monologue_tag(ml, &s); if (!redis_hash_get_str(&s, rh, "via-branch")) __monologue_viabranch(ml, &s); + if (!redis_hash_get_str(&s, rh, "label")) + call_str_cpy(c, &ml->label, &s); redis_hash_get_time_t(&ml->deleted, rh, "deleted"); tags->ptrs[i] = ml; @@ -1849,12 +1851,12 @@ char* redis_encode_json(struct call *c) { JSON_SET_SIMPLE("active","%u",ml->active_dialogue ? ml->active_dialogue->unique_id : -1); JSON_SET_SIMPLE("deleted","%llu",(long long unsigned) ml->deleted); - if (ml->tag.s) { + if (ml->tag.s) JSON_SET_SIMPLE_STR("tag",&ml->tag); - } - if (ml->viabranch.s) { + if (ml->viabranch.s) JSON_SET_SIMPLE_STR("via-branch",&ml->viabranch); - } + if (ml->label.s) + JSON_SET_SIMPLE_STR("label",&ml->label); } json_builder_end_object (builder); diff --git a/perl/NGCP/Rtpengine/Test.pm b/perl/NGCP/Rtpengine/Test.pm index b6d7c0531..ab090d04a 100644 --- a/perl/NGCP/Rtpengine/Test.pm +++ b/perl/NGCP/Rtpengine/Test.pm @@ -271,7 +271,7 @@ sub _default_req_args { my $req = { command => $cmd, 'call-id' => $self->{parent}->{callid} }; - for my $cp (qw(sdp from-tag to-tag ICE transport-protocol address-family)) { + for my $cp (qw(sdp from-tag to-tag ICE transport-protocol address-family label)) { $args{$cp} and $req->{$cp} = $args{$cp}; } for my $cp (@{$args{flags}}) { diff --git a/t/test-basic.pl b/t/test-basic.pl index 4a1c76b20..5a6c14a16 100755 --- a/t/test-basic.pl +++ b/t/test-basic.pl @@ -12,16 +12,16 @@ my ($a, $b) = $r->client_pair( ); $r->timer_once(3, sub { - $b->answer($a, ICE => 'remove'); + $b->answer($a, ICE => 'remove', label => "callee"); $a->start_rtp(); $a->start_rtcp(); }); $r->timer_once(10, sub { $r->stop(); }); -$a->offer($b, ICE => 'remove'); +$a->offer($b, ICE => 'remove', label => "caller"); $b->start_rtp(); $b->start_rtcp(); $r->run(); -$a->teardown(); +$a->teardown(dump => 1); diff --git a/tests/simulator-ng.pl b/tests/simulator-ng.pl index 3191c2688..339bce7fd 100755 --- a/tests/simulator-ng.pl +++ b/tests/simulator-ng.pl @@ -666,6 +666,7 @@ a=rtpmap:111 opus/48000/2 #direction => [ $$pr{direction}, $$pr_o{direction} ], 'received from' => [ qw(IP4 127.0.0.1) ], 'rtcp-mux' => ['demux'], + label => rand(), }; $PORT_LATCHING and push(@flags, 'port latching'); $RECORD and push(@flags, 'record call');