class Pio::OpenFlow13::Match::Options

Match.new option parser.

Public Class Methods

new(user_attrs) click to toggle source

rubocop:disable MethodLength rubocop:disable AbcSize rubocop:disable LineLength

# File lib/pio/open_flow13/match.rb, line 1269
def initialize(user_attrs)
  @match_fields = []

  %i[in_port ether_type ip_protocol vlan_vid vlan_pcp
     ip_dscp ip_ecn tcp_source_port tcp_destination_port
     udp_source_port udp_destination_port
     sctp_source_port sctp_destination_port
     icmpv4_type icmpv4_code arp_operation].each do |each|
    next unless user_attrs.key?(each)
    klass = Match.const_get(each.to_s.split('_').map(&:capitalize).join)
    @match_fields << { oxm_class: klass.superclass.const_get(:OXM_CLASS),
                       class_payload: { oxm_field: klass.const_get(:OXM_FIELD),
                                        tlv_value: { each => user_attrs.fetch(each) } } }
  end

  %i[metadata destination_mac_address source_mac_address
     ipv4_source_address ipv4_destination_address
     arp_sender_protocol_address arp_target_protocol_address
     arp_sender_hardware_address arp_target_hardware_address
     ipv6_source_address ipv6_destination_address tunnel_id
     reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7
     packet_reg0 packet_reg1 packet_reg2 packet_reg3].each do |each|
    next unless user_attrs.key?(each)
    klass = Match.const_get(each.to_s.split('_').map(&:capitalize).join)
    mask_key = "#{each}_mask".to_sym
    @match_fields << { oxm_class: klass.superclass.const_get(:OXM_CLASS),
                       class_payload: { oxm_field: klass.const_get(:OXM_FIELD),
                                        oxm_hasmask: user_attrs.key?(mask_key) ? 1 : 0,
                                        tlv_value: { each => user_attrs[each],
                                                     mask_key => user_attrs[mask_key] } } }
  end
end

Public Instance Methods

to_hash() click to toggle source

rubocop:enable MethodLength rubocop:enable AbcSize rubocop:enable LineLength

# File lib/pio/open_flow13/match.rb, line 1305
def to_hash
  { match_fields: @match_fields }
end