blib/lib/Net/SNMP/XS.pm

filter: Statementstmt 74.1% 46 / 62 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 87.5% 7 / 8 Podpod 0.0% 0 / 1 totaltotal 58.2% 53 / 91 CC 8 SCAR 36.6
CC
8
Cov
59%
var_bind_list
72.0
BEGIN
1.0
BEGIN
1.0
CRAP 38.9
↑ Summary XS.xs »
1 =head1 NAME
2  
3 Net::SNMP::XS - speed up Net::SNMP by decoding in XS, with limitations
4  
5 =head1 SYNOPSIS
6  
7 use Net::SNMP::XS;
8  
9 # loading it is enough to speed up Net::SNMP
10  
11 =head1 DESCRIPTION
12  
13 This module tries to speed up Net::SNMP response packet decoding.
14  
15 It does this by overriding a few selected internal method by (almost)
16 equivalent XS methods.
17  
18 This currently reduces decode time by a factor of ten for typical bulk
19 responses.
20  
21 There are currently the following limitations when using this module:
22  
23 =over 4
24  
25 =item overriding internal functions might cause the module to
26 malfunction with future versions of Net::SNMP
27  
28 =item error messages will be simpler/different
29  
30 =item translation will be ignored (all values will be delivered "raw")
31  
32 =item a moderately modern (>= C99) C compiler is required
33  
34 =item only tested with 5.10, no intentions to port to older perls
35  
36 =item duplicate OIDs are not supported
37  
38 =item REPORT PDUs are not supported
39  
40 =back
41  
42 =cut
43  
44 package Net::SNMP::XS;
45  
46 1 ▶use common::sense;
Subroutine BEGIN: called CC=1 SCAR=0.0
47  
48 1 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
49  
50 1 ▶use Net::SNMP ();
Subroutine BEGIN: called CC=1 SCAR=0.0
51 1 ▶use Net::SNMP::PDU ();
Subroutine BEGIN: called CC=1 SCAR=0.0
52 1 ▶use Net::SNMP::Message ();
Subroutine BEGIN: called CC=1 SCAR=0.0
53 1 ▶use Net::SNMP::MessageProcessing ();
Subroutine BEGIN: called CC=1 SCAR=0.0
54  
55 1 our $VERSION;
56  
57 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
58 1 $VERSION = 1.34;
59  
60 # this overrides many methods inside Net::SNMP and it's submodules
61 1 require XSLoader;
62 1 XSLoader::load Net::SNMP::XS, $VERSION;
63 }
64  
65 package Net::SNMP::Message;
66  
67 1 Net::SNMP::XS::set_type INTEGER , \&_process_integer32;
68 1 Net::SNMP::XS::set_type OCTET_STRING , \&_process_octet_string;
69 1 Net::SNMP::XS::set_type NULL , \&_process_null;
70 1 Net::SNMP::XS::set_type OBJECT_IDENTIFIER, \&_process_object_identifier;
71 1 Net::SNMP::XS::set_type SEQUENCE , \&_process_sequence;
72 1 Net::SNMP::XS::set_type IPADDRESS , \&_process_ipaddress;
73 1 Net::SNMP::XS::set_type COUNTER , \&_process_counter;
74 1 Net::SNMP::XS::set_type GAUGE , \&_process_gauge;
75 1 Net::SNMP::XS::set_type TIMETICKS , \&_process_timeticks;
76 1 Net::SNMP::XS::set_type OPAQUE , \&_process_opaque;
77 1 Net::SNMP::XS::set_type COUNTER64 , \&_process_counter64;
78 1 Net::SNMP::XS::set_type NOSUCHOBJECT , \&_process_nosuchobject;
79 1 Net::SNMP::XS::set_type NOSUCHINSTANCE , \&_process_nosuchinstance;
80 1 Net::SNMP::XS::set_type ENDOFMIBVIEW , \&_process_endofmibview;
81 1 Net::SNMP::XS::set_type GET_REQUEST , \&_process_get_request;
82 1 Net::SNMP::XS::set_type GET_NEXT_REQUEST , \&_process_get_next_request;
83 1 Net::SNMP::XS::set_type GET_RESPONSE , \&_process_get_response;
84 1 Net::SNMP::XS::set_type SET_REQUEST , \&_process_set_request;
85 1 Net::SNMP::XS::set_type TRAP , \&_process_trap;
86 1 Net::SNMP::XS::set_type GET_BULK_REQUEST , \&_process_get_bulk_request;
87 1 Net::SNMP::XS::set_type INFORM_REQUEST , \&_process_inform_request;
88 1 Net::SNMP::XS::set_type SNMPV2_TRAP , \&_process_v2_trap;
89 1 Net::SNMP::XS::set_type REPORT , \&_process_report;
90  
91 package Net::SNMP::PDU;
92  
93 # var_bind_list hardcodes oid_lex_sort. *sigh*
94 # we copy it 1:1, except for using oid_lex_sort.
95  
96 sub var_bind_list
97 0 ▶{
Subroutine var_bind_list: not called CC=8 SCAR=42.8
Pod undocumented
98 0 my ($this, $vbl, $types) = @_;
99  
100 0 ▶ return if defined($this->{_error});
Branch: 1 branch
BranchTrueFalseTotal
if defined $this->{"_error"} 0 0 0
101  
102 0 ▶ if (@_ > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 0 0 0
103 # The VarBindList HASH is being updated from an external
104 # source. We need to update the VarBind names ARRAY to
105 # correspond to the new keys of the HASH. If the updated
106 # information is valid, we will use lexicographical ordering
107 # for the ARRAY entries since we do not have a PDU to use
108 # to determine the ordering. The ASN.1 types HASH is also
109 # updated here if a cooresponding HASH is passed. We double
110 # check the mapping by populating the hash with the keys of
111 # the VarBindList HASH.
112  
113 0 ▶ if (!defined($vbl) || (ref($vbl) ne 'HASH')) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $vbl or ref $vbl ne 'HASH') { } 0 0 0
Condition0%0/3
not defined $vbl or ref $vbl ne "HASH"
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $vbl or ref $vbl ne "HASH"
not defined $vbl ref $vbl ne "HASH"
Truth table0%0/3
not(A) or B
A= not defined $vblB= ref $vbl ne "HASH"
ABresult
1X1
011
000
114  
115 0 $this->{_var_bind_list} = undef;
116 0 $this->{_var_bind_names} = [];
117 0 $this->{_var_bind_types} = undef;
118  
119 } else {
120  
121 0 $this->{_var_bind_list} = $vbl;
122  
123 0 @{$this->{_var_bind_names}} = Net::SNMP::oid_lex_sort keys %$vbl;
124  
125 0 ▶ if (!defined($types) || (ref($types) ne 'HASH')) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $types or ref $types ne "HASH") 0 0 0
Condition0%0/3
not defined $types or ref $types ne "HASH"
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $types or ref $types ne "HASH"
not defined $types ref $types ne "HASH"
Truth table0%0/3
not(A) or B
A= not defined $typesB= ref $types ne "HASH"
ABresult
1X1
011
000
126 0 $types = {};
127 }
128  
129 map {
130 $this->{_var_bind_types}->{$_} =
131 0 ▶ exists($types->{$_}) ? $types->{$_} : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $types->{$_} ? : 0 0 0
132 0 } keys(%{$vbl});
133  
134 }
135  
136 }
137  
138 0 $this->{_var_bind_list};
139 }
140  
141 1 1;
142  
143 =head1 AUTHOR
144  
145 Marc Lehmann <schmorp@schmorp.de>
146 http://home.schmorp.de/
147  
148 =cut
149  
↑ Summary XS.xs »