From 493ca399a5e3bc436e9de3bc3dfff3eb78d33cef Mon Sep 17 00:00:00 2001 From: Donat Zenichev Date: Mon, 21 Mar 2022 18:28:11 +0100 Subject: [PATCH] TT#167350 outbound registration: add proper transport handling We need to properly handle transport picking for the SIP peerings: - in case a non-default 'outbound_socket' is set for the peering, give a precedence to the transport used for it ; - in case a default 'outbound_socket' is set for the peering, use a transport protocol configured for this SIP peering ; The idea is quite simple, and meets our current requirements. Change-Id: I98d55b090f04642442d83da83d441aca0f000dec --- lib/NGCP/Panel/Utils/Sems.pm | 62 +++++++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 8 deletions(-) diff --git a/lib/NGCP/Panel/Utils/Sems.pm b/lib/NGCP/Panel/Utils/Sems.pm index 5a0f073171..ab1903a92e 100644 --- a/lib/NGCP/Panel/Utils/Sems.pm +++ b/lib/NGCP/Panel/Utils/Sems.pm @@ -64,10 +64,33 @@ sub create_peer_registration { $c->log->debug("creating peer registration for subscriber '".$username.'@'.$domain."'"); - my $outbound_sock = _get_outbound_socket($c, $prefs); - if($outbound_sock) { - $contact = $outbound_sock->{contact}; - $transport = $outbound_sock->{transport}; + if ($type eq 'peering') { + # outbound_sock preference is only available for peerings + my $outbound_sock = _get_outbound_socket($c, $prefs); + + # if the socket is not default, then a precedence for picking + # the transport is given to the transport of the outbound socket + if($outbound_sock) { + $contact = $outbound_sock->{contact}; + $transport = $outbound_sock->{transport}; + + # if the outbound socket is default, then use the transport + # of the peering's parameters (Protocol: UDP/TCP/TLS) + } else { + SWITCH: for ($c->stash->{server_result}->transport) { + /^2$/ && do { + $transport = ';transport=tcp'; + last SWITCH; + }; + /^3$/ && do { + $transport = ';transport=tls'; + last SWITCH; + }; + # default UDP always + $transport = ';transport=udp'; + } + } + $c->log->debug("transport picked for the outbound peering registration is '$transport'"); } # if no specific username defined for the Authorization header @@ -155,10 +178,33 @@ sub update_peer_registration { $c->log->debug("trying to update peer registration for subscriber '".$username.'@'.$domain."'"); - my $outbound_sock = _get_outbound_socket($c, $prefs); - if($outbound_sock) { - $contact = $outbound_sock->{contact}; - $transport = $outbound_sock->{transport}; + if ($type eq 'peering') { + # outbound_sock preference is only available for peerings + my $outbound_sock = _get_outbound_socket($c, $prefs); + + # if the socket is not default, then a precedence for picking + # the transport is given to the transport of the outbound socket + if($outbound_sock) { + $contact = $outbound_sock->{contact}; + $transport = $outbound_sock->{transport}; + + # if the outbound socket is default, then use the transport + # of the peering's parameters (Protocol: UDP/TCP/TLS) + } else { + SWITCH: for ($c->stash->{server_result}->transport) { + /^2$/ && do { + $transport = ';transport=tcp'; + last SWITCH; + }; + /^3$/ && do { + $transport = ';transport=tls'; + last SWITCH; + }; + # default UDP always + $transport = ';transport=udp'; + } + } + $c->log->debug("transport picked for the outbound peering registration is '$transport'"); } use Data::Dumper;