Sha256: 2bb877b37ef8431d4b681584c00452e837866adb4969cc58de7269afc556c330

Contents?: true

Size: 1.71 KB

Versions: 21

Compression:

Stored size: 1.71 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_source_port: BOOTPC,
          udp_destination_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

21 entries across 21 versions & 1 rubygems

Version Path
pio-0.27.2 lib/pio/dhcp/boot_request_options.rb
pio-0.27.1 lib/pio/dhcp/boot_request_options.rb
pio-0.27.0 lib/pio/dhcp/boot_request_options.rb
pio-0.26.0 lib/pio/dhcp/boot_request_options.rb
pio-0.25.0 lib/pio/dhcp/boot_request_options.rb
pio-0.24.2 lib/pio/dhcp/boot_request_options.rb
pio-0.24.1 lib/pio/dhcp/boot_request_options.rb
pio-0.24.0 lib/pio/dhcp/boot_request_options.rb
pio-0.23.1 lib/pio/dhcp/boot_request_options.rb
pio-0.23.0 lib/pio/dhcp/boot_request_options.rb
pio-0.22.0 lib/pio/dhcp/boot_request_options.rb
pio-0.21.1 lib/pio/dhcp/boot_request_options.rb
pio-0.21.0 lib/pio/dhcp/boot_request_options.rb
pio-0.20.1 lib/pio/dhcp/boot_request_options.rb
pio-0.20.0 lib/pio/dhcp/boot_request_options.rb
pio-0.19.0 lib/pio/dhcp/boot_request_options.rb
pio-0.18.2 lib/pio/dhcp/boot_request_options.rb
pio-0.18.1 lib/pio/dhcp/boot_request_options.rb
pio-0.18.0 lib/pio/dhcp/boot_request_options.rb
pio-0.17.0 lib/pio/dhcp/boot_request_options.rb