Module: Pio::IPv4

Includes:
Payload
Included in:
Dhcp::Frame, IPv4Header, Pio::Icmp::Format, Parser::IPv4Packet, Udp
Defined in:
lib/pio/ipv4_header.rb

Overview

IP Version 4 Header Format

Defined Under Namespace

Modules: ProtocolNumber

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Payload

#binary_after

Class Method Details

.included(klass) ⇒ Object

rubocop:disable MethodLength This method smells of :reek:TooManyStatements



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/pio/ipv4_header.rb', line 22

def self.included(klass)
  def klass.ipv4_header(options = {})
    bit4 :ip_version, value: 0x4
    bit4 :ip_header_length, initial_value: 0x5
    uint8 :ip_type_of_service, initial_value: 0
    uint16be :ip_total_length, initial_value: :calculate_ip_length
    uint16be :ip_identifier, initial_value: 0
    bit3 :ip_flag, initial_value: 0
    bit13 :ip_fragment, initial_value: 0
    uint8 :ip_ttl, initial_value: 128
    uint8 :ip_protocol, initial_value: options[:ip_protocol] || 0
    uint16be :ip_header_checksum, initial_value: :calculate_ip_checksum
    ip_address :source_ip_address
    ip_address :destination_ip_address
    string :ip_option, read_length: :ip_option_length
  end
end

Instance Method Details

#ip_header_length_in_bytesObject

rubocop:enable MethodLength



61
62
63
# File 'lib/pio/ipv4_header.rb', line 61

def ip_header_length_in_bytes
  ip_header_length * 4
end

#to_exact_match(in_port) ⇒ Object

rubocop:disable MethodLength



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/pio/ipv4_header.rb', line 42

def to_exact_match(in_port)
  match_options = {
    in_port: in_port,
    source_mac_address: source_mac,
    destination_mac_address: destination_mac,
    vlan_vid: vlan? ? vlan_vid : 0xffff,
    vlan_priority: vlan_pcp,
    ether_type: ether_type,
    tos: ip_type_of_service,
    ip_protocol: ip_protocol,
    source_ip_address: source_ip_address,
    destination_ip_address: destination_ip_address,
    transport_source_port: transport_source_port,
    transport_destination_port: transport_destination_port
  }
  Pio::OpenFlow10::Match.new match_options
end