def show_isis_topology(router): """ Get the ISIS topology in a dictionary format. Sample: { 'area-name': { 'level-1': [ { 'vertex': 'r1' } ], 'level-2': [ { 'vertex': '10.0.0.1/24', 'type': 'IP', 'parent': '0', 'metric': 'internal' } ] }, 'area-name-2': { 'level-2': [ { "interface": "rX-ethY", "metric": "Z", "next-hop": "rA", "parent": "rC(B)", "type": "TE-IS", "vertex": "rD" } ] } } """ l1out = topotest.normalize_text( router.vtysh_cmd('show isis topology level-1') ).splitlines() l2out = topotest.normalize_text( router.vtysh_cmd('show isis topology level-2') ).splitlines() l1 = parse_topology(l1out, 'level-1') l2 = parse_topology(l2out, 'level-2') dict_merge(l1, l2) return l1
def version_info(self): "Get equipment information from 'show version'." output = self.vtysh_cmd('show version').split('\n')[0] columns = topotest.normalize_text(output).split(' ') try: return { 'type': columns[0], 'version': columns[1], } except IndexError: return { 'type': None, 'version': None, }
def version_info(self): "Get equipment information from 'show version'." output = self.vtysh_cmd('show version').split('\n')[0] columns = topotest.normalize_text(output).split(' ') try: return { 'type': columns[0], 'version': columns[1], } except IndexError: return { 'type': None, 'version': None, }
def show_isis_interface_detail(router, rname): """ Get the show isis mpls ldp-sync info in a dictionary format. """ out = topotest.normalize_text( router.vtysh_cmd("show isis interface detail")).splitlines() logger.warning(out) parsed = parse_show_isis_interface_detail(out, rname) logger.warning(parsed) return parsed
def compare_show_ipv6(rname, expected): """ Calls 'show ipv6 route' for router `rname` and compare the obtained result with the expected output. """ tgen = get_topogen() # Use the vtysh output, with some masking to make comparison easy current = topotest.ip6_route_zebra(tgen.gears[rname]) # Use just the 'O'spf lines of the output linearr = [] for line in current.splitlines(): if re.match("^O", line): linearr.append(line) current = "\n".join(linearr) return topotest.difflines( topotest.normalize_text(current), topotest.normalize_text(expected), title1="Current output", title2="Expected output", )
def ospf_get_lsa_type5(router_name): "Return a dict with link state id as key and forwarding addresses as value" result = dict() tgen = get_topogen() router = tgen.gears[router_name] cmd = "show ip ospf database external\n" output = topotest.normalize_text(router.vtysh_cmd(cmd)) for line in output.splitlines(): re0 = re.match(r"\s+Link State ID: (\S+) \(External Network Number\)", line) if re0: lsa = re0.group(1) re1 = re.match(r"\s+Forward Address: (\S+)", line) if re1: result[lsa] = re1.group(1) return result
def ip_eigrp_topo(node): """ Parse 'show ip eigrp topo' from `node` and returns a dict with the result. Example: { 'P': { '192.168.1.0/24': { 'sucessors': 1, 'fd': 112233, 'serno': 0, 'via': 'Connected', 'interface': 'eth0', }, '192.168.2.0/24': { 'sucessors': 1, 'fd': 112234, 'serno': 0, 'via': 'Connected', 'interface': 'eth1', } } } """ output = topotest.normalize_text( node.vtysh_cmd('show ip eigrp topo')).splitlines() result = {} for idx, line in enumerate(output): columns = line.split(' ', 1) # Parse the following format into python dicts # code A.B.C.D/E, X successors, FD is Y, serno: Z # via FOO, interface-name code = columns[0] if code not in ['P', 'A', 'U', 'Q', 'R', 'r', 's']: continue if not result.has_key(code): result[code] = {} # Split network from the rest columns = columns[1].split(',') # Parse first line data network = columns[0] result[code][network] = {} for column in columns: # Skip the network column if column == columns[0]: continue match = re.search(r'(\d+) successors', column) if match is not None: result[code][network]['successors'] = match.group(1) continue match = re.search(r'FD is (\d+)', column) if match is not None: result[code][network]['fd'] = match.group(1) continue match = re.search(r'serno: (\d+)', column) if match is not None: result[code][network]['serno'] = match.group(1) continue # Parse second line data nextline = output[idx + 1] columns = topotest.normalize_text(nextline).split(',') for column in columns: match = re.search(r'via (.+)', column) if match is not None: result[code][network]['via'] = match.group(1) continue match = re.search(r'(.+)', column) if match is not None: result[code][network]['interface'] = match.group(1) continue return result
def ip_eigrp_topo(node): """ Parse 'show ip eigrp topo' from `node` and returns a dict with the result. Example: { 'P': { '192.168.1.0/24': { 'sucessors': 1, 'fd': 112233, 'serno': 0, 'via': 'Connected', 'interface': 'eth0', }, '192.168.2.0/24': { 'sucessors': 1, 'fd': 112234, 'serno': 0, 'via': 'Connected', 'interface': 'eth1', } } } """ output = topotest.normalize_text( node.vtysh_cmd("show ip eigrp topo")).splitlines() result = {} for idx, line in enumerate(output): columns = line.split(" ", 1) # Parse the following format into python dicts # code A.B.C.D/E, X successors, FD is Y, serno: Z # via FOO, interface-name code = columns[0] if code not in ["P", "A", "U", "Q", "R", "r", "s"]: continue if code not in result: result[code] = {} # Split network from the rest columns = columns[1].split(",") # Parse first line data network = columns[0] result[code][network] = {} for column in columns: # Skip the network column if column == columns[0]: continue match = re.search(r"(\d+) successors", column) if match is not None: result[code][network]["successors"] = match.group(1) continue match = re.search(r"FD is (\d+)", column) if match is not None: result[code][network]["fd"] = match.group(1) continue match = re.search(r"serno: (\d+)", column) if match is not None: result[code][network]["serno"] = match.group(1) continue # Parse second line data nextline = output[idx + 1] columns = topotest.normalize_text(nextline).split(",") for column in columns: match = re.search(r"via (.+)", column) if match is not None: result[code][network]["via"] = match.group(1) continue match = re.search(r"(.+)", column) if match is not None: result[code][network]["interface"] = match.group(1) continue return result