-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Delete Enqueue::Format class using Pio::OpenFlow::Action. Refs #253.
- Loading branch information
Showing
5 changed files
with
43 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,43 @@ | ||
require 'bindata' | ||
require 'forwardable' | ||
require 'pio/monkey_patch/integer' | ||
require 'pio/open_flow/action' | ||
require 'pio/open_flow10/port16' | ||
|
||
module Pio | ||
# An action to enqueue the packet on the specified queue attached to | ||
# a port. | ||
class Enqueue | ||
# OpenFlow 1.0 OFPAT_ENQUEUE action format. | ||
class Format < BinData::Record | ||
endian :big | ||
|
||
uint16 :action_type, value: 11 | ||
uint16 :action_length, value: 16 | ||
module OpenFlow10 | ||
# An action to enqueue the packet on the specified queue attached | ||
# to a port. | ||
class Enqueue < OpenFlow::Action | ||
action_header action_type: 11, action_length: 16 | ||
port16 :port | ||
uint48 :padding | ||
string :padding, length: 6 | ||
hide :padding | ||
uint32 :queue_id | ||
end | ||
|
||
def self.read(raw_data) | ||
enqueue = allocate | ||
enqueue.instance_variable_set :@format, Format.read(raw_data) | ||
enqueue | ||
end | ||
|
||
extend Forwardable | ||
|
||
def_delegators :@format, :action_type | ||
def_delegator :@format, :action_length, :length | ||
def_delegators :@format, :port | ||
def_delegators :@format, :queue_id | ||
def_delegator :@format, :to_binary_s, :to_binary | ||
|
||
def initialize(user_options) | ||
validate_port user_options | ||
validate_queue_id user_options | ||
@format = Format.new(user_options) | ||
end | ||
def initialize(user_options) | ||
validate_port user_options | ||
validate_queue_id user_options | ||
super(user_options) | ||
end | ||
|
||
private | ||
private | ||
|
||
def validate_port(user_options) | ||
port = user_options.fetch(:port) | ||
if port.is_a?(Symbol) && port != :in_port | ||
fail(ArgumentError, | ||
':port must be a valid physical port or :in_port') | ||
def validate_port(user_options) | ||
port = user_options.fetch(:port) | ||
if port.is_a?(Symbol) && port != :in_port | ||
fail(ArgumentError, | ||
':port must be a valid physical port or :in_port') | ||
end | ||
rescue KeyError | ||
raise ArgumentError, ':port is a mandatory option' | ||
end | ||
rescue KeyError | ||
raise ArgumentError, ':port is a mandatory option' | ||
end | ||
|
||
def validate_queue_id(user_options) | ||
unless user_options.fetch(:queue_id).unsigned_32bit? | ||
fail ArgumentError, ':queue_id must be an unsigned 32-bit integer' | ||
def validate_queue_id(user_options) | ||
unless user_options.fetch(:queue_id).unsigned_32bit? | ||
fail ArgumentError, ':queue_id must be an unsigned 32-bit integer' | ||
end | ||
rescue KeyError | ||
raise ArgumentError, ':queue_id is a mandatory option' | ||
end | ||
rescue KeyError | ||
raise ArgumentError, ':queue_id is a mandatory option' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters