Skip to content

Commit

Permalink
Add Pio::OpenFlow13::Error::BadRequest.
Browse files Browse the repository at this point in the history
  • Loading branch information
yasuhito committed Aug 19, 2015
1 parent 4bd4fda commit f571f7a
Show file tree
Hide file tree
Showing 18 changed files with 199 additions and 82 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ supports the following packet formats:
- OpenFlow 1.3
- [Hello](https://relishapp.com/trema/pio/docs/open-flow13/pio-hello)
- [HelloFailed](https://relishapp.com/trema/pio/docs/open-flow13/pio-error-hellofailed)
- [BadRequest](https://relishapp.com/trema/pio/docs/open-flow13/pio-error-badrequest)
- [Echo Request](https://relishapp.com/trema/pio/docs/open-flow13/pio-echo-request)
- [Echo Reply](https://relishapp.com/trema/pio/docs/open-flow13/pio-echo-reply)
- [Features Request](https://relishapp.com/trema/pio/docs/open-flow13/pio-features-request)
Expand Down
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 = 481
FLAY_THRESHOLD = 575

task default: :travis
task test: [:spec, :cucumber]
Expand Down
1 change: 1 addition & 0 deletions features/.nav
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- open_flow13:
- hello.feature
- hello_failed.feature
- bad_request.feature
- echo_request.feature
- echo_reply.feature
- features_request.feature
Expand Down
35 changes: 35 additions & 0 deletions features/open_flow13/bad_request.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@open_flow13
Feature: Pio::Error::BadRequest

Request was not understood error.

Scenario: new (raw_data = Echo request 1.0)
When I try to create an OpenFlow message with:
"""
Pio::Error::BadRequest.new(raw_data: Pio::OpenFlow10::Echo::Request.new.to_binary)
"""
Then it should finish successfully
And the message has the following fields and values:
| field | value |
| ofp_version | 4 |
| message_type | 1 |
| message_length | 20 |
| transaction_id | 0 |
| xid | 0 |
| error_type | :bad_request |
| error_code | :bad_version |
| raw_data.length | 8 |

Scenario: read
When I try to parse a file named "open_flow13/bad_request.raw" with "Pio::Error::BadRequest" class
Then it should finish successfully
And the message has the following fields and values:
| field | value |
| ofp_version | 4 |
| message_type | 1 |
| message_length | 20 |
| transaction_id | 0 |
| xid | 0 |
| error_type | :bad_request |
| error_code | :bad_version |
| raw_data.length | 8 |
Binary file added features/open_flow13/bad_request.raw
Binary file not shown.
4 changes: 2 additions & 2 deletions lib/pio/open_flow10.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
require 'pio/open_flow10/bad_request'
require 'pio/open_flow10/barrier_reply'
require 'pio/open_flow10/barrier_request'
require 'pio/open_flow10/echo'
require 'pio/open_flow10/error'
require 'pio/open_flow10/error/bad_request'
require 'pio/open_flow10/error/hello_failed'
require 'pio/open_flow10/exact_match'
require 'pio/open_flow10/features'
require 'pio/open_flow10/flow_mod'
require 'pio/open_flow10/flow_stats_reply'
require 'pio/open_flow10/flow_stats_request'
require 'pio/open_flow10/hello'
require 'pio/open_flow10/hello_failed'
require 'pio/open_flow10/packet_in'
require 'pio/open_flow10/packet_out'
require 'pio/open_flow10/port_status'
Expand Down
2 changes: 2 additions & 0 deletions lib/pio/open_flow10/error.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'pio/open_flow10/error/error_type10'

module Pio
module OpenFlow10
# Error message parser
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'bindata'
require 'pio/open_flow/format'
require 'pio/open_flow/message'
require 'pio/open_flow10/error_type10'
require 'pio/open_flow10/error/error_type10'

module Pio
module OpenFlow10
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'pio/open_flow/format'
require 'pio/open_flow/hello_failed_code'
require 'pio/open_flow/message'
require 'pio/open_flow10/error_type10'
require 'pio/open_flow10/error/error_type10'

module Pio
module OpenFlow10
Expand Down
3 changes: 2 additions & 1 deletion lib/pio/open_flow13.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
require 'pio/open_flow13/apply'
require 'pio/open_flow13/echo'
require 'pio/open_flow13/error/bad_request'
require 'pio/open_flow13/error/hello_failed'
require 'pio/open_flow13/features_reply'
require 'pio/open_flow13/features_request'
require 'pio/open_flow13/flow_mod'
require 'pio/open_flow13/goto_table'
require 'pio/open_flow13/hello'
require 'pio/open_flow13/hello_failed'
require 'pio/open_flow13/meter'
require 'pio/open_flow13/packet_in'
require 'pio/open_flow13/packet_out'
Expand Down
66 changes: 66 additions & 0 deletions lib/pio/open_flow13/error/bad_request.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
require 'pio/open_flow/format'
require 'pio/open_flow/message'
require 'pio/open_flow13/error/error_type13'

module Pio
module OpenFlow13
module Error
# Bad request error.
class BadRequest < OpenFlow::Message
# Bad request error format.
class Format < BinData::Record
# enum ofp_bad_request_code
class BadRequestCode < BinData::Primitive
ERROR_CODES = {
bad_version: 0,
bad_type: 1,
bad_multipart: 2,
bad_experimenter: 3,
bad_experimenter_type: 4,
permissions_error: 5,
bad_length: 6,
buffer_empty: 7,
buffer_unknown: 8,
bad_table_id: 9,
controller_is_slave: 10,
bad_port: 11,
bad_packet: 12,
multipart_buffer_overflow: 13
}

endian :big
uint16 :error_code

def get
ERROR_CODES.invert.fetch(error_code)
end

def set(value)
self.error_code = ERROR_CODES.fetch(value)
end
end

# Bad request error body.
class Body < BinData::Record
endian :big

error_type13 :error_type, value: -> { :bad_request }
bad_request_code :error_code
rest :raw_data

def length
4 + raw_data.length
end
end

extend OpenFlow::Format

header version: 4, message_type: 1
body :body
end

body_option :raw_data
end
end
end
end
37 changes: 37 additions & 0 deletions lib/pio/open_flow13/error/error_type13.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module Pio
module OpenFlow13
module Error
# enum ofp_error_type
class ErrorType13 < BinData::Primitive
ERROR_TYPES = {
hello_failed: 0,
bad_request: 1,
bad_action: 2,
bad_instruction: 3,
bad_match: 4,
flow_mod_failed: 5,
group_mod_failed: 6,
port_mod_failed: 7,
table_mod_failed: 8,
queue_operation_failed: 9,
switch_config_failed: 10,
role_request_failed: 11,
meter_mod_failed: 12,
table_features_failed: 13,
experimenter: 0xffff
}

endian :big
uint16 :error_type

def get
ERROR_TYPES.invert.fetch(error_type)
end

def set(value)
self.error_type = ERROR_TYPES.fetch(value)
end
end
end
end
end
42 changes: 42 additions & 0 deletions lib/pio/open_flow13/error/hello_failed.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require 'pio/open_flow/hello_failed_code'
require 'pio/open_flow/format'
require 'pio/open_flow/message'

# Base module.
module Pio
# OpenFlow 1.3 messages
module OpenFlow13
module Error
# Hello Failed error message
class HelloFailed < OpenFlow::Message
# Hello Failed error format.
class Format < BinData::Record
# Hello Failed error body.
class Body < BinData::Record
endian :big

error_type13 :error_type
hello_failed_code :error_code
rest :description

def length
4 + description.length
end
end

extend OpenFlow::Format

header version: 4, message_type: 1
body :body

def length
8 + body.length
end
end

body_option :error_code
body_option :description
end
end
end
end
74 changes: 0 additions & 74 deletions lib/pio/open_flow13/hello_failed.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'pio/open_flow10/hello_failed'
require 'pio/open_flow10/error/hello_failed'

describe Pio::OpenFlow10::Error::HelloFailed do
it_should_behave_like('an OpenFlow message',
Expand Down
6 changes: 6 additions & 0 deletions spec/pio/open_flow13/error/bad_request_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require 'pio/open_flow13/error/bad_request'

describe Pio::OpenFlow13::Error::BadRequest do
it_should_behave_like('an OpenFlow message',
Pio::OpenFlow13::Error::BadRequest)
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'pio/open_flow13/hello_failed'
require 'pio/open_flow13/error/hello_failed'

describe Pio::OpenFlow13::Error::HelloFailed do
it_should_behave_like('an OpenFlow message',
Expand Down

0 comments on commit f571f7a

Please sign in to comment.