Skip to content

Commit

Permalink
Rename SetIpTos -> SetTos
Browse files Browse the repository at this point in the history
refs #249
  • Loading branch information
yasuhito committed Oct 26, 2015
1 parent b9790da commit c76cda0
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
1 change: 1 addition & 0 deletions lib/pio/open_flow10.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
4 changes: 2 additions & 2 deletions lib/pio/open_flow10/actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions spec/pio/open_flow10/packet_out_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -257,21 +257,21 @@
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

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

Expand Down
30 changes: 0 additions & 30 deletions spec/pio/open_flow10/set_ip_tos_spec.rb

This file was deleted.

30 changes: 30 additions & 0 deletions spec/pio/open_flow10/set_tos_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c76cda0

Please sign in to comment.