Class: OpenFlow::Protocol::Match::Wildcards

Inherits:
BinData::Primitive
  • Object
show all
Defined in:
lib/openflow-protocol/structs/match.rb

Constant Summary collapse

FLAGS =
{
  in_port:            1 <<  0,
  vlan_id:            1 <<  1,
  mac_source:         1 <<  2,
  mac_destination:    1 <<  3,
  mac_protocol:       1 <<  4,
  ip_protocol:        1 <<  5,
  source_port:        1 <<  6,
  destination_port:   1 <<  7,
  ip_source0:         1 <<  8,
  ip_source1:         1 <<  9,
  ip_source2:         1 << 10,
  ip_source3:         1 << 11,
  ip_source4:         1 << 12,
  ip_source_all:      1 << 13,
  ip_destination0:    1 << 14,
  ip_destination1:    1 << 15,
  ip_destination2:    1 << 16,
  ip_destination3:    1 << 17,
  ip_destination4:    1 << 18,
  ip_destination_all: 1 << 19,
  vlan_pcp:           1 << 20,
  ip_tos:             1 << 21
}
ALL_FLAGS =
Hash[
          FLAGS.keys.select { |key| /^ip_(source|destination)\d$/ !~ key }
.map { |key| [key, true]

Instance Method Summary collapse

Instance Method Details

#getObject



41
42
43
44
45
46
47
48
49
50
# File 'lib/openflow-protocol/structs/match.rb', line 41

def get
  FLAGS.each_with_object(Hash.new(0)) do |(key, bit), memo|
    next if flags & bit == 0
    if /^(ip_source|ip_destination)(\d)/ =~ key
      memo[$LAST_MATCH_INFO[1].to_sym] |= 1 << $LAST_MATCH_INFO[2].to_i
    else
      memo[key] = true
    end
  end
end

#set(value) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/openflow-protocol/structs/match.rb', line 52

def set(value)
  value = Hash[value.map { |v| [v, true] }] if value.is_a?(Array)
  self.flags = value.inject(0) do |memo, (key, val)|
    memo |
      case key
      when :ip_source, :ip_destination
        (val & 31) << (key == :ip_source ? 8 : 14)
      else
        val ? FLAGS.fetch(key) : 0
      end
  end
end