Class: Alaxala::MACFIB

Inherits:
Parser show all
Defined in:
lib/netutils/cli/alaxala/macfib.rb

Constant Summary collapse

AX2000_RE =

Date 2017/10/15 08:24:22 JST Aging time : 300 MAC address VLAN Type Port-list dead.beef.dead 9999 Dynamic 0/26-27

/^[0-9a-z.]+\s+[0-9]+\s+[^\s]+\s+([0-9\/,\-]+)$/
AX8600_RE =

Date 2017/10/14 19:39:20 JST MAC address VLAN C-Tag Aging-Time Type Port-list dead.beef.dead 9999 - 479 Dynamic 7/5,11/5

/^[0-9a-z.]+\s+[0-9]+\s+[^\s]+\s+[0-9]+\s+[^\s]+\s+([0-9\/,\-]+)$/

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

#initialize(sw) ⇒ MACFIB

Returns a new instance of MACFIB.



27
28
29
30
31
32
# File 'lib/netutils/cli/alaxala/macfib.rb', line 27

def initialize(sw)
	@ports = {}
	super()
	add('Init',	:init)
	@sw = sw
end

Instance Attribute Details

#portsObject (readonly)

Returns the value of attribute ports.



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

def ports
  @ports
end

Instance Method Details

#cmd(ma, vlan) ⇒ Object



22
23
24
25
# File 'lib/netutils/cli/alaxala/macfib.rb', line 22

def cmd(ma, vlan)
	mac = "mac " if @sw.product =~ /^AX2[0-9]{3}/
	return "show mac-address-table #{mac}#{ma.to_s} vlan #{vlan}"
end

#init(l, m) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/netutils/cli/alaxala/macfib.rb', line 34

def init(l, m)
	case l
	# XXX: other switches...
	when AX2000_RE, AX8600_RE
		$1.split(',').each do |port|
			port, last = port.split('-')
			if port =~ /^(.*\/)([0-9]+)$/
				prefix = $1
				first = $2.to_i
			else
				raise(ArgumentError,
				    "Unknown port name format: #{port}")
			end
			if last
				last = last.to_i
			else
				last = first
			end
			for i in first .. last do
				name = prefix + i.to_s
				name = @sw.interface_name(name)
				@ports[name] = name
			end
		end
	end
end