Sha256: 4460ba4f9fc593b755bf8076141fd75ae138bd404364cb839f857bda602919bb

Contents?: true

Size: 1.68 KB

Versions: 7

Compression:

Stored size: 1.68 KB

Contents

require 'pio/ethernet_header'
require 'pio/ipv4_header'
require 'pio/open_flow'
require 'pio/parse_error'
require 'pio/parser'

# Base module.
module Pio
  module OpenFlow10
    # OpenFlow 1.0 Packet-In message
    class PacketIn < OpenFlow::Message
      # Why is this packet being sent to the controller?
      # (enum ofp_packet_in_reason)
      class Reason < BinData::Primitive
        REASONS = { no_match: 0, action: 1 }

        uint8 :reason

        def get
          REASONS.invert.fetch(reason)
        end

        def set(value)
          self.reason = REASONS.fetch(value)
        end
      end

      # Message body of Packet-In.
      class Body < BinData::Record
        endian :big

        uint32 :buffer_id
        uint16 :total_len, value: -> { raw_data.length }
        uint16 :in_port
        reason :reason
        uint8 :padding
        hide :padding
        string :raw_data, read_length: :total_len

        def data
          @data ||= Pio::Parser.read(raw_data)
        end

        def empty?
          false
        end

        def length
          10 + raw_data.length
        end

        def lldp?
          data.is_a? Lldp
        end

        def method_missing(method, *args)
          data.__send__(method, *args).snapshot
        end
      end

      # OpenFlow 1.0 Flow Mod message format.
      class Format < BinData::Record
        extend OpenFlow::Format

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

      attr_accessor :datapath_id
      alias_method :dpid, :datapath_id
      alias_method :dpid=, :datapath_id=

      body_option :buffer_id
      body_option :in_port
      body_option :reason
      body_option :raw_data
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
pio-0.27.1 lib/pio/open_flow10/packet_in.rb
pio-0.27.0 lib/pio/open_flow10/packet_in.rb
pio-0.26.0 lib/pio/open_flow10/packet_in.rb
pio-0.25.0 lib/pio/open_flow10/packet_in.rb
pio-0.24.2 lib/pio/open_flow10/packet_in.rb
pio-0.24.1 lib/pio/open_flow10/packet_in.rb
pio-0.24.0 lib/pio/open_flow10/packet_in.rb