Class: SNMP::PDU

Inherits:
Object
  • Object
show all
Defined in:
lib/snmp/pdu.rb

Constant Summary collapse

ERROR_STATUS_NAME =
{
     0 => :noError,
     1 => :tooBig,
     2 => :noSuchName,
     3 => :badValue,
     4 => :readOnly,
     5 => :genErr,
     6 => :noAccess,
     7 => :wrongType,
     8 => :wrongLength,
     9 => :wrongEncoding,
    10 => :wrongValue,
    11 => :noCreation,
    12 => :inconsistentValue,
    13 => :resourceUnavailable,
    14 => :commitFailed,
    15 => :undoFailed,
    16 => :authorizationError,
    17 => :notWritable,
    18 => :inconsistentName
}
ERROR_STATUS_CODE =
ERROR_STATUS_NAME.invert

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_id, varbind_list, error_status = 0, error_index = 0) ⇒ PDU

Returns a new instance of PDU.



147
148
149
150
151
152
# File 'lib/snmp/pdu.rb', line 147

def initialize(request_id, varbind_list, error_status=0, error_index=0)
    @request_id = request_id
    self.error_status = error_status
    @error_index = error_index.to_int
    @varbind_list = varbind_list
end

Instance Attribute Details

#error_indexObject

Returns the value of attribute error_index.



111
112
113
# File 'lib/snmp/pdu.rb', line 111

def error_index
  @error_index
end

#request_idObject

Returns the value of attribute request_id.



110
111
112
# File 'lib/snmp/pdu.rb', line 110

def request_id
  @request_id
end

#varbind_listObject

Returns the value of attribute varbind_list.



112
113
114
# File 'lib/snmp/pdu.rb', line 112

def varbind_list
  @varbind_list
end

Class Method Details

.decode(pdu_class, pdu_data) ⇒ Object



114
115
116
117
118
119
120
121
# File 'lib/snmp/pdu.rb', line 114

def self.decode(pdu_class, pdu_data)
    request_id, remainder = decode_integer(pdu_data)
    error_status, remainder = decode_integer(remainder)
    error_index, remainder = decode_integer(remainder)
    varbind_list, remainder = VarBindList.decode(remainder)
    assert_no_remainder(remainder)
    pdu_class.new(request_id, varbind_list, error_status, error_index)
end

Instance Method Details

#each_varbind(&block) ⇒ Object



177
178
179
# File 'lib/snmp/pdu.rb', line 177

def each_varbind(&block)
    @varbind_list.each(&block)
end

#encode_pdu(pdu_tag) ⇒ Object



169
170
171
172
173
174
175
# File 'lib/snmp/pdu.rb', line 169

def encode_pdu(pdu_tag)
    pdu_data = encode_integer(@request_id)
    pdu_data << encode_integer(@error_status)
    pdu_data << encode_integer(@error_index)
    pdu_data << @varbind_list.encode
    encode_tlv(pdu_tag, pdu_data)
end

#error_statusObject



165
166
167
# File 'lib/snmp/pdu.rb', line 165

def error_status
    ERROR_STATUS_NAME[@error_status]
end

#error_status=(status) ⇒ Object



154
155
156
157
158
159
160
161
162
163
# File 'lib/snmp/pdu.rb', line 154

def error_status=(status)
    @error_status = ERROR_STATUS_CODE[status]
    unless @error_status
        if status.respond_to?(:to_int) && ERROR_STATUS_NAME[status.to_int]
            @error_status = status
        else
            raise InvalidErrorStatus, status.to_s
        end
    end
end