Sha256: 70a05ce69de69220066cf52b203cceadce7eae9f366fb2560d6b8754859d71b2

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

require 'bindata'

module Pio
  module OpenFlow13
    # Actions not yet implemented.
    class UnsupportedAction < BinData::Record
      endian :big

      uint16 :action_type
      uint16 :action_length
      string :body, length: -> { action_length - 4 }

      def to_binary
        to_binary_s
      end
    end

    # Actions list of actions-apply instruction.
    class Actions13 < BinData::Primitive
      mandatory_parameter :length

      endian :big

      string :binary, read_length: :length

      def set(actions)
        self.binary = Array(actions).map(&:to_binary).join
      end

      # rubocop:disable MethodLength
      def get
        actions = []
        tmp = binary
        until tmp.empty?
          action = case BinData::Uint16be.read(tmp)
                   when 0
                     OpenFlow13::SendOutPort.read(tmp)
                   else
                     UnsupportedAction.read(tmp)
                   end
          tmp = tmp[action.action_length..-1]
          actions << action
        end
        actions
      end
      # rubocop:enable MethodLength
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pio-0.30.2 lib/pio/open_flow13/actions.rb