Sha256: 01dc6ebaff0be45773a807dbe40d43f1d5ee60c9a45dfceaeb8c9c1c36694f01

Contents?: true

Size: 939 Bytes

Versions: 24

Compression:

Stored size: 939 Bytes

Contents

require 'pio/type/mac_address'

module Pio
  # Adds ethernet_header macro.
  module EthernetHeader
    # EtherType constants for ethernet_header.ether_type.
    module EtherType
      ARP = 0x0806
      IPV4 = 0x0800
      VLAN = 0x8100
      LLDP = 0x88cc
    end

    # This method smells of :reek:TooManyStatements
    def self.included(klass)
      def klass.ethernet_header(options)
        mac_address :destination_mac
        mac_address :source_mac
        uint16 :ether_type, value: options.fetch(:ether_type)
        bit3 :vlan_pcp_internal, onlyif: :vlan?
        bit1 :vlan_cfi, onlyif: :vlan?
        bit12 :vlan_vid_internal, onlyif: :vlan?
        uint16 :ether_type_vlan, value: :ether_type, onlyif: :vlan?
      end
    end

    def vlan_vid
      vlan? ? vlan_vid_internal : 0xffff
    end

    def vlan_pcp
      vlan? ? vlan_pcp_internal : 0
    end

    def vlan?
      ether_type == EtherType::VLAN
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
pio-0.18.2 lib/pio/ethernet_header.rb
pio-0.18.1 lib/pio/ethernet_header.rb
pio-0.18.0 lib/pio/ethernet_header.rb
pio-0.17.0 lib/pio/ethernet_header.rb