From 6e3ec7f3e89c028ba5de402d2e5c481c1792f715 Mon Sep 17 00:00:00 2001 From: Yasuhito Takamiya Date: Tue, 27 Oct 2015 17:01:09 +0900 Subject: [PATCH] Add PortStats::Request class. Refs #235 --- .../open_flow10/port_stats_request.feature | 48 ++++++++++++++++++ features/open_flow10/port_stats_request.raw | Bin 12 -> 20 bytes lib/pio/open_flow.rb | 2 +- lib/pio/open_flow10.rb | 1 + lib/pio/open_flow10/port_stats/request.rb | 25 +++++++++ lib/pio/open_flow10/stats_request.rb | 4 +- 6 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 features/open_flow10/port_stats_request.feature create mode 100644 lib/pio/open_flow10/port_stats/request.rb 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 285575885352e3cedc02e603477d75e852cb963a..a06b498e5f775d2d8efea87bf425cb061044ceef 100644 GIT binary patch literal 20 YcmZP+U=U$oV5nwbVPN?GAIJg%02l}YqW}N^ literal 12 TcmZP+VBle3VBlw9W?%pS0f+!F 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.