Sha256: b4d5dd01596f03197baaa7ecc488ec513de372f3ea9f245ba32108590a86ea3d

Contents?: true

Size: 1.61 KB

Versions: 5

Compression:

Stored size: 1.61 KB

Contents

require "rubygems"
require "bindata"

require "pio/lldp/chassis_id_tlv"
require "pio/lldp/optional_tlv"
require "pio/lldp/port_id_tlv"
require "pio/lldp/ttl_tlv"
require "pio/type/ethernet_header"


module Pio
  class Lldp
    # LLDP frame
    class Frame < BinData::Record
      extend Type::EthernetHeader

      endian :big

      ethernet_header :ether_type => 0x88cc
      chassis_id_tlv :chassis_id
      port_id_tlv :port_id
      ttl_tlv :ttl, :initial_value => 120
      array :optional_tlv, :type => :optional_tlv, :read_until => lambda { element.end_of_lldpdu? }


      def dpid
        chassis_id
      end


      def port_description
        get_tlv_field 4, "port_description"
      end


      def system_name
        get_tlv_field 5, "system_name"
      end


      def system_description
        get_tlv_field 6, "system_description"
      end


      def system_capabilities
        get_tlv 7
      end


      def management_address
        get_tlv_field 8, "management_address"
      end


      def organizationally_specific
        get_tlv 127
      end


      ##########################################################################
      private
      ##########################################################################


      def get_tlv tlv_type
        tlv = optional_tlv.find do | each |
          each[ "tlv_type" ] == tlv_type
        end
        tlv[ "tlv_value" ] if tlv
      end


      def get_tlv_field tlv_type, name
        tlv = get_tlv( tlv_type )
        tlv[ name ] if tlv
      end
    end
  end
end


### Local variables:
### mode: Ruby
### coding: utf-8-unix
### indent-tabs-mode: nil
### End:

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pio-0.2.6 lib/pio/lldp/frame.rb
pio-0.2.5 lib/pio/lldp/frame.rb
pio-0.2.4 lib/pio/lldp/frame.rb
pio-0.2.3 lib/pio/lldp/frame.rb
pio-0.2.2 lib/pio/lldp/frame.rb