pysnmp icon indicating copy to clipboard operation
pysnmp copied to clipboard

Payload changed before parsing to pyasn1 producing Constraint error

Open camdun opened this issue 6 years ago • 1 comments

Hi,

I'm new to this package and I'm trying to update some code using version 4.2.3 to 4.4.9. I ran into an error when getting payloads that uses types with bigger display hint adjustments. I'm using the mibdump method. It appears to me that the display hint value in the example below is getting scaled by magnitudes of 10 for the absolute displayHint adjustment before being passed to pyasn1. Which means the Value is too large for the ValueRangeConstraint. Example and error attached.

Thanks

Constraint error.txt

camdun avatar Jun 28 '19 07:06 camdun

If in the compiled Python module you have

class FrequencyHz(TextualConvention, Unsigned32):
    status = 'current'
    displayHint = 'd-6'
    subtypeSpec = Unsigned32.subtypeSpec + ValueRangeConstraint(0, 4294967295)

Then in the original MIB document, you should have the fragment like

FrequencyHz ::= TEXTUAL-CONVENTION
    DISPLAY-HINT "d-6"
    STATUS       current
    DESCRIPTION
        "FrequencyHz"
    SYNTAX       Unsigned32 (0..4294967295)

The type Unsigned32 is obsolete, and the SNMP agent you tested seems to return a Gauge32 object for this OID. Together, this prevents display hint from working properly (which I can reproduce) and the constraint error.

To really resolve this issue, you need to study further how this SNMP agent works internally and which data type it tries to return. Then you have to revise the MIB document to strictly match the data type.

lextm avatar Feb 12 '23 22:02 lextm