Skip to content

Commit

Permalink
Add NiciraStackPop
Browse files Browse the repository at this point in the history
  • Loading branch information
yasuhito committed Nov 20, 2015
1 parent a9bb3f0 commit 5184287
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Rakefile
@@ -1,7 +1,7 @@
require 'bundler/gem_tasks'

RELISH_PROJECT = 'trema/pio'
FLAY_THRESHOLD = 1204
FLAY_THRESHOLD = 1410

task default: :travis
task test: [:spec, :cucumber]
Expand Down
28 changes: 28 additions & 0 deletions features/open_flow13/nicira_stack_pop.feature
@@ -0,0 +1,28 @@
@open_flow13
Feature: Pio::NiciraStackPop

Pops field[offset: offset + n_bits] from top of the stack.

Scenario: new(:reg0)
When I try to create an OpenFlow action with:
"""
Pio::NiciraStackPop.new(:reg0)
"""
Then it should finish successfully
And the action has the following fields and values:
| field | value |
| offset | 0 |
| n_bits | 32 |
| field | :reg0 |

Scenario: new(:reg0, n_bits: 16, offset: 16)
When I try to create an OpenFlow action with:
"""
Pio::NiciraStackPop.new(:reg0, n_bits: 16, offset: 16)
"""
Then it should finish successfully
And the action has the following fields and values:
| field | value |
| offset | 16 |
| n_bits | 16 |
| field | :reg0 |
5 changes: 4 additions & 1 deletion lib/pio/open_flow.rb
Expand Up @@ -14,18 +14,21 @@ def self.version
@version
end

# rubocop:disable MethodLength
def self.switch_version(version)
[:Barrier, :Echo, :Features, :FlowMod, :Hello, :Match,
:PacketIn, :FlowRemoved, :PacketOut, :SendOutPort,
:SetSourceMacAddress, :SetDestinationMacAddress, :PortStatus, :Stats,
:FlowStats, :DescriptionStats, :AggregateStats, :TableStats, :PortStats,
:QueueStats, :Error, :SetArpOperation, :SetArpSenderProtocolAddress,
:SetArpSenderHardwareAddress, :NiciraRegMove, :SetMetadata,
:NiciraRegLoad, :NiciraSendOutPort, :NiciraStackPush].each do |each|
:NiciraRegLoad, :NiciraSendOutPort, :NiciraStackPush,
:NiciraStackPop].each do |each|
set_message_class_name each, version
@version = version.to_s
end
end
# rubocop:enable MethodLength

# rubocop:disable MethodLength
def self.read(binary)
Expand Down
1 change: 1 addition & 0 deletions lib/pio/open_flow13.rb
Expand Up @@ -18,6 +18,7 @@
require 'pio/open_flow13/nicira_reg_load'
require 'pio/open_flow13/nicira_reg_move'
require 'pio/open_flow13/nicira_send_out_port'
require 'pio/open_flow13/nicira_stack_pop'
require 'pio/open_flow13/nicira_stack_push'
require 'pio/open_flow13/send_out_port'
require 'pio/open_flow13/set_arp_operation'
Expand Down
49 changes: 49 additions & 0 deletions lib/pio/open_flow13/nicira_stack_pop.rb
@@ -0,0 +1,49 @@
require 'pio/open_flow/nicira_action'
require 'pio/open_flow13/match'

module Pio
module OpenFlow13
# NXAST_STACK_POP action
class NiciraStackPop < OpenFlow::NiciraAction
nicira_action_header action_type: 0xffff,
action_length: 24,
subtype: 28
uint16 :_offset
struct :field do
uint16 :oxm_class
bit7 :oxm_field
bit1 :oxm_hasmask, value: 0
uint8 :oxm_length
end
uint16 :_n_bits
string :padding, length: 6
hide :padding

def initialize(field, options = {})
@field = field
super(_offset: options[:offset] || 0,
_n_bits: (options[:n_bits] || oxm_length * 8) + 1,
field: { oxm_class: field_oxm_class.const_get(:OXM_CLASS),
oxm_field: field_oxm_class.const_get(:OXM_FIELD),
oxm_length: oxm_length })
end

attr_reader :field
alias_method :offset, :_offset

def n_bits
_n_bits - 1
end

private

def oxm_length
field_oxm_class.new.length
end

def field_oxm_class
Match.const_get(@field.to_s.split('_').map(&:capitalize).join)
end
end
end
end

0 comments on commit 5184287

Please sign in to comment.