-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
83 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |