Sha256: d0cb1f9d46b1d07671e263e54312f38801616adfac6036199fb911561cf1719f

Contents?: true

Size: 1.18 KB

Versions: 7

Compression:

Stored size: 1.18 KB

Contents

require 'bindata'

module Pio
  # OpenFlow 1.0 format.
  module OpenFlow
    # OpenFlow 1.0 message header format.
    class OpenFlowHeader < BinData::Record
      # Transaction ID (uint32)
      class TransactionId < BinData::Primitive
        endian :big
        uint32 :xid

        def set(value)
          unless value.unsigned_32bit?
            fail(ArgumentError,
                 'Transaction ID should be an unsigned 32-bit integer.')
          end
          self.xid = value
        end

        def get
          xid
        end
      end

      endian :big
      uint8 :ofp_version, value: 1
      uint8 :message_type, initial_value: :message_type_value
      uint16 :message_length, initial_value: -> { 8 + body.length }
      transaction_id :transaction_id, initial_value: 0

      # parse header options
      class Options
        def self.parse(options)
          xid = if options.respond_to?(:to_i)
                  options.to_i
                elsif options.respond_to?(:fetch)
                  options[:transaction_id] || options[:xid] || 0
                else
                  fail TypeError
                end
          { transaction_id: xid }
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
pio-0.18.2 lib/pio/open_flow/open_flow_header.rb
pio-0.18.1 lib/pio/open_flow/open_flow_header.rb
pio-0.18.0 lib/pio/open_flow/open_flow_header.rb
pio-0.17.0 lib/pio/open_flow/open_flow_header.rb
pio-0.16.0 lib/pio/open_flow/open_flow_header.rb
pio-0.15.2 lib/pio/open_flow/open_flow_header.rb
pio-0.15.1 lib/pio/open_flow/open_flow_header.rb