Class: Pio::OpenFlow::Action

Inherits:
Object
  • Object
show all
Extended by:
ActiveSupport::DescendantsTracker
Defined in:
lib/pio/open_flow/action.rb

Overview

OpenFlow actions.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_options) ⇒ Action

Returns a new instance of Action.



38
39
40
# File 'lib/pio/open_flow/action.rb', line 38

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

Class Method Details

.action_header(options) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/pio/open_flow/action.rb', line 12

def self.action_header(options)
  module_eval do
    endian :big

    uint16 :action_type, value: options.fetch(:action_type)
    uint16 :action_length, value: options.fetch(:action_length)
  end
end

.method_missing(method, *args, &block) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/pio/open_flow/action.rb', line 27

def self.method_missing(method, *args, &block)
  begin
    const_get(:Format).__send__ method, *args, &block
  rescue NameError
    const_set :Format, Class.new(BinData::Record)
    retry
  end
  return if method == :endian || method == :virtual
  define_method(args.first) { @format.__send__ args.first }
end

.read(raw_data) ⇒ Object



21
22
23
24
25
# File 'lib/pio/open_flow/action.rb', line 21

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

Instance Method Details

#to_binaryObject



42
43
44
# File 'lib/pio/open_flow/action.rb', line 42

def to_binary
  @format.to_binary_s
end