Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# trim out non-used values
g_phy = anm["phy"]
r1_phy = g_phy.node("r1")
r1_phy_lo100 = r1_phy.add_interface(
"Loopback100", id="Loopback100", category="logical")
for iface in r1_phy.interfaces():
print iface.dump()
g_phy_live = anm.add_overlay("phy_live", multi_edge=True)
g_phy_live.add_nodes_from(anm['phy'])
g_phy_live.add_edges_from(anm['phy'].edges())
g_phy_live.data.paths = [] # to store paths onto
ank_utils.copy_int_attr_from(anm['phy'], anm['phy_live'], "id")
for overlay_id in ("ospf_live", "eigrp_live", "rip_live", "isis_live"):
g_overlay = anm.add_overlay(
overlay_id, directed=True, multi_edge=True)
g_overlay.add_nodes_from(anm['phy'])
for overlay_id in ("ibgp_v4_live", "ebgp_v4_live"):
g_overlay = anm.add_overlay(overlay_id, directed=True,)
g_overlay.add_nodes_from(anm['phy'])
print anm.overlays()
g_ospf_live = anm["ospf_live"]
print g_ospf_live.nodes()
r1_ospf = g_ospf_live.node("r1")
r2_ospf = g_ospf_live.node("r2")
def test_copy_int_attr_from(self):
anm = autonetkit.topos.house()
g_in = anm['input']
g_phy = anm['phy']
result = [iface.get('ospf_cost') for node in g_phy for iface in node]
expected_result = [None, None, None, None, None, None, None, None,
None, None, None, None]
self.assertListEqual(expected_result, result)
for node in g_in:
for interface in node:
interface.set('ospf_cost', 10)
ank_utils.copy_int_attr_from(g_in, g_phy, "ospf_cost")
result = [iface.get('ospf_cost') for node in g_phy for iface in node]
expected_result = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]
self.assertListEqual(expected_result, result)
def build_ebgp(anm):
g_l3 = anm['layer3']
g_ebgp = anm.add_overlay("ebgp", directed=True)
g_ebgp.add_nodes_from(g_l3.routers())
ank_utils.copy_int_attr_from(g_l3, g_ebgp, "multipoint")
ebgp_edges = [e for e in g_l3.edges() if e.src.asn != e.dst.asn]
g_ebgp.add_edges_from(ebgp_edges, bidirectional=True, type='ebgp')
def build_ebgp(anm):
g_l3 = anm['layer3']
g_ebgp = anm.add_overlay("ebgp", directed=True)
g_ebgp.add_nodes_from(g_l3.routers())
ank_utils.copy_int_attr_from(g_l3, g_ebgp, "multipoint")
ebgp_edges = [e for e in g_l3.edges() if e.src.asn != e.dst.asn]
g_ebgp.add_edges_from(ebgp_edges, bidirectional=True, type='ebgp')
g_l3 = anm['layer3']
g_phy = anm['phy']
# add regardless, so allows quick check of node in anm['ospf'] in compilers
g_ospf = anm.add_overlay("ospf")
if not anm['phy'].data.enable_routing:
g_ospf.log.info("Routing disabled, not configuring OSPF")
return
if not any(n.igp == "ospf" for n in g_phy):
g_ospf.log.debug("No OSPF nodes")
return
ospf_nodes = [n for n in g_l3 if n['phy'].igp == "ospf"]
g_ospf.add_nodes_from(ospf_nodes)
g_ospf.add_edges_from(g_l3.edges(), warn=False)
ank_utils.copy_int_attr_from(g_l3, g_ospf, "multipoint")
# TODO: work out why this doesnt work
# ank_utils.copy_int_attr_from(g_in, g_ospf, "ospf_cost", dst_attr="cost", type=int, default = 1)
for node in g_ospf:
for interface in node.interfaces():
interface.cost = 1
'''Sharad: Will there be any errors if we use the above loop instead of the 2 loops below
for interface in node.physical_interfaces():
interface.cost = 1
for interface in node.portchannel_interfaces():
interface.cost = 1
'''
ank_utils.copy_attr_from(g_in, g_ospf, "ospf_area", dst_attr="area")
# ank_utils.copy_edge_attr_from(g_in, g_ospf, "ospf_cost", dst_attr="cost", type=int, default = 1)
ank_utils.copy_attr_from(
g_l3 = anm['layer3']
g_phy = anm['phy']
g_isis = anm.add_overlay("isis")
if not anm['phy'].data.enable_routing:
g_isis.log.info("Routing disabled, not configuring ISIS")
return
if not any(n.igp == "isis" for n in g_phy):
g_isis.log.debug("No ISIS nodes")
return
isis_nodes = [n for n in g_l3 if n['phy'].igp == "isis"]
g_isis.add_nodes_from(isis_nodes)
g_isis.add_edges_from(g_l3.edges(), warn=False)
ank_utils.copy_int_attr_from(g_l3, g_isis, "multipoint")
ank_utils.copy_attr_from(
g_in, g_isis, "custom_config_isis", dst_attr="custom_config")
g_isis.remove_edges_from(
[link for link in g_isis.edges() if link.src.asn != link.dst.asn])
build_network_entity_title(anm)
for node in g_isis.routers():
node.process_id = node.asn
for link in g_isis.edges():
link.metric = 1 # default
for edge in g_isis.edges():
g_l3 = anm['layer3']
g_phy = anm['phy']
g_isis = anm.add_overlay("isis")
if not anm['phy'].data.enable_routing:
g_isis.log.info("Routing disabled, not configuring ISIS")
return
if not any(n.igp == "isis" for n in g_phy):
g_isis.log.debug("No ISIS nodes")
return
isis_nodes = [n for n in g_l3 if n['phy'].igp == "isis"]
g_isis.add_nodes_from(isis_nodes)
g_isis.add_edges_from(g_l3.edges(), warn=False)
ank_utils.copy_int_attr_from(g_l3, g_isis, "multipoint")
ank_utils.copy_attr_from(
g_in, g_isis, "custom_config_isis", dst_attr="custom_config")
g_isis.remove_edges_from(
[link for link in g_isis.edges() if link.src.asn != link.dst.asn])
build_network_entity_title(anm)
for node in g_isis.routers():
node.process_id = node.asn
for link in g_isis.edges():
link.metric = 1 # default
for edge in g_isis.edges():
g_l3 = anm['layer3']
g_phy = anm['phy']
# add regardless, so allows quick check of node in anm['ospf'] in compilers
g_ospf = anm.add_overlay("ospf")
if not anm['phy'].data.enable_routing:
g_ospf.log.info("Routing disabled, not configuring OSPF")
return
if not any(n.igp == "ospf" for n in g_phy):
g_ospf.log.debug("No OSPF nodes")
return
ospf_nodes = [n for n in g_l3 if n['phy'].igp == "ospf"]
g_ospf.add_nodes_from(ospf_nodes)
g_ospf.add_edges_from(g_l3.edges(), warn=False)
ank_utils.copy_int_attr_from(g_l3, g_ospf, "multipoint")
# TODO: work out why this doesnt work
#ank_utils.copy_int_attr_from(g_in, g_ospf, "ospf_cost", dst_attr="cost", type=int, default = 1)
for node in g_ospf:
for interface in node.physical_interfaces():
interface.cost = 1
ank_utils.copy_attr_from(g_in, g_ospf, "ospf_area", dst_attr="area")
#ank_utils.copy_edge_attr_from(g_in, g_ospf, "ospf_cost", dst_attr="cost", type=int, default = 1)
ank_utils.copy_attr_from(
g_in, g_ospf, "custom_config_ospf", dst_attr="custom_config")
g_ospf.remove_edges_from([link for link in g_ospf.edges(
) if link.src.asn != link.dst.asn]) # remove inter-AS links
area_zero_ip = netaddr.IPAddress("0.0.0.0")