-
Notifications
You must be signed in to change notification settings - Fork 11
wip: Add support for NXAST_LEARN #298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| @openflow13 | ||
| Feature: NiciraLearn | ||
|
|
||
| This action adds or modifies a flow in an OpenFlow table, similar to | ||
| OFPT_FLOW_MOD with OFPFC_MODIFY_STRICT as 'command'. | ||
|
|
||
| Scenario: new({}) | ||
| When I try to create an OpenFlow action with: | ||
| """ | ||
| Pio::OpenFlow::NiciraLearn.new({}) | ||
| """ | ||
| Then it should finish successfully | ||
| And the action has the following fields and values: | ||
| | field | value | | ||
| | idle_timeout | 0 | | ||
| | hard_timeout | 0 | | ||
| | priority | 65535 | | ||
| | cookie | 0 | | ||
| | flags | [] | | ||
| | table_id | 0 | | ||
| | fin_idle_timeout | 0 | | ||
| | fin_hard_timeout | 0 | |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| require 'bindata' | ||
| require 'forwardable' | ||
| require 'pio/open_flow13/match' | ||
|
|
||
| module Pio | ||
| module OpenFlow13 | ||
| class LearnMatch | ||
| extend Forwardable | ||
|
|
||
| # rubocop:disable MethodLength | ||
| def initialize(arguments) | ||
| @source = arguments.fetch(:source) | ||
| @destination = arguments.fetch(:destination) | ||
| registers = { _source: { oxm_class: source_oxm_class, | ||
| oxm_field: source_oxm_field, | ||
| oxm_length: source_oxm_length }, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Align the elements of a hash literal if they span more than one line. |
||
| _destination: { oxm_class: destination_oxm_class, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Align the elements of a hash literal if they span more than one line. |
||
| oxm_field: destination_oxm_field, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Align the elements of a hash literal if they span more than one line. |
||
| oxm_length: destination_oxm_length } } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Align the elements of a hash literal if they span more than one line. |
||
| options = [:n_bits, | ||
| :source_offset, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Align the elements of an array literal if they span more than one line. |
||
| :destination_offset].each_with_object({}) do |each, opts| | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Align the elements of an array literal if they span more than one line. |
||
| opts[each] = arguments[each] if arguments[each] | ||
| end | ||
| @frame = Field.new(registers.merge(options)) | ||
| end | ||
| # rubocop:enable MethodLength | ||
|
|
||
| attr_reader :source | ||
| attr_reader :destination | ||
|
|
||
| def_delegator :@frame, :to_binary_s | ||
|
|
||
| def self.read(raw_data) | ||
| begin | ||
| frame = Field.read(raw_data) | ||
| rescue | ||
| raise Pio::ParseError, $ERROR_INFO.message | ||
| end | ||
|
|
||
| field = allocate | ||
| field.instance_variable_set :@frame, frame | ||
| field | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def source_oxm_class | ||
| source_class.const_get(:OXM_CLASS) | ||
| end | ||
|
|
||
| def source_oxm_field | ||
| source_class.const_get(:OXM_FIELD) | ||
| end | ||
|
|
||
| def source_oxm_length | ||
| source_class.new.length | ||
| end | ||
|
|
||
| def source_class | ||
| Match.const_get(@source.to_s | ||
| .split('_') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Place the . on the previous line, together with the method call receiver. |
||
| .map(&:capitalize) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Place the . on the previous line, together with the method call receiver. |
||
| .join) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Place the . on the previous line, together with the method call receiver. |
||
| end | ||
|
|
||
| def destination_oxm_class | ||
| destination_class.const_get(:OXM_CLASS) | ||
| end | ||
|
|
||
| def destination_oxm_field | ||
| destination_class.const_get(:OXM_FIELD) | ||
| end | ||
|
|
||
| def destination_oxm_length | ||
| destination_class.new.length | ||
| end | ||
|
|
||
| def destination_class | ||
| Match.const_get(@destination.to_s | ||
| .split('_') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Place the . on the previous line, together with the method call receiver. |
||
| .map(&:capitalize) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Place the . on the previous line, together with the method call receiver. |
||
| .join) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Place the . on the previous line, together with the method call receiver. |
||
| end | ||
|
|
||
| class Field < BinData::Record | ||
| endian :big | ||
|
|
||
| bit2 :zero | ||
| hide :zero | ||
| bit1 :src_type, value: 0 | ||
| hide :src_type | ||
| bit2 :dst_type, value: 0 | ||
| hide :dst_type | ||
|
|
||
| bit11 :_n_bits | ||
| struct :_source do | ||
| uint16 :oxm_class | ||
| bit7 :oxm_field | ||
| bit1 :oxm_hasmask, value: 0 | ||
| uint8 :oxm_length | ||
| end | ||
| uint16 :source_offset | ||
| struct :_destination do | ||
| uint16 :oxm_class | ||
| bit7 :oxm_field | ||
| bit1 :oxm_hasmask, value: 0 | ||
| uint8 :oxm_length | ||
| end | ||
| uint16 :destination_offset | ||
| end | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| require 'pio/open_flow' | ||
|
|
||
| module Pio | ||
| module OpenFlow13 | ||
| # NXAST_LEARN action | ||
| class NiciraLearn < OpenFlow::NiciraAction | ||
| extend OpenFlow::Flags | ||
|
|
||
| flags_16bit :flags, [:send_flow_rem, | ||
| :delete_learned] | ||
|
|
||
| nicira_action_header action_type: 0xffff, | ||
| action_length: 24, | ||
| subtype: 16 | ||
| uint16 :idle_timeout | ||
| uint16 :hard_timeout | ||
| uint16 :priority, initial_value: 0xffff | ||
| uint64 :cookie | ||
| flags :flags | ||
| uint8 :table_id | ||
| string :padding1, length: 1 | ||
| hide :padding1 | ||
| uint16 :fin_idle_timeout | ||
| uint16 :fin_hard_timeout | ||
| array :flow_mod_specs, type: :uint16, initial_length: 0 | ||
| string :padding2, length: 2 | ||
| hide :padding2 | ||
|
|
||
| def fms_length | ||
| if flow_mod_specs.size > 0 | ||
| flow_mod_specs.map(&:length).inject(&:+) | ||
| else | ||
| 0 | ||
| end | ||
| end | ||
|
|
||
| def padding_length | ||
| (22 + 7) / 8 * 8 - 22 | ||
| end | ||
| end | ||
| end | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Align the elements of a hash literal if they span more than one line.