diff --git a/CHANGELOG.md b/CHANGELOG.md index bc5282ae..a3473af7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### New features * [#250](https://github.com/trema/pio/pull/250): Add Flow Removed message parser. * [#251](https://github.com/trema/pio/pull/251): Add Table Stats Request message generator. +* [#266](https://github.com/trema/pio/pull/266): Add Port Stats Request message generator. ### Changes * [#265](https://github.com/trema/pio/pull/265): Rename `SetIpTos` -> `SetTos`. diff --git a/features/open_flow10/port_stats_request.feature b/features/open_flow10/port_stats_request.feature new file mode 100644 index 00000000..57b45396 --- /dev/null +++ b/features/open_flow10/port_stats_request.feature @@ -0,0 +1,48 @@ +Feature: Pio::OpenFlow10::PortStats::Request + @open_flow10 + Scenario: new(:none) + When I try to create an OpenFlow message with: + """ + Pio::OpenFlow10::PortStats::Request.new(:none) + """ + Then it should finish successfully + And the message has the following fields and values: + | field | value | + | ofp_version | 1 | + | message_type | 16 | + | message_length | 20 | + | transaction_id | 0 | + | xid | 0 | + | stats_type | :port | + | port | :none | + + @open_flow10 + Scenario: new(:none, transaction_id: 123) + When I try to create an OpenFlow message with: + """ + Pio::OpenFlow10::PortStats::Request.new(:none, transaction_id: 123) + """ + Then it should finish successfully + And the message has the following fields and values: + | field | value | + | ofp_version | 1 | + | message_type | 16 | + | message_length | 20 | + | transaction_id | 123 | + | xid | 123 | + | stats_type | :port | + | port | :none | + + @open_flow10 + Scenario: read + When I try to parse a file named "open_flow10/port_stats_request.raw" with "PortStats::Request" class + Then it should finish successfully + And the message has the following fields and values: + | field | value | + | ofp_version | 1 | + | message_type | 16 | + | message_length | 20 | + | transaction_id | 123 | + | xid | 123 | + | stats_type | :port | + | port | :none | diff --git a/features/open_flow10/port_stats_request.raw b/features/open_flow10/port_stats_request.raw index 28557588..a06b498e 100644 Binary files a/features/open_flow10/port_stats_request.raw and b/features/open_flow10/port_stats_request.raw differ diff --git a/lib/pio/open_flow.rb b/lib/pio/open_flow.rb index 5f10098c..8009a452 100644 --- a/lib/pio/open_flow.rb +++ b/lib/pio/open_flow.rb @@ -18,7 +18,7 @@ def self.switch_version(version) [:Barrier, :Echo, :Features, :FlowMod, :Hello, :Match, :PacketIn, :FlowRemoved, :PacketOut, :SendOutPort, :PortStatus, :Stats, :FlowStats, :DescriptionStats, :AggregateStats, - :TableStats, :Error, :NiciraResubmit, + :TableStats, :PortStats, :Error, :NiciraResubmit, :NiciraResubmitTable].each do |each| set_message_class_name each, version @version = version.to_s diff --git a/lib/pio/open_flow10.rb b/lib/pio/open_flow10.rb index 3695d1cb..5f9c955e 100644 --- a/lib/pio/open_flow10.rb +++ b/lib/pio/open_flow10.rb @@ -19,6 +19,7 @@ require 'pio/open_flow10/hello' require 'pio/open_flow10/packet_in' require 'pio/open_flow10/packet_out' +require 'pio/open_flow10/port_stats/request' require 'pio/open_flow10/port_status' require 'pio/open_flow10/stats_reply' require 'pio/open_flow10/stats_request' diff --git a/lib/pio/open_flow10/port_stats/request.rb b/lib/pio/open_flow10/port_stats/request.rb new file mode 100644 index 00000000..59c1383e --- /dev/null +++ b/lib/pio/open_flow10/port_stats/request.rb @@ -0,0 +1,25 @@ +require 'pio/open_flow/message' + +module Pio + module OpenFlow10 + # Port Stats messages + class PortStats + # Port Stats Request message + class Request < OpenFlow::Message + open_flow_header version: 1, + message_type: 16, + message_length: 20 + + stats_type :stats_type, value: -> { :port } + uint16 :flags + port16 :port + string :padding, length: 6 + hide :padding + + def initialize(port, user_options = {}) + super({ port: port }.merge user_options) + end + end + end + end +end diff --git a/lib/pio/open_flow10/stats_request.rb b/lib/pio/open_flow10/stats_request.rb index a47cf87f..8ec47469 100644 --- a/lib/pio/open_flow10/stats_request.rb +++ b/lib/pio/open_flow10/stats_request.rb @@ -1,4 +1,5 @@ require 'pio/open_flow10/table_stats/request' +require 'pio/open_flow10/port_stats/request' require 'pio/open_flow/message' module Pio @@ -10,7 +11,8 @@ class Request description: OpenFlow10::DescriptionStats::Request, flow: OpenFlow10::FlowStats::Request, aggregate: OpenFlow10::AggregateStats::Request, - table: OpenFlow10::TableStats::Request + table: OpenFlow10::TableStats::Request, + port: OpenFlow10::PortStats::Request } # Stats request format.