本文整理汇总了Python中AutoNetkit.bgp_routers方法的典型用法代码示例。如果您正苦于以下问题:Python AutoNetkit.bgp_routers方法的具体用法?Python AutoNetkit.bgp_routers怎么用?Python AutoNetkit.bgp_routers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AutoNetkit
的用法示例。
在下文中一共展示了AutoNetkit.bgp_routers方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: configure
# 需要导入模块: import AutoNetkit [as 别名]
# 或者: from AutoNetkit import bgp_routers [as 别名]
def configure(self):
"""Configure C-BGP"""
LOG.info("Configuring C-BGP")
self.initialise()
default_weight = 1
template = lookup.get_template("cbgp/cbgp.mako")
physical_graph = self.network.graph
igp_graph = ank.igp_graph(self.network)
ibgp_graph = ank.get_ibgp_graph(self.network)
ebgp_graph = ank.get_ebgp_graph(self.network)
as_graphs = ank.get_as_graphs(self.network)
ip_as_allocs = ank.get_ip_as_allocs(self.network) # Allocs for ebgp announcements
physical_topology = defaultdict(dict)
ibgp_topology = {}
igp_topology = {}
ebgp_topology = {}
ebgp_prefixes = {}
bgp_routers = {}
# Fast lookup of loopbacks - the unique router ID for cBGP
loopback = dict( (n, self.network.lo_ip(n).ip) for n in physical_graph)
# Physical topology
for as_graph in as_graphs:
asn = as_graph.name
physical_topology[asn]['nodes'] = [loopback[n] for n in as_graph]
physical_topology[asn]['links'] = [ (loopback[s], loopback[t])
for (s,t) in unidirectional(as_graph.edges())]
# Interdomain links
interdomain_links = [ (loopback[s], loopback[t])
for (s,t) in unidirectional(ebgp_graph.edges())]
#IGP configuration
for as_graph in as_graphs:
asn = as_graph.name
igp_topology[asn] = {}
# Subgraph of IGP graph for this AS
as_igp_graph = igp_graph.subgraph(as_graph.nodes())
igp_topology[asn]['nodes'] = [loopback[n] for n in as_igp_graph]
igp_topology[asn]['links'] = [ (loopback[s], loopback[t], data.get('weight', default_weight))
for (s,t,data) in (as_graph.edges(data=True))]
# iBGP configuration
#TODO: if ibgp graph is a clique then use "bgp domain 1 full-mesh" where 1 is asn
# use nx.graph_clique_number(G) and compare to size of G, if same then is a clique
# otherwise create ibgp session by session
#TODO: add support for non full-mesh (need to find documentation on this)
for as_graph in as_graphs:
asn = as_graph.name
for router in as_graph:
if not router.is_router:
continue
if router not in ibgp_graph:
# likely single node AS
continue
ibgp_topology[router] = []
for peer in ibgp_graph.neighbors(router):
ibgp_topology[router].append(peer)
bgp_routers[asn] = [n.lo_ip.ip for n in ank.bgp_routers(self.network)
if n.asn == asn]
# eBGP configuration
for node in ebgp_graph.nodes():
node_id = loopback[node]
peers = []
for peer in ebgp_graph.neighbors(node):
peers.append( (self.network.asn(peer), loopback[peer]))
ebgp_topology[node_id] = peers
# Prefixes to originate
adv_subnet = ip_as_allocs[self.network.asn(node)]
ebgp_prefixes[node_id] = adv_subnet
#TODO: see if can just do for node in ebgp_graph ie without the .nodes() on end
# bgp policy
bgp_policy = {}
for router in self.network.routers():
for peer in self.network.g_session.neighbors(router):
pol_egress = self.network.g_session[router][peer]['egress']
pol_ingress = self.network.g_session[peer][router]['ingress']
if len(pol_ingress) or len(pol_egress):
try:
bgp_policy[router][peer] = {
'ingress': pol_ingress,
'egress': pol_egress,
}
except KeyError:
bgp_policy[router] = {}
bgp_policy[router][peer] = {
'ingress': pol_ingress,
'egress': pol_egress,
}
# tags dict for mapping from tag to community value, and for prefixes
tags = self.network.g_session.graph['tags']
prefixes = self.network.g_session.graph['prefixes']
#.........这里部分代码省略.........