Class: Pio::OpenFlow::Action

Inherits:
Object
  • Object
show all
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.



32
33
34
# File 'lib/pio/open_flow/action.rb', line 32

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

Class Method Details

.action_header(options) ⇒ Object



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

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

.inherited(child_klass) ⇒ Object



7
8
9
# File 'lib/pio/open_flow/action.rb', line 7

def self.inherited(child_klass)
  child_klass.const_set :Format, Class.new(BinData::Record)
end

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



26
27
28
29
30
# File 'lib/pio/open_flow/action.rb', line 26

def self.method_missing(method, *args, &block)
  const_get(:Format).__send__ method, *args, &block
  return if method == :endian || method == :virtual
  define_method(args.first) { @format.__send__ args.first }
end

.read(raw_data) ⇒ Object



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

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



36
37
38
# File 'lib/pio/open_flow/action.rb', line 36

def to_binary
  @format.to_binary_s
end