Class: Pio::OpenFlow::Message
- Inherits:
-
Object
- Object
- Pio::OpenFlow::Message
- Extended by:
- ActiveSupport::DescendantsTracker, Flags
- Defined in:
- lib/pio/open_flow/message.rb
Overview
OpenFlow messages.
Direct Known Subclasses
Pio::OpenFlow10::AggregateStats::Reply, Pio::OpenFlow10::AggregateStats::Request, Pio::OpenFlow10::Barrier::Reply, Pio::OpenFlow10::Barrier::Request, Pio::OpenFlow10::DescriptionStats::Reply, Pio::OpenFlow10::DescriptionStats::Request, Pio::OpenFlow10::Echo::Reply, Pio::OpenFlow10::Echo::Request, Pio::OpenFlow10::Error::BadRequest, Pio::OpenFlow10::Error::HelloFailed, Pio::OpenFlow10::Features::Reply, Pio::OpenFlow10::Features::Request, Pio::OpenFlow10::FlowMod, Pio::OpenFlow10::FlowRemoved, Pio::OpenFlow10::FlowStats::Reply, Pio::OpenFlow10::FlowStats::Request, Pio::OpenFlow10::Hello, Pio::OpenFlow10::PacketIn, Pio::OpenFlow10::PacketOut, Pio::OpenFlow10::PortStats::Request, Pio::OpenFlow10::PortStatus, Pio::OpenFlow10::QueueStats::Request, Pio::OpenFlow10::Stats::Reply, Pio::OpenFlow10::Stats::Request, Pio::OpenFlow10::TableStats::Request, Pio::OpenFlow13::Echo::Reply, Pio::OpenFlow13::Echo::Request, Pio::OpenFlow13::Error::BadRequest, Pio::OpenFlow13::Error::HelloFailed, Pio::OpenFlow13::Features::Reply, Pio::OpenFlow13::Features::Request, Pio::OpenFlow13::FlowMod, Pio::OpenFlow13::Hello, Pio::OpenFlow13::PacketIn, Pio::OpenFlow13::PacketOut, Pio::OpenFlow13::StatsRequest
Instance Attribute Summary collapse
-
#format ⇒ Object
readonly
Returns the value of attribute format.
Class Method Summary collapse
-
.method_missing(method, *args, &block) ⇒ Object
rubocop:disable MethodLength rubocop:disable AbcSize.
-
.open_flow_header(opts) ⇒ Object
rubocop:disable AbcSize rubocop:disable MethodLength.
- .read(raw_data) ⇒ Object
Instance Method Summary collapse
-
#initialize(user_options = {}) ⇒ Message
constructor
rubocop:enable AbcSize rubocop:enable MethodLength.
- #method_missing(method, *args, &block) ⇒ Object
- #to_binary ⇒ Object
Methods included from Flags
_define_flags, _flags, define_flags_32bit, flags_16bit, flags_32bit
Constructor Details
#initialize(user_options = {}) ⇒ Message
rubocop:enable AbcSize rubocop:enable MethodLength
92 93 94 95 |
# File 'lib/pio/open_flow/message.rb', line 92 def initialize( = {}) @format = self.class.const_get(:Format).new(()) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
101 102 103 |
# File 'lib/pio/open_flow/message.rb', line 101 def method_missing(method, *args, &block) @format.__send__ method, *args, &block end |
Instance Attribute Details
#format ⇒ Object (readonly)
Returns the value of attribute format.
15 16 17 |
# File 'lib/pio/open_flow/message.rb', line 15 def format @format end |
Class Method Details
.method_missing(method, *args, &block) ⇒ Object
rubocop:disable MethodLength rubocop:disable AbcSize
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/pio/open_flow/message.rb', line 32 def self.method_missing(method, *args, &block) begin const_get(:Format).__send__ method, *args, &block rescue NameError klass = Class.new(BinData::Record) const_set :Format, klass klass.class_eval do include RubyDumper define_method(:header_length) { 8 } define_method(:length) { _length } end class_variable_set(:@@valid_options, []) retry end return if method == :endian || method == :virtual define_method(args.first) do snapshot = @format.snapshot.__send__(args.first) if snapshot.class == BinData::Struct::Snapshot @format.__send__(args.first) else snapshot end end class_variable_set(:@@valid_options, class_variable_get(:@@valid_options) + [args.first]) end |
.open_flow_header(opts) ⇒ Object
rubocop:disable AbcSize rubocop:disable MethodLength
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/pio/open_flow/message.rb', line 65 def self.open_flow_header(opts) module_eval do cattr_reader(:type) { opts.fetch(:type) } endian :big uint8 :version, value: opts.fetch(:version) uint8 :type, value: opts.fetch(:type) uint16(:_length, initial_value: opts[:length] || lambda do begin 8 + body.length rescue 8 end end) transaction_id :transaction_id, initial_value: 0 virtual assert: -> { version == opts.fetch(:version) } virtual assert: -> { type == opts.fetch(:type) } alias_method :xid, :transaction_id end end |
.read(raw_data) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/pio/open_flow/message.rb', line 20 def self.read(raw_data) allocate.tap do || .instance_variable_set(:@format, const_get(:Format).read(raw_data)) end rescue BinData::ValidityError = name.split('::')[1..-1].join(' ') raise Pio::ParseError, "Invalid #{} message." end |
Instance Method Details
#to_binary ⇒ Object
97 98 99 |
# File 'lib/pio/open_flow/message.rb', line 97 def to_binary @format.to_binary_s end |