diff --git a/lib/NGCP/Panel/Utils/DialogicImg.pm b/lib/NGCP/Panel/Utils/DialogicImg.pm index 22db098f8a..d1264066e5 100644 --- a/lib/NGCP/Panel/Utils/DialogicImg.pm +++ b/lib/NGCP/Panel/Utils/DialogicImg.pm @@ -40,6 +40,9 @@ has '+serializer_options' => (default => sub { options => { RootName => 'object' } ); return { serializer => $s }; }); +has '+clientattrs' => ( default => sub { + return {timeout => 5}; + }); has 'appid' => ( is => 'rw', isa => Int, default => 0 ); has 'pids' => ( is => 'rw', @@ -53,6 +56,7 @@ has 'pids' => ( }; } ); +# returns appid or 0 sub login { my ( $self, $username, $password ) = @_; my $resp = $self->post( @@ -64,6 +68,7 @@ sub login { $self->appid( $data->{appid} ); return $self->appid; } + return 0; } sub obtain_lock { @@ -163,7 +168,6 @@ sub create_interface { return $resp; } -#TODO: only supports ipv4 now sub create_ip_address { my ( $self, $options ) = @_; @@ -181,6 +185,15 @@ sub create_ip_address { warn "Failed to fetch resource\n"; return $resp; } + my $validation_data = $self->_build_validation_data( $resp->data, $pid, $options ); + $resp = $self->get( + "/oamp/configuration/objects/NetworkInterface/NULL", + $validation_data, + ); + if ( $resp->code != 200 ) { + warn "Failed to fetch resource second time (revalidate)\n"; + return $resp; + } my $new_resp = $self->_build_response_data( $resp->data, $pid, $options ); $resp = $self->post( "/oamp/configuration/objects/NetworkInterface/NULL?pid=$pid&appid=$appid", @@ -390,10 +403,19 @@ sub create_ip_profile { warn "Failed to fetch resource\n"; return $resp; } - my $new_resp = $self->_build_response_data( $resp->data, $pid, $options ); + my $validation_data = $self->_build_validation_data( $resp->data, $pid, $options ); + $resp = $self->get( + "/oamp/configuration/objects/IPProfile/NULL", + $validation_data, + ); + if ( $resp->code != 200 ) { + warn "Failed to fetch resource second time (revalidate)\n"; + return $resp; + } + my $new_data = $self->_build_response_data( $resp->data, $pid, $options ); $resp = $self->post( "/oamp/configuration/objects/IPProfile/NULL?pid=$pid&appid=$appid", - $new_resp, + $new_data, ); if ( $resp->code == 200 ) { $self->pids->{ip_profile} = $resp->data->{oid}; @@ -411,7 +433,7 @@ sub create_vocoder_profile { "/oamp/configuration/objects/VocoderProfile/NULL?detaillevel=4&pid=$pid&appid=$appid&$enc_data", ); if ( $resp->code != 200 ) { - warn "Failed to fetch resource second time (revalidate)\n"; + warn "Failed to fetch resource\n"; return $resp; } my $validation_data = $self->_build_validation_data( $resp->data, $pid, $options ); @@ -419,6 +441,10 @@ sub create_vocoder_profile { "/oamp/configuration/objects/VocoderProfile/NULL", $validation_data, ); + if ( $resp->code != 200 ) { + warn "Failed to fetch resource second time (revalidate)\n"; + return $resp; + } my $new_data = $self->_build_response_data( $resp->data, $pid, $options ); $resp = $self->post( "/oamp/configuration/objects/VocoderProfile/NULL?pid=$pid&appid=$appid", @@ -476,6 +502,84 @@ sub create_sip_profile { return $resp; } +sub create_external_network_elements { + my ( $self ) = @_; + + my $pid = 10_000; + my $appid = $self->appid; + my $resp = $self->get( + "/oamp/configuration/objects/ExternalNetworkElements/NULL?detaillevel=4&pid=$pid&appid=$appid", + ); + if ( $resp->code != 200 ) { + warn "Failed to fetch resource\n"; + return $resp; + } + my $new_data = $self->_build_response_data( $resp->data, $pid ); + $resp = $self->post( + "/oamp/configuration/objects/ExternalNetworkElements/NULL?pid=$pid&appid=$appid", + $new_data, + ); + if ( $resp->code == 200 ) { + $self->pids->{external_network_elements} = $resp->data->{oid}; + } + return $resp; +} + +sub create_external_gateway_collection { + my ( $self, $options ) = @_; + + my $pid = $self->pids->{external_network_elements}; + my $appid = $self->appid; + my $resp = $self->get( + "/oamp/configuration/objects/ExternalGateways/NULL?detaillevel=4&pid=$pid&appid=$appid", + ); + if ( $resp->code != 200 ) { + warn "Failed to fetch resource\n"; + return $resp; + } + my $new_data = $self->_build_response_data( $resp->data, $pid, $options ); + $resp = $self->post( + "/oamp/configuration/objects/ExternalGateways/NULL?pid=$pid&appid=$appid", + $new_data, + ); + if ( $resp->code == 200 ) { + $self->pids->{external_gateway_collection} = $resp->data->{oid}; + } + return $resp; +} + +sub create_external_gateway { + my ( $self, $options ) = @_; + + my $pid = $self->pids->{external_gateway_collection}; + my $appid = $self->appid; + my $resp = $self->get( + "/oamp/configuration/objects/ExternalGateway/NULL?detaillevel=4&pid=$pid&appid=$appid", + ); + if ( $resp->code != 200 ) { + warn "Failed to fetch resource\n"; + return $resp; + } + my $validation_data = $self->_build_validation_data( $resp->data, $pid, $options ); + $resp = $self->get( + "/oamp/configuration/objects/ExternalGateway/NULL", + $validation_data, + ); + if ( $resp->code != 200 ) { + warn "Failed to fetch resource second time (revalidate)\n"; + return $resp; + } + my $new_data = $self->_build_response_data( $resp->data, $pid, $options ); + $resp = $self->post( + "/oamp/configuration/objects/ExternalGateway/NULL?pid=$pid&appid=$appid", + $new_data, + ); + if ( $resp->code == 200 ) { + $self->pids->{external_gateway} = $resp->data->{oid}; + } + return $resp; +} + sub create_routing_configuration { my ($self) = @_; @@ -545,6 +649,130 @@ sub create_channel_group { return $resp; } +sub create_route_table_collection { + my ($self, $options) = @_; + + my $pid = $self->pids->{routing_configuration}; + my $appid = $self->appid; + my $resp = $self->get( + "/oamp/configuration/objects/RoutingTables/NULL?detaillevel=4&pid=$pid&appid=$appid", + ); + if ( $resp->code != 200 ) { + warn "Failed to fetch resource\n"; + return $resp; + } + my $new_data = $self->_build_response_data( $resp->data, $pid, $options); + $resp = $self->post( + "/oamp/configuration/objects/RoutingTables/NULL?pid=$pid&appid=$appid", + $new_data, + ); + if ( $resp->code == 200 ) { + $self->pids->{route_table_collection} = $resp->data->{oid}; + } + return $resp; +} + +sub create_route_table { + my ($self, $options) = @_; + + my $pid = $self->pids->{route_table_collection}; + my $appid = $self->appid; + my $resp = $self->get( + "/oamp/configuration/objects/RouteTable/NULL?detaillevel=4&pid=$pid&appid=$appid", + ); + if ( $resp->code != 200 ) { + warn "Failed to fetch resource\n"; + return $resp; + } + my $new_data = $self->_build_response_data( $resp->data, $pid, $options); + $resp = $self->post( + "/oamp/configuration/objects/RouteTable/NULL?pid=$pid&appid=$appid", + $new_data, + ); + if ( $resp->code == 200 ) { + $self->pids->{route_table} = $resp->data->{oid}; + } + return $resp; +} + +sub create_route_element { + my ($self, $options) = @_; + + my $pid = $self->pids->{route_table}; + my $appid = $self->appid; + my $resp = $self->get( + "/oamp/configuration/objects/RouteElement/NULL?detaillevel=4&pid=$pid&appid=$appid", + ); + if ( $resp->code != 200 ) { + warn "Failed to fetch resource\n"; + return $resp; + } + my $validation_data = $self->_build_validation_data( $resp->data, $pid, $options ); + $resp = $self->get( + "/oamp/configuration/objects/RouteElement/NULL", + $validation_data, + ); + if ( $resp->code != 200 ) { + warn "Failed to fetch resource second time (revalidate)\n"; + return $resp; + } + my $new_data = $self->_build_response_data( $resp->data, $pid, $options); + $resp = $self->post( + "/oamp/configuration/objects/RouteElement/NULL?pid=$pid&appid=$appid", + $new_data, + ); + if ( $resp->code == 200 ) { + $self->pids->{route_element} = $resp->data->{oid}; + } + return $resp; +} + +sub create_cg_network_element { + my ($self, $options) = @_; + + my $pid = $self->pids->{channel_group}; + my $appid = $self->appid; + my $resp = $self->get( + "/oamp/configuration/objects/NetworkElement/NULL?detaillevel=4&pid=$pid&appid=$appid", + ); + if ( $resp->code != 200 ) { + warn "Failed to fetch resource\n"; + return $resp; + } + my $new_data = $self->_build_response_data( $resp->data, $pid, $options); + $resp = $self->post( + "/oamp/configuration/objects/NetworkElement/NULL?pid=$pid&appid=$appid", + $new_data, + ); + if ( $resp->code == 200 ) { + $self->pids->{cg_network_element} = $resp->data->{oid}; + } + return $resp; +} + +sub create_node_association { + my ($self, $options) = @_; + + my $pid = $self->pids->{cg_network_element}; + my $appid = $self->appid; + my $resp = $self->get( + "/oamp/configuration/objects/NodeAssociation/NULL?detaillevel=4&pid=$pid&appid=$appid", + ); + if ( $resp->code != 200 ) { + warn "Failed to fetch resource\n"; + return $resp; + } + my $new_data = $self->_build_response_data( $resp->data, $pid, $options); + $resp = $self->post( + "/oamp/configuration/objects/NodeAssociation/NULL?pid=$pid&appid=$appid", + $new_data, + ); + if ( $resp->code == 200 ) { + $self->pids->{node_association} = $resp->data->{oid}; + } + return $resp; +} + ### OTHER STUFF ### sub download_profiles { @@ -559,6 +787,30 @@ sub download_profiles { return $resp; } +sub download_route_table { + my ($self) = @_; + + my $appid = $self->appid; + my $pid = $self->pids->{route_table}; + $self->set_header( 'Content-Length' => '0', ); + my $resp = $self->put( + "/oamp/configuration/objects/RouteTable/$pid/provisions/Cached?appid=$appid&sync_key=0", + ); + return $resp; +} + +sub download_channel_groups { + my ($self) = @_; + + my $appid = $self->appid; + my $pid = $self->pids->{channel_group_collection}; + $self->set_header( 'Content-Length' => '0', ); + my $resp = $self->put( + "/oamp/configuration/objects/ChannelGroups/$pid/provisions/Cached?appid=$appid&sync_key=0", + ); + return $resp; +} + #delete all children of bn2020 but not the node itself sub delete_all_bn2020 { my ($self) = @_; diff --git a/share/tools/dialogic-test-client.pl b/share/tools/dialogic-test-client.pl index ffd6b56dce..d38e1e7069 100644 --- a/share/tools/dialogic-test-client.pl +++ b/share/tools/dialogic-test-client.pl @@ -9,16 +9,8 @@ exit if try_parse_file(@ARGV); my $test = NGCP::Panel::Utils::DialogicImg->new( server => 'https://10.15.20.150', - clientattrs => { - timeout => 5, - # SSL_options => { - # SSL_version => 'SSLv23:!SSLv2:!SSLv3:!TLSv1_1:!TLSv1_2', - # }, - }, ); -#p $test; - p $test->login( 'dialogic', 'Dial0gic' ); my $resp @@ -30,13 +22,29 @@ p $resp->code; print "LOGGED IN, LOCK OBTAINED ############################\n"; # $resp = $test->delete_all_bn2020; -# p $resp; +# $resp = $test->delete_all_bn2020; +# p $resp->code; # exit 0; # $resp = $test->reboot_and_wait; # p $resp; # exit 0; +# $test->pids->{route_table} = 10033; +# $test->download_route_table; +# $test->pids->{channel_group_collection} = 10030; +# $test->download_channel_groups; +# exit 0; +# $resp = $test->create_route_element({ +# StringType => 'Channel Group', +# InChannelGroup => 'ChannelGroup0', +# RouteActionType => 'Channel Group', +# RouteActionList => 'ChannelGroup0', +# }); +# p $resp->code; +# #p $resp->data; +# exit 0; + $resp = $test->create_bn2020; p $resp->code; #p $resp->data; @@ -61,7 +69,7 @@ p $resp->code; #p $resp->data; $resp = $test->create_ip_address({ - NIIPAddress => '11.2.3.4', + NIIPAddress => '10.15.20.92', NIIPPhy => 'Services', }); p $resp->code; @@ -71,8 +79,9 @@ $resp = $test->create_interface; # DataA by default p $resp->code; #p $resp->data; -$resp = $test->create_ip_address({NIIPAddress => '11.6.7.8', - NIIPPhy => 'Media 0'}); +$resp = $test->create_ip_address({ + NIIPAddress => '10.15.21.10', + NIIPPhy => 'Media 0'}); p $resp->code; #p $resp->data; @@ -91,14 +100,16 @@ p $resp->code; print "CREATE PACKET FACILITY ###################################\n"; $resp = $test->create_packet_facility({ - ChannelCount => 5, # our licence has 128 or so + ChannelCount => 50, # our licence has 128 or so }); p $resp->code; #p $resp->data; +lsign: + print "CREATE SIGNALING ###################################\n"; -$resp = $test->create_signaling({}); +$resp = $test->create_signaling; p $resp->code; #p $resp->data; @@ -110,7 +121,9 @@ p $resp->code; print "CREATE SIP IP ###################################\n"; -$resp = $test->create_sip_ip; +$resp = $test->create_sip_ip({ + IPAddress => '10.15.20.92', + }); p $resp->code; #p $resp->data; @@ -154,6 +167,12 @@ $resp = $test->create_vocoder_profile({ p $resp->code; #p $resp->data; +$resp = $test->create_vocoder_profile({ + PayloadType => 'AMR', + }); +p $resp->code; +#p $resp->data; + print "CREATE SIP PROFILE COLLECTION ###################################\n"; $resp = $test->create_sip_profile_collection; @@ -167,10 +186,10 @@ $resp = $test->create_sip_profile({ p $resp->code; #p $resp->data; -$resp = $test->create_sip_profile({ - }); -p $resp->code; -#p $resp->data; +# $resp = $test->create_sip_profile({ +# }); +# p $resp->code; +# #p $resp->data; print "DOWNLOAD PROFILE COLLECTION ###################################\n"; @@ -178,6 +197,28 @@ $resp = $test->download_profiles; p $resp->code; #p $resp->data; +print "CREATE EXTERNAL NETWORK ELEMENTS ###################################\n"; + +$resp = $test->create_external_network_elements; +p $resp->code; +#p $resp->data; + +print "CREATE EXTERNAL GATEWAY COLLECTION ###################################\n"; + +$resp = $test->create_external_gateway_collection; +p $resp->code; +#p $resp->data; + +print "CREATE EXTERNAL GATEWAY ###################################\n"; + +$resp = $test->create_external_gateway({ + Name => 'Phone1', + IPAddress => '10.15.20.199', + IPAddress4 => '10.15.20.199', + }); +p $resp->code; +#p $resp->data; + print "CREATE ROUTING CONFIGURATION ###################################\n"; $resp = $test->create_routing_configuration({ @@ -192,14 +233,65 @@ $resp = $test->create_channel_group_collection({ p $resp->code; #p $resp->data; +print "CREATE ROUTE TABLE COLLECTION ###################################\n"; + +$resp = $test->create_route_table_collection; +p $resp->code; +#p $resp->data; + +print "CREATE ROUTE TABLE ###################################\n"; + +$resp = $test->create_route_table({ + #Name => 'ngcp_route_table', + }); +p $resp->code; +#p $resp->data; + print "CREATE CHANNEL GROUP ###################################\n"; $resp = $test->create_channel_group({ SignalingType => 'SIP', + #RouteTable => ???, + InRouteTable => 'Table - ID: 5', + InIPProfile => 'IP_Profile_1', + InIPProfileId => '1', + OutIPProfile => 'IP_Profile_1', + #incoming ip profile, set? + #outgoing ip profile, set? + SupportA2F => 'True', + }); +p $resp->code; +#p $resp->data; + +print "CREATE NETWORK ELEMENT (CG) ###################################\n"; + +$resp = $test->create_cg_network_element; +p $resp->code; +#p $resp->data; + +print "CREATE NODE ASSOCIATION ###################################\n"; + +$resp = $test->create_node_association; +p $resp->code; +#p $resp->data; + +print "CREATE ROUTE ELEMENT ###################################\n"; + +$resp = $test->create_route_element({ + StringType => 'Channel Group', + InChannelGroup => 'ChannelGroup0', + RouteActionType => 'Channel Group', + RouteActionList => 'ChannelGroup0', }); p $resp->code; #p $resp->data; +$resp = $test->download_route_table; +p $resp->code; + +$resp = $test->download_channel_groups; +p $resp->code; + sub try_parse_file { return unless ($#ARGV >= 1);