diff options
| -rw-r--r-- | bgpd/bgp_vty.c | 96 | ||||
| -rw-r--r-- | doc/user/routemap.rst | 21 | ||||
| -rw-r--r-- | isisd/isis_circuit.c | 1 | ||||
| -rw-r--r-- | lib/ipaddr.h | 5 | ||||
| -rw-r--r-- | lib/plist.c | 7 | ||||
| -rw-r--r-- | lib/routemap.c | 1058 | ||||
| -rw-r--r-- | lib/routemap.h | 14 | ||||
| -rwxr-xr-x | tests/topotests/bgp-route-map/test_route_map_topo1.py | 26 | ||||
| -rwxr-xr-x | tests/topotests/bgp-route-map/test_route_map_topo2.py | 1259 | ||||
| -rw-r--r-- | tests/topotests/lib/bgp.py | 4 | ||||
| -rw-r--r-- | zebra/zebra_gr.c | 29 | ||||
| -rw-r--r-- | zebra/zebra_vty.c | 195 |
12 files changed, 1878 insertions, 837 deletions
diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index f18f9ccf4b..62767a603c 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -9443,7 +9443,7 @@ static void bgp_show_neighnor_graceful_restart_rbit(struct vty *vty, bool rbit_status = 0; if (!use_json) - vty_out(vty, "\n R bit : "); + vty_out(vty, "\n R bit: "); if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV) && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) @@ -9476,7 +9476,7 @@ static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty, const char *mode = "NotApplicable"; if (!use_json) - vty_out(vty, "\n Remote GR Mode : "); + vty_out(vty, "\n Remote GR Mode: "); if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) && (peer->status == Established)) { @@ -9512,7 +9512,7 @@ static void bgp_show_neighbor_graceful_restart_local_mode(struct vty *vty, const char *mode = "Invalid"; if (!use_json) - vty_out(vty, " Local GR Mode : "); + vty_out(vty, " Local GR Mode: "); if (bgp_peer_gr_mode_get(p) == PEER_HELPER) mode = "Helper"; @@ -9570,10 +9570,10 @@ static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi( eor_flag = false; if (!use_json) { - vty_out(vty, " %s :\n", + vty_out(vty, " %s:\n", get_afi_safi_str(afi, safi, false)); - vty_out(vty, " F bit : "); + vty_out(vty, " F bit: "); } if (peer->nsf[afi][safi] @@ -9594,27 +9594,7 @@ static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi( } if (!use_json) - vty_out(vty, " End-of-RIB Received : "); - - if (CHECK_FLAG(peer->af_sflags[afi][safi], - PEER_STATUS_EOR_RECEIVED)) { - if (use_json) - json_object_boolean_true_add( - json_endofrib_status, - "endOfRibRecv"); - else - vty_out(vty, "Yes\n"); - } else { - if (use_json) - json_object_boolean_false_add( - json_endofrib_status, - "endOfRibRecv"); - else - vty_out(vty, "No\n"); - } - - if (!use_json) - vty_out(vty, " End-of-RIB Send : "); + vty_out(vty, " End-of-RIB sent: "); if (CHECK_FLAG(peer->af_sflags[afi][safi], PEER_STATUS_EOR_SEND)) { @@ -9627,7 +9607,7 @@ static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi( } else { vty_out(vty, "Yes\n"); vty_out(vty, - " EoRSentAfterUpdate : "); + " End-of-RIB sent after update: "); PRINT_EOR(eor_flag); } @@ -9642,11 +9622,31 @@ static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi( } else { vty_out(vty, "No\n"); vty_out(vty, - " EoRSentAfterUpdate : "); + " End-of-RIB sent after update: "); vty_out(vty, "No\n"); } } + if (!use_json) + vty_out(vty, " End-of-RIB received: "); + + if (CHECK_FLAG(peer->af_sflags[afi][safi], + PEER_STATUS_EOR_RECEIVED)) { + if (use_json) + json_object_boolean_true_add( + json_endofrib_status, + "endOfRibRecv"); + else + vty_out(vty, "Yes\n"); + } else { + if (use_json) + json_object_boolean_false_add( + json_endofrib_status, + "endOfRibRecv"); + else + vty_out(vty, "No\n"); + } + if (use_json) { json_object_int_add(json_timer, "stalePathTimer", @@ -9686,46 +9686,36 @@ static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi( .t_select_deferral)); } } else { - vty_out(vty, " Timers:\n"); - - vty_out(vty, "%*s", 6, ""); + vty_out(vty, " Timers:\n"); vty_out(vty, - "Configured Stale Path Time(sec)%*s: %u\n", - 8, "", peer->bgp->stalepath_time); + " Configured Stale Path Time(sec): %u\n", + peer->bgp->stalepath_time); - if (peer->t_gr_stale != NULL) { - vty_out(vty, "%*s", 6, ""); + if (peer->t_gr_stale != NULL) vty_out(vty, - "Stale Path Remaining(sec)%*s: %ld\n", - 14, "", + " Stale Path Remaining(sec): %ld\n", thread_timer_remain_second( peer->t_gr_stale)); - } /* Display Configured Selection * Deferral only when when * Gr mode is enabled. */ if (CHECK_FLAG(peer->flags, - PEER_FLAG_GRACEFUL_RESTART)) { - vty_out(vty, "%*s", 6, ""); + PEER_FLAG_GRACEFUL_RESTART)) vty_out(vty, - "Configured Selection Deferral Time(sec): %u\n", + " Configured Selection Deferral Time(sec): %u\n", peer->bgp->select_defer_time); - } if (peer->bgp->gr_info[afi][safi] .t_select_deferral - != NULL) { - - vty_out(vty, "%*s", 6, ""); + != NULL) vty_out(vty, - "Selection Deferral Time Remaining(sec) : %ld\n", + " Selection Deferral Time Remaining(sec): %ld\n", thread_timer_remain_second( peer->bgp ->gr_info[afi] [safi] .t_select_deferral)); - } } if (use_json) { json_object_object_add(json_afi_safi, @@ -9765,19 +9755,17 @@ static void bgp_show_neighbor_graceful_restart_time(struct vty *vty, json_object_object_add(json, "timers", json_timer); } else { - vty_out(vty, " Timers :\n"); - vty_out(vty, " Configured Restart Time(sec) : %u\n", + vty_out(vty, " Timers:\n"); + vty_out(vty, " Configured Restart Time(sec): %u\n", p->bgp->restart_time); - vty_out(vty, " Received Restart Time(sec) : %u\n", + vty_out(vty, " Received Restart Time(sec): %u\n", p->v_gr_restart); if (p->t_gr_restart != NULL) - vty_out(vty, - " Restart Time Remaining(sec) : %ld\n", + vty_out(vty, " Restart Time Remaining(sec): %ld\n", thread_timer_remain_second(p->t_gr_restart)); if (p->t_gr_restart != NULL) { - vty_out(vty, - " Restart Time Remaining(sec) : %ld\n", + vty_out(vty, " Restart Time Remaining(sec): %ld\n", thread_timer_remain_second(p->t_gr_restart)); } } diff --git a/doc/user/routemap.rst b/doc/user/routemap.rst index 435639c291..8526b0f984 100644 --- a/doc/user/routemap.rst +++ b/doc/user/routemap.rst @@ -346,6 +346,27 @@ Route Map Exit Action Command Proceed processing the route-map at the first entry whose order is >= N +.. _route-map-optimization-command: + +Route Map Optimization Command +============================== + +.. index:: route-map optimization +.. clicmd:: route-map optimization + + Enable route-map processing optimization. The optimization is + enabled by default. + Instead of sequentially passing through all the route-map indexes + until a match is found, the search for the best-match index will be + based on a look-up in a prefix-tree. A per-route-map prefix-tree + will be constructed for this purpose. The prefix-tree will compose + of all the prefixes in all the prefix-lists that are included in the + match rule of all the sequences of a route-map. + +.. index:: no route-map optimization +.. clicmd:: no route-map optimization + + Disable the route-map processing optimization. Route Map Examples ================== diff --git a/isisd/isis_circuit.c b/isisd/isis_circuit.c index 8343f7d85f..e4152a8712 100644 --- a/isisd/isis_circuit.c +++ b/isisd/isis_circuit.c @@ -1386,7 +1386,6 @@ int isis_if_delete_hook(struct interface *ifp) if (ifp && ifp->info) { circuit = ifp->info; isis_csm_state_change(IF_DOWN_FROM_Z, circuit, circuit->area); - isis_csm_state_change(ISIS_DISABLE, circuit, circuit->area); } return 0; diff --git a/lib/ipaddr.h b/lib/ipaddr.h index 6bd614044c..c6372f1abb 100644 --- a/lib/ipaddr.h +++ b/lib/ipaddr.h @@ -119,10 +119,13 @@ static inline void ipv4_mapped_ipv6_to_ipv4(struct in6_addr *in6, memcpy(in, (char *)in6 + 12, sizeof(struct in_addr)); } +/* + * Check if a struct ipaddr has nonzero value + */ static inline bool ipaddr_isset(struct ipaddr *ip) { static struct ipaddr a = {}; - return (0 == memcmp(&a, ip, sizeof(struct ipaddr))); + return (0 != memcmp(&a, ip, sizeof(struct ipaddr))); } #ifdef __cplusplus diff --git a/lib/plist.c b/lib/plist.c index 662221beec..2a3a087cf0 100644 --- a/lib/plist.c +++ b/lib/plist.c @@ -303,6 +303,8 @@ static void prefix_list_delete(struct prefix_list *plist) /* If prefix-list contain prefix_list_entry free all of it. */ for (pentry = plist->head; pentry; pentry = next) { + route_map_notify_pentry_dependencies(plist->name, pentry, + RMAP_EVENT_PLIST_DELETED); next = pentry->next; prefix_list_trie_del(plist, pentry); prefix_list_entry_free(pentry); @@ -518,6 +520,8 @@ static void prefix_list_entry_delete(struct prefix_list *plist, else plist->tail = pentry->prev; + route_map_notify_pentry_dependencies(plist->name, pentry, + RMAP_EVENT_PLIST_DELETED); prefix_list_entry_free(pentry); plist->count--; @@ -631,6 +635,9 @@ static void prefix_list_entry_add(struct prefix_list *plist, /* Increment count. */ plist->count++; + route_map_notify_pentry_dependencies(plist->name, pentry, + RMAP_EVENT_PLIST_ADDED); + /* Run hook function. */ if (plist->master->add_hook) (*plist->master->add_hook)(plist); diff --git a/lib/routemap.c b/lib/routemap.c index e214aa43b7..54b5383173 100644 --- a/lib/routemap.c +++ b/lib/routemap.c @@ -31,6 +31,7 @@ #include "hash.h" #include "libfrr.h" #include "lib_errors.h" +#include "table.h" DEFINE_MTYPE_STATIC(LIB, ROUTE_MAP, "Route map") DEFINE_MTYPE(LIB, ROUTE_MAP_NAME, "Route map name") @@ -44,12 +45,52 @@ DEFINE_MTYPE_STATIC(LIB, ROUTE_MAP_DEP_DATA, "Route map dependency data") DEFINE_QOBJ_TYPE(route_map_index) DEFINE_QOBJ_TYPE(route_map) +#define IPv4_PREFIX_LIST "ip address prefix-list" +#define IPv6_PREFIX_LIST "ipv6 address prefix-list" +#define IPv4_MATCH_RULE "ip " +#define IPv6_MATCH_RULE "ipv6 " + +#define IS_RULE_IPv4_PREFIX_LIST(S) \ + (strncmp(S, IPv4_PREFIX_LIST, strlen(IPv4_PREFIX_LIST)) == 0) +#define IS_RULE_IPv6_PREFIX_LIST(S) \ + (strncmp(S, IPv6_PREFIX_LIST, strlen(IPv6_PREFIX_LIST)) == 0) + +#define IS_IPv4_RULE(S) \ + (strncmp(S, IPv4_MATCH_RULE, strlen(IPv4_MATCH_RULE)) == 0) +#define IS_IPv6_RULE(S) \ + (strncmp(S, IPv6_MATCH_RULE, strlen(IPv6_MATCH_RULE)) == 0) +struct route_map_pentry_dep { + struct prefix_list_entry *pentry; + const char *plist_name; + route_map_event_t event; +}; + /* Vector for route match rules. */ static vector route_match_vec; /* Vector for route set rules. */ static vector route_set_vec; +static void route_map_pfx_tbl_update(route_map_event_t event, + struct route_map_index *index, afi_t afi, + const char *plist_name); +static void route_map_pfx_table_add_default(afi_t afi, + struct route_map_index *index); +static void route_map_pfx_table_del_default(afi_t afi, + struct route_map_index *index); +static void route_map_add_plist_entries(afi_t afi, + struct route_map_index *index, + const char *plist_name, + struct prefix_list_entry *entry); +static void route_map_del_plist_entries(afi_t afi, + struct route_map_index *index, + const char *plist_name, + struct prefix_list_entry *entry); +static bool route_map_is_ip_rule_present(struct route_map_index *index); +static bool route_map_is_ipv6_rule_present(struct route_map_index *index); + +static struct hash *route_map_get_dep_hash(route_map_event_t event); + struct route_map_match_set_hooks rmap_match_set_hook; /* match interface */ @@ -566,6 +607,12 @@ static struct route_map *route_map_add(const char *name) route_map_notify_dependencies(name, RMAP_EVENT_CALL_ADDED); } + if (!map->ipv4_prefix_table) + map->ipv4_prefix_table = route_table_init(); + + if (!map->ipv6_prefix_table) + map->ipv6_prefix_table = route_table_init(); + if (rmap_debug) zlog_debug("Add route-map %s", name); return map; @@ -786,8 +833,9 @@ static void vty_show_route_map_entry(struct vty *vty, struct route_map *map) struct route_map_index *index; struct route_map_rule *rule; - vty_out(vty, "route-map: %s Invoked: %" PRIu64 "\n", - map->name, map->applied - map->applied_clear); + vty_out(vty, "route-map: %s Invoked: %" PRIu64 " Optimization: %s\n", + map->name, map->applied - map->applied_clear, + map->optimization_disabled ? "disabled" : "enabled"); for (index = map->head; index; index = index->next) { vty_out(vty, " %s, sequence %d Invoked %" PRIu64 "\n", @@ -928,8 +976,17 @@ void route_map_index_delete(struct route_map_index *index, int notify) routemap_hook_context_free(rhc); /* Free route match. */ - while ((rule = index->match_list.head) != NULL) + while ((rule = index->match_list.head) != NULL) { + if (IS_RULE_IPv4_PREFIX_LIST(rule->cmd->str)) + route_map_pfx_tbl_update(RMAP_EVENT_PLIST_DELETED, + index, AFI_IP, rule->rule_str); + else if (IS_RULE_IPv6_PREFIX_LIST(rule->cmd->str)) + route_map_pfx_tbl_update(RMAP_EVENT_PLIST_DELETED, + index, AFI_IP6, + rule->rule_str); + route_map_rule_delete(&index->match_list, rule); + } /* Free route set. */ while ((rule = index->set_list.head) != NULL) @@ -949,6 +1006,8 @@ void route_map_index_delete(struct route_map_index *index, int notify) /* Free 'char *nextrm' if not NULL */ XFREE(MTYPE_ROUTE_MAP_NAME, index->nextrm); + route_map_pfx_tbl_update(RMAP_EVENT_INDEX_DELETED, index, 0, NULL); + /* Execute event hook. */ if (route_map_master.event_hook && notify) { (*route_map_master.event_hook)(index->map->name); @@ -1008,6 +1067,8 @@ route_map_index_add(struct route_map *map, enum route_map_type type, int pref) point->prev = index; } + route_map_pfx_tbl_update(RMAP_EVENT_INDEX_ADDED, index, 0, NULL); + /* Execute event hook. */ if (route_map_master.event_hook) { (*route_map_master.event_hook)(map->name); @@ -1255,6 +1316,19 @@ enum rmap_compile_rets route_map_add_match(struct route_map_index *index, return RMAP_COMPILE_SUCCESS; } + /* If IPv4 or IPv6 prefix-list match criteria + * has been delete to the route-map index, update + * the route-map's prefix table. + */ + if (IS_RULE_IPv4_PREFIX_LIST(match_name)) + route_map_pfx_tbl_update( + RMAP_EVENT_PLIST_DELETED, index, AFI_IP, + rule->rule_str); + else if (IS_RULE_IPv6_PREFIX_LIST(match_name)) + route_map_pfx_tbl_update( + RMAP_EVENT_PLIST_DELETED, index, + AFI_IP6, rule->rule_str); + /* Remove the dependency of the route-map on the rule * that is being replaced. */ @@ -1283,6 +1357,38 @@ enum rmap_compile_rets route_map_add_match(struct route_map_index *index, /* Add new route match rule to linked list. */ route_map_rule_add(&index->match_list, rule); + /* If IPv4 or IPv6 prefix-list match criteria + * has been added to the route-map index, update + * the route-map's prefix table. + */ + if (IS_RULE_IPv4_PREFIX_LIST(match_name)) { + route_map_pfx_tbl_update(RMAP_EVENT_PLIST_ADDED, index, AFI_IP, + match_arg); + } else if (IS_RULE_IPv6_PREFIX_LIST(match_name)) { + route_map_pfx_tbl_update(RMAP_EVENT_PLIST_ADDED, index, AFI_IP6, + match_arg); + } else { + /* If IPv4 match criteria has been added to the route-map + * index, check for IPv6 prefix-list match rule presence and + * remove this index from the trie node created for each of the + * prefix-entry within the prefix-list. If no IPv6 prefix-list + * match rule is present, remove this index from the IPv6 + * default route's trie node. + */ + if (IS_IPv4_RULE(match_name)) + route_map_del_plist_entries(AFI_IP6, index, NULL, NULL); + + /* If IPv6 match criteria has been added to the route-map + * index, check for IPv4 prefix-list match rule presence and + * remove this index from the trie node created for each of the + * prefix-entry within the prefix-list. If no IPv4 prefix-list + * match rule is present, remove this index from the IPv4 + * default route's trie node. + */ + else if (IS_IPv6_RULE(match_name)) + route_map_del_plist_entries(AFI_IP, index, NULL, NULL); + } + /* Execute event hook. */ if (route_map_master.event_hook) { (*route_map_master.event_hook)(index->map->name); @@ -1330,6 +1436,45 @@ enum rmap_compile_rets route_map_delete_match(struct route_map_index *index, index->map->name); route_map_rule_delete(&index->match_list, rule); + + /* If IPv4 or IPv6 prefix-list match criteria + * has been delete to the route-map index, update + * the route-map's prefix table. + */ + if (IS_RULE_IPv4_PREFIX_LIST(match_name)) { + route_map_pfx_tbl_update( + RMAP_EVENT_PLIST_DELETED, index, AFI_IP, + match_arg); + } else if (IS_RULE_IPv6_PREFIX_LIST(match_name)) { + route_map_pfx_tbl_update( + RMAP_EVENT_PLIST_DELETED, index, + AFI_IP6, match_arg); + } else { + /* If no more IPv4 match rules are present in + * this index, check for IPv6 prefix-list match + * rule presence and add this index to trie node + * created for each of the prefix-entry within + * the prefix-list. If no IPv6 prefix-list match + * rule is present, add this index to the IPv6 + * default route's trie node. + */ + if (!route_map_is_ip_rule_present(index)) + route_map_add_plist_entries( + AFI_IP6, index, NULL, NULL); + + /* If no more IPv6 match rules are present in + * this index, check for IPv4 prefix-list match + * rule presence and add this index to trie node + * created for each of the prefix-entry within + * the prefix-list. If no IPv6 prefix-list match + * rule is present, add this index to the IPv4 + * default route's trie node. + */ + if (!route_map_is_ipv6_rule_present(index)) + route_map_add_plist_entries( + AFI_IP, index, NULL, NULL); + } + return RMAP_COMPILE_SUCCESS; } /* Can't find matched rule. */ @@ -1495,6 +1640,705 @@ route_map_apply_match(struct route_map_rule_list *match_list, return ret; } +static struct list *route_map_get_index_list(struct route_node **rn, + const struct prefix *prefix, + struct route_table *table) +{ + struct route_node *tmp_rn = NULL; + + if (!(*rn)) { + *rn = route_node_match(table, prefix); + + if (!(*rn)) + return NULL; + + if ((*rn)->info) + return (struct list *)((*rn)->info); + + /* If rn->info is NULL, get the parent. + * Store the rn in tmp_rn and unlock it later. + */ + tmp_rn = *rn; + } + + do { + *rn = (*rn)->parent; + if (tmp_rn) + route_unlock_node(tmp_rn); + + if (!(*rn)) + break; + + if ((*rn)->info) { + route_lock_node(*rn); + return (struct list *)((*rn)->info); + } + } while (!(*rn)->info); + + return NULL; +} + +/* + * This function returns the route-map index that best matches the prefix. + */ +static struct route_map_index * +route_map_get_index(struct route_map *map, const struct prefix *prefix, + route_map_object_t type, void *object, uint8_t *match_ret) +{ + int ret = 0; + struct list *candidate_rmap_list = NULL; + struct route_node *rn = NULL; + struct listnode *ln = NULL, *nn = NULL; + struct route_map_index *index = NULL, *best_index = NULL; + struct route_map_index *head_index = NULL; + struct route_table *table = NULL; + unsigned char family = prefix->family; + + if (family == AF_INET) + table = map->ipv4_prefix_table; + else + table = map->ipv6_prefix_table; + + if (!table) + return NULL; + + do { + candidate_rmap_list = + route_map_get_index_list(&rn, prefix, table); + if (!rn) + break; + + /* If the index at the head of the list is of seq higher + * than that in best_index, ignore the list and get the + * parent node's list. + */ + head_index = (struct route_map_index *)(listgetdata( + listhead(candidate_rmap_list))); + if (best_index && head_index + && (best_index->pref < head_index->pref)) { + route_unlock_node(rn); + continue; + } + + for (ALL_LIST_ELEMENTS(candidate_rmap_list, ln, nn, index)) { + /* If the index is of seq higher than that in + * best_index, ignore the list and get the parent + * node's list. + */ + if (best_index && (best_index->pref < index->pref)) + break; + + ret = route_map_apply_match(&index->match_list, prefix, + type, object); + + if (ret == RMAP_MATCH) { + *match_ret = ret; + best_index = index; + break; + } else if (ret == RMAP_NOOP) { + /* + * If match_ret is denymatch, even if we see + * more noops, we retain this return value and + * return this eventually if there are no + * matches. + */ + if (*match_ret != RMAP_NOMATCH) + *match_ret = ret; + } else { + /* + * ret is RMAP_NOMATCH. + */ + *match_ret = ret; + } + } + + route_unlock_node(rn); + + } while (rn); + + return best_index; +} + +static int route_map_candidate_list_cmp(struct route_map_index *idx1, + struct route_map_index *idx2) +{ + if (!idx1) + return -1; + if (!idx2) + return 1; + + return (idx1->pref - idx2->pref); +} + +/* + * This function adds the route-map index into the default route's + * route-node in the route-map's IPv4/IPv6 prefix-table. + */ +static void route_map_pfx_table_add_default(afi_t afi, + struct route_map_index *index) +{ + struct route_node *rn = NULL; + struct list *rmap_candidate_list = NULL; + struct prefix p; + bool updated_rn = false; + struct route_table *table = NULL; + + memset(&p, 0, sizeof(p)); + p.family = afi2family(afi); + p.prefixlen = 0; + + if (p.family == AF_INET) { + table = index->map->ipv4_prefix_table; + if (!table) + index->map->ipv4_prefix_table = route_table_init(); + + table = index->map->ipv4_prefix_table; + } else { + table = index->map->ipv6_prefix_table; + if (!table) + index->map->ipv6_prefix_table = route_table_init(); + + table = index->map->ipv6_prefix_table; + } + + /* Add default route to table */ + rn = route_node_get(table, &p); + + if (!rn) + return; + + if (!rn->info) { + rmap_candidate_list = list_new(); + rmap_candidate_list->cmp = + (int (*)(void *, void *))route_map_candidate_list_cmp; + rn->info = rmap_candidate_list; + } else { + rmap_candidate_list = (struct list *)rn->info; + updated_rn = true; + } + + listnode_add_sort_nodup(rmap_candidate_list, index); + if (updated_rn) + route_unlock_node(rn); +} + +/* + * This function removes the route-map index from the default route's + * route-node in the route-map's IPv4/IPv6 prefix-table. + */ +static void route_map_pfx_table_del_default(afi_t afi, + struct route_map_index *index) +{ + struct route_node *rn = NULL; + struct list *rmap_candidate_list = NULL; + struct prefix p; + struct route_table *table = NULL; + + memset(&p, 0, sizeof(p)); + p.family = afi2family(afi); + p.prefixlen = 0; + + if (p.family == AF_INET) + table = index->map->ipv4_prefix_table; + else + table = index->map->ipv6_prefix_table; + + /* Remove RMAP index from default route in table */ + rn = route_node_lookup(table, &p); + if (!rn || !rn->info) + return; + + rmap_candidate_list = (struct list *)rn->info; + + listnode_delete(rmap_candidate_list, index); + + if (listcount(rmap_candidate_list) == 0) { + list_delete(&rmap_candidate_list); + rn->info = NULL; + route_unlock_node(rn); + } + route_unlock_node(rn); +} + +/* + * This function adds the route-map index to the route-node for + * the prefix-entry in the route-map's IPv4/IPv6 prefix-table. + */ +static void route_map_pfx_table_add(struct route_table *table, + struct route_map_index *index, + struct prefix_list_entry *pentry) +{ + struct route_node *rn = NULL; + struct list *rmap_candidate_list = NULL; + bool updated_rn = false; + + rn = route_node_get(table, &pentry->prefix); + if (!rn) + return; + + if (!rn->info) { + rmap_candidate_list = list_new(); + rmap_candidate_list->cmp = + (int (*)(void *, void *))route_map_candidate_list_cmp; + rn->info = rmap_candidate_list; + } else { + rmap_candidate_list = (struct list *)rn->info; + updated_rn = true; + } + + listnode_add_sort_nodup(rmap_candidate_list, index); + if (updated_rn) + route_unlock_node(rn); +} + +/* + * This function removes the route-map index from the route-node for + * the prefix-entry in the route-map's IPv4/IPv6 prefix-table. + */ +static void route_map_pfx_table_del(struct route_table *table, + struct route_map_index *index, + struct prefix_list_entry *pentry) +{ + struct route_node *rn = NULL; + struct list *rmap_candidate_list = NULL; + + rn = route_node_lookup(table, &pentry->prefix); + if (!rn || !rn->info) + return; + + rmap_candidate_list = (struct list *)rn->info; + + listnode_delete(rmap_candidate_list, index); + + if (listcount(rmap_candidate_list) == 0) { + list_delete(&rmap_candidate_list); + rn->info = NULL; + route_unlock_node(rn); + } + route_unlock_node(rn); +} + +/* This function checks for the presence of an IPv4 match rule + * in the given route-map index. + */ +static bool route_map_is_ip_rule_present(struct route_map_index *index) +{ + struct route_map_rule_list *match_list = NULL; + struct route_map_rule *rule = NULL; + + match_list = &index->match_list; + for (rule = match_list->head; rule; rule = rule->next) + if (IS_IPv4_RULE(rule->cmd->str)) + return true; + + return false; +} + +/* This function checks for the presence of an IPv6 match rule + * in the given route-map index. + */ +static bool route_map_is_ipv6_rule_present(struct route_map_index *index) +{ + struct route_map_rule_list *match_list = NULL; + struct route_map_rule *rule = NULL; + + match_list = &index->match_list; + for (rule = match_list->head; rule; rule = rule->next) + if (IS_IPv6_RULE(rule->cmd->str)) + return true; + + return false; +} + +/* This function does the following: + * 1) If plist_name is not present, search for a IPv4 or IPv6 prefix-list + * match clause (based on the afi passed to this foo) and get the + * prefix-list name. + * 2) Look up the prefix-list using the name. + * 3) If the prefix-list is not found then, add the index to the IPv4/IPv6 + * default-route's node in the trie (based on the afi passed to this foo). + * 4) If the prefix-list is found then, remove the index from the IPv4/IPv6 + * default-route's node in the trie (based on the afi passed to this foo). + * 5) If a prefix-entry is passed then, create a route-node for this entry and + * add this index to the route-node. + * 6) If prefix-entry is not passed then, for every prefix-entry in the + * prefix-list, create a route-node for this entry and + * add this index to the route-node. + */ +static void route_map_add_plist_entries(afi_t afi, + struct route_map_index *index, + const char *plist_name, + struct prefix_list_entry *entry) +{ + struct route_map_rule_list *match_list = NULL; + struct route_map_rule *match = NULL; + struct prefix_list *plist = NULL; + struct prefix_list_entry *pentry = NULL; + bool plist_rule_is_present = false; + + if (!plist_name) { + match_list = &index->match_list; + + for (match = match_list->head; match; match = match->next) { + if (afi == AFI_IP) { + if (IS_RULE_IPv4_PREFIX_LIST(match->cmd->str)) { + plist_rule_is_present = true; + break; + } + } else { + if (IS_RULE_IPv6_PREFIX_LIST(match->cmd->str)) { + plist_rule_is_present = true; + break; + } + } + } + + if (plist_rule_is_present) + plist = prefix_list_lookup(afi, match->rule_str); + } else { + plist = prefix_list_lookup(afi, plist_name); + } + + if (!plist) { + route_map_pfx_table_add_default(afi, index); + return; + } + + route_map_pfx_table_del_default(afi, index); + + if (entry) { + if (afi == AFI_IP) { + route_map_pfx_table_add(index->map->ipv4_prefix_table, + index, entry); + } else { + route_map_pfx_table_add(index->map->ipv6_prefix_table, + index, entry); + } + } else { + for (pentry = plist->head; pentry; pentry = pentry->next) { + if (afi == AFI_IP) { + route_map_pfx_table_add( + index->map->ipv4_prefix_table, index, + pentry); + } else { + route_map_pfx_table_add( + index->map->ipv6_prefix_table, index, + pentry); + } + } + } +} + +/* This function does the following: + * 1) If plist_name is not present, search for a IPv4 or IPv6 prefix-list + * match clause (based on the afi passed to this foo) and get the + * prefix-list name. + * 2) Look up the prefix-list using the name. + * 3) If the prefix-list is not found then, delete the index from the IPv4/IPv6 + * default-route's node in the trie (based on the afi passed to this foo). + * 4) If a prefix-entry is passed then, remove this index from the route-node + * for the prefix in this prefix-entry. + * 5) If prefix-entry is not passed then, for every prefix-entry in the + * prefix-list, remove this index from the route-node + * for the prefix in this prefix-entry. + */ +static void route_map_del_plist_entries(afi_t afi, + struct route_map_index *index, + const char *plist_name, + struct prefix_list_entry *entry) +{ + struct route_map_rule_list *match_list = NULL; + struct route_map_rule *match = NULL; + struct prefix_list *plist = NULL; + struct prefix_list_entry *pentry = NULL; + bool plist_rule_is_present = false; + + if (!plist_name) { + match_list = &index->match_list; + + for (match = match_list->head; match; match = match->next) { + if (afi == AFI_IP) { + if (IS_RULE_IPv4_PREFIX_LIST(match->cmd->str)) { + plist_rule_is_present = true; + break; + } + } else { + if (IS_RULE_IPv6_PREFIX_LIST(match->cmd->str)) { + plist_rule_is_present = true; + break; + } + } + } + + if (plist_rule_is_present) + plist = prefix_list_lookup(afi, match->rule_str); + } else { + plist = prefix_list_lookup(afi, plist_name); + } + + if (!plist) { + route_map_pfx_table_del_default(afi, index); + return; + } + + if (entry) { + if (afi == AFI_IP) { + route_map_pfx_table_del(index->map->ipv4_prefix_table, + index, entry); + } else { + route_map_pfx_table_del(index->map->ipv6_prefix_table, + index, entry); + } + } else { + for (pentry = plist->head; pentry; pentry = pentry->next) { + if (afi == AFI_IP) { + route_map_pfx_table_del( + index->map->ipv4_prefix_table, index, + pentry); + } else { + route_map_pfx_table_del( + index->map->ipv6_prefix_table, index, + pentry); + } + } + } +} + +/* + * This function handles the cases where a prefix-list is added/removed + * as a match command from a particular route-map index. + * It updates the prefix-table of the route-map accordingly. + */ +static void route_map_trie_update(afi_t afi, route_map_event_t event, + struct route_map_index *index, + const char *plist_name) +{ + if (event == RMAP_EVENT_PLIST_ADDED) { + if (afi == AFI_IP) { + if (!route_map_is_ipv6_rule_present(index)) { + route_map_pfx_table_del_default(AFI_IP6, index); + route_map_add_plist_entries(afi, index, + plist_name, NULL); + } else { + route_map_del_plist_entries(AFI_IP6, index, + NULL, NULL); + } + } else { + if (!route_map_is_ip_rule_present(index)) { + route_map_pfx_table_del_default(AFI_IP, index); + route_map_add_plist_entries(afi, index, + plist_name, NULL); + } else { + route_map_del_plist_entries(AFI_IP, index, NULL, + NULL); + } + } + } else if (event == RMAP_EVENT_PLIST_DELETED) { + if (afi == AFI_IP) { + route_map_del_plist_entries(afi, index, plist_name, + NULL); + + if (!route_map_is_ipv6_rule_present(index)) + route_map_pfx_table_add_default(afi, index); + + if (!route_map_is_ip_rule_present(index)) + route_map_add_plist_entries(AFI_IP6, index, + NULL, NULL); + } else { + route_map_del_plist_entries(afi, index, plist_name, + NULL); + + if (!route_map_is_ip_rule_present(index)) + route_map_pfx_table_add_default(afi, index); + + if (!route_map_is_ipv6_rule_present(index)) + route_map_add_plist_entries(AFI_IP, index, NULL, + NULL); + } + } +} + +/* + * This function handles the cases where a route-map index and + * prefix-list is added/removed. + * It updates the prefix-table of the route-map accordingly. + */ +static void route_map_pfx_tbl_update(route_map_event_t event, + struct route_map_index *index, afi_t afi, + const char *plist_name) +{ + struct route_map *rmap = NULL; + + if (!index) + return; + + if (event == RMAP_EVENT_INDEX_ADDED) { + route_map_pfx_table_add_default(AFI_IP, index); + route_map_pfx_table_add_default(AFI_IP6, index); + return; + } + + if (event == RMAP_EVENT_INDEX_DELETED) { + route_map_pfx_table_del_default(AFI_IP, index); + route_map_pfx_table_del_default(AFI_IP6, index); + + if ((index->map->head == NULL) && (index->map->tail == NULL)) { + rmap = index->map; + + if (rmap->ipv4_prefix_table) { + route_table_finish(rmap->ipv4_prefix_table); + rmap->ipv4_prefix_table = NULL; + } + + if (rmap->ipv6_prefix_table) { + route_table_finish(rmap->ipv6_prefix_table); + rmap->ipv6_prefix_table = NULL; + } + } + return; + } + + /* Handle prefix-list match rule addition/deletion. + */ + route_map_trie_update(afi, event, index, plist_name); +} + +/* + * This function handles the cases where a new prefix-entry is added to + * a prefix-list or, an existing prefix-entry is removed from the prefix-list. + * It updates the prefix-table of the route-map accordingly. + */ +static void route_map_pentry_update(route_map_event_t event, + const char *plist_name, + struct route_map_index *index, + struct prefix_list_entry *pentry) +{ + struct prefix_list *plist = NULL; + afi_t afi; + unsigned char family = pentry->prefix.family; + + if (family == AF_INET) { + afi = AFI_IP; + plist = prefix_list_lookup(AFI_IP, plist_name); + } else { + afi = AFI_IP6; + plist = prefix_list_lookup(AFI_IP6, plist_name); + } + + if (event == RMAP_EVENT_PLIST_ADDED) { + if (plist->count == 1) { + if (afi == AFI_IP) { + if (!route_map_is_ipv6_rule_present(index)) + route_map_add_plist_entries( + afi, index, plist_name, pentry); + } else { + if (!route_map_is_ip_rule_present(index)) + route_map_add_plist_entries( + afi, index, plist_name, pentry); + } + } else { + route_map_add_plist_entries(afi, index, plist_name, + pentry); + } + } else if (event == RMAP_EVENT_PLIST_DELETED) { + route_map_del_plist_entries(afi, index, plist_name, pentry); + + if (plist->count == 1) { + if (afi == AFI_IP) { + if (!route_map_is_ipv6_rule_present(index)) + route_map_pfx_table_add_default(afi, + index); + } else { + if (!route_map_is_ip_rule_present(index)) + route_map_pfx_table_add_default(afi, + index); + } + } + } +} + +static void route_map_pentry_process_dependency(struct hash_backet *backet, + void *data) +{ + char *rmap_name = NULL; + struct route_map *rmap = NULL; + struct route_map_index *index = NULL; + struct route_map_rule_list *match_list = NULL; + struct route_map_rule *match = NULL; + struct route_map_dep_data *dep_data = NULL; + struct route_map_pentry_dep *pentry_dep = + (struct route_map_pentry_dep *)data; + unsigned char family = pentry_dep->pentry->prefix.family; + + dep_data = (struct route_map_dep_data *)backet->data; + if (!dep_data) + return; + + rmap_name = dep_data->rname; + rmap = route_map_lookup_by_name(rmap_name); + if (!rmap || !rmap->head) + return; + + for (index = rmap->head; index; index = index->next) { + match_list = &index->match_list; + + if (!match_list) + continue; + + for (match = match_list->head; match; match = match->next) { + if (strcmp(match->rule_str, pentry_dep->plist_name) + == 0) { + if (IS_RULE_IPv4_PREFIX_LIST(match->cmd->str) + && family == AF_INET) { + route_map_pentry_update( + pentry_dep->event, + pentry_dep->plist_name, index, + pentry_dep->pentry); + } else if (IS_RULE_IPv6_PREFIX_LIST( + match->cmd->str) + && family == AF_INET6) { + route_map_pentry_update( + pentry_dep->event, + pentry_dep->plist_name, index, + pentry_dep->pentry); + } + } + } + } +} + +void route_map_notify_pentry_dependencies(const char *affected_name, + struct prefix_list_entry *pentry, + route_map_event_t event) +{ + struct route_map_dep *dep = NULL; + struct hash *upd8_hash = NULL; + struct route_map_pentry_dep pentry_dep; + + if (!affected_name || !pentry) + return; + + upd8_hash = route_map_get_dep_hash(event); + if (!upd8_hash) + return; + + dep = (struct route_map_dep *)hash_get(upd8_hash, (void *)affected_name, + NULL); + if (dep) { + if (!dep->this_hash) + dep->this_hash = upd8_hash; + + memset(&pentry_dep, 0, sizeof(struct route_map_pentry_dep)); + pentry_dep.pentry = pentry; + pentry_dep.plist_name = affected_name; + pentry_dep.event = event; + + hash_iterate(dep->dep_rmap_hash, + route_map_pentry_process_dependency, + (void *)&pentry_dep); + } +} + /* Apply route map's each index to the object. The matrix for a route-map looks like this: @@ -1548,9 +2392,10 @@ route_map_result_t route_map_apply(struct route_map *map, static int recursion = 0; enum route_map_cmd_result_t match_ret = RMAP_NOMATCH; route_map_result_t ret = RMAP_PERMITMATCH; - struct route_map_index *index; - struct route_map_rule *set; + struct route_map_index *index = NULL; + struct route_map_rule *set = NULL; char buf[PREFIX_STRLEN]; + bool skip_match_clause = false; if (recursion > RMAP_RECURSION_LIMIT) { flog_warn( @@ -1567,18 +2412,55 @@ route_map_result_t route_map_apply(struct route_map *map, } map->applied++; - for (index = map->head; index; index = index->next) { - /* Apply this index. */ - index->applied++; - match_ret = route_map_apply_match(&index->match_list, prefix, - type, object); - - if (rmap_debug) { - zlog_debug("Route-map: %s, sequence: %d, prefix: %s, result: %s", - map->name, index->pref, - prefix2str(prefix, buf, sizeof(buf)), - route_map_cmd_result_str(match_ret)); + + if ((!map->optimization_disabled) + && (map->ipv4_prefix_table || map->ipv6_prefix_table)) { + index = route_map_get_index(map, prefix, type, object, + (uint8_t *)&match_ret); + if (index) { + if (rmap_debug) + zlog_debug( + "Best match route-map: %s, sequence: %d for pfx: %s, result: %s", + map->name, index->pref, + prefix2str(prefix, buf, sizeof(buf)), + route_map_cmd_result_str(match_ret)); + } else { + if (rmap_debug) + zlog_debug( + "No best match sequence for pfx: %s in route-map: %s, result: %s", + prefix2str(prefix, buf, sizeof(buf)), + map->name, + route_map_cmd_result_str(match_ret)); + /* + * No index matches this prefix. Return deny unless, + * match_ret = RMAP_NOOP. + */ + if (match_ret == RMAP_NOOP) + ret = RMAP_PERMITMATCH; + else + ret = RMAP_DENYMATCH; + goto route_map_apply_end; } + skip_match_clause = true; + } else { + index = map->head; + } + + for (; index; index = index->next) { + if (skip_match_clause == false) { + /* Apply this index. */ + match_ret = route_map_apply_match(&index->match_list, + prefix, type, object); + if (rmap_debug) { + zlog_debug( + "Route-map: %s, sequence: %d, prefix: %s, result: %s", + map->name, index->pref, + prefix2str(prefix, buf, sizeof(buf)), + route_map_cmd_result_str(match_ret)); + } + } else + skip_match_clause = false; + /* Now we apply the matrix from above */ if (match_ret == RMAP_NOOP) @@ -2026,8 +2908,30 @@ void route_map_notify_dependencies(const char *affected_name, XFREE(MTYPE_ROUTE_MAP_NAME, name); } - /* VTY related functions. */ +DEFUN(no_routemap_optimization, no_routemap_optimization_cmd, + "no route-map optimization", + NO_STR + "route-map\n" + "optimization\n") +{ + VTY_DECLVAR_CONTEXT(route_map_index, index); + + index->map->optimization_disabled = true; + return CMD_SUCCESS; +} + +DEFUN(routemap_optimization, routemap_optimization_cmd, + "route-map optimization", + "route-map\n" + "optimization\n") +{ + VTY_DECLVAR_CONTEXT(route_map_index, index); + + index->map->optimization_disabled = false; + return CMD_SUCCESS; +} + static void clear_route_map_helper(struct route_map *map) { struct route_map_index *index; @@ -2202,6 +3106,121 @@ void route_map_counter_decrement(struct route_map *map) } } +DEFUN_HIDDEN(show_route_map_pfx_tbl, show_route_map_pfx_tbl_cmd, + "show route-map WORD prefix-table", + SHOW_STR + "route-map\n" + "route-map name\n" + "internal prefix-table\n") +{ + const char *rmap_name = argv[2]->arg; + struct route_map *rmap = NULL; + struct route_table *rm_pfx_tbl4 = NULL; + struct route_table *rm_pfx_tbl6 = NULL; + struct route_node *rn = NULL, *prn = NULL; + struct list *rmap_index_list = NULL; + struct listnode *ln = NULL, *nln = NULL; + struct route_map_index *index = NULL; + struct prefix *p = NULL, *pp = NULL; + char buf[SU_ADDRSTRLEN], pbuf[SU_ADDRSTRLEN]; + uint8_t len = 54; + + vty_out(vty, "%s:\n", frr_protonameinst); + rmap = route_map_lookup_by_name(rmap_name); + if (rmap) { + rm_pfx_tbl4 = rmap->ipv4_prefix_table; + if (rm_pfx_tbl4) { + vty_out(vty, "\n%s%43s%s\n", "IPv4 Prefix", "", + "Route-map Index List"); + vty_out(vty, "%s%39s%s\n", "_______________", "", + "____________________"); + for (rn = route_top(rm_pfx_tbl4); rn; + rn = route_next(rn)) { + p = &rn->p; + + vty_out(vty, " %s/%d (%d)\n", + inet_ntop(p->family, &p->u.prefix, buf, + SU_ADDRSTRLEN), + p->prefixlen, rn->lock); + + vty_out(vty, "(P) "); + prn = rn->parent; + if (prn) { + pp = &prn->p; + vty_out(vty, "%s/%d\n", + inet_ntop(pp->family, + &pp->u.prefix, pbuf, + SU_ADDRSTRLEN), + pp->prefixlen); + } + + vty_out(vty, "\n"); + rmap_index_list = (struct list *)rn->info; + if (!rmap_index_list + || !listcount(rmap_index_list)) + vty_out(vty, "%*s%s\n", len, "", "-"); + else + for (ALL_LIST_ELEMENTS(rmap_index_list, + ln, nln, + index)) { + vty_out(vty, "%*s%s seq %d\n", + len, "", + index->map->name, + index->pref); + } + vty_out(vty, "\n"); + } + } + + rm_pfx_tbl6 = rmap->ipv6_prefix_table; + if (rm_pfx_tbl6) { + vty_out(vty, "\n%s%43s%s\n", "IPv6 Prefix", "", + "Route-map Index List"); + vty_out(vty, "%s%39s%s\n", "_______________", "", + "____________________"); + for (rn = route_top(rm_pfx_tbl6); rn; + rn = route_next(rn)) { + p = &rn->p; + + vty_out(vty, " %s/%d (%d)\n", + inet_ntop(p->family, &p->u.prefix, buf, + SU_ADDRSTRLEN), + p->prefixlen, rn->lock); + + vty_out(vty, "(P) "); + prn = rn->parent; + if (prn) { + pp = &prn->p; + vty_out(vty, "%s/%d\n", + inet_ntop(pp->family, + &pp->u.prefix, pbuf, + SU_ADDRSTRLEN), + pp->prefixlen); + } + + vty_out(vty, "\n"); + rmap_index_list = (struct list *)rn->info; + if (!rmap_index_list + || !listcount(rmap_index_list)) + vty_out(vty, "%*s%s\n", len, "", "-"); + else + for (ALL_LIST_ELEMENTS(rmap_index_list, + ln, nln, + index)) { + vty_out(vty, "%*s%s seq %d\n", + len, "", + index->map->name, + index->pref); + } + vty_out(vty, "\n"); + } + } + } + + vty_out(vty, "\n"); + return CMD_SUCCESS; +} + /* Initialization of route map vector. */ void route_map_init(void) { @@ -2238,4 +3257,9 @@ void route_map_init(void) install_element(ENABLE_NODE, &debug_rmap_cmd); install_element(ENABLE_NODE, &no_debug_rmap_cmd); + + install_element(RMAP_NODE, &routemap_optimization_cmd); + install_element(RMAP_NODE, &no_routemap_optimization_cmd); + + install_element(ENABLE_NODE, &show_route_map_pfx_tbl_cmd); } diff --git a/lib/routemap.h b/lib/routemap.h index 05c958967c..e8cab64b47 100644 --- a/lib/routemap.h +++ b/lib/routemap.h @@ -25,6 +25,8 @@ #include "memory.h" #include "qobj.h" #include "vty.h" +#include "lib/plist.h" +#include "lib/plist_int.h" #ifdef __cplusplus extern "C" { @@ -220,6 +222,7 @@ struct route_map { /* Maintain update info */ bool to_be_processed; /* True if modification isn't acted on yet */ bool deleted; /* If 1, then this node will be deleted */ + bool optimization_disabled; /* How many times have we applied this route-map */ uint64_t applied; @@ -228,6 +231,12 @@ struct route_map { /* Counter to track active usage of this route-map */ uint16_t use_count; + /* Tables to maintain IPv4 and IPv6 prefixes from + * the prefix-list match clause. + */ + struct route_table *ipv4_prefix_table; + struct route_table *ipv6_prefix_table; + QOBJ_FIELDS }; DECLARE_QOBJ_TYPE(route_map) @@ -310,7 +319,10 @@ extern void route_map_upd8_dependency(route_map_event_t type, const char *arg, const char *rmap_name); extern void route_map_notify_dependencies(const char *affected_name, route_map_event_t event); - +extern void +route_map_notify_pentry_dependencies(const char *affected_name, + struct prefix_list_entry *pentry, + route_map_event_t event); extern int generic_match_add(struct vty *vty, struct route_map_index *index, const char *command, const char *arg, route_map_event_t type); diff --git a/tests/topotests/bgp-route-map/test_route_map_topo1.py b/tests/topotests/bgp-route-map/test_route_map_topo1.py index 86ec6c82d2..22dd3a6380 100755 --- a/tests/topotests/bgp-route-map/test_route_map_topo1.py +++ b/tests/topotests/bgp-route-map/test_route_map_topo1.py @@ -71,7 +71,7 @@ from time import sleep # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) +sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers @@ -102,7 +102,7 @@ ADDR_TYPES = check_address_types() # Reading the data from JSON File for topology and configuration creation jsonFile = "{}/bgp_route_map_topo1.json".format(CWD) try: - with open(jsonFile, 'r') as topoJson: + with open(jsonFile, "r") as topoJson: topo = json.load(topoJson) except IOError: assert False, "Could not read file {}".format(jsonFile) @@ -442,11 +442,12 @@ def test_route_map_inbound_outbound_same_neighbor_p0(request): } } - result = verify_rib(tgen, adt, dut, input_dict_2, protocol=protocol) + result = verify_rib(tgen, adt, dut, input_dict_2, protocol=protocol, + expected=False) assert result is not True, "Testcase {} : Failed \n" - "Expected behavior: routes are not present in rib \n" - "Error: {}".format( + "routes are not present in rib \n Error: {}".format( tc_name, result) + logger.info("Expected behaviour: {}".format(result)) # Verifying RIB routes dut = "r4" @@ -461,11 +462,12 @@ def test_route_map_inbound_outbound_same_neighbor_p0(request): ] } } - result = verify_rib(tgen, adt, dut, input_dict, protocol=protocol) + result = verify_rib(tgen, adt, dut, input_dict, protocol=protocol, + expected=False) assert result is not True, "Testcase {} : Failed \n " - "Expected behavior: routes are not present in rib \n " - "Error: {}".format( + "routes are not present in rib \n Error: {}".format( tc_name, result) + logger.info("Expected behaviour: {}".format(result)) write_test_footer(tc_name) @@ -649,10 +651,14 @@ def test_route_map_with_action_values_combination_of_prefix_action_p0( } } - result = verify_rib(tgen, adt, dut, input_dict_2, protocol=protocol) + #tgen.mininet_cli() + result = verify_rib(tgen, adt, dut, input_dict_2, protocol=protocol, + expected=False) if "deny" in [prefix_action, rmap_action]: - assert result is not True, "Testcase {} : Failed \n Error: {}".\ + assert result is not True, "Testcase {} : Failed \n " + "Routes are still present \n Error: {}".\ format(tc_name, result) + logger.info("Expected behaviour: {}".format(result)) else: assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) diff --git a/tests/topotests/bgp-route-map/test_route_map_topo2.py b/tests/topotests/bgp-route-map/test_route_map_topo2.py index 7009fc97ce..f2398c33ff 100755 --- a/tests/topotests/bgp-route-map/test_route_map_topo2.py +++ b/tests/topotests/bgp-route-map/test_route_map_topo2.py @@ -32,17 +32,17 @@ TC_61: TC_50_1: Test modify/remove prefix-lists referenced by a route-map for match statement. -TC_50_1: +TC_50_2: Remove prefix-list referencec by route-map match cluase and verifying it reflecting as intended TC_51: Add and remove community-list referencec by route-map match cluase and verifying it reflecting as intended TC_45: - Test multiple match statements as part of a route-map's single + Test multiple match statements as part of a route-map"s single sequence number. (Logical OR-ed of multiple match statements) TC_44: - Test multiple match statements as part of a route-map's single + Test multiple match statements as part of a route-map"s single sequence number. (Logical AND of multiple match statements) TC_41: Test add/remove route-maps to specific neighbor and see if @@ -57,7 +57,7 @@ TC_48: Create route map setting local preference and weight to eBGP peeer and metric to ibgp peer and verifying it should not get advertised TC_43: - Test multiple set statements as part of a route-map's + Test multiple set statements as part of a route-map"s single sequence number. TC_54: Verify route-maps continue clause functionality. @@ -112,7 +112,7 @@ from time import sleep # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) +sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 # Import topogen and topotest helpers @@ -127,7 +127,8 @@ from lib.common_config import ( verify_rib, delete_route_maps, create_bgp_community_lists, interface_status, create_route_maps, create_prefix_lists, verify_route_maps, check_address_types, verify_bgp_community, - shutdown_bringup_interface, verify_prefix_lists, reset_config_on_routers) + shutdown_bringup_interface, verify_prefix_lists, reset_config_on_routers, + verify_create_community_list) from lib.topolog import logger from lib.bgp import ( verify_bgp_convergence, create_router_bgp, @@ -138,7 +139,7 @@ from lib.topojson import build_topo_from_json, build_config_from_json jsonFile = "{}/bgp_route_map_topo2.json".format(CWD) try: - with open(jsonFile, 'r') as topoJson: + with open(jsonFile, "r") as topoJson: topo = json.load(topoJson) except IOError: assert False, "Could not read file {}".format(jsonFile) @@ -198,14 +199,14 @@ def setup_module(mod): global bgp_convergence global ADDR_TYPES - # Don't run this test if we have any failure. + # 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 bgp_convergence = verify_bgp_convergence(tgen, topo) - assert bgp_convergence is True, ('setup_module :Failed \n Error:' - ' {}'.format(bgp_convergence)) + assert bgp_convergence is True, ("setup_module :Failed \n Error:" + " {}".format(bgp_convergence)) logger.info("Running setup_module() done") @@ -241,7 +242,7 @@ def test_rmap_match_prefix_list_permit_in_and_outbound_prefixes_p0(): global bgp_convergence if bgp_convergence is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = inspect.stack()[0][3] @@ -250,20 +251,20 @@ def test_rmap_match_prefix_list_permit_in_and_outbound_prefixes_p0(): # Create ip prefix list input_dict_2 = { - 'r3': { - 'prefix_lists': { - 'ipv4': { - 'pf_list_1_ipv4': [{ - 'seqid': 10, - 'network': 'any', - 'action': 'permit', + "r3": { + "prefix_lists": { + "ipv4": { + "pf_list_1_ipv4": [{ + "seqid": 10, + "network": "any", + "action": "permit", }] }, - 'ipv6': { - 'pf_list_1_ipv6': [{ - 'seqid': 10, - 'network': 'any', - 'action': 'permit', + "ipv6": { + "pf_list_1_ipv6": [{ + "seqid": 10, + "network": "any", + "action": "permit", }] } } @@ -271,7 +272,7 @@ def test_rmap_match_prefix_list_permit_in_and_outbound_prefixes_p0(): } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) for addr_type in ADDR_TYPES: # Create route map @@ -280,7 +281,7 @@ def test_rmap_match_prefix_list_permit_in_and_outbound_prefixes_p0(): "route_maps": { "rmap_match_pf_1_{}".format(addr_type): [{ "action": "permit", - 'seq_id': '5', + "seq_id": "5", "match": { addr_type: { "prefix_lists": "pf_list_1_" + addr_type @@ -294,7 +295,7 @@ def test_rmap_match_prefix_list_permit_in_and_outbound_prefixes_p0(): ], "rmap_match_pf_2_{}".format(addr_type): [{ "action": "permit", - 'seq_id': '5', + "seq_id": "5", "match": { addr_type: { "prefix_lists": "pf_list_1_" + addr_type @@ -309,12 +310,12 @@ def test_rmap_match_prefix_list_permit_in_and_outbound_prefixes_p0(): } } result = create_route_maps(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Configure neighbor for route map input_dict_4 = { - 'r3': { + "r3": { "bgp": { "address_family": { "ipv4": { @@ -326,7 +327,7 @@ def test_rmap_match_prefix_list_permit_in_and_outbound_prefixes_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv4", - "direction": 'in' + "direction": "in" }] } } @@ -337,7 +338,7 @@ def test_rmap_match_prefix_list_permit_in_and_outbound_prefixes_p0(): "route_maps": [{ "name": "rmap_match_pf_2_ipv4", - "direction": 'out' + "direction": "out" }] } } @@ -354,7 +355,7 @@ def test_rmap_match_prefix_list_permit_in_and_outbound_prefixes_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv6", - "direction": 'in' + "direction": "in" }] } } @@ -365,7 +366,7 @@ def test_rmap_match_prefix_list_permit_in_and_outbound_prefixes_p0(): "route_maps": [{ "name": "rmap_match_pf_2_ipv6", - "direction": 'out' + "direction": "out" }] } } @@ -379,23 +380,23 @@ def test_rmap_match_prefix_list_permit_in_and_outbound_prefixes_p0(): } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" input_dict = topo["routers"] # dual stack changes for addr_type in ADDR_TYPES: result4 = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result4 is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result4 is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result4) # Verifying BGP set attributes - dut = 'r3' + dut = "r3" routes = { "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], "ipv6": ["1::1/128", "1::2/128"] @@ -405,21 +406,21 @@ def test_rmap_match_prefix_list_permit_in_and_outbound_prefixes_p0(): rmap_name = "rmap_match_pf_1_{}".format(addr_type) result4 = verify_bgp_attributes(tgen, addr_type, dut, routes[ addr_type],rmap_name, input_dict_3) - assert result4 is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result4 is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result4) # Verifying RIB routes - dut = 'r4' - protocol = 'bgp' + dut = "r4" + protocol = "bgp" # dual stack changes for addr_type in ADDR_TYPES: result4 = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result4 is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result4 is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result4) # Verifying BGP set attributes - dut = 'r4' + dut = "r4" routes = { "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], "ipv6": ["1::1/128", "1::2/128"] @@ -429,7 +430,7 @@ def test_rmap_match_prefix_list_permit_in_and_outbound_prefixes_p0(): rmap_name = "rmap_match_pf_2_{}".format(addr_type) result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name) @@ -448,7 +449,7 @@ def test_modify_set_match_clauses_in_rmap_p0(): global bgp_convergence if bgp_convergence is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = inspect.stack()[0][3] @@ -458,37 +459,37 @@ def test_modify_set_match_clauses_in_rmap_p0(): # Create ip prefix list input_dict_2 = { - 'r3': { - 'prefix_lists': { - 'ipv4': { - 'pf_list_1_ipv4': [{ - 'seqid': 10, - 'network': 'any', - 'action': 'permit', + "r3": { + "prefix_lists": { + "ipv4": { + "pf_list_1_ipv4": [{ + "seqid": 10, + "network": "any", + "action": "permit", }], - 'pf_list_2_ipv4': [{ - 'seqid': 10, - 'network': 'any', - 'action': 'permit' + "pf_list_2_ipv4": [{ + "seqid": 10, + "network": "any", + "action": "permit" }] }, - 'ipv6': { - 'pf_list_1_ipv6': [{ - 'seqid': 10, - 'network': 'any', - 'action': 'permit', + "ipv6": { + "pf_list_1_ipv6": [{ + "seqid": 10, + "network": "any", + "action": "permit", }], - 'pf_list_2_ipv6': [{ - 'seqid': 10, - 'network': 'any', - 'action': 'permit' + "pf_list_2_ipv6": [{ + "seqid": 10, + "network": "any", + "action": "permit" }] } } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Create route map @@ -498,7 +499,7 @@ def test_modify_set_match_clauses_in_rmap_p0(): "route_maps": { "rmap_match_pf_1_{}".format(addr_type): [{ "action": "permit", - 'seq_id': '5', + "seq_id": "5", "match": { addr_type: { "prefix_lists": "pf_list_1_{}".format(addr_type) @@ -510,7 +511,7 @@ def test_modify_set_match_clauses_in_rmap_p0(): }], "rmap_match_pf_2_{}".format(addr_type): [{ "action": "permit", - 'seq_id': '5', + "seq_id": "5", "match": { addr_type: { "prefix_lists": "pf_list_1_{}".format(addr_type) @@ -524,12 +525,12 @@ def test_modify_set_match_clauses_in_rmap_p0(): } } result = create_route_maps(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Configure neighbor for route map input_dict_4 = { - 'r3': { + "r3": { "bgp": { "address_family": { "ipv4": { @@ -541,7 +542,7 @@ def test_modify_set_match_clauses_in_rmap_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv4", - "direction": 'in' + "direction": "in" }] } } @@ -552,7 +553,7 @@ def test_modify_set_match_clauses_in_rmap_p0(): "route_maps": [{ "name": "rmap_match_pf_2_ipv4", - "direction": 'out' + "direction": "out" }] } } @@ -569,7 +570,7 @@ def test_modify_set_match_clauses_in_rmap_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv6", - "direction": 'in' + "direction": "in" }] } } @@ -580,7 +581,7 @@ def test_modify_set_match_clauses_in_rmap_p0(): "route_maps": [{ "name": "rmap_match_pf_2_ipv6", - "direction": 'out' + "direction": "out" }] } } @@ -593,21 +594,21 @@ def test_modify_set_match_clauses_in_rmap_p0(): } } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" input_dict = topo["routers"] for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying BGP set attributes - dut = 'r3' + dut = "r3" routes = { "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], "ipv6": ["1::1/128", "1::2/128"] @@ -617,21 +618,21 @@ def test_modify_set_match_clauses_in_rmap_p0(): rmap_name = "rmap_match_pf_1_{}".format(addr_type) result4 = verify_bgp_attributes(tgen, addr_type, dut, routes[ addr_type],rmap_name, input_dict_3) - assert result4 is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result4 is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result4) # Verifying RIB routes - dut = 'r4' - protocol = 'bgp' + dut = "r4" + protocol = "bgp" # dual stack changes for addr_type in ADDR_TYPES: result4 = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result4 is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result4 is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result4) # Verifying BGP set attributes - dut = 'r4' + dut = "r4" routes = { "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], "ipv6": ["1::1/128", "1::2/128"] @@ -640,7 +641,7 @@ def test_modify_set_match_clauses_in_rmap_p0(): rmap_name = "rmap_match_pf_2_{}".format(addr_type) result = verify_bgp_attributes(tgen, addr_type, dut, routes[ addr_type],rmap_name, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Modify set/match clause of in-used route map @@ -650,7 +651,7 @@ def test_modify_set_match_clauses_in_rmap_p0(): "route_maps": { "rmap_match_pf_1_{}".format(addr_type): [{ "action": "permit", - 'seq_id': '5', + "seq_id": "5", "match": { addr_type: { "prefix_lists": "pf_list_1_{}".format(addr_type) @@ -662,7 +663,7 @@ def test_modify_set_match_clauses_in_rmap_p0(): }], "rmap_match_pf_2_{}".format(addr_type): [{ "action": "permit", - 'seq_id': '5', + "seq_id": "5", "match": { addr_type: { "prefix_lists": "pf_list_1_{}".format(addr_type) @@ -676,20 +677,20 @@ def test_modify_set_match_clauses_in_rmap_p0(): } } result = create_route_maps(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying BGP set attributes - dut = 'r3' + dut = "r3" routes = { "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], "ipv6": ["1::1/128", "1::2/128"] @@ -698,20 +699,20 @@ def test_modify_set_match_clauses_in_rmap_p0(): rmap_name = "rmap_match_pf_1_{}".format(addr_type) result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r4' - protocol = 'bgp' + dut = "r4" + protocol = "bgp" for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying BGP set attributes - dut = 'r4' + dut = "r4" routes = { "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], "ipv6": ["1::1/128", "1::2/128"] @@ -720,7 +721,7 @@ def test_modify_set_match_clauses_in_rmap_p0(): rmap_name = "rmap_match_pf_2_{}".format(addr_type) result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name) @@ -739,7 +740,7 @@ def test_delete_route_maps_p1(): global bgp_convergence if bgp_convergence is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = inspect.stack()[0][3] @@ -763,22 +764,22 @@ def test_delete_route_maps_p1(): } } result = create_route_maps(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Delete route maps for addr_type in ADDR_TYPES: input_dict = { - 'r3': { - 'route_maps': ['rmap_match_tag_1_{}'.format(addr_type)] + "r3": { + "route_maps": ["rmap_match_tag_1_{}".format(addr_type)] } } result = delete_route_maps(tgen, input_dict) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) result = verify_route_maps(tgen, input_dict) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name) @@ -797,7 +798,7 @@ def test_modify_prefix_list_referenced_by_rmap_p0(): global bgp_convergence if bgp_convergence is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = inspect.stack()[0][3] @@ -806,27 +807,27 @@ def test_modify_prefix_list_referenced_by_rmap_p0(): # Create ip prefix list input_dict_2 = { - 'r3': { - 'prefix_lists': { - 'ipv4': { - 'pf_list_1_ipv4': [{ - 'seqid': 10, - 'network': 'any', - 'action': 'permit', + "r3": { + "prefix_lists": { + "ipv4": { + "pf_list_1_ipv4": [{ + "seqid": 10, + "network": "any", + "action": "permit", }] }, - 'ipv6': { - 'pf_list_1_ipv6': [{ - 'seqid': 100, - 'network': 'any', - 'action': 'permit', + "ipv6": { + "pf_list_1_ipv6": [{ + "seqid": 100, + "network": "any", + "action": "permit", }] } } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Create route map @@ -836,7 +837,7 @@ def test_modify_prefix_list_referenced_by_rmap_p0(): "route_maps": { "rmap_match_pf_1_{}".format(addr_type): [{ "action": "permit", - 'seq_id': '5', + "seq_id": "5", "match": { addr_type: { "prefix_lists": "pf_list_1_{}".format(addr_type) @@ -849,7 +850,7 @@ def test_modify_prefix_list_referenced_by_rmap_p0(): }], "rmap_match_pf_2_{}".format(addr_type): [{ "action": "permit", - 'seq_id': '5', + "seq_id": "5", "match": { addr_type: { "prefix_lists": "pf_list_1_{}".format(addr_type) @@ -863,12 +864,12 @@ def test_modify_prefix_list_referenced_by_rmap_p0(): } } result = create_route_maps(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Configure neighbor for route map input_dict_4 = { - 'r3': { + "r3": { "bgp": { "address_family": { "ipv4": { @@ -880,7 +881,7 @@ def test_modify_prefix_list_referenced_by_rmap_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv4", - "direction": 'in' + "direction": "in" }] } } @@ -891,7 +892,7 @@ def test_modify_prefix_list_referenced_by_rmap_p0(): "route_maps": [{ "name": "rmap_match_pf_2_ipv4", - "direction": 'out' + "direction": "out" }] } } @@ -908,7 +909,7 @@ def test_modify_prefix_list_referenced_by_rmap_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv6", - "direction": 'in' + "direction": "in" }] } } @@ -919,7 +920,7 @@ def test_modify_prefix_list_referenced_by_rmap_p0(): "route_maps": [{ "name": "rmap_match_pf_2_ipv6", - "direction": 'out' + "direction": "out" }] } } @@ -933,21 +934,21 @@ def test_modify_prefix_list_referenced_by_rmap_p0(): } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" input_dict = topo["routers"] for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying BGP set attributes - dut = 'r3' + dut = "r3" routes = { "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], "ipv6": ["1::1/128", "1::2/128"] @@ -956,20 +957,20 @@ def test_modify_prefix_list_referenced_by_rmap_p0(): rmap_name = "rmap_match_pf_1_{}".format(addr_type) result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r4' - protocol = 'bgp' + dut = "r4" + protocol = "bgp" for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying BGP set attributes - dut = 'r4' + dut = "r4" routes = { "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], "ipv6": ["1::1/128", "1::2/128"] @@ -979,55 +980,55 @@ def test_modify_prefix_list_referenced_by_rmap_p0(): rmap_name = "rmap_match_pf_2_{}".format(addr_type) result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Modify ip prefix list input_dict_2 = { - 'r3': { - 'prefix_lists': { - 'ipv4': { - 'pf_list_1_ipv4': [{ - 'seqid': 10, - 'network': 'any', - 'action': 'deny' + "r3": { + "prefix_lists": { + "ipv4": { + "pf_list_1_ipv4": [{ + "seqid": 10, + "network": "any", + "action": "deny" }] }, - 'ipv6': { - 'pf_list_1_ipv6': [{ - 'seqid': 100, - 'network': 'any', - 'action': 'deny' + "ipv6": { + "pf_list_1_ipv6": [{ + "seqid": 100, + "network": "any", + "action": "deny" }] } } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) sleep(5) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, - protocol=protocol) - assert result is not True, 'Testcase {} : Failed \n' - 'Expected behaviour: routes are not present \n ' - 'Error: {}'.format( + protocol=protocol, expected=False) + assert result is not True, "Testcase {} : Failed \n" + "routes are not present \n Error: {}".format( tc_name, result) + logger.info("Expected behaviour: {}".format(result)) # Verifying RIB routes - dut = 'r4' - protocol = 'bgp' + dut = "r4" + protocol = "bgp" for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, - protocol=protocol) - assert result is not True, 'Testcase {} : Failed \n' - 'Expected behaviour: routes are not present \n ' - 'Error: {}'.format( + protocol=protocol, expected=False) + assert result is not True, "Testcase {} : Failed \n" + "Expected behaviour: routes are not present \n " + "Error: {}".format( tc_name, result) write_test_footer(tc_name) @@ -1038,7 +1039,7 @@ def test_modify_prefix_list_referenced_by_rmap_p0(): def test_remove_prefix_list_referenced_by_rmap_p0(): """ - TC_50_1: + TC_50_2: Remove prefix-list referencec by route-map match cluase and verifying it reflecting as intended """ @@ -1046,7 +1047,7 @@ def test_remove_prefix_list_referenced_by_rmap_p0(): global bgp_convergence if bgp_convergence is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = inspect.stack()[0][3] @@ -1055,27 +1056,27 @@ def test_remove_prefix_list_referenced_by_rmap_p0(): # Create ip prefix list input_dict_2 = { - 'r3': { - 'prefix_lists': { - 'ipv4': { - 'pf_list_1_ipv4': [{ - 'seqid': 10, - 'network': 'any', - 'action': 'permit' + "r3": { + "prefix_lists": { + "ipv4": { + "pf_list_1_ipv4": [{ + "seqid": 10, + "network": "any", + "action": "permit" }] }, - 'ipv6': { - 'pf_list_1_ipv6': [{ - 'seqid': 100, - 'network': 'any', - 'action': 'permit' + "ipv6": { + "pf_list_1_ipv6": [{ + "seqid": 100, + "network": "any", + "action": "permit" }] } } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Create route map @@ -1085,7 +1086,7 @@ def test_remove_prefix_list_referenced_by_rmap_p0(): "route_maps": { "rmap_match_pf_1_{}".format(addr_type): [{ "action": "permit", - 'seq_id': '5', + "seq_id": "5", "match": { addr_type: { "prefix_lists": "pf_list_1_{}".format(addr_type) @@ -1097,7 +1098,7 @@ def test_remove_prefix_list_referenced_by_rmap_p0(): }], "rmap_match_pf_2_{}".format(addr_type): [{ "action": "permit", - 'seq_id': '5', + "seq_id": "5", "match": { addr_type: { "prefix_lists": "pf_list_1_{}".format(addr_type) @@ -1111,13 +1112,13 @@ def test_remove_prefix_list_referenced_by_rmap_p0(): } } result = create_route_maps(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Configure neighbor for route map for addr_type in ADDR_TYPES: input_dict_4 = { - 'r3': { + "r3": { "bgp": { "address_family": { "ipv4": { @@ -1129,7 +1130,7 @@ def test_remove_prefix_list_referenced_by_rmap_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv4", - "direction": 'in' + "direction": "in" }] } } @@ -1140,7 +1141,7 @@ def test_remove_prefix_list_referenced_by_rmap_p0(): "route_maps": [{ "name": "rmap_match_pf_2_ipv4", - "direction": 'out' + "direction": "out" }] } } @@ -1157,7 +1158,7 @@ def test_remove_prefix_list_referenced_by_rmap_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv6", - "direction": 'in' + "direction": "in" }] } } @@ -1168,7 +1169,7 @@ def test_remove_prefix_list_referenced_by_rmap_p0(): "route_maps": [{ "name": "rmap_match_pf_2_ipv6", - "direction": 'out' + "direction": "out" }] } } @@ -1181,21 +1182,21 @@ def test_remove_prefix_list_referenced_by_rmap_p0(): } } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" input_dict = topo["routers"] for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying BGP set attributes - dut = 'r3' + dut = "r3" routes = { "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], "ipv6": ["1::1/128", "1::2/128"] @@ -1204,20 +1205,20 @@ def test_remove_prefix_list_referenced_by_rmap_p0(): rmap_name = "rmap_match_pf_1_{}".format(addr_type) result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r4' - protocol = 'bgp' + dut = "r4" + protocol = "bgp" for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying BGP set attributes - dut = 'r4' + dut = "r4" routes = { "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], "ipv6": ["1::1/128", "1::2/128"] @@ -1226,67 +1227,67 @@ def test_remove_prefix_list_referenced_by_rmap_p0(): rmap_name = "rmap_match_pf_2_{}".format(addr_type) result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Remove/Delete prefix list input_dict_3 = { - 'r3': { - 'prefix_lists': { - 'ipv4': { - 'pf_list_1_ipv4': [{ - 'seqid': 10, - 'network': 'any', - 'action': 'permit', - 'delete': True + "r3": { + "prefix_lists": { + "ipv4": { + "pf_list_1_ipv4": [{ + "seqid": 10, + "network": "any", + "action": "permit", + "delete": True }] }, - 'ipv6': { - 'pf_list_1_ipv6': [{ - 'seqid': 100, - 'network': 'any', - 'action': 'permit', - 'delete': True + "ipv6": { + "pf_list_1_ipv6": [{ + "seqid": 100, + "network": "any", + "action": "permit", + "delete": True }] } } } } result = create_prefix_lists(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) result = verify_prefix_lists(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Api call to clear bgp, so config changes would be reflected - dut = 'r3' + dut = "r3" result = clear_bgp_and_verify(tgen, topo, dut) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, - protocol=protocol) - assert result is not True, 'Testcase {} : Failed \n' - 'Expected behaviour: routes are not present \n ' - 'Error: {}'.format( + protocol=protocol, expected=False) + assert result is not True, "Testcase {} : Failed \n" + "routes are not present \n Error: {}".format( tc_name, result) + logger.info("Expected behaviour: {}".format(result)) # Verifying RIB routes - dut = 'r4' - protocol = 'bgp' + dut = "r4" + protocol = "bgp" for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, - protocol=protocol) - assert result is not True, 'Testcase {} : Failed \n' - 'Expected behaviour: routes are not present \n ' - 'Error: {}'.format( - tc_name, result) + protocol=protocol, expected=False) + assert result is not True, "Testcase {} : Failed \n" + "routes are not present \n Error: {}".\ + format(tc_name, result) + logger.info("Expected behaviour: {}".format(result)) write_test_footer(tc_name) @@ -1304,7 +1305,7 @@ def test_add_and_remove_community_list_referenced_by_rmap_p0(): global bgp_convergence if bgp_convergence is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = inspect.stack()[0][3] @@ -1329,12 +1330,12 @@ def test_add_and_remove_community_list_referenced_by_rmap_p0(): } } result = create_route_maps(tgen, input_dict_5) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Configure neighbor for route map input_dict_6 = { - 'r1': { + "r1": { "bgp": { "address_family": { "ipv4": { @@ -1345,7 +1346,7 @@ def test_add_and_remove_community_list_referenced_by_rmap_p0(): "r1": { "route_maps": [{ "name": "rm_r1_out_ipv4", - "direction": 'out' + "direction": "out" }] } } @@ -1361,7 +1362,7 @@ def test_add_and_remove_community_list_referenced_by_rmap_p0(): "r1": { "route_maps": [{ "name": "rm_r1_out_ipv6", - "direction": 'out' + "direction": "out" }] } } @@ -1375,7 +1376,7 @@ def test_add_and_remove_community_list_referenced_by_rmap_p0(): } result = create_router_bgp(tgen, topo, input_dict_6) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) for addr_type in ADDR_TYPES: @@ -1394,9 +1395,14 @@ def test_add_and_remove_community_list_referenced_by_rmap_p0(): } } result = create_bgp_community_lists(tgen, input_dict_1) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) + # Verify BGP large community is created + result = verify_create_community_list(tgen, input_dict_1) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result) + for addr_type in ADDR_TYPES: # Create route map input_dict_2 = { @@ -1415,12 +1421,12 @@ def test_add_and_remove_community_list_referenced_by_rmap_p0(): } } result = create_route_maps(tgen, input_dict_2) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Configure neighbor for route map input_dict_3 = { - 'r3': { + "r3": { "bgp": { "address_family": { "ipv4": { @@ -1431,7 +1437,7 @@ def test_add_and_remove_community_list_referenced_by_rmap_p0(): "r3": { "route_maps": [{ "name": "rm_r3_in_ipv4", - "direction": 'in' + "direction": "in" }] } } @@ -1447,7 +1453,7 @@ def test_add_and_remove_community_list_referenced_by_rmap_p0(): "r3": { "route_maps": [{ "name": "rm_r3_in_ipv6", - "direction": 'in' + "direction": "in" }] } } @@ -1461,33 +1467,33 @@ def test_add_and_remove_community_list_referenced_by_rmap_p0(): } result = create_router_bgp(tgen, topo, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) sleep(5) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" input_dict = topo["routers"] for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verify large-community-list - dut = 'r3' + dut = "r3" networks = { "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], "ipv6": ["1::1/128", "1::2/128"] } input_dict_4 = { - 'largeCommunity': '1:1:1 1:2:3 2:1:1 2:2:2' + "largeCommunity": "1:1:1 1:2:3 2:1:1 2:2:2" } for addr_type in ADDR_TYPES: result = verify_bgp_community(tgen, addr_type, dut, networks[ addr_type],input_dict_4) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name) @@ -1498,14 +1504,14 @@ def test_add_and_remove_community_list_referenced_by_rmap_p0(): def test_multiple_match_statement_in_route_map_logical_ORed_p0(): """ TC_45: - Test multiple match statements as part of a route-map's single + Test multiple match statements as part of a route-map"s single sequence number. (Logical OR-ed of multiple match statements) """ tgen = get_topogen() global bgp_convergence if bgp_convergence is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = inspect.stack()[0][3] @@ -1514,20 +1520,20 @@ def test_multiple_match_statement_in_route_map_logical_ORed_p0(): # Api call to advertise networks input_dict_nw1 = { - 'r1': { + "r1": { "bgp": { "address_family": { "ipv4": { "unicast": { "advertise_networks": [ - {"network": '10.0.30.1/32'} + {"network": "10.0.30.1/32"} ] } }, "ipv6": { "unicast": { "advertise_networks": [ - {"network": '1::1/128'} + {"network": "1::1/128"} ] } } @@ -1537,25 +1543,25 @@ def test_multiple_match_statement_in_route_map_logical_ORed_p0(): } result = create_router_bgp(tgen, topo, input_dict_nw1) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Api call to advertise networks input_dict_nw2 = { - 'r1': { + "r1": { "bgp": { "address_family": { "ipv4": { "unicast": { "advertise_networks": [ - {"network": '20.0.30.1/32'} + {"network": "20.0.30.1/32"} ] } }, "ipv6": { "unicast": { "advertise_networks": [ - {"network": '2::1/128'} + {"network": "2::1/128"} ] } } @@ -1565,57 +1571,57 @@ def test_multiple_match_statement_in_route_map_logical_ORed_p0(): } result = create_router_bgp(tgen, topo, input_dict_nw2) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Create ip prefix list input_dict_2 = { - 'r3': { - 'prefix_lists': { - 'ipv4': { - 'pf_list_1_ipv4': [{ - 'seqid': 10, - 'network': 'any', - 'action': 'permit' + "r3": { + "prefix_lists": { + "ipv4": { + "pf_list_1_ipv4": [{ + "seqid": 10, + "network": "any", + "action": "permit" }] }, - 'ipv6': { - 'pf_list_1_ipv6': [{ - 'seqid': 100, - 'network': 'any', - 'action': 'permit' + "ipv6": { + "pf_list_1_ipv6": [{ + "seqid": 100, + "network": "any", + "action": "permit" }] } } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Create ip prefix list input_dict_2 = { - 'r3': { - 'prefix_lists': { - 'ipv4': { - 'pf_list_2_ipv4': [{ - 'seqid': 10, - 'network': 'any', - 'action': 'permit' + "r3": { + "prefix_lists": { + "ipv4": { + "pf_list_2_ipv4": [{ + "seqid": 10, + "network": "any", + "action": "permit" }] }, - 'ipv6': { - 'pf_list_2_ipv6': [{ - 'seqid': 100, - 'network': 'any', - 'action': 'permit' + "ipv6": { + "pf_list_2_ipv6": [{ + "seqid": 100, + "network": "any", + "action": "permit" }] } } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) input_dict_3_addr_type ={} @@ -1626,7 +1632,7 @@ def test_multiple_match_statement_in_route_map_logical_ORed_p0(): "route_maps": { "rmap_match_pf_1_{}".format(addr_type): [{ "action": "permit", - 'seq_id': '5', + "seq_id": "5", "match": { addr_type: { "prefix_lists": "pf_list_1_{}".format(addr_type) @@ -1641,7 +1647,7 @@ def test_multiple_match_statement_in_route_map_logical_ORed_p0(): } input_dict_3_addr_type[addr_type] = input_dict_3 result = create_route_maps(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Create route map @@ -1651,7 +1657,7 @@ def test_multiple_match_statement_in_route_map_logical_ORed_p0(): "route_maps": { "rmap_match_pf_1_{}".format(addr_type): [{ "action": "permit", - 'seq_id': '5', + "seq_id": "5", "match": { addr_type: { "prefix_lists": "pf_list_1_{}".format(addr_type) @@ -1666,12 +1672,12 @@ def test_multiple_match_statement_in_route_map_logical_ORed_p0(): } input_dict_3_addr_type[addr_type] = input_dict_3 result = create_route_maps(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Configure neighbor for route map input_dict_6 = { - 'r3': { + "r3": { "bgp": { "address_family": { "ipv4": { @@ -1683,7 +1689,7 @@ def test_multiple_match_statement_in_route_map_logical_ORed_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv4", - "direction": 'in' + "direction": "in" }] } } @@ -1700,7 +1706,7 @@ def test_multiple_match_statement_in_route_map_logical_ORed_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv6", - "direction": 'in' + "direction": "in" }] } } @@ -1714,21 +1720,21 @@ def test_multiple_match_statement_in_route_map_logical_ORed_p0(): } result = create_router_bgp(tgen, topo, input_dict_6) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" input_dict = topo["routers"] for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying BGP set attributes - dut = 'r3' + dut = "r3" routes = { "ipv4": ["10.0.30.1/32"], "ipv6": ["1::1/128"] @@ -1737,7 +1743,7 @@ def test_multiple_match_statement_in_route_map_logical_ORed_p0(): rmap_name = "rmap_match_pf_1_{}".format(addr_type) result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3_addr_type[addr_type]) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying BGP set attributes @@ -1748,7 +1754,7 @@ def test_multiple_match_statement_in_route_map_logical_ORed_p0(): for addr_type in ADDR_TYPES: result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name) @@ -1757,17 +1763,17 @@ def test_multiple_match_statement_in_route_map_logical_ORed_p0(): # tgen.mininet_cli() -def test_multiple_match_statement_in_route_map_logical_ANDed(): +def test_multiple_match_statement_in_route_map_logical_ANDed_p1(): """ TC_44: - Test multiple match statements as part of a route-map's single + Test multiple match statements as part of a route-map"s single sequence number. (Logical AND of multiple match statements) """ tgen = get_topogen() global bgp_convergence if bgp_convergence is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = inspect.stack()[0][3] @@ -1790,13 +1796,13 @@ def test_multiple_match_statement_in_route_map_logical_ANDed(): } } result = create_route_maps(tgen, input_dict_5) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Configure neighbor for route map for addr_type in ADDR_TYPES: input_dict_6 = { - 'r1': { + "r1": { "bgp": { "address_family": { addr_type: { @@ -1808,7 +1814,7 @@ def test_multiple_match_statement_in_route_map_logical_ANDed(): "route_maps": [{ "name": "rm_r1_out_{}".format(addr_type), - "direction": 'out' + "direction": "out" }] } } @@ -1821,25 +1827,25 @@ def test_multiple_match_statement_in_route_map_logical_ANDed(): } } result = create_router_bgp(tgen, topo, input_dict_6) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Create ip prefix list input_dict_2 = { - 'r3': { - 'prefix_lists': { - 'ipv4': { - 'pf_list_1_ipv4': [{ - 'seqid': 10, - 'network': 'any', - 'action': 'permit' + "r3": { + "prefix_lists": { + "ipv4": { + "pf_list_1_ipv4": [{ + "seqid": 10, + "network": "any", + "action": "permit" }] }, - 'ipv6': { - 'pf_list_1_ipv6': [{ - 'seqid': 100, - 'network': 'any', - 'action': 'permit' + "ipv6": { + "pf_list_1_ipv6": [{ + "seqid": 100, + "network": "any", + "action": "permit" }] } } @@ -1847,7 +1853,7 @@ def test_multiple_match_statement_in_route_map_logical_ANDed(): } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) for addr_type in ADDR_TYPES: @@ -1866,9 +1872,14 @@ def test_multiple_match_statement_in_route_map_logical_ANDed(): } } result = create_bgp_community_lists(tgen, input_dict_1) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) + # Verify BGP large community is created + result = verify_create_community_list(tgen, input_dict_1) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result) + # Create route map for addr_type in ADDR_TYPES: input_dict_3 = { @@ -1876,7 +1887,7 @@ def test_multiple_match_statement_in_route_map_logical_ANDed(): "route_maps": { "rmap_match_pf_1_{}".format(addr_type): [{ "action": "permit", - 'seq_id': '5', + "seq_id": "5", "match": { addr_type: { "prefix_lists": "pf_list_1_{}".format(addr_type) @@ -1890,7 +1901,7 @@ def test_multiple_match_statement_in_route_map_logical_ANDed(): } } result = create_route_maps(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) for addr_type in ADDR_TYPES: @@ -1900,7 +1911,7 @@ def test_multiple_match_statement_in_route_map_logical_ANDed(): "route_maps": { "rmap_match_pf_1_{}".format(addr_type): [{ "action": "permit", - 'seq_id': '5', + "seq_id": "5", "match": { addr_type : { "large_community_list": {"id": "rmap_lcomm_"+ @@ -1915,12 +1926,12 @@ def test_multiple_match_statement_in_route_map_logical_ANDed(): } } result = create_route_maps(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Configure neighbor for route map for addr_type in ADDR_TYPES: input_dict_4 = { - 'r3': { + "r3": { "bgp": { "address_family": { addr_type: { @@ -1932,7 +1943,7 @@ def test_multiple_match_statement_in_route_map_logical_ANDed(): "route_maps": [{ "name": "rmap_match_pf_1_{}".format(addr_type), - "direction": 'in' + "direction": "in" }] } } @@ -1945,20 +1956,20 @@ def test_multiple_match_statement_in_route_map_logical_ANDed(): } } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # sleep(10) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" input_dict = topo["routers"] for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying BGP set attributes - dut = 'r3' + dut = "r3" routes = { "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], "ipv6": ["1::1/128", "1::2/128"] @@ -1967,7 +1978,7 @@ def test_multiple_match_statement_in_route_map_logical_ANDed(): rmap_name = "rmap_match_pf_1_{}".format(addr_type) result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name) @@ -1986,7 +1997,7 @@ def test_add_remove_rmap_to_specific_neighbor_p0(): global bgp_convergence if bgp_convergence is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = inspect.stack()[0][3] @@ -1995,27 +2006,27 @@ def test_add_remove_rmap_to_specific_neighbor_p0(): # Create ip prefix list input_dict_2 = { - 'r3': { - 'prefix_lists': { - 'ipv4': { - 'pf_list_1_ipv4': [{ - 'seqid': 10, - 'network': 'any', - 'action': 'deny' + "r3": { + "prefix_lists": { + "ipv4": { + "pf_list_1_ipv4": [{ + "seqid": 10, + "network": "any", + "action": "deny" }] }, - 'ipv6': { - 'pf_list_1_ipv6': [{ - 'seqid': 100, - 'network': 'any', - 'action': 'deny' + "ipv6": { + "pf_list_1_ipv6": [{ + "seqid": 100, + "network": "any", + "action": "deny" }] } } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Create route map @@ -2025,7 +2036,7 @@ def test_add_remove_rmap_to_specific_neighbor_p0(): "route_maps": { "rmap_match_pf_1_{}".format(addr_type): [{ "action": "permit", - 'seq_id': '5', + "seq_id": "5", "match": { addr_type: { "prefix_lists": "pf_list_1_{}".format(addr_type) @@ -2039,12 +2050,12 @@ def test_add_remove_rmap_to_specific_neighbor_p0(): } } result = create_route_maps(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Configure neighbor for route map input_dict_4 = { - 'r3': { + "r3": { "bgp": { "address_family": { "ipv4": { @@ -2056,7 +2067,7 @@ def test_add_remove_rmap_to_specific_neighbor_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv4", - "direction": 'in' + "direction": "in" }] } } @@ -2073,7 +2084,7 @@ def test_add_remove_rmap_to_specific_neighbor_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv6", - "direction": 'in' + "direction": "in" }] } } @@ -2087,24 +2098,24 @@ def test_add_remove_rmap_to_specific_neighbor_p0(): } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" input_dict = topo["routers"] for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, - protocol=protocol) - assert result is not True, 'Testcase {} : \n' - 'Expected Behavior: Routes are not present in RIB \n' - ' Error: {}'.format( + protocol=protocol, expected=False) + assert result is not True, "Testcase {} : Failed \n Error" + "Routes are still present: {}".format( tc_name, result) + logger.info("Expected behaviour: {}".format(result)) # Remove applied rmap from neighbor input_dict_4 = { - 'r3': { + "r3": { "bgp": { "address_family": { "ipv4": { @@ -2116,7 +2127,7 @@ def test_add_remove_rmap_to_specific_neighbor_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv4", - "direction": 'in', + "direction": "in", "delete": True }] } @@ -2134,7 +2145,7 @@ def test_add_remove_rmap_to_specific_neighbor_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv6", - "direction": 'in', + "direction": "in", "delete": True }] } @@ -2149,16 +2160,16 @@ def test_add_remove_rmap_to_specific_neighbor_p0(): } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" input_dict = topo["routers"] for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name) @@ -2177,7 +2188,7 @@ def test_clear_bgp_and_flap_interface_to_verify_rmap_properties_p0(): global bgp_convergence if bgp_convergence is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = inspect.stack()[0][3] @@ -2186,27 +2197,27 @@ def test_clear_bgp_and_flap_interface_to_verify_rmap_properties_p0(): # Create ip prefix list input_dict_2 = { - 'r3': { - 'prefix_lists': { - 'ipv4': { - 'pf_list_1_ipv4': [{ - 'seqid': 10, - 'network': 'any', - 'action': 'permit' + "r3": { + "prefix_lists": { + "ipv4": { + "pf_list_1_ipv4": [{ + "seqid": 10, + "network": "any", + "action": "permit" }] }, - 'ipv6': { - 'pf_list_1_ipv6': [{ - 'seqid': 100, - 'network': 'any', - 'action': 'permit' + "ipv6": { + "pf_list_1_ipv6": [{ + "seqid": 100, + "network": "any", + "action": "permit" }] } } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Create route map @@ -2216,7 +2227,7 @@ def test_clear_bgp_and_flap_interface_to_verify_rmap_properties_p0(): "route_maps": { "rmap_match_pf_1_{}".format(addr_type): [{ "action": "permit", - 'seq_id': '5', + "seq_id": "5", "match": { addr_type: { "prefix_lists": "pf_list_1_{}".format(addr_type) @@ -2231,12 +2242,12 @@ def test_clear_bgp_and_flap_interface_to_verify_rmap_properties_p0(): } } result = create_route_maps(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Configure neighbor for route map input_dict_4 = { - 'r3': { + "r3": { "bgp": { "address_family": { "ipv4": { @@ -2248,7 +2259,7 @@ def test_clear_bgp_and_flap_interface_to_verify_rmap_properties_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv4", - "direction": 'in' + "direction": "in" }] } } @@ -2265,7 +2276,7 @@ def test_clear_bgp_and_flap_interface_to_verify_rmap_properties_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv6", - "direction": 'in' + "direction": "in" }] } } @@ -2279,20 +2290,20 @@ def test_clear_bgp_and_flap_interface_to_verify_rmap_properties_p0(): } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" input_dict = topo["routers"] for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying BGP set attributes - dut = 'r3' + dut = "r3" routes = { "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], "ipv6": ["1::1/128", "1::2/128"] @@ -2301,26 +2312,26 @@ def test_clear_bgp_and_flap_interface_to_verify_rmap_properties_p0(): rmap_name = "rmap_match_pf_1_{}".format(addr_type) result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # clear bgp, so config changes would be reflected - dut = 'r3' + dut = "r3" result = clear_bgp_and_verify(tgen, topo, dut) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" input_dict = topo["routers"] for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying BGP set attributes - dut = 'r3' + dut = "r3" routes = { "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], "ipv6": ["1::1/128", "1::2/128"] @@ -2329,7 +2340,7 @@ def test_clear_bgp_and_flap_interface_to_verify_rmap_properties_p0(): rmap_name = "rmap_match_pf_1_{}".format(addr_type) result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Flap interface to see if route-map properties are intact @@ -2348,19 +2359,19 @@ def test_clear_bgp_and_flap_interface_to_verify_rmap_properties_p0(): # Verify BGP convergence once interface is up result = verify_bgp_convergence(tgen, topo) assert result is True, ( - 'setup_module :Failed \n Error:' ' {}'.format(result)) + "setup_module :Failed \n Error:" " {}".format(result)) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" input_dict = topo["routers"] for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying BGP set attributes - dut = 'r3' + dut = "r3" routes = { "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], "ipv6": ["1::1/128", "1::2/128"] @@ -2369,7 +2380,7 @@ def test_clear_bgp_and_flap_interface_to_verify_rmap_properties_p0(): rmap_name = "rmap_match_pf_1_{}".format(addr_type) result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name) @@ -2388,7 +2399,7 @@ def test_rmap_without_match_and_set_clause_p0(): global bgp_convergence if bgp_convergence is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = inspect.stack()[0][3] @@ -2402,22 +2413,22 @@ def test_rmap_without_match_and_set_clause_p0(): "route_maps": { "rmap_no_match_set_1_{}".format(addr_type): [{ "action": "permit", - 'seq_id': '5' + "seq_id": "5" }], "rmap_no_match_set_2_{}".format(addr_type): [{ "action": "deny", - 'seq_id': '5' + "seq_id": "5" }] } } } result = create_route_maps(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Configure neighbor for route map input_dict_4 = { - 'r3': { + "r3": { "bgp": { "address_family": { "ipv4": { @@ -2429,7 +2440,7 @@ def test_rmap_without_match_and_set_clause_p0(): "route_maps": [{ "name": "rmap_no_match_set_1_ipv4", - "direction": 'in' + "direction": "in" }] } } @@ -2440,7 +2451,7 @@ def test_rmap_without_match_and_set_clause_p0(): "route_maps": [{ "name": "rmap_no_match_set_2_ipv4", - "direction": 'out' + "direction": "out" }] } } @@ -2457,7 +2468,7 @@ def test_rmap_without_match_and_set_clause_p0(): "route_maps": [{ "name": "rmap_no_match_set_1_ipv6", - "direction": 'in' + "direction": "in" }] } } @@ -2468,7 +2479,7 @@ def test_rmap_without_match_and_set_clause_p0(): "route_maps": [{ "name": "rmap_no_match_set_2_ipv6", - "direction": 'out' + "direction": "out" }] } } @@ -2482,30 +2493,30 @@ def test_rmap_without_match_and_set_clause_p0(): } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" input_dict = topo["routers"] for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r4' - protocol = 'bgp' + dut = "r4" + protocol = "bgp" for addr_type in ADDR_TYPES: - result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is not True, 'Testcase {} : Failed \n' - 'Expected behaviour: routes are not present \n ' - 'Error: {}'.format( + result = verify_rib(tgen, addr_type, dut, input_dict, + protocol=protocol, expected=False) + assert result is not True, "Testcase {} : Failed \n" + "routes are not present \n Error: {}".format( tc_name, result) + logger.info("Expected behaviour: {}".format(result)) write_test_footer(tc_name) - # Uncomment next line for debugging # tgen.mininet_cli() @@ -2520,7 +2531,7 @@ def test_set_localpref_weight_to_ebgp_and_med_to_ibgp_peers_p0(): global bgp_convergence if bgp_convergence is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = inspect.stack()[0][3] @@ -2529,27 +2540,27 @@ def test_set_localpref_weight_to_ebgp_and_med_to_ibgp_peers_p0(): # Create ip prefix list input_dict_2 = { - 'r3': { - 'prefix_lists': { - 'ipv4': { - 'pf_list_1_ipv4': [{ - 'seqid': 10, - 'network': 'any', - 'action': 'permit' + "r3": { + "prefix_lists": { + "ipv4": { + "pf_list_1_ipv4": [{ + "seqid": 10, + "network": "any", + "action": "permit" }] }, - 'ipv6': { - 'pf_list_1_ipv6': [{ - 'seqid': 100, - 'network': 'any', - 'action': 'permit' + "ipv6": { + "pf_list_1_ipv6": [{ + "seqid": 100, + "network": "any", + "action": "permit" }] } } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Create route map @@ -2597,12 +2608,12 @@ def test_set_localpref_weight_to_ebgp_and_med_to_ibgp_peers_p0(): } input_dict_3_addr_type[addr_type] = input_dict_3 result = create_route_maps(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Configure neighbor for route map input_dict_4 = { - 'r3': { + "r3": { "bgp": { "address_family": { "ipv4": { @@ -2614,7 +2625,7 @@ def test_set_localpref_weight_to_ebgp_and_med_to_ibgp_peers_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv4", - "direction": 'in' + "direction": "in" }] } } @@ -2625,7 +2636,7 @@ def test_set_localpref_weight_to_ebgp_and_med_to_ibgp_peers_p0(): "route_maps": [{ "name": "rmap_match_pf_2_ipv4", - "direction": 'out' + "direction": "out" }] } } @@ -2636,7 +2647,7 @@ def test_set_localpref_weight_to_ebgp_and_med_to_ibgp_peers_p0(): "route_maps": [{ "name": "rmap_match_pf_3_ipv4", - "direction": 'out' + "direction": "out" }] } } @@ -2653,7 +2664,7 @@ def test_set_localpref_weight_to_ebgp_and_med_to_ibgp_peers_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv6", - "direction": 'in' + "direction": "in" }] } } @@ -2664,7 +2675,7 @@ def test_set_localpref_weight_to_ebgp_and_med_to_ibgp_peers_p0(): "route_maps": [{ "name": "rmap_match_pf_2_ipv6", - "direction": 'out' + "direction": "out" }] } } @@ -2675,7 +2686,7 @@ def test_set_localpref_weight_to_ebgp_and_med_to_ibgp_peers_p0(): "route_maps": [{ "name": "rmap_match_pf_3_ipv6", - "direction": 'out' + "direction": "out" }] } } @@ -2689,21 +2700,21 @@ def test_set_localpref_weight_to_ebgp_and_med_to_ibgp_peers_p0(): } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" input_dict = topo["routers"] for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying BGP set attributes - dut = 'r3' + dut = "r3" routes = { "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], "ipv6": ["1::1/128", "1::2/128"] @@ -2713,20 +2724,20 @@ def test_set_localpref_weight_to_ebgp_and_med_to_ibgp_peers_p0(): rmap_name = "rmap_match_pf_1_{}".format(addr_type) result = verify_bgp_attributes(tgen, addr_type, dut, routes[ addr_type],rmap_name, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r4' - protocol = 'bgp' + dut = "r4" + protocol = "bgp" for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying BGP set attributes - dut = 'r4' + dut = "r4" routes = { "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], "ipv6": ["1::1/128", "1::2/128"] @@ -2736,22 +2747,23 @@ def test_set_localpref_weight_to_ebgp_and_med_to_ibgp_peers_p0(): rmap_name = "rmap_match_pf_2_{}".format(addr_type) result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], - rmap_name, input_dict_3_addr_type[addr_type]) - assert result is not True, 'Testcase {} : Failed \n' - 'Expected behaviour: Attributes are not set \n' - 'Error: {}'.format( + rmap_name, input_dict_3_addr_type[addr_type], + expected=False) + assert result is not True, "Testcase {} : Failed \n" + "Attributes are not set \n Error: {}".format( tc_name, result) + logger.info("Expected behaviour: {}".format(result)) # Verifying RIB routes - dut = 'r5' - protocol = 'bgp' + dut = "r5" + protocol = "bgp" for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying BGP set attributes - dut = 'r5' + dut = "r5" routes = { "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], "ipv6": ["1::1/128", "1::2/128"] @@ -2761,12 +2773,11 @@ def test_set_localpref_weight_to_ebgp_and_med_to_ibgp_peers_p0(): for addr_type in ADDR_TYPES: rmap_name = "rmap_match_pf_3_{}".format(addr_type) result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], - rmap_name, input_dict_3_addr_type[addr_type]) - assert result is not True, 'Testcase {} : Failed \n' - 'Expected behaviour: Attributes are not set \n' - 'Error: {}'.format( + rmap_name, input_dict_3_addr_type[addr_type], + expected=False) + assert result is not True, "Testcase {} : Failed \n" + "Attributes are not set \n Error: {}".format( tc_name, result) - logger.info("Expected behaviour: {}".format(result)) write_test_footer(tc_name) @@ -2778,14 +2789,14 @@ def test_set_localpref_weight_to_ebgp_and_med_to_ibgp_peers_p0(): def test_multiple_set_on_single_sequence_in_rmap_p0(): """ TC_43: - Test multiple set statements as part of a route-map's + Test multiple set statements as part of a route-map"s single sequence number. """ tgen = get_topogen() global bgp_convergence if bgp_convergence is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = inspect.stack()[0][3] @@ -2794,27 +2805,27 @@ def test_multiple_set_on_single_sequence_in_rmap_p0(): # Create ip prefix list input_dict_2 = { - 'r3': { - 'prefix_lists': { - 'ipv4': { - 'pf_list_1_ipv4': [{ - 'seqid': 10, - 'network': 'any', - 'action': 'permit' + "r3": { + "prefix_lists": { + "ipv4": { + "pf_list_1_ipv4": [{ + "seqid": 10, + "network": "any", + "action": "permit" }] }, - 'ipv6': { - 'pf_list_1_ipv6': [{ - 'seqid': 100, - 'network': 'any', - 'action': 'permit' + "ipv6": { + "pf_list_1_ipv6": [{ + "seqid": 100, + "network": "any", + "action": "permit" }] } } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Create route map @@ -2839,12 +2850,12 @@ def test_multiple_set_on_single_sequence_in_rmap_p0(): } } result = create_route_maps(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Configure neighbor for route map input_dict_4 = { - 'r3': { + "r3": { "bgp": { "address_family": { "ipv4": { @@ -2856,7 +2867,7 @@ def test_multiple_set_on_single_sequence_in_rmap_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv4", - "direction": 'in' + "direction": "in" }] } } @@ -2873,7 +2884,7 @@ def test_multiple_set_on_single_sequence_in_rmap_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv6", - "direction": 'in' + "direction": "in" }] } } @@ -2886,20 +2897,20 @@ def test_multiple_set_on_single_sequence_in_rmap_p0(): } } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" input_dict = topo["routers"] for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying BGP set attributes - dut = 'r3' + dut = "r3" routes = { "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], "ipv6": ["1::1/128", "1::2/128"] @@ -2910,7 +2921,7 @@ def test_multiple_set_on_single_sequence_in_rmap_p0(): rmap_name = "rmap_match_pf_1_{}".format(addr_type) result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name) @@ -2928,7 +2939,7 @@ def test_route_maps_with_continue_clause_p0(): global bgp_convergence if bgp_convergence is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = inspect.stack()[0][3] @@ -2937,27 +2948,27 @@ def test_route_maps_with_continue_clause_p0(): # Create ip prefix list input_dict_2 = { - 'r3': { - 'prefix_lists': { - 'ipv4': { - 'pf_list_1_ipv4': [{ - 'seqid': 10, - 'network': 'any', - 'action': 'permit' + "r3": { + "prefix_lists": { + "ipv4": { + "pf_list_1_ipv4": [{ + "seqid": 10, + "network": "any", + "action": "permit" }] }, - 'ipv6': { - 'pf_list_1_ipv6': [{ - 'seqid': 100, - 'network': 'any', - 'action': 'permit' + "ipv6": { + "pf_list_1_ipv6": [{ + "seqid": 100, + "network": "any", + "action": "permit" }] } } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Create route map @@ -2967,7 +2978,7 @@ def test_route_maps_with_continue_clause_p0(): "route_maps": { "rmap_match_pf_1_{}".format(addr_type): [{ "action": "permit", - 'seq_id': '10', + "seq_id": "10", "match": { addr_type: { "prefix_lists": "pf_list_1_{}".format(addr_type) @@ -2980,7 +2991,7 @@ def test_route_maps_with_continue_clause_p0(): }, { "action": "permit", - 'seq_id': '20', + "seq_id": "20", "match": { addr_type: { "prefix_lists": "pf_list_1_{}".format(addr_type) @@ -2992,7 +3003,7 @@ def test_route_maps_with_continue_clause_p0(): }, { "action": "permit", - 'seq_id': '30', + "seq_id": "30", "match": { addr_type: { "prefix_lists": "pf_list_1_{}".format(addr_type) @@ -3007,12 +3018,12 @@ def test_route_maps_with_continue_clause_p0(): } } result = create_route_maps(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Configure neighbor for route map input_dict_4 = { - 'r3': { + "r3": { "bgp": { "address_family": { "ipv4": { @@ -3024,7 +3035,7 @@ def test_route_maps_with_continue_clause_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv4", - "direction": 'in' + "direction": "in" }] } } @@ -3041,7 +3052,7 @@ def test_route_maps_with_continue_clause_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv6", - "direction": 'in' + "direction": "in" }] } } @@ -3054,21 +3065,21 @@ def test_route_maps_with_continue_clause_p0(): } } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" input_dict = topo["routers"] for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying BGP set attributes - dut = 'r3' + dut = "r3" rmap_name = "rmap_match_pf_1" routes = { "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], @@ -3082,7 +3093,7 @@ def test_route_maps_with_continue_clause_p0(): rmap_name = "rmap_match_pf_1_{}".format(addr_type) result = verify_bgp_attributes(tgen, addr_type, dut, routes[ addr_type],rmap_name, input_dict_3, seq_id[addr_type]) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name) @@ -3100,7 +3111,7 @@ def test_route_maps_with_goto_clause_p0(): global bgp_convergence if bgp_convergence is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = inspect.stack()[0][3] @@ -3109,27 +3120,27 @@ def test_route_maps_with_goto_clause_p0(): # Create ip prefix list input_dict_2 = { - 'r3': { - 'prefix_lists': { - 'ipv4': { - 'pf_list_1_ipv4': [{ - 'seqid': 10, - 'network': 'any', - 'action': 'permit' + "r3": { + "prefix_lists": { + "ipv4": { + "pf_list_1_ipv4": [{ + "seqid": 10, + "network": "any", + "action": "permit" }] }, - 'ipv6': { - 'pf_list_1_ipv6': [{ - 'seqid': 100, - 'network': 'any', - 'action': 'permit' + "ipv6": { + "pf_list_1_ipv6": [{ + "seqid": 100, + "network": "any", + "action": "permit" }] } } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Create route map @@ -3139,7 +3150,7 @@ def test_route_maps_with_goto_clause_p0(): "route_maps": { "rmap_match_pf_1_{}".format(addr_type): [{ "action": "permit", - 'seq_id': '10', + "seq_id": "10", "match": { addr_type: { "prefix_lists": "pf_list_1_{}".format(addr_type) @@ -3149,7 +3160,7 @@ def test_route_maps_with_goto_clause_p0(): }, { "action": "permit", - 'seq_id': '20', + "seq_id": "20", "match": { addr_type: { "prefix_lists": "pf_list_1_{}".format(addr_type) @@ -3161,7 +3172,7 @@ def test_route_maps_with_goto_clause_p0(): }, { "action": "permit", - 'seq_id': '30', + "seq_id": "30", "match": { addr_type: { "prefix_lists": "pf_list_1_{}".format(addr_type) @@ -3176,12 +3187,13 @@ def test_route_maps_with_goto_clause_p0(): } } result = create_route_maps(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + # tgen.mininet_cli() + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Configure neighbor for route map input_dict_4 = { - 'r3': { + "r3": { "bgp": { "address_family": { "ipv4": { @@ -3193,7 +3205,7 @@ def test_route_maps_with_goto_clause_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv4", - "direction": 'in' + "direction": "in" }] } } @@ -3210,7 +3222,7 @@ def test_route_maps_with_goto_clause_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv6", - "direction": 'in' + "direction": "in" }] } } @@ -3223,20 +3235,20 @@ def test_route_maps_with_goto_clause_p0(): } } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" input_dict = topo["routers"] for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying BGP set attributes - dut = 'r3' + dut = "r3" rmap_name = "rmap_match_pf_1" routes = { "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], @@ -3250,7 +3262,7 @@ def test_route_maps_with_goto_clause_p0(): rmap_name = "rmap_match_pf_1_{}".format(addr_type) result = verify_bgp_attributes(tgen, addr_type, dut, routes[ addr_type],rmap_name, input_dict_3, seq_id[addr_type]) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name) @@ -3268,7 +3280,7 @@ def test_route_maps_with_call_clause_p0(): global bgp_convergence if bgp_convergence is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = inspect.stack()[0][3] @@ -3277,27 +3289,27 @@ def test_route_maps_with_call_clause_p0(): # Create ip prefix list input_dict_2 = { - 'r3': { - 'prefix_lists': { - 'ipv4': { - 'pf_list_1_ipv4': [{ - 'seqid': 10, - 'network': 'any', - 'action': 'permit' + "r3": { + "prefix_lists": { + "ipv4": { + "pf_list_1_ipv4": [{ + "seqid": 10, + "network": "any", + "action": "permit" }] }, - 'ipv6': { - 'pf_list_1_ipv6': [{ - 'seqid': 100, - 'network': 'any', - 'action': 'permit' + "ipv6": { + "pf_list_1_ipv6": [{ + "seqid": 100, + "network": "any", + "action": "permit" }] } } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Create route map @@ -3332,12 +3344,12 @@ def test_route_maps_with_call_clause_p0(): } } result = create_route_maps(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Configure neighbor for route map input_dict_4 = { - 'r3': { + "r3": { "bgp": { "address_family": { "ipv4": { @@ -3349,7 +3361,7 @@ def test_route_maps_with_call_clause_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv4", - "direction": 'in' + "direction": "in" }] } } @@ -3366,7 +3378,7 @@ def test_route_maps_with_call_clause_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv6", - "direction": 'in' + "direction": "in" }] } } @@ -3379,20 +3391,20 @@ def test_route_maps_with_call_clause_p0(): } } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" input_dict = topo["routers"] for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying BGP set attributes - dut = 'r3' + dut = "r3" routes = { "ipv4": ["10.0.20.1/32", "10.0.20.2/32"], "ipv6": ["1::1/128", "1::2/128"] @@ -3402,7 +3414,7 @@ def test_route_maps_with_call_clause_p0(): rmap_name = "rmap_match_pf_1_{}".format(addr_type) result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) rmap_name = "rmap_match_pf_2" @@ -3410,7 +3422,7 @@ def test_route_maps_with_call_clause_p0(): rmap_name = "rmap_match_pf_2_{}".format(addr_type) result = verify_bgp_attributes(tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name) @@ -3429,7 +3441,7 @@ def test_create_rmap_match_prefix_list_to_deny_in_and_outbound_prefixes_p0(): global bgp_convergence if bgp_convergence is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = inspect.stack()[0][3] @@ -3438,27 +3450,27 @@ def test_create_rmap_match_prefix_list_to_deny_in_and_outbound_prefixes_p0(): # Create ip prefix list input_dict_2 = { - 'r3': { - 'prefix_lists': { - 'ipv4': { - 'pf_list_1_ipv4': [{ - 'seqid': 10, - 'network': 'any', - 'action': 'permit' + "r3": { + "prefix_lists": { + "ipv4": { + "pf_list_1_ipv4": [{ + "seqid": 10, + "network": "any", + "action": "permit" }] }, - 'ipv6': { - 'pf_list_1_ipv6': [{ - 'seqid': 100, - 'network': 'any', - 'action': 'permit' + "ipv6": { + "pf_list_1_ipv6": [{ + "seqid": 100, + "network": "any", + "action": "permit" }] } } } } result = create_prefix_lists(tgen, input_dict_2) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Create route map @@ -3492,12 +3504,12 @@ def test_create_rmap_match_prefix_list_to_deny_in_and_outbound_prefixes_p0(): } } result = create_route_maps(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Configure neighbor for route map input_dict_4 = { - 'r3': { + "r3": { "bgp": { "address_family": { "ipv4": { @@ -3509,7 +3521,7 @@ def test_create_rmap_match_prefix_list_to_deny_in_and_outbound_prefixes_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv4", - "direction": 'in' + "direction": "in" }] } } @@ -3520,7 +3532,7 @@ def test_create_rmap_match_prefix_list_to_deny_in_and_outbound_prefixes_p0(): "route_maps": [{ "name": "rmap_match_pf_2_ipv6", - "direction": 'out' + "direction": "out" }] } } @@ -3537,7 +3549,7 @@ def test_create_rmap_match_prefix_list_to_deny_in_and_outbound_prefixes_p0(): "route_maps": [{ "name": "rmap_match_pf_1_ipv4", - "direction": 'in' + "direction": "in" }] } } @@ -3548,7 +3560,7 @@ def test_create_rmap_match_prefix_list_to_deny_in_and_outbound_prefixes_p0(): "route_maps": [{ "name": "rmap_match_pf_2_ipv6", - "direction": 'out' + "direction": "out" }] } } @@ -3561,31 +3573,31 @@ def test_create_rmap_match_prefix_list_to_deny_in_and_outbound_prefixes_p0(): } } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" input_dict = topo["routers"] for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, - protocol=protocol) - assert result is not True, 'Testcase {} : Failed \n' - 'Expected behaviour: routes are not present \n ' - 'Error: {}'.format( - tc_name, result) + protocol=protocol, expected=False) + assert result is not True, "Testcase {} : Failed \n" + "routes are not present \n Error: {}".\ + format(tc_name, result) + logger.info("Expected behaviour: {}".format(result)) # Verifying RIB routes - dut = 'r4' - protocol = 'bgp' + dut = "r4" + protocol = "bgp" for addr_type in ADDR_TYPES: result = verify_rib(tgen, addr_type, dut, input_dict, - protocol=protocol) - assert result is not True, 'Testcase {} : Failed \n' - 'Expected behaviour: routes are not present \n ' - 'Error: {}'.format( - tc_name, result) + protocol=protocol, expected=False) + assert result is not True, "Testcase {} : Failed \n" + "routes are not present \n Error: {}".\ + format(tc_name, result) + logger.info("Expected behaviour: {}".format(result)) write_test_footer(tc_name) @@ -3603,7 +3615,7 @@ def test_create_rmap_to_match_tag_permit_inbound_prefixes_p0(): global bgp_convergence if bgp_convergence is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = inspect.stack()[0][3] @@ -3675,12 +3687,12 @@ def test_create_rmap_to_match_tag_permit_inbound_prefixes_p0(): } } result = create_route_maps(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Configure neighbor for route map input_dict_4 = { - 'r1': { + "r1": { "bgp": { "address_family": { "ipv4": { @@ -3692,7 +3704,7 @@ def test_create_rmap_to_match_tag_permit_inbound_prefixes_p0(): "route_maps": [{ "name": "rmap_match_tag_1_ipv4", - "direction": 'out' + "direction": "out" }] } } @@ -3709,7 +3721,7 @@ def test_create_rmap_to_match_tag_permit_inbound_prefixes_p0(): "route_maps": [{ "name": "rmap_match_tag_1_ipv6", - "direction": 'out' + "direction": "out" }] } } @@ -3722,12 +3734,12 @@ def test_create_rmap_to_match_tag_permit_inbound_prefixes_p0(): } } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" for addr_type in ADDR_TYPES: input_dict = { @@ -3743,7 +3755,7 @@ def test_create_rmap_to_match_tag_permit_inbound_prefixes_p0(): } result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name) @@ -3762,7 +3774,7 @@ def test_create_rmap_to_match_tag_deny_outbound_prefixes_p0(): global bgp_convergence if bgp_convergence is not True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = inspect.stack()[0][3] @@ -3834,12 +3846,12 @@ def test_create_rmap_to_match_tag_deny_outbound_prefixes_p0(): } } result = create_route_maps(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Configure neighbor for route map input_dict_4 = { - 'r1': { + "r1": { "bgp": { "address_family": { "ipv4": { @@ -3851,7 +3863,7 @@ def test_create_rmap_to_match_tag_deny_outbound_prefixes_p0(): "route_maps": [{ "name": "rmap_match_tag_1_ipv4", - "direction": 'out' + "direction": "out" }] } } @@ -3868,7 +3880,7 @@ def test_create_rmap_to_match_tag_deny_outbound_prefixes_p0(): "route_maps": [{ "name": "rmap_match_tag_1_ipv6", - "direction": 'out' + "direction": "out" }] } } @@ -3881,12 +3893,12 @@ def test_create_rmap_to_match_tag_deny_outbound_prefixes_p0(): } } result = create_router_bgp(tgen, topo, input_dict_4) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying RIB routes - dut = 'r3' - protocol = 'bgp' + dut = "r3" + protocol = "bgp" for addr_type in ADDR_TYPES: input_dict = { @@ -3901,16 +3913,17 @@ def test_create_rmap_to_match_tag_deny_outbound_prefixes_p0(): } } result = verify_rib(tgen, addr_type, dut, input_dict, - protocol=protocol) - assert result is not True, 'Testcase {} : Failed \n' - 'Expected behavior: routes are denied \n Error: {}'.format( + protocol=protocol, expected=False) + assert result is not True, "Testcase {} : Failed \n" + "routes are denied \n Error: {}".format( tc_name, result) + logger.info("Expected behaviour: {}".format(result)) write_test_footer(tc_name) # Uncomment next line for debugging # tgen.mininet_cli() -if __name__ == '__main__': +if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) diff --git a/tests/topotests/lib/bgp.py b/tests/topotests/lib/bgp.py index a8354f4c77..f3c17be684 100644 --- a/tests/topotests/lib/bgp.py +++ b/tests/topotests/lib/bgp.py @@ -1293,16 +1293,13 @@ def verify_bgp_attributes(tgen, addr_type, dut, static_routes, rmap_name, for static_route in static_routes: cmd = "show bgp {} {} json".format(addr_type, static_route) show_bgp_json = run_frr_cmd(rnode, cmd, isjson=True) - print("show_bgp_json $$$$$", show_bgp_json) dict_to_test = [] tmp_list = [] for rmap_router in input_dict.keys(): for rmap, values in input_dict[rmap_router][ "route_maps"].items(): - print("rmap == rmap_name $$$$1", rmap, rmap_name) if rmap == rmap_name: - print("rmap == rmap_name $$$$", rmap, rmap_name) dict_to_test = values for rmap_dict in values: if seq_id is not None: @@ -1318,7 +1315,6 @@ def verify_bgp_attributes(tgen, addr_type, dut, static_routes, rmap_name, if tmp_list: dict_to_test = tmp_list - print("dict_to_test $$$$", dict_to_test) for rmap_dict in dict_to_test: if "set" in rmap_dict: for criteria in rmap_dict["set"].keys(): diff --git a/zebra/zebra_gr.c b/zebra/zebra_gr.c index e8c7304f44..956fe9c2c8 100644 --- a/zebra/zebra_gr.c +++ b/zebra/zebra_gr.c @@ -468,9 +468,7 @@ static int32_t zebra_gr_route_stale_delete_timer_expiry(struct thread *thread) LOG_GR("%s: Client %s all starle routes processed", __func__, zebra_route_string(client->proto)); - if (info->current_prefix != NULL) - XFREE(MTYPE_TMP, info->current_prefix); - info->current_prefix = NULL; + XFREE(MTYPE_TMP, info->current_prefix); info->current_afi = 0; zebra_gr_delete_stale_client(info); } @@ -516,7 +514,6 @@ static int32_t zebra_gr_delete_stale_route(struct client_gr_info *info, struct route_entry *next; struct route_table *table; int32_t n = 0; - struct prefix *p; afi_t afi, curr_afi; uint8_t proto; uint16_t instance; @@ -541,25 +538,21 @@ static int32_t zebra_gr_delete_stale_route(struct client_gr_info *info, /* Process routes for all AFI */ for (afi = curr_afi; afi < AFI_MAX; afi++) { table = zvrf->table[afi][SAFI_UNICAST]; - p = info->current_prefix; if (table) { /* * If the current prefix is NULL then get the first * route entry in the table */ - if (p == NULL) { + if (info->current_prefix == NULL) { rn = route_top(table); if (rn == NULL) continue; - p = XCALLOC(MTYPE_TMP, sizeof(struct prefix)); - if (p == NULL) - return -1; curr = rn; - prefix_copy(p, &rn->p); } else /* Get the next route entry */ - curr = route_table_get_next(table, p); + curr = route_table_get_next( + table, info->current_prefix); for (rn = curr; rn; rn = srcdest_route_next(rn)) { RNODE_FOREACH_RE_SAFE (rn, re, next) { @@ -583,9 +576,13 @@ static int32_t zebra_gr_delete_stale_route(struct client_gr_info *info, */ if ((n >= ZEBRA_MAX_STALE_ROUTE_COUNT) && (info->delete == false)) { - prefix_copy(p, &rn->p); info->current_afi = afi; - info->current_prefix = p; + info->current_prefix = XCALLOC( + MTYPE_TMP, + sizeof(struct prefix)); + prefix_copy( + info->current_prefix, + &rn->p); return n; } } @@ -595,11 +592,7 @@ static int32_t zebra_gr_delete_stale_route(struct client_gr_info *info, * Reset the current prefix to indicate processing completion * of the current AFI */ - if (info->current_prefix) { - XFREE(MTYPE_TMP, info->current_prefix); - info->current_prefix = NULL; - } - continue; + XFREE(MTYPE_TMP, info->current_prefix); } return 0; } diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 48bc985118..7b8af4e6b7 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -62,7 +62,7 @@ static int do_show_ip_route(struct vty *vty, const char *vrf_name, afi_t afi, route_tag_t tag, const struct prefix *longer_prefix_p, bool supernets_only, int type, - unsigned short ospf_instance_id); + unsigned short ospf_instance_id, uint32_t tableid); static void vty_show_ip_route_detail(struct vty *vty, struct route_node *rn, int mcast, bool use_fib, bool show_ng); static void vty_show_ip_route_summary(struct vty *vty, @@ -131,7 +131,7 @@ DEFUN (show_ip_rpf, { bool uj = use_json(argc, argv); return do_show_ip_route(vty, VRF_DEFAULT_NAME, AFI_IP, SAFI_MULTICAST, - false, uj, 0, NULL, false, 0, 0); + false, uj, 0, NULL, false, 0, 0, 0); } DEFUN (show_ip_rpf_addr, @@ -915,12 +915,40 @@ static void do_show_route_helper(struct vty *vty, struct zebra_vrf *zvrf, } } +static void do_show_ip_route_all(struct vty *vty, struct zebra_vrf *zvrf, afi_t afi, + bool use_fib, bool use_json, + route_tag_t tag, + const struct prefix *longer_prefix_p, + bool supernets_only, int type, + unsigned short ospf_instance_id) +{ + struct zebra_router_table *zrt; + rib_table_info_t *info; + + RB_FOREACH (zrt, zebra_router_table_head, + &zrouter.tables) { + info = route_table_get_info(zrt->table); + + if (zvrf != info->zvrf) + continue; + if (zrt->afi != afi || + zrt->safi != SAFI_UNICAST) + continue; + if (zrt->table) + do_show_ip_route(vty, zvrf_name(zvrf), afi, + SAFI_UNICAST, use_fib, use_json, + tag, longer_prefix_p, + supernets_only, type, + ospf_instance_id, zrt->tableid); + } +} + static int do_show_ip_route(struct vty *vty, const char *vrf_name, afi_t afi, safi_t safi, bool use_fib, bool use_json, route_tag_t tag, const struct prefix *longer_prefix_p, bool supernets_only, int type, - unsigned short ospf_instance_id) + unsigned short ospf_instance_id, uint32_t tableid) { struct route_table *table; struct zebra_vrf *zvrf = NULL; @@ -941,7 +969,10 @@ static int do_show_ip_route(struct vty *vty, const char *vrf_name, afi_t afi, return CMD_SUCCESS; } - table = zebra_vrf_table(afi, safi, zvrf_id(zvrf)); + if (tableid) + table = zebra_router_find_table(zvrf, tableid, afi, SAFI_UNICAST); + else + table = zebra_vrf_table(afi, safi, zvrf_id(zvrf)); if (!table) { if (use_json) vty_out(vty, "{}\n"); @@ -950,98 +981,11 @@ static int do_show_ip_route(struct vty *vty, const char *vrf_name, afi_t afi, do_show_route_helper(vty, zvrf, table, afi, use_fib, tag, longer_prefix_p, supernets_only, type, - ospf_instance_id, use_json, 0); - - return CMD_SUCCESS; -} - -DEFPY (show_route_table, - show_route_table_cmd, - "show <ip$ipv4|ipv6$ipv6> route table (1-4294967295)$table [json$json]", - SHOW_STR - IP_STR - IP6_STR - "IP routing table\n" - "Table to display\n" - "The table number to display, if available\n" - JSON_STR) -{ - afi_t afi = ipv4 ? AFI_IP : AFI_IP6; - struct zebra_vrf *zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT); - struct route_table *t; - - t = zebra_router_find_table(zvrf, table, afi, SAFI_UNICAST); - if (t) - do_show_route_helper(vty, zvrf, t, afi, false, 0, false, false, - 0, 0, !!json, table); + ospf_instance_id, use_json, tableid); return CMD_SUCCESS; } -DEFPY (show_route_table_vrf, - show_route_table_vrf_cmd, - "show <ip$ipv4|ipv6$ipv6> route table (1-4294967295)$table vrf NAME$vrf_name [json$json]", - SHOW_STR - IP_STR - IP6_STR - "IP routing table\n" - "Table to display\n" - "The table number to display, if available\n" - VRF_CMD_HELP_STR - JSON_STR) -{ - afi_t afi = ipv4 ? AFI_IP : AFI_IP6; - struct zebra_vrf *zvrf; - struct route_table *t; - vrf_id_t vrf_id = VRF_DEFAULT; - - if (vrf_name) - VRF_GET_ID(vrf_id, vrf_name, !!json); - zvrf = zebra_vrf_lookup_by_id(vrf_id); - - t = zebra_router_find_table(zvrf, table, afi, SAFI_UNICAST); - if (t) - do_show_route_helper(vty, zvrf, t, afi, false, 0, false, false, - 0, 0, !!json, table); - - return CMD_SUCCESS; -} - -DEFPY (show_route_all_table_vrf, - show_route_all_table_vrf_cmd, - "show <ip$ipv4|ipv6$ipv6> route [vrf <NAME$vrf_name|all$vrf_all>] tables [json$json]", - SHOW_STR - IP_STR - IP6_STR - "IP routing table\n" - "Display all tables\n" - VRF_FULL_CMD_HELP_STR - JSON_STR) -{ - afi_t afi = ipv4 ? AFI_IP : AFI_IP6; - struct zebra_vrf *zvrf = NULL; - vrf_id_t vrf_id = VRF_UNKNOWN; - struct zebra_router_table *zrt; - - if (vrf_name) { - VRF_GET_ID(vrf_id, vrf_name, !!json); - zvrf = zebra_vrf_lookup_by_id(vrf_id); - } - - RB_FOREACH (zrt, zebra_router_table_head, &zrouter.tables) { - rib_table_info_t *info = route_table_get_info(zrt->table); - - if (zvrf && zvrf != info->zvrf) - continue; - if (zrt->afi != afi || zrt->safi != SAFI_UNICAST) - continue; - - do_show_route_helper(vty, info->zvrf, zrt->table, afi, false, 0, - false, false, 0, 0, !!json, zrt->tableid); - } - return CMD_SUCCESS; -} - DEFPY (show_ip_nht, show_ip_nht_cmd, "show <ip$ipv4|ipv6$ipv6> <nht|import-check>$type [<A.B.C.D|X:X::X:X>$addr|vrf NAME$vrf_name [<A.B.C.D|X:X::X:X>$addr]|vrf all$vrf_all]", @@ -1512,7 +1456,8 @@ DEFPY (show_route, show_route_cmd, "show\ <\ - ip$ipv4 <fib$fib|route> [vrf <NAME$vrf_name|all$vrf_all>]\ + ip$ipv4 <fib$fib|route> [table <(1-4294967295)$table|all$table_all>]\ + [vrf <NAME$vrf_name|all$vrf_all>]\ [{\ tag (1-4294967295)\ |A.B.C.D/M$prefix longer-prefixes\ @@ -1522,7 +1467,8 @@ DEFPY (show_route, " FRR_IP_REDIST_STR_ZEBRA "$type_str\ |ospf$type_str (1-65535)$ospf_instance_id\ >]\ - |ipv6$ipv6 <fib$fib|route> [vrf <NAME$vrf_name|all$vrf_all>]\ + |ipv6$ipv6 <fib$fib|route> [table <(1-4294967295)$table|all$table_all>]\ + [vrf <NAME$vrf_name|all$vrf_all>]\ [{\ tag (1-4294967295)\ |X:X::X:X/M$prefix longer-prefixes\ @@ -1534,6 +1480,9 @@ DEFPY (show_route, IP_STR "IP forwarding table\n" "IP routing table\n" + "Table to display\n" + "The table number to display\n" + "All tables\n" VRF_FULL_CMD_HELP_STR "Show only routes with tag\n" "Tag value\n" @@ -1546,6 +1495,9 @@ DEFPY (show_route, IPV6_STR "IP forwarding table\n" "IP routing table\n" + "Table to display\n" + "The table number to display\n" + "All tables\n" VRF_FULL_CMD_HELP_STR "Show only routes with tag\n" "Tag value\n" @@ -1557,7 +1509,19 @@ DEFPY (show_route, afi_t afi = ipv4 ? AFI_IP : AFI_IP6; struct vrf *vrf; int type = 0; + struct zebra_vrf *zvrf; + if (!vrf_is_backend_netns()) { + if ((vrf_all || vrf_name) && (table || table_all)) { + if (!!json) + vty_out(vty, "{}\n"); + else { + vty_out(vty, "Linux vrf backend already points to table id\n"); + vty_out(vty, "Either remove table parameter or vrf parameter\n"); + } + return CMD_SUCCESS; + } + } if (type_str) { type = proto_redistnum(afi, type_str); if (type < 0) { @@ -1568,17 +1532,24 @@ DEFPY (show_route, if (vrf_all) { RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { - struct zebra_vrf *zvrf; - struct route_table *table; + struct route_table *route_table; if ((zvrf = vrf->info) == NULL - || (table = zvrf->table[afi][SAFI_UNICAST]) == NULL) + || (route_table = zvrf->table[afi][SAFI_UNICAST]) == NULL) continue; - do_show_ip_route( - vty, zvrf_name(zvrf), afi, SAFI_UNICAST, !!fib, - !!json, tag, prefix_str ? prefix : NULL, - !!supernets_only, type, ospf_instance_id); + if (table_all) + do_show_ip_route_all(vty, zvrf, afi, + !!fib, !!json, + tag, prefix_str ? prefix : NULL, + !!supernets_only, type, + ospf_instance_id); + else + do_show_ip_route(vty, zvrf_name(zvrf), afi, + SAFI_UNICAST, !!fib, !!json, tag, + prefix_str ? prefix : NULL, + !!supernets_only, type, + ospf_instance_id, table); } } else { vrf_id_t vrf_id = VRF_DEFAULT; @@ -1586,9 +1557,21 @@ DEFPY (show_route, if (vrf_name) VRF_GET_ID(vrf_id, vrf_name, !!json); vrf = vrf_lookup_by_id(vrf_id); - do_show_ip_route(vty, vrf->name, afi, SAFI_UNICAST, !!fib, - !!json, tag, prefix_str ? prefix : NULL, - !!supernets_only, type, ospf_instance_id); + if (vrf) + zvrf = vrf->info; + if (!vrf || !zvrf) + return CMD_SUCCESS; + + if (table_all) + do_show_ip_route_all(vty, zvrf, afi, + !!fib, !!json, + tag, prefix_str ? prefix : NULL, + !!supernets_only, type, + ospf_instance_id); + else + do_show_ip_route(vty, vrf->name, afi, SAFI_UNICAST, !!fib, + !!json, tag, prefix_str ? prefix : NULL, + !!supernets_only, type, ospf_instance_id, table); } return CMD_SUCCESS; @@ -3539,10 +3522,6 @@ void zebra_vty_init(void) install_element(VIEW_NODE, &show_vrf_cmd); install_element(VIEW_NODE, &show_vrf_vni_cmd); install_element(VIEW_NODE, &show_route_cmd); - install_element(VIEW_NODE, &show_route_table_cmd); - if (vrf_is_backend_netns()) - install_element(VIEW_NODE, &show_route_table_vrf_cmd); - install_element(VIEW_NODE, &show_route_all_table_vrf_cmd); install_element(VIEW_NODE, &show_route_detail_cmd); install_element(VIEW_NODE, &show_route_summary_cmd); install_element(VIEW_NODE, &show_ip_nht_cmd); |
