Class: RIB::Route

Inherits:
Object
  • Object
show all
Defined in:
lib/netutils/rib.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(proto, dst, nh, interface) ⇒ Route

Returns a new instance of Route.



7
8
9
10
11
12
13
14
# File 'lib/netutils/rib.rb', line 7

def initialize(proto, dst, nh, interface)
	dst = ip_address_normalize(dst)
	@proto     = proto
	@dst       = dst
	@prefixlen = prefixlen_get(dst)
	@nh        = nh
	@interface = interface
end

Instance Attribute Details

#dstObject (readonly)

Returns the value of attribute dst.



5
6
7
# File 'lib/netutils/rib.rb', line 5

def dst
  @dst
end

#interfaceObject (readonly)

Returns the value of attribute interface.



5
6
7
# File 'lib/netutils/rib.rb', line 5

def interface
  @interface
end

#nhObject (readonly)

Returns the value of attribute nh.



5
6
7
# File 'lib/netutils/rib.rb', line 5

def nh
  @nh
end

#prefixlenObject (readonly)

Returns the value of attribute prefixlen.



5
6
7
# File 'lib/netutils/rib.rb', line 5

def prefixlen
  @prefixlen
end

#protoObject (readonly)

Returns the value of attribute proto.



5
6
7
# File 'lib/netutils/rib.rb', line 5

def proto
  @proto
end

Instance Method Details

#compare(other) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/netutils/rib.rb', line 44

def compare(other)
	return self if ! other
	if defined?(PREFERRED_NEXTHOPS)
		PREFERRED_NEXTHOPS.each do |prefix|
			ir = IPAddr.new(prefix)
			if ir.include?(@nh) &&
			    ! ir.include?(other.nh)
				return self
			elsif ! ir.include?(@nh) &&
			    ir.include?(other.nh)
				return other
			end
		end
	end
	return other if @prefixlen < other.prefixlen
	return self
end

#tunnel?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/netutils/rib.rb', line 40

def tunnel?
	@interface =~ /^[tT]unnel/
end