TT#66577 Add support of outbound registrations for SIP peerings

We need to add an improvement, which fulfills the work of the
registration mechanism for SIP peerings.

Not only do we add here a registration tirggering for peerings,
but also a 'type' is introduced, which is mostly needed for XMLRPC
commands being sent towards SEMS, to let it understand to whom the $sid is related to.

Plus a list of improvements:
- de-register peering host on deletion ;
- de-register peering host on disable / register of peering host on enable ;

Change-Id: I035dfadf6709acb4d106a70f6124f024e719044f
mr10.1
Donat Zenichev 4 years ago
parent 74db09a720
commit df30292c6b

@ -378,6 +378,11 @@ sub servers_edit :Chained('servers_base') :PathPart('edit') :Args(0) {
transport => $c->stash->{server_result}->transport,
);
}
if (!$c->stash->{server_result}->enabled) {
NGCP::Panel::Utils::Peering::_sip_delete_peer_registration(c => $c);
} else {
NGCP::Panel::Utils::Peering::_sip_create_peer_registration(c => $c);
}
NGCP::Panel::Utils::Peering::_sip_dispatcher_reload(c => $c);
NGCP::Panel::Utils::Message::info(
c => $c,
@ -405,6 +410,8 @@ sub servers_delete :Chained('servers_base') :PathPart('delete') :Args(0) {
try {
my $probe = $c->stash->{server_result}->probe;
NGCP::Panel::Utils::Peering::_sip_delete_peer_registration(c => $c);
$c->stash->{server_result}->delete;
NGCP::Panel::Utils::Peering::_sip_lcr_reload(c => $c);
if($probe) {
@ -608,7 +615,20 @@ sub servers_preferences_edit :Chained('servers_preferences_base') :PathPart('edi
->voip_preferences_enums
->all;
my $pref_rs = $c->stash->{server_result}->voip_peer_preferences;
my $pref_rs = $c->stash->{server_result}->voip_peer_preferences->search({
}, {
join => 'attribute',
});
my $old_authentication_prefs = {};
if ($c->req->method eq "POST" && $c->stash->{preference_meta}->attribute =~ /^peer_auth_/) {
foreach my $pref ($pref_rs->all) {
my $attr = $pref->attribute->attribute;
if ($attr =~ /^peer_auth_/) {
$old_authentication_prefs->{$attr} = $pref->value;
}
}
}
NGCP::Panel::Utils::Preferences::create_preference_form( c => $c,
pref_rs => $pref_rs,
@ -617,6 +637,39 @@ sub servers_preferences_edit :Chained('servers_preferences_base') :PathPart('edi
edit_uri => $c->uri_for_action('/peering/servers_preferences_edit', $c->req->captures),
blob_rs => $c->model('DB')->resultset('voip_peer_preferences_blob'),
);
if (keys %{ $old_authentication_prefs }) {
my $new_authentication_prefs = {};
if ($c->req->method eq "POST" && $c->stash->{preference_meta}->attribute =~ /^peer_auth_/) {
foreach my $pref ($pref_rs->all) {
my $attr = $pref->attribute->attribute;
if ($attr =~ /^peer_auth_/) {
$new_authentication_prefs->{$attr} = $pref->value;
}
}
my $prov_peer = {};
my $type = 'peering';
$prov_peer->{username} = $c->stash->{server}->{name};
$prov_peer->{domain} = $c->stash->{server}->{ip};
$prov_peer->{id} = $c->stash->{server}->{id};
$prov_peer->{uuid} = 0;
unless(compare($old_authentication_prefs, $new_authentication_prefs)) {
try {
NGCP::Panel::Utils::Preferences::update_sems_peer_auth(
$c, $prov_peer, $type, $old_authentication_prefs, $new_authentication_prefs);
} catch($e) {
NGCP::Panel::Utils::Message::error(
c => $c,
log => "Failed to set peer registration: $e",
desc => $c->loc('Peer registration error'),
);
}
}
}
}
return;
}

@ -865,9 +865,10 @@ sub preferences_edit :Chained('preferences_base') :PathPart('edit') :Args(0) {
NGCP::Panel::Utils::Preferences::get_peer_auth_params(
$c, $prov_subscriber, $new_auth_prefs);
unless(compare($old_auth_prefs, $new_auth_prefs)) {
my $type = 'subscriber';
try {
NGCP::Panel::Utils::Preferences::update_sems_peer_auth(
$c, $prov_subscriber, $old_auth_prefs, $new_auth_prefs);
$c, $prov_subscriber, $type, $old_auth_prefs, $new_auth_prefs);
} catch($e) {
NGCP::Panel::Utils::Message::error(
c => $c,

@ -18,6 +18,71 @@ EOF
return 1;
}
sub _sip_delete_peer_registration {
my(%params) = @_;
my($c) = @params{qw/c/};
my $prov_peer = {};
my $type = 'peering';
$prov_peer->{username} = $c->stash->{server}->{name};
$prov_peer->{domain} = $c->stash->{server}->{ip};
$prov_peer->{id} = $c->stash->{server}->{id};
$prov_peer->{uuid} = 0;
my $pref_all = $c->stash->{server_result}->voip_peer_preferences->search({
}, {
join => 'attribute',
});
my $auth_prefs = {};
foreach my $pref ($pref_all->all) {
my $attr = $pref->attribute->attribute;
if ($attr =~ /^peer_auth_/) {
$auth_prefs->{$attr} = $pref->value;
}
}
if (defined $auth_prefs->{peer_auth_register} && $auth_prefs->{peer_auth_register} == 1 &&
defined $auth_prefs->{peer_auth_user} &&
defined $auth_prefs->{peer_auth_realm} &&
defined $auth_prefs->{peer_auth_pass}) {
NGCP::Panel::Utils::Sems::delete_peer_registration($c, $prov_peer, $type, $auth_prefs);
}
return 1;
}
sub _sip_create_peer_registration {
my(%params) = @_;
my($c) = @params{qw/c/};
my $prov_peer = {};
my $type = 'peering';
$prov_peer->{username} = $c->stash->{server}->{name};
$prov_peer->{domain} = $c->stash->{server}->{ip};
$prov_peer->{id} = $c->stash->{server}->{id};
$prov_peer->{uuid} = 0;
my $pref_all = $c->stash->{server_result}->voip_peer_preferences->search({
}, {
join => 'attribute',
});
my $auth_prefs = {};
foreach my $pref ($pref_all->all) {
my $attr = $pref->attribute->attribute;
if ($attr =~ /^peer_auth_/) {
$auth_prefs->{$attr} = $pref->value;
}
}
if (defined $auth_prefs->{peer_auth_register} && $auth_prefs->{peer_auth_register} == 1 &&
defined $auth_prefs->{peer_auth_user} &&
defined $auth_prefs->{peer_auth_realm} &&
defined $auth_prefs->{peer_auth_pass}) {
NGCP::Panel::Utils::Sems::create_peer_registration($c, $prov_peer, $type, $auth_prefs);
}
return 1;
}
sub _sip_dispatcher_reload {
my ($self, $c) = @_;
my ($res) = NGCP::Panel::Utils::XMLDispatcher::dispatch($c, "proxy-ng", 1, 1, <<EOF );

@ -1005,9 +1005,10 @@ sub update_preferences {
$c, $prov_subscriber, $new_auth_prefs);
unless(compare($old_auth_prefs, $new_auth_prefs)) {
$c->log->debug("peer_auth_params changed. Updating sems.");
my $type = 'subscriber';
try {
update_sems_peer_auth(
$c, $prov_subscriber, $old_auth_prefs, $new_auth_prefs);
$c, $prov_subscriber, $type, $old_auth_prefs, $new_auth_prefs);
} catch($e) {
$c->log->error("Failed to set peer registration: $e");
&$err_code(HTTP_INTERNAL_SERVER_ERROR, "Internal Server Error."); # TODO?
@ -2550,23 +2551,24 @@ sub get_contract_preference_rs {
}
sub update_sems_peer_auth {
my ($c, $prov_subscriber, $old_auth_prefs, $new_auth_prefs) = @_;
my ($c, $prov_object, $type, $old_auth_prefs, $new_auth_prefs) = @_;
# prov_object can be either peering or subscriber
if(!_is_peer_auth_active($c, $old_auth_prefs) &&
_is_peer_auth_active($c, $new_auth_prefs)) {
NGCP::Panel::Utils::Sems::create_peer_registration(
$c, $prov_subscriber, $new_auth_prefs);
$c, $prov_object, $type, $new_auth_prefs);
} elsif( _is_peer_auth_active($c, $old_auth_prefs) &&
!_is_peer_auth_active($c, $new_auth_prefs)) {
NGCP::Panel::Utils::Sems::delete_peer_registration(
$c, $prov_subscriber, $old_auth_prefs);
$c, $prov_object, $type, $old_auth_prefs);
} elsif(_is_peer_auth_active($c, $old_auth_prefs) &&
_is_peer_auth_active($c, $new_auth_prefs)){
NGCP::Panel::Utils::Sems::update_peer_registration(
$c, $prov_subscriber, $new_auth_prefs, $old_auth_prefs);
$c, $prov_object, $type, $new_auth_prefs, $old_auth_prefs);
}
return;

@ -25,10 +25,35 @@ sub _get_outbound_socket {
}
sub create_peer_registration {
my ($c, $prov_subscriber, $prefs) = @_;
my ($c, $prov_obj, $type, $prefs) = @_;
my $sid;
my $uuid;
my $username;
my $domain;
my $contact = $c->config->{sip}->{lb_ext};
my $transport = '';
if ($type eq 'peering') {
# outbound registration for a peering
$sid = $prov_obj->{id};
$uuid = $prov_obj->{uuid};
$username = $prov_obj->{username};
$domain = $prov_obj->{domain};
} elsif ($type eq "subscriber") {
# outbound registration for usual subscriber
$sid = $prov_obj->id;
$uuid = $prov_obj->uuid;
$username = $prov_obj->username;
$domain = $prov_obj->domain->domain;
} else {
$c->log->debug("skip creating a registration for undefined type!");
return 1;
}
if($c->config->{features}->{debug}) {
$c->log->debug("skip creating peer registration for subscriber '".$prov_subscriber->username.'@'.$prov_subscriber->domain->domain."'");
$c->log->debug("skip creating peer registration for subscriber '".$username.'@'.$domain."'");
return 1;
}
@ -37,12 +62,7 @@ sub create_peer_registration {
$all = 0;
}
$c->log->debug("creating peer registration for subscriber '".$prov_subscriber->username.'@'.$prov_subscriber->domain->domain."'");
my $sid = $prov_subscriber->id;
my $uuid = $prov_subscriber->uuid;
my $contact = $c->config->{sip}->{lb_ext};
my $transport = '';
$c->log->debug("creating peer registration for subscriber '".$username.'@'.$domain."'");
my $outbound_sock = _get_outbound_socket($c, $prefs);
if($outbound_sock) {
@ -65,6 +85,7 @@ sub create_peer_registration {
<param><value><string>$$prefs{peer_auth_realm}</string></value></param>
<param><value><string>sip:$$prefs{peer_auth_user}\@$contact;uuid=$uuid$transport</string></value></param>
<param><value><string>$authorization_username</string></value></param>
<param><value><string>$type</string></value></param>
</params>
</methodCall>
EOF
@ -95,10 +116,35 @@ EOF
}
sub update_peer_registration {
my ($c, $prov_subscriber, $prefs, $oldprefs) = @_;
my ($c, $prov_obj, $type, $prefs, $oldprefs) = @_;
my $sid;
my $uuid;
my $username;
my $domain;
my $contact = $c->config->{sip}->{lb_ext};
my $transport = '';
if ($type eq 'peering') {
# outbound registration for a peering
$sid = $prov_obj->{id};
$uuid = $prov_obj->{uuid};
$username = $prov_obj->{username};
$domain = $prov_obj->{domain};
} elsif ($type eq "subscriber") {
# outbound registration for usual subscriber
$sid = $prov_obj->id;
$uuid = $prov_obj->uuid;
$username = $prov_obj->username;
$domain = $prov_obj->domain->domain;
} else {
$c->log->debug("skip updating a registration for undefined type!");
return 1;
}
if($c->config->{features}->{debug}) {
$c->log->debug("skip updating peer registration for subscriber '".$prov_subscriber->username.'@'.$prov_subscriber->domain->domain."'");
$c->log->debug("skip updating peer registration for subscriber '".$username.'@'.$domain."'");
return 1;
}
@ -107,12 +153,7 @@ sub update_peer_registration {
$all = 0;
}
$c->log->debug("trying to update peer registration for subscriber '".$prov_subscriber->username.'@'.$prov_subscriber->domain->domain."'");
my $sid = $prov_subscriber->id;
my $uuid = $prov_subscriber->uuid;
my $contact = $c->config->{sip}->{lb_ext};
my $transport = '';
$c->log->debug("trying to update peer registration for subscriber '".$username.'@'.$domain."'");
my $outbound_sock = _get_outbound_socket($c, $prefs);
if($outbound_sock) {
@ -143,6 +184,7 @@ sub update_peer_registration {
<param><value><string>$$prefs{peer_auth_realm}</string></value></param>
<param><value><string>sip:$$prefs{peer_auth_user}\@$contact;uuid=$uuid$transport</string></value></param>
<param><value><string>$authorization_username</string></value></param>
<param><value><string>$type</string></value></param>
</params>
</methodCall>
EOF
@ -171,6 +213,7 @@ EOF
<param><value><string>$$oldprefs{peer_auth_realm}</string></value></param>
<param><value><string>sip:$$oldprefs{peer_auth_user}\@$contact;uuid=$uuid</string></value></param>
<param><value><string>$old_authorization_username</string></value></param>
<param><value><string>$type</string></value></param>
</params>
</methodCall>
EOF
@ -182,10 +225,34 @@ EOF
}
sub delete_peer_registration {
my ($c, $prov_subscriber, $oldprefs) = @_;
my ($c, $prov_obj, $type, $oldprefs) = @_;
my $sid;
my $uuid;
my $username;
my $domain;
my $contact = $c->config->{sip}->{lb_ext};
if ($type eq 'peering') {
# outbound registration for a peering
$sid = $prov_obj->{id};
$uuid = $prov_obj->{uuid};
$username = $prov_obj->{username};
$domain = $prov_obj->{domain};
} elsif ($type eq "subscriber") {
# outbound registration for usual subscriber
$sid = $prov_obj->id;
$uuid = $prov_obj->uuid;
$username = $prov_obj->username;
$domain = $prov_obj->domain->domain;
} else {
$c->log->debug("skip deleting a registration for undefined type!");
return 1;
}
if($c->config->{features}->{debug}) {
$c->log->debug("skip deleting peer registration for subscriber '".$prov_subscriber->username.'@'.$prov_subscriber->domain->domain."'");
$c->log->debug("skip deleting peer registration for subscriber '".$username.'@'.$domain."'");
return 1;
}
@ -194,11 +261,7 @@ sub delete_peer_registration {
$all = 0;
}
$c->log->debug("trying to delete peer registration for subscriber '".$prov_subscriber->username.'@'.$prov_subscriber->domain->domain."'");
my $sid = $prov_subscriber->id;
my $uuid = $prov_subscriber->uuid;
my $contact = $c->config->{sip}->{lb_ext};
$c->log->debug("trying to delete peer registration for subscriber '".$username.'@'.$domain."'");
my @ret = NGCP::Panel::Utils::XMLDispatcher::dispatch($c, "appserver", $all, 1, <<EOF);
<?xml version="1.0"?>
@ -206,6 +269,7 @@ sub delete_peer_registration {
<methodName>db_reg_agent.removeRegistration</methodName>
<params>
<param><value><int>$sid</int></value></param>
<param><value><string>$type</string></value></param>
</params>
</methodCall>
EOF
@ -234,6 +298,7 @@ EOF
<param><value><string>$$oldprefs{peer_auth_realm}</string></value></param>
<param><value><string>sip:$$oldprefs{peer_auth_user}\@$contact;uuid=$uuid</string></value></param>
<param><value><string>$old_authorization_username</string></value></param>
<param><value><string>$type</string></value></param>
</params>
</methodCall>
EOF

@ -1786,8 +1786,9 @@ sub terminate {
subscriber => $subscriber,
);
my $auth_prefs = {};
my $type = 'subscriber';
NGCP::Panel::Utils::Preferences::get_peer_auth_params($c, $prov_subscriber, $auth_prefs);
NGCP::Panel::Utils::Preferences::update_sems_peer_auth($c, $prov_subscriber, $auth_prefs, {});
NGCP::Panel::Utils::Preferences::update_sems_peer_auth($c, $prov_subscriber, $type, $auth_prefs, {});
foreach my $pref(qw/allowed_ips_grp man_allowed_ips_grp/) {
my $aig_rs = NGCP::Panel::Utils::Preferences::get_usr_preference_rs(
c => $c, prov_subscriber => $prov_subscriber, attribute => $pref,

Loading…
Cancel
Save