From c76cda054775ff88b7d8ce162994c264974d6b1c Mon Sep 17 00:00:00 2001 From: Yasuhito Takamiya Date: Mon, 26 Oct 2015 17:31:01 +0900 Subject: [PATCH] Rename SetIpTos -> SetTos refs #249 --- .../{set_ip_tos.feature => set_tos.feature} | 4 +-- lib/pio/open_flow10.rb | 1 + lib/pio/open_flow10/actions.rb | 4 +-- .../open_flow10/{set_ip_tos.rb => set_tos.rb} | 8 ++--- spec/pio/open_flow10/packet_out_spec.rb | 6 ++-- spec/pio/open_flow10/set_ip_tos_spec.rb | 30 ------------------- spec/pio/open_flow10/set_tos_spec.rb | 30 +++++++++++++++++++ 7 files changed, 42 insertions(+), 41 deletions(-) rename features/open_flow10/{set_ip_tos.feature => set_tos.feature} (80%) rename lib/pio/open_flow10/{set_ip_tos.rb => set_tos.rb} (82%) delete mode 100644 spec/pio/open_flow10/set_ip_tos_spec.rb create mode 100644 spec/pio/open_flow10/set_tos_spec.rb diff --git a/features/open_flow10/set_ip_tos.feature b/features/open_flow10/set_tos.feature similarity index 80% rename from features/open_flow10/set_ip_tos.feature rename to features/open_flow10/set_tos.feature index ccec567d..b2738109 100644 --- a/features/open_flow10/set_ip_tos.feature +++ b/features/open_flow10/set_tos.feature @@ -1,10 +1,10 @@ @open_flow10 -Feature: Pio::OpenFlow10::SetIpTos +Feature: Pio::OpenFlow10::SetTos Scenario: new(0b11111100) When I try to create an OpenFlow action with: """ - Pio::OpenFlow10::SetIpTos.new(0b11111100) + Pio::OpenFlow10::SetTos.new(0b11111100) """ Then it should finish successfully And the action has the following fields and values: diff --git a/lib/pio/open_flow10.rb b/lib/pio/open_flow10.rb index 87446894..3695d1cb 100644 --- a/lib/pio/open_flow10.rb +++ b/lib/pio/open_flow10.rb @@ -28,6 +28,7 @@ require 'pio/open_flow10/nicira_resubmit' require 'pio/open_flow10/nicira_resubmit_table' require 'pio/open_flow10/send_out_port' +require 'pio/open_flow10/set_tos' require 'pio/open_flow10/set_vlan_priority' require 'pio/open_flow10/set_vlan_vid' diff --git a/lib/pio/open_flow10/actions.rb b/lib/pio/open_flow10/actions.rb index 44e3df81..56605e5b 100644 --- a/lib/pio/open_flow10/actions.rb +++ b/lib/pio/open_flow10/actions.rb @@ -3,7 +3,7 @@ require 'pio/open_flow10/send_out_port' require 'pio/open_flow10/set_ether_address' require 'pio/open_flow10/set_ip_address' -require 'pio/open_flow10/set_ip_tos' +require 'pio/open_flow10/set_tos' require 'pio/open_flow10/set_transport_port' require 'pio/open_flow10/set_vlan_priority' require 'pio/open_flow10/set_vlan_vid' @@ -23,7 +23,7 @@ class Actions < BinData::Primitive 5 => Pio::OpenFlow10::SetEtherDestinationAddress, 6 => Pio::OpenFlow10::SetIpSourceAddress, 7 => Pio::OpenFlow10::SetIpDestinationAddress, - 8 => Pio::OpenFlow10::SetIpTos, + 8 => Pio::OpenFlow10::SetTos, 9 => Pio::OpenFlow10::SetTransportSourcePort, 10 => Pio::OpenFlow10::SetTransportDestinationPort, 11 => Pio::OpenFlow10::Enqueue, diff --git a/lib/pio/open_flow10/set_ip_tos.rb b/lib/pio/open_flow10/set_tos.rb similarity index 82% rename from lib/pio/open_flow10/set_ip_tos.rb rename to lib/pio/open_flow10/set_tos.rb index 725d7650..85d38f6a 100644 --- a/lib/pio/open_flow10/set_ip_tos.rb +++ b/lib/pio/open_flow10/set_tos.rb @@ -4,16 +4,16 @@ module Pio module OpenFlow10 # An action to modify the IP ToS/DSCP field of a packet. - class SetIpTos < OpenFlow::Action + class SetTos < OpenFlow::Action action_header action_type: 8, action_length: 8 uint8 :type_of_service string :padding, length: 3 hide :padding def initialize(type_of_service) - # ip_tos (IP ToS) value consists of 8 bits, of which only the 6 - # high-order bits belong to DSCP, the 2 low-order bits must be - # zero. + # ip_tos (IP ToS) value consists of 8 bits, of which only the + # 6 high-order bits belong to DSCP, the 2 low-order bits must + # be zero. unless type_of_service.unsigned_8bit? && type_of_service % 4 == 0 fail ArgumentError, 'Invalid type_of_service (ToS) value.' end diff --git a/spec/pio/open_flow10/packet_out_spec.rb b/spec/pio/open_flow10/packet_out_spec.rb index 9d73e0b6..62928be6 100644 --- a/spec/pio/open_flow10/packet_out_spec.rb +++ b/spec/pio/open_flow10/packet_out_spec.rb @@ -257,13 +257,13 @@ Then { result.actions[0].ip_address == '1.2.3.4' } end - context 'with a SetIpTos action' do + context 'with a SetTos action' do When(:user_options) do { transaction_id: 0x16, buffer_id: 0xffffffff, in_port: 0xffff, - actions: Pio::OpenFlow10::SetIpTos.new(32), + actions: Pio::OpenFlow10::SetTos.new(32), raw_data: data_dump } end @@ -271,7 +271,7 @@ Then { result.message_length == 0x58 } Then { result.actions_len == 0x8 } Then { result.actions.length == 1 } - Then { result.actions[0].is_a? Pio::OpenFlow10::SetIpTos } + Then { result.actions[0].is_a? Pio::OpenFlow10::SetTos } Then { result.actions[0].type_of_service == 32 } end diff --git a/spec/pio/open_flow10/set_ip_tos_spec.rb b/spec/pio/open_flow10/set_ip_tos_spec.rb deleted file mode 100644 index f664b2b7..00000000 --- a/spec/pio/open_flow10/set_ip_tos_spec.rb +++ /dev/null @@ -1,30 +0,0 @@ -require 'pio/open_flow10/set_ip_tos' - -describe Pio::OpenFlow10::SetIpTos do - describe '.new' do - context 'with 32' do - When(:set_ip_tos) { Pio::OpenFlow10::SetIpTos.new(32) } - - describe '#type_of_service' do - Then { set_ip_tos.type_of_service == 32 } - end - - describe '#action_type' do - Then { set_ip_tos.action_type == 8 } - end - - describe '#action_length' do - Then { set_ip_tos.action_length == 8 } - end - - describe '#to_binary' do - Then { set_ip_tos.to_binary.length == 8 } - end - end - - context 'with 1' do - When(:set_ip_tos) { Pio::OpenFlow10::SetIpTos.new(1) } - Then { set_ip_tos == Failure(ArgumentError) } - end - end -end diff --git a/spec/pio/open_flow10/set_tos_spec.rb b/spec/pio/open_flow10/set_tos_spec.rb new file mode 100644 index 00000000..b01eed57 --- /dev/null +++ b/spec/pio/open_flow10/set_tos_spec.rb @@ -0,0 +1,30 @@ +require 'pio/open_flow10/set_tos' + +describe Pio::OpenFlow10::SetTos do + describe '.new' do + context 'with 32' do + When(:set_tos) { Pio::OpenFlow10::SetTos.new(32) } + + describe '#type_of_service' do + Then { set_tos.type_of_service == 32 } + end + + describe '#action_type' do + Then { set_tos.action_type == 8 } + end + + describe '#action_length' do + Then { set_tos.action_length == 8 } + end + + describe '#to_binary' do + Then { set_tos.to_binary.length == 8 } + end + end + + context 'with 1' do + When(:set_tos) { Pio::OpenFlow10::SetTos.new(1) } + Then { set_tos == Failure(ArgumentError) } + end + end +end