DIAGC.pl 7.9 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 45 46 47 48
our ($TEST_OPTION, $HOSTIP, $HOSTPORT) = '';

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

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

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

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

71 72 73 74 75 76
                        print "****************************************\n";
                        print "****************************************\n";

                        print "Choose the device number: ";
                        my $DEVICE_NO = <>;
                        chomp $DEVICE_NO;
77

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

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

99
    switch($TEST_OPTION){
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
       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);
                       }
168 169
       case ('x')      { goto START; }
       else            { goto GET_USER_OPT; }
170
    }
171
    Util::print_diagc_start;
172
}
173

174
1;