Class: Alaxala::ShowARP

Inherits:
Parser show all
Defined in:
lib/netutils/cli/alaxala/showarp.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

#initializeShowARP

Returns a new instance of ShowARP.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/netutils/cli/alaxala/showarp.rb', line 9

def initialize
  @arps = ARPTable.new
  super
  # Date 2017/10/05 21:30:53 JST
  add('Init',  :init,   /^Date/)
  # VRF: 1 Total: 946 entries
  add('VRF', :vrf,   /^VRF/)
  #  IP Address       Linklayer Address  Netif             Expire     Type
  add('Title', :title, /^(?: IP Address       Linklayer Address  Netif             Expire     Type|There is no ARP entry.)/)
  # 192.168.0.1      dead.beaf.dead     VLAN9999          4m58s      arpa
  add('Entry', :entry, /^\s+([0-9\.]+)\s+([0-9a-f\.]+|\(incomplete\))\s+([^\s]+)\s+([^\s]+).*$/)
end

Instance Attribute Details

#arpsObject (readonly)

Returns the value of attribute arps.



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

def arps
  @arps
end

Instance Method Details

#entry(l, m) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/netutils/cli/alaxala/showarp.rb', line 36

def entry(l, m)
  #
  # remove mediate ``0''s because Alaxala CLI may to accept such 
  # interface name like ``VLAN0620.''
  #
  if m[3] =~ /^([^0-9]+)0+([0-9]+)$/
    interface = "#{$1}#{$2}"
  else
    interface = m[3]
  end
  return if m[2] === '(incomplete)'
  @arps.add(m[1], m[2].downcase, interface, m[4] === 'Static')
end

#init(l, m) ⇒ Object



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

def init(l, m)
  # XXX: VRF appears if and only if an IP address is given.
  #changeto('VRF')
  changeto('Title')
end

#title(l, m) ⇒ Object



32
33
34
# File 'lib/netutils/cli/alaxala/showarp.rb', line 32

def title(l, m)
  changeto('Entry')
end

#vrf(l, m) ⇒ Object



28
29
30
# File 'lib/netutils/cli/alaxala/showarp.rb', line 28

def vrf(l, m)
  changeto('Title')
end