diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 15c1df8473..941bae4ff4 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -550,6 +550,7 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new, bool same_esi; bool old_proxy; bool new_proxy; + bool new_origin, exist_origin; *paths_eq = 0; @@ -794,8 +795,12 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new, * - BGP_ROUTE_AGGREGATE * - BGP_ROUTE_REDISTRIBUTE */ - if (!(new->sub_type == BGP_ROUTE_NORMAL || - new->sub_type == BGP_ROUTE_IMPORTED)) { + new_origin = !(new->sub_type == BGP_ROUTE_NORMAL || + new->sub_type == BGP_ROUTE_IMPORTED); + exist_origin = !(exist->sub_type == BGP_ROUTE_NORMAL || + exist->sub_type == BGP_ROUTE_IMPORTED); + + if (new_origin && !exist_origin) { *reason = bgp_path_selection_local_route; if (debug) zlog_debug( @@ -804,8 +809,7 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new, return 1; } - if (!(exist->sub_type == BGP_ROUTE_NORMAL || - exist->sub_type == BGP_ROUTE_IMPORTED)) { + if (!new_origin && exist_origin) { *reason = bgp_path_selection_local_route; if (debug) zlog_debug( diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/ce1/bgpd.conf b/tests/topotests/bgp_l3vpn_to_bgp_vrf/ce1/bgpd.conf index 6e6b9edde2..ae574319b3 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/ce1/bgpd.conf +++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/ce1/bgpd.conf @@ -18,6 +18,8 @@ router bgp 5227 network 5.1.0.0/24 route-map rm-nh network 5.1.1.0/24 route-map rm-nh redistribute sharp route-map sharp-nh + network 6.0.1.0/24 route-map rm-nh + network 6.0.2.0/24 route-map rm-nh-same neighbor 192.168.1.1 activate exit-address-family ! @@ -41,5 +43,13 @@ route-map sharp-nh permit 10 set extcommunity rt 80:987 set community 0:65 ! - +route-map rm-nh-same permit 10 + match ip address al-any + set ip next-hop 99.0.0.1 + set local-preference 100 + set metric 100 + set large-community 12:34:11 + set extcommunity rt 89:123 + set community 0:67 +! end diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/ce2/bgpd.conf b/tests/topotests/bgp_l3vpn_to_bgp_vrf/ce2/bgpd.conf index 618acabd9f..599e2ddc1e 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/ce2/bgpd.conf +++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/ce2/bgpd.conf @@ -18,6 +18,8 @@ router bgp 5227 network 5.1.0.0/24 route-map rm-nh network 5.1.1.0/24 route-map rm-nh redistribute sharp route-map sharp-nh + network 6.0.1.0/24 route-map rm-nh + network 6.0.2.0/24 route-map rm-nh-same neighbor 192.168.1.1 activate exit-address-family ! @@ -41,5 +43,13 @@ route-map sharp-nh permit 10 set extcommunity rt 70:456 set community 0:66 ! - +route-map rm-nh-same permit 10 + match ip address al-any + set ip next-hop 99.0.0.2 + set local-preference 100 + set metric 100 + set large-community 12:34:12 + set extcommunity rt 89:123 + set community 0:67 +! end diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/ce3/bgpd.conf b/tests/topotests/bgp_l3vpn_to_bgp_vrf/ce3/bgpd.conf index 85c5973e6f..e316de5690 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/ce3/bgpd.conf +++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/ce3/bgpd.conf @@ -17,6 +17,8 @@ router bgp 5227 network 99.0.0.3/32 network 5.1.2.0/24 route-map rm-nh network 5.1.3.0/24 route-map rm-nh + network 6.0.1.0/24 route-map rm-nh + network 6.0.2.0/24 route-map rm-nh-same neighbor 192.168.1.1 activate exit-address-family ! @@ -31,5 +33,13 @@ route-map rm-nh permit 10 set extcommunity rt 89:123 set community 0:67 ! - +route-map rm-nh-same permit 10 + match ip address al-any + set ip next-hop 99.0.0.3 + set local-preference 100 + set metric 100 + set large-community 12:34:13 + set extcommunity rt 89:123 + set community 0:67 +! end diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/ce4/bgpd.conf b/tests/topotests/bgp_l3vpn_to_bgp_vrf/ce4/bgpd.conf index 6a5075a000..60d9e93108 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/ce4/bgpd.conf +++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/ce4/bgpd.conf @@ -17,6 +17,8 @@ router bgp 5228 vrf ce4-cust2 network 99.0.0.4/32 network 5.4.2.0/24 route-map rm-nh network 5.4.3.0/24 route-map rm-nh + network 6.0.1.0/24 route-map rm-nh + network 6.0.2.0/24 route-map rm-nh-same neighbor 192.168.2.1 activate exit-address-family ! @@ -31,5 +33,13 @@ route-map rm-nh permit 10 set extcommunity rt 89:123 set community 0:67 ! - +route-map rm-nh-same permit 10 + match ip address al-any + set ip next-hop 99.0.0.4 + set local-preference 100 + set metric 100 + set large-community 12:34:14 + set extcommunity rt 89:123 + set community 0:67 +! end diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/check_routes.py b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/check_routes.py index f5a29b95c9..f553513b9c 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/check_routes.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/check_routes.py @@ -14,6 +14,8 @@ from bgprib import bgpribRequireVpnRoutes, bgpribRequireUnicastRoutes want = [ {"p": "5.1.0.0/24", "n": "99.0.0.1"}, {"p": "5.1.1.0/24", "n": "99.0.0.1"}, + {"p": "6.0.1.0/24", "n": "99.0.0.1"}, + {"p": "6.0.2.0/24", "n": "99.0.0.1"}, {"p": "99.0.0.1/32", "n": "0.0.0.0"}, ] bgpribRequireUnicastRoutes("ce1", "ipv4", "", "Cust 1 routes in ce1", want) @@ -21,6 +23,8 @@ bgpribRequireUnicastRoutes("ce1", "ipv4", "", "Cust 1 routes in ce1", want) want = [ {"p": "5.1.0.0/24", "n": "99.0.0.2"}, {"p": "5.1.1.0/24", "n": "99.0.0.2"}, + {"p": "6.0.1.0/24", "n": "99.0.0.2"}, + {"p": "6.0.2.0/24", "n": "99.0.0.2"}, {"p": "99.0.0.2/32", "n": "0.0.0.0"}, ] bgpribRequireUnicastRoutes("ce2", "ipv4", "", "Cust 2 routes in ce1", want) @@ -28,6 +32,8 @@ bgpribRequireUnicastRoutes("ce2", "ipv4", "", "Cust 2 routes in ce1", want) want = [ {"p": "5.1.2.0/24", "n": "99.0.0.3"}, {"p": "5.1.3.0/24", "n": "99.0.0.3"}, + {"p": "6.0.1.0/24", "n": "99.0.0.3"}, + {"p": "6.0.2.0/24", "n": "99.0.0.3"}, {"p": "99.0.0.3/32", "n": "0.0.0.0"}, ] bgpribRequireUnicastRoutes("ce3", "ipv4", "", "Cust 3 routes in ce1", want) @@ -35,6 +41,8 @@ bgpribRequireUnicastRoutes("ce3", "ipv4", "", "Cust 3 routes in ce1", want) want = [ {"p": "5.4.2.0/24", "n": "99.0.0.4"}, {"p": "5.4.3.0/24", "n": "99.0.0.4"}, + {"p": "6.0.1.0/24", "n": "99.0.0.4"}, + {"p": "6.0.2.0/24", "n": "99.0.0.4"}, {"p": "99.0.0.4/32", "n": "0.0.0.0"}, ] bgpribRequireUnicastRoutes("ce4", "ipv4", "ce4-cust2", "Cust 4 routes in ce1", want) @@ -49,6 +57,8 @@ bgpribRequireUnicastRoutes("ce4", "ipv4", "ce4-cust2", "Cust 4 routes in ce1", w want_r1_cust1_routes = [ {"p": "5.1.0.0/24", "n": "99.0.0.1"}, {"p": "5.1.1.0/24", "n": "99.0.0.1"}, + {"p": "6.0.1.0/24", "n": "99.0.0.1"}, + {"p": "6.0.2.0/24", "n": "99.0.0.1"}, {"p": "99.0.0.1/32", "n": "192.168.1.2"}, ] bgpribRequireUnicastRoutes( @@ -58,6 +68,8 @@ bgpribRequireUnicastRoutes( want_r3_cust1_routes = [ {"p": "5.1.0.0/24", "n": "99.0.0.2"}, {"p": "5.1.1.0/24", "n": "99.0.0.2"}, + {"p": "6.0.1.0/24", "n": "99.0.0.2"}, + {"p": "6.0.2.0/24", "n": "99.0.0.2"}, {"p": "99.0.0.2/32", "n": "192.168.1.2"}, ] bgpribRequireUnicastRoutes( @@ -67,6 +79,8 @@ bgpribRequireUnicastRoutes( want_r4_cust1_routes = [ {"p": "5.1.2.0/24", "n": "99.0.0.3"}, {"p": "5.1.3.0/24", "n": "99.0.0.3"}, + {"p": "6.0.1.0/24", "n": "99.0.0.3"}, + {"p": "6.0.2.0/24", "n": "99.0.0.3"}, {"p": "99.0.0.3/32", "n": "192.168.1.2"}, ] bgpribRequireUnicastRoutes( @@ -76,6 +90,8 @@ bgpribRequireUnicastRoutes( want_r4_cust2_routes = [ {"p": "5.4.2.0/24", "n": "99.0.0.4"}, {"p": "5.4.3.0/24", "n": "99.0.0.4"}, + {"p": "6.0.1.0/24", "n": "99.0.0.4"}, + {"p": "6.0.2.0/24", "n": "99.0.0.4"}, {"p": "99.0.0.4/32", "n": "192.168.2.2"}, ] bgpribRequireUnicastRoutes( @@ -152,23 +168,27 @@ else: luCommand( "r1", 'vtysh -c "show bgp ipv4 vpn"', - r"Distinguisher: *10:1.*5.1.0.0/24 *99.0.0.1\b.*5.1.1.0/24 *99.0.0.1\b.*99.0.0.1/32 *192.168.1.2\b", + r"Distinguisher: *10:1.*5.1.0.0/24 *99.0.0.1\b.*5.1.1.0/24 *99.0.0.1\b.*6.0.1.0/24 *99.0.0.1\b.*6.0.2.0/24 *99.0.0.1\b.*99.0.0.1/32 *192.168.1.2\b", "pass", "vrf->vpn routes", ) luCommand( "r3", 'vtysh -c "show bgp ipv4 vpn"', - r"Distinguisher: *10:3.*5.1.0.0/24 *99.0.0.2\b.*5.1.1.0/24 *99.0.0.2\b.*99.0.0.2/32 *192.168.1.2\b", + r"Distinguisher: *10:3.*5.1.0.0/24 *99.0.0.2\b.*5.1.1.0/24 *99.0.0.2\b.*6.0.1.0/24 *99.0.0.2\b.*6.0.2.0/24 *99.0.0.2\b.*99.0.0.2/32 *192.168.1.2\b", "pass", "vrf->vpn routes", ) want = [ {"rd": "10:41", "p": "5.1.2.0/24", "n": "99.0.0.3"}, {"rd": "10:41", "p": "5.1.3.0/24", "n": "99.0.0.3"}, + {"rd": "10:41", "p": "6.0.1.0/24", "n": "99.0.0.3"}, + {"rd": "10:41", "p": "6.0.2.0/24", "n": "99.0.0.3"}, {"rd": "10:41", "p": "99.0.0.3/32", "n": "192.168.1.2"}, {"rd": "10:42", "p": "5.4.2.0/24", "n": "99.0.0.4"}, {"rd": "10:42", "p": "5.4.3.0/24", "n": "99.0.0.4"}, + {"rd": "10:42", "p": "6.0.1.0/24", "n": "99.0.0.4"}, + {"rd": "10:42", "p": "6.0.2.0/24", "n": "99.0.0.4"}, {"rd": "10:42", "p": "99.0.0.4/32", "n": "192.168.2.2"}, ] bgpribRequireVpnRoutes("r4", "vrf->vpn routes", want) @@ -266,58 +286,95 @@ bgpribRequireVpnRoutes( # PE routers: VRFs contain routes from remote customer nets ######################################################################## want_r1_remote_cust1_routes = [ - {"p": "5.1.0.0/24", "n": "3.3.3.3"}, - {"p": "5.1.1.0/24", "n": "3.3.3.3"}, - {"p": "99.0.0.2/32", "n": "3.3.3.3"}, + {"p": "5.1.0.0/24", "n": "3.3.3.3", "bp": False}, + {"p": "5.1.0.0/24", "n": "99.0.0.1", "bp": True}, + {"p": "5.1.1.0/24", "n": "3.3.3.3", "bp": False}, + {"p": "5.1.1.0/24", "n": "99.0.0.1", "bp": True}, {"p": "5.1.2.0/24", "n": "4.4.4.4"}, {"p": "5.1.3.0/24", "n": "4.4.4.4"}, - {"p": "99.0.0.3/32", "n": "4.4.4.4"}, {"p": "5.4.2.0/24", "n": "4.4.4.4"}, {"p": "5.4.3.0/24", "n": "4.4.4.4"}, + {"p": "6.0.1.0/24", "n": "3.3.3.3", "bp": False}, + {"p": "6.0.1.0/24", "n": "4.4.4.4", "bp": False}, + {"p": "6.0.1.0/24", "n": "99.0.0.1", "bp": True}, + {"p": "6.0.2.0/24", "n": "3.3.3.3", "bp": False}, + {"p": "6.0.2.0/24", "n": "4.4.4.4", "bp": False}, + {"p": "6.0.2.0/24", "n": "99.0.0.1", "bp": True}, + {"p": "99.0.0.1/32", "n": "192.168.1.2", "bp": True}, + {"p": "99.0.0.2/32", "n": "3.3.3.3"}, {"p": "99.0.0.3/32", "n": "4.4.4.4"}, + {"p": "99.0.0.4/32", "n": "4.4.4.4"}, ] bgpribRequireUnicastRoutes( - "r1", "ipv4", "r1-cust1", "Customer 1 routes in r1 vrf", want_r1_remote_cust1_routes -) + "r1", "ipv4", "r1-cust1", "Customer 1 routes in r1 vrf (2)", want_r1_remote_cust1_routes + , debug=False) want_r3_remote_cust1_routes = [ - {"p": "5.1.0.0/24", "n": "1.1.1.1"}, - {"p": "5.1.1.0/24", "n": "1.1.1.1"}, - {"p": "99.0.0.1/32", "n": "1.1.1.1"}, - {"p": "5.1.2.0/24", "n": "4.4.4.4"}, - {"p": "5.1.3.0/24", "n": "4.4.4.4"}, - {"p": "99.0.0.3/32", "n": "4.4.4.4"}, - {"p": "5.4.2.0/24", "n": "4.4.4.4"}, - {"p": "5.4.3.0/24", "n": "4.4.4.4"}, - {"p": "99.0.0.3/32", "n": "4.4.4.4"}, + {"p": "5.1.0.0/24", "n": "1.1.1.1", "bp": True}, + {"p": "5.1.0.0/24", "n": "99.0.0.2", "bp": False}, + {"p": "5.1.1.0/24", "n": "1.1.1.1", "bp": True}, + {"p": "5.1.1.0/24", "n": "99.0.0.2", "bp": False}, + {"p": "5.1.2.0/24", "n": "4.4.4.4", "bp": True}, + {"p": "5.1.3.0/24", "n": "4.4.4.4", "bp": True}, + {"p": "5.4.2.0/24", "n": "4.4.4.4", "bp": True}, + {"p": "5.4.3.0/24", "n": "4.4.4.4", "bp": True}, + {"p": "6.0.1.0/24", "n": "1.1.1.1", "bp": True}, + {"p": "6.0.1.0/24", "n": "4.4.4.4", "bp": False}, + {"p": "6.0.1.0/24", "n": "99.0.0.2", "bp": False}, + {"p": "6.0.2.0/24", "n": "1.1.1.1", "bp": False}, + {"p": "6.0.2.0/24", "n": "4.4.4.4", "bp": False}, + {"p": "6.0.2.0/24", "n": "99.0.0.2", "bp": True}, + {"p": "99.0.0.1/32", "n": "1.1.1.1", "bp": True}, + {"p": "99.0.0.3/32", "n": "4.4.4.4", "bp": True}, + {"p": "99.0.0.4/32", "n": "4.4.4.4", "bp": True}, ] bgpribRequireUnicastRoutes( - "r3", "ipv4", "r3-cust1", "Customer 1 routes in r3 vrf", want_r3_remote_cust1_routes -) + "r3", "ipv4", "r3-cust1", "Customer 1 routes in r3 vrf (2)", want_r3_remote_cust1_routes + , debug=False) want_r4_remote_cust1_routes = [ - {"p": "5.1.0.0/24", "n": "1.1.1.1"}, - {"p": "5.1.1.0/24", "n": "1.1.1.1"}, - {"p": "5.1.0.0/24", "n": "3.3.3.3"}, - {"p": "5.1.1.0/24", "n": "3.3.3.3"}, - {"p": "99.0.0.1/32", "n": "1.1.1.1"}, - {"p": "99.0.0.2/32", "n": "3.3.3.3"}, + {"p": "5.1.0.0/24", "n": "1.1.1.1", "bp": True}, + {"p": "5.1.0.0/24", "n": "3.3.3.3", "bp": False}, + {"p": "5.1.1.0/24", "n": "1.1.1.1", "bp": True}, + {"p": "5.1.1.0/24", "n": "3.3.3.3", "bp": False}, + {"p": "6.0.1.0/24", "n": "1.1.1.1", "bp": True}, + {"p": "6.0.1.0/24", "n": "3.3.3.3", "bp": False}, + {"p": "6.0.1.0/24", "n": "99.0.0.3", "bp": False}, + {"p": "6.0.1.0/24", "n": "99.0.0.4", "bp": False}, + {"p": "6.0.2.0/24", "n": "1.1.1.1", "bp": False}, + {"p": "6.0.2.0/24", "n": "3.3.3.3", "bp": False}, + {"p": "6.0.2.0/24", "n": "99.0.0.3", "bp": False}, + {"p": "6.0.2.0/24", "n": "99.0.0.4", "bp": True}, + {"p": "99.0.0.1/32", "n": "1.1.1.1", "bp": True}, + {"p": "99.0.0.2/32", "n": "3.3.3.3", "bp": True}, + {"p": "99.0.0.3/32", "n": "192.168.1.2", "bp": True}, + {"p": "99.0.0.4/32", "n": "192.168.2.2", "bp": True}, ] bgpribRequireUnicastRoutes( - "r4", "ipv4", "r4-cust1", "Customer 1 routes in r4 vrf", want_r4_remote_cust1_routes -) + "r4", "ipv4", "r4-cust1", "Customer 1 routes in r4 vrf (2)", want_r4_remote_cust1_routes + , debug=False) want_r4_remote_cust2_routes = [ - {"p": "5.1.0.0/24", "n": "1.1.1.1"}, - {"p": "5.1.1.0/24", "n": "1.1.1.1"}, - {"p": "5.1.0.0/24", "n": "3.3.3.3"}, - {"p": "5.1.1.0/24", "n": "3.3.3.3"}, - {"p": "99.0.0.1/32", "n": "1.1.1.1"}, - {"p": "99.0.0.2/32", "n": "3.3.3.3"}, + {"p": "5.1.0.0/24", "n": "1.1.1.1", "bp": True}, + {"p": "5.1.0.0/24", "n": "3.3.3.3", "bp": False}, + {"p": "5.1.1.0/24", "n": "1.1.1.1", "bp": True}, + {"p": "5.1.1.0/24", "n": "3.3.3.3", "bp": False}, + {"p": "6.0.1.0/24", "n": "1.1.1.1", "bp": True}, + {"p": "6.0.1.0/24", "n": "3.3.3.3", "bp": False}, + {"p": "6.0.1.0/24", "n": "99.0.0.3", "bp": False}, + {"p": "6.0.1.0/24", "n": "99.0.0.4", "bp": False}, + {"p": "6.0.2.0/24", "n": "1.1.1.1", "bp": False}, + {"p": "6.0.2.0/24", "n": "3.3.3.3", "bp": False}, + {"p": "6.0.2.0/24", "n": "99.0.0.3", "bp": True}, + {"p": "6.0.2.0/24", "n": "99.0.0.4", "bp": False}, + {"p": "99.0.0.1/32", "n": "1.1.1.1", "bp": True}, + {"p": "99.0.0.2/32", "n": "3.3.3.3", "bp": True}, + {"p": "99.0.0.3/32", "n": "192.168.1.2", "bp": True}, + {"p": "99.0.0.4/32", "n": "192.168.2.2", "bp": True}, ] bgpribRequireUnicastRoutes( - "r4", "ipv4", "r4-cust2", "Customer 2 routes in r4 vrf", want_r4_remote_cust2_routes -) + "r4", "ipv4", "r4-cust2", "Customer 2 routes in r4 vrf (2)", want_r4_remote_cust2_routes + , debug=False) ######################################################################### @@ -330,36 +387,45 @@ bgpribRequireUnicastRoutes( luCommand( "ce1", 'vtysh -c "show bgp ipv4 uni"', - "10 routes and 10", + "12 routes and 12", "wait", "Local and remote routes", 10, ) want = [ - {"p": "5.1.2.0/24", "n": "192.168.1.1"}, - {"p": "5.1.3.0/24", "n": "192.168.1.1"}, - {"p": "5.4.2.0/24", "n": "192.168.1.1"}, - {"p": "5.4.3.0/24", "n": "192.168.1.1"}, + {"p": "5.1.0.0/24", "n": "99.0.0.1", "bp": True}, + {"p": "5.1.1.0/24", "n": "99.0.0.1", "bp": True}, + {"p": "5.1.2.0/24", "n": "192.168.1.1", "bp": True}, + {"p": "5.1.3.0/24", "n": "192.168.1.1", "bp": True}, + {"p": "5.4.2.0/24", "n": "192.168.1.1", "bp": True}, + {"p": "5.4.3.0/24", "n": "192.168.1.1", "bp": True}, + {"p": "6.0.1.0/24", "n": "99.0.0.1", "bp": True}, + {"p": "6.0.2.0/24", "n": "99.0.0.1", "bp": True}, ] -bgpribRequireUnicastRoutes("ce1", "ipv4", "", "Cust 1 routes from remote", want) +bgpribRequireUnicastRoutes("ce1", "ipv4", "", "Cust 1 routes from remote", want, debug=False) luCommand( "ce2", 'vtysh -c "show bgp ipv4 uni"', - "10 routes and 12", + "12 routes and 15", "wait", "Local and remote routes", 10, ) want = [ - {"p": "5.1.0.0/24", "n": "192.168.1.1"}, - {"p": "5.1.1.0/24", "n": "192.168.1.1"}, - {"p": "5.1.2.0/24", "n": "192.168.1.1"}, - {"p": "5.1.3.0/24", "n": "192.168.1.1"}, - {"p": "5.4.2.0/24", "n": "192.168.1.1"}, - {"p": "5.4.3.0/24", "n": "192.168.1.1"}, + {"p": "5.1.0.0/24", "n": "192.168.1.1", "bp": False}, + {"p": "5.1.0.0/24", "n": "99.0.0.2", "bp": True}, + {"p": "5.1.1.0/24", "n": "192.168.1.1", "bp": False}, + {"p": "5.1.1.0/24", "n": "99.0.0.2", "bp": True}, + {"p": "5.1.2.0/24", "n": "192.168.1.1", "bp": True}, + {"p": "5.1.3.0/24", "n": "192.168.1.1", "bp": True}, + {"p": "5.4.2.0/24", "n": "192.168.1.1", "bp": True}, + {"p": "5.4.3.0/24", "n": "192.168.1.1", "bp": True}, + {"p": "6.0.1.0/24", "n": "192.168.1.1", "bp": False}, + {"p": "6.0.1.0/24", "n": "99.0.0.2", "bp": True}, + {"p": "6.0.2.0/24", "n": "99.0.0.2", "bp": True}, ] -bgpribRequireUnicastRoutes("ce2", "ipv4", "", "Cust 1 routes from remote", want) +bgpribRequireUnicastRoutes("ce2", "ipv4", "", "Cust 1 routes from remote", want, debug=False) # human readable output for debugging luCommand("r4", 'vtysh -c "show bgp vrf r4-cust1 ipv4 uni"') @@ -371,34 +437,98 @@ luCommand("r4", 'vtysh -c "show ip route vrf r4-cust2"') luCommand( "ce3", 'vtysh -c "show bgp ipv4 uni"', - "10 routes and 10", + "12 routes and 14", "wait", "Local and remote routes", 10, ) # Requires bvl-bug-degenerate-no-label fix (FRR PR #2053) want = [ - {"p": "5.1.0.0/24", "n": "192.168.1.1"}, - {"p": "5.1.1.0/24", "n": "192.168.1.1"}, - {"p": "5.4.2.0/24", "n": "192.168.1.1"}, - {"p": "5.4.3.0/24", "n": "192.168.1.1"}, + {"p": "5.1.0.0/24", "n": "192.168.1.1", "bp": True}, + {"p": "5.1.1.0/24", "n": "192.168.1.1", "bp": True}, + {"p": "5.4.2.0/24", "n": "192.168.1.1", "bp": True}, + {"p": "5.4.3.0/24", "n": "192.168.1.1", "bp": True}, + {"p": "6.0.1.0/24", "n": "192.168.1.1", "bp": False}, + {"p": "6.0.2.0/24", "n": "192.168.1.1", "bp": False}, + {"p": "6.0.1.0/24", "n": "99.0.0.3", "bp": True}, + {"p": "6.0.2.0/24", "n": "99.0.0.3", "bp": True}, ] -bgpribRequireUnicastRoutes("ce3", "ipv4", "", "Cust 1 routes from remote", want) +bgpribRequireUnicastRoutes("ce3", "ipv4", "", "Cust 1 routes from remote", want, debug=False) luCommand( "ce4", 'vtysh -c "show bgp vrf ce4-cust2 ipv4 uni"', - "10 routes and 10", + "12 routes and 14", "wait", "Local and remote routes", 10, ) want = [ - {"p": "5.1.0.0/24", "n": "192.168.2.1"}, - {"p": "5.1.1.0/24", "n": "192.168.2.1"}, - {"p": "5.1.2.0/24", "n": "192.168.2.1"}, - {"p": "5.1.3.0/24", "n": "192.168.2.1"}, + {"p": "5.1.0.0/24", "n": "192.168.2.1", "bp": True}, + {"p": "5.1.1.0/24", "n": "192.168.2.1", "bp": True}, + {"p": "5.1.2.0/24", "n": "192.168.2.1", "bp": True}, + {"p": "5.1.3.0/24", "n": "192.168.2.1", "bp": True}, + {"p": "6.0.1.0/24", "n": "192.168.2.1", "bp": False}, + {"p": "6.0.2.0/24", "n": "192.168.2.1", "bp": False}, + {"p": "6.0.1.0/24", "n": "99.0.0.4", "bp": True}, + {"p": "6.0.2.0/24", "n": "99.0.0.4", "bp": True}, ] bgpribRequireUnicastRoutes( - "ce4", "ipv4", "ce4-cust2", "Cust 2 routes from remote", want + "ce4", "ipv4", "ce4-cust2", "Cust 2 routes from remote", want, debug=False ) + +#verify details of exported/imported routes +luCommand("ce1",'vtysh -c "show bgp ipv4 uni 6.0.1.0"', + "1 available.*192.168.1.1.*99.0.0.1.*Community: 0:67.*Extended Community: RT:89:123.*Large Community: 12:34:56", + "pass", "Redundant route 1 details") +luCommand("ce2",'vtysh -c "show bgp ipv4 uni 6.0.1.0"', + "2 available, best .*192.168.1.1.* Local.* 192.168.1.1 from 192.168.1.1 .192.168.1.1" + + ".* Origin IGP, metric 98, localpref 123, valid, internal" + + ".* Community: 0:67.* Extended Community: RT:52:100 RT:89:123.* Large Community: 12:34:56", + ".* Local.* 99.0.0.2 from 0.0.0.0 .99.0.0.2" + + ".* Origin IGP, metric 100, localpref 100, weight 32768, valid, sourced, local, best .Weight" + + ".* Community: 0:67.* Extended Community: RT:89:123.* Large Community: 12:34:56", + "pass", "Redundant route 1 details") +luCommand("ce3",'vtysh -c "show bgp ipv4 uni 6.0.1.0"', + "2 available, best .*192.168.1.1.* Local.* 99.0.0.3 from 0.0.0.0 .99.0.0.3" + + ".* Origin IGP, metric 200, localpref 50, weight 32768, valid, sourced, local, best .Weight" + + ".* Community: 0:67.* Extended Community: RT:89:123.* Large Community: 12:34:56" + + ".* Local.* 192.168.1.1 from 192.168.1.1 .192.168.1.1" + + ".* Origin IGP, metric 98, localpref 123, valid, internal" + + ".* Community: 0:67.* Extended Community: RT:52:100 RT:89:123.* Large Community: 12:34:56", + "pass", "Redundant route 1 details") +luCommand("ce4",'vtysh -c "show bgp vrf ce4-cust2 ipv4 6.0.1.0"', + "2 available, best .*192.168.2.1.* Local.* 192.168.2.1 from 192.168.2.1 .192.168.2.1" + + ".* Origin IGP, metric 98, localpref 123, valid, internal" + + ".* Community: 0:67.* Extended Community: RT:52:100 RT:89:123.* Large Community: 12:34:56" + + ".* Local.* 99.0.0.4 from 0.0.0.0 .99.0.0.4" + + ".* Origin IGP, metric 200, localpref 50, weight 32768, valid, sourced, local, best .Weight" + + ".* Community: 0:67.* Extended Community: RT:89:123.* Large Community: 12:34:56", + "pass", "Redundant route 1 details") + +luCommand("ce1",'vtysh -c "show bgp ipv4 uni 6.0.2.0"', + "1 available, best .*192.168.1.1.* Local.* 99.0.0.1 from 0.0.0.0 .99.0.0.1" + + ".* Origin IGP, metric 100, localpref 100, weight 32768, valid, sourced, local, best .First path received" + + ".* Community: 0:67.* Extended Community: RT:89:123.* Large Community: 12:34:11", + "pass", "Redundant route 2 details") +luCommand("ce2",'vtysh -c "show bgp ipv4 uni 6.0.2.0"', "1 available, best .*192.168.1.1.* Local.* 99.0.0.2 from 0.0.0.0 .99.0.0.2" + + ".* Origin IGP, metric 100, localpref 100, weight 32768, valid, sourced, local, best .First path received" + + ".* Community: 0:67.* Extended Community: RT:89:123.* Large Community: 12:34:12", + "pass", "Redundant route 2 details") +luCommand("ce3",'vtysh -c "show bgp ipv4 uni 6.0.2.0"', + "2 available, best .*192.168.1.1.* Local.* 99.0.0.3 from 0.0.0.0 .99.0.0.3" + + ".* Origin IGP, metric 100, localpref 100, weight 32768, valid, sourced, local, best .Weight" + + ".* Community: 0:67.* Extended Community: RT:89:123.* Large Community: 12:34:13" + + ".* Local.* 192.168.1.1 from 192.168.1.1 .192.168.1.1" + + ".* Origin IGP, metric 100, localpref 100, valid, internal" + + ".* Community: 0:67.* Extended Community: RT:52:100 RT:89:123.* Large Community: 12:34:14", + "pass", "Redundant route 2 details") +luCommand("ce4",'vtysh -c "show bgp vrf ce4-cust2 ipv4 6.0.2.0"', + "2 available, best .*192.168.2.1.* Local.* 192.168.2.1 from 192.168.2.1 .192.168.2.1" + + ".* Origin IGP, metric 100, localpref 100, valid, internal" + + ".* Community: 0:67.* Extended Community: RT:52:100 RT:89:123.* Large Community: 12:34:13" + + ".* Local.* 99.0.0.4 from 0.0.0.0 .99.0.0.4" + + ".* Origin IGP, metric 100, localpref 100, weight 32768, valid, sourced, local, best .Weight" + + ".* Community: 0:67.* Extended Community: RT:89:123.* Large Community: 12:34:14", + "pass", "Redundant route 2 details") +#done diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/scale_down.py b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/scale_down.py index b4fa240495..7990533f3a 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/scale_down.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/scale_down.py @@ -49,7 +49,7 @@ if ret != False and found != None: luCommand( rtr, 'vtysh -c "show bgp ipv4 uni" | grep Display', - " 10 route", + " 12 route", "wait", "BGP routes removed", wait, diff --git a/tests/topotests/lib/bgprib.py b/tests/topotests/lib/bgprib.py index 3d92718c78..8629ebd2ca 100644 --- a/tests/topotests/lib/bgprib.py +++ b/tests/topotests/lib/bgprib.py @@ -18,8 +18,8 @@ # # want_rd_routes = [ -# {'rd':'10:1', 'p':'5.1.0.0/24', 'n':'1.1.1.1'}, -# {'rd':'10:1', 'p':'5.1.0.0/24', 'n':'1.1.1.1'}, +# {'rd':'10:1', 'p':'5.1.0.0/24', 'n':'1.1.1.1', 'bp': True}, +# {'rd':'10:1', 'p':'5.1.0.0/24', 'n':'1.1.1.1', 'bp': False}, # # {'rd':'10:3', 'p':'5.1.0.0/24', 'n':'3.3.3.3'}, # ] @@ -34,39 +34,47 @@ # ribRequireUnicastRoutes('r1','ipv4','','Customer routes in default',want_unicast_routes) # -from lutil import luCommand, luResult +from lutil import luCommand, luResult, LUtil import json import re # gpz: get rib in json form and compare against desired routes class BgpRib: + + def log(self, str): + LUtil.log ("BgpRib: "+ str) + def routes_include_wanted(self, pfxtbl, want, debug): # helper function to RequireVpnRoutes for pfx in pfxtbl.iterkeys(): if debug: - print "trying pfx " + pfx + self.log("trying pfx %s" % pfx) if pfx != want["p"]: if debug: - print "want pfx=" + want["p"] + ", not " + pfx + self.log("want pfx=" + want["p"] + ", not " + pfx) continue if debug: - print "have pfx=" + pfx + self.log("have pfx=%s" % pfx) for r in pfxtbl[pfx]: + bp = r.get("bestpath", False) if debug: - print "trying route" + self.log("trying route %s bp=%s" % (r, bp)) nexthops = r["nexthops"] for nh in nexthops: if debug: - print "trying nh " + nh["ip"] + self.log("trying nh %s" % nh["ip"]) if nh["ip"] == want["n"]: if debug: - print "found " + want["n"] - return 1 + self.log("found %s" % want["n"]) + if bp == want.get("bp", bp): + return 1 + elif debug: + self.log("bestpath mismatch %s != %s" % (bp, want["bp"])) else: if debug: - print "want nh=" + want["n"] + ", not " + nh["ip"] + self.log("want nh=" + want["n"] + ", not " + nh["ip"]) if debug: - print "missing route: pfx=" + want["p"] + ", nh=" + want["n"] + self.log("missing route: pfx=" + want["p"] + ", nh=" + want["n"]) return 0 def RequireVpnRoutes(self, target, title, wantroutes, debug=0): @@ -99,12 +107,12 @@ class BgpRib: for want in wantroutes: found = 0 if debug: - print "want rd " + want["rd"] + self.log("want rd %s" % want["rd"]) for rd in rds.iterkeys(): if rd != want["rd"]: continue if debug: - print "found rd " + rd + self.log("found rd %s" % rd) table = rds[rd] if self.routes_include_wanted(table, want, debug): found = 1 @@ -115,13 +123,13 @@ class BgpRib: luResult(target, True, title, logstr) def RequireUnicastRoutes(self, target, afi, vrf, title, wantroutes, debug=0): - logstr = "RequireVpnRoutes " + str(wantroutes) + logstr = "RequireVpnRoutes %s" % str(wantroutes) vrfstr = "" if vrf != "": vrfstr = "vrf %s" % (vrf) if (afi != "ipv4") and (afi != "ipv6"): - print "ERROR invalid afi" + self.log("ERROR invalid afi") cmdstr = "show bgp %s %s unicast" % (vrfstr, afi) # non json form for humans @@ -148,7 +156,11 @@ class BgpRib: errstr = "-script ERROR: check if vrf missing" luResult(target, False, title + errstr, logstr) return + #if debug: + # self.log("table=%s" % table) for want in wantroutes: + if debug: + self.log("want=%s" % want) if not self.routes_include_wanted(table, want, debug): luResult(target, False, title, logstr) return