Class: FlowEntry

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

Overview

Class for creating and interacting with OpenFlow flows

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(flow_table_id: 0, flow_id: nil, flow_priority: nil, name: nil, idle_timeout: 0, hard_timeout: 0, strict: false, install_hw: false, barrier: false, cookie: nil, cookie_mask: nil, out_port: nil, out_group: nil, flags: nil, buffer_id: nil) ⇒ FlowEntry

Returns a new instance of FlowEntry.

Raises:

  • (ArgumentError)


109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/openflowdev/flow_entry.rb', line 109

def initialize(flow_table_id: 0, flow_id: nil, flow_priority: nil, name: nil,
    idle_timeout: 0, hard_timeout: 0, strict: false, install_hw: false,
    barrier: false, cookie: nil, cookie_mask: nil, out_port: nil,
    out_group: nil, flags: nil, buffer_id: nil)
  raise ArgumentError, "Flow ID (flow_id) required" unless flow_id
  raise ArgumentError, "Flow Priority (flow_priority) required" unless flow_priority
  
  @table_id = flow_table_id
  @id = flow_id
  @name = name
  @priority = flow_priority
  @idle_timeout = idle_timeout
  @hard_timeout = hard_timeout
  @strict = strict
  @install_hw = install_hw
  @barrier = barrier
  @cookie = cookie
  @cookie_mask = cookie_mask
  @instructions = []
  @out_port = out_port
  @out_group = out_group
  @flags = flags
  @buffer_id = buffer_id
end

Instance Attribute Details

#barrierObject (readonly)

boolean: Boolean flag used to enforce OpenFlow switch to do ordered message processing. Barrier request/reply messages are used by the controller to ensure message dependencies have been met or to receive notifications for completed operations. When the controller wants to ensure message dependencies have been met or wants to receive notifications for completed operations, it may use an OFPT_BARRIER_REQUEST message. This message has no body. Upon receipt, the switch must finish processing all previously-received messages, including sending corresponding reply or error messages, before executing any messages beyond the Barrier Request.



58
59
60
# File 'lib/openflowdev/flow_entry.rb', line 58

def barrier
  @barrier
end

#buffer_idObject (readonly)

Buffered packet to apply to, or OFP_NO_BUFFER. Not meaningful for delete



79
80
81
# File 'lib/openflowdev/flow_entry.rb', line 79

def buffer_id
  @buffer_id
end

integer: Opaque Controller-issued identifier



60
61
62
# File 'lib/openflowdev/flow_entry.rb', line 60

def cookie
  @cookie
end

integer: Mask used to restrict the cookie bits that must match when the command is OFPFC_MODIFY* or OFPFC_DELETE*. A value of 0 indicates no restriction



63
64
65
# File 'lib/openflowdev/flow_entry.rb', line 63

def cookie_mask
  @cookie_mask
end

#flagsObject (readonly)

integer: Bitmap of OpenFlow flags (OFPFF_* from OpenFlow spec)



77
78
79
# File 'lib/openflowdev/flow_entry.rb', line 77

def flags
  @flags
end

#hard_timeoutObject (readonly)

integer: Max time before discarding (seconds)



45
46
47
# File 'lib/openflowdev/flow_entry.rb', line 45

def hard_timeout
  @hard_timeout
end

#idObject (readonly)

integer: Unique identifier of this FlowEntry in the Controller’s data store



39
40
41
# File 'lib/openflowdev/flow_entry.rb', line 39

def id
  @id
end

#idle_timeoutObject (readonly)

integer: Idle time before discarding (seconds)



43
44
45
# File 'lib/openflowdev/flow_entry.rb', line 43

def idle_timeout
  @idle_timeout
end

#install_hwObject (readonly)

internal Controller’s inventory attribute



49
50
51
# File 'lib/openflowdev/flow_entry.rb', line 49

def install_hw
  @install_hw
end

#instructionsObject (readonly)

list of Instruction: Instructions to be executed when a flow matches this entry flow match fields



67
68
69
# File 'lib/openflowdev/flow_entry.rb', line 67

def instructions
  @instructions
end

#matchObject (readonly)

Match: Flow match fields



69
70
71
# File 'lib/openflowdev/flow_entry.rb', line 69

def match
  @match
end

#nameObject (readonly)

string: FlowEntry name in the FlowTable (internal Controller’s inventory attribute)



65
66
67
# File 'lib/openflowdev/flow_entry.rb', line 65

def name
  @name
end

#out_groupObject (readonly)

integer: For delete commands, require matching entries to include this as an output group. A value of OFPG_ANY indicates no restriction



75
76
77
# File 'lib/openflowdev/flow_entry.rb', line 75

def out_group
  @out_group
end

#out_portObject (readonly)

integer: For delete commands, require matching entries to include this as an output port. A value of OFPP_ANY indicates no restriction.



72
73
74
# File 'lib/openflowdev/flow_entry.rb', line 72

def out_port
  @out_port
end

#priorityObject (readonly)

integer: Priority level of flow entry



41
42
43
# File 'lib/openflowdev/flow_entry.rb', line 41

def priority
  @priority
end

#strictObject (readonly)

boolean: Modify/Delete entry strictly matching wildcards and priority



47
48
49
# File 'lib/openflowdev/flow_entry.rb', line 47

def strict
  @strict
end

#table_idObject (readonly)

string: ID of the table to put the flow in



37
38
39
# File 'lib/openflowdev/flow_entry.rb', line 37

def table_id
  @table_id
end

Instance Method Details

#add_instruction(instruction) ⇒ Object

Add an Instruction to the flow entry.

Parameters

  • instruction

    Instruction : Instruction to add to the flow entry.

Raises:

  • (ArgumentError)


139
140
141
142
# File 'lib/openflowdev/flow_entry.rb', line 139

def add_instruction(instruction)
  raise ArgumentError, "Instruction must be of type 'Instruction'" unless instruction.is_a?(Instruction)
  @instructions << instruction
end

#add_match(match) ⇒ Object

Add a match rule to the flow entry.

Parameters

  • match

    Match : Match to add to the flow entry.

Raises:

  • (ArgumentError)


149
150
151
152
# File 'lib/openflowdev/flow_entry.rb', line 149

def add_match(match)
  raise ArgumentError, "Match must be of type 'Match'" unless match.is_a?(Match)
  @match = match
end

#to_hashObject

:nodoc:



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/openflowdev/flow_entry.rb', line 154

def to_hash #:nodoc:
  instructions_hash = []
  @instructions.each do |instruction|
    instructions_hash << instruction.to_hash
  end
  
  hash = {'flow-node-inventory:flow' => {:barrier => @barrier,
    'hard-timeout' => @hard_timeout, :id => @id,
    'idle-timeout' => @idle_timeout, 'installHw' => @install_hw,
    'out-port' => @out_port, 'out-group' => @out_group, :flags => @flags,
    'buffer-id' => @buffer_id, :match => @match.to_hash, :priority => @priority,
    :strict => @strict, :table_id => @table_id, :cookie => @cookie,
    :cookie_mask => @cookie_mask, 'flow-name' => @name,
    :instructions => {:instruction => instructions_hash}}}
  hash = hash.compact
  hash
end