Class: Pio::OpenFlow10::Match::Wildcards
- Inherits:
-
BinData::Primitive
- Object
- BinData::Primitive
- Pio::OpenFlow10::Match::Wildcards
- Defined in:
- lib/pio/open_flow10/match.rb
Overview
Flow wildcards
Constant Summary collapse
- BITS =
{ in_port: 1 << 0, vlan_vid: 1 << 1, source_mac_address: 1 << 2, destination_mac_address: 1 << 3, ether_type: 1 << 4, ip_protocol: 1 << 5, transport_source_port: 1 << 6, transport_destination_port: 1 << 7, source_ip_address: 0, source_ip_address0: 1 << 8, source_ip_address1: 1 << 9, source_ip_address2: 1 << 10, source_ip_address3: 1 << 11, source_ip_address4: 1 << 12, source_ip_address_all: 1 << 13, destination_ip_address: 0, destination_ip_address0: 1 << 14, destination_ip_address1: 1 << 15, destination_ip_address2: 1 << 16, destination_ip_address3: 1 << 17, destination_ip_address4: 1 << 18, destination_ip_address_all: 1 << 19, vlan_priority: 1 << 20, tos: 1 << 21 }.freeze
- NW_FLAGS =
%i[source_ip_address destination_ip_address].freeze
- FLAGS =
BITS.keys.reject { |each| (/^(source|destination)_ip/=~ each) }
Instance Method Summary collapse
- #destination_ip_address ⇒ Object
-
#get ⇒ Object
This method smells of :reek:FeatureEnvy.
- #set(params) ⇒ Object
- #source_ip_address ⇒ Object
Instance Method Details
#destination_ip_address ⇒ Object
78 79 80 81 82 |
# File 'lib/pio/open_flow10/match.rb', line 78 def destination_ip_address get.fetch(:destination_ip_address) rescue KeyError 0 end |
#get ⇒ Object
This method smells of :reek:FeatureEnvy
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/pio/open_flow10/match.rb', line 49 def get BITS.each_with_object(Hash.new(0)) do |(key, bit), memo| next if (flags & bit).zero? if /(source_ip_address|destination_ip_address)(\d)/=~ key memo[$LAST_MATCH_INFO[1].to_sym] |= 1 << $LAST_MATCH_INFO[2].to_i else memo[key] = true end end end |
#set(params) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/pio/open_flow10/match.rb', line 60 def set(params) self.flags = params.inject(0) do |memo, (key, val)| memo | case key when :source_ip_address, :destination_ip_address (params.fetch(key) & 31) << (key == :source_ip_address ? 8 : 14) else val ? BITS.fetch(key) : 0 end end end |
#source_ip_address ⇒ Object
72 73 74 75 76 |
# File 'lib/pio/open_flow10/match.rb', line 72 def source_ip_address get.fetch(:source_ip_address) rescue KeyError 0 end |