-
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.
- Loading branch information
Showing
19 changed files
with
305 additions
and
283 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
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,8 +1,8 @@ | ||
require 'pio/open_flow' | ||
|
||
# Base module. | ||
module Pio | ||
# @!parse | ||
# # OpenFlow 1.0 Hello message | ||
# class Hello < OpenFlow::Message; end | ||
class Hello < OpenFlow::Message.factory(Pio::OpenFlow::Type::HELLO); end | ||
# OpenFlow 1.0 Hello message | ||
class Hello; end | ||
OpenFlow::Message.factory(Hello, OpenFlow::HELLO) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,22 @@ | ||
module Pio | ||
# OpenFlow specific types. | ||
module OpenFlow | ||
# OFPT_* constants. | ||
HELLO = 0 | ||
ECHO_REQUEST = 2 | ||
ECHO_REPLY = 3 | ||
FEATURES_REQUEST = 5 | ||
FEATURES_REPLY = 6 | ||
PACKET_IN = 10 | ||
PORT_STATUS = 12 | ||
PACKET_OUT = 13 | ||
FLOW_MOD = 14 | ||
end | ||
end | ||
|
||
require 'pio/open_flow/actions' | ||
require 'pio/open_flow/flags' | ||
require 'pio/open_flow/message' | ||
require 'pio/open_flow/open_flow_header' | ||
require 'pio/open_flow/phy_port' | ||
require 'pio/open_flow/port_number' | ||
require 'pio/open_flow/type' |
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,55 +1,61 @@ | ||
# bitmap functions. | ||
# This class smells of :reek:DataClump | ||
module Flags | ||
def flags_32bit(name, flags) | ||
_def_flags name, 32, flags | ||
end | ||
module Pio | ||
module OpenFlow | ||
# bitmap functions. | ||
# This class smells of :reek:DataClump | ||
module Flags | ||
def flags_32bit(name, flags) | ||
_def_flags name, 32, flags | ||
end | ||
|
||
def flags_16bit(name, flags) | ||
_def_flags name, 16, flags | ||
end | ||
def flags_16bit(name, flags) | ||
_def_flags name, 16, flags | ||
end | ||
|
||
# rubocop:disable MethodLength | ||
# This method smells of :reek:TooManyStatements | ||
def _def_flags(name, size, flags) | ||
flag_value = case flags | ||
when Array | ||
shift = 0 | ||
flags.each_with_object({}) do |each, result| | ||
result[each] = 1 << shift | ||
shift += 1 | ||
result | ||
end | ||
when Hash | ||
flags | ||
end | ||
# rubocop:disable MethodLength | ||
# This method smells of :reek:TooManyStatements | ||
def _def_flags(name, size, flags) | ||
flag_value = case flags | ||
when Array | ||
shift = 0 | ||
flags.each_with_object({}) do |each, result| | ||
result[each] = 1 << shift | ||
shift += 1 | ||
result | ||
end | ||
when Hash | ||
flags | ||
end | ||
|
||
klass_name = name.to_s.split('_').map(&:capitalize).join | ||
flags_hash = flag_value.inspect | ||
klass_name = name.to_s.split('_').map(&:capitalize).join | ||
flags_hash = flag_value.inspect | ||
|
||
code = %{ | ||
class #{klass_name} < BinData::Primitive | ||
endian :big | ||
code = %{ | ||
class #{klass_name} < BinData::Primitive | ||
endian :big | ||
uint#{size} :#{name} | ||
uint#{size} :#{name} | ||
def get | ||
list = #{flags_hash} | ||
list.each_with_object([]) do |(key, value), result| | ||
result << key if #{name} & value != 0 | ||
result | ||
end | ||
end | ||
def get | ||
list = #{flags_hash} | ||
list.each_with_object([]) do |(key, value), result| | ||
result << key if #{name} & value != 0 | ||
result | ||
end | ||
end | ||
def set(v) | ||
list = #{flags_hash} | ||
v.each do |each| | ||
fail "Invalid state flag: \#{v}" unless list.keys.include?(each) | ||
def set(v) | ||
list = #{flags_hash} | ||
v.each do |each| | ||
fail "Invalid state flag: \#{v}" unless list.keys.include?(each) | ||
end | ||
self.#{name} = v.empty? ? | ||
0 : | ||
v.map { |each| list[each] }.inject(:|) | ||
end | ||
end | ||
self.#{name} = v.empty? ? 0 : v.map { |each| list[each] }.inject(:|) | ||
end | ||
} | ||
module_eval code | ||
end | ||
} | ||
module_eval code | ||
end | ||
end | ||
end |
Oops, something went wrong.