diff --git a/CHANGELOG.md b/CHANGELOG.md index c63943ae..2b78c1cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### New features * [#201](https://github.com/trema/pio/pull/201): Add oxm experimenter support (OpenFlow1.3). * [#202](https://github.com/trema/pio/pull/202): Add `Pio::OpenFlow.switch_version` method. +* [#205](https://github.com/trema/pio/pull/205): Add new classes `Pio::OpenFlow10::Barrier::Request`, `Pio::OpenFlow10::Barrier::Reply`. ### Bugs fixed diff --git a/README.md b/README.md index e8b3d409..75207a93 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,8 @@ supports the following packet formats: - [Flow Mod](https://relishapp.com/trema/pio/docs/open-flow10/pio-flowmod) - [Port Status](https://relishapp.com/trema/pio/docs/open-flow10/pio-portstatus) - [Exact Match](https://relishapp.com/trema/pio/docs/open-flow10/pio-exactmatch) + - [Barrier Request](https://relishapp.com/trema/pio/docs/open-flow10/pio-barrier-request) + - [Barrier Reply](https://relishapp.com/trema/pio/docs/open-flow10/pio-barrier-reply) - OpenFlow 1.3 - [Hello](https://relishapp.com/trema/pio/docs/open-flow13/pio-hello) - [Echo Request](https://relishapp.com/trema/pio/docs/open-flow13/pio-echo-request) diff --git a/Rakefile b/Rakefile index e43b354b..b6dc7315 100644 --- a/Rakefile +++ b/Rakefile @@ -1,7 +1,7 @@ require 'bundler/gem_tasks' RELISH_PROJECT = 'trema/pio' -FLAY_THRESHOLD = 480 +FLAY_THRESHOLD = 526 task default: :travis task test: [:spec, :cucumber] diff --git a/features/open_flow10/barrier_reply.feature b/features/open_flow10/barrier_reply.feature new file mode 100644 index 00000000..a924f02a --- /dev/null +++ b/features/open_flow10/barrier_reply.feature @@ -0,0 +1,58 @@ +@open_flow10 +Feature: Pio::Barrier::Reply + Scenario: new + When I try to create an OpenFlow message with: + """ + Pio::Barrier::Reply.new + """ + Then it should finish successfully + And the message have the following fields and values: + | field | value | + | ofp_version | 1 | + | message_type | 19 | + | message_length | 8 | + | transaction_id | 0 | + | xid | 0 | + | body | | + + Scenario: new(transaction_id: 123) + When I try to create an OpenFlow message with: + """ + Pio::Barrier::Reply.new(transaction_id: 123) + """ + Then it should finish successfully + And the message have the following fields and values: + | field | value | + | ofp_version | 1 | + | message_type | 19 | + | message_length | 8 | + | transaction_id | 123 | + | xid | 123 | + | body | | + + Scenario: new(xid: 123) + When I try to create an OpenFlow message with: + """ + Pio::Barrier::Reply.new(xid: 123) + """ + Then it should finish successfully + And the message have the following fields and values: + | field | value | + | ofp_version | 1 | + | message_type | 19 | + | message_length | 8 | + | transaction_id | 123 | + | xid | 123 | + | body | | + + Scenario: read + When I try to parse a file named "open_flow10/barrier_reply.raw" with "Barrier::Reply" class + Then it should finish successfully + And the message have the following fields and values: + | field | value | + | ofp_version | 1 | + | message_type | 19 | + | message_length | 8 | + | transaction_id | 0 | + | xid | 0 | + | body | | diff --git a/features/open_flow10/barrier_request.feature b/features/open_flow10/barrier_request.feature new file mode 100644 index 00000000..4fc36191 --- /dev/null +++ b/features/open_flow10/barrier_request.feature @@ -0,0 +1,58 @@ +@open_flow10 +Feature: Pio::Barrier::Request + Scenario: new + When I try to create an OpenFlow message with: + """ + Pio::Barrier::Request.new + """ + Then it should finish successfully + And the message have the following fields and values: + | field | value | + | ofp_version | 1 | + | message_type | 18 | + | message_length | 8 | + | transaction_id | 0 | + | xid | 0 | + | body | | + + Scenario: new(transaction_id: 123) + When I try to create an OpenFlow message with: + """ + Pio::Barrier::Request.new(transaction_id: 123) + """ + Then it should finish successfully + And the message have the following fields and values: + | field | value | + | ofp_version | 1 | + | message_type | 18 | + | message_length | 8 | + | transaction_id | 123 | + | xid | 123 | + | body | | + + Scenario: new(xid: 123) + When I try to create an OpenFlow message with: + """ + Pio::Barrier::Request.new(xid: 123) + """ + Then it should finish successfully + And the message have the following fields and values: + | field | value | + | ofp_version | 1 | + | message_type | 18 | + | message_length | 8 | + | transaction_id | 123 | + | xid | 123 | + | body | | + + Scenario: read + When I try to parse a file named "open_flow10/barrier_request.raw" with "Barrier::Request" class + Then it should finish successfully + And the message have the following fields and values: + | field | value | + | ofp_version | 1 | + | message_type | 18 | + | message_length | 8 | + | transaction_id | 0 | + | xid | 0 | + | body | | diff --git a/lib/pio/open_flow.rb b/lib/pio/open_flow.rb index 61ea921c..32425e02 100644 --- a/lib/pio/open_flow.rb +++ b/lib/pio/open_flow.rb @@ -2,16 +2,15 @@ module Pio # OpenFlow specific types. module OpenFlow def self.set_class_name(klass_name, open_flow_module) - if Pio.__send__(:const_defined?, klass_name) - Pio.__send__ :remove_const, klass_name - end - Pio.__send__(:const_set, - klass_name, - Pio.const_get(open_flow_module).const_get(klass_name)) + return unless Pio.const_get(open_flow_module).const_defined?(klass_name) + Pio.__send__ :remove_const, klass_name if Pio.const_defined?(klass_name) + Pio.const_set(klass_name, + Pio.const_get(open_flow_module).const_get(klass_name)) nil end def self.switch_version(open_flow_module) + set_class_name :Barrier, open_flow_module set_class_name :Echo, open_flow_module set_class_name :Features, open_flow_module set_class_name :FlowMod, open_flow_module diff --git a/lib/pio/open_flow10.rb b/lib/pio/open_flow10.rb index 1e58d5e4..ce57b54a 100644 --- a/lib/pio/open_flow10.rb +++ b/lib/pio/open_flow10.rb @@ -1,3 +1,5 @@ +require 'pio/open_flow10/barrier_reply' +require 'pio/open_flow10/barrier_request' require 'pio/open_flow10/echo' require 'pio/open_flow10/exact_match' require 'pio/open_flow10/features' diff --git a/lib/pio/open_flow10/barrier_reply.rb b/lib/pio/open_flow10/barrier_reply.rb new file mode 100644 index 00000000..d5d6e6e6 --- /dev/null +++ b/lib/pio/open_flow10/barrier_reply.rb @@ -0,0 +1,21 @@ +require 'pio/open_flow/format' +require 'pio/open_flow/message' + +module Pio + # OpenFlow 1.0 messages + module OpenFlow10 + # OpenFlow 1.0 Barrier messages + module Barrier + # OpenFlow 1.0 Barrier Request message + class Reply < OpenFlow::Message + # OpenFlow 1.0 Barrier Request message format + class Format < BinData::Record + extend OpenFlow::Format + + header version: 1, message_type: 19 + string :body, value: '' + end + end + end + end +end diff --git a/lib/pio/open_flow10/barrier_request.rb b/lib/pio/open_flow10/barrier_request.rb new file mode 100644 index 00000000..ee904915 --- /dev/null +++ b/lib/pio/open_flow10/barrier_request.rb @@ -0,0 +1,22 @@ +require 'pio/open_flow/format' +require 'pio/open_flow/message' + +# Base module. +module Pio + # OpenFlow 1.0 messages + module OpenFlow10 + # OpenFlow 1.0 Barrier messages + module Barrier + # OpenFlow 1.0 Barrier Request message + class Request < OpenFlow::Message + # OpenFlow 1.0 Barrier Request message format + class Format < BinData::Record + extend OpenFlow::Format + + header version: 1, message_type: 18 + string :body, value: '' + end + end + end + end +end