Class: Cisco::ShowRoute

Inherits:
Parser show all
Defined in:
lib/netutils/cli/cisco/showroute.rb

Constant Summary

Constants inherited from FSM

FSM::FSM_S_INIT

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Parser

#add, #parse, #regexp

Methods inherited from FSM

#add, #cb, #changeto, #state_name

Constructor Details

#initializeShowRoute

Returns a new instance of ShowRoute.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/netutils/cli/cisco/showroute.rb', line 13

def initialize
	@rib = RIB.new
	super
	# % Network not in table
	# Routing entry for 192.168.0.0/24
	add('Init',	:init)
 		#   Known via "connected", distance 0, metric 0 (connected, via interface)
	add('Protocol',	:protocol, /  Known via "([^"]+)",.*$/)
	add('Descriptor',	:descriptor)
	#   * 192.168.0.200
 		#   * directly connected, via Vlan4000
	#   * 192.168.0.1, from 192.168.0.1, 00:00:19 ago, via Vlan9999
	add('Nexthop',	:nexthop, /^  \* ([^ ,]+)(?:,? .*, via ([^ ]+)|)$/)
     		#       Route metric is 0, traffic share count is 1
	add('Metric',	:metric, /^      Route metric is .*$/)
end

Instance Attribute Details

#ribObject (readonly)

Returns the value of attribute rib.



7
8
9
# File 'lib/netutils/cli/cisco/showroute.rb', line 7

def rib
  @rib
end

Instance Method Details

#cmd(ia) ⇒ Object



9
10
11
# File 'lib/netutils/cli/cisco/showroute.rb', line 9

def cmd(ia)
	"show ip route vrf \* #{ia}"
end

#descriptor(l, m) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/netutils/cli/cisco/showroute.rb', line 45

def descriptor(l, m)
 		#   Routing Descriptor Blocks:
	case l
	when /^  Routing Descriptor Blocks:$/
		changeto('Nexthop')
	when /^  Redistributing via /, /^  Advertised by /
	end
end

#init(l, m) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/netutils/cli/cisco/showroute.rb', line 30

def init(l, m)
	return if l =~ /^% .* not in table/
	return if l =~ /^$/
	if l !~ /^Routing entry for ([0-9\.\/]+)(?:, supernet)?$/
		raise "Invalid format: #{l}"
	end
	@dst = $1
	changeto('Protocol')
end

#metric(l, m) ⇒ Object



67
68
69
70
# File 'lib/netutils/cli/cisco/showroute.rb', line 67

def metric(l, m)
	@rib.add(@protocol, @dst, @nh, @interface)
	changeto('Init')
end

#nexthop(l, m) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/netutils/cli/cisco/showroute.rb', line 54

def nexthop(l, m)
	case m[1]
	when 'directly'
		@nh = nil
	when /[0-9\.\/]+/
		@nh = m[1]
	else
		raise "Invalid format: #{l}"
	end
	@interface = m[2]
	changeto('Metric')
end

#protocol(l, m) ⇒ Object



40
41
42
43
# File 'lib/netutils/cli/cisco/showroute.rb', line 40

def protocol(l, m)
	@protocol = m[1]
	changeto('Descriptor')
end