Skip to content

Commit

Permalink
Merge pull request #228 from trema/feature/set_transport_source_port
Browse files Browse the repository at this point in the history
Add open_flow10/set_transport_source_port.feature
  • Loading branch information
yasuhito committed Sep 1, 2015
2 parents 524f1e7 + 8ead49f commit 556d858
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
16 changes: 16 additions & 0 deletions features/open_flow10/set_transport_source_port.feature
@@ -0,0 +1,16 @@
@open_flow10
Feature: Pio::SetTransportSourcePort

Scenario: new(100)
When I try to create an OpenFlow action with:
"""
Pio::SetTransportSourcePort.new(100)
"""
Then it should finish successfully
And the action has the following fields and values:
| field | value |
| action_type | 9 |
| message_length | 8 |
| port_number | 100 |


10 changes: 5 additions & 5 deletions lib/pio/open_flow10/set_transport_port.rb
Expand Up @@ -6,12 +6,12 @@ module Pio
# An action to modify the source/destination TCP/UDP port of a packet.
class SetTransportPort
# rubocop:disable MethodLength
def self.def_format(action_type)
def self.action_type(action_type)
str = %(
class Format < BinData::Record
endian :big
uint16 :type, value: #{action_type}
uint16 :action_type, value: #{action_type}
uint16 :message_length, value: 8
uint16 :port_number
uint16 :padding
Expand All @@ -30,7 +30,7 @@ def self.read(raw_data)

extend Forwardable

def_delegators :@format, :type
def_delegators :@format, :action_type
def_delegators :@format, :message_length
def_delegators :@format, :port_number
def_delegator :@format, :to_binary_s, :to_binary
Expand All @@ -48,11 +48,11 @@ def initialize(number)

# An action to modify the source TCP/UDP port of a packet.
class SetTransportSourcePort < SetTransportPort
def_format 9
action_type 9
end

# An action to modify the source TCP/UDP port of a packet.
class SetTransportDestinationPort < SetTransportPort
def_format 10
action_type 10
end
end
4 changes: 2 additions & 2 deletions spec/pio/open_flow10/set_transport_destination_port_spec.rb
Expand Up @@ -13,8 +13,8 @@
Then { set_transport_destination_port.port_number == 100 }
end

describe '#type' do
Then { set_transport_destination_port.type == 10 }
describe '#action_type' do
Then { set_transport_destination_port.action_type == 10 }
end

describe '#message_length' do
Expand Down
4 changes: 2 additions & 2 deletions spec/pio/open_flow10/set_transport_source_port_spec.rb
Expand Up @@ -13,8 +13,8 @@
Then { set_transport_source_port.port_number == 100 }
end

describe '#type' do
Then { set_transport_source_port.type == 9 }
describe '#action_type' do
Then { set_transport_source_port.action_type == 9 }
end

describe '#message_length' do
Expand Down

0 comments on commit 556d858

Please sign in to comment.