Commit 88d6ffe9 authored by rygelgit's avatar rygelgit

Perl scripts for simulating DIAGC/DIAGE interactions

parents
#!/usr/bin/perl
use strict;
use Switch;
# Use the module
use utils::Util;
use utils::SocketCalls;
use include::ActionRequestInclude;
use include::ActionResponseInclude;
use ResponseValidator;
while (1) {
Util::print_diagc_start;
our ($OPTION, $HOSTIP, $HOSTPORT) = Util::get_user_input;
switch($OPTION){
case 1 {
my $devicestatus_response = DeviceStatusRequest::devicestatus_request($HOSTIP, $HOSTPORT);
ResponseValidator::valiate_soap_response($devicestatus_response);
}
case 2 {
print "Enter the Test number for CancelTest : ";
my $TESTID = <>;
chomp $TESTID;
my $canceltest_response = CancelTestRequest::canceltest_request($HOSTIP, $HOSTPORT, $TESTID);
ResponseValidator::valiate_soap_response($canceltest_response);
}
case 3 {
my $activetestids_response = GetActiveTestIDsRequest::activetestids_request($HOSTIP, $HOSTPORT);
ResponseValidator::valiate_soap_response($activetestids_response);
}
case 4 {
print "Enter the HostName to perform NSLookup : ";
my $HOST_NAME = <>;
chomp $HOST_NAME;
my $nslookup_req_response = NSLookUpRequest::nslookup_request($HOSTIP, $HOSTPORT, $HOST_NAME);
ResponseValidator::valiate_soap_response($nslookup_req_response);
}
case 5 {
print "Enter the HostName to perform Ping : ";
my $HOST_NAME = <>;
chomp $HOST_NAME;
my $ping_req_response = PingRequest::ping_request($HOSTIP, $HOSTPORT, $HOST_NAME);
ResponseValidator::valiate_soap_response($ping_req_response);
}
case 6 {
print "Enter the HostName to perform traceroute : ";
my $HOST_NAME = <>;
chomp $HOST_NAME;
my $traceroute_req_request = TracerouteRequest::traceroute_request($HOSTIP, $HOSTPORT, $HOST_NAME);
ResponseValidator::valiate_soap_response($traceroute_req_request);
}
case 7 {
my $testidsreq_response = TestIDsRequest::testids_request($HOSTIP, $HOSTPORT);
ResponseValidator::valiate_soap_response($testidsreq_response);
}
case 8 {
print "Enter the Test number for TestInfo : ";
my $TESTID_INFO = <>;
chomp $TESTID_INFO;
my $testinfo_response = TestInfoRequest::testinfo_request($HOSTIP, $HOSTPORT, $TESTID_INFO);
ResponseValidator::valiate_soap_response($testinfo_response);
}
case 9 {
print "Enter the Test number for GetNSLookupResult : ";
my $TESTID_INFO = <>;
chomp $TESTID_INFO;
my $nslookup_res_response = NSLookUpResponse::nslookup_response($HOSTIP, $HOSTPORT, $TESTID_INFO);
ResponseValidator::valiate_soap_response($nslookup_res_response);
}
case 10 {
print "Enter the Test number for GetPingResult : ";
my $TESTID_INFO = <>;
chomp $TESTID_INFO;
my $ping_res_response = PingResponse::ping_response($HOSTIP, $HOSTPORT, $TESTID_INFO);
ResponseValidator::valiate_soap_response($ping_res_response);
}
case 11 {
print "Enter the Test number for GetTracerouteResult : ";
my $TESTID_INFO = <>;
chomp $TESTID_INFO;
my $traceroute_res_response = TracerouteResponse::traceroute_response($HOSTIP, $HOSTPORT, $TESTID_INFO);
ResponseValidator::valiate_soap_response($traceroute_res_response);
}
case ('x') { exit; }
}
}
1;
Install Switch module before using the script:
----------------------------------------------
sudo apt-get install libswitch-perl
Running the script:
-------------------
DIAGC.pl is the main script.
#!/usr/bin/perl
package ResponseValidator;
sub valiate_soap_response {
my $soap_response = $_[0];
#if($soap_response->code == 200) {
print $soap_response->as_string;
#}
#else {
# print $soap_response->as_string;
#}
}
1;
#!/bin/usr/perl
package ActionRequestInclude;
use requestaction::DeviceStatusRequest;
use requestaction::CancelTestRequest;
use requestaction::GetActiveTestIDsRequest;
use requestaction::NSLookUpRequest;
use requestaction::PingRequest;
use requestaction::TracerouteRequest;
use requestaction::TestIDsRequest;
use requestaction::TestInfoRequest;
1;
#!/bin/usr/perl
package ActionresponseInclude;
use responseaction::NSLookUpResponse;
use responseaction::PingResponse;
use responseaction::TracerouteResponse;
1;
#!/usr/bin/perl
package CancelTestRequest;
use utils::SocketCalls;
our $canceltest_action = "\"urn:schemas-upnp-org:service:BasicManagement:2#CancelTest\"";
our $canceltest_request_message1 = "<?xml version=\"1.0\" encoding=\"utf-8\"?>
<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">
<s:Body>
<u:CancelTest xmlns:u=\"urn:schemas-upnp-org:service:BasicManagement:2\">
<TestID>";
our $canceltest_request_message2="</TestID>
</u:CancelTest>
</s:Body>
</s:Envelope>";
sub canceltest_request {
return SocketCalls::invoke_soap_request($_[0], $_[1], $canceltest_request_message1 . $_[2] . $canceltest_request_message2, $canceltest_action);
}
#!/usr/bin/perl
package DeviceStatusRequest;
use utils::SocketCalls;
our $devicestatus_action = "\"urn:schemas-upnp-org:service:BasicManagement:2#GetDeviceStatus\"";
our $devicestatus_request_message = "<?xml version=\"1.0\" encoding=\"utf-8\"?>
<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">
<s:Body>
<u:GetDeviceStatus xmlns:u=\"urn:schemas-upnp-org:service:BasicManagement:2\" />
</s:Body>
</s:Envelope>";
sub devicestatus_request {
return SocketCalls::invoke_soap_request($_[0], $_[1], $devicestatus_request_message,$devicestatus_action);
}
#!/usr/bin/perl
package GetActiveTestIDsRequest;
use utils::SocketCalls;
our $activetestids_action = "\"urn:schemas-upnp-org:service:BasicManagement:2#GetActiveTestIDs\"";
our $activetestids_request_message = "<?xml version=\"1.0\" encoding=\"utf-8\"?>
<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">
<s:Body>
<u:GetActiveTestIDs xmlns:u=\"urn:schemas-upnp-org:service:BasicManagement:2\" />
</s:Body>
</s:Envelope>";
sub activetestids_request {
return SocketCalls::invoke_soap_request($_[0], $_[1], $activetestids_request_message, $activetestids_action);
}
#!/usr/bin/perl
package NSLookUpRequest;
use utils::SocketCalls;
our $nslookup_action = "\"urn:schemas-upnp-org:service:BasicManagement:2#NSLookup\"";
our $nslookup_request_message1 = "<?xml version=\"1.0\" encoding=\"utf-8\"?>
<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">
<s:Body>
<u:NSLookup xmlns:u=\"urn:schemas-upnp-org:service:BasicManagement:2\">
<HostName>";
our $host_nslookup = "127.0.0.1";
our $nslookup_request_message2="</HostName>
<DNSServer />
<NumberOfRepetitions>0</NumberOfRepetitions>
<Timeout>0</Timeout>
</u:NSLookup>
</s:Body>
</s:Envelope>";
sub nslookup_request {
my $host_value = "";
if ($_[2] eq '') {
$host_value = $host_value . $host_nslookup;
} else {
$host_value = $host_value . $_[2];
}
return SocketCalls::invoke_soap_request($_[0], $_[1], $nslookup_request_message1 . $host_value . $nslookup_request_message2, $nslookup_action);
}
#!/usr/bin/perl
package PingRequest;
use utils::SocketCalls;
our $ping_action = "\"urn:schemas-upnp-org:service:BasicManagement:2#Ping\"";
our $ping_request_message1 = "<?xml version=\"1.0\" encoding=\"utf-8\"?>
<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">
<s:Body>
<u:Ping xmlns:u=\"urn:schemas-upnp-org:service:BasicManagement:2\">
<Host>";
our $host_ping = "127.0.0.1";
our $ping_request_message2="</Host>
<NumberOfRepetitions>0</NumberOfRepetitions>
<Timeout>0</Timeout>
<DataBlockSize>0</DataBlockSize>
<DSCP>0</DSCP>
</u:Ping>
</s:Body>
</s:Envelope>";
sub ping_request {
my $host_value = "";
if ($_[2] eq '') {
$host_value = $host_value . $host_ping;
} else {
$host_value = $host_value . $_[2];
}
return SocketCalls::invoke_soap_request($_[0], $_[1], $ping_request_message1 . $host_value . $ping_request_message2, $ping_action);
}
#!/usr/bin/perl
package TestIDsRequest;
use utils::SocketCalls;
our $testids_action = "\"urn:schemas-upnp-org:service:BasicManagement:2#GetTestIDs\"";
our $testids_request_message = "<?xml version=\"1.0\" encoding=\"utf-8\"?>
<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">
<s:Body>
<u:GetTestIDs xmlns:u=\"urn:schemas-upnp-org:service:BasicManagement:2\" />
</s:Body>
</s:Envelope>";
sub testids_request {
return SocketCalls::invoke_soap_request($_[0], $_[1], $testids_request_message, $testids_action);
}
#!/usr/bin/perl
package TestInfoRequest;
use utils::SocketCalls;
our $testinfo_action = "\"urn:schemas-upnp-org:service:BasicManagement:2#GetTestInfo\"";
our $testinfo_request_message1 = "<?xml version=\"1.0\" encoding=\"utf-8\"?>
<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">
<s:Body>
<u:GetTestInfo xmlns:u=\"urn:schemas-upnp-org:service:BasicManagement:2\">
<TestID>";
our $testinfo_request_message2="</TestID>
</u:GetTestInfo>
</s:Body>
</s:Envelope>";
sub testinfo_request {
return SocketCalls::invoke_soap_request($_[0], $_[1], $testinfo_request_message1 . $_[2] . $testinfo_request_message2, $testinfo_action);
}
#!/usr/bin/perl
package TracerouteRequest;
use utils::SocketCalls;
our $traceroute_action = "\"urn:schemas-upnp-org:service:BasicManagement:2#Traceroute\"";
our $traceroute_request_message1 = "<?xml version=\"1.0\" encoding=\"utf-8\"?>
<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">
<s:Body>
<u:Traceroute xmlns:u=\"urn:schemas-upnp-org:service:BasicManagement:2\">
<Host>";
our $host_ping = "127.0.0.1";
our $traceroute_request_message2="</Host>
<Timeout>0</Timeout>
<DataBlockSize>0</DataBlockSize>
<MaxHopCount>0</MaxHopCount>
<DSCP>0</DSCP>
</u:Traceroute>
</s:Body>
</s:Envelope>";
sub traceroute_request {
my $host_value = "";
if ($_[2] eq '') {
$host_value = $host_value . $host_ping;
} else {
$host_value = $host_value . $_[2];
}
return SocketCalls::invoke_soap_request($_[0], $_[1], $traceroute_request_message1 . $host_value . $traceroute_request_message2, $traceroute_action);
}
#!/usr/bin/perl
package NSLookUpResponse;
use utils::SocketCalls;
our $nslookup_response_action = "\"urn:schemas-upnp-org:service:BasicManagement:2#GetNSLookupResult\"";
our $nslookup_response_message1 = "<?xml version=\"1.0\" encoding=\"utf-8\"?>
<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">
<s:Body>
<u:GetNSLookupResult xmlns:u=\"urn:schemas-upnp-org:service:BasicManagement:2\">
<TestID>";
our $nslookup_response_message2="</TestID>
</u:GetNSLookupResult>
</s:Body>
</s:Envelope>";
sub nslookup_response {
return SocketCalls::invoke_soap_request($_[0], $_[1], $nslookup_response_message1 . $_[2] . $nslookup_response_message2, $nslookup_response_action);
}
#!/usr/bin/perl
package PingResponse;
use utils::SocketCalls;
our $ping_response_action = "\"urn:schemas-upnp-org:service:BasicManagement:2#GetPingResult\"";
our $ping_response_message1 = "<?xml version=\"1.0\" encoding=\"utf-8\"?>
<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">
<s:Body>
<u:GetPingResult xmlns:u=\"urn:schemas-upnp-org:service:BasicManagement:2\">
<TestID>";
our $ping_response_message2="</TestID>
</u:GetPingResult>
</s:Body>
</s:Envelope>";
sub ping_response {
return SocketCalls::invoke_soap_request($_[0], $_[1], $ping_response_message1 . $_[2] . $ping_response_message2, $ping_response_action);
}
#!/usr/bin/perl
package TracerouteResponse;
use utils::SocketCalls;
our $traceroute_response_action = "\"urn:schemas-upnp-org:service:BasicManagement:2#GetTracerouteResult\"";
our $traceroute_response_message1 = "<?xml version=\"1.0\" encoding=\"utf-8\"?>
<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">
<s:Body>
<u:GetTracerouteResult xmlns:u=\"urn:schemas-upnp-org:service:BasicManagement:2\">
<TestID>";
our $traceroute_response_message2="</TestID>
</u:GetTracerouteResult>
</s:Body>
</s:Envelope>";
sub traceroute_response {
return SocketCalls::invoke_soap_request($_[0], $_[1], $traceroute_response_message1 . $_[2] . $traceroute_response_message2, $traceroute_response_action);
}
package SoapHeaders;
our $content_type = "text/xml; charset=utf-8";
our $control_url = "/Control/ODIDMediaServer/RygelBasicManagement";
our $http_prefix = 'http://';
our $separator = ':';
1;
#!/usr/bin/perl
package SocketCalls;
use utils::SoapHeaders qw( );
use LWP::UserAgent;
use HTTP::Request;
sub invoke_soap_request {
#print "The passed IP Address :" . $_[0] . "\n";
#print "The passed port no :" . $_[1] . "\n";
#print "Request Message : " . $_[2] . "\n";
#print "Soap Action :".$_[3] . "\n";
my $post_url = $SoapHeaders::http_prefix . $_[0] . $SoapHeaders::separator . $_[1] . $SoapHeaders::control_url;
print $post_url;
my $user_agent = LWP::UserAgent->new();
my $soap_request = HTTP::Request->new(POST => $post_url);
$soap_request->header(SOAPAction => $_[3]);
$soap_request->content($_[2]);
$soap_request->content_type($SoapHeaders::content_type);
my $soap_response = $user_agent->request($soap_request);
return $soap_response;
}
1;
#!/usr/bin/perl
package Util;
use strict;
sub print_diagc_start {
print "\n\nDIAGC - Utility Client\n";
print " ---------------------\n";
print "1. GetDeviceStatus \n";
print "2. CancelTest \n";
print "3. GetActiveTestIDs \n";
print "4. NSLookup \n";
print "5. Ping \n";
print "6. Traceroute \n";
print "7. GetTestIDs\n";
print "8. GetTestInfo\n";
print "9. GetNSLookupResult \n";
print "10. GetPingResult \n";
print "11. GetTracerouteResult \n";
print "x - Exit application \n";
print " ---------------------\n";
}
sub get_user_input {
print "Input the number corresponding to the action to be invoked : ";
our $USR_OPT = <>;
chomp $USR_OPT;
if ($USR_OPT eq 'x') {
return ($USR_OPT);
}
print "Enter the DIAGE host IPAddress : " ;
our $IP = <>;
chomp $IP;
print "Enter the DIAGE host Port Number : ";
our $PORT = <>;
chomp $PORT;
return ($USR_OPT, $IP, $PORT);
}
1;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment