Sha256: 5e4a50f05d87ccea72fb9eba7d9a52786bc614842d195b9046bd64f6075995df

Contents?: true

Size: 1.36 KB

Versions: 11

Compression:

Stored size: 1.36 KB

Contents

require 'bindata'
require 'forwardable'
require 'pio/type/mac_address'

module Pio
  # An action to modify the source/destination Ethernet address of a packet.
  class SetEtherAddress
    # rubocop:disable MethodLength
    def self.def_format(action_type)
      str = %(
        class Format < BinData::Record
          endian :big

          uint16 :type, value: #{action_type}
          uint16 :message_length, value: 16
          mac_address :mac_address
          uint48 :padding
          hide :padding
        end
      )
      module_eval str
    end
    # rubocop:enable MethodLength

    def self.read(raw_data)
      set_ether_address = allocate
      set_ether_address.instance_variable_set(:@format,
                                              const_get(:Format).read(raw_data))
      set_ether_address
    end

    extend Forwardable

    def_delegators :@format, :message_length
    def_delegators :@format, :mac_address
    def_delegator :@format, :to_binary_s, :to_binary

    def initialize(mac_address)
      @format = self.class.const_get(:Format).new(mac_address: mac_address)
    end
  end

  # An action to modify the source Ethernet address of a packet.
  class SetEtherSourceAddr < SetEtherAddress
    def_format 4
  end

  # An action to modify the destination Ethernet address of a packet.
  class SetEtherDestinationAddr < SetEtherAddress
    def_format 5
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
pio-0.25.0 lib/pio/open_flow10/set_ether_address.rb
pio-0.24.2 lib/pio/open_flow10/set_ether_address.rb
pio-0.24.1 lib/pio/open_flow10/set_ether_address.rb
pio-0.24.0 lib/pio/open_flow10/set_ether_address.rb
pio-0.23.1 lib/pio/open_flow10/set_ether_address.rb
pio-0.23.0 lib/pio/open_flow10/set_ether_address.rb
pio-0.22.0 lib/pio/open_flow10/set_ether_address.rb
pio-0.21.1 lib/pio/open_flow10/set_ether_address.rb
pio-0.21.0 lib/pio/set_ether_address.rb
pio-0.20.1 lib/pio/set_ether_address.rb
pio-0.20.0 lib/pio/set_ether_address.rb