Class: Alaxala::ShowRoute

Inherits:
Parser show all
Defined in:
lib/netutils/cli/alaxala/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
29
30
31
# File 'lib/netutils/cli/alaxala/showroute.rb', line 13

def initialize
	@rib = RIB.new
	super
	# Route 10/8 , VRF 2
	add('Init',	:init)
	# AX8600
	# Entries 1
	# AX3600
	# Entries 1 Announced 1 Depth 0 <>
	add('Entries',	:entries, /^Entries [0-9]+.*$/)
	# empty line
	add('Empty',	:empty, /^$/)
	# * NextHop 192.168.0.1    , Interface   : VLAN9999
	add('Nexthop',	:nexthop, /^..NextHop ([^\s]+)\s*, Interface\s*: ([^\s]+)\s*$/)
	#     Protocol <OSPF inter>
	add('Protocol',	:protocol, /^     Protocol <([^>]+)>/)
	#
	add('Skip',	:skip)
end

Instance Attribute Details

#ribObject (readonly)

Returns the value of attribute rib.



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

def rib
  @rib
end

Instance Method Details

#cmd(ia) ⇒ Object



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

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

#empty(l, m) ⇒ Object



45
46
47
# File 'lib/netutils/cli/alaxala/showroute.rb', line 45

def empty(l, m)
	changeto('Nexthop')
end

#entries(l, m) ⇒ Object



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

def entries(l, m)
	changeto('Empty')
end

#init(l, m) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/netutils/cli/alaxala/showroute.rb', line 33

def init(l, m)
	return if l =~ /^$/
	return if l !~ /^Route ([0-9\.\/]+)\s*, VRF ([0-9]+|global)$/
	@dst = $1
	@vrf = $1
	changeto('Entries')
end

#nexthop(l, m) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'lib/netutils/cli/alaxala/showroute.rb', line 49

def nexthop(l, m)
	@nh = m[1]
	@interface = m[2]
	#
	# remove mediate ``0''s because Alaxala CLI may to accept such 
	# interface name like ``VLAN0999.''
	#
	@interface = "#{$1}#{$2}" if @interface =~ /^([^0-9]+)0+([0-9]+)$/
	changeto('Protocol')
end

#protocol(l, m) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/netutils/cli/alaxala/showroute.rb', line 60

def protocol(l, m)
	case m[1]
	when /^Static/
		@protocol = 'static'
	when /^Connected/
		@protocol = 'connected'
	when /^RIP/
		@protocol = 'rip'
	when /^OSPF/
		@protocol = 'ospf'
	when /^BGP/
		@protocol = 'bgp'
	when /^Extra-VRF/
		@protocol = 'extranet'
	else
		raise(ArgumentError, "Invalid routing protocol: #{m[1]}")
	end
	@rib.add(@protocol, @dst, @nh, @interface)
	changeto('Skip')
end

#skip(l, m) ⇒ Object



81
82
83
# File 'lib/netutils/cli/alaxala/showroute.rb', line 81

def skip(l, m)
	changeto('Init') if l =~ /^$/
end