Sha256: 177f99e80ebb92eb4d8e9bb74f059679363f5d7b439b423246c9e7f03111307a

Contents?: true

Size: 1.7 KB

Versions: 13

Compression:

Stored size: 1.7 KB

Contents

require 'pio/options'
require 'pio/dhcp/common_options'
require 'pio/dhcp/dhcp_tlv_options'

module Pio
  class Dhcp
    # Options for creating a DHCP message.
    class BootRequestOptions < Pio::Options
      include CommonOptions
      include DhcpTlvOptions

      mandatory_option :source_mac
      mandatory_option :type
      option :destination_mac
      option :requested_ip_address
      option :server_identifier
      option :transaction_id

      def initialize(options)
        validate options
        @options = options
      end

      def to_hash
        {
          destination_mac: destination_mac,
          source_mac: source_mac,
          ip_source_address: QUAD_ZERO_IP_ADDRESS,
          ip_destination_address: BROADCAST_IP_ADDRESS,
          udp_src_port: BOOTPC,
          udp_dst_port: BOOTPS,
          dhcp: dhcp_data
        }
      end

      private

      def dhcp_field_values
        {
          message_type: BootRequest::MESSAGE_TYPE,
          transaction_id: transaction_id,
          client_ip_address: QUAD_ZERO_IP_ADDRESS,
          your_ip_address: QUAD_ZERO_IP_ADDRESS,
          next_server_ip_address: QUAD_ZERO_IP_ADDRESS,
          relay_agent_ip_address: QUAD_ZERO_IP_ADDRESS,
          client_mac_address: source_mac,
          optional_tlvs: options_for_optional_tlv
        }
      end

      def options_for_optional_tlv
        [
          message_type_hash,
          client_identifier_hash,
          requested_ip_address_hash,
          parameters_list_hash,
          dhcp_server_identifier_hash
        ].compact
      end

      def server_identifier
        server_id = @options[:server_identifier]
        IPv4Address.new(server_id) if server_id
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
pio-0.15.2 lib/pio/dhcp/boot_request_options.rb
pio-0.15.1 lib/pio/dhcp/boot_request_options.rb
pio-0.15.0 lib/pio/dhcp/boot_request_options.rb
pio-0.14.0 lib/pio/dhcp/boot_request_options.rb
pio-0.13.0 lib/pio/dhcp/boot_request_options.rb
pio-0.12.0 lib/pio/dhcp/boot_request_options.rb
pio-0.11.2 lib/pio/dhcp/boot_request_options.rb
pio-0.11.1 lib/pio/dhcp/boot_request_options.rb
pio-0.11.0 lib/pio/dhcp/boot_request_options.rb
pio-0.10.1 lib/pio/dhcp/boot_request_options.rb
pio-0.10.0 lib/pio/dhcp/boot_request_options.rb
pio-0.9.0 lib/pio/dhcp/boot_request_options.rb
pio-0.8.2 lib/pio/dhcp/boot_request_options.rb