Class: Pio::Match::Wildcards

Inherits:
BinData::Primitive
  • Object
show all
Defined in:
lib/pio/match.rb

Overview

Flow wildcards

Constant Summary collapse

BITS =
{
  in_port: 1 << 0,
  dl_vlan: 1 << 1,
  dl_src: 1 << 2,
  dl_dst: 1 << 3,
  dl_type: 1 << 4,
  nw_proto: 1 << 5,
  tp_src: 1 << 6,
  tp_dst: 1 << 7,
  nw_src: 0,
  nw_src0: 1 << 8,
  nw_src1: 1 << 9,
  nw_src2: 1 << 10,
  nw_src3: 1 << 11,
  nw_src4: 1 << 12,
  nw_src_all: 1 << 13,
  nw_dst: 0,
  nw_dst0: 1 << 14,
  nw_dst1: 1 << 15,
  nw_dst2: 1 << 16,
  nw_dst3: 1 << 17,
  nw_dst4: 1 << 18,
  nw_dst_all: 1 << 19,
  dl_vlan_pcp: 1 << 20,
  nw_tos: 1 << 21
}
NW_FLAGS =
[:nw_src, :nw_dst]
FLAGS =
BITS.keys.select { |each| !(/^nw_(src|dst)/=~ each) }

Instance Method Summary collapse

Instance Method Details

#getObject

This method smells of :reek:FeatureEnvy



47
48
49
50
51
52
53
54
55
56
# File 'lib/pio/match.rb', line 47

def get
  BITS.each_with_object(Hash.new(0)) do |(key, bit), memo|
    next if flags & bit == 0
    if /(nw_src|nw_dst)(\d)/=~ key
      memo[$LAST_MATCH_INFO[1].intern] |= 1 << $LAST_MATCH_INFO[2].to_i
    else
      memo[key] = true
    end
  end
end

#nw_dstObject



75
76
77
78
79
# File 'lib/pio/match.rb', line 75

def nw_dst
  get.fetch(:nw_dst)
rescue KeyError
  0
end

#nw_srcObject



69
70
71
72
73
# File 'lib/pio/match.rb', line 69

def nw_src
  get.fetch(:nw_src)
rescue KeyError
  0
end

#set(params) ⇒ Object



58
59
60
61
62
63
64
65
66
67
# File 'lib/pio/match.rb', line 58

def set(params)
  self.flags = params.inject(0) do |memo, (key, val)|
    memo | case key
           when :nw_src, :nw_dst
             (params.fetch(key) & 31) << (key == :nw_src ? 8 : 14)
           else
             val ? BITS.fetch(key) : 0
           end
  end
end