Skip to content

Commit

Permalink
Add SetArpOperation action
Browse files Browse the repository at this point in the history
  • Loading branch information
yasuhito committed Nov 9, 2015
1 parent b9a713a commit e72eacb
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'bundler/gem_tasks'

RELISH_PROJECT = 'trema/pio'
FLAY_THRESHOLD = 1196
FLAY_THRESHOLD = 1245

task default: :travis
task test: [:spec, :cucumber]
Expand Down
16 changes: 8 additions & 8 deletions features/open_flow13/match.feature
Original file line number Diff line number Diff line change
Expand Up @@ -278,16 +278,16 @@ Feature: Pio::Match
| ip_protocol | 1 |
| icmpv4_code | 0 |

Scenario: new(eth_type: 2054, arp_op: 1)
Scenario: new(eth_type: 2054, arp_operation: 1)
When I try to create an OpenFlow message with:
"""
Pio::Match.new(ether_type: 2054, arp_op: 1)
Pio::Match.new(ether_type: 2054, arp_operation: 1)
"""
Then it should finish successfully
And the message has the following fields and values:
| field | value |
| ether_type | 2054 |
| arp_op | 1 |
| field | value |
| ether_type | 2054 |
| arp_operation | 1 |

Scenario: new(eth_type: 2054, arp_sender_protocol_address: '1.2.3.4')
When I try to create an OpenFlow message with:
Expand Down Expand Up @@ -655,9 +655,9 @@ Feature: Pio::Match
When I try to parse a file named "open_flow13/oxm_arp_op_field.raw" with "Pio::Match" class
Then it should finish successfully
And the message has the following fields and values:
| field | value |
| ether_type | 2054 |
| arp_op | 1 |
| field | value |
| ether_type | 2054 |
| arp_operation | 1 |

Scenario: read (file: open_flow13/oxm_arp_spa_field.raw)
When I try to parse a file named "open_flow13/oxm_arp_spa_field.raw" with "Pio::Match" class
Expand Down
14 changes: 14 additions & 0 deletions features/open_flow13/set_arp_operation.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@open_flow13
Feature: Pio::SetArpOperation

Scenario: new(Pio::Arp::Reply::OPERATION)
When I try to create an OpenFlow action with:
"""
Pio::SetArpOperation.new(Pio::Arp::Reply::OPERATION)
"""
Then it should finish successfully
And the action has the following fields and values:
| field | value |
| action_type | 25 |
| action_length | 16 |
| operation | 2 |
2 changes: 1 addition & 1 deletion lib/pio/open_flow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def self.switch_version(version)
:PacketIn, :FlowRemoved, :PacketOut, :SendOutPort,
:SetSourceMacAddress, :SetDestinationMacAddress, :PortStatus, :Stats,
:FlowStats, :DescriptionStats, :AggregateStats, :TableStats, :PortStats,
:QueueStats, :Error, :NiciraResubmit,
:QueueStats, :Error, :NiciraResubmit, :SetArpOperation,
:NiciraResubmitTable].each do |each|
set_message_class_name each, version
@version = version.to_s
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 @@ -14,6 +14,7 @@

# Actions
require 'pio/open_flow13/send_out_port'
require 'pio/open_flow13/set_arp_operation'
require 'pio/open_flow13/set_destination_mac_address'
require 'pio/open_flow13/set_source_mac_address'

Expand Down
12 changes: 6 additions & 6 deletions lib/pio/open_flow13/match.rb
Original file line number Diff line number Diff line change
Expand Up @@ -350,12 +350,12 @@ def length
end

# The value of OXM_OF_ARP_OP
class ArpOp < BinData::Record
class ArpOperation < BinData::Record
OXM_FIELD = 21

endian :big

uint16 :arp_op
uint16 :arp_operation

def length
2
Expand Down Expand Up @@ -597,7 +597,7 @@ class OpenflowBasic < BinData::Record
udp_destination_port UdpDestinationPort
sctp_source_port SctpSourcePort
sctp_destination_port SctpDestinationPort
arp_op ArpOp
arp_operation ArpOperation
arp_sender_protocol_address ArpSenderProtocolAddress
masked_arp_sender_protocol_address MaskedArpSenderProtocolAddress
arp_target_protocol_address ArpTargetProtocolAddress
Expand Down Expand Up @@ -676,8 +676,8 @@ def choose_tlv_value
Icmpv4Type
when Icmpv4Code::OXM_FIELD
Icmpv4Code
when ArpOp::OXM_FIELD
ArpOp
when ArpOperation::OXM_FIELD
ArpOperation
when ArpSenderProtocolAddress::OXM_FIELD
if masked?
MaskedArpSenderProtocolAddress
Expand Down Expand Up @@ -819,7 +819,7 @@ def initialize(user_attrs)
:ip_dscp, :ip_ecn, :tcp_source_port, :tcp_destination_port,
:udp_source_port, :udp_destination_port,
:sctp_source_port, :sctp_destination_port,
:icmpv4_type, :icmpv4_code, :arp_op].each do |each|
:icmpv4_type, :icmpv4_code, :arp_operation].each do |each|
next unless user_attrs.key?(each)
klass = Match.const_get(each.to_s.split('_').map(&:capitalize).join)
@match_fields << { class_payload:
Expand Down
23 changes: 23 additions & 0 deletions lib/pio/open_flow13/set_arp_operation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'pio/open_flow/action'
require 'pio/open_flow13/match'

module Pio
module OpenFlow13
# Set ARP operation field
class SetArpOperation < OpenFlow::Action
action_header action_type: 25, action_length: 16

uint16 :oxm_class, value: Match::OXM_CLASS_OPENFLOW_BASIC
bit7 :oxm_field, value: Match::ArpOperation::OXM_FIELD
bit1 :oxm_hasmask, value: 0
uint8 :oxm_length, value: 2
uint16 :operation
string :padding, length: 6
hide :padding

def initialize(operation)
super operation: operation
end
end
end
end
8 changes: 4 additions & 4 deletions spec/pio/open_flow13/match_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -404,15 +404,15 @@
And { match.match_fields[2].oxm_length == 1 }
end

context 'with ether_type: 0x0806, arp_op: 1' do
context 'with ether_type: 0x0806, arp_operation: 1' do
When(:match) do
Pio::OpenFlow13::Match.new(
ether_type: 0x0806,
arp_op: 1
arp_operation: 1
)
end
Then { match.ether_type == 0x0806 }
Then { match.arp_op == 1 }
Then { match.arp_operation == 1 }
And { match.class == Pio::OpenFlow13::Match }
And { match.length == 16 }
And { match.match_type == Pio::OpenFlow13::MATCH_TYPE_OXM }
Expand All @@ -424,7 +424,7 @@
end
And do
match.match_fields[1].oxm_field ==
Pio::OpenFlow13::Match::ArpOp::OXM_FIELD
Pio::OpenFlow13::Match::ArpOperation::OXM_FIELD
end
And { match.match_fields[1].masked? == false }
And { match.match_fields[1].oxm_length == 2 }
Expand Down

0 comments on commit e72eacb

Please sign in to comment.