Skip to content
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

Add CopyField action #279

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions features/open_flow13/copy_field.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@open_flow13
Feature: Pio::CopyField

Scenario: new(from: :arp_sender_hardware_address, to: :arp_target_hardware_address)
When I try to create an OpenFlow action with:
"""
Pio::CopyField.new(from: :arp_sender_hardware_address, to: :arp_target_hardware_address)
"""
Then it should finish successfully
And the action has the following fields and values:
| field | value |
| action_type.to_hex | 0xffff |
| action_length | 32 |
| experimenter_id.to_hex | 0x4f4e4600 |
| experimenter_type | 3200 |
| from | :arp_sender_hardware_address |
| oxm_ids[0].oxm_field | 24 |
| oxm_ids[0].oxm_length | 6 |
| to | :arp_target_hardware_address |
| oxm_ids[1].oxm_field | 25 |
| oxm_ids[1].oxm_length | 6 |
2 changes: 1 addition & 1 deletion lib/pio/open_flow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def self.switch_version(version)
:FlowStats, :DescriptionStats, :AggregateStats, :TableStats, :PortStats,
:QueueStats, :Error, :NiciraResubmit, :SetArpOperation,
:SetArpSenderProtocolAddress, :SetArpSenderHardwareAddress,
:NiciraResubmitTable].each do |each|
:NiciraResubmitTable, :CopyField].each do |each|
set_message_class_name each, version
@version = version.to_s
end
Expand Down
1 change: 1 addition & 0 deletions lib/pio/open_flow13.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
require 'pio/open_flow13/stats_request'

# Actions
require 'pio/open_flow13/copy_field'
require 'pio/open_flow13/send_out_port'
require 'pio/open_flow13/set_arp_operation'
require 'pio/open_flow13/set_arp_sender_hardware_address'
Expand Down
42 changes: 42 additions & 0 deletions lib/pio/open_flow13/copy_field.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require 'active_support/core_ext/string/inflections'
require 'pio/open_flow/action'

module Pio
module OpenFlow13
# Copy-field action (ONF extension 320)
class CopyField < OpenFlow::Action
action_header action_type: 0xffff, action_length: 32
uint32 :experimenter_id, value: 0x4f4e4600
uint16 :experimenter_type, value: 3200
string :padding1, length: 2
hide :padding1
uint16 :n_bits
uint16 :source_offset, value: 0
uint16 :destination_offset, value: 0
string :padding2, length: 2
hide :padding2
array :oxm_ids, initial_length: 2 do
uint16 :oxm_class, value: Match::OXM_CLASS_OPENFLOW_BASIC
bit7 :oxm_field
bit1 :oxm_hasmask, value: 0
uint8 :oxm_length
end
string :padding3, length: 4
hide :padding3

attr_reader :from
attr_reader :to

def initialize(options)
@from = options.fetch(:from)
@to = options.fetch(:to)
from_klass = Match.const_get(@from.to_s.classify)
to_klass = Match.const_get(@to.to_s.classify)
super(oxm_ids: [{ oxm_field: from_klass.const_get(:OXM_FIELD),
oxm_length: from_klass.new.length },
{ oxm_field: to_klass.const_get(:OXM_FIELD),
oxm_length: to_klass.new.length }])
end
end
end
end
1 change: 1 addition & 0 deletions pio.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Gem::Specification.new do |gem|
gem.required_ruby_version = '>= 2.0.0'

gem.add_dependency 'bindata', '~> 2.1.0'
gem.add_dependency 'activesupport', '~> 4.2', '>= 4.2.4'

gem.add_development_dependency 'bundler', '~> 1.10.6'
gem.add_development_dependency 'pry', '~> 0.10.3'
Expand Down