lib/Cisco/SNMP/Config.pm

filter: Statementstmt 12.1% 24 / 197 Branchbran 0.0% 0 / 108 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 60.0% 6 / 10 Podpod 100% 3 / 3 totaltotal 9.6% 33 / 343 CC 61 SCAR 71.9
CC
61
Cov
8%
config_copy
1980.0
_config_copy
342.0
ccStartTime
2.0
CRAP 1332.7
↑ Summary lib/Cisco/SNMP/ProxyPing.pm »
1 package Cisco::SNMP::Config;
2  
3 ##################################################
4 # AUTHOR = Michael Vincent
5 # www.VinsWorld.com
6 ##################################################
7  
8 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 ▶use Net::SNMP qw(:asn1);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Cisco::SNMP;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 our $VERSION = $Cisco::SNMP::VERSION;
15  
16 2 our @ISA = qw(Cisco::SNMP);
17  
18 2 ▶use Sys::Hostname;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶use Socket qw(AF_INET);
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 2 my $AF_INET6 = eval { Socket::AF_INET6() };
22  
23 2 my %PROTO = (
24 tftp => 1,
25 ftp => 2,
26 rcp => 3,
27 scp => 4,
28 sftp => 5
29 );
30  
31 ##################################################
32 # Start Public Module
33 ##################################################
34  
35 0 ▶sub config_copy {
Subroutine config_copy: not called CC=44 SCAR=75.9
Pod documented
36 0 my $self = shift;
37 0 ▶ my $class = ref($self) || $self;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
38  
39 0 my $session = $self->{_SESSION_};
40  
41 0 my %params = (
42 op => 'wr',
43 catos => 0,
44 timeout => 10,
45 source => 4,
46 dest => 3,
47 protocol => 'tftp',
48 username => 'cisco',
49 password => 'cisco'
50 );
51  
52 0 my %args;
53 0 ▶ if ( @_ == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) { } 0 0 0
54 0 $Cisco::SNMP::LASTERROR = "Insufficient number of args";
55 0 return undef;
56 } else {
57 0 %args = @_;
58 0 for ( keys(%args) ) {
59 0 ▶ if ( (/^-?(?:tftp)?server$/i) || (/^-?tftp$/) ) {
Branch: 9 branches
BranchTrueFalseTotal
if (/^-?(?:tftp)?server$/i or /^-?tftp$/) { } 0 0 0
elsif (/^-?catos$/i) { } 0 0 0
elsif (/^-?user(?:name)?$/i) { } 0 0 0
elsif (/^-?pass(?:word)?$/i) { } 0 0 0
elsif (/^-?timeout$/i) { } 0 0 0
elsif (/^-?proto(?:col)?$/i) { } 0 0 0
elsif (/^-?family$/i) { } 0 0 0
elsif (/^-?source$/i) { } 0 0 0
elsif (/^-?dest(?:ination)?$/i) { } 0 0 0
Condition0%0/3
/^-?(?:tftp)?server$/i or /^-?tftp$/
l!l&&r!l&&!r
000
MC/DC0%0/2
/^-?(?:tftp)?server$/i or /^-?tftp$/
/^-?(?:tftp)?server$/i /^-?tftp$/
Truth table0%0/3
A or B
A= /^-?(?:tftp)?server$/iB= /^-?tftp$/
ABresult
1X1
011
000
60 0 $params{server} = $args{$_};
61 } elsif (/^-?catos$/i) {
62 0 ▶ if ( $args{$_} == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{$_} == 1) 0 0 0
63 0 $params{catos} = 1;
64 }
65 } elsif (/^-?user(?:name)?$/i) {
66 0 $params{username} = $args{$_};
67 } elsif (/^-?pass(?:word)?$/i) {
68 0 $params{password} = $args{$_};
69 } elsif (/^-?timeout$/i) {
70 0 $params{timeout} = $args{$_};
71 } elsif (/^-?proto(?:col)?$/i) {
72 0 ▶ if ( exists( $PROTO{lc( $args{$_} )} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $PROTO{lc $args{$_}}) { } 0 0 0
73 0 $params{protocol} = lc( $args{$_} );
74 } else {
75 0 $Cisco::SNMP::LASTERROR = "Invalid protocol `$args{$_}'";
76 0 return undef;
77 }
78 } elsif (/^-?family$/i) {
79 0 ▶ if ( $args{$_}
Branch: 1 branch
BranchTrueFalseTotal
if ($args{$_} =~ /^(?:(?:(:?ip)?v?(?:4|6))|${\2;}|$AF_INET6)$/) { } 0 0 0
80 0 =~ /^(?:(?:(:?ip)?v?(?:4|6))|${\AF_INET}|$AF_INET6)$/ ) {
81 0 ▶ if ( $args{$_} =~ /^(?:(?:(:?ip)?v?4)|${\AF_INET})$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{$_} =~ /^(?:(?:(:?ip)?v?4)|${\2;})$/) { } 0 0 0
82 0 $params{family} = AF_INET;
83 } else {
84 0 $params{family} = $AF_INET6;
85 }
86 } else {
87 0 $Cisco::SNMP::LASTERROR = "Invalid family `$args{$_}'";
88 0 return undef;
89 }
90 } elsif (/^-?source$/i) {
91 0 ▶ if ( $args{$_} =~ /^run(?:ning)?(?:-config)?$/i ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args{$_} =~ /^run(?:ning)?(?:-config)?$/i) { } 0 0 0
elsif ($args{$_} =~ /^start(?:up)?(?:-config)?$/i) { } 0 0 0
92 0 $params{source} = 4;
93 } elsif ( $args{$_} =~ /^start(?:up)?(?:-config)?$/i ) {
94 0 $params{source} = 3;
95 } else {
96 0 $params{source} = 1;
97 0 $params{op} = 'put';
98 0 $params{file} = $args{$_};
99 }
100 } elsif (/^-?dest(?:ination)?$/i) {
101 0 ▶ if ( $args{$_} =~ /^run(?:ning)?(?:-config)?$/i ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args{$_} =~ /^run(?:ning)?(?:-config)?$/i) { } 0 0 0
elsif ($args{$_} =~ /^start(?:up)?(?:-config)?$/i) { } 0 0 0
102 0 $params{dest} = 4;
103 } elsif ( $args{$_} =~ /^start(?:up)?(?:-config)?$/i ) {
104 0 $params{dest} = 3;
105 } else {
106 0 $params{dest} = 1;
107 0 $params{op} = 'get';
108 0 $params{file} = $args{$_};
109 }
110 }
111 }
112 }
113 0 my $cc;
114 0 $cc->{_params_} = \%params;
115  
116 0 ▶ if ( $params{source} == $params{dest} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params{"source"} == $params{"dest"}) 0 0 0
117 0 $Cisco::SNMP::LASTERROR = "Source and destination cannot be same";
118 0 return undef;
119 }
120  
121 # server must be defined if put/get
122 0 ▶ if ( ( $params{op} ne 'wr' ) and not defined $params{server} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params{"op"} ne "wr" and not defined $params{"server"}) 0 0 0
Condition0%0/3
$params{"op"} ne "wr" and not defined $params{"server"}
!ll&&!rl&&r
000
MC/DC0%0/2
$params{"op"} ne "wr" and not defined $params{"server"}
$params{"op"} ne "wr" not defined $params{"server"}
Truth table0%0/3
A and not(B)
A= $params{"op"} ne "wr"B= not defined $params{"server"}
ABresult
0X0
100
111
123 0 $params{server} = hostname;
124 }
125  
126 # inherit from new()
127 0 ▶ if ( not defined $params{family} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $params{"family"}) 0 0 0
128 0 $params{family} = $self->{family};
129 }
130  
131 0 ▶ if ( $params{catos} and $params{protocol} ne 'tftp' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params{"catos"} and $params{"protocol"} ne "tftp") 0 0 0
Condition0%0/3
$params{"catos"} and $params{"protocol"} ne "tftp"
!ll&&!rl&&r
000
MC/DC0%0/2
$params{"catos"} and $params{"protocol"} ne "tftp"
$params{"catos"} $params{"protocol"} ne "tftp"
Truth table0%0/3
A and B
A= $params{"catos"}B= $params{"protocol"} ne "tftp"
ABresult
0X0
100
111
132 0 $Cisco::SNMP::LASTERROR = "CatOS only supports tftp";
133 0 return undef;
134 }
135  
136 # resolve server our way
137 0 ▶ if ( defined $params{server} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params{"server"}) 0 0 0
138 0 ▶ if (defined(
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $ret = Cisco::SNMP::_resolv($params{'server'}, $params{'family'}))) { } 0 0 0
139 my $ret
140 = Cisco::SNMP::_resolv( $params{server}, $params{family} )
141 )
142 ) {
143 0 $params{server} = $ret->{addr};
144 0 $params{family} = $ret->{family};
145 } else {
146 0 return undef;
147 }
148 0 ▶ if ( $params{catos} and $params{family} == $AF_INET6 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params{"catos"} and $params{"family"} == $AF_INET6) 0 0 0
Condition0%0/3
$params{"catos"} and $params{"family"} == $AF_INET6
!ll&&!rl&&r
000
MC/DC0%0/2
$params{"catos"} and $params{"family"} == $AF_INET6
$params{"catos"} $params{"family"} == $AF_INET6
Truth table0%0/3
A and B
A= $params{"catos"}B= $params{"family"} == $AF_INET6
ABresult
0X0
100
111
149 0 $Cisco::SNMP::LASTERROR = "CatOS does not support IPv6";
150 0 return undef;
151 }
152 }
153  
154 0 my $response;
155 0 my $instance = int( rand(1024) + 1024 );
156 0 my %ioserr = (
157 1 => "Unknown",
158 2 => "Bad file name",
159 3 => "Timeout",
160 4 => "No memory",
161 5 => "No config",
162 6 => "Unsupported protocol",
163 7 => "Config apply fail",
164 8 => "System not ready",
165 9 => "Request abort"
166 );
167  
168 # wr mem
169 0 ▶ if ( $params{op} eq 'wr' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params{'op'} eq 'wr') { } 0 0 0
170 0 ▶ if ( $params{catos} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params{"catos"}) 0 0 0
171 0 $Cisco::SNMP::LASTERROR
172 = "CatOS does not support `copy run start'";
173 0 return undef;
174 }
175  
176 # ccCopyEntryRowStatus (5 = createAndWait, 6 = destroy)
177 $response
178 0 = $session->set_request(
179 '1.3.6.1.4.1.9.9.96.1.1.1.1.14.' . $instance,
180 INTEGER, 6 );
181  
182 0 ▶ if ( not defined $response ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $response) 0 0 0
183  
184 # copy run start NOT SUPPORTED - trying old way
185 0 $response
186 = $session->set_request( '1.3.6.1.4.1.9.2.1.54.0', INTEGER, 1 );
187 0 ▶ if ( defined $response ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $response) { } 0 0 0
188 0 return bless $cc, $class;
189 } else {
190 0 $Cisco::SNMP::LASTERROR
191 = "`copy run start' FAILED (new and old)";
192 0 return undef;
193 }
194 }
195  
196 # ccCopySourceFileType (1 = networkFile, 3 = startupConfig, 4 = runningConfig)
197 $response
198 = $session->set_request(
199 '1.3.6.1.4.1.9.9.96.1.1.1.1.3.' . $instance,
200 0 INTEGER, $params{source} );
201  
202 # ccCopyDestFileType (1 = networkFile, 3 = startupConfig, 4 = runningConfig)
203 $response
204 = $session->set_request(
205 '1.3.6.1.4.1.9.9.96.1.1.1.1.4.' . $instance,
206 INTEGER, $params{dest} )
207  
208 # TFTP PUT/GET (to/from device)
209 0 } else {
210 0 $response = _config_copy( \%params, $session, $instance );
211 0 ▶ if ( $response == 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($response == 0) { } 0 0 0
elsif ($response == -1) { } 0 0 0
212 0 return bless $cc, $class;
213 } elsif ( $response == -1 ) {
214 0 return undef;
215 }
216  
217 # $response == 1, continue ...
218 }
219  
220 # ccCopyEntryRowStatus (4 = createAndGo, 6 = destroy)
221 0 $response
222 = $session->set_request( '1.3.6.1.4.1.9.9.96.1.1.1.1.14.' . $instance,
223 INTEGER, 1 );
224  
225 # Check status, wait done
226 0 $response
227 = $session->get_request( '1.3.6.1.4.1.9.9.96.1.1.1.1.10.' . $instance );
228 0 ▶ if ( not defined $response ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $response) 0 0 0
229 0 $Cisco::SNMP::LASTERROR
230 = "$params{protocol} NOT SUPPORTED (after setup)";
231 0 return undef;
232 }
233  
234 # loop and check response - error if timeout
235 0 my $loop = 0;
236 0 ▶ while ( $response->{'1.3.6.1.4.1.9.9.96.1.1.1.1.10.' . $instance} <= 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$response{'1.3.6.1.4.1.9.9.96.1.1.1.1.10.' . $instance} <= 2) 0 0 0
237 0 $response = $session->get_request(
238 '1.3.6.1.4.1.9.9.96.1.1.1.1.10.' . $instance );
239 0 ▶ if ( not defined $response ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $response) 0 0 0
240 0 $Cisco::SNMP::LASTERROR
241 = "IOS $params{protocol} `$params{op}' FAILED - cannot verify completion";
242 0 return undef;
243 }
244 0 ▶ if ( $loop++ == $params{timeout} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($loop++ == $params{"timeout"}) 0 0 0
245 0 $Cisco::SNMP::LASTERROR
246 = "IOS $params{protocol} `$params{op}' FAILED - timeout during completion verification";
247 0 return undef;
248 }
249 0 sleep 1;
250 }
251  
252 # Success
253 0 ▶ if ( $response->{'1.3.6.1.4.1.9.9.96.1.1.1.1.10.' . $instance} == 3 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($$response{'1.3.6.1.4.1.9.9.96.1.1.1.1.10.' . $instance} == 3) { } 0 0 0
elsif ($$response{'1.3.6.1.4.1.9.9.96.1.1.1.1.10.' . $instance} == 4) { } 0 0 0
254 0 $response = $session->get_request(
255 '1.3.6.1.4.1.9.9.96.1.1.1.1.11.' . $instance );
256 $cc->{StartTime}
257 0 = $response->{'1.3.6.1.4.1.9.9.96.1.1.1.1.11.' . $instance};
258 0 $response = $session->get_request(
259 '1.3.6.1.4.1.9.9.96.1.1.1.1.12.' . $instance );
260 $cc->{EndTime}
261 0 = $response->{'1.3.6.1.4.1.9.9.96.1.1.1.1.12.' . $instance};
262 0 $session->set_request( '1.3.6.1.4.1.9.9.96.1.1.1.1.14.' . $instance,
263 INTEGER, 6 );
264 0 return bless $cc, $class
265  
266 # Error
267 } elsif ( $response->{'1.3.6.1.4.1.9.9.96.1.1.1.1.10.' . $instance} == 4 )
268 {
269 0 $response = $session->get_request(
270 '1.3.6.1.4.1.9.9.96.1.1.1.1.13.' . $instance );
271 0 $session->set_request( '1.3.6.1.4.1.9.9.96.1.1.1.1.14.' . $instance,
272 INTEGER, 6 );
273 $Cisco::SNMP::LASTERROR
274 = "IOS $params{protocol} `$params{op}' FAILED - "
275 0 . $ioserr{$response->{'1.3.6.1.4.1.9.9.96.1.1.1.1.13.' . $instance}
276 };
277 0 return undef;
278 } else {
279 0 $Cisco::SNMP::LASTERROR = "Cannot determine success or failure";
280 0 return undef;
281 }
282 }
283  
284 0 ▶sub ccStartTime {
Subroutine ccStartTime: not called CC=1 SCAR=6.9
Pod documented
285 0 my $self = shift;
286 0 return $self->{StartTime};
287 }
288  
289 0 ▶sub ccEndTime {
Subroutine ccEndTime: not called CC=1 SCAR=6.9
Pod documented
290 0 my $self = shift;
291 0 return $self->{EndTime};
292 }
293  
294 ##################################################
295 # End Public Module
296 ##################################################
297  
298 ##################################################
299 # Start Private subs
300 ##################################################
301  
302 # Return:
303 # -1 = error
304 # 0 = DONE
305 # 1 = continue
306 0 ▶sub _config_copy {
Subroutine _config_copy: not called CC=18 SCAR=58.3
307  
308 0 my ( $params, $session, $instance ) = @_;
309  
310 0 my $response;
311 0 my %caterr = (
312 1 => "In Progress",
313 2 => "Success",
314 3 => "No Response",
315 4 => "Too Many Retries",
316 5 => "No Buffers",
317 6 => "No Processes",
318 7 => "Bad Checksum",
319 8 => "Bad Length",
320 9 => "Bad Flash",
321 10 => "Server Error",
322 11 => "User Cancelled",
323 12 => "Wrong Code",
324 13 => "File Not Found",
325 14 => "Invalid TFTP Host",
326 15 => "Invalid TFTP Module",
327 16 => "Access Violation",
328 17 => "Unknown Status",
329 18 => "Invalid Storage Device",
330 19 => "Insufficient Space On Storage Device",
331 20 => "Insufficient Dram Size",
332 21 => "Incompatible Image"
333 );
334  
335 0 ▶ if ( $params->{catos} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{'catos'}) { } 0 0 0
336 $response
337 = $session->set_request( '1.3.6.1.4.1.9.5.1.5.1.0', OCTET_STRING,
338 0 $params->{server} );
339 $response
340 = $session->set_request( '1.3.6.1.4.1.9.5.1.5.2.0', OCTET_STRING,
341 0 $params->{file} );
342 0 $response
343 = $session->set_request( '1.3.6.1.4.1.9.5.1.5.3.0', INTEGER, 1 );
344 0 ▶ if ( $params->{op} eq 'put' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{'op'} eq 'put') { } 0 0 0
345 0 $response
346 = $session->set_request( '1.3.6.1.4.1.9.5.1.5.4.0', INTEGER,
347 2 );
348 } else {
349 0 $response
350 = $session->set_request( '1.3.6.1.4.1.9.5.1.5.4.0', INTEGER,
351 3 );
352 }
353  
354 # loop and check response - error if timeout
355 0 ▶ if (defined(
Branch: 1 branch
BranchTrueFalseTotal
if (defined($response = $session->get_request('1.3.6.1.4.1.9.5.1.5.5.0'))) { } 0 0 0
356 $response = $session->get_request('1.3.6.1.4.1.9.5.1.5.5.0')
357 )
358 ) {
359 0 my $loop = 0;
360 0 ▶ while ( $response->{'1.3.6.1.4.1.9.5.1.5.5.0'} == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->{"1.3.6.1.4.1.9.5.1.5.5.0"} == 1) 0 0 0
361 0 $response = $session->get_request('1.3.6.1.4.1.9.5.1.5.5.0');
362 0 ▶ if ( $loop++ == $params->{timeout} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($loop++ == $params->{"timeout"}) 0 0 0
363 0 $Cisco::SNMP::LASTERROR
364 = "CatOS TFTP `$params->{op}' FAILED - timeout during completion verification";
365 0 return -1;
366 }
367 0 sleep 1;
368 }
369 } else {
370 0 $Cisco::SNMP::LASTERROR
371 = "CatOS TFTP `$params->{op}' FAILED - can't get initial response";
372 0 return -1;
373 }
374  
375 0 ▶ if ( $response->{'1.3.6.1.4.1.9.5.1.5.5.0'} == 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->{'1.3.6.1.4.1.9.5.1.5.5.0'} == 2) { } 0 0 0
376 0 return 0;
377 } else {
378 $Cisco::SNMP::LASTERROR = "CatOS TFTP `$params->{op}' FAILED - "
379 0 . $caterr{$response->{'1.3.6.1.4.1.9.5.1.5.5.0'}};
380 0 return -1;
381 }
382  
383 # IOS
384 } else {
385  
386 # ccCopyEntryRowStatus (5 = createAndWait, 6 = destroy)
387 0 $response
388 = $session->set_request(
389 '1.3.6.1.4.1.9.9.96.1.1.1.1.14.' . $instance,
390 INTEGER, 6 );
391 0 $response
392 = $session->set_request(
393 '1.3.6.1.4.1.9.9.96.1.1.1.1.14.' . $instance,
394 INTEGER, 5 );
395  
396 # ccCopyProtocol
397 $response
398 = $session->set_request(
399 '1.3.6.1.4.1.9.9.96.1.1.1.1.2.' . $instance,
400 0 INTEGER, $PROTO{$params->{protocol}} );
401  
402 0 ▶ if ( not defined $response ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $response) 0 0 0
403 0 $Cisco::SNMP::LASTERROR
404 = "IOS TFTP `$params->{op}' NOT SUPPORTED - trying old way";
405 0 ▶ if ( $params->{protocol} ne 'tftp' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{"protocol"} ne "tftp") 0 0 0
406 0 $Cisco::SNMP::LASTERROR
407 = "Old way does not support `$params->{protocol}'";
408 0 return -1;
409 }
410 0 ▶ if ( $params->{family} == $AF_INET6 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{"family"} == $AF_INET6) 0 0 0
411 0 $Cisco::SNMP::LASTERROR
412 = "IOS TFTP `$params->{op}' old way does not support IPv6";
413 0 return -1;
414 }
415 0 ▶ if ( $params->{op} eq 'put' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{'op'} eq 'put') { } 0 0 0
416 $response
417 = $session->set_request(
418 '1.3.6.1.4.1.9.2.1.50.' . $params->{server},
419 0 OCTET_STRING, $params->{file} );
420 } else {
421 $response
422 = $session->set_request(
423 '1.3.6.1.4.1.9.2.1.55.' . $params->{server},
424 0 OCTET_STRING, $params->{file} );
425 }
426 0 ▶ if ( defined $response ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $response) { } 0 0 0
427 0 return 0;
428 } else {
429 0 $Cisco::SNMP::LASTERROR
430 = "IOS TFTP `$params->{op}' FAILED (new and old)";
431 0 return -1;
432 }
433 }
434  
435 0 ▶ if ( $params->{protocol} ne 'tftp' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{"protocol"} ne "tftp") 0 0 0
436 $response
437 = $session->set_request(
438 '1.3.6.1.4.1.9.9.96.1.1.1.1.7.' . $instance,
439 0 OCTET_STRING, $params->{username} );
440 0 ▶ if ( $params->{protocol} ne 'rcp' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{"protocol"} ne "rcp") 0 0 0
441 $response
442 = $session->set_request(
443 '1.3.6.1.4.1.9.9.96.1.1.1.1.8.' . $instance,
444 0 OCTET_STRING, $params->{password} );
445 }
446 }
447  
448 # ccCopySourceFileType [.3] (1 = networkFile, 3 = startupConfig, 4 = runningConfig)
449 # ccCopyDestFileType [.4] (1 = networkFile, 3 = startupConfig, 4 = runningConfig)
450 0 ▶ if ( $params->{op} eq 'put' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{'op'} eq 'put') { } 0 0 0
451 0 $response
452 = $session->set_request(
453 '1.3.6.1.4.1.9.9.96.1.1.1.1.3.' . $instance,
454 INTEGER, 1 );
455 $response
456 = $session->set_request(
457 '1.3.6.1.4.1.9.9.96.1.1.1.1.4.' . $instance,
458 0 INTEGER, $params->{dest} );
459 } else {
460 $response
461 = $session->set_request(
462 '1.3.6.1.4.1.9.9.96.1.1.1.1.3.' . $instance,
463 0 INTEGER, $params->{source} );
464 0 $response
465 = $session->set_request(
466 '1.3.6.1.4.1.9.9.96.1.1.1.1.4.' . $instance,
467 INTEGER, 1 );
468 }
469  
470 # New way
471 # ccCopyServerAddressType (1 = IPv4, 2 = IPv6)
472 $response
473 = $session->set_request(
474 '1.3.6.1.4.1.9.9.96.1.1.1.1.15.' . $instance,
475 0 ▶ INTEGER, ( $params->{family} == AF_INET ) ? 1 : 2 );
Branch: 1 branch
BranchTrueFalseTotal
$params->{'family'} == 2 ? : 0 0 0
476  
477 0 ▶ if ( defined $response ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $response) { } 0 0 0
478  
479 # ccCopyServerAddressRev1
480 $response
481 = $session->set_request(
482 '1.3.6.1.4.1.9.9.96.1.1.1.1.16.' . $instance,
483 0 OCTET_STRING, $params->{server} );
484 } else {
485  
486 # Deprecated
487 # ccCopyServerAddress
488 0 ▶ if ( $params->{family} == $AF_INET6 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{"family"} == $AF_INET6) 0 0 0
489 0 $Cisco::SNMP::LASTERROR
490 = "ccCopyServerAddressRev1 not supported (requried for IPv6)";
491 0 return -1;
492 }
493 $response
494 = $session->set_request(
495 '1.3.6.1.4.1.9.9.96.1.1.1.1.5.' . $instance,
496 0 IPADDRESS, $params->{server} );
497 }
498  
499 # ccCopyFileName
500 $response
501 = $session->set_request(
502 '1.3.6.1.4.1.9.9.96.1.1.1.1.6.' . $instance,
503 0 OCTET_STRING, $params->{file} );
504 }
505 0 return 1;
506 }
507  
508 ##################################################
509 # End Private subs
510 ##################################################
511  
512 2 1;
513  
514 __END__
↑ Summary lib/Cisco/SNMP/ProxyPing.pm »