diff --git a/lib/NGCP/Panel/Utils/DialogicImg.pm b/lib/NGCP/Panel/Utils/DialogicImg.pm
index f8bb58d41c..8b8a3ab8f2 100644
--- a/lib/NGCP/Panel/Utils/DialogicImg.pm
+++ b/lib/NGCP/Panel/Utils/DialogicImg.pm
@@ -1,3 +1,6 @@
+use strict;
+use warnings;
+
{
package My::Serializer::Plain;
@@ -20,31 +23,32 @@
return $s;
}
- has '+serializer' => (
- default => \&_set_serializer,
- );
-
+ has '+serializer' => ( default => \&_set_serializer, );
1;
}
package NGCP::Panel::Utils::DialogicImg;
-use strict;
-use warnings;
use Moo;
use Types::Standard qw(Int HashRef);
use HTTP::Tiny;
with 'Role::REST::Client'; # TODO: dependency
has '+type' => ( default => 'application/xml', is => 'rw' );
-has '+serializer_class' => ( is => 'rw', default => sub {'My::Serializer::Plain'} );
+has '+serializer_class' =>
+ ( is => 'rw', default => sub {'My::Serializer::Plain'} );
has 'appid' => ( is => 'rw', isa => Int, default => 0 );
-has 'pids' => (is => 'rw', isa => HashRef, default => sub {return {
- bn2020 => 10001, # defaults (should be overwritten)
- network => 10002,
- interface_collection => 10003,
- interface => 10004,
- };});
+has 'pids' => (
+ is => 'rw',
+ isa => HashRef,
+ default => sub {
+ return {
+ bn2020 => 10_001, # defaults (should be overwritten)
+ network => 10_002,
+ interface_collection => 10_003,
+ interface => 10_004,
+ };
+ } );
sub login {
my ( $self, $username, $password ) = @_;
@@ -71,13 +75,14 @@ sub obtain_lock {
sub create_bn2020 {
my ($self) = @_;
+
my $data = $self->objects->{bn2020};
my $resp = $self->post(
'/oamp/configuration/objects/Node/NULL?pid=10000&appid='
. $self->appid,
- $data
+ $data,
);
- if ($resp->code == 200) {
+ if ( $resp->code == 200 ) {
$self->pids->{bn2020} = $resp->data->{oid};
}
return $resp;
@@ -85,19 +90,19 @@ sub create_bn2020 {
sub create_network {
my ($self) = @_;
- my $data = $self->objects->{bn2020};
- my $pid = $self->pids->{bn2020};
+
+ my $pid = $self->pids->{bn2020};
my $appid = $self->appid;
- my $resp = $self->get(
+ my $resp = $self->get(
"/oamp/configuration/objects/NetworkInterfaces/NULL?pid=$pid&appid=$appid",
);
- return $resp if ($resp->code != 200);
- my $new_resp = $self->_build_response_data($resp->data, $pid);
+ return $resp if ( $resp->code != 200 );
+ my $new_resp = $self->_build_response_data( $resp->data, $pid );
$resp = $self->post(
"/oamp/configuration/objects/NetworkInterfaces/NULL?pid=$pid&appid=$appid",
$new_resp,
);
- if ($resp->code == 200) {
+ if ( $resp->code == 200 ) {
$self->pids->{network} = $resp->data->{oid};
}
return $resp;
@@ -106,22 +111,21 @@ sub create_network {
sub create_interface_collection {
my ($self) = @_;
- my $data = $self->objects->{bn2020};
- my $pid = $self->pids->{network};
+ my $pid = $self->pids->{network};
my $appid = $self->appid;
- my $resp = $self->get(
+ my $resp = $self->get(
"/oamp/configuration/objects/NetworkLogicalInterfaces/NULL?detaillevel=4&pid=$pid&appid=$appid",
);
- if ($resp->code != 200) {
+ if ( $resp->code != 200 ) {
warn "Failed to fetch resource\n";
return $resp;
}
- my $new_resp = $self->_build_response_data($resp->data, $pid);
+ my $new_resp = $self->_build_response_data( $resp->data, $pid );
$resp = $self->post(
"/oamp/configuration/objects/NetworkLogicalInterfaces/NULL?pid=$pid&appid=$appid",
$new_resp,
);
- if ($resp->code == 200) {
+ if ( $resp->code == 200 ) {
$self->pids->{interface_collection} = $resp->data->{oid};
}
return $resp;
@@ -130,25 +134,24 @@ sub create_interface_collection {
sub create_interface {
my ($self) = @_;
- my $data = $self->objects->{bn2020};
- my $pid = $self->pids->{interface_collection};
+ my $pid = $self->pids->{interface_collection};
my $appid = $self->appid;
- my $resp = $self->get(
+ my $resp = $self->get(
"/oamp/configuration/objects/NetworkLogicalInterface/NULL?detaillevel=4&pid=$pid&appid=$appid",
);
- if ($resp->code != 200) {
+ if ( $resp->code != 200 ) {
warn "Failed to fetch resource\n";
return $resp;
}
- my $new_resp = $self->_build_response_data($resp->data, $pid);
+ my $new_resp = $self->_build_response_data( $resp->data, $pid );
$resp = $self->post(
"/oamp/configuration/objects/NetworkLogicalInterface/NULL?pid=$pid&appid=$appid",
$new_resp,
);
- if ($resp->code == 200) {
- if ($resp->data->{property}{Interface}{value} eq "Control") {
+ if ( $resp->code == 200 ) {
+ if ( $resp->data->{property}{Interface}{value} eq "Control" ) {
$self->pids->{interface_control} = $resp->data->{oid};
- } elsif ($resp->data->{property}{Interface}{value} eq "Data A") {
+ } elsif ( $resp->data->{property}{Interface}{value} eq "Data A" ) {
$self->pids->{interface_dataa} = $resp->data->{oid};
}
$self->pids->{interface} = $resp->data->{oid};
@@ -159,53 +162,271 @@ sub create_interface {
#TODO: only supports ipv4 now
sub create_ip_address {
- my ($self, $options) = @_;
+ my ( $self, $options ) = @_;
- if (defined $options->{NIIPAddress} && ! defined $options->{NIIPGateway} ) {
+ if ( defined $options->{NIIPAddress} && !defined $options->{NIIPGateway} )
+ {
$options->{NIIPGateway} = $options->{NIIPAddress} =~ s/\.[0-9]+$/.1/r;
}
- my $data = $self->objects->{bn2020};
- my $pid = $self->pids->{interface};
+ my $data = $self->objects->{bn2020};
+ my $pid = $self->pids->{interface};
my $appid = $self->appid;
- my $resp = $self->get(
+ my $resp = $self->get(
"/oamp/configuration/objects/NetworkInterface/NULL?detaillevel=4&pid=$pid&appid=$appid",
);
- if ($resp->code != 200) {
+ if ( $resp->code != 200 ) {
warn "Failed to fetch resource\n";
return $resp;
}
- my $new_resp = $self->_build_response_data($resp->data, $pid, $options);
+ my $new_resp = $self->_build_response_data( $resp->data, $pid, $options );
$resp = $self->post(
"/oamp/configuration/objects/NetworkInterface/NULL?pid=$pid&appid=$appid",
$new_resp,
);
- if ($resp->code == 200) {
+ if ( $resp->code == 200 ) {
$self->pids->{interface} = $resp->data->{oid};
}
return $resp;
}
+sub create_facility {
+ my ($self) = @_;
+
+ my $pid = $self->pids->{bn2020};
+ my $appid = $self->appid;
+ my $resp = $self->get(
+ "/oamp/configuration/objects/Facility/NULL?detaillevel=4&pid=$pid&appid=$appid",
+ );
+ if ( $resp->code != 200 ) {
+ warn "Failed to fetch resource\n";
+ return $resp;
+ }
+ my $new_resp = $self->_build_response_data( $resp->data, $pid );
+ $resp
+ = $self->post(
+ "/oamp/configuration/objects/Facility/NULL?pid=$pid&appid=$appid",
+ $new_resp, );
+ if ( $resp->code == 200 ) {
+ $self->pids->{facility} = $resp->data->{oid};
+
+ }
+ return $resp;
+}
+
+sub create_packet_facility_collection {
+ my ($self) = @_;
+
+ my $pid = $self->pids->{facility};
+ my $appid = $self->appid;
+ my $resp = $self->get(
+ "/oamp/configuration/objects/PacketFacilities/NULL?detaillevel=4&pid=$pid&appid=$appid",
+ );
+ if ( $resp->code != 200 ) {
+ warn "Failed to fetch resource\n";
+ return $resp;
+ }
+ my $new_resp = $self->_build_response_data( $resp->data, $pid );
+ $resp
+ = $self->post(
+ "/oamp/configuration/objects/PacketFacilities/NULL?pid=$pid&appid=$appid",
+ $new_resp, );
+ if ( $resp->code == 200 ) {
+ $self->pids->{packet_facility_collection} = $resp->data->{oid};
+
+ }
+ return $resp;
+}
+
+sub create_packet_facility {
+ my ( $self, $options ) = @_;
+
+ my $pid = $self->pids->{packet_facility_collection};
+ my $appid = $self->appid;
+ my $resp = $self->get(
+ "/oamp/configuration/objects/PacketFacility/NULL?detaillevel=4&pid=$pid&appid=$appid",
+ );
+ if ( $resp->code != 200 ) {
+ warn "Failed to fetch resource\n";
+ return $resp;
+ }
+ my $new_resp = $self->_build_response_data( $resp->data, $pid, $options );
+ $resp = $self->post(
+ "/oamp/configuration/objects/PacketFacility/NULL?pid=$pid&appid=$appid",
+ $new_resp,
+ );
+ if ( $resp->code == 200 ) {
+ $self->pids->{packet_facility} = $resp->data->{oid};
+ }
+ return $resp;
+}
+
+sub create_signaling {
+ my ( $self, $options ) = @_;
+
+ my $pid = $self->pids->{bn2020};
+ my $appid = $self->appid;
+ my $resp = $self->get(
+ "/oamp/configuration/objects/Signaling/NULL?detaillevel=4&pid=$pid&appid=$appid",
+ );
+ if ( $resp->code != 200 ) {
+ warn "Failed to fetch resource\n";
+ return $resp;
+ }
+ my $new_resp = $self->_build_response_data( $resp->data, $pid, $options );
+ $resp = $self->post(
+ "/oamp/configuration/objects/Signaling/NULL?pid=$pid&appid=$appid",
+ $new_resp,
+ );
+ if ( $resp->code == 200 ) {
+ $self->pids->{signaling} = $resp->data->{oid};
+ }
+ return $resp;
+}
+
+sub create_sip {
+ my ( $self, $options ) = @_;
+
+ my $pid = $self->pids->{signaling};
+ my $appid = $self->appid;
+ my $resp = $self->get(
+ "/oamp/configuration/objects/SIP/NULL?detaillevel=4&pid=$pid&appid=$appid",
+ );
+ if ( $resp->code != 200 ) {
+ warn "Failed to fetch resource\n";
+ return $resp;
+ }
+ my $new_resp = $self->_build_response_data( $resp->data, $pid, $options );
+ $resp = $self->post(
+ "/oamp/configuration/objects/SIP/NULL?pid=$pid&appid=$appid",
+ $new_resp,
+ );
+ if ( $resp->code == 200 ) {
+ $self->pids->{sip} = $resp->data->{oid};
+ }
+ return $resp;
+}
+
+sub create_sip_ip {
+ my ( $self, $options ) = @_;
+
+ my $pid = $self->pids->{sip};
+ my $appid = $self->appid;
+ my $resp = $self->get(
+ "/oamp/configuration/objects/SIPIP/NULL?detaillevel=4&pid=$pid&appid=$appid",
+ );
+ if ( $resp->code != 200 ) {
+ warn "Failed to fetch resource\n";
+ return $resp;
+ }
+ my $new_resp = $self->_build_response_data( $resp->data, $pid, $options );
+ $resp = $self->post(
+ "/oamp/configuration/objects/SIPIP/NULL?pid=$pid&appid=$appid",
+ $new_resp,
+ );
+ if ( $resp->code == 200 ) {
+ $self->pids->{sip_ip} = $resp->data->{oid};
+ }
+ return $resp;
+}
+
+### OTHER STUFF ###
+
+#delete all children of bn2020 but not the node itself
+sub delete_all_bn2020 {
+ my ($self) = @_;
+
+ my $pid = $self->pids->{bn2020};
+ my $appid = $self->appid;
+ my $resp = $self->get(
+ "/oamp/configuration/objects?appid=$appid",
+ );
+ if ($resp->code != 200) {
+ warn "failed to get objects\n";
+ return $resp;
+ }
+ my $root = $resp->data->{object}[0]{object}; #bn2020
+ for my $ch (_get_all_children($root)) {
+ $self->_recursive_delete($ch);
+ }
+
+ return $resp;
+}
+
+sub _get_all_children {
+ my $node = shift;
+ if (defined $node->{object}) {
+ if ("HASH" eq ref $node->{object}) {
+ return ($node->{object},);
+ }
+ elsif ("ARRAY" eq ref $node->{object}) {
+ return @{ $node->{object} };
+ }
+ }
+ return ();
+}
+
+sub _recursive_delete {
+ my ($self, $node) = @_;
+ my $classname = $node->{classname};
+ my $oid = $node->{oid};
+ my $appid = $self->appid;
+ for my $ch (_get_all_children($node)) {
+ $self->_recursive_delete($ch);
+ }
+ my $path = "/oamp/configuration/objects/$classname/$oid?appid=$appid&sync_key=0";
+ $self->set_header( 'Content-Length' => '0', );
+ my $resp = $self->delete($path);
+ #use DDP; p $path; p $resp->code;
+ return;
+}
+
+sub reboot_and_wait {
+ my ($self) = @_;
+
+ my $appid = $self->appid;
+
+ $self->set_header( 'Content-Length' => '0', );
+ # my $resp = $self->delete("/oamp/configuration/database/new?appid=$appid",
+ # '');
+ my $resp = $self->_request_with_body("DELETE",
+ "/oamp/configuration/database/new?appid=$appid",
+ '');
+ if ($resp->code != 200) {
+ warn "failed to reset config\n";
+ return $resp;
+ }
+ sleep 2; # not to catch the old server
+ for (my $i = 0; $i < 40; $i++) { # 200 seconds on 5 seconds timeout
+ $resp = $self->get("/");
+ last if $resp->code < 500;
+ }
+ return $resp;
+}
sub _build_response_data {
- my ($self, $req, $pid, $options) = @_;
+ my ( $self, $req, $pid, $options ) = @_;
my $resp = {
- pid => $pid,
+ pid => $pid,
property => {},
};
- for my $p(keys %{ $req->{property} }) {
+ for my $p ( keys %{ $req->{property} } ) {
next if "_state_" eq $p;
- next if $req->{property}{$p}{visible} eq "__NULL__"; # TODO: that's SwitchOver
- next if ($req->{property}{$p}{readonly} eq "True") &&
- ($req->{property}{$p}{visible} eq "true");
- $resp->{property}{$p} = {configuredvalue => $req->{property}{$p}{value}};
- if (defined $options->{$p}) {
+ next
+ if $req->{property}{$p}{visible} eq
+ "__NULL__"; # TODO: that's SwitchOver
+ next
+ if ( $req->{property}{$p}{readonly} eq "True" )
+ && ( $req->{property}{$p}{visible} eq "true" );
+ $resp->{property}{$p}
+ = { configuredvalue => $req->{property}{$p}{value} };
+ if ( defined $options->{$p} ) {
$resp->{property}{$p}{configuredvalue} = $options->{$p};
}
}
return $resp;
}
-sub _build_user_agent { HTTP::Tiny->new }
+sub _build_user_agent { return HTTP::Tiny->new; }
sub objects {
return {
@@ -235,9 +456,9 @@ sub objects {
'ID' => { 'configuredvalue' => '0' },
'_objectName_' =>
{ 'configuredvalue' => 'BN2020: Node0 - ID: 0' },
- 'LicIPChannels' => { 'configuredvalue' => '0' }
+ 'LicIPChannels' => { 'configuredvalue' => '0' },
},
- 'pid' => '10000'
+ 'pid' => '10000',
},
};
diff --git a/share/tools/dialogic-test-client.pl b/share/tools/dialogic-test-client.pl
index dfa6073d73..dfd70dafc5 100644
--- a/share/tools/dialogic-test-client.pl
+++ b/share/tools/dialogic-test-client.pl
@@ -17,7 +17,7 @@ my $test = NGCP::Panel::Utils::DialogicImg->new(
},
);
-p $test;
+#p $test;
p $test->login( 'dialogic', 'Dial0gic' );
@@ -25,25 +25,15 @@ my $resp
= $test->get( '/oamp/configuration/objects', { appid => $test->appid } );
$resp = $test->obtain_lock();
-p $resp;
+p $resp->code;
print "LOGGED IN, LOCK OBTAINED ############################\n";
-# $resp
-# = $test->get(
-# '/oamp/configuration/objects/Node/NULL?detaillevel=1&pid=10000&appid='
-# . $test->appid );
-# p $resp;
-# #p $resp->data;
-# print "GOT DATA, SEND NOW ###################################\n";
-# $resp
-# = $test->post(
-# '/oamp/configuration/objects/Node/NULL?detaillevel=1&pid=10000&appid='
-# . $test->appid, $resp->data );
+# $resp = $test->reboot_and_wait;
# p $resp;
-# #p $resp->data;
+# exit 0;
$resp = $test->create_bn2020;
p $resp->code;
@@ -69,21 +59,59 @@ p $resp->code;
#p $resp->data;
$resp = $test->create_ip_address({
- NIIPAddress => '10.2.3.4',
+ NIIPAddress => '11.2.3.4',
NIIPPhy => 'Services',
});
p $resp->code;
#p $resp->data;
-$resp = $test->create_interface; # DataA
+$resp = $test->create_interface; # DataA by default
p $resp->code;
#p $resp->data;
-$resp = $test->create_ip_address({NIIPAddress => '10.6.7.8',
+$resp = $test->create_ip_address({NIIPAddress => '11.6.7.8',
NIIPPhy => 'Media 0'});
p $resp->code;
#p $resp->data;
+print "CREATE FACILITY ###################################\n";
+
+$resp = $test->create_facility;
+p $resp->code;
+#p $resp->data;
+
+print "CREATE PACKET FACILITY COLLECTION ###################################\n";
+
+$resp = $test->create_packet_facility_collection;
+p $resp->code;
+#p $resp->data;
+
+print "CREATE PACKET FACILITY ###################################\n";
+
+$resp = $test->create_packet_facility({
+ ChannelCount => 5, # our licence has 128 or so
+ });
+p $resp->code;
+#p $resp->data;
+
+print "CREATE SIGNALING ###################################\n";
+
+$resp = $test->create_signaling({});
+p $resp->code;
+#p $resp->data;
+
+print "CREATE SIP ###################################\n";
+
+$resp = $test->create_sip;
+p $resp->code;
+#p $resp->data;
+
+print "CREATE SIP IP ###################################\n";
+
+$resp = $test->create_sip_ip;
+p $resp->code;
+#p $resp->data;
+
sub try_parse_file {
return unless ($#ARGV >= 1);