Sha256: a560573dcfcbc557e72491e9d44c79452a5a86411d7b21fed3482de50ad8f932

Contents?: true

Size: 1.35 KB

Versions: 1

Compression:

Stored size: 1.35 KB

Contents

require 'pio/lldp/port_description_value'
require 'pio/lldp/system_name_value'
require 'pio/lldp/system_description_value'
require 'pio/lldp/system_capabilities_value'
require 'pio/lldp/management_address_value'
require 'pio/lldp/organizationally_specific_value'
require 'pio/lldp/end_of_lldpdu_value'

module Pio
  class Lldp
    # Optional TLV and End Of LLDPDU
    class OptionalTlv < BinData::Record
      endian :big

      bit7 :tlv_type
      bit9 :tlv_info_length
      choice :tlv_value,
             read_length: :tlv_info_length,
             onlyif: -> { !end_of_lldpdu? },
             selection: :chooser do
        end_of_lldpdu_value 0
        port_description_value 4
        system_name_value 5
        system_description_value 6
        system_capabilities_value 7
        management_address_value 8
        organizationally_specific_value 127
        string 'unknown'
      end

      def end_of_lldpdu?
        tlv_type.zero?
      end

      def chooser
        if valid_optional_tlv?
          tlv_type
        else
          'unknown'
        end
      end

      private

      def valid_optional_tlv?
        optional_tlv? || end_of_lldpdu_tlv?
      end

      def optional_tlv?
        tmp_tlv_type = tlv_type
        4 <= tmp_tlv_type && tmp_tlv_type <= 127
      end

      def end_of_lldpdu_tlv?
        tlv_type.zero?
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pio-0.30.1 lib/pio/lldp/optional_tlv.rb