Sha256: 8c3c6f579df0b2a424a9ded320b9499361bd211719780e97f598bc7b4377bfee

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

require 'active_support/core_ext/object/try'
require 'pio/open_flow'
require 'pio/open_flow/buffer_id'
require 'pio/open_flow13/actions'

module Pio
  module OpenFlow13
    # OpenFlow 1.3 PacketOut message parser and generator
    class PacketOut < OpenFlow::Message
      # Packet's input port or :controller
      class InPort < BinData::Primitive
        CONTROLLER = 0xfffffffd

        endian :big
        uint32 :in_port

        def get
          in_port == CONTROLLER ? :controller : in_port
        end

        def set(value)
          self.in_port = (value == :controller ? NO_CONTROLLER : value)
        end
      end

      open_flow_header(version: 4, type: 13,
                       length: lambda do
                         24 + actions_length + raw_data.length
                       end)
      buffer_id :buffer_id
      in_port :in_port
      uint16 :actions_length, initial_value: -> { actions.binary.length }
      string :padding, length: 6
      actions13 :actions, length: :actions_length
      string :raw_data, read_length: -> { length - 24 - actions_length }

      def data
        @data ||= Pio::Parser.read(raw_data)
      end

      def method_missing(method, *args)
        bindata_value = data.__send__(method, *args)
        bindata_value.try(:snapshot) || bindata_value
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pio-0.30.1 lib/pio/open_flow13/packet_out.rb