ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Net-SNMP-XS/XS.pm
Revision: 1.8
Committed: Sat Apr 11 06:24:18 2009 UTC (15 years, 2 months ago) by root
Branch: MAIN
Changes since 1.7: +73 -26 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.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, there are no public symbols
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 root 1.5 This currently reduces decode time by a factor of ten for typical bulk
19 root 1.3 responses.
20 root 1.1
21     There are currently the following limitations when using this module:
22    
23     =over 4
24    
25 root 1.6 =item overriding internal functions might cause the module to
26     malfunction with future versions of Net::SNMP
27    
28 root 1.4 =item only leading dots for oids are supported
29 root 1.1
30 root 1.3 =item error messages will be simpler/different
31    
32 root 1.1 =item translation will be ignored (all values will be delivered "raw")
33    
34 root 1.2 =item a moderately modern (>= C99) C compiler is required
35    
36 root 1.7 =item only tested with 5.10, no intentions to port to older perls
37 root 1.2
38 root 1.5 =item duplicate OIDs are not supported
39    
40     =item REPORT PDUs are not supported
41    
42 root 1.1 =back
43    
44     =cut
45    
46     package Net::SNMP::XS;
47    
48     use strict qw(vars subs);
49     no warnings;
50    
51     use Guard;
52    
53 root 1.8 use Net::SNMP ();
54 root 1.1 use Net::SNMP::PDU ();
55     use Net::SNMP::Message ();
56     use Net::SNMP::MessageProcessing ();
57    
58     our $VERSION;
59     our $old_prepare;
60    
61     BEGIN {
62 root 1.7 $VERSION = '0.02';
63 root 1.1
64     $old_prepare = \&Net::SNMP::MessageProcessing::prepare_data_elements;
65    
66     # this overrides many methods inside
67     require XSLoader;
68     XSLoader::load Net::SNMP::XS, $VERSION;
69     }
70    
71     sub Net::SNMP::MessageProcessing::prepare_data_elements {
72     my ($self, $msg) = @_;
73    
74     set_msg $msg, $msg->{_buffer};
75     scope_guard \&clr_msg;
76     &$old_prepare
77     }
78    
79 root 1.8 package Net::SNMP::Message;
80    
81     Net::SNMP::XS::set_type INTEGER , \&_process_integer32;
82     Net::SNMP::XS::set_type OCTET_STRING , \&_process_octet_string;
83     Net::SNMP::XS::set_type NULL , \&_process_null;
84     Net::SNMP::XS::set_type OBJECT_IDENTIFIER, \&_process_object_identifier;
85     Net::SNMP::XS::set_type SEQUENCE , \&_process_sequence;
86     Net::SNMP::XS::set_type IPADDRESS , \&_process_ipaddress;
87     Net::SNMP::XS::set_type COUNTER , \&_process_counter;
88     Net::SNMP::XS::set_type GAUGE , \&_process_gauge;
89     Net::SNMP::XS::set_type TIMETICKS , \&_process_timeticks;
90     Net::SNMP::XS::set_type OPAQUE , \&_process_opaque;
91     Net::SNMP::XS::set_type COUNTER64 , \&_process_counter64;
92     Net::SNMP::XS::set_type NOSUCHOBJECT , \&_process_nosuchobject;
93     Net::SNMP::XS::set_type NOSUCHINSTANCE , \&_process_nosuchinstance;
94     Net::SNMP::XS::set_type ENDOFMIBVIEW , \&_process_endofmibview;
95     Net::SNMP::XS::set_type GET_REQUEST , \&_process_get_request;
96     Net::SNMP::XS::set_type GET_NEXT_REQUEST , \&_process_get_next_request;
97     Net::SNMP::XS::set_type GET_RESPONSE , \&_process_get_response;
98     Net::SNMP::XS::set_type SET_REQUEST , \&_process_set_request;
99     Net::SNMP::XS::set_type TRAP , \&_process_trap;
100     Net::SNMP::XS::set_type GET_BULK_REQUEST , \&_process_get_bulk_request;
101     Net::SNMP::XS::set_type INFORM_REQUEST , \&_process_inform_request;
102     Net::SNMP::XS::set_type SNMPV2_TRAP , \&_process_v2_trap;
103     Net::SNMP::XS::set_type REPORT , \&_process_report;
104    
105     package Net::SNMP::PDU;
106    
107     # var_bind_list hardcodes oid_lext_sort. *sigh*
108     # we copy it 1:1, except for using oid_lex_sort.
109    
110     sub var_bind_list
111 root 1.1 {
112 root 1.8 my ($this, $vbl, $types) = @_;
113    
114     return if defined($this->{_error});
115    
116     if (@_ > 1) {
117     # The VarBindList HASH is being updated from an external
118     # source. We need to update the VarBind names ARRAY to
119     # correspond to the new keys of the HASH. If the updated
120     # information is valid, we will use lexicographical ordering
121     # for the ARRAY entries since we do not have a PDU to use
122     # to determine the ordering. The ASN.1 types HASH is also
123     # updated here if a cooresponding HASH is passed. We double
124     # check the mapping by populating the hash with the keys of
125     # the VarBindList HASH.
126    
127     if (!defined($vbl) || (ref($vbl) ne 'HASH')) {
128    
129     $this->{_var_bind_list} = undef;
130     $this->{_var_bind_names} = [];
131     $this->{_var_bind_types} = undef;
132    
133     } else {
134    
135     $this->{_var_bind_list} = $vbl;
136    
137     @{$this->{_var_bind_names}} = Net::SNMP::oid_lex_sort keys %$vbl;
138    
139     if (!defined($types) || (ref($types) ne 'HASH')) {
140     $types = {};
141     }
142    
143     map {
144     $this->{_var_bind_types}->{$_} =
145     exists($types->{$_}) ? $types->{$_} : undef;
146     } keys(%{$vbl});
147    
148     }
149    
150     }
151 root 1.1
152 root 1.8 $this->{_var_bind_list};
153 root 1.1 }
154    
155     1;
156    
157     =head1 AUTHOR
158    
159     Marc Lehmann <schmorp@schmorp.de>
160     http://home.schmorp.de/
161    
162     =cut
163