DIAGC.pl 9.99 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
our ($diage_devices, $device_name, $diage_ip, $diage_port, $control_url);
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 50
print "3. List Searched devices \n";
print "4. Exit Application \n";
51
print "\33[1;33mEnter the option number : \33[m";
52 53 54 55
our $SEARCH_OPTS = <>;
chomp $SEARCH_OPTS;

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

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

                        foreach my $device_temp (@$diage_devices) {
65
                            print "----------------------------------------\33[m\n";
66
                            print "\33[1;33m[" . ($device_count + 1) . "] : " . @$device_name[$device_count] . "\33[m\n";
67 68 69
                            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";
70
                            $device_count++;
71
                        }
72

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

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

80 81
                        $HOSTIP = @$diage_ip[$DEVICE_NO - 1];
                        $HOSTPORT = @$diage_port[$DEVICE_NO - 1];
82
                        $CONTROL_URL = @$control_url[$DEVICE_NO - 1];
83 84 85 86
                        Util::print_diagc_start;
                       }
       case 2          {
                        Util::print_diagc_start;
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
                       }
       case 3          { 
                        print "\33[1;33mChoose the corresponding device number to start testing: \33[m\n";
                        my $device_count=0;
                        print "****************************************\n";
                        print "****************************************\n";

                        foreach my $device_temp (@$diage_devices) {
                            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";
                            $device_count++;
                        }

                        print "****************************************\n";
                        print "****************************************\n";

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

                        $HOSTIP = @$diage_ip[$DEVICE_NO - 1];
                        $HOSTPORT = @$diage_port[$DEVICE_NO - 1];
                        $CONTROL_URL = @$control_url[$DEVICE_NO - 1];
                        Util::print_diagc_start;
                       }
       case 4          {
116 117 118 119 120 121
                        exit;
                       }
       else            { exit;}  
       
}

122
while (1) {
123
GET_USER_OPT:
124 125
    $TEST_OPTION = Util::get_user_options;
    if ($SEARCH_OPTS eq '2') {
126
      ($HOSTIP, $HOSTPORT, $CONTROL_URL) = Util::get_manual_device_details;
127
    }
128

129
    switch($TEST_OPTION){
130
       case 1          {
131
                        my $devicestatus_response = DeviceStatusRequest::devicestatus_request($HOSTIP, $HOSTPORT, $CONTROL_URL);
132 133 134 135 136 137
                        ResponseValidator::valiate_soap_response($devicestatus_response);
                       }
       case 2          {
                        print "Enter the Test number for CancelTest : ";
                        my $TESTID = <>;
                        chomp $TESTID;
138
                        my $canceltest_response = CancelTestRequest::canceltest_request($HOSTIP, $HOSTPORT, $TESTID, $CONTROL_URL);
139 140 141
                        ResponseValidator::valiate_soap_response($canceltest_response);
                       }
       case 3          {
142
                        my $activetestids_response = GetActiveTestIDsRequest::activetestids_request($HOSTIP, $HOSTPORT, $CONTROL_URL);
143 144 145 146 147 148
                        ResponseValidator::valiate_soap_response($activetestids_response);
                       }
       case 4          {
                        print "Enter the HostName to perform NSLookup : ";
                        my $HOST_NAME = <>;
                        chomp $HOST_NAME;
149
                        my $nslookup_req_response = NSLookUpRequest::nslookup_request($HOSTIP, $HOSTPORT, $HOST_NAME, $CONTROL_URL);
150 151 152 153 154 155
                        ResponseValidator::valiate_soap_response($nslookup_req_response);
                       }
       case 5          {
                        print "Enter the HostName to perform Ping : ";
                        my $HOST_NAME = <>;
                        chomp $HOST_NAME;
156
                        my $ping_req_response = PingRequest::ping_request($HOSTIP, $HOSTPORT, $HOST_NAME, $CONTROL_URL);
157 158 159 160 161 162
                        ResponseValidator::valiate_soap_response($ping_req_response);
                       }
       case 6          {
                        print "Enter the HostName to perform traceroute : ";
                        my $HOST_NAME = <>;
                        chomp $HOST_NAME;
163
                        my $traceroute_req_request = TracerouteRequest::traceroute_request($HOSTIP, $HOSTPORT, $HOST_NAME, $CONTROL_URL);
164 165 166
                        ResponseValidator::valiate_soap_response($traceroute_req_request);
                       }
       case 7          {
167
                        my $testidsreq_response = TestIDsRequest::testids_request($HOSTIP, $HOSTPORT, $CONTROL_URL);
168 169 170 171 172 173
                        ResponseValidator::valiate_soap_response($testidsreq_response);
                       }
       case 8          {
                        print "Enter the Test number for TestInfo : ";
                        my $TESTID_INFO = <>;
                        chomp $TESTID_INFO;
174
                        my $testinfo_response = TestInfoRequest::testinfo_request($HOSTIP, $HOSTPORT, $TESTID_INFO, $CONTROL_URL);
175 176 177 178 179 180
                        ResponseValidator::valiate_soap_response($testinfo_response);
                       }
       case 9          {
                        print "Enter the Test number for GetNSLookupResult : ";
                        my $TESTID_INFO = <>;
                        chomp $TESTID_INFO;
181
                        my $nslookup_res_response = NSLookUpResponse::nslookup_response($HOSTIP, $HOSTPORT, $TESTID_INFO, $CONTROL_URL);
182 183 184 185 186 187
                        ResponseValidator::valiate_soap_response($nslookup_res_response);
                       }
       case 10         {
                        print "Enter the Test number for GetPingResult : ";
                        my $TESTID_INFO = <>;
                        chomp $TESTID_INFO;
188
                        my $ping_res_response = PingResponse::ping_response($HOSTIP, $HOSTPORT, $TESTID_INFO, $CONTROL_URL);
189 190 191 192 193 194
                        ResponseValidator::valiate_soap_response($ping_res_response);
                       }
       case 11         {
                        print "Enter the Test number for GetTracerouteResult : ";
                        my $TESTID_INFO = <>;
                        chomp $TESTID_INFO;
195
                        my $traceroute_res_response = TracerouteResponse::traceroute_response($HOSTIP, $HOSTPORT, $TESTID_INFO, $CONTROL_URL);
196 197
                        ResponseValidator::valiate_soap_response($traceroute_res_response);
                       }
198 199
       case ('x')      { goto START; }
       else            { goto GET_USER_OPT; }
200
    }
201
    Util::print_diagc_start;
202
}
203

204
1;