DIAGC.pl 8.36 KB
Newer Older
rygelgit's avatar
rygelgit committed
1 2
#!/usr/bin/perl

rygelgit's avatar
rygelgit committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
# Copyright (c) 2014, CableLabs, Inc.
# All rights reserved.
#
# Author: Parthiban Balasubramanian<p.balasubramanian@cablelabs.com>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
rygelgit's avatar
rygelgit committed
29
#
30 31 32 33 34 35 36 37 38

use strict;
use Switch;

# Use the module
use utils::Util;
use utils::SocketCalls;
use include::ActionRequestInclude;
use include::ActionResponseInclude;
39
use include::UPnPInclude;
40
use responsevalidator::ResponseValidator;
41

42 43
START:

44
our ($TEST_OPTION, $HOSTIP, $HOSTPORT, $CONTROL_URL) = '';
45

46
print "\33[1;33m------- Choose an option -------\33[m\n";
47 48
print "1. Search DIAGE capable devices \n";
print "2. Manual DIAGE device testing \n";
49
print "3. Exit Application \n";
50
print "\33[1;33mEnter the option number : \33[m";
51 52 53 54
our $SEARCH_OPTS = <>;
chomp $SEARCH_OPTS;

switch($SEARCH_OPTS){
55
       case 1          {
56 57
                        my ($diage_devices, $diage_ip, $diage_port, $control_url) = SearchDevices::lookup_diage_device;
                        print "\33[1;33mChoose the corresponding device number to start testing: \33[m\n";
58

59
                        my $device_count=0;
60 61
                        print "****************************************\n";
                        print "****************************************\n";
62 63

                        foreach my $device_temp (@$diage_devices) {
64 65 66 67 68
                            print "----------------------------------------\33[m\n";
                            print "\33[1;33m[" . ($device_count + 1) . "] : " . $device_temp->getfriendlyname() . "\33[m\n";
                            print "\33[1;33mDevice IP : " . @$diage_ip[$device_count] . "\33[m\n";
                            print "\33[1;33mDevice Port : " . @$diage_port[$device_count] . "\33[m\n";
                            print "\33[1;33mControl URL : " . @$control_url[$device_count] . "\33[m\n";
69
                            $device_count++;
70
                        }
71

72 73 74
                        print "****************************************\n";
                        print "****************************************\n";

75
                        print "\33[1;33mChoose the device number: \33[m";
76 77
                        my $DEVICE_NO = <>;
                        chomp $DEVICE_NO;
78

79 80
                        $HOSTIP = @$diage_ip[$DEVICE_NO - 1];
                        $HOSTPORT = @$diage_port[$DEVICE_NO - 1];
81
                        $CONTROL_URL = @$control_url[$DEVICE_NO - 1];
82 83 84 85 86
                        Util::print_diagc_start;
                       }
       case 2          {
                        Util::print_diagc_start;
                       }                       
87
       case 3          {
88 89 90 91 92 93
                        exit;
                       }
       else            { exit;}  
       
}

94
while (1) {
95
GET_USER_OPT:
96 97
    $TEST_OPTION = Util::get_user_options;
    if ($SEARCH_OPTS eq '2') {
98
      ($HOSTIP, $HOSTPORT, $CONTROL_URL) = Util::get_manual_device_details;
99
    }
100

101
    switch($TEST_OPTION){
102
       case 1          {
103
                        my $devicestatus_response = DeviceStatusRequest::devicestatus_request($HOSTIP, $HOSTPORT, $CONTROL_URL);
104 105 106 107 108 109
                        ResponseValidator::valiate_soap_response($devicestatus_response);
                       }
       case 2          {
                        print "Enter the Test number for CancelTest : ";
                        my $TESTID = <>;
                        chomp $TESTID;
110
                        my $canceltest_response = CancelTestRequest::canceltest_request($HOSTIP, $HOSTPORT, $TESTID, $CONTROL_URL);
111 112 113
                        ResponseValidator::valiate_soap_response($canceltest_response);
                       }
       case 3          {
114
                        my $activetestids_response = GetActiveTestIDsRequest::activetestids_request($HOSTIP, $HOSTPORT, $CONTROL_URL);
115 116 117 118 119 120
                        ResponseValidator::valiate_soap_response($activetestids_response);
                       }
       case 4          {
                        print "Enter the HostName to perform NSLookup : ";
                        my $HOST_NAME = <>;
                        chomp $HOST_NAME;
121
                        my $nslookup_req_response = NSLookUpRequest::nslookup_request($HOSTIP, $HOSTPORT, $HOST_NAME, $CONTROL_URL);
122 123 124 125 126 127
                        ResponseValidator::valiate_soap_response($nslookup_req_response);
                       }
       case 5          {
                        print "Enter the HostName to perform Ping : ";
                        my $HOST_NAME = <>;
                        chomp $HOST_NAME;
128
                        my $ping_req_response = PingRequest::ping_request($HOSTIP, $HOSTPORT, $HOST_NAME, $CONTROL_URL);
129 130 131 132 133 134
                        ResponseValidator::valiate_soap_response($ping_req_response);
                       }
       case 6          {
                        print "Enter the HostName to perform traceroute : ";
                        my $HOST_NAME = <>;
                        chomp $HOST_NAME;
135
                        my $traceroute_req_request = TracerouteRequest::traceroute_request($HOSTIP, $HOSTPORT, $HOST_NAME, $CONTROL_URL);
136 137 138
                        ResponseValidator::valiate_soap_response($traceroute_req_request);
                       }
       case 7          {
139
                        my $testidsreq_response = TestIDsRequest::testids_request($HOSTIP, $HOSTPORT, $CONTROL_URL);
140 141 142 143 144 145
                        ResponseValidator::valiate_soap_response($testidsreq_response);
                       }
       case 8          {
                        print "Enter the Test number for TestInfo : ";
                        my $TESTID_INFO = <>;
                        chomp $TESTID_INFO;
146
                        my $testinfo_response = TestInfoRequest::testinfo_request($HOSTIP, $HOSTPORT, $TESTID_INFO, $CONTROL_URL);
147 148 149 150 151 152
                        ResponseValidator::valiate_soap_response($testinfo_response);
                       }
       case 9          {
                        print "Enter the Test number for GetNSLookupResult : ";
                        my $TESTID_INFO = <>;
                        chomp $TESTID_INFO;
153
                        my $nslookup_res_response = NSLookUpResponse::nslookup_response($HOSTIP, $HOSTPORT, $TESTID_INFO, $CONTROL_URL);
154 155 156 157 158 159
                        ResponseValidator::valiate_soap_response($nslookup_res_response);
                       }
       case 10         {
                        print "Enter the Test number for GetPingResult : ";
                        my $TESTID_INFO = <>;
                        chomp $TESTID_INFO;
160
                        my $ping_res_response = PingResponse::ping_response($HOSTIP, $HOSTPORT, $TESTID_INFO, $CONTROL_URL);
161 162 163 164 165 166
                        ResponseValidator::valiate_soap_response($ping_res_response);
                       }
       case 11         {
                        print "Enter the Test number for GetTracerouteResult : ";
                        my $TESTID_INFO = <>;
                        chomp $TESTID_INFO;
167
                        my $traceroute_res_response = TracerouteResponse::traceroute_response($HOSTIP, $HOSTPORT, $TESTID_INFO, $CONTROL_URL);
168 169
                        ResponseValidator::valiate_soap_response($traceroute_res_response);
                       }
170 171
       case ('x')      { goto START; }
       else            { goto GET_USER_OPT; }
172
    }
173
    Util::print_diagc_start;
174
}
175

176
1;