HostInfo/IpNetToMediaEntry.pm

filter: Statementstmt 39.4% 15 / 38 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 66.6% 4 / 6 Podpod 0.0% 0 / 1 totaltotal 27.5% 19 / 69 CC 9 SCAR 40.7
CC
9
Cov
26%
AUTOLOAD
90.0
new
2.0
BEGIN
1.0
CRAP 58.3
↑ Summary HostInfo.pm »
1 package Net::SNMP::HostInfo::IpNetToMediaEntry;
2
3 =head1 NAME
4
5 Net::SNMP::HostInfo::IpNetToMediaEntry - An entry in the ipNetToMediaTable of a MIB-II host
6
7 =head1 SYNOPSIS
8
9 use Net::SNMP::HostInfo;
10
11 $host = shift || 'localhost';
12 $hostinfo = Net::SNMP::HostInfo->new(Hostname => $host);
13
14 print "\nNet To Media Table:\n";
15 printf "%-3s %-15s %-17s %s\n",
16 qw/If NetAddress PhysAddress Type/;
17 for $entry ($hostinfo->ipNetToMediaTable) {
18 printf "%-3s %-15s %-17s %s\n",
19 $entry->ipNetToMediaIfIndex,
20 $entry->ipNetToMediaNetAddress,
21 $entry->ipNetToMediaPhysAddress,
22 $entry->ipNetToMediaType;
23 }
24
25 =head1 DESCRIPTION
26
27 "Each entry contains one IpAddress to `physical'
28 address equivalence."
29
30 =cut
31
32 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
35
36 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
37
38 #our $VERSION = '0.01';
39
40 1 our $AUTOLOAD;
41
42 1 my %oids = (
43 ipNetToMediaIfIndex => '1.3.6.1.2.1.4.22.1.1',
44 ipNetToMediaPhysAddress => '1.3.6.1.2.1.4.22.1.2',
45 ipNetToMediaNetAddress => '1.3.6.1.2.1.4.22.1.3',
46 ipNetToMediaType => '1.3.6.1.2.1.4.22.1.4',
47 );
48
49 1 my %decodedObjects = (
50 ipNetToMediaType => { qw/1 other 2 invalid 3 dynamic 4 static/ },
51 );
52
53 # Preloaded methods go here.
54
55 =head1 METHODS
56
57 =over
58
59 =cut
60
61 sub new
62 0 ▶{
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
63 0 my $class = shift;
64
65 0 my %args = @_;
66
67 0 my $self = {};
68
69 0 $self->{_session} = $args{Session};
70 0 $self->{_decode} = $args{Decode};
71 0 $self->{_index} = $args{Index};
72
73 0 bless $self, $class;
74 0 return $self;
75 }
76
77 =item ipNetToMediaIfIndex
78
79 "The interface on which this entry's equivalence
80 is effective. The interface identified by a
81 particular value of this index is the same
82 interface as identified by the same value of
83 ifIndex."
84
85 =item ipNetToMediaPhysAddress
86
87 "The media-dependent `physical' address."
88
89 =item ipNetToMediaNetAddress
90
91 "The IpAddress corresponding to the media-
92 dependent `physical' address."
93
94 =item ipNetToMediaType
95
96 "The type of mapping.
97
98 Setting this object to the value invalid(2) has
99 the effect of invalidating the corresponding entry
100 in the ipNetToMediaTable. That is, it effectively
101 dissasociates the interface identified with said
102 entry from the mapping identified with said entry.
103 It is an implementation-specific matter as to
104 whether the agent removes an invalidated entry
105 from the table. Accordingly, management stations
106 must be prepared to receive tabular information
107 from agents that corresponds to entries not
108 currently in use. Proper interpretation of such
109 entries requires examination of the relevant
110 ipNetToMediaType object."
111
112 Possible values are:
113
114 other(1),
115 invalid(2),
116 dynamic(3),
117 static(4)
118
119 =back
120
121 =cut
122
123 sub AUTOLOAD
124 0 ▶{
Subroutine AUTOLOAD: not called CC=9 SCAR=45.0
125 0 my $self = shift;
126
127
128 0 ▶ return if $AUTOLOAD =~ /DESTROY$/;
Branch: 1 branch
BranchTrueFalseTotal
if $Net::SNMP::HostInfo::IpNetToMediaEntry::AUTOLOAD =~ /DESTROY$/ 0 0 0
129
130 0 my ($name) = $AUTOLOAD =~ /::([^:]+)$/;
131 #print "Called $name\n";
132
133 0 ▶ if (!exists $oids{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $oids{$name}) 0 0 0
134 0 croak "Can't locate object method '$name'";
135 }
136
137 0 my $oid = $oids{$name} . '.' . $self->{_index};
138
139 #print "Trying $oid\n";
140
141 0 my $response = $self->{_session}->get_request($oid);
142
143 0 ▶ if ($response) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response) { } 0 0 0
144 0 my $value = $response->{$oid};
145
146 0 ▶ if ($self->{_decode} &&
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'_decode'} and exists $decodedObjects{$name} and exists $decodedObjects{$name}{$value}) { } 0 0 0
Condition0%0/6
$self->{"_decode"} and exists $decodedObjects{$name} and exists $decodedObjects{$name}{$value}
!ll&&!rl&&r
000
$self->{"_decode"} and exists $decodedObjects{$name}
!ll&&!rl&&r
000
MC/DC0%0/3
$self->{"_decode"} and exists $decodedObjects{$name} and exists $decodedObjects{$name}{$value}
$self->{"_decode"} exists $decodedObjects{$name} exists $decodedObjects{$name}{$value}
Truth table0%0/4
A and B and C
A= $self->{"_decode"}B= exists $decodedObjects{$name}C= exists $decodedObjects{$name}{$value}
ABCresult
0XX0
10X0
1100
1111
147 exists $decodedObjects{$name} &&
148 exists $decodedObjects{$name}{$value}) {
149 0 return $decodedObjects{$name}{$value}."($value)";
150 } else {
151 0 ▶ if ($self->{_decode} && $name eq "ipNetToMediaPhysAddress") {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_decode"} and $name eq "ipNetToMediaPhysAddress") 0 0 0
Condition0%0/3
$self->{"_decode"} and $name eq "ipNetToMediaPhysAddress"
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"_decode"} and $name eq "ipNetToMediaPhysAddress"
$self->{"_decode"} $name eq "ipNetToMediaPhysAddress"
Truth table0%0/3
A and B
A= $self->{"_decode"}B= $name eq "ipNetToMediaPhysAddress"
ABresult
0X0
100
111
152 0 $value =~ s/^0x(\w\w)(\w\w)(\w\w)(\w\w)(\w\w)(\w\w)$/$1-$2-$3-$4-$5-$6/;
153 }
154 0 return $value;
155 }
156 } else {
157 0 return undef;
158 }
159 }
160
161 1 1;
162
163 __END__
↑ Summary HostInfo.pm »