ret = route_map_apply(rmap, dest_p, RMAP_BGP, &path);
if (ret != RMAP_PERMITMATCH)
bgp_attr_flush(&dummy_attr);
- else
+ else {
+ if (BGP_DEBUG(update, UPDATE_OUT))
+ zlog_debug(
+ "%s: Condition map routes present in BGP table",
+ __func__);
+
return ret;
+ }
}
}
+
+ if (BGP_DEBUG(update, UPDATE_OUT))
+ zlog_debug("%s: Condition map routes not present in BGP table",
+ __func__);
+
return ret;
}
static void bgp_conditional_adv_routes(struct peer *peer, afi_t afi,
safi_t safi, struct bgp_table *table,
struct route_map *rmap,
- enum update_type advertise)
+ enum update_type update_type)
{
int addpath_capable;
struct bgp_dest *dest;
if (!subgrp)
return;
+ if (BGP_DEBUG(update, UPDATE_OUT))
+ zlog_debug("%s: %s routes to/from %s for %s", __func__,
+ update_type == ADVERTISE ? "Advertise" : "Withdraw",
+ peer->host, get_afi_safi_str(afi, safi, false));
+
addpath_capable = bgp_addpath_encode_tx(peer, afi, safi);
for (dest = bgp_table_top(table); dest; dest = bgp_route_next(dest)) {
* on same peer, routes in advertise-map may not
* be advertised as expected.
*/
- if ((advertise == ADVERTISE)
+ if ((update_type == ADVERTISE)
&& subgroup_announce_check(dest, pi, subgrp,
dest_p, &attr,
true))
bgp = THREAD_ARG(t);
assert(bgp);
- bgp->t_condition_check = NULL;
thread_add_timer(bm->master, bgp_conditional_adv_timer, bgp,
CONDITIONAL_ROUTES_POLL_TIME, &bgp->t_condition_check);
&& !peer->advmap_table_change)
continue;
+ if (BGP_DEBUG(update, UPDATE_OUT)) {
+ if (peer->advmap_table_change)
+ zlog_debug(
+ "%s: %s - routes changed in BGP table.",
+ __func__, peer->host);
+ if (peer->advmap_config_change[afi][safi])
+ zlog_debug(
+ "%s: %s for %s - advertise/condition map configuration is changed.",
+ __func__, peer->host,
+ get_afi_safi_str(afi, safi,
+ false));
+ }
+
/* cmap (route-map attached to exist-map or
* non-exist-map) map validation
*/
* or route-map filter configuration on the same peer.
*/
if (peer->advmap_config_change[afi][safi]) {
+
+ if (BGP_DEBUG(update, UPDATE_OUT))
+ zlog_debug(
+ "%s: Configuration is changed on peer %s for %s, send the normal update first.",
+ __func__, peer->host,
+ get_afi_safi_str(afi, safi,
+ false));
+
paf = peer_af_find(peer, afi, safi);
if (paf) {
update_subgroup_split_peer(paf, NULL);
/* advertise-map is already configured on atleast one of its
* neighbors (AFI/SAFI). So just increment the counter.
*/
- if (++bgp->condition_filter_count > 1)
+ if (++bgp->condition_filter_count > 1) {
+ if (BGP_DEBUG(update, UPDATE_OUT))
+ zlog_debug("%s: condition_filter_count %d", __func__,
+ bgp->condition_filter_count);
+
return;
+ }
/* Register for conditional routes polling timer */
thread_add_timer(bm->master, bgp_conditional_adv_timer, bgp,
* it is configured on more than one neighbor(AFI/SAFI).
* So there's nothing to do except decrementing the counter.
*/
- if (--bgp->condition_filter_count != 0)
+ if (--bgp->condition_filter_count != 0) {
+ if (BGP_DEBUG(update, UPDATE_OUT))
+ zlog_debug("%s: condition_filter_count %d", __func__,
+ bgp->condition_filter_count);
+
return;
+ }
/* Last filter removed. So cancel conditional routes polling thread. */
THREAD_OFF(bgp->t_condition_check);
-------------------------
TC11: R3 BGP convergence, without advertise-map configuration.
All routes are advertised to R3.
+
TC21: exist-map routes present in R2's BGP table.
advertise-map routes present in R2's BGP table are advertised to R3.
TC22: exist-map routes not present in R2's BGP table
advertise-map routes present in R2's BGP table are advertised to R3.
TC32: non-exist-map routes present in R2's BGP table
advertise-map routes present in R2's BGP table are withdrawn from R3.
+
TC41: non-exist-map route-map configuration removed in R2.
advertise-map routes present in R2's BGP table are advertised to R3.
TC42: exist-map route-map configuration removed in R2
advertise-map routes present in R2's BGP table are withdrawn from R3.
-Conditional advertisement along with Route-map Filter
------------------------------------------------------
+Conditional advertisement(received routes) along with Route-map Filter
+----------------------------------------------------------------------
TC51: exist-map routes present in R2's BGP table, with route-map filter.
All routes are withdrawn from R3 except advertise-map routes.
TC52: exist-map routes present in R2's BGP table, without route-map filter.
All routes are withdrawn from R3 including advertise-map routes.
TC54: non-exist-map routes present in R2's BGP table, without route-map filter.
All routes are advertised to R3 except advertise-map routes.
+
TC61: exist-map routes not present in R2's BGP table, with route-map filter.
All routes are withdrawn from R3 including advertise-map routes.
TC62: exist-map routes not present in R2's BGP table, without route-map filter.
TC64: non-exist-map routes not present in R2's BGP table, without route-map filter.
All routes are advertised to R3 including advertise-map routes.
+Conditional advertisement(attached routes) along with Route-map Filter
+-----------------------------------------------------------------
+TC71: exist-map routes present in R2's BGP table, with route-map filter.
+ All routes are withdrawn from R3 except advertise-map routes.
+TC72: exist-map routes present in R2's BGP table, without route-map filter.
+ All routes are advertised to R3 including advertise-map routes.
+TC73: non-exist-map routes present in R2's BGP table, with route-map filter.
+ All routes are withdrawn from R3 including advertise-map routes.
+TC74: non-exist-map routes present in R2's BGP table, without route-map filter.
+ All routes are advertised to R3 except advertise-map routes.
+
+TC81: exist-map routes not present in R2's BGP table, with route-map filter.
+ All routes are withdrawn from R3 including advertise-map routes.
+TC82: exist-map routes not present in R2's BGP table, without route-map filter.
+ All routes are advertised to R3 except advertise-map routes.
+TC83: non-exist-map routes not present in R2's BGP table, with route-map filter.
+ All routes are withdrawn from R3 except advertise-map routes.
+TC84: non-exist-map routes not present in R2's BGP table, without route-map filter.
+ All routes are advertised to R3 including advertise-map routes.
+
+TC91: exist-map routes present in R2's BGP table, with route-map filter and network.
+ All routes are advertised to R3 including advertise-map routes.
+TC92: exist-map routes present in R2's BGP table, with route-map filter and no network.
+ All routes are advertised to R3 except advertise-map routes.
+TC93: non-exist-map routes not present in R2's BGP table, with route-map filter and network.
+ All routes are advertised to R3 including advertise-map routes.
+TC94: non-exist-map routes not present in R2's BGP table, with route-map filter and no network.
+ All routes are advertised to R3 except advertise-map routes.
i.e.
+----------------+-------------------------+------------------------+
"192.0.2.1/32": [{"protocol": "bgp"}],
"192.0.2.5/32": [{"protocol": "bgp"}],
"10.139.224.0/20": [{"protocol": "bgp"}],
+ "203.0.113.1/32": [{"protocol": "bgp"}],
}
return topotest.json_cmp(output, expected)
"192.0.2.1/32": None,
"192.0.2.5/32": None,
"10.139.224.0/20": None,
+ "203.0.113.1/32": None,
}
return topotest.json_cmp(output, expected)
+ # BGP conditional advertisement with route-maps
+ # EXIST-MAP, ADV-MAP-1 and RMAP-1
def _exist_map_routes_present(router):
return _all_routes_advertised(router)
"192.0.2.1/32": None,
"192.0.2.5/32": [{"protocol": "bgp"}],
"10.139.224.0/20": None,
+ "203.0.113.1/32": [{"protocol": "bgp"}],
}
return topotest.json_cmp(output, expected)
"192.0.2.1/32": None,
"192.0.2.5/32": [{"protocol": "bgp"}],
"10.139.224.0/20": None,
+ "203.0.113.1/32": [{"protocol": "bgp"}],
}
return topotest.json_cmp(output, expected)
"192.0.2.1/32": [{"protocol": "bgp"}],
"192.0.2.5/32": [{"protocol": "bgp"}],
"10.139.224.0/20": [{"protocol": "bgp"}],
+ "203.0.113.1/32": [{"protocol": "bgp"}],
}
return topotest.json_cmp(output, expected)
"192.0.2.1/32": [{"protocol": "bgp"}],
"192.0.2.5/32": None,
"10.139.224.0/20": [{"protocol": "bgp"}],
+ "203.0.113.1/32": None,
}
return topotest.json_cmp(output, expected)
def _non_exist_map_routes_not_present_no_rmap_filter(router):
return _non_exist_map_routes_not_present(router)
+ # BGP conditional advertisement with route-maps
+ # EXIST-MAP, ADV-MAP-2 and RMAP-2
+ def _exist_map_routes_not_present_rmap2_filter(router):
+ return _all_routes_withdrawn(router)
+
+ def _exist_map_routes_not_present_no_rmap2_filter(router):
+ output = json.loads(router.vtysh_cmd("show ip route json"))
+ expected = {
+ "0.0.0.0/0": None,
+ "192.0.2.1/32": [{"protocol": "bgp"}],
+ "192.0.2.5/32": [{"protocol": "bgp"}],
+ "10.139.224.0/20": [{"protocol": "bgp"}],
+ "203.0.113.1/32": None,
+ }
+ return topotest.json_cmp(output, expected)
+
+ def _non_exist_map_routes_not_present_rmap2_filter(router):
+ output = json.loads(router.vtysh_cmd("show ip route json"))
+ expected = {
+ "0.0.0.0/0": None,
+ "192.0.2.1/32": None,
+ "192.0.2.5/32": None,
+ "10.139.224.0/20": None,
+ "203.0.113.1/32": [{"protocol": "bgp"}],
+ }
+ return topotest.json_cmp(output, expected)
+
+ def _non_exist_map_routes_not_present_no_rmap2_filter(router):
+ return _non_exist_map_routes_not_present(router)
+
+ def _exist_map_routes_present_rmap2_filter(router):
+ return _non_exist_map_routes_not_present_rmap2_filter(router)
+
+ def _exist_map_routes_present_no_rmap2_filter(router):
+ return _all_routes_advertised(router)
+
+ def _non_exist_map_routes_present_rmap2_filter(router):
+ return _all_routes_withdrawn(router)
+
+ def _non_exist_map_routes_present_no_rmap2_filter(router):
+ output = json.loads(router.vtysh_cmd("show ip route json"))
+ expected = {
+ "0.0.0.0/0": [{"protocol": "bgp"}],
+ "192.0.2.1/32": [{"protocol": "bgp"}],
+ "192.0.2.5/32": [{"protocol": "bgp"}],
+ "10.139.224.0/20": [{"protocol": "bgp"}],
+ "203.0.113.1/32": None,
+ }
+ return topotest.json_cmp(output, expected)
+
+ def _exist_map_routes_present_rmap2_network(router):
+ return _non_exist_map_routes_not_present_rmap2_filter(router)
+
+ def _exist_map_routes_present_rmap2_no_network(router):
+ return _all_routes_withdrawn(router)
+
+ def _non_exist_map_routes_not_present_rmap2_network(router):
+ return _non_exist_map_routes_not_present_rmap2_filter(router)
+
+ def _non_exist_map_routes_not_present_rmap2_no_network(router):
+ return _all_routes_withdrawn(router)
+
# TC11: R3 BGP convergence, without advertise-map configuration.
# All routes are advertised to R3.
test_func = functools.partial(_all_routes_advertised, router3)
configure terminal
router bgp 2
address-family ipv4 unicast
- neighbor 10.10.20.3 advertise-map ADV-MAP exist-map EXIST-MAP
+ neighbor 10.10.20.3 advertise-map ADV-MAP-1 exist-map EXIST-MAP
"""
)
configure terminal
router bgp 2
address-family ipv4 unicast
- neighbor 10.10.20.3 advertise-map ADV-MAP non-exist-map EXIST-MAP
+ neighbor 10.10.20.3 advertise-map ADV-MAP-1 non-exist-map EXIST-MAP
"""
)
configure terminal
router bgp 2
address-family ipv4 unicast
- neighbor 10.10.20.3 advertise-map ADV-MAP exist-map EXIST-MAP
+ neighbor 10.10.20.3 advertise-map ADV-MAP-1 exist-map EXIST-MAP
"""
)
match community DEFAULT-ROUTE
match ip address prefix-list DEFAULT-ROUTE
!
- route-map RMAP deny 10
- match ip address prefix-list IP1
- !
router bgp 2
address-family ipv4 unicast
- neighbor 10.10.20.3 route-map RMAP out
+ neighbor 10.10.20.3 route-map RMAP-1 out
"""
)
configure terminal
router bgp 2
address-family ipv4 unicast
- no neighbor 10.10.20.3 route-map RMAP out
+ no neighbor 10.10.20.3 route-map RMAP-1 out
"""
)
configure terminal
router bgp 2
address-family ipv4 unicast
- neighbor 10.10.20.3 route-map RMAP out
- neighbor 10.10.20.3 advertise-map ADV-MAP non-exist-map EXIST-MAP
+ neighbor 10.10.20.3 route-map RMAP-1 out
+ neighbor 10.10.20.3 advertise-map ADV-MAP-1 non-exist-map EXIST-MAP
"""
)
configure terminal
router bgp 2
address-family ipv4 unicast
- no neighbor 10.10.20.3 route-map RMAP out
+ no neighbor 10.10.20.3 route-map RMAP-1 out
"""
)
configure terminal
router bgp 2
address-family ipv4 unicast
- neighbor 10.10.20.3 route-map RMAP out
- neighbor 10.10.20.3 advertise-map ADV-MAP exist-map EXIST-MAP
+ neighbor 10.10.20.3 route-map RMAP-1 out
+ neighbor 10.10.20.3 advertise-map ADV-MAP-1 exist-map EXIST-MAP
"""
)
configure terminal
router bgp 2
address-family ipv4 unicast
- no neighbor 10.10.20.3 route-map RMAP out
+ no neighbor 10.10.20.3 route-map RMAP-1 out
"""
)
configure terminal
router bgp 2
address-family ipv4 unicast
- neighbor 10.10.20.3 route-map RMAP out
- neighbor 10.10.20.3 advertise-map ADV-MAP non-exist-map EXIST-MAP
+ neighbor 10.10.20.3 route-map RMAP-1 out
+ neighbor 10.10.20.3 advertise-map ADV-MAP-1 non-exist-map EXIST-MAP
"""
)
configure terminal
router bgp 2
address-family ipv4 unicast
- no neighbor 10.10.20.3 route-map RMAP out
+ no neighbor 10.10.20.3 route-map RMAP-1 out
"""
)
logger.info(msg + passed)
+ # TC71: exist-map routes present in R2's BGP table, with route-map filter.
+ # All routes are withdrawn from R3 except advertise-map routes.
+ router1.vtysh_cmd(
+ """
+ configure terminal
+ router bgp 1
+ address-family ipv4 unicast
+ network 0.0.0.0/0 route-map DEF
+ """
+ )
+ router2.vtysh_cmd(
+ """
+ configure terminal
+ router bgp 2
+ address-family ipv4 unicast
+ neighbor 10.10.20.3 route-map RMAP-2 out
+ neighbor 10.10.20.3 advertise-map ADV-MAP-2 exist-map EXIST-MAP
+ """
+ )
+
+ test_func = functools.partial(_exist_map_routes_present_rmap2_filter, router3)
+ success, result = topotest.run_and_expect(test_func, None, count=90, wait=1)
+
+ msg = "TC71: exist-map routes present, route-map filter - "
+ assert result is None, msg + failed
+
+ logger.info(msg + passed)
+
+ # TC72: exist-map routes present in R2's BGP table, without route-map filter.
+ # All routes are advertised to R3 including advertise-map routes.
+ router2.vtysh_cmd(
+ """
+ configure terminal
+ router bgp 2
+ address-family ipv4 unicast
+ no neighbor 10.10.20.3 route-map RMAP-2 out
+ """
+ )
+
+ test_func = functools.partial(_exist_map_routes_present_no_rmap2_filter, router3)
+ success, result = topotest.run_and_expect(test_func, None, count=90, wait=1)
+
+ msg = "TC72: exist-map routes present, no route-map filter - "
+ assert result is None, msg + failed
+
+ logger.info(msg + passed)
+
+ # TC73: non-exist-map routes present in R2's BGP table, with route-map filter.
+ # All routes are advertised to R3 including advertise-map routes.
+ router2.vtysh_cmd(
+ """
+ configure terminal
+ router bgp 2
+ address-family ipv4 unicast
+ neighbor 10.10.20.3 route-map RMAP-2 out
+ neighbor 10.10.20.3 advertise-map ADV-MAP-2 non-exist-map EXIST-MAP
+ """
+ )
+
+ test_func = functools.partial(_non_exist_map_routes_present_rmap2_filter, router3)
+ success, result = topotest.run_and_expect(test_func, None, count=90, wait=1)
+
+ msg = "TC73: non-exist-map routes present, route-map filter - "
+ assert result is None, msg + failed
+
+ logger.info(msg + passed)
+
+ # TC74: non-exist-map routes present in R2's BGP table, without route-map filter.
+ # All routes are advertised to R3 including advertise-map routes.
+ router2.vtysh_cmd(
+ """
+ configure terminal
+ router bgp 2
+ address-family ipv4 unicast
+ no neighbor 10.10.20.3 route-map RMAP-2 out
+ """
+ )
+
+ test_func = functools.partial(
+ _non_exist_map_routes_present_no_rmap2_filter, router3
+ )
+ success, result = topotest.run_and_expect(test_func, None, count=90, wait=1)
+
+ msg = "TC74: non-exist-map routes present, no route-map filter - "
+ assert result is None, msg + failed
+
+ logger.info(msg + passed)
+
+ # TC81: exist-map routes not present in R2's BGP table, with route-map filter.
+ # All routes are withdrawn from R3 including advertise-map routes.
+ router1.vtysh_cmd(
+ """
+ configure terminal
+ router bgp 1
+ address-family ipv4 unicast
+ no network 0.0.0.0/0 route-map DEF
+ """
+ )
+ router2.vtysh_cmd(
+ """
+ configure terminal
+ router bgp 2
+ address-family ipv4 unicast
+ neighbor 10.10.20.3 route-map RMAP-2 out
+ neighbor 10.10.20.3 advertise-map ADV-MAP-2 exist-map EXIST-MAP
+ """
+ )
+
+ test_func = functools.partial(_exist_map_routes_not_present_rmap2_filter, router3)
+ success, result = topotest.run_and_expect(test_func, None, count=90, wait=1)
+
+ msg = "TC81: exist-map routes not present, route-map filter - "
+ assert result is None, msg + failed
+
+ logger.info(msg + passed)
+
+ # TC82: exist-map routes not present in R2's BGP table, without route-map filter.
+ # All routes are advertised to R3 except advertise-map routes.
+ router2.vtysh_cmd(
+ """
+ configure terminal
+ router bgp 2
+ address-family ipv4 unicast
+ no neighbor 10.10.20.3 route-map RMAP-2 out
+ """
+ )
+
+ test_func = functools.partial(
+ _exist_map_routes_not_present_no_rmap2_filter, router3
+ )
+ success, result = topotest.run_and_expect(test_func, None, count=90, wait=1)
+
+ msg = "TC82: exist-map routes not present, no route-map filter - "
+ assert result is None, msg + failed
+
+ logger.info(msg + passed)
+
+ # TC83: non-exist-map routes not present in R2's BGP table, with route-map filter.
+ # All routes are advertised to R3 including advertise-map routes.
+ router2.vtysh_cmd(
+ """
+ configure terminal
+ router bgp 2
+ address-family ipv4 unicast
+ neighbor 10.10.20.3 route-map RMAP-2 out
+ neighbor 10.10.20.3 advertise-map ADV-MAP-2 non-exist-map EXIST-MAP
+ """
+ )
+
+ test_func = functools.partial(
+ _non_exist_map_routes_not_present_rmap2_filter, router3
+ )
+ success, result = topotest.run_and_expect(test_func, None, count=90, wait=1)
+
+ msg = "TC83: non-exist-map routes not present, route-map filter - "
+ assert result is None, msg + failed
+
+ logger.info(msg + passed)
+
+ # TC84: non-exist-map routes not present in R2's BGP table, without route-map filter.
+ # All routes are advertised to R3 including advertise-map routes.
+ router2.vtysh_cmd(
+ """
+ configure terminal
+ router bgp 2
+ address-family ipv4 unicast
+ no neighbor 10.10.20.3 route-map RMAP-2 out
+ """
+ )
+
+ test_func = functools.partial(
+ _non_exist_map_routes_not_present_no_rmap2_filter, router3
+ )
+ success, result = topotest.run_and_expect(test_func, None, count=90, wait=1)
+
+ msg = "TC84: non-exist-map routes not present, no route-map filter - "
+ assert result is None, msg + failed
+
+ logger.info(msg + passed)
+
+ # TC91: exist-map routes present in R2's BGP table, with route-map filter and network.
+ # All routes are advertised to R3 including advertise-map routes.
+ router1.vtysh_cmd(
+ """
+ configure terminal
+ router bgp 1
+ address-family ipv4 unicast
+ network 0.0.0.0/0 route-map DEF
+ """
+ )
+ router2.vtysh_cmd(
+ """
+ configure terminal
+ router bgp 2
+ address-family ipv4 unicast
+ neighbor 10.10.20.3 route-map RMAP-2 out
+ neighbor 10.10.20.3 advertise-map ADV-MAP-2 exist-map EXIST-MAP
+ """
+ )
+
+ test_func = functools.partial(_exist_map_routes_present_rmap2_network, router3)
+ success, result = topotest.run_and_expect(test_func, None, count=90, wait=1)
+
+ msg = "TC91: exist-map routes present, route-map filter and network - "
+ assert result is None, msg + failed
+
+ logger.info(msg + passed)
+
+ # TC92: exist-map routes present in R2's BGP table, with route-map filter and no network.
+ # All routes are advertised to R3 except advertise-map routes.
+ router2.vtysh_cmd(
+ """
+ configure terminal
+ router bgp 2
+ address-family ipv4 unicast
+ no network 203.0.113.1/32
+ """
+ )
+
+ test_func = functools.partial(_exist_map_routes_present_rmap2_no_network, router3)
+ success, result = topotest.run_and_expect(test_func, None, count=90, wait=1)
+
+ msg = "TC92: exist-map routes present, route-map filter and no network - "
+ assert result is None, msg + failed
+
+ logger.info(msg + passed)
+
+ # TC93: non-exist-map routes not present in R2's BGP table, with route-map filter and network.
+ # All routes are advertised to R3 including advertise-map routes.
+ router1.vtysh_cmd(
+ """
+ configure terminal
+ router bgp 1
+ address-family ipv4 unicast
+ no network 0.0.0.0/0 route-map DEF
+ """
+ )
+ router2.vtysh_cmd(
+ """
+ configure terminal
+ router bgp 2
+ address-family ipv4 unicast
+ network 203.0.113.1/32
+ neighbor 10.10.20.3 advertise-map ADV-MAP-2 non-exist-map EXIST-MAP
+ """
+ )
+
+ test_func = functools.partial(
+ _non_exist_map_routes_not_present_rmap2_network, router3
+ )
+ success, result = topotest.run_and_expect(test_func, None, count=90, wait=1)
+
+ msg = "TC93: non-exist-map routes not present, route-map filter and network - "
+ assert result is None, msg + failed
+
+ logger.info(msg + passed)
+
+ # TC94: non-exist-map routes not present in R2's BGP table, with route-map filter and no network.
+ # All routes are advertised to R3 except advertise-map routes.
+ router2.vtysh_cmd(
+ """
+ configure terminal
+ router bgp 2
+ address-family ipv4 unicast
+ no network 203.0.113.1/32
+ """
+ )
+
+ test_func = functools.partial(
+ _non_exist_map_routes_not_present_rmap2_no_network, router3
+ )
+ success, result = topotest.run_and_expect(test_func, None, count=90, wait=1)
+
+ msg = "TC94: non-exist-map routes not present, route-map filter and no network - "
+ assert result is None, msg + failed
+
+ logger.info(msg + passed)
+
def test_memory_leak():
"Run the memory leak test and report results."