def get_bgp_neighbors(self):
supported_afi = ["<STR_LIT>", "<STR_LIT>"]<EOL>bgp_neighbor_data = dict()<EOL>bgp_neighbor_data["<STR_LIT>"] = {}<EOL>cmd_bgp_all_sum = "<STR_LIT>"<EOL>summary_output = self._send_command(cmd_bgp_all_sum).strip()<EOL>if "<STR_LIT>" in summary_output:<EOL><INDENT>raise CommandErrorException("<STR_LIT>")<EOL><DEDENT>neighbor_output = "<STR_LIT>"<EOL>for afi in supported_afi:<EOL><INDENT>cmd_bgp_neighbor = "<STR_LIT>" % afi<EOL>neighbor_output += self._send_command(cmd_bgp_neighbor).strip()<EOL>neighbor_output += "<STR_LIT:\n>"<EOL><DEDENT>parse_summary = {<EOL>"<STR_LIT>": [<EOL>{<EOL>"<STR_LIT>": re.compile(r"<STR_LIT>"),<EOL>"<STR_LIT>": False,<EOL>},<EOL>{<EOL>"<STR_LIT>": re.compile(<EOL>r"<STR_LIT>"<EOL>r"<STR_LIT>".format(<EOL>IPV4_ADDR_REGEX, ASN_REGEX<EOL>)<EOL>),<EOL>"<STR_LIT>": False,<EOL>},<EOL>{<EOL>"<STR_LIT>": re.compile(<EOL>r"<STR_LIT>"<EOL>r"<STR_LIT>"<EOL>r"<STR_LIT>"<EOL>r"<STR_LIT>".format(<EOL>IPV4_ADDR_REGEX, IPV6_ADDR_REGEX, ASN_REGEX<EOL>)<EOL>),<EOL>"<STR_LIT>": True,<EOL>},<EOL>{<EOL>"<STR_LIT>": re.compile(<EOL>r"<STR_LIT>"<EOL>r"<STR_LIT>"<EOL>r"<STR_LIT>".format(<EOL>IPV4_ADDR_REGEX, IPV6_ADDR_REGEX, ASN_REGEX<EOL>)<EOL>),<EOL>"<STR_LIT>": True,<EOL>},<EOL>{<EOL>"<STR_LIT>": re.compile(<EOL>r"<STR_LIT>".format(<EOL>IPV4_ADDR_REGEX, IPV6_ADDR_REGEX<EOL>)<EOL>),<EOL>"<STR_LIT>": False,<EOL>},<EOL>{<EOL>"<STR_LIT>": re.compile(<EOL>r"<STR_LIT>"<EOL>r"<STR_LIT>"<EOL>r"<STR_LIT>".format(ASN_REGEX)<EOL>),<EOL>"<STR_LIT>": True,<EOL>},<EOL>{<EOL>"<STR_LIT>": re.compile(<EOL>r"<STR_LIT>"<EOL>r"<STR_LIT>".format(<EOL>ASN_REGEX<EOL>)<EOL>),<EOL>"<STR_LIT>": True,<EOL>},<EOL>],<EOL>"<STR_LIT>": [<EOL>"<STR_LIT>",<EOL>"<STR_LIT:state>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>],<EOL>}<EOL>parse_neighbors = {<EOL>"<STR_LIT>": [<EOL>{<EOL>"<STR_LIT>": re.compile(<EOL>r"<STR_LIT>"<EOL>r"<STR_LIT>".format(<EOL>IPV4_ADDR_REGEX, IPV6_ADDR_REGEX, ASN_REGEX<EOL>)<EOL>),<EOL>"<STR_LIT>": False,<EOL>},<EOL>{<EOL>"<STR_LIT>": re.compile(r"<STR_LIT>"),<EOL>"<STR_LIT>": False,<EOL>},<EOL>{<EOL>"<STR_LIT>": re.compile(<EOL>r"<STR_LIT>"<EOL>r"<STR_LIT>".format(IPV4_ADDR_REGEX)<EOL>),<EOL>"<STR_LIT>": False,<EOL>},<EOL>{<EOL>"<STR_LIT>": re.compile(r"<STR_LIT>"),<EOL>"<STR_LIT>": False,<EOL>},<EOL>{<EOL>"<STR_LIT>": re.compile(r"<STR_LIT>"),<EOL>"<STR_LIT>": False,<EOL>},<EOL>{<EOL>"<STR_LIT>": re.compile(<EOL>r"<STR_LIT>"<EOL>r"<STR_LIT>"<EOL>),<EOL>"<STR_LIT>": False,<EOL>},<EOL>{<EOL>"<STR_LIT>": re.compile(<EOL>r"<STR_LIT>"<EOL>),<EOL>"<STR_LIT>": True,<EOL>},<EOL>{<EOL>"<STR_LIT>": re.compile(r"<STR_LIT>"),<EOL>"<STR_LIT>": True,<EOL>},<EOL>],<EOL>"<STR_LIT>": [<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>],<EOL>}<EOL>summary_data = []<EOL>summary_data_entry = {}<EOL>for line in summary_output.splitlines():<EOL><INDENT>for item in parse_summary["<STR_LIT>"]:<EOL><INDENT>match = item["<STR_LIT>"].match(line)<EOL>if match:<EOL><INDENT>summary_data_entry.update(match.groupdict())<EOL>if item["<STR_LIT>"]:<EOL><INDENT>summary_data.append(copy.deepcopy(summary_data_entry))<EOL>for field in parse_summary["<STR_LIT>"]:<EOL><INDENT>try:<EOL><INDENT>del summary_data_entry[field]<EOL><DEDENT>except KeyError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT><DEDENT>break<EOL><DEDENT><DEDENT><DEDENT>neighbor_data = []<EOL>neighbor_data_entry = {}<EOL>for line in neighbor_output.splitlines():<EOL><INDENT>for item in parse_neighbors["<STR_LIT>"]:<EOL><INDENT>match = item["<STR_LIT>"].match(line)<EOL>if match:<EOL><INDENT>neighbor_data_entry.update(match.groupdict())<EOL>if item["<STR_LIT>"]:<EOL><INDENT>neighbor_data.append(copy.deepcopy(neighbor_data_entry))<EOL>for field in parse_neighbors["<STR_LIT>"]:<EOL><INDENT>try:<EOL><INDENT>del neighbor_data_entry[field]<EOL><DEDENT>except KeyError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT><DEDENT>break<EOL><DEDENT><DEDENT><DEDENT>router_id = None<EOL>for entry in summary_data:<EOL><INDENT>if not router_id:<EOL><INDENT>router_id = entry["<STR_LIT>"]<EOL><DEDENT>elif entry["<STR_LIT>"] != router_id:<EOL><INDENT>raise ValueError<EOL><DEDENT><DEDENT>router_id = napalm.base.helpers.ip(router_id, version=<NUM_LIT:4>)<EOL>bgp_neighbor_data["<STR_LIT>"]["<STR_LIT>"] = router_id<EOL>bgp_neighbor_data["<STR_LIT>"]["<STR_LIT>"] = {}<EOL>for entry in summary_data:<EOL><INDENT>remote_addr = napalm.base.helpers.ip(entry["<STR_LIT>"])<EOL>afi = entry["<STR_LIT>"].lower()<EOL>if afi not in supported_afi:<EOL><INDENT>continue<EOL><DEDENT>neighbor_entry = None<EOL>for neighbor in neighbor_data:<EOL><INDENT>if (<EOL>neighbor["<STR_LIT>"].lower() == afi<EOL>and napalm.base.helpers.ip(neighbor["<STR_LIT>"]) == remote_addr<EOL>):<EOL><INDENT>neighbor_entry = neighbor<EOL>break<EOL><DEDENT><DEDENT>if neighbor_entry is None:<EOL><INDENT>continue<EOL><DEDENT>elif not isinstance(neighbor_entry, dict):<EOL><INDENT>raise ValueError(<EOL>msg="<STR_LIT>"<EOL>% (remote_addr, afi)<EOL>)<EOL><DEDENT>try:<EOL><INDENT>if "<STR_LIT>" in entry["<STR_LIT:state>"]:<EOL><INDENT>is_enabled = False<EOL><DEDENT>else:<EOL><INDENT>is_enabled = True<EOL><DEDENT><DEDENT>except KeyError:<EOL><INDENT>is_enabled = True<EOL><DEDENT>uptime = self.bgp_time_conversion(entry["<STR_LIT>"])<EOL>is_up = "<STR_LIT>" in neighbor_entry["<STR_LIT:state>"]<EOL>try:<EOL><INDENT>accepted_prefixes = int(entry["<STR_LIT>"])<EOL><DEDENT>except (ValueError, KeyError):<EOL><INDENT>accepted_prefixes = -<NUM_LIT:1><EOL><DEDENT>if is_up:<EOL><INDENT>try:<EOL><INDENT>accepted_prefixes = int(neighbor_entry["<STR_LIT>"])<EOL><DEDENT>except (ValueError, KeyError):<EOL><INDENT>pass<EOL><DEDENT>received_prefixes = neighbor_entry.get(<EOL>"<STR_LIT>", accepted_prefixes<EOL>)<EOL>sent_prefixes = int(neighbor_entry.get("<STR_LIT>", -<NUM_LIT:1>))<EOL><DEDENT>else:<EOL><INDENT>received_prefixes = -<NUM_LIT:1><EOL>sent_prefixes = -<NUM_LIT:1><EOL>uptime = -<NUM_LIT:1><EOL><DEDENT>try:<EOL><INDENT>description = py23_compat.text_type(neighbor_entry["<STR_LIT:description>"])<EOL><DEDENT>except KeyError:<EOL><INDENT>description = "<STR_LIT>"<EOL><DEDENT>remote_id = napalm.base.helpers.ip(neighbor_entry["<STR_LIT>"], version=<NUM_LIT:4>)<EOL>if remote_addr not in bgp_neighbor_data["<STR_LIT>"]["<STR_LIT>"]:<EOL><INDENT>bgp_neighbor_data["<STR_LIT>"]["<STR_LIT>"][remote_addr] = {<EOL>"<STR_LIT>": napalm.base.helpers.as_number(entry["<STR_LIT>"]),<EOL>"<STR_LIT>": napalm.base.helpers.as_number(entry["<STR_LIT>"]),<EOL>"<STR_LIT>": remote_id,<EOL>"<STR_LIT>": is_up,<EOL>"<STR_LIT>": is_enabled,<EOL>"<STR_LIT:description>": description,<EOL>"<STR_LIT>": uptime,<EOL>"<STR_LIT>": {<EOL>afi: {<EOL>"<STR_LIT>": received_prefixes,<EOL>"<STR_LIT>": accepted_prefixes,<EOL>"<STR_LIT>": sent_prefixes,<EOL>}<EOL>},<EOL>}<EOL><DEDENT>else:<EOL><INDENT>existing = bgp_neighbor_data["<STR_LIT>"]["<STR_LIT>"][remote_addr]<EOL>assert afi not in existing["<STR_LIT>"]<EOL>assert existing["<STR_LIT>"] == napalm.base.helpers.as_number(<EOL>entry["<STR_LIT>"]<EOL>)<EOL>assert existing["<STR_LIT>"] == napalm.base.helpers.as_number(<EOL>entry["<STR_LIT>"]<EOL>)<EOL>assert existing["<STR_LIT>"] == remote_id<EOL>assert existing["<STR_LIT>"] == is_enabled<EOL>assert existing["<STR_LIT:description>"] == description<EOL>existing["<STR_LIT>"] = existing["<STR_LIT>"] or is_up<EOL>existing["<STR_LIT>"] = max(existing["<STR_LIT>"], uptime)<EOL>existing["<STR_LIT>"][afi] = {<EOL>"<STR_LIT>": received_prefixes,<EOL>"<STR_LIT>": accepted_prefixes,<EOL>"<STR_LIT>": sent_prefixes,<EOL>}<EOL><DEDENT><DEDENT>return bgp_neighbor_data<EOL>
BGP neighbor information.

        Currently no VRF support. Supports both IPv4 and IPv6.