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.



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

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.



130
131
132
# File 'lib/snmp/pdu.rb', line 130

def error_index
  @error_index
end

#request_idObject

Returns the value of attribute request_id.



129
130
131
# File 'lib/snmp/pdu.rb', line 129

def request_id
  @request_id
end

#varbind_listObject Also known as: vb_list

Returns the value of attribute varbind_list.



131
132
133
# File 'lib/snmp/pdu.rb', line 131

def varbind_list
  @varbind_list
end

Class Method Details

.decode(pdu_class, pdu_data, mib = nil) ⇒ Object



135
136
137
138
139
140
141
142
# File 'lib/snmp/pdu.rb', line 135

def self.decode(pdu_class, pdu_data, mib=nil)
  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, mib)
  assert_no_remainder(remainder)
  pdu_class.new(request_id, varbind_list, error_status, error_index)
end

Instance Method Details

#each_varbind(&block) ⇒ Object



198
199
200
# File 'lib/snmp/pdu.rb', line 198

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

#encode_pdu(pdu_tag) ⇒ Object



190
191
192
193
194
195
196
# File 'lib/snmp/pdu.rb', line 190

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



186
187
188
# File 'lib/snmp/pdu.rb', line 186

def error_status
  ERROR_STATUS_NAME[@error_status]
end

#error_status=(status) ⇒ Object



175
176
177
178
179
180
181
182
183
184
# File 'lib/snmp/pdu.rb', line 175

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