Sha256: eaaae577c13249b85c9c7f237688412bd66d60d9a0b441f02a31300c217a541e

Contents?: true

Size: 1.72 KB

Versions: 6

Compression:

Stored size: 1.72 KB

Contents

# encoding: utf-8

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

6 entries across 6 versions & 1 rubygems

Version Path
pio-0.8.1 lib/pio/dhcp/boot_request_options.rb
pio-0.8.0 lib/pio/dhcp/boot_request_options.rb
pio-0.7.0 lib/pio/dhcp/boot_request_options.rb
pio-0.6.0 lib/pio/dhcp/boot_request_options.rb
pio-0.5.0 lib/pio/dhcp/boot_request_options.rb
pio-0.4.0 lib/pio/dhcp/boot_request_options.rb