class Havox::Route
Constants
- IP_REGEX
- ROUTE_REGEX
- TYPE_CHAR_REGEX
- TYPE_HASH
Attributes
best[R]
fib[R]
interface[R]
network[R]
protocol[R]
raw[R]
recursive_via[R]
router[R]
timestamp[R]
via[R]
Public Class Methods
new(raw, router, opts = {})
click to toggle source
# File lib/havox/classes/route.rb, line 23 def initialize(raw, router, opts = {}) @router = router @opts = opts @raw = raw parse_raw_entry end
Public Instance Methods
bgp?()
click to toggle source
# File lib/havox/classes/route.rb, line 51 def bgp? @protocol.eql?(:bgp) end
direct?()
click to toggle source
# File lib/havox/classes/route.rb, line 47 def direct? @via.nil? end
inspect()
click to toggle source
# File lib/havox/classes/route.rb, line 37 def inspect "Route #{object_id.to_s(16)}, router #{@router}, #{to_s}" end
ospf?()
click to toggle source
# File lib/havox/classes/route.rb, line 55 def ospf? @protocol.eql?(:ospf) end
to_h()
click to toggle source
# File lib/havox/classes/route.rb, line 41 def to_h { router: @router, protocol: @protocol, network: @network, via: @via, recursive_via: @recursive_via, interface: @interface, timestamp: @timestamp, best: @best, fib: @fib } end
to_s()
click to toggle source
# File lib/havox/classes/route.rb, line 30 def to_s connection = @via.nil? ? 'direct' : "via #{@via}" "#{@protocol.upcase}: to #{@network} #{connection} in " \ "#{@interface || @recursive_via}#{', BEST' if @best}" \ "#{', FIB route' if @fib}" end
Private Instance Methods
evaluate_protocol(flags_str)
click to toggle source
# File lib/havox/classes/route.rb, line 67 def evaluate_protocol(flags_str) type_char = flags_str.scan(TYPE_CHAR_REGEX).first @protocol = TYPE_HASH[type_char] || :unknown end
evaluate_route_attributes(parsed_entry)
click to toggle source
# File lib/havox/classes/route.rb, line 72 def evaluate_route_attributes(parsed_entry) @network = parsed_entry[:network]&.to_s @via = parsed_entry[:via]&.to_s @interface = parsed_entry[:interface]&.to_s @timestamp = parsed_entry[:timestamp]&.to_s @best = parsed_entry[:flags].include?('>') @fib = parsed_entry[:flags].include?('*') @recursive_via = parsed_entry[:recursive_via]&.to_s end
parse_raw_entry()
click to toggle source
# File lib/havox/classes/route.rb, line 61 def parse_raw_entry parsed_entry = @raw.match(ROUTE_REGEX) evaluate_protocol(parsed_entry[:flags]) evaluate_route_attributes(parsed_entry) end