Class: Pio::SendOutPort

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/pio/send_out_port.rb

Overview

An action to output a packet to a port.

Defined Under Namespace

Classes: Format

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_options) ⇒ SendOutPort

Creates an action to output a packet to a port.

rubocop:disable MethodLength

Examples:

SendOutPort.new(1)
SendOutPort.new(port_number: 1)
SendOutPort.new(port_number: :controller, max_len: 256)

Parameters:

  • user_options (Integer|Hash)

    the port number or the options hash to create this action class instance with.

Options Hash (user_options):

  • :port_number (Number)

    port number an index into switch’s physical port list. There are also fake output ports. For example a port number set to :flood would output packets to all physical ports except input port and ports disabled by STP.

  • :max_len (Number)

    the maximum number of bytes from a packet to send to controller when port is set to :controller. A zero length means no bytes of the packet should be sent. It defaults to 64K.

Raises:

  • (ArgumentError)

    if :port_number is not an unsigned 16-bit integer.

  • (ArgumentError)

    if :max_len is not an unsigned 16-bit integer.



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/pio/send_out_port.rb', line 59

def initialize(user_options)
  options = if user_options.respond_to?(:to_i)
              { port_number: user_options.to_i }
            elsif PortNumber::NUMBERS.key?(user_options)
              { port_number: user_options }
            else
              user_options
            end
  max_len = options[:max_len]
  if max_len && !max_len.unsigned_16bit?
    fail ArgumentError, 'The max_len should be an unsigned 16bit integer.'
  end
  @format = Format.new(options)
end

Class Method Details

.read(raw_data) ⇒ Object



19
20
21
22
23
# File 'lib/pio/send_out_port.rb', line 19

def self.read(raw_data)
  send_out_port = allocate
  send_out_port.instance_variable_set :@format, Format.read(raw_data)
  send_out_port
end