Commit c1ba8b4b authored by Dmitry Lukhtionov's avatar Dmitry Lukhtionov Committed by Andrey Vertiprahov
Browse files

Update Cisco.IOS profile to support more physical interfaces

parent cdba3474
......@@ -38,6 +38,7 @@ class Script(BaseScript):
r"^(?P<interface>.+?)\s+is(?:\s+administratively)?\s+(?P<admin_status>up|down),\s+line\s+"
r"protocol\s+is\s+(?P<oper_status>up|down)\s"
r"(?:\((?:connected|notconnect|disabled|monitoring|err-disabled)\)\s*|, Autostate \S+)?\n"
r"(^\s+Hardware is .+\n)?"
r"\s+Hardware is (?P<hardw>[^\n]+)\n(?:\s+Description:\s(?P<desc>[^\n]+)\n)?"
r"(?:\s+Internet address ((is\s(?P<ip>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/\d{1,2}))|([^\d]+))\n)?"
r"[^\n]+\n[^\n]+\n\s+Encapsulation\s+(?P<encaps>[^\n]+)",
......@@ -77,12 +78,13 @@ class Script(BaseScript):
rx_ctp = re.compile(r"Keepalive set \(\d+ sec\)")
rx_cdp = re.compile(r"^(?P<iface>\S+) is ")
rx_lldp = re.compile(
r"^(?P<iface>(?:Fa|Gi|Te|Fo)[^:]+?):.+Rx: (?P<rx_state>\S+)", re.MULTILINE | re.DOTALL
r"^(?P<iface>(?:Fa|Gi|Te|Fo|Fi|Tw|Twe)[^:]+?):.+Rx: (?P<rx_state>\S+)",
re.MULTILINE | re.DOTALL,
)
rx_gvtp = re.compile(r"VTP Operating Mode\s+: Off", re.MULTILINE)
rx_vtp = re.compile(r"^\s*(?P<iface>(?:Fa|Gi|Te|Fo)[^:]+?)\s+enabled", re.MULTILINE)
rx_vtp = re.compile(r"^\s*(?P<iface>(?:Fa|Gi|Te|Fo|Fi|Tw|Twe)[^:]+?)\s+enabled", re.MULTILINE)
rx_vtp1 = re.compile(
r"^\s*Local updater ID is \S+ on interface (?P<iface>(?:Fa|Gi|Te|Fo)[^:]+?)\s+",
r"^\s*Local updater ID is \S+ on interface (?P<iface>(?:Fa|Gi|Te|Fo|Fi|Tw|Twe)[^:]+?)\s+",
re.MULTILINE,
)
rx_oam = re.compile(r"^\s*(?P<iface>(?:Fa|Gi|Te|Fo)\S+)\s+\S+\s+\S+\s+\S+\s+\S+\s*$")
......@@ -218,8 +220,8 @@ class Script(BaseScript):
except self.CLISyntaxError:
return {}
r = {}
for l in c.split("\n"):
match = self.rx_ifindex.match(l.strip())
for line in c.split("\n"):
match = self.rx_ifindex.match(line.strip())
if match:
r[match.group("interface")] = int(match.group("ifindex"))
return r
......@@ -230,8 +232,8 @@ class Script(BaseScript):
def get_ubr_pvm(self):
vlans = self.cli("show cable l2-vpn dot1q-vc-map")
pvm = {}
for l in vlans.split("\n"):
match = self.rx_vlan_ubr.search(l)
for line in vlans.split("\n"):
match = self.rx_vlan_ubr.search(line)
if match:
port = match.group("port")
vlan_id = int(match.group("vlan_id"))
......@@ -365,16 +367,16 @@ class Script(BaseScript):
# Get IPv4 interfaces
ipv4_interfaces = defaultdict(list) # interface -> [ipv4 addresses]
c_iface = None
for l in self.cli("show ip interface").splitlines():
match = self.rx_sh_ip_int.search(l)
for line in self.cli("show ip interface").splitlines():
match = self.rx_sh_ip_int.search(line)
if match:
c_iface = self.profile.convert_interface_name(match.group("interface").strip())
continue
# Primary ip
match = self.rx_ip.search(l)
match = self.rx_ip.search(line)
if not match:
# Secondary ip
match = self.rx_sec_ip.search(l)
match = self.rx_sec_ip.search(line)
if not match:
continue
ip = match.group("ip")
......@@ -386,8 +388,8 @@ class Script(BaseScript):
v = self.cli("show ipv6 interface")
except self.CLISyntaxError:
v = ""
for l in v.splitlines():
match = self.rx_sh_ip_int.search(l)
for line in v.splitlines():
match = self.rx_sh_ip_int.search(line)
if match:
iface = match.group("interface")
try:
......@@ -398,7 +400,7 @@ class Script(BaseScript):
if not c_iface:
continue # Skip wierd interfaces
# Primary ip
match = self.rx_ipv6.search(l)
match = self.rx_ipv6.search(line)
if not match:
# Secondary ip?
continue
......
# ---------------------------------------------------------------------
# Cisco.IOS.get_lldp_neighbors
# ---------------------------------------------------------------------
# Copyright (C) 2007-2019 The NOC Project
# Copyright (C) 2007-2020 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
......@@ -13,6 +13,24 @@ from noc.sa.profiles.Generic.get_lldp_neighbors import Script as BaseScript
from noc.sa.interfaces.igetlldpneighbors import IGetLLDPNeighbors
from noc.sa.interfaces.base import MACAddressParameter, IPv4Parameter
from noc.core.validators import is_int, is_ipv4, is_ipv6, is_mac
from noc.core.lldp import (
LLDP_PORT_SUBTYPE_ALIAS,
LLDP_PORT_SUBTYPE_MAC,
LLDP_PORT_SUBTYPE_NETWORK_ADDRESS,
LLDP_PORT_SUBTYPE_LOCAL,
LLDP_CHASSIS_SUBTYPE_MAC,
LLDP_CHASSIS_SUBTYPE_NETWORK_ADDRESS,
LLDP_CHASSIS_SUBTYPE_LOCAL,
LLDP_CAP_OTHER,
LLDP_CAP_REPEATER,
LLDP_CAP_BRIDGE,
LLDP_CAP_WLAN_ACCESS_POINT,
LLDP_CAP_ROUTER,
LLDP_CAP_TELEPHONE,
LLDP_CAP_DOCSIS_CABLE_DEVICE,
LLDP_CAP_STATION_ONLY,
lldp_caps_to_bits,
)
class Script(BaseScript):
......@@ -20,7 +38,7 @@ class Script(BaseScript):
interface = IGetLLDPNeighbors
rx_summary_split = re.compile(r"^Device ID.+?\n", re.MULTILINE | re.IGNORECASE)
rx_s_line = re.compile(r"^[\S+\s]*(?P<local_if>(?:Fa|Gi|Te|Fo)\d+[\d/\.]*)\s+.+$")
rx_s_line = re.compile(r"^[\S+\s]*(?P<local_if>(?:Fa|Gi|Te|Fo|Fi|Tw|Twe)\d+[\d/\.]*)\s+.+$")
rx_chassis_id = re.compile(r"^Chassis id:\s*(?P<id>\S+)", re.MULTILINE | re.IGNORECASE)
rx_remote_port = re.compile(r"^Port id:\s*(?P<remote_if>.+?)\s*$", re.MULTILINE | re.IGNORECASE)
rx_enabled_caps = re.compile(
......@@ -63,23 +81,20 @@ class Script(BaseScript):
# Get remote port
match = self.re_search(self.rx_remote_port, v)
remote_port = match.group("remote_if")
remote_port_subtype = 1
remote_port_subtype = LLDP_PORT_SUBTYPE_ALIAS
if is_ipv4(remote_port):
# Actually networkAddress(4)
remote_port = IPv4Parameter().clean(remote_port)
remote_port_subtype = 4
remote_port_subtype = LLDP_PORT_SUBTYPE_NETWORK_ADDRESS
elif is_mac(remote_port):
# Actually macAddress(3)
# Convert MAC to common form
remote_port = MACAddressParameter().clean(remote_port)
remote_port_subtype = 3
remote_port_subtype = LLDP_PORT_SUBTYPE_MAC
elif is_int(remote_port):
# Actually local(7)
remote_port_subtype = 7
remote_port_subtype = LLDP_PORT_SUBTYPE_LOCAL
n = {
"remote_port": remote_port,
"remote_port_subtype": remote_port_subtype,
"remote_chassis_id_subtype": 4,
"remote_chassis_id_subtype": LLDP_CHASSIS_SUBTYPE_MAC,
}
match = self.rx_descr.search(v)
if match:
......@@ -93,30 +108,30 @@ class Script(BaseScript):
cap = 0
match = self.rx_enabled_caps.search(v)
if match:
for c in match.group("caps").split(","):
c = c.strip()
if c:
cap |= {
"O": 1,
"P": 2,
"B": 4,
"W": 8,
"R": 16,
"T": 32,
"C": 64,
"S": 128,
}[c]
cap = lldp_caps_to_bits(
match.group("caps").strip().split(","),
{
"o": LLDP_CAP_OTHER,
"p": LLDP_CAP_REPEATER,
"b": LLDP_CAP_BRIDGE,
"w": LLDP_CAP_WLAN_ACCESS_POINT,
"r": LLDP_CAP_ROUTER,
"t": LLDP_CAP_TELEPHONE,
"c": LLDP_CAP_DOCSIS_CABLE_DEVICE,
"s": LLDP_CAP_STATION_ONLY,
},
)
n["remote_capabilities"] = cap
# Get remote chassis id
match = self.rx_system.search(v)
if match:
n["remote_system_name"] = match.group("name")
if is_ipv4(n["remote_chassis_id"]) or is_ipv6(n["remote_chassis_id"]):
n["remote_chassis_id_subtype"] = 5
n["remote_chassis_id_subtype"] = LLDP_CHASSIS_SUBTYPE_NETWORK_ADDRESS
elif is_mac(n["remote_chassis_id"]):
pass
else:
n["remote_chassis_id_subtype"] = 7
n["remote_chassis_id_subtype"] = LLDP_CHASSIS_SUBTYPE_LOCAL
i["neighbors"] += [n]
r += [i]
return r
......@@ -128,6 +128,10 @@ class Profile(BaseProfile):
return "CPP"
if il.startswith("srp"):
return "SRP %s" % interface[3:].strip()
if il.startswith("twe"):
if il.startswith("twe "):
return il.capitalize()
return "Twe %s" % interface[14:].strip()
if il.startswith("cable"):
match = self.rx_cable_if.search(interface)
if match:
......@@ -202,6 +206,7 @@ class Profile(BaseProfile):
"Et": "physical", # Ethernet
"Fa": "physical", # FastEthernet
"Fd": "physical", # Fddi
"Fi": "physical", # FiveGigabitEthernet
"Fo": "physical", # FortyGigabitEthernet
"Gi": "physical", # GigabitEthernet
"Gm": "physical", # GMPLS
......@@ -224,6 +229,7 @@ class Profile(BaseProfile):
"Te": "physical", # TenGigabitEthernet
"To": "physical", # TokenRing
"Tu": "tunnel", # Tunnel
"Tw": "physical", # TwoGigabitEthernet or TwentyFiveGigE
"Vi": "template", # Virtual-Template
"VL": "SVI", # VLAN, found on C3500XL
"Vl": "SVI", # Vlan
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment