class Proxy::Probing::NeighbourCache

Public Class Methods

new() click to toggle source
# File lib/smart-proxy-probing/neighbour_cache.rb, line 3
def initialize
  @cache = []
end

Public Instance Methods

cache!() click to toggle source
# File lib/smart-proxy-probing/neighbour_cache.rb, line 15
def cache!
  @cache = `ip neigh show`.lines.map do |line|
    fields = line.chomp.split(/\s+/)
    hash = { :ip => fields.shift }
    fields.each_slice(2) do |k, v|
      if v
        hash[k] = v
      else
        hash[:state] = k
      end
    end
    hash
  end
end
clean!() click to toggle source
# File lib/smart-proxy-probing/neighbour_cache.rb, line 30
def clean!
  @cache = {}
end
ips_for_mac(mac) click to toggle source
# File lib/smart-proxy-probing/neighbour_cache.rb, line 7
def ips_for_mac(mac)
  @cache.select { |record| record['lladdr'] == mac }.map { |record| record[:ip] }
end
mac_for_ip(ip) click to toggle source
# File lib/smart-proxy-probing/neighbour_cache.rb, line 11
def mac_for_ip(ip)
  @cache.select { |record| record[:ip] == ip }.map { |record| record['lladdr'] }.first
end