diff options
71 files changed, 1640 insertions, 196 deletions
diff --git a/doc/developer/topotests.rst b/doc/developer/topotests.rst index b32f2bbf49..5486fd826d 100644 --- a/doc/developer/topotests.rst +++ b/doc/developer/topotests.rst @@ -722,7 +722,7 @@ Example: .. code:: py # For all registered routers, load the zebra configuration file - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, '{}/zebra.conf'.format(rname)) diff --git a/lib/northbound.c b/lib/northbound.c index 895647cfb7..99c6ab57ec 100644 --- a/lib/northbound.c +++ b/lib/northbound.c @@ -122,8 +122,8 @@ static int nb_node_new_cb(const struct lys_node *snode, void *arg) if (CHECK_FLAG(snode->nodetype, LYS_CONTAINER | LYS_LIST)) { bool config_only = true; - yang_snodes_iterate_subtree(snode, nb_node_check_config_only, - YANG_ITER_ALLOW_AUGMENTATIONS, + yang_snodes_iterate_subtree(snode, NULL, + nb_node_check_config_only, 0, &config_only); if (config_only) SET_FLAG(nb_node->flags, F_NB_NODE_CONFIG_ONLY); @@ -141,6 +141,7 @@ static int nb_node_new_cb(const struct lys_node *snode, void *arg) * another. */ nb_node->snode = snode; + assert(snode->priv == NULL); lys_set_private(snode, nb_node); return YANG_ITER_CONTINUE; diff --git a/lib/yang.c b/lib/yang.c index 9bfdcb858c..5bf7758e18 100644 --- a/lib/yang.c +++ b/lib/yang.c @@ -147,11 +147,15 @@ struct yang_module *yang_module_find(const char *module_name) } int yang_snodes_iterate_subtree(const struct lys_node *snode, + const struct lys_module *module, yang_iterate_cb cb, uint16_t flags, void *arg) { struct lys_node *child; int ret = YANG_ITER_CONTINUE; + if (module && snode->module != module) + goto next; + if (CHECK_FLAG(flags, YANG_ITER_FILTER_IMPLICIT)) { switch (snode->nodetype) { case LYS_CASE: @@ -214,11 +218,8 @@ next: return YANG_ITER_CONTINUE; LY_TREE_FOR (snode->child, child) { - if (!CHECK_FLAG(flags, YANG_ITER_ALLOW_AUGMENTATIONS) - && child->parent != snode) - continue; - - ret = yang_snodes_iterate_subtree(child, cb, flags, arg); + ret = yang_snodes_iterate_subtree(child, module, cb, flags, + arg); if (ret == YANG_ITER_STOP) return ret; } @@ -233,15 +234,16 @@ int yang_snodes_iterate_module(const struct lys_module *module, int ret = YANG_ITER_CONTINUE; LY_TREE_FOR (module->data, snode) { - ret = yang_snodes_iterate_subtree(snode, cb, flags, arg); + ret = yang_snodes_iterate_subtree(snode, module, cb, flags, + arg); if (ret == YANG_ITER_STOP) return ret; } for (uint8_t i = 0; i < module->augment_size; i++) { ret = yang_snodes_iterate_subtree( - (const struct lys_node *)&module->augment[i], cb, flags, - arg); + (const struct lys_node *)&module->augment[i], module, + cb, flags, arg); if (ret == YANG_ITER_STOP) return ret; } @@ -255,9 +257,14 @@ int yang_snodes_iterate_all(yang_iterate_cb cb, uint16_t flags, void *arg) int ret = YANG_ITER_CONTINUE; RB_FOREACH (module, yang_modules, &yang_modules) { - ret = yang_snodes_iterate_module(module->info, cb, flags, arg); - if (ret == YANG_ITER_STOP) - return ret; + struct lys_node *snode; + + LY_TREE_FOR (module->info->data, snode) { + ret = yang_snodes_iterate_subtree(snode, NULL, cb, + flags, arg); + if (ret == YANG_ITER_STOP) + return ret; + } } return ret; diff --git a/lib/yang.h b/lib/yang.h index 94bbed233d..867ade9676 100644 --- a/lib/yang.h +++ b/lib/yang.h @@ -102,9 +102,6 @@ enum yang_iter_flags { /* Filter implicitely created nodes. */ YANG_ITER_FILTER_IMPLICIT = (1<<3), - - /* Allow iteration over augmentations. */ - YANG_ITER_ALLOW_AUGMENTATIONS = (1<<4), }; /* Callback used by the yang_snodes_iterate_*() family of functions. */ @@ -168,6 +165,9 @@ extern void yang_module_embed(struct yang_module_embed *embed); * snode * YANG schema node to operate on. * + * module + * When set, iterate over all nodes of the specified module only. + * * cb * Function to call with each schema node. * @@ -181,6 +181,7 @@ extern void yang_module_embed(struct yang_module_embed *embed); * The return value of the last called callback. */ extern int yang_snodes_iterate_subtree(const struct lys_node *snode, + const struct lys_module *module, yang_iterate_cb cb, uint16_t flags, void *arg); diff --git a/ospfd/ospf_abr.c b/ospfd/ospf_abr.c index f6c0504999..5a9adcba0d 100644 --- a/ospfd/ospf_abr.c +++ b/ospfd/ospf_abr.c @@ -642,6 +642,15 @@ static int ospf_abr_translate_nssa(struct ospf_area *area, struct ospf_lsa *lsa) old = ospf_external_info_find_lsa(area->ospf, &p); if (old) { + /* Do not continue if type 5 LSA not approved */ + if (!CHECK_FLAG(old->flags, OSPF_LSA_APPROVED)) { + if (IS_DEBUG_OSPF_NSSA) + zlog_debug( + "ospf_abr_translate_nssa(): LSA Id %s type 5 is not approved", + inet_ntoa(old->data->id)); + return 1; + } + if (IS_DEBUG_OSPF_NSSA) zlog_debug( "ospf_abr_translate_nssa(): found old translated LSA Id %s, refreshing", diff --git a/ospfd/ospf_lsa.c b/ospfd/ospf_lsa.c index 376310e4ff..8095219146 100644 --- a/ospfd/ospf_lsa.c +++ b/ospfd/ospf_lsa.c @@ -1796,7 +1796,15 @@ struct ospf_lsa *ospf_translated_nssa_originate(struct ospf *ospf, return NULL; } - extnew = (struct as_external_lsa *)new; + extnew = (struct as_external_lsa *)new->data; + + if ((new = ospf_lsa_install(ospf, NULL, new)) == NULL) { + flog_warn( + EC_OSPF_LSA_INSTALL_FAILURE, + "ospf_lsa_translated_nssa_originate(): Could not install LSA id %s", + inet_ntoa(type7->data->id)); + return NULL; + } if (IS_DEBUG_OSPF_NSSA) { zlog_debug( @@ -1807,13 +1815,6 @@ struct ospf_lsa *ospf_translated_nssa_originate(struct ospf *ospf, inet_ntoa(extnew->e[0].fwd_addr)); } - if ((new = ospf_lsa_install(ospf, NULL, new)) == NULL) { - flog_warn(EC_OSPF_LSA_INSTALL_FAILURE, - "ospf_lsa_translated_nssa_originate(): Could not install LSA id %s", - inet_ntoa(type7->data->id)); - return NULL; - } - ospf->lsa_originate_count++; ospf_flood_through_as(ospf, NULL, new); diff --git a/ospfd/ospf_zebra.c b/ospfd/ospf_zebra.c index 0487ace301..dc8a8dccd2 100644 --- a/ospfd/ospf_zebra.c +++ b/ospfd/ospf_zebra.c @@ -1355,16 +1355,26 @@ static int ospf_distribute_list_update_timer(struct thread *thread) else if ( (lsa = ospf_external_info_find_lsa( ospf, &ei->p))) { - if (!CHECK_FLAG( - lsa->flags, - OSPF_LSA_IN_MAXAGE)) - ospf_external_lsa_refresh( - ospf, lsa, ei, - LSA_REFRESH_IF_CHANGED); - else - ospf_external_lsa_refresh( - ospf, lsa, ei, - LSA_REFRESH_FORCE); + int force = + LSA_REFRESH_IF_CHANGED; + /* If this is a MaxAge LSA, we + * need to force refresh it + * because distribute settings + * might have changed and now, + * this LSA needs to be + * originated, not be removed. + * If we don't force refresh it, + * it will remain a MaxAge LSA + * because it will look like it + * hasn't changed. Neighbors + * will not receive updates for + * this LSA. + */ + if (IS_LSA_MAXAGE(lsa)) + force = LSA_REFRESH_FORCE; + + ospf_external_lsa_refresh( + ospf, lsa, ei, force); } else ospf_external_lsa_originate( ospf, ei); diff --git a/tests/topotests/bfd-bgp-cbit-topo3/test_bfd_bgp_cbit_topo3.py b/tests/topotests/bfd-bgp-cbit-topo3/test_bfd_bgp_cbit_topo3.py index 186dac31a0..7d1521c8b2 100755..100644 --- a/tests/topotests/bfd-bgp-cbit-topo3/test_bfd_bgp_cbit_topo3.py +++ b/tests/topotests/bfd-bgp-cbit-topo3/test_bfd_bgp_cbit_topo3.py @@ -72,7 +72,7 @@ def setup_module(mod): router_list = tgen.routers() - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)), ) diff --git a/tests/topotests/bfd-isis-topo1/test_bfd_isis_topo1.py b/tests/topotests/bfd-isis-topo1/test_bfd_isis_topo1.py index a1ed0cc2af..1adfec76d8 100755..100644 --- a/tests/topotests/bfd-isis-topo1/test_bfd_isis_topo1.py +++ b/tests/topotests/bfd-isis-topo1/test_bfd_isis_topo1.py @@ -136,7 +136,7 @@ def setup_module(mod): router_list = tgen.routers() # For all registered routers, load the zebra configuration file - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) diff --git a/tests/topotests/bfd-profiles-topo1/test_bfd_profiles_topo1.py b/tests/topotests/bfd-profiles-topo1/test_bfd_profiles_topo1.py index 02385b32e5..514933b891 100755..100644 --- a/tests/topotests/bfd-profiles-topo1/test_bfd_profiles_topo1.py +++ b/tests/topotests/bfd-profiles-topo1/test_bfd_profiles_topo1.py @@ -84,7 +84,7 @@ def setup_module(mod): tgen.start_topology() router_list = tgen.routers() - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): daemon_file = "{}/{}/bfdd.conf".format(CWD, rname) if os.path.isfile(daemon_file): router.load_config(TopoRouter.RD_BFD, daemon_file) diff --git a/tests/topotests/bfd-topo1/test_bfd_topo1.py b/tests/topotests/bfd-topo1/test_bfd_topo1.py index e1865dc5a8..5306fdf353 100644 --- a/tests/topotests/bfd-topo1/test_bfd_topo1.py +++ b/tests/topotests/bfd-topo1/test_bfd_topo1.py @@ -76,7 +76,7 @@ def setup_module(mod): tgen.start_topology() router_list = tgen.routers() - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) diff --git a/tests/topotests/bfd-topo2/test_bfd_topo2.py b/tests/topotests/bfd-topo2/test_bfd_topo2.py index 3e87e8485a..2c5ce3e4c3 100644 --- a/tests/topotests/bfd-topo2/test_bfd_topo2.py +++ b/tests/topotests/bfd-topo2/test_bfd_topo2.py @@ -77,7 +77,7 @@ def setup_module(mod): tgen.start_topology() router_list = tgen.routers() - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) diff --git a/tests/topotests/bfd-topo3/test_bfd_topo3.py b/tests/topotests/bfd-topo3/test_bfd_topo3.py index bcee338a92..fa68ace59d 100644 --- a/tests/topotests/bfd-topo3/test_bfd_topo3.py +++ b/tests/topotests/bfd-topo3/test_bfd_topo3.py @@ -76,7 +76,7 @@ def setup_module(mod): tgen.start_topology() router_list = tgen.routers() - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): daemon_file = "{}/{}/bfdd.conf".format(CWD, rname) if os.path.isfile(daemon_file): router.load_config(TopoRouter.RD_BFD, daemon_file) diff --git a/tests/topotests/bfd-vrf-topo1/test_bfd_vrf_topo1.py b/tests/topotests/bfd-vrf-topo1/test_bfd_vrf_topo1.py index b1f755ad06..95595ecba4 100755..100644 --- a/tests/topotests/bfd-vrf-topo1/test_bfd_vrf_topo1.py +++ b/tests/topotests/bfd-vrf-topo1/test_bfd_vrf_topo1.py @@ -79,7 +79,7 @@ def setup_module(mod): router_list = tgen.routers() # check for zebra capability - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): if router.check_capability(TopoRouter.RD_ZEBRA, "--vrfwnetns") == False: return pytest.skip( "Skipping BFD Topo1 VRF NETNS feature. VRF NETNS backend not available on FRR" @@ -105,7 +105,7 @@ def setup_module(mod): "ip netns exec {0}-cust1 ifconfig {0}-eth2 up", ] - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): # create VRF rx-cust1 and link rx-eth0 to rx-cust1 for cmd in cmds: output = tgen.net[rname].cmd(cmd.format(rname)) @@ -113,7 +113,7 @@ def setup_module(mod): for cmd in cmds2: output = tgen.net[rname].cmd(cmd.format(rname)) - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)), @@ -145,7 +145,7 @@ def teardown_module(_mod): ] router_list = tgen.routers() - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): if rname == "r2": for cmd in cmds2: tgen.net[rname].cmd(cmd.format(rname)) diff --git a/tests/topotests/bgp-auth/test_bgp_auth.py b/tests/topotests/bgp-auth/test_bgp_auth.py index 6198997b86..286af3bf65 100755..100644 --- a/tests/topotests/bgp-auth/test_bgp_auth.py +++ b/tests/topotests/bgp-auth/test_bgp_auth.py @@ -217,7 +217,7 @@ def setup_module(mod): router_list = tgen.routers() # For all registred routers, load the zebra configuration file - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) @@ -273,7 +273,7 @@ def print_diag(vrf): tgen = get_topogen() router_list = tgen.routers() - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): print(rname + ":") print(router.vtysh_cmd("show run")) print(router.vtysh_cmd("show ip route {}".format(vrf_str(vrf)))) @@ -285,7 +285,7 @@ def configure(conf_file): tgen = get_topogen() router_list = tgen.routers() - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): with open( os.path.join(CWD, "{}/{}").format(router.name, conf_file), "r+" ) as cfg: @@ -321,7 +321,7 @@ def clear_ospf(vrf=""): tgen = get_topogen() router_list = tgen.routers() - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): if vrf == "": router.vtysh_cmd("conf t\nno router ospf") else: diff --git a/tests/topotests/bgp-ecmp-topo1/test_bgp_ecmp_topo1.py b/tests/topotests/bgp-ecmp-topo1/test_bgp_ecmp_topo1.py index c37f818b0f..400e7e9bf5 100755..100644 --- a/tests/topotests/bgp-ecmp-topo1/test_bgp_ecmp_topo1.py +++ b/tests/topotests/bgp-ecmp-topo1/test_bgp_ecmp_topo1.py @@ -95,7 +95,7 @@ def setup_module(module): # Starting Routers router_list = tgen.routers() - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) @@ -107,7 +107,7 @@ def setup_module(module): # Starting Hosts and init ExaBGP on each of them topotest.sleep(10, "starting BGP on all {} peers".format(total_ebgp_peers)) peer_list = tgen.exabgp_peers() - for pname, peer in peer_list.iteritems(): + for pname, peer in peer_list.items(): peer_dir = os.path.join(CWD, pname) env_file = os.path.join(CWD, "exabgp.env") peer.start(peer_dir, env_file) diff --git a/tests/topotests/bgp-ecmp-topo2/test_ebgp_ecmp_topo2.py b/tests/topotests/bgp-ecmp-topo2/test_ebgp_ecmp_topo2.py index 6068f5f831..eed118ebdc 100755..100644 --- a/tests/topotests/bgp-ecmp-topo2/test_ebgp_ecmp_topo2.py +++ b/tests/topotests/bgp-ecmp-topo2/test_ebgp_ecmp_topo2.py @@ -145,7 +145,7 @@ def setup_module(mod): link_data = [ val - for links, val in topo["routers"]["r2"]["links"].iteritems() + for links, val in topo["routers"]["r2"]["links"].items() if "r3" in links ] for adt in ADDR_TYPES: @@ -162,7 +162,7 @@ def setup_module(mod): link_data = [ val - for links, val in topo["routers"]["r3"]["links"].iteritems() + for links, val in topo["routers"]["r3"]["links"].items() if "r2" in links ] INTF_LIST_R3 = [val["interface"].split("/")[0] for val in link_data] diff --git a/tests/topotests/bgp-ecmp-topo2/test_ibgp_ecmp_topo2.py b/tests/topotests/bgp-ecmp-topo2/test_ibgp_ecmp_topo2.py index ae54019a0f..7357c33824 100755..100644 --- a/tests/topotests/bgp-ecmp-topo2/test_ibgp_ecmp_topo2.py +++ b/tests/topotests/bgp-ecmp-topo2/test_ibgp_ecmp_topo2.py @@ -146,7 +146,7 @@ def setup_module(mod): link_data = [ val - for links, val in topo["routers"]["r2"]["links"].iteritems() + for links, val in topo["routers"]["r2"]["links"].items() if "r3" in links ] for adt in ADDR_TYPES: @@ -163,7 +163,7 @@ def setup_module(mod): link_data = [ val - for links, val in topo["routers"]["r3"]["links"].iteritems() + for links, val in topo["routers"]["r3"]["links"].items() if "r2" in links ] INTF_LIST_R3 = [val["interface"].split("/")[0] for val in link_data] diff --git a/tests/topotests/bgp-evpn-mh/test_evpn_mh.py b/tests/topotests/bgp-evpn-mh/test_evpn_mh.py index fe28f79bd4..ee50a422a7 100755..100644 --- a/tests/topotests/bgp-evpn-mh/test_evpn_mh.py +++ b/tests/topotests/bgp-evpn-mh/test_evpn_mh.py @@ -384,7 +384,7 @@ def setup_module(module): # tgen.mininet_cli() # This is a sample of configuration loading. router_list = tgen.routers() - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) @@ -416,7 +416,7 @@ def check_local_es(esi, vtep_ips, dut_name, down_vteps): else: tor_ips_rack = tor_ips_rack_2 - for tor_name, tor_ip in tor_ips_rack.iteritems(): + for tor_name, tor_ip in tor_ips_rack.items(): if dut_name not in tor_name: peer_ips.append(tor_ip) @@ -442,7 +442,7 @@ def check_remote_es(esi, vtep_ips, dut_name, down_vteps): else: tor_ips_rack = tor_ips_rack_1 - for tor_name, tor_ip in tor_ips_rack.iteritems(): + for tor_name, tor_ip in tor_ips_rack.items(): remote_ips.append(tor_ip) # remove down VTEPs from the remote check list @@ -464,7 +464,7 @@ def check_es(dut): result = None - expected_es_set = set([v for k, v in host_es_map.iteritems()]) + expected_es_set = set([v for k, v in host_es_map.items()]) curr_es_set = [] # check is ES content is correct @@ -588,7 +588,7 @@ def check_mac(dut, vni, mac, m_type, esi, intf): out = dut.vtysh_cmd("show evpn mac vni %d mac %s json" % (vni, mac)) mac_js = json.loads(out) - for mac, info in mac_js.iteritems(): + for mac, info in mac_js.items(): tmp_esi = info.get("esi", "") tmp_m_type = info.get("type", "") tmp_intf = info.get("intf", "") if tmp_m_type == "local" else "" diff --git a/tests/topotests/bgp-evpn-vxlan_topo1/test_bgp_evpn_vxlan.py b/tests/topotests/bgp-evpn-vxlan_topo1/test_bgp_evpn_vxlan.py index 90144f5c66..2a14105383 100755..100644 --- a/tests/topotests/bgp-evpn-vxlan_topo1/test_bgp_evpn_vxlan.py +++ b/tests/topotests/bgp-evpn-vxlan_topo1/test_bgp_evpn_vxlan.py @@ -122,7 +122,7 @@ def setup_module(mod): router_list = tgen.routers() # For all registred routers, load the zebra configuration file - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) diff --git a/tests/topotests/bgp-vrf-route-leak-basic/test_bgp-vrf-route-leak-basic.py b/tests/topotests/bgp-vrf-route-leak-basic/test_bgp-vrf-route-leak-basic.py index 6178bfc63a..5aa1bdf329 100755..100644 --- a/tests/topotests/bgp-vrf-route-leak-basic/test_bgp-vrf-route-leak-basic.py +++ b/tests/topotests/bgp-vrf-route-leak-basic/test_bgp-vrf-route-leak-basic.py @@ -57,7 +57,7 @@ def setup_module(mod): tgen.start_topology() # For all registered routers, load the zebra configuration file - for rname, router in tgen.routers().iteritems(): + for rname, router in tgen.routers().items(): router.run("/bin/bash {}/setup_vrfs".format(CWD)) router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) diff --git a/tests/topotests/bgp_aggregate-address_origin/test_bgp_aggregate-address_origin.py b/tests/topotests/bgp_aggregate-address_origin/test_bgp_aggregate-address_origin.py index fa799f8256..86fd4b601f 100644 --- a/tests/topotests/bgp_aggregate-address_origin/test_bgp_aggregate-address_origin.py +++ b/tests/topotests/bgp_aggregate-address_origin/test_bgp_aggregate-address_origin.py @@ -66,7 +66,7 @@ def setup_module(mod): router_list = tgen.routers() - for i, (rname, router) in enumerate(router_list.iteritems(), 1): + for i, (rname, router) in enumerate(router_list.items(), 1): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) diff --git a/tests/topotests/bgp_aggregate-address_route-map/test_bgp_aggregate-address_route-map.py b/tests/topotests/bgp_aggregate-address_route-map/test_bgp_aggregate-address_route-map.py index 9c06c9d382..c7d9f13f3f 100644 --- a/tests/topotests/bgp_aggregate-address_route-map/test_bgp_aggregate-address_route-map.py +++ b/tests/topotests/bgp_aggregate-address_route-map/test_bgp_aggregate-address_route-map.py @@ -69,7 +69,7 @@ def setup_module(mod): router_list = tgen.routers() - for i, (rname, router) in enumerate(router_list.iteritems(), 1): + for i, (rname, router) in enumerate(router_list.items(), 1): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) diff --git a/tests/topotests/bgp_as_wide_bgp_identifier/test_bgp_as_wide_bgp_identifier.py b/tests/topotests/bgp_as_wide_bgp_identifier/test_bgp_as_wide_bgp_identifier.py index 459af486ff..02edb62ca0 100644 --- a/tests/topotests/bgp_as_wide_bgp_identifier/test_bgp_as_wide_bgp_identifier.py +++ b/tests/topotests/bgp_as_wide_bgp_identifier/test_bgp_as_wide_bgp_identifier.py @@ -65,7 +65,7 @@ def setup_module(mod): router_list = tgen.routers() - for i, (rname, router) in enumerate(router_list.iteritems(), 1): + for i, (rname, router) in enumerate(router_list.items(), 1): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) diff --git a/tests/topotests/bgp_comm-list_delete/test_bgp_comm-list_delete.py b/tests/topotests/bgp_comm-list_delete/test_bgp_comm-list_delete.py index 314ad12a6d..fe7052b80f 100644 --- a/tests/topotests/bgp_comm-list_delete/test_bgp_comm-list_delete.py +++ b/tests/topotests/bgp_comm-list_delete/test_bgp_comm-list_delete.py @@ -64,7 +64,7 @@ def setup_module(mod): router_list = tgen.routers() - for i, (rname, router) in enumerate(router_list.iteritems(), 1): + for i, (rname, router) in enumerate(router_list.items(), 1): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) diff --git a/tests/topotests/bgp_default-route_route-map/test_bgp_default-originate_route-map.py b/tests/topotests/bgp_default-route_route-map/test_bgp_default-originate_route-map.py index ba9a6dffb5..a72c3a4cbf 100644 --- a/tests/topotests/bgp_default-route_route-map/test_bgp_default-originate_route-map.py +++ b/tests/topotests/bgp_default-route_route-map/test_bgp_default-originate_route-map.py @@ -69,7 +69,7 @@ def setup_module(mod): router_list = tgen.routers() - for i, (rname, router) in enumerate(router_list.iteritems(), 1): + for i, (rname, router) in enumerate(router_list.items(), 1): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) diff --git a/tests/topotests/bgp_distance_change/test_bgp_distance_change.py b/tests/topotests/bgp_distance_change/test_bgp_distance_change.py index 6d09cd2e8c..f338d52e70 100644 --- a/tests/topotests/bgp_distance_change/test_bgp_distance_change.py +++ b/tests/topotests/bgp_distance_change/test_bgp_distance_change.py @@ -68,7 +68,7 @@ def setup_module(mod): router_list = tgen.routers() - for i, (rname, router) in enumerate(router_list.iteritems(), 1): + for i, (rname, router) in enumerate(router_list.items(), 1): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) diff --git a/tests/topotests/bgp_ebgp_requires_policy/test_bgp_ebgp_requires_policy.py b/tests/topotests/bgp_ebgp_requires_policy/test_bgp_ebgp_requires_policy.py index 5c2af2b30b..2520763bda 100644 --- a/tests/topotests/bgp_ebgp_requires_policy/test_bgp_ebgp_requires_policy.py +++ b/tests/topotests/bgp_ebgp_requires_policy/test_bgp_ebgp_requires_policy.py @@ -82,7 +82,7 @@ def setup_module(mod): router_list = tgen.routers() - for i, (rname, router) in enumerate(router_list.iteritems(), 1): + for i, (rname, router) in enumerate(router_list.items(), 1): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) diff --git a/tests/topotests/bgp_features/test_bgp_features.py b/tests/topotests/bgp_features/test_bgp_features.py index a27aaf9ec7..91613a0193 100755..100644 --- a/tests/topotests/bgp_features/test_bgp_features.py +++ b/tests/topotests/bgp_features/test_bgp_features.py @@ -102,7 +102,7 @@ def setup_module(module): # Starting Routers router_list = tgen.routers() - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) diff --git a/tests/topotests/bgp_flowspec/test_bgp_flowspec_topo.py b/tests/topotests/bgp_flowspec/test_bgp_flowspec_topo.py index a7e2c31cde..7e6bfc8b2b 100755..100644 --- a/tests/topotests/bgp_flowspec/test_bgp_flowspec_topo.py +++ b/tests/topotests/bgp_flowspec/test_bgp_flowspec_topo.py @@ -124,7 +124,7 @@ def setup_module(module): router.start() peer_list = tgen.exabgp_peers() - for pname, peer in peer_list.iteritems(): + for pname, peer in peer_list.items(): peer_dir = os.path.join(CWD, pname) env_file = os.path.join(CWD, "exabgp.env") peer.start(peer_dir, env_file) diff --git a/tests/topotests/bgp_ipv6_rtadv/test_bgp_ipv6_rtadv.py b/tests/topotests/bgp_ipv6_rtadv/test_bgp_ipv6_rtadv.py index 10b2f3595f..0acf8d2dbc 100644 --- a/tests/topotests/bgp_ipv6_rtadv/test_bgp_ipv6_rtadv.py +++ b/tests/topotests/bgp_ipv6_rtadv/test_bgp_ipv6_rtadv.py @@ -69,7 +69,7 @@ def setup_module(mod): router_list = tgen.routers() - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) diff --git a/tests/topotests/bgp_link_bw_ip/test_bgp_linkbw_ip.py b/tests/topotests/bgp_link_bw_ip/test_bgp_linkbw_ip.py index 86eb2969ce..dff69e3a27 100755..100644 --- a/tests/topotests/bgp_link_bw_ip/test_bgp_linkbw_ip.py +++ b/tests/topotests/bgp_link_bw_ip/test_bgp_linkbw_ip.py @@ -119,7 +119,7 @@ def setup_module(mod): tgen.start_topology() router_list = tgen.routers() - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, '{}/zebra.conf'.format(rname)) diff --git a/tests/topotests/bgp_local_as_private_remove/test_bgp_local_as_private_remove.py b/tests/topotests/bgp_local_as_private_remove/test_bgp_local_as_private_remove.py index 56bb14411a..32e7a4df61 100644 --- a/tests/topotests/bgp_local_as_private_remove/test_bgp_local_as_private_remove.py +++ b/tests/topotests/bgp_local_as_private_remove/test_bgp_local_as_private_remove.py @@ -66,7 +66,7 @@ def setup_module(mod): router_list = tgen.routers() - for i, (rname, router) in enumerate(router_list.iteritems(), 1): + for i, (rname, router) in enumerate(router_list.items(), 1): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) diff --git a/tests/topotests/bgp_maximum_prefix_invalid_update/test_bgp_maximum_prefix_invalid_update.py b/tests/topotests/bgp_maximum_prefix_invalid_update/test_bgp_maximum_prefix_invalid_update.py index 5e7c6d4b63..8494653dfe 100644 --- a/tests/topotests/bgp_maximum_prefix_invalid_update/test_bgp_maximum_prefix_invalid_update.py +++ b/tests/topotests/bgp_maximum_prefix_invalid_update/test_bgp_maximum_prefix_invalid_update.py @@ -66,7 +66,7 @@ def setup_module(mod): router_list = tgen.routers() - for i, (rname, router) in enumerate(router_list.iteritems(), 1): + for i, (rname, router) in enumerate(router_list.items(), 1): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) diff --git a/tests/topotests/bgp_maximum_prefix_out/test_bgp_maximum_prefix_out.py b/tests/topotests/bgp_maximum_prefix_out/test_bgp_maximum_prefix_out.py index 708684f696..b99664e700 100644 --- a/tests/topotests/bgp_maximum_prefix_out/test_bgp_maximum_prefix_out.py +++ b/tests/topotests/bgp_maximum_prefix_out/test_bgp_maximum_prefix_out.py @@ -62,7 +62,7 @@ def setup_module(mod): router_list = tgen.routers() - for i, (rname, router) in enumerate(router_list.iteritems(), 1): + for i, (rname, router) in enumerate(router_list.items(), 1): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) diff --git a/tests/topotests/bgp_prefix_sid/test_bgp_prefix_sid.py b/tests/topotests/bgp_prefix_sid/test_bgp_prefix_sid.py index 3a6aefe7ee..6d7131e1e5 100755..100644 --- a/tests/topotests/bgp_prefix_sid/test_bgp_prefix_sid.py +++ b/tests/topotests/bgp_prefix_sid/test_bgp_prefix_sid.py @@ -75,7 +75,7 @@ def setup_module(module): logger.info("starting exaBGP on peer1") peer_list = tgen.exabgp_peers() - for pname, peer in peer_list.iteritems(): + for pname, peer in peer_list.items(): peer_dir = os.path.join(CWD, pname) env_file = os.path.join(CWD, "exabgp.env") logger.info("Running ExaBGP peer") diff --git a/tests/topotests/bgp_reject_as_sets/test_bgp_reject_as_sets.py b/tests/topotests/bgp_reject_as_sets/test_bgp_reject_as_sets.py index b49a57b308..d514dccd4a 100644 --- a/tests/topotests/bgp_reject_as_sets/test_bgp_reject_as_sets.py +++ b/tests/topotests/bgp_reject_as_sets/test_bgp_reject_as_sets.py @@ -73,7 +73,7 @@ def setup_module(mod): router_list = tgen.routers() - for i, (rname, router) in enumerate(router_list.iteritems(), 1): + for i, (rname, router) in enumerate(router_list.items(), 1): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) diff --git a/tests/topotests/bgp_route_aggregation/bgp_aggregation.json b/tests/topotests/bgp_route_aggregation/bgp_aggregation.json new file mode 100644 index 0000000000..5520f67d0d --- /dev/null +++ b/tests/topotests/bgp_route_aggregation/bgp_aggregation.json @@ -0,0 +1,249 @@ +{ + "address_types": [ + "ipv4", + "ipv6" + ], + "ipv4base": "192.168.0.0", + "ipv4mask": 24, + "ipv6base": "fd00::", + "ipv6mask": 64, + "link_ip_start": { + "ipv4": "192.168.0.0", + "v4mask": 24, + "ipv6": "fd00::", + "v6mask": 64 + }, + "lo_prefix": { + "ipv4": "1.0.", + "v4mask": 32, + "ipv6": "2001:db8:f::", + "v6mask": 128 + }, + "routers": { + "r1": { + "links": { + "lo": { + "ipv4": "auto", + "ipv6": "auto", + "type": "loopback" + }, + "r2": { + "ipv4": "auto", + "ipv6": "auto" + }, + "r3": { + "ipv4": "auto", + "ipv6": "auto" + } + }, + "bgp": { + "local_as": "100", + "address_family": { + "ipv4": { + "unicast": { + "neighbor": { + "r2": { + "dest_link": { + "r1": {} + } + }, + "r3": { + "dest_link": { + "r1": { + } + } + } + } + } + }, + "ipv6": { + "unicast": { + "neighbor": { + "r2": { + "dest_link": { + "r1": { + } + } + }, + "r3": { + "dest_link": { + "r1": { + } + } + } + } + } + } + } + } + }, + "r2": { + "links": { + "lo": { + "ipv4": "auto", + "ipv6": "auto", + "type": "loopback" + }, + "r1": { + "ipv4": "auto", + "ipv6": "auto" + }, + "r4": { + "ipv4": "auto", + "ipv6": "auto" + } + }, + "bgp": { + "local_as": "100", + "address_family": { + "ipv4": { + "unicast": { + "neighbor": { + "r1": { + "dest_link": { + "r2": {} + } + }, + "r4": { + "dest_link": { + "r2": {} + } + } + } + } + }, + "ipv6": { + "unicast": { + "neighbor": { + "r1": { + "dest_link": { + "r2": { + } + } + }, + "r4": { + "dest_link": { + "r2": { + } + } + } + } + } + } + } + } + }, + "r3": { + "links": { + "lo": { + "ipv4": "auto", + "ipv6": "auto", + "type": "loopback" + }, + "r1": { + "ipv4": "auto", + "ipv6": "auto" + }, + "r4": { + "ipv4": "auto", + "ipv6": "auto" + } + }, + "bgp": { + "local_as": "300", + "address_family": { + "ipv4": { + "unicast": { + "neighbor": { + "r1": { + "dest_link": { + "r3": {} + } + }, + "r4": { + "dest_link": { + "r3": {} + } + } + } + } + }, + "ipv6": { + "unicast": { + "neighbor": { + "r1": { + "dest_link": { + "r3": { + } + } + }, + "r4": { + "dest_link": { + "r3": { + } + } + } + } + } + } + } + } + }, + "r4": { + "links": { + "lo": { + "ipv4": "auto", + "ipv6": "auto", + "type": "loopback" + }, + "r2": { + "ipv4": "auto", + "ipv6": "auto" + }, + "r3": { + "ipv4": "auto", + "ipv6": "auto" + } + }, + "bgp": { + "local_as": "400", + "address_family": { + "ipv4": { + "unicast": { + "neighbor": { + "r2": { + "dest_link": { + "r4": {} + } + }, + "r3": { + "dest_link": { + "r4": {} + } + } + } + } + }, + "ipv6": { + "unicast": { + "neighbor": { + "r2": { + "dest_link": { + "r4": { + } + } + }, + "r3": { + "dest_link": { + "r4": { + } + } + } + } + } + } + } + } + } + } +} diff --git a/tests/topotests/bgp_route_aggregation/test_bgp_aggregation.py b/tests/topotests/bgp_route_aggregation/test_bgp_aggregation.py new file mode 100755 index 0000000000..0fabd90341 --- /dev/null +++ b/tests/topotests/bgp_route_aggregation/test_bgp_aggregation.py @@ -0,0 +1,1167 @@ +#!/usr/bin/python +# +# Copyright (c) 2020 by VMware, Inc. ("VMware") +# Used Copyright (c) 2018 by Network Device Education Foundation, +# Inc. ("NetDEF") in this file. +# +# Permission to use, copy, modify, and/or distribute this software +# for any purpose with or without fee is hereby granted, provided +# that the above copyright notice and this permission notice appear +# in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND VMWARE DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL VMWARE BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY +# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS +# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE +# OF THIS SOFTWARE. +# + +""" +Following tests are covered to test bgp aggregation functionality: + +1. Verify route summarisation with summary-only for redistributed as well as + locally generated routes. +2. Verify route summarisation with as-set for redistributed routes. + +""" + +import os +import sys +import time +import json +import pytest +from time import sleep +from copy import deepcopy + +# Save the Current Working Directory to find configuration files. +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, "../")) + +# pylint: disable=C0413 +# Import topogen and topotest helpers +from lib import topotest +from mininet.topo import Topo +from lib.topogen import Topogen, get_topogen + +# Import topoJson from lib, to create topology and initial configuration +from lib.common_config import ( + start_topology, + write_test_header, + apply_raw_config, + write_test_footer, + reset_config_on_routers, + verify_rib, + create_static_routes, + check_address_types, + step, + create_route_maps, + create_prefix_lists, +) +from lib.topolog import logger +from lib.bgp import ( + verify_bgp_convergence, + create_router_bgp, + verify_bgp_rib, + verify_bgp_community, + verify_bgp_timers_and_functionality, +) +from lib.topojson import build_topo_from_json, build_config_from_json + +# Reading the data from JSON File for topology and configuration creation +jsonFile = "{}/bgp_aggregation.json".format(CWD) +try: + with open(jsonFile, "r") as topoJson: + topo = json.load(topoJson) +except IOError: + logger.info("Could not read file:", jsonFile) + +# Global variables +BGP_CONVERGENCE = False +ADDR_TYPES = check_address_types() + +NETWORK_1_1 = {"ipv4": "10.1.1.0/24", "ipv6": "10:1::1:0/120"} +NETWORK_1_2 = {"ipv4": "10.1.2.0/24", "ipv6": "10:1::2:0/120"} +NETWORK_1_3 = {"ipv4": "10.1.3.0/24", "ipv6": "10:1::3:0/120"} +NETWORK_1_4 = {"ipv4": "10.1.4.0/24", "ipv6": "10:1::4:0/120"} +NETWORK_1_5 = {"ipv4": "10.1.5.0/24", "ipv6": "10:1::5:0/120"} +NETWORK_2_1 = {"ipv4": "10.1.1.100/32", "ipv6": "10:1::1:0/124"} +NETWORK_2_2 = {"ipv4": "10.1.5.0/24", "ipv6": "10:1::5:0/120"} +NETWORK_2_3 = {"ipv4": "10.1.6.0/24", "ipv6": "10:1::6:0/120"} +NETWORK_2_4 = {"ipv4": "10.1.7.0/24", "ipv6": "10:1::7:0/120"} +NETWORK_3_1 = {"ipv4": "10.1.8.0/24", "ipv6": "10:1::8:0/120"} +NETWORK_4_1 = {"ipv4": "10.2.1.0/24", "ipv6": "10:2::1:0/120"} +NEXT_HOP = {"ipv4": "Null0", "ipv6": "Null0"} +AGGREGATE_NW = {"ipv4": "10.1.0.0/20", "ipv6": "10:1::/96"} + +COMMUNITY = [ + "0:1 0:10 0:100", + "0:2 0:20 0:200", + "0:3 0:30 0:300", + "0:4 0:40 0:400", + "0:5 0:50 0:500", + "0:1 0:2 0:3 0:4 0:5 0:10 0:20 0:30 0:40 0:50 0:100 0:200 0:300 0:400 0:500", + "0:3 0:4 0:5 0:30 0:40 0:50 0:300 0:400 0:500", + "0:6 0:60 0:600", + "0:7 0:70 0:700", + "0:3 0:4 0:5 0:6 0:30 0:40 0:50 0:60 0:300 0:400 0:500 0:600", +] + + +class CreateTopo(Topo): + """ + Test BasicTopo - topology 1 + + * `Topo`: Topology object + """ + + def build(self, *_args, **_opts): + """Build function""" + tgen = get_topogen(self) + + # Building topology from json file + build_topo_from_json(tgen, topo) + + +def setup_module(mod): + """ + Sets up the pytest environment + + * `mod`: module name + """ + + testsuite_run_time = time.asctime(time.localtime(time.time())) + logger.info("Testsuite start time: {}".format(testsuite_run_time)) + logger.info("=" * 40) + + logger.info("Running setup_module to create topology") + + # This function initiates the topology build with Topogen... + tgen = Topogen(CreateTopo, mod.__name__) + # ... and here it calls Mininet initialization functions. + + # Starting topology, create tmp files which are loaded to routers + # to start deamons and then start routers + start_topology(tgen) + + # Creating configuration from JSON + build_config_from_json(tgen, topo) + + # Don't run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + # Api call verify whether BGP is converged + ADDR_TYPES = check_address_types() + + for addr_type in ADDR_TYPES: + BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo) + assert BGP_CONVERGENCE is True, "setup_module :Failed \n Error:" " {}".format( + BGP_CONVERGENCE + ) + + logger.info("Running setup_module() done") + + +def teardown_module(mod): + """ + Teardown the pytest environment + + * `mod`: module name + """ + + logger.info("Running teardown_module to delete topology") + + tgen = get_topogen() + + # Stop toplogy and Remove tmp files + tgen.stop_topology() + + logger.info( + "Testsuite end time: {}".format(time.asctime(time.localtime(time.time()))) + ) + logger.info("=" * 40) + + +##################################################### +# +# Tests starting +# +##################################################### + + +def test_route_summarisation_with_summary_only_p1(request): + """ + Verify route summarisation with summary-only for redistributed as well as + locally generated routes. + """ + + tgen = get_topogen() + tc_name = request.node.name + reset_config_on_routers(tgen) + write_test_header(tc_name) + + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + step("Configure static routes on router R1 and redistribute in " "BGP process.") + + for addr_type in ADDR_TYPES: + input_static = { + "r1": { + "static_routes": [ + { + "network": [ + NETWORK_1_1[addr_type], + NETWORK_1_2[addr_type], + NETWORK_1_3[addr_type], + ], + "next_hop": NEXT_HOP[addr_type], + } + ] + } + } + input_redistribute = { + "r1": { + "bgp": { + "address_family": { + addr_type: { + "unicast": {"redistribute": [{"redist_type": "static"}]} + } + } + } + } + } + + step("Configuring {} static routes on router R1 ".format(addr_type)) + + result = create_static_routes(tgen, input_static) + assert result is True, "Testcase : Failed \n Error: {}".format(tc_name, result) + + step( + "Configuring redistribute static for {} address-family on router R1 ".format( + addr_type + ) + ) + + result = create_router_bgp(tgen, topo, input_redistribute) + assert result is True, "Testcase {} :Failed \n Error: {}".format( + tc_name, result + ) + + step("Verify that Static routes are redistributed in BGP process") + + for addr_type in ADDR_TYPES: + input_static = { + "r1": { + "static_routes": [ + { + "network": [ + NETWORK_1_1[addr_type], + NETWORK_1_2[addr_type], + NETWORK_1_3[addr_type], + ] + } + ] + } + } + + result = verify_rib(tgen, addr_type, "r3", input_static) + assert result is True, "Testcase : Failed \n Error: {}".format(tc_name, result) + + step("Advertise some prefixes using network command") + step( + "Additionally advertise 10.1.4.0/24 & 10.1.5.0/24 and " + "10:1::4:0/120 & 10:1::5:0/120 from R4 to R1." + ) + + for addr_type in ADDR_TYPES: + input_advertise = { + "r1": { + "bgp": { + "address_family": { + addr_type: { + "unicast": { + "advertise_networks": [ + { + "network": [ + NETWORK_2_1[addr_type], + NETWORK_2_2[addr_type], + NETWORK_2_3[addr_type], + NETWORK_2_4[addr_type], + ] + } + ] + } + } + } + } + }, + "r4": { + "bgp": { + "address_family": { + addr_type: { + "unicast": { + "advertise_networks": [ + { + "network": [ + NETWORK_1_4[addr_type], + NETWORK_1_5[addr_type], + ] + } + ] + } + } + } + } + }, + } + + result = create_router_bgp(tgen, topo, input_advertise) + assert result is True, "Testcase {} :Failed \n Error: {}".format( + tc_name, result + ) + + step( + "Verify that advertised prefixes using network command are being " + "advertised in BGP process" + ) + + for addr_type in ADDR_TYPES: + input_advertise = { + "r1": { + "bgp": { + "address_family": { + addr_type: { + "unicast": { + "advertise_networks": [ + { + "network": [ + NETWORK_2_1[addr_type], + NETWORK_2_2[addr_type], + NETWORK_2_3[addr_type], + NETWORK_2_4[addr_type], + ] + } + ] + } + } + } + } + } + } + + result = verify_rib(tgen, addr_type, "r3", input_advertise) + assert result is True, "Testcase : Failed \n Error: {}".format(tc_name, result) + + step("Configure aggregate-address to summarise all the advertised routes.") + + for addr_type in ADDR_TYPES: + route_aggregate = { + "r1": { + "bgp": { + "address_family": { + addr_type: { + "unicast": { + "aggregate_address": [ + { + "network": AGGREGATE_NW[addr_type], + "summary": True, + } + ] + } + } + } + } + } + } + + result = create_router_bgp(tgen, topo, route_aggregate) + assert result is True, "Testcase {} :Failed \n Error: {}".format( + tc_name, result + ) + + step( + "Verify that we see 1 summarised route and remaining suppressed " + "routes on advertising router R1 and only 1 summarised route on " + "receiving router R3 for both AFIs." + ) + + for addr_type in ADDR_TYPES: + input_static_agg = { + "r1": {"static_routes": [{"network": AGGREGATE_NW[addr_type]}]} + } + + input_static = { + "r1": { + "static_routes": [ + { + "network": [ + NETWORK_1_1[addr_type], + NETWORK_1_2[addr_type], + NETWORK_1_3[addr_type], + ] + } + ] + } + } + + result = verify_rib(tgen, addr_type, "r3", input_static_agg, protocol="bgp") + assert result is True, "Testcase : Failed \n Error: {}".format(tc_name, result) + + result = verify_rib( + tgen, addr_type, "r3", input_static, protocol="bgp", expected=False + ) + assert result is not True, ( + "Testcase : Failed \n " + "Routes are still present \n Error: {}".format(tc_name, result) + ) + + result = verify_rib(tgen, addr_type, "r1", input_static_agg, protocol="bgp") + assert result is True, "Testcase : Failed \n Error: {}".format(tc_name, result) + + result = verify_rib(tgen, addr_type, "r1", input_static) + assert result is True, "Testcase : Failed \n Error: {}".format(tc_name, result) + + for action, value in zip(["removed", "add"], [True, False]): + + step( + "{} static routes as below: " + "(no) ip route 10.1.1.0/24 and (no) ip route 10.1.2.0/24" + "(no) ipv6 route 10:1::1:0/120 and (no) ip route 10:1::2:0/120".format( + action + ) + ) + + for addr_type in ADDR_TYPES: + input_static = { + "r1": { + "static_routes": [ + { + "network": [NETWORK_1_1[addr_type], NETWORK_1_2[addr_type]], + "next_hop": NEXT_HOP[addr_type], + "delete": value, + } + ] + } + } + + result = create_static_routes(tgen, input_static) + assert result is True, "Testcase : Failed \n Error: {}".format( + tc_name, result + ) + + step( + "Verify that there is no impact on R3, as summarised route remains " + "intact. However suppressed routes on R1 disappear and re-appear " + "based on {} static routes.".format(action) + ) + + for addr_type in ADDR_TYPES: + input_static_1 = { + "r1": { + "static_routes": [ + {"network": [NETWORK_1_1[addr_type], NETWORK_1_2[addr_type]]} + ] + } + } + + input_static_2 = { + "r1": {"static_routes": [{"network": AGGREGATE_NW[addr_type]}]} + } + + if value: + result = verify_rib( + tgen, addr_type, "r1", input_static_1, expected=False + ) + assert result is not True, ( + "Testcase : Failed \n " + "Routes are still present \n Error: {}".format(tc_name, result) + ) + else: + result = verify_rib(tgen, addr_type, "r1", input_static_1) + assert result is True, "Testcase : Failed \n Error: {}".format( + tc_name, result + ) + + result = verify_rib(tgen, addr_type, "r3", input_static_2, protocol="bgp") + assert result is True, "Testcase : Failed \n Error: {}".format( + tc_name, result + ) + + step( + "{} prefixes using network command as below:" + "(no) network 10.1.6.1/24 and (no) network 10.1.7.1/24" + "(no) network 10:1::6:0/120 and (no) network 10:1::7:0/120".format(action) + ) + + for addr_type in ADDR_TYPES: + input_advertise = { + "r1": { + "bgp": { + "address_family": { + addr_type: { + "unicast": { + "advertise_networks": [ + { + "network": [ + NETWORK_2_3[addr_type], + NETWORK_2_4[addr_type], + ], + "delete": value, + } + ] + } + } + } + } + } + } + + result = create_router_bgp(tgen, topo, input_advertise) + assert result is True, "Testcase {} :Failed \n Error: {}".format( + tc_name, result + ) + + step( + "Verify that there is no impact on R3, as summarised route remains " + "intact. However suppressed routes on R1 disappear and re-appear " + "based on {} of network command.".format(action) + ) + + for addr_type in ADDR_TYPES: + input_advertise_1 = { + "r1": { + "bgp": { + "address_family": { + addr_type: { + "unicast": { + "advertise_networks": [ + { + "network": [ + NETWORK_2_3[addr_type], + NETWORK_2_4[addr_type], + ] + } + ] + } + } + } + } + } + } + + input_advertise_2 = { + "r1": { + "bgp": { + "address_family": { + addr_type: { + "unicast": { + "advertise_networks": [ + {"network": AGGREGATE_NW[addr_type]} + ] + } + } + } + } + } + } + + if value: + result = verify_bgp_rib( + tgen, addr_type, "r1", input_advertise_1, expected=False + ) + assert result is not True, ( + "Testcase : Failed \n " + "Routes are still present \n Error: {}".format(tc_name, result) + ) + else: + result = verify_bgp_rib(tgen, addr_type, "r1", input_advertise_1) + assert result is True, "Testcase : Failed \n Error: {}".format( + tc_name, result + ) + + result = verify_rib(tgen, addr_type, "r3", input_advertise_2) + assert result is True, "Testcase : Failed \n Error: {}".format( + tc_name, result + ) + + step( + "Add a new network each one from out of aggregation range and " + "other within aggregation range. " + ) + + for addr_type in ADDR_TYPES: + input_static = { + "r1": { + "static_routes": [ + {"network": NETWORK_3_1[addr_type], "next_hop": NEXT_HOP[addr_type]} + ] + } + } + + result = create_static_routes(tgen, input_static) + assert result is True, "Testcase : Failed \n Error: {}".format(tc_name, result) + + for addr_type in ADDR_TYPES: + input_advertise = { + "r1": { + "bgp": { + "address_family": { + addr_type: { + "unicast": { + "advertise_networks": [ + {"network": NETWORK_4_1[addr_type],} + ] + } + } + } + } + } + } + + result = create_router_bgp(tgen, topo, input_advertise) + assert result is True, "Testcase {} :Failed \n Error: {}".format( + tc_name, result + ) + + step( + "Verify that when a network within aggregation range is added, " + "there is no impact on receiving router. However if a network " + "outside aggregation range is added/removed, R3 receives and " + "withdraws it accordingly." + ) + + for addr_type in ADDR_TYPES: + input_static = {"r1": {"static_routes": [{"network": AGGREGATE_NW[addr_type]}]}} + + result = verify_rib(tgen, addr_type, "r3", input_static, protocol="bgp") + assert result is True, "Testcase : Failed \n Error: {}".format(tc_name, result) + + input_advertise_2 = { + "r1": { + "bgp": { + "address_family": { + addr_type: { + "unicast": { + "advertise_networks": [ + { + "network": [ + NETWORK_4_1[addr_type], + AGGREGATE_NW[addr_type], + ] + } + ] + } + } + } + } + } + } + + result = verify_rib(tgen, addr_type, "r3", input_advertise_2, protocol="bgp") + assert result is True, "Testcase : Failed \n Error: {}".format(tc_name, result) + + for action, value in zip(["Delete", "Re-add"], [True, False]): + step("{} aggregation command from R1.".format(action)) + + for addr_type in ADDR_TYPES: + route_aggregate = { + "r1": { + "bgp": { + "address_family": { + addr_type: { + "unicast": { + "aggregate_address": [ + { + "network": AGGREGATE_NW[addr_type], + "summary": True, + "delete": value, + } + ] + } + } + } + } + } + } + + result = create_router_bgp(tgen, topo, route_aggregate) + assert result is True, "Testcase {} :Failed \n Error: {}".format( + tc_name, result + ) + + step( + "Verify on both routers that summarised route is withdrawn from R1 " + "and R3 when aggregate-address command is removed and appears again " + "when aggregate-address command is re-added. Check for both AFIs." + ) + + for addr_type in ADDR_TYPES: + input_static_agg = { + "r1": {"static_routes": [{"network": AGGREGATE_NW[addr_type]}]} + } + + if value: + result = verify_rib( + tgen, addr_type, "r1", input_static_agg, expected=False + ) + assert result is not True, ( + "Testcase : Failed \n " + "Aggregated route is still present \n Error: {}".format( + tc_name, result + ) + ) + + result = verify_rib( + tgen, addr_type, "r3", input_static_agg, expected=False + ) + assert result is not True, ( + "Testcase : Failed \n " + "Aggregated route is still present \n Error: {}".format( + tc_name, result + ) + ) + else: + result = verify_rib(tgen, addr_type, "r1", input_static_agg) + assert result is True, "Testcase : Failed \n Error: {}".format( + tc_name, result + ) + + result = verify_rib(tgen, addr_type, "r3", input_static_agg) + assert result is True, "Testcase : Failed \n Error: {}".format( + tc_name, result + ) + + write_test_footer(tc_name) + + +def test_route_summarisation_with_as_set_p1(request): + """ + Verify route summarisation with as-set for redistributed routes. + """ + + tgen = get_topogen() + tc_name = request.node.name + reset_config_on_routers(tgen) + write_test_header(tc_name) + + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + step("Configure static routes on router R1 and redistribute in " "BGP process.") + + for addr_type in ADDR_TYPES: + input_static = { + "r1": { + "static_routes": [ + { + "network": [ + NETWORK_1_1[addr_type], + NETWORK_1_2[addr_type], + NETWORK_1_3[addr_type], + NETWORK_1_4[addr_type], + NETWORK_1_5[addr_type], + ], + "next_hop": NEXT_HOP[addr_type], + } + ] + } + } + input_redistribute = { + "r1": { + "bgp": { + "address_family": { + addr_type: { + "unicast": {"redistribute": [{"redist_type": "static"}]} + } + } + } + } + } + + step("Configuring {} static routes on router R1 ".format(addr_type)) + + result = create_static_routes(tgen, input_static) + assert result is True, "Testcase : Failed \n Error: {}".format(tc_name, result) + + step( + "Configuring redistribute static for {} address-family on router R1 ".format( + addr_type + ) + ) + + result = create_router_bgp(tgen, topo, input_redistribute) + assert result is True, "Testcase {} :Failed \n Error: {}".format( + tc_name, result + ) + + step("Verify that Static routes are redistributed in BGP process") + + for addr_type in ADDR_TYPES: + input_static = { + "r1": { + "static_routes": [ + { + "network": [ + NETWORK_1_1[addr_type], + NETWORK_1_2[addr_type], + NETWORK_1_3[addr_type], + NETWORK_1_4[addr_type], + NETWORK_1_5[addr_type], + ] + } + ] + } + } + + result = verify_rib(tgen, addr_type, "r3", input_static) + assert result is True, "Testcase : Failed \n Error: {}".format(tc_name, result) + + step( + "Configure a route-map to attach a unique community attribute value " + "to each of these prefixes, while re-distributing static." + ) + + for addr_type in ADDR_TYPES: + for pfx, seq_id, network, in zip( + [1, 2, 3, 4, 5], + [10, 20, 30, 40, 50], + [NETWORK_1_1, NETWORK_1_2, NETWORK_1_3, NETWORK_1_4, NETWORK_1_5], + ): + prefix_list = { + "r1": { + "prefix_lists": { + addr_type: { + "pf_list_{}_{}".format(addr_type, pfx): [ + { + "seqid": seq_id, + "network": network[addr_type], + "action": "permit", + } + ] + } + } + } + } + result = create_prefix_lists(tgen, prefix_list) + assert result is True, "Test case {} : Failed \n Error: {}".format( + tc_name, result + ) + + step("Create route-map for applying prefix-list on r1") + + for addr_type in ADDR_TYPES: + for pfx, comm_id in zip([1, 2, 3, 4, 5], [0, 1, 2, 3, 4]): + route_map = { + "r1": { + "route_maps": { + "rmap_{}".format(addr_type): [ + { + "action": "permit", + "match": { + addr_type: { + "prefix_lists": "pf_list_{}_{}".format( + addr_type, pfx + ) + } + }, + "set": {"community": {"num": COMMUNITY[comm_id]}}, + } + ] + } + } + } + + result = create_route_maps(tgen, route_map) + assert result is True, "Testcase {} :Failed \n Error: {}".format( + tc_name, result + ) + + step("Re-configure redistribute static with route-map") + + for addr_type in ADDR_TYPES: + input_redistribute = { + "r1": { + "bgp": { + "address_family": { + addr_type: { + "unicast": { + "redistribute": [ + { + "redist_type": "static", + "attribute": { + "route-map": "rmap_{}".format(addr_type) + }, + } + ] + } + } + } + } + } + } + + result = create_router_bgp(tgen, topo, input_redistribute) + assert result is True, "Testcase {} :Failed \n Error: {}".format( + tc_name, result + ) + + step("Configure aggregate-address to summarise all the advertised routes.") + + for addr_type in ADDR_TYPES: + route_aggregate = { + "r1": { + "bgp": { + "address_family": { + addr_type: { + "unicast": { + "aggregate_address": [ + {"network": AGGREGATE_NW[addr_type], "as_set": True} + ] + } + } + } + } + } + } + + result = create_router_bgp(tgen, topo, route_aggregate) + assert result is True, "Testcase {} :Failed \n Error: {}".format( + tc_name, result + ) + + step( + "Verify that we see summarised route on router R3 with all the " + "community attribute values combined with that aggregate route." + ) + + for addr_type in ADDR_TYPES: + input_dict = {"community": COMMUNITY[5]} + result = verify_bgp_community( + tgen, addr_type, "r3", [AGGREGATE_NW[addr_type]], input_dict + ) + assert result is True, "Test case {} : Failed \n Error: {}".format( + tc_name, result + ) + + step( + "Remove static routes as below: " + "(no) ip route 10.1.1.0/24 blackhole " + "(no) ip route 10.1.2.0/24 blackhole " + "(no) ipv6 route 10:1::1:0/120 blackhole " + "(no) ipv6 route 10:1::2:0/120 blackhole " + ) + + for addr_type in ADDR_TYPES: + input_static = { + "r1": { + "static_routes": [ + { + "network": [NETWORK_1_1[addr_type], NETWORK_1_2[addr_type]], + "next_hop": NEXT_HOP[addr_type], + "delete": True, + } + ] + } + } + + result = create_static_routes(tgen, input_static) + assert result is True, "Testcase : Failed \n Error: {}".format(tc_name, result) + + step( + "Verify on R3 that whenever we remove the static routes, we still" + " see aggregated route however the corresponding community attribute" + "values are withdrawn." + ) + + for addr_type in ADDR_TYPES: + input_dict = {"community": COMMUNITY[6]} + result = verify_bgp_community( + tgen, addr_type, "r3", [AGGREGATE_NW[addr_type]], input_dict + ) + assert result is True, "Test case {} : Failed \n Error: {}".format( + tc_name, result + ) + + step( + "Add/remove a new network with community value, each one from out of " + "aggregation range and other within aggregation range. " + ) + + step( + "Add a new network each one from out of aggregation range and " + "other within aggregation range. " + ) + + for addr_type in ADDR_TYPES: + input_static = { + "r1": { + "static_routes": [ + { + "network": [NETWORK_3_1[addr_type], NETWORK_4_1[addr_type]], + "next_hop": NEXT_HOP[addr_type], + } + ] + } + } + + result = create_static_routes(tgen, input_static) + assert result is True, "Testcase : Failed \n Error: {}".format(tc_name, result) + + for addr_type in ADDR_TYPES: + for pfx, seq_id, network, in zip([6, 7], [60, 70], [NETWORK_3_1, NETWORK_4_1]): + prefix_list = { + "r1": { + "prefix_lists": { + addr_type: { + "pf_list_{}_{}".format(addr_type, pfx): [ + { + "seqid": seq_id, + "network": network[addr_type], + "action": "permit", + } + ] + } + } + } + } + result = create_prefix_lists(tgen, prefix_list) + assert result is True, "Test case {} : Failed \n Error: {}".format( + tc_name, result + ) + + step("Create route-map for applying prefix-list on r1") + + for addr_type in ADDR_TYPES: + for pfx, comm_id in zip([6, 7], [7, 8]): + route_map = { + "r1": { + "route_maps": { + "rmap_{}".format(addr_type): [ + { + "action": "permit", + "match": { + addr_type: { + "prefix_lists": "pf_list_{}_{}".format( + addr_type, pfx + ) + } + }, + "set": {"community": {"num": COMMUNITY[comm_id]}}, + } + ] + } + } + } + + result = create_route_maps(tgen, route_map) + assert result is True, "Testcase {} :Failed \n Error: {}".format( + tc_name, result + ) + + step( + "Verify on R3 when route is added within the summary range, aggregated" + " route also has associated community value added. However if the route" + " is beyond the summary range the aggregated route would have no impact" + ) + + for addr_type in ADDR_TYPES: + input_dict = {"community": COMMUNITY[9]} + result = verify_bgp_community( + tgen, addr_type, "r3", [AGGREGATE_NW[addr_type]], input_dict + ) + assert result is True, "Test case {} : Failed \n Error: {}".format( + tc_name, result + ) + + for action, value in zip(["Delete", "Re-add"], [True, False]): + step("{} aggregation command from R1.".format(action)) + + for addr_type in ADDR_TYPES: + route_aggregate = { + "r1": { + "bgp": { + "address_family": { + addr_type: { + "unicast": { + "aggregate_address": [ + { + "network": AGGREGATE_NW[addr_type], + "as_set": True, + "delete": value, + } + ] + } + } + } + } + } + } + + result = create_router_bgp(tgen, topo, route_aggregate) + assert result is True, "Testcase {} :Failed \n Error: {}".format( + tc_name, result + ) + + step( + "Verify that when as-set command is removed, we do not see community " + "attribute added to summarised route on R3. However when as-set option " + "is re-added, all the community attribute values must appear with " + "summarised route." + ) + + for addr_type in ADDR_TYPES: + input_static_agg = { + "r1": {"static_routes": [{"network": AGGREGATE_NW[addr_type]}]} + } + + if value: + result = verify_rib( + tgen, addr_type, "r1", input_static_agg, expected=False + ) + assert result is not True, ( + "Testcase : Failed \n " + "Aggregated route is still present \n Error: {}".format( + tc_name, result + ) + ) + + result = verify_rib( + tgen, addr_type, "r3", input_static_agg, expected=False + ) + assert result is not True, ( + "Testcase : Failed \n " + "Aggregated route is still present \n Error: {}".format( + tc_name, result + ) + ) + else: + result = verify_rib(tgen, addr_type, "r1", input_static_agg) + assert result is True, "Testcase : Failed \n Error: {}".format( + tc_name, result + ) + + result = verify_rib(tgen, addr_type, "r3", input_static_agg) + assert result is True, "Testcase : Failed \n Error: {}".format( + tc_name, result + ) + + input_dict = {"community": COMMUNITY[9]} + result = verify_bgp_community( + tgen, addr_type, "r3", [AGGREGATE_NW[addr_type]], input_dict + ) + assert result is True, "Test case {} : Failed \n Error: {}".format( + tc_name, result + ) + + write_test_footer(tc_name) + + +if __name__ == "__main__": + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_rr_ibgp/test_bgp_rr_ibgp_topo1.py b/tests/topotests/bgp_rr_ibgp/test_bgp_rr_ibgp_topo1.py index da45e73ab4..6a604765ca 100755..100644 --- a/tests/topotests/bgp_rr_ibgp/test_bgp_rr_ibgp_topo1.py +++ b/tests/topotests/bgp_rr_ibgp/test_bgp_rr_ibgp_topo1.py @@ -104,7 +104,7 @@ def setup_module(module): # This is a sample of configuration loading. router_list = tgen.routers() - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) diff --git a/tests/topotests/bgp_sender-as-path-loop-detection/test_bgp_sender-as-path-loop-detection.py b/tests/topotests/bgp_sender-as-path-loop-detection/test_bgp_sender-as-path-loop-detection.py index 56a98c1ef8..88935ae4d1 100644 --- a/tests/topotests/bgp_sender-as-path-loop-detection/test_bgp_sender-as-path-loop-detection.py +++ b/tests/topotests/bgp_sender-as-path-loop-detection/test_bgp_sender-as-path-loop-detection.py @@ -66,7 +66,7 @@ def setup_module(mod): router_list = tgen.routers() - for i, (rname, router) in enumerate(router_list.iteritems(), 1): + for i, (rname, router) in enumerate(router_list.items(), 1): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) diff --git a/tests/topotests/bgp_set_local-preference_add_subtract/test_bgp_set_local-preference_add_subtract.py b/tests/topotests/bgp_set_local-preference_add_subtract/test_bgp_set_local-preference_add_subtract.py index ce3165db25..af64648951 100644 --- a/tests/topotests/bgp_set_local-preference_add_subtract/test_bgp_set_local-preference_add_subtract.py +++ b/tests/topotests/bgp_set_local-preference_add_subtract/test_bgp_set_local-preference_add_subtract.py @@ -64,7 +64,7 @@ def setup_module(mod): router_list = tgen.routers() - for i, (rname, router) in enumerate(router_list.iteritems(), 1): + for i, (rname, router) in enumerate(router_list.items(), 1): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) diff --git a/tests/topotests/bgp_update_delay/test_bgp_update_delay.py b/tests/topotests/bgp_update_delay/test_bgp_update_delay.py index 9d2818b965..4de7184c8e 100755..100644 --- a/tests/topotests/bgp_update_delay/test_bgp_update_delay.py +++ b/tests/topotests/bgp_update_delay/test_bgp_update_delay.py @@ -104,7 +104,7 @@ def setup_module(mod): router_list = tgen.routers() - for i, (rname, router) in enumerate(router_list.iteritems(), 1): + for i, (rname, router) in enumerate(router_list.items(), 1): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) diff --git a/tests/topotests/bgp_vrf_lite_ipv6_rtadv/test_bgp_vrf_lite_ipv6_rtadv.py b/tests/topotests/bgp_vrf_lite_ipv6_rtadv/test_bgp_vrf_lite_ipv6_rtadv.py index 5d8c80c6a2..50b9b092d6 100644 --- a/tests/topotests/bgp_vrf_lite_ipv6_rtadv/test_bgp_vrf_lite_ipv6_rtadv.py +++ b/tests/topotests/bgp_vrf_lite_ipv6_rtadv/test_bgp_vrf_lite_ipv6_rtadv.py @@ -95,7 +95,7 @@ def setup_module(mod): "ip link set {0}-eth0 master {0}-cust1", ] - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): for cmd in cmds: output = tgen.net[rname].cmd(cmd.format(rname)) @@ -109,7 +109,7 @@ def setup_module(mod): "sysctl -w net.ipv4.tcp_l3mdev_accept={}".format(l3mdev_accept) ) - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) diff --git a/tests/topotests/bgp_vrf_netns/test_bgp_vrf_netns_topo.py b/tests/topotests/bgp_vrf_netns/test_bgp_vrf_netns_topo.py index ae48f01a0e..30bb9595b7 100755..100644 --- a/tests/topotests/bgp_vrf_netns/test_bgp_vrf_netns_topo.py +++ b/tests/topotests/bgp_vrf_netns/test_bgp_vrf_netns_topo.py @@ -140,7 +140,7 @@ def setup_module(module): # Starting Hosts and init ExaBGP on each of them logger.info("starting exaBGP on peer1") peer_list = tgen.exabgp_peers() - for pname, peer in peer_list.iteritems(): + for pname, peer in peer_list.items(): peer_dir = os.path.join(CWD, pname) env_file = os.path.join(CWD, "exabgp.env") logger.info("Running ExaBGP peer") diff --git a/tests/topotests/eigrp-topo1/test_eigrp_topo1.py b/tests/topotests/eigrp-topo1/test_eigrp_topo1.py index c1dd88823b..70666a3d61 100755..100644 --- a/tests/topotests/eigrp-topo1/test_eigrp_topo1.py +++ b/tests/topotests/eigrp-topo1/test_eigrp_topo1.py @@ -99,7 +99,7 @@ def setup_module(module): # This is a sample of configuration loading. router_list = tgen.routers() - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) diff --git a/tests/topotests/evpn-pim-1/test_evpn_pim_topo1.py b/tests/topotests/evpn-pim-1/test_evpn_pim_topo1.py index 94bb91d49f..265124132f 100755..100644 --- a/tests/topotests/evpn-pim-1/test_evpn_pim_topo1.py +++ b/tests/topotests/evpn-pim-1/test_evpn_pim_topo1.py @@ -123,7 +123,7 @@ def setup_module(module): # tgen.mininet_cli() # This is a sample of configuration loading. router_list = tgen.routers() - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) diff --git a/tests/topotests/example-test/test_template.py b/tests/topotests/example-test/test_template.py index afe974876a..4305e0199f 100755..100644 --- a/tests/topotests/example-test/test_template.py +++ b/tests/topotests/example-test/test_template.py @@ -82,7 +82,7 @@ def setup_module(mod): router_list = tgen.routers() # For all registred routers, load the zebra configuration file - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): router.load_config( TopoRouter.RD_ZEBRA, # Uncomment next line to load configuration from ./router/zebra.conf diff --git a/tests/topotests/isis-sr-topo1/test_isis_sr_topo1.py b/tests/topotests/isis-sr-topo1/test_isis_sr_topo1.py index 72bc96e4d0..d4ebe52bf6 100755..100644 --- a/tests/topotests/isis-sr-topo1/test_isis_sr_topo1.py +++ b/tests/topotests/isis-sr-topo1/test_isis_sr_topo1.py @@ -140,7 +140,7 @@ def setup_module(mod): router_list = tgen.routers() # For all registered routers, load the zebra configuration file - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, '{}/zebra.conf'.format(rname)) diff --git a/tests/topotests/isis-topo1-vrf/test_isis_topo1_vrf.py b/tests/topotests/isis-topo1-vrf/test_isis_topo1_vrf.py index a0e34b71b0..65515f22cc 100755..100644 --- a/tests/topotests/isis-topo1-vrf/test_isis_topo1_vrf.py +++ b/tests/topotests/isis-topo1-vrf/test_isis_topo1_vrf.py @@ -113,7 +113,7 @@ def setup_module(mod): ] # For all registered routers, load the zebra configuration file - for rname, router in tgen.routers().iteritems(): + for rname, router in tgen.routers().items(): # create VRF rx-cust1 and link rx-eth0 to rx-cust1 for cmd in cmds: output = tgen.net[rname].cmd(cmd.format(rname)) @@ -127,7 +127,7 @@ def setup_module(mod): "sysctl -w net.ipv4.tcp_l3mdev_accept={}".format(l3mdev_accept) ) - for rname, router in tgen.routers().iteritems(): + for rname, router in tgen.routers().items(): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) @@ -164,7 +164,7 @@ def test_isis_convergence(): logger.info("waiting for ISIS protocol to converge") - for rname, router in tgen.routers().iteritems(): + for rname, router in tgen.routers().items(): filename = "{0}/{1}/{1}_topology.json".format(CWD, rname) expected = json.loads(open(filename).read()) def compare_isis_topology(router, expected): @@ -186,13 +186,13 @@ def test_isis_route_installation(): logger.info("Checking routers for installed ISIS vrf routes") # Check for routes in 'show ip route vrf {}-cust1 json' - for rname, router in tgen.routers().iteritems(): + for rname, router in tgen.routers().items(): filename = "{0}/{1}/{1}_route.json".format(CWD, rname) expected = json.loads(open(filename, "r").read()) actual = router.vtysh_cmd("show ip route vrf {0}-cust1 json".format(rname) , isjson=True) # Older FRR versions don't list interfaces in some ISIS routes if router.has_version("<", "3.1"): - for network, routes in expected.iteritems(): + for network, routes in expected.items(): for route in routes: if route["protocol"] != "isis": continue @@ -220,14 +220,14 @@ def test_isis_linux_route_installation(): logger.info("Checking routers for installed ISIS vrf routes in OS") # Check for routes in `ip route show vrf {}-cust1` - for rname, router in tgen.routers().iteritems(): + for rname, router in tgen.routers().items(): filename = "{0}/{1}/{1}_route_linux.json".format(CWD, rname) expected = json.loads(open(filename, "r").read()) actual = topotest.ip4_vrf_route(router) # Older FRR versions install routes using different proto if router.has_version("<", "3.1"): - for network, netoptions in expected.iteritems(): + for network, netoptions in expected.items(): if "proto" in netoptions and netoptions["proto"] == "187": netoptions["proto"] = "zebra" @@ -243,14 +243,14 @@ def test_isis_route6_installation(): logger.info("Checking routers for installed ISIS vrf IPv6 routes") # Check for routes in 'show ipv6 route vrf {}-cust1 json' - for rname, router in tgen.routers().iteritems(): + for rname, router in tgen.routers().items(): filename = "{0}/{1}/{1}_route6.json".format(CWD, rname) expected = json.loads(open(filename, "r").read()) actual = router.vtysh_cmd("show ipv6 route vrf {}-cust1 json".format(rname) , isjson=True) # Older FRR versions don't list interfaces in some ISIS routes if router.has_version("<", "3.1"): - for network, routes in expected.iteritems(): + for network, routes in expected.items(): for route in routes: if route["protocol"] != "isis": continue @@ -277,14 +277,14 @@ def test_isis_linux_route6_installation(): logger.info("Checking routers for installed ISIS vrf IPv6 routes in OS") # Check for routes in `ip -6 route show vrf {}-cust1` - for rname, router in tgen.routers().iteritems(): + for rname, router in tgen.routers().items(): filename = "{0}/{1}/{1}_route6_linux.json".format(CWD, rname) expected = json.loads(open(filename, "r").read()) actual = topotest.ip6_vrf_route(router) # Older FRR versions install routes using different proto if router.has_version("<", "3.1"): - for network, netoptions in expected.iteritems(): + for network, netoptions in expected.items(): if "proto" in netoptions and netoptions["proto"] == "187": netoptions["proto"] = "zebra" @@ -323,7 +323,7 @@ def dict_merge(dct, merge_dct): Source: https://gist.github.com/angstwad/bf22d1822c38a92ec0a9 """ - for k, v in merge_dct.iteritems(): + for k, v in merge_dct.items(): if ( k in dct and isinstance(dct[k], dict) diff --git a/tests/topotests/isis-topo1/test_isis_topo1.py b/tests/topotests/isis-topo1/test_isis_topo1.py index 6b1d9a8964..71005a0362 100644 --- a/tests/topotests/isis-topo1/test_isis_topo1.py +++ b/tests/topotests/isis-topo1/test_isis_topo1.py @@ -91,7 +91,7 @@ def setup_module(mod): tgen.start_topology() # For all registered routers, load the zebra configuration file - for rname, router in tgen.routers().iteritems(): + for rname, router in tgen.routers().items(): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) @@ -129,12 +129,12 @@ def test_isis_convergence(): logger.info("waiting for ISIS protocol to converge") # Code to generate the json files. - # for rname, router in tgen.routers().iteritems(): + # for rname, router in tgen.routers().items(): # open('/tmp/{}_topology.json'.format(rname), 'w').write( # json.dumps(show_isis_topology(router), indent=2, sort_keys=True) # ) - for rname, router in tgen.routers().iteritems(): + for rname, router in tgen.routers().items(): filename = "{0}/{1}/{1}_topology.json".format(CWD, rname) expected = json.loads(open(filename).read()) @@ -158,14 +158,14 @@ def test_isis_route_installation(): logger.info("Checking routers for installed ISIS routes") # Check for routes in 'show ip route json' - for rname, router in tgen.routers().iteritems(): + for rname, router in tgen.routers().items(): filename = "{0}/{1}/{1}_route.json".format(CWD, rname) expected = json.loads(open(filename, "r").read()) actual = router.vtysh_cmd("show ip route json", isjson=True) # Older FRR versions don't list interfaces in some ISIS routes if router.has_version("<", "3.1"): - for network, routes in expected.iteritems(): + for network, routes in expected.items(): for route in routes: if route["protocol"] != "isis": continue @@ -188,14 +188,14 @@ def test_isis_linux_route_installation(): logger.info("Checking routers for installed ISIS routes in OS") # Check for routes in `ip route` - for rname, router in tgen.routers().iteritems(): + for rname, router in tgen.routers().items(): filename = "{0}/{1}/{1}_route_linux.json".format(CWD, rname) expected = json.loads(open(filename, "r").read()) actual = topotest.ip4_route(router) # Older FRR versions install routes using different proto if router.has_version("<", "3.1"): - for network, netoptions in expected.iteritems(): + for network, netoptions in expected.items(): if "proto" in netoptions and netoptions["proto"] == "187": netoptions["proto"] = "zebra" @@ -213,14 +213,14 @@ def test_isis_route6_installation(): logger.info("Checking routers for installed ISIS IPv6 routes") # Check for routes in 'show ip route json' - for rname, router in tgen.routers().iteritems(): + for rname, router in tgen.routers().items(): filename = "{0}/{1}/{1}_route6.json".format(CWD, rname) expected = json.loads(open(filename, "r").read()) actual = router.vtysh_cmd("show ipv6 route json", isjson=True) # Older FRR versions don't list interfaces in some ISIS routes if router.has_version("<", "3.1"): - for network, routes in expected.iteritems(): + for network, routes in expected.items(): for route in routes: # Older versions display different metrics for IPv6 routes route.pop("metric", None) @@ -246,14 +246,14 @@ def test_isis_linux_route6_installation(): logger.info("Checking routers for installed ISIS IPv6 routes in OS") # Check for routes in `ip route` - for rname, router in tgen.routers().iteritems(): + for rname, router in tgen.routers().items(): filename = "{0}/{1}/{1}_route6_linux.json".format(CWD, rname) expected = json.loads(open(filename, "r").read()) actual = topotest.ip6_route(router) # Older FRR versions install routes using different proto if router.has_version("<", "3.1"): - for network, netoptions in expected.iteritems(): + for network, netoptions in expected.items(): if "proto" in netoptions and netoptions["proto"] == "187": netoptions["proto"] = "zebra" @@ -293,7 +293,7 @@ def dict_merge(dct, merge_dct): Source: https://gist.github.com/angstwad/bf22d1822c38a92ec0a9 """ - for k, v in merge_dct.iteritems(): + for k, v in merge_dct.items(): if ( k in dct and isinstance(dct[k], dict) diff --git a/tests/topotests/ldp-oc-acl-topo1/test_ldp_oc_acl_topo1.py b/tests/topotests/ldp-oc-acl-topo1/test_ldp_oc_acl_topo1.py index 450d35e16c..dadb2065e6 100755..100644 --- a/tests/topotests/ldp-oc-acl-topo1/test_ldp_oc_acl_topo1.py +++ b/tests/topotests/ldp-oc-acl-topo1/test_ldp_oc_acl_topo1.py @@ -117,7 +117,7 @@ def setup_module(mod): router_list = tgen.routers() # For all registered routers, load the zebra configuration file - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) diff --git a/tests/topotests/ldp-oc-topo1/test_ldp_oc_topo1.py b/tests/topotests/ldp-oc-topo1/test_ldp_oc_topo1.py index ac99eb1a26..ea449e4aba 100755..100644 --- a/tests/topotests/ldp-oc-topo1/test_ldp_oc_topo1.py +++ b/tests/topotests/ldp-oc-topo1/test_ldp_oc_topo1.py @@ -117,7 +117,7 @@ def setup_module(mod): router_list = tgen.routers() # For all registered routers, load the zebra configuration file - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) diff --git a/tests/topotests/ldp-sync-isis-topo1/test_ldp_sync_isis_topo1.py b/tests/topotests/ldp-sync-isis-topo1/test_ldp_sync_isis_topo1.py index 1dce698c17..01f895891c 100755..100644 --- a/tests/topotests/ldp-sync-isis-topo1/test_ldp_sync_isis_topo1.py +++ b/tests/topotests/ldp-sync-isis-topo1/test_ldp_sync_isis_topo1.py @@ -130,7 +130,7 @@ def setup_module(mod): router_list = tgen.routers() # For all registered routers, load the zebra configuration file - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) @@ -163,9 +163,9 @@ def router_compare_json_output(rname, command, reference): filename = "{}/{}/{}".format(CWD, rname, reference) expected = json.loads(open(filename).read()) - # Run test function until we get an result. Wait at most 80 seconds. + # Run test function until we get an result. test_func = partial(topotest.router_json_cmp, tgen.gears[rname], command, expected) - _, diff = topotest.run_and_expect(test_func, None, count=160, wait=0.5) + _, diff = topotest.run_and_expect(test_func, None, count=320, wait=0.5) assertmsg = '"{}" JSON output mismatches the expected result'.format(rname) assert diff is None, assertmsg diff --git a/tests/topotests/ldp-sync-ospf-topo1/test_ldp_sync_ospf_topo1.py b/tests/topotests/ldp-sync-ospf-topo1/test_ldp_sync_ospf_topo1.py index dc6a76eb49..9694fa982f 100755..100644 --- a/tests/topotests/ldp-sync-ospf-topo1/test_ldp_sync_ospf_topo1.py +++ b/tests/topotests/ldp-sync-ospf-topo1/test_ldp_sync_ospf_topo1.py @@ -129,7 +129,7 @@ def setup_module(mod): router_list = tgen.routers() # For all registered routers, load the zebra configuration file - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) @@ -162,9 +162,9 @@ def router_compare_json_output(rname, command, reference): filename = "{}/{}/{}".format(CWD, rname, reference) expected = json.loads(open(filename).read()) - # Run test function until we get an result. Wait at most 80 seconds. + # Run test function until we get an result. test_func = partial(topotest.router_json_cmp, tgen.gears[rname], command, expected) - _, diff = topotest.run_and_expect(test_func, None, count=160, wait=0.5) + _, diff = topotest.run_and_expect(test_func, None, count=320, wait=0.5) assertmsg = '"{}" JSON output mismatches the expected result'.format(rname) assert diff is None, assertmsg diff --git a/tests/topotests/ldp-vpls-topo1/test_ldp_vpls_topo1.py b/tests/topotests/ldp-vpls-topo1/test_ldp_vpls_topo1.py index a1662dc411..0b8bf4de0e 100755..100644 --- a/tests/topotests/ldp-vpls-topo1/test_ldp_vpls_topo1.py +++ b/tests/topotests/ldp-vpls-topo1/test_ldp_vpls_topo1.py @@ -130,7 +130,7 @@ def setup_module(mod): router_list = tgen.routers() # For all registered routers, load the zebra configuration file - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) diff --git a/tests/topotests/lib/bgp.py b/tests/topotests/lib/bgp.py index 53257525c6..a3d846edbb 100644 --- a/tests/topotests/lib/bgp.py +++ b/tests/topotests/lib/bgp.py @@ -367,7 +367,7 @@ def __create_bgp_unicast_neighbor( bgp_data = input_dict["address_family"] - for addr_type, addr_dict in bgp_data.iteritems(): + for addr_type, addr_dict in bgp_data.items(): if not addr_dict: continue @@ -391,12 +391,11 @@ def __create_bgp_unicast_neighbor( del_action = advertise_network_dict.setdefault("delete", False) # Generating IPs for verification - prefix = str(ipaddress.ip_network(unicode(network[0])).prefixlen) network_list = generate_ips(network, no_of_network) for ip in network_list: - ip = str(ipaddress.ip_network(unicode(ip)).network_address) + ip = str(ipaddress.ip_network(unicode(ip))) - cmd = "network {}/{}".format(ip, prefix) + cmd = "network {}".format(ip) if del_action: cmd = "no {}".format(cmd) @@ -471,7 +470,7 @@ def __create_bgp_unicast_neighbor( ) config_data.extend(neigh_data) - for addr_type, addr_dict in bgp_data.iteritems(): + for addr_type, addr_dict in bgp_data.items(): if not addr_dict or not check_address_types(addr_type): continue @@ -509,7 +508,7 @@ def __create_l2vpn_evpn_address_family( bgp_data = input_dict["address_family"] - for family_type, family_dict in bgp_data.iteritems(): + for family_type, family_dict in bgp_data.items(): if family_type != "l2vpn": continue @@ -665,8 +664,8 @@ def __create_bgp_neighbor(topo, input_dict, router, addr_type, add_neigh=True): bgp_data = input_dict["address_family"] neigh_data = bgp_data[addr_type]["unicast"]["neighbor"] - for name, peer_dict in neigh_data.iteritems(): - for dest_link, peer in peer_dict["dest_link"].iteritems(): + for name, peer_dict in neigh_data.items(): + for dest_link, peer in peer_dict["dest_link"].items(): nh_details = topo[name] if "vrfs" in topo[router] or type(nh_details["bgp"]) is list: @@ -770,8 +769,8 @@ def __create_bgp_unicast_address_family( bgp_data = input_dict["address_family"] neigh_data = bgp_data[addr_type]["unicast"]["neighbor"] - for peer_name, peer_dict in deepcopy(neigh_data).iteritems(): - for dest_link, peer in peer_dict["dest_link"].iteritems(): + for peer_name, peer_dict in deepcopy(neigh_data).items(): + for dest_link, peer in peer_dict["dest_link"].items(): deactivate = None activate = None nh_details = topo[peer_name] @@ -779,7 +778,7 @@ def __create_bgp_unicast_address_family( deactivate_addr_family = peer.setdefault("deactivate", None) # Loopback interface if "source_link" in peer and peer["source_link"] == "lo": - for destRouterLink, data in sorted(nh_details["links"].iteritems()): + for destRouterLink, data in sorted(nh_details["links"].items()): if "type" in data and data["type"] == "loopback": if dest_link == destRouterLink: ip_addr = nh_details["links"][destRouterLink][ @@ -961,7 +960,7 @@ def modify_bgp_config_when_bgpd_down(tgen, topo, input_dict): # Copy bgp config file to /etc/frr for dut in input_dict.keys(): router_list = tgen.routers() - for router, rnode in router_list.iteritems(): + for router, rnode in router_list.items(): if router != dut: continue @@ -1083,7 +1082,7 @@ def verify_bgp_convergence(tgen, topo, dut=None): """ logger.debug("Entering lib API: verify_bgp_convergence()") - for router, rnode in tgen.routers().iteritems(): + for router, rnode in tgen.routers().items(): if "bgp" not in topo["routers"][router]: continue @@ -1462,9 +1461,9 @@ def verify_as_numbers(tgen, topo, input_dict): bgp_neighbors = bgp_addr_type[addr_type]["unicast"]["neighbor"] - for bgp_neighbor, peer_data in bgp_neighbors.iteritems(): + for bgp_neighbor, peer_data in bgp_neighbors.items(): remote_as = input_dict[bgp_neighbor]["bgp"]["local_as"] - for dest_link, peer_dict in peer_data["dest_link"].iteritems(): + for dest_link, peer_dict in peer_data["dest_link"].items(): neighbor_ip = None data = topo["routers"][bgp_neighbor]["links"] @@ -1534,7 +1533,7 @@ def verify_bgp_convergence_from_running_config(tgen, dut=None): logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name)) - for router, rnode in tgen.routers().iteritems(): + for router, rnode in tgen.routers().items(): if dut is not None and dut != router: continue @@ -1686,8 +1685,8 @@ def clear_bgp_and_verify(tgen, topo, router): for addr_type in bgp_addr_type: bgp_neighbors = bgp_addr_type[addr_type]["unicast"]["neighbor"] - for bgp_neighbor, peer_data in bgp_neighbors.iteritems(): - for dest_link, peer_dict in peer_data["dest_link"].iteritems(): + for bgp_neighbor, peer_data in bgp_neighbors.items(): + for dest_link, peer_dict in peer_data["dest_link"].items(): data = topo["routers"][bgp_neighbor]["links"] if dest_link in data: @@ -1768,8 +1767,8 @@ def clear_bgp_and_verify(tgen, topo, router): for addr_type in bgp_addr_type: bgp_neighbors = bgp_addr_type[addr_type]["unicast"]["neighbor"] - for bgp_neighbor, peer_data in bgp_neighbors.iteritems(): - for dest_link, peer_dict in peer_data["dest_link"].iteritems(): + for bgp_neighbor, peer_data in bgp_neighbors.items(): + for dest_link, peer_dict in peer_data["dest_link"].items(): data = topo["routers"][bgp_neighbor]["links"] if dest_link in data: @@ -1873,8 +1872,8 @@ def verify_bgp_timers_and_functionality(tgen, topo, input_dict): continue bgp_neighbors = bgp_addr_type[addr_type]["unicast"]["neighbor"] - for bgp_neighbor, peer_data in bgp_neighbors.iteritems(): - for dest_link, peer_dict in peer_data["dest_link"].iteritems(): + for bgp_neighbor, peer_data in bgp_neighbors.items(): + for dest_link, peer_dict in peer_data["dest_link"].items(): data = topo["routers"][bgp_neighbor]["links"] keepalivetimer = peer_dict["keepalivetimer"] @@ -2116,7 +2115,7 @@ def verify_bgp_attributes( """ logger.debug("Entering lib API: verify_bgp_attributes()") - for router, rnode in tgen.routers().iteritems(): + for router, rnode in tgen.routers().items(): if router != dut: continue @@ -2330,7 +2329,7 @@ def verify_best_path_as_per_bgp_attribute( # - rule is IGP>EGP>INCOMPLETE _next_hop = [ key - for (key, value) in attribute_dict.iteritems() + for (key, value) in attribute_dict.items() if value == "IGP" ][0] compare = "" @@ -2550,7 +2549,7 @@ def verify_bgp_rib(tgen, addr_type, dut, input_dict, next_hop=None, aspath=None) list1 = [] list2 = [] for routerInput in input_dict.keys(): - for router, rnode in router_list.iteritems(): + for router, rnode in router_list.items(): if router != dut: continue @@ -2834,7 +2833,7 @@ def verify_graceful_restart(tgen, topo, addr_type, input_dict, dut, peer): logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name)) - for router, rnode in tgen.routers().iteritems(): + for router, rnode in tgen.routers().items(): if router != dut: continue @@ -3082,7 +3081,7 @@ def verify_r_bit(tgen, topo, addr_type, input_dict, dut, peer): logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name)) - for router, rnode in tgen.routers().iteritems(): + for router, rnode in tgen.routers().items(): if router != dut: continue @@ -3200,7 +3199,7 @@ def verify_eor(tgen, topo, addr_type, input_dict, dut, peer): """ logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name)) - for router, rnode in tgen.routers().iteritems(): + for router, rnode in tgen.routers().items(): if router != dut: continue @@ -3365,7 +3364,7 @@ def verify_f_bit(tgen, topo, addr_type, input_dict, dut, peer): logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name)) - for router, rnode in tgen.routers().iteritems(): + for router, rnode in tgen.routers().items(): if router != dut: continue @@ -3491,7 +3490,7 @@ def verify_graceful_restart_timers(tgen, topo, addr_type, input_dict, dut, peer) logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name)) - for router, rnode in tgen.routers().iteritems(): + for router, rnode in tgen.routers().items(): if router != dut: continue @@ -3595,7 +3594,7 @@ def verify_gr_address_family(tgen, topo, addr_type, addr_family, dut): logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name)) - for router, rnode in tgen.routers().iteritems(): + for router, rnode in tgen.routers().items(): if router != dut: continue diff --git a/tests/topotests/lib/common_config.py b/tests/topotests/lib/common_config.py index 9a79693840..6dd8d646f3 100644 --- a/tests/topotests/lib/common_config.py +++ b/tests/topotests/lib/common_config.py @@ -355,7 +355,7 @@ def kill_mininet_routers_process(tgen): """ router_list = tgen.routers() - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): daemon_list = [ "zebra", "ospfd", @@ -382,7 +382,7 @@ def check_router_status(tgen): try: router_list = tgen.routers() - for router, rnode in router_list.iteritems(): + for router, rnode in router_list.items(): result = rnode.check_router_running() if result != "": @@ -612,7 +612,7 @@ def get_frr_ipv6_linklocal(tgen, router, intf=None, vrf=None): """ router_list = tgen.routers() - for rname, rnode in router_list.iteritems(): + for rname, rnode in router_list.items(): if rname != router: continue @@ -670,7 +670,7 @@ def generate_support_bundle(): test_name = sys._getframe(2).f_code.co_name TMPDIR = os.path.join(LOGDIR, tgen.modname) - for rname, rnode in router_list.iteritems(): + for rname, rnode in router_list.items(): logger.info("Generating support bundle for {}".format(rname)) rnode.run("mkdir -p /var/log/frr") bundle_log = rnode.run("python2 /usr/lib/frr/generate_support_bundle.py") @@ -904,7 +904,7 @@ def create_vrf_cfg(tgen, topo, input_dict=None, build=False): input_dict = deepcopy(input_dict) try: - for c_router, c_data in input_dict.iteritems(): + for c_router, c_data in input_dict.items(): rnode = tgen.routers()[c_router] if "vrfs" in c_data: for vrf in c_data["vrfs"]: @@ -949,7 +949,7 @@ def create_vrf_cfg(tgen, topo, input_dict=None, build=False): if "links" in c_data: for destRouterLink, data in sorted( - c_data["links"].iteritems() + c_data["links"].items() ): # Loopback interfaces if "type" in data and data["type"] == "loopback": @@ -1184,7 +1184,7 @@ def find_interface_with_greater_ip(topo, router, loopback=True, interface=True): lo_list = [] interfaces_list = [] lo_exists = False - for destRouterLink, data in sorted(link_data.iteritems()): + for destRouterLink, data in sorted(link_data.items()): if loopback: if "type" in data and data["type"] == "loopback": lo_exists = True @@ -1378,9 +1378,9 @@ def create_interfaces_cfg(tgen, topo, build=False): topo = deepcopy(topo) try: - for c_router, c_data in topo.iteritems(): + for c_router, c_data in topo.items(): interface_data = [] - for destRouterLink, data in sorted(c_data["links"].iteritems()): + for destRouterLink, data in sorted(c_data["links"].items()): # Loopback interfaces if "type" in data and data["type"] == "loopback": interface_name = destRouterLink @@ -1654,11 +1654,11 @@ def create_prefix_lists(tgen, input_dict, build=False): config_data = [] prefix_lists = input_dict[router]["prefix_lists"] - for addr_type, prefix_data in prefix_lists.iteritems(): + for addr_type, prefix_data in prefix_lists.items(): if not check_address_types(addr_type): continue - for prefix_name, prefix_list in prefix_data.iteritems(): + for prefix_name, prefix_list in prefix_data.items(): for prefix_dict in prefix_list: if "action" not in prefix_dict or "network" not in prefix_dict: errormsg = "'action' or network' missing in" " input_dict" @@ -1795,7 +1795,7 @@ def create_route_maps(tgen, input_dict, build=False): logger.debug("route_maps not present in input_dict") continue rmap_data = [] - for rmap_name, rmap_value in input_dict[router]["route_maps"].iteritems(): + for rmap_name, rmap_value in input_dict[router]["route_maps"].items(): for rmap_dict in rmap_value: del_action = rmap_dict.setdefault("delete", False) @@ -2607,7 +2607,7 @@ def verify_rib( additional_nexthops_in_required_nhs = [] found_hops = [] for routerInput in input_dict.keys(): - for router, rnode in router_list.iteritems(): + for router, rnode in router_list.items(): if router != dut: continue @@ -2960,7 +2960,7 @@ def verify_fib_routes(tgen, addr_type, dut, input_dict, next_hop=None): router_list = tgen.routers() for routerInput in input_dict.keys(): - for router, rnode in router_list.iteritems(): + for router, rnode in router_list.items(): if router != dut: continue @@ -3216,7 +3216,7 @@ def verify_fib_routes(tgen, addr_type, dut, input_dict, next_hop=None): router_list = tgen.routers() for routerInput in input_dict.keys(): - for router, rnode in router_list.iteritems(): + for router, rnode in router_list.items(): if router != dut: continue diff --git a/tests/topotests/lib/ltemplate.py b/tests/topotests/lib/ltemplate.py index a76d8e4b08..192c121008 100644 --- a/tests/topotests/lib/ltemplate.py +++ b/tests/topotests/lib/ltemplate.py @@ -82,7 +82,7 @@ class LTemplate(): router_list = tgen.routers() # For all registred routers, load the zebra configuration file - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): logger.info("Setting up %s" % rname) for rd_val in TopoRouter.RD: config = os.path.join(self.testdir, '{}/{}.conf'.format(rname,TopoRouter.RD[rd_val])) diff --git a/tests/topotests/lib/topogen.py b/tests/topotests/lib/topogen.py index a6cc5280ec..b9f82877e2 100644 --- a/tests/topotests/lib/topogen.py +++ b/tests/topotests/lib/topogen.py @@ -254,7 +254,7 @@ class Topogen(object): ```py tgen = get_topogen() router_dict = tgen.get_gears(TopoRouter) - for router_name, router in router_dict.iteritems(): + for router_name, router in router_dict.items(): # Do stuff ``` * List iteration: @@ -267,7 +267,7 @@ class Topogen(object): """ return dict( (name, gear) - for name, gear in self.gears.iteritems() + for name, gear in self.gears.items() if isinstance(gear, geartype) ) @@ -316,7 +316,7 @@ class Topogen(object): """ if router is None: # pylint: disable=r1704 - for _, router in self.routers().iteritems(): + for _, router in self.routers().items(): router.start() else: if isinstance(router, str): @@ -430,7 +430,7 @@ class TopoGear(object): def __str__(self): links = "" - for myif, dest in self.links.iteritems(): + for myif, dest in self.links.items(): _, destif = dest if links != "": links += "," @@ -684,7 +684,7 @@ class TopoRouter(TopoGear): # Enable all daemon command logging, logging files # and set them to the start dir. - for daemon, enabled in nrouter.daemons.iteritems(): + for daemon, enabled in nrouter.daemons.items(): if enabled == 0: continue self.vtysh_cmd( @@ -733,7 +733,7 @@ class TopoRouter(TopoGear): # Enable all daemon command logging, logging files # and set them to the start dir. - for daemon, enabled in nrouter.daemons.iteritems(): + for daemon, enabled in nrouter.daemons.items(): for d in daemons: if enabled == 0: continue diff --git a/tests/topotests/lib/topojson.py b/tests/topotests/lib/topojson.py index 6d97ab2e90..b3af09aa99 100644 --- a/tests/topotests/lib/topojson.py +++ b/tests/topotests/lib/topojson.py @@ -109,7 +109,7 @@ def build_topo_from_json(tgen, topo): return int(re_search("\d+", x).group(0)) for destRouterLink, data in sorted( - topo["routers"][curRouter]["links"].iteritems(), + topo["routers"][curRouter]["links"].items(), key=lambda x: link_sort(x[0]), ): currRouter_lo_json = topo["routers"][curRouter]["links"][destRouterLink] diff --git a/tests/topotests/ospf-sr-topo1/test_ospf_sr_topo1.py b/tests/topotests/ospf-sr-topo1/test_ospf_sr_topo1.py index 6792c56b3b..86fc90e665 100755..100644 --- a/tests/topotests/ospf-sr-topo1/test_ospf_sr_topo1.py +++ b/tests/topotests/ospf-sr-topo1/test_ospf_sr_topo1.py @@ -93,7 +93,7 @@ def setup_module(mod): router_list = tgen.routers() - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) diff --git a/tests/topotests/ospf-topo1-vrf/test_ospf_topo1_vrf.py b/tests/topotests/ospf-topo1-vrf/test_ospf_topo1_vrf.py index 130d0c85f9..4ec09b10d3 100755..100644 --- a/tests/topotests/ospf-topo1-vrf/test_ospf_topo1_vrf.py +++ b/tests/topotests/ospf-topo1-vrf/test_ospf_topo1_vrf.py @@ -84,7 +84,7 @@ def setup_module(mod): router_list = tgen.routers() # check for zebra capability - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): if router.check_capability(TopoRouter.RD_ZEBRA, "--vrfwnetns") == False: return pytest.skip( "Skipping OSPF VRF NETNS feature. VRF NETNS backend not available on FRR" @@ -106,7 +106,7 @@ def setup_module(mod): "ip netns exec {0}-cust1 ifconfig {0}-eth1 up", ] - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): # create VRF rx-cust1 and link rx-eth0 to rx-cust1 for cmd in cmds: @@ -141,7 +141,7 @@ def teardown_module(mod): ] router_list = tgen.routers() - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): for cmd in cmds: tgen.net[rname].cmd(cmd.format(rname)) tgen.stop_topology() @@ -169,7 +169,7 @@ def test_ospf_convergence(): if tgen.routers_have_failure(): pytest.skip("skipped because of router(s) failure") - for rname, router in tgen.routers().iteritems(): + for rname, router in tgen.routers().items(): logger.info('Waiting for router "%s" convergence', rname) # Load expected results from the command @@ -216,7 +216,7 @@ def test_ospf_json(): if tgen.routers_have_failure(): pytest.skip("skipped because of router(s) failure") - for rname, router in tgen.routers().iteritems(): + for rname, router in tgen.routers().items(): logger.info( 'Comparing router "%s" "show ip ospf vrf %s-cust1 json" output', router.name, @@ -283,7 +283,7 @@ def test_ospf_link_down(): ) # Expect convergence on all routers - for rname, router in tgen.routers().iteritems(): + for rname, router in tgen.routers().items(): logger.info('Waiting for router "%s" convergence after link failure', rname) # Load expected results from the command reffile = os.path.join(CWD, "{}/ospfroute_down.txt".format(rname)) diff --git a/tests/topotests/ospf-topo1/test_ospf_topo1.py b/tests/topotests/ospf-topo1/test_ospf_topo1.py index d734f378e7..3af60fd48f 100755..100644 --- a/tests/topotests/ospf-topo1/test_ospf_topo1.py +++ b/tests/topotests/ospf-topo1/test_ospf_topo1.py @@ -95,7 +95,7 @@ def setup_module(mod): ospf6_config = "ospf6d.conf-pre-v4" router_list = tgen.routers() - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) @@ -146,7 +146,7 @@ def test_ospf_convergence(): if tgen.routers_have_failure(): pytest.skip("skipped because of router(s) failure") - for router, rnode in tgen.routers().iteritems(): + for router, rnode in tgen.routers().items(): logger.info('Waiting for router "%s" convergence', router) # Load expected results from the command @@ -335,7 +335,7 @@ def test_ospf_link_down(): router3.peer_link_enable("r3-eth0", False) # Expect convergence on all routers - for router, rnode in tgen.routers().iteritems(): + for router, rnode in tgen.routers().items(): logger.info('Waiting for router "%s" convergence after link failure', router) # Load expected results from the command reffile = os.path.join(CWD, "{}/ospfroute_down.txt".format(router)) diff --git a/tests/topotests/ospf-topo2/test_ospf_topo2.py b/tests/topotests/ospf-topo2/test_ospf_topo2.py index a04d841214..0b6f568462 100755..100644 --- a/tests/topotests/ospf-topo2/test_ospf_topo2.py +++ b/tests/topotests/ospf-topo2/test_ospf_topo2.py @@ -76,7 +76,7 @@ def setup_module(mod): tgen.start_topology() router_list = tgen.routers() - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, '{}/zebra.conf'.format(rname)) @@ -118,7 +118,7 @@ def test_ospf_convergence(): if tgen.routers_have_failure(): pytest.skip('skipped because of router(s) failure') - for router, rnode in tgen.routers().iteritems(): + for router, rnode in tgen.routers().items(): logger.info('Waiting for router "%s" convergence', router) json_file = '{}/{}/ospf-route.json'.format(CWD, router) diff --git a/tests/topotests/ospf6-topo1/test_ospf6_topo1.py b/tests/topotests/ospf6-topo1/test_ospf6_topo1.py index 30c09ea606..8e3a329f10 100755..100644 --- a/tests/topotests/ospf6-topo1/test_ospf6_topo1.py +++ b/tests/topotests/ospf6-topo1/test_ospf6_topo1.py @@ -164,7 +164,7 @@ def setup_module(mod): # tgen.mininet_cli() router_list = tgen.routers() - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) @@ -209,7 +209,7 @@ def test_ospf6_converged(): sys.stdout.flush() # Look for any node not yet converged - for router, rnode in tgen.routers().iteritems(): + for router, rnode in tgen.routers().items(): resStr = rnode.vtysh_cmd("show ipv6 ospf neigh") isConverged = False @@ -287,7 +287,7 @@ def test_ospfv3_routingTable(): # tgen.mininet_cli() # Verify OSPFv3 Routing Table - for router, rnode in tgen.routers().iteritems(): + for router, rnode in tgen.routers().items(): logger.info('Waiting for router "%s" convergence', router) # Load expected results from the command diff --git a/tests/topotests/pbr-topo1/test_pbr_topo1.py b/tests/topotests/pbr-topo1/test_pbr_topo1.py index ffac8e2889..9ae4cce360 100755..100644 --- a/tests/topotests/pbr-topo1/test_pbr_topo1.py +++ b/tests/topotests/pbr-topo1/test_pbr_topo1.py @@ -92,7 +92,7 @@ def setup_module(module): pytest.skip(tgen.errors) router_list = tgen.routers() - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): # Install vrf into the kernel and slave eth3 router.run("ip link add vrf-chiyoda type vrf table 1000") router.run("ip link set dev {}-eth3 master vrf-chiyoda".format(rname)) diff --git a/tests/topotests/pim-basic/test_pim.py b/tests/topotests/pim-basic/test_pim.py index 2abee39176..e8a9f72b48 100644 --- a/tests/topotests/pim-basic/test_pim.py +++ b/tests/topotests/pim-basic/test_pim.py @@ -87,7 +87,7 @@ def setup_module(mod): tgen.start_topology() # For all registered routers, load the zebra configuration file - for rname, router in tgen.routers().iteritems(): + for rname, router in tgen.routers().items(): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) diff --git a/tests/topotests/route-scale/test_route_scale.py b/tests/topotests/route-scale/test_route_scale.py index 508d1746b3..0bfae3b830 100755..100644 --- a/tests/topotests/route-scale/test_route_scale.py +++ b/tests/topotests/route-scale/test_route_scale.py @@ -86,7 +86,7 @@ def setup_module(module): tgen.start_topology() router_list = tgen.routers() - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) diff --git a/tests/topotests/zebra_netlink/test_zebra_netlink.py b/tests/topotests/zebra_netlink/test_zebra_netlink.py index 7b692c75ab..3b3c74d502 100755..100644 --- a/tests/topotests/zebra_netlink/test_zebra_netlink.py +++ b/tests/topotests/zebra_netlink/test_zebra_netlink.py @@ -81,7 +81,7 @@ def setup_module(mod): tgen.start_topology() router_list = tgen.routers() - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) diff --git a/tests/topotests/zebra_rib/test_zebra_rib.py b/tests/topotests/zebra_rib/test_zebra_rib.py index 17eb736cab..13965c63ae 100755..100644 --- a/tests/topotests/zebra_rib/test_zebra_rib.py +++ b/tests/topotests/zebra_rib/test_zebra_rib.py @@ -73,7 +73,7 @@ def setup_module(mod): tgen.start_topology() router_list = tgen.routers() - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) |
