ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Net-SNMP-XS/XS.pm
(Generate patch)

Comparing Net-SNMP-XS/XS.pm (file contents):
Revision 1.2 by root, Wed Apr 8 10:39:32 2009 UTC vs.
Revision 1.5 by root, Thu Apr 9 05:56:36 2009 UTC

13This module tries to speed up Net::SNMP response packet decoding. 13This module tries to speed up Net::SNMP response packet decoding.
14 14
15It does this by overriding a few selected internal method by (almost) 15It does this by overriding a few selected internal method by (almost)
16equivalent XS methods. 16equivalent XS methods.
17 17
18This currently reduces decode time by some 70%. 18This currently reduces decode time by a factor of ten for typical bulk
19responses.
19 20
20There are currently the following limitations when using this module: 21There are currently the following limitations when using this module:
21 22
22=over 4 23=over 4
23 24
24=item leading dots are required for iods 25=item only leading dots for oids are supported
25 26
26=item error handling is currently broken (but parse errors will be detected) 27=item error handling is currently broken (but parse errors will be detected)
28
29=item error messages will be simpler/different
27 30
28=item oid components are limited to unsigned 32 bit integers 31=item oid components are limited to unsigned 32 bit integers
29 32
30=item translation will be ignored (all values will be delivered "raw") 33=item translation will be ignored (all values will be delivered "raw")
31 34
32=item a 64 bit perl is required 35=item a 64 bit perl is required
33 36
34=item a moderately modern (>= C99) C compiler is required 37=item a moderately modern (>= C99) C compiler is required
35 38
36=item only tested with 5.10 39=item only tested with 5.10
40
41=item duplicate OIDs are not supported
42
43=item REPORT PDUs are not supported
37 44
38=back 45=back
39 46
40=cut 47=cut
41 48
69 set_msg $msg, $msg->{_buffer}; 76 set_msg $msg, $msg->{_buffer};
70 scope_guard \&clr_msg; 77 scope_guard \&clr_msg;
71 &$old_prepare 78 &$old_prepare
72} 79}
73 80
74# almost direct copy from Net::SNMP::Message, as we cannot access $process_methods
75{ 81{
76 package Net::SNMP::Message; 82 package Net::SNMP::Message;
77 83
78 my @process_methods; 84 Net::SNMP::XS::set_type INTEGER , \&_process_integer32;
79 85 Net::SNMP::XS::set_type OCTET_STRING , \&_process_octet_string;
80 $process_methods [INTEGER ] = \&_process_integer32; 86 Net::SNMP::XS::set_type NULL , \&_process_null;
81 $process_methods [OCTET_STRING ] = \&_process_octet_string; 87 Net::SNMP::XS::set_type OBJECT_IDENTIFIER, \&_process_object_identifier;
82 $process_methods [NULL ] = \&_process_null; 88 Net::SNMP::XS::set_type SEQUENCE , \&_process_sequence;
83 $process_methods [OBJECT_IDENTIFIER] = \&_process_object_identifier; 89 Net::SNMP::XS::set_type IPADDRESS , \&_process_ipaddress;
84 $process_methods [SEQUENCE ] = \&_process_sequence; 90 Net::SNMP::XS::set_type COUNTER , \&_process_counter;
85 $process_methods [IPADDRESS ] = \&_process_ipaddress; 91 Net::SNMP::XS::set_type GAUGE , \&_process_gauge;
86 $process_methods [COUNTER ] = \&_process_counter; 92 Net::SNMP::XS::set_type TIMETICKS , \&_process_timeticks;
87 $process_methods [GAUGE ] = \&_process_gauge; 93 Net::SNMP::XS::set_type OPAQUE , \&_process_opaque;
88 $process_methods [TIMETICKS ] = \&_process_timeticks; 94 Net::SNMP::XS::set_type COUNTER64 , \&_process_counter64;
89 $process_methods [OPAQUE ] = \&_process_opaque; 95 Net::SNMP::XS::set_type NOSUCHOBJECT , \&_process_nosuchobject;
90 $process_methods [COUNTER64 ] = \&_process_counter64; 96 Net::SNMP::XS::set_type NOSUCHINSTANCE , \&_process_nosuchinstance;
91 $process_methods [NOSUCHOBJECT ] = \&_process_nosuchobject; 97 Net::SNMP::XS::set_type ENDOFMIBVIEW , \&_process_endofmibview;
92 $process_methods [NOSUCHINSTANCE ] = \&_process_nosuchinstance; 98 Net::SNMP::XS::set_type GET_REQUEST , \&_process_get_request;
93 $process_methods [ENDOFMIBVIEW ] = \&_process_endofmibview; 99 Net::SNMP::XS::set_type GET_NEXT_REQUEST , \&_process_get_next_request;
94 $process_methods [GET_REQUEST ] = \&_process_get_request; 100 Net::SNMP::XS::set_type GET_RESPONSE , \&_process_get_response;
95 $process_methods [GET_NEXT_REQUEST ] = \&_process_get_next_request; 101 Net::SNMP::XS::set_type SET_REQUEST , \&_process_set_request;
96 $process_methods [GET_RESPONSE ] = \&_process_get_response; 102 Net::SNMP::XS::set_type TRAP , \&_process_trap;
97 $process_methods [SET_REQUEST ] = \&_process_set_request; 103 Net::SNMP::XS::set_type GET_BULK_REQUEST , \&_process_get_bulk_request;
98 $process_methods [TRAP ] = \&_process_trap; 104 Net::SNMP::XS::set_type INFORM_REQUEST , \&_process_inform_request;
99 $process_methods [GET_BULK_REQUEST ] = \&_process_get_bulk_request; 105 Net::SNMP::XS::set_type SNMPV2_TRAP , \&_process_v2_trap;
100 $process_methods [INFORM_REQUEST ] = \&_process_inform_request; 106 Net::SNMP::XS::set_type REPORT , \&_process_report;
101 $process_methods [SNMPV2_TRAP ] = \&_process_v2_trap;
102 $process_methods [REPORT ] = \&_process_report;
103
104 # should be done in XS
105 sub process
106 {
107# my ($this, $expected, $found) = @_;
108
109 return $_[0]->_error if defined($_[0]->{_error});
110 return $_[0]->_error unless defined(my $type = _buffer_get($_[0], 1));
111
112 $type = unpack 'C', $type;
113
114 if ($process_methods[$type]) {
115 if (@_ >= 2 && (defined $_[1]) && $type != $_[1]) {
116 return $_[0]->_error(
117 'Expected %s, but found %s', asn1_itoa($_[1]), asn1_itoa($type)
118 );
119 }
120 $_[2] = $type if (@_ == 3);
121 $process_methods[$type]->($_[0], $type);
122 } else {
123 $_[0]->_error('Unknown ASN.1 type [0x%02x]', $type);
124 }
125 }
126} 107}
127 108
1281; 1091;
129 110
130=head1 AUTHOR 111=head1 AUTHOR

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines