From e72eacbffa55e17479af4e43df00e0946be944f7 Mon Sep 17 00:00:00 2001 From: Yasuhito Takamiya Date: Mon, 9 Nov 2015 10:25:59 +0900 Subject: [PATCH] Add SetArpOperation action --- Rakefile | 2 +- features/open_flow13/match.feature | 16 ++++++------- .../open_flow13/set_arp_operation.feature | 14 +++++++++++ lib/pio/open_flow.rb | 2 +- lib/pio/open_flow13.rb | 1 + lib/pio/open_flow13/match.rb | 12 +++++----- lib/pio/open_flow13/set_arp_operation.rb | 23 +++++++++++++++++++ spec/pio/open_flow13/match_spec.rb | 8 +++---- 8 files changed, 58 insertions(+), 20 deletions(-) create mode 100644 features/open_flow13/set_arp_operation.feature create mode 100644 lib/pio/open_flow13/set_arp_operation.rb diff --git a/Rakefile b/Rakefile index a76252f4..ba3d3501 100644 --- a/Rakefile +++ b/Rakefile @@ -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] diff --git a/features/open_flow13/match.feature b/features/open_flow13/match.feature index d485d43a..b6e4de4d 100644 --- a/features/open_flow13/match.feature +++ b/features/open_flow13/match.feature @@ -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: @@ -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 diff --git a/features/open_flow13/set_arp_operation.feature b/features/open_flow13/set_arp_operation.feature new file mode 100644 index 00000000..9086b17e --- /dev/null +++ b/features/open_flow13/set_arp_operation.feature @@ -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 | diff --git a/lib/pio/open_flow.rb b/lib/pio/open_flow.rb index 5b4d630f..f3db262c 100644 --- a/lib/pio/open_flow.rb +++ b/lib/pio/open_flow.rb @@ -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 diff --git a/lib/pio/open_flow13.rb b/lib/pio/open_flow13.rb index 8e830fd4..b10aa06c 100644 --- a/lib/pio/open_flow13.rb +++ b/lib/pio/open_flow13.rb @@ -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' diff --git a/lib/pio/open_flow13/match.rb b/lib/pio/open_flow13/match.rb index 32f9857a..ca5e019d 100644 --- a/lib/pio/open_flow13/match.rb +++ b/lib/pio/open_flow13/match.rb @@ -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 @@ -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 @@ -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 @@ -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: diff --git a/lib/pio/open_flow13/set_arp_operation.rb b/lib/pio/open_flow13/set_arp_operation.rb new file mode 100644 index 00000000..678ac8ed --- /dev/null +++ b/lib/pio/open_flow13/set_arp_operation.rb @@ -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 diff --git a/spec/pio/open_flow13/match_spec.rb b/spec/pio/open_flow13/match_spec.rb index f246532b..2bd9bc00 100644 --- a/spec/pio/open_flow13/match_spec.rb +++ b/spec/pio/open_flow13/match_spec.rb @@ -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 } @@ -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 }