Class: Instruction

Inherits:
Object
  • Object
show all
Defined in:
lib/openflowdev/instruction.rb

Overview

Class representing OpenFlow flow instruction

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(instruction_order: nil) ⇒ Instruction

Parameters

  • instruction_order

    Order in which to carry out this instruction relative to other instructions.

Raises:

  • (ArgumentError)


41
42
43
44
45
# File 'lib/openflowdev/instruction.rb', line 41

def initialize(instruction_order: nil)
  raise ArgumentError, "Instruction Order (instruction_order) required" unless instruction_order
  @order = instruction_order
  @actions = []
end

Instance Attribute Details

#actionsObject (readonly)

Action : list of Action



36
37
38
# File 'lib/openflowdev/instruction.rb', line 36

def actions
  @actions
end

#orderObject

integer : order that action is to be carried out relative to other instructions.



34
35
36
# File 'lib/openflowdev/instruction.rb', line 34

def order
  @order
end

Instance Method Details

#add_apply_action(action) ⇒ Object

Add action to an Instruction.

Parameters

  • action

    Action : What action to take

Raises:

  • (ArgumentError)


52
53
54
55
# File 'lib/openflowdev/instruction.rb', line 52

def add_apply_action(action)
  raise ArgumentError, "Action must be a subclass of 'Action'" unless action.is_a?(Action)
  @actions << action
end

#to_hashObject

:nodoc:



57
58
59
60
61
62
63
# File 'lib/openflowdev/instruction.rb', line 57

def to_hash #:nodoc:
  actions_hash = []
  @actions.each do |action|
    actions_hash << action.to_hash
  end
  {:order => @order, 'apply-actions' => {:action => actions_hash}}
end