Merge pull request #7113 from donaldsharp/bgp_bestpath_origin

bgpd: allow bestpath to handle mutliple locally-originated paths
This commit is contained in:
Russ White 2020-10-06 10:41:31 -04:00 committed by GitHub
commit b0508095f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 272 additions and 86 deletions

View File

@ -550,6 +550,7 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
bool same_esi; bool same_esi;
bool old_proxy; bool old_proxy;
bool new_proxy; bool new_proxy;
bool new_origin, exist_origin;
*paths_eq = 0; *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_AGGREGATE
* - BGP_ROUTE_REDISTRIBUTE * - BGP_ROUTE_REDISTRIBUTE
*/ */
if (!(new->sub_type == BGP_ROUTE_NORMAL || new_origin = !(new->sub_type == BGP_ROUTE_NORMAL ||
new->sub_type == BGP_ROUTE_IMPORTED)) { 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; *reason = bgp_path_selection_local_route;
if (debug) if (debug)
zlog_debug( zlog_debug(
@ -804,8 +809,7 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
return 1; return 1;
} }
if (!(exist->sub_type == BGP_ROUTE_NORMAL || if (!new_origin && exist_origin) {
exist->sub_type == BGP_ROUTE_IMPORTED)) {
*reason = bgp_path_selection_local_route; *reason = bgp_path_selection_local_route;
if (debug) if (debug)
zlog_debug( zlog_debug(

View File

@ -18,6 +18,8 @@ router bgp 5227
network 5.1.0.0/24 route-map rm-nh network 5.1.0.0/24 route-map rm-nh
network 5.1.1.0/24 route-map rm-nh network 5.1.1.0/24 route-map rm-nh
redistribute sharp route-map sharp-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 neighbor 192.168.1.1 activate
exit-address-family exit-address-family
! !
@ -41,5 +43,13 @@ route-map sharp-nh permit 10
set extcommunity rt 80:987 set extcommunity rt 80:987
set community 0:65 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 end

View File

@ -18,6 +18,8 @@ router bgp 5227
network 5.1.0.0/24 route-map rm-nh network 5.1.0.0/24 route-map rm-nh
network 5.1.1.0/24 route-map rm-nh network 5.1.1.0/24 route-map rm-nh
redistribute sharp route-map sharp-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 neighbor 192.168.1.1 activate
exit-address-family exit-address-family
! !
@ -41,5 +43,13 @@ route-map sharp-nh permit 10
set extcommunity rt 70:456 set extcommunity rt 70:456
set community 0:66 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 end

View File

@ -17,6 +17,8 @@ router bgp 5227
network 99.0.0.3/32 network 99.0.0.3/32
network 5.1.2.0/24 route-map rm-nh network 5.1.2.0/24 route-map rm-nh
network 5.1.3.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 neighbor 192.168.1.1 activate
exit-address-family exit-address-family
! !
@ -31,5 +33,13 @@ route-map rm-nh permit 10
set extcommunity rt 89:123 set extcommunity rt 89:123
set community 0:67 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 end

View File

@ -17,6 +17,8 @@ router bgp 5228 vrf ce4-cust2
network 99.0.0.4/32 network 99.0.0.4/32
network 5.4.2.0/24 route-map rm-nh network 5.4.2.0/24 route-map rm-nh
network 5.4.3.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 neighbor 192.168.2.1 activate
exit-address-family exit-address-family
! !
@ -31,5 +33,13 @@ route-map rm-nh permit 10
set extcommunity rt 89:123 set extcommunity rt 89:123
set community 0:67 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 end

View File

@ -14,6 +14,8 @@ from bgprib import bgpribRequireVpnRoutes, bgpribRequireUnicastRoutes
want = [ want = [
{"p": "5.1.0.0/24", "n": "99.0.0.1"}, {"p": "5.1.0.0/24", "n": "99.0.0.1"},
{"p": "5.1.1.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"}, {"p": "99.0.0.1/32", "n": "0.0.0.0"},
] ]
bgpribRequireUnicastRoutes("ce1", "ipv4", "", "Cust 1 routes in ce1", want) bgpribRequireUnicastRoutes("ce1", "ipv4", "", "Cust 1 routes in ce1", want)
@ -21,6 +23,8 @@ bgpribRequireUnicastRoutes("ce1", "ipv4", "", "Cust 1 routes in ce1", want)
want = [ want = [
{"p": "5.1.0.0/24", "n": "99.0.0.2"}, {"p": "5.1.0.0/24", "n": "99.0.0.2"},
{"p": "5.1.1.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"}, {"p": "99.0.0.2/32", "n": "0.0.0.0"},
] ]
bgpribRequireUnicastRoutes("ce2", "ipv4", "", "Cust 2 routes in ce1", want) bgpribRequireUnicastRoutes("ce2", "ipv4", "", "Cust 2 routes in ce1", want)
@ -28,6 +32,8 @@ bgpribRequireUnicastRoutes("ce2", "ipv4", "", "Cust 2 routes in ce1", want)
want = [ want = [
{"p": "5.1.2.0/24", "n": "99.0.0.3"}, {"p": "5.1.2.0/24", "n": "99.0.0.3"},
{"p": "5.1.3.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"}, {"p": "99.0.0.3/32", "n": "0.0.0.0"},
] ]
bgpribRequireUnicastRoutes("ce3", "ipv4", "", "Cust 3 routes in ce1", want) bgpribRequireUnicastRoutes("ce3", "ipv4", "", "Cust 3 routes in ce1", want)
@ -35,6 +41,8 @@ bgpribRequireUnicastRoutes("ce3", "ipv4", "", "Cust 3 routes in ce1", want)
want = [ want = [
{"p": "5.4.2.0/24", "n": "99.0.0.4"}, {"p": "5.4.2.0/24", "n": "99.0.0.4"},
{"p": "5.4.3.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"}, {"p": "99.0.0.4/32", "n": "0.0.0.0"},
] ]
bgpribRequireUnicastRoutes("ce4", "ipv4", "ce4-cust2", "Cust 4 routes in ce1", want) 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 = [ want_r1_cust1_routes = [
{"p": "5.1.0.0/24", "n": "99.0.0.1"}, {"p": "5.1.0.0/24", "n": "99.0.0.1"},
{"p": "5.1.1.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"}, {"p": "99.0.0.1/32", "n": "192.168.1.2"},
] ]
bgpribRequireUnicastRoutes( bgpribRequireUnicastRoutes(
@ -58,6 +68,8 @@ bgpribRequireUnicastRoutes(
want_r3_cust1_routes = [ want_r3_cust1_routes = [
{"p": "5.1.0.0/24", "n": "99.0.0.2"}, {"p": "5.1.0.0/24", "n": "99.0.0.2"},
{"p": "5.1.1.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"}, {"p": "99.0.0.2/32", "n": "192.168.1.2"},
] ]
bgpribRequireUnicastRoutes( bgpribRequireUnicastRoutes(
@ -67,6 +79,8 @@ bgpribRequireUnicastRoutes(
want_r4_cust1_routes = [ want_r4_cust1_routes = [
{"p": "5.1.2.0/24", "n": "99.0.0.3"}, {"p": "5.1.2.0/24", "n": "99.0.0.3"},
{"p": "5.1.3.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"}, {"p": "99.0.0.3/32", "n": "192.168.1.2"},
] ]
bgpribRequireUnicastRoutes( bgpribRequireUnicastRoutes(
@ -76,6 +90,8 @@ bgpribRequireUnicastRoutes(
want_r4_cust2_routes = [ want_r4_cust2_routes = [
{"p": "5.4.2.0/24", "n": "99.0.0.4"}, {"p": "5.4.2.0/24", "n": "99.0.0.4"},
{"p": "5.4.3.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"}, {"p": "99.0.0.4/32", "n": "192.168.2.2"},
] ]
bgpribRequireUnicastRoutes( bgpribRequireUnicastRoutes(
@ -152,23 +168,27 @@ else:
luCommand( luCommand(
"r1", "r1",
'vtysh -c "show bgp ipv4 vpn"', '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", "pass",
"vrf->vpn routes", "vrf->vpn routes",
) )
luCommand( luCommand(
"r3", "r3",
'vtysh -c "show bgp ipv4 vpn"', '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", "pass",
"vrf->vpn routes", "vrf->vpn routes",
) )
want = [ want = [
{"rd": "10:41", "p": "5.1.2.0/24", "n": "99.0.0.3"}, {"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": "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: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.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": "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"}, {"rd": "10:42", "p": "99.0.0.4/32", "n": "192.168.2.2"},
] ]
bgpribRequireVpnRoutes("r4", "vrf->vpn routes", want) bgpribRequireVpnRoutes("r4", "vrf->vpn routes", want)
@ -266,58 +286,95 @@ bgpribRequireVpnRoutes(
# PE routers: VRFs contain routes from remote customer nets # PE routers: VRFs contain routes from remote customer nets
######################################################################## ########################################################################
want_r1_remote_cust1_routes = [ want_r1_remote_cust1_routes = [
{"p": "5.1.0.0/24", "n": "3.3.3.3"}, {"p": "5.1.0.0/24", "n": "3.3.3.3", "bp": False},
{"p": "5.1.1.0/24", "n": "3.3.3.3"}, {"p": "5.1.0.0/24", "n": "99.0.0.1", "bp": True},
{"p": "99.0.0.2/32", "n": "3.3.3.3"}, {"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.2.0/24", "n": "4.4.4.4"},
{"p": "5.1.3.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.2.0/24", "n": "4.4.4.4"},
{"p": "5.4.3.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.3/32", "n": "4.4.4.4"},
{"p": "99.0.0.4/32", "n": "4.4.4.4"},
] ]
bgpribRequireUnicastRoutes( 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 = [ want_r3_remote_cust1_routes = [
{"p": "5.1.0.0/24", "n": "1.1.1.1"}, {"p": "5.1.0.0/24", "n": "1.1.1.1", "bp": True},
{"p": "5.1.1.0/24", "n": "1.1.1.1"}, {"p": "5.1.0.0/24", "n": "99.0.0.2", "bp": False},
{"p": "99.0.0.1/32", "n": "1.1.1.1"}, {"p": "5.1.1.0/24", "n": "1.1.1.1", "bp": True},
{"p": "5.1.2.0/24", "n": "4.4.4.4"}, {"p": "5.1.1.0/24", "n": "99.0.0.2", "bp": False},
{"p": "5.1.3.0/24", "n": "4.4.4.4"}, {"p": "5.1.2.0/24", "n": "4.4.4.4", "bp": True},
{"p": "99.0.0.3/32", "n": "4.4.4.4"}, {"p": "5.1.3.0/24", "n": "4.4.4.4", "bp": True},
{"p": "5.4.2.0/24", "n": "4.4.4.4"}, {"p": "5.4.2.0/24", "n": "4.4.4.4", "bp": True},
{"p": "5.4.3.0/24", "n": "4.4.4.4"}, {"p": "5.4.3.0/24", "n": "4.4.4.4", "bp": True},
{"p": "99.0.0.3/32", "n": "4.4.4.4"}, {"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( 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 = [ want_r4_remote_cust1_routes = [
{"p": "5.1.0.0/24", "n": "1.1.1.1"}, {"p": "5.1.0.0/24", "n": "1.1.1.1", "bp": True},
{"p": "5.1.1.0/24", "n": "1.1.1.1"}, {"p": "5.1.0.0/24", "n": "3.3.3.3", "bp": False},
{"p": "5.1.0.0/24", "n": "3.3.3.3"}, {"p": "5.1.1.0/24", "n": "1.1.1.1", "bp": True},
{"p": "5.1.1.0/24", "n": "3.3.3.3"}, {"p": "5.1.1.0/24", "n": "3.3.3.3", "bp": False},
{"p": "99.0.0.1/32", "n": "1.1.1.1"}, {"p": "6.0.1.0/24", "n": "1.1.1.1", "bp": True},
{"p": "99.0.0.2/32", "n": "3.3.3.3"}, {"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( 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 = [ want_r4_remote_cust2_routes = [
{"p": "5.1.0.0/24", "n": "1.1.1.1"}, {"p": "5.1.0.0/24", "n": "1.1.1.1", "bp": True},
{"p": "5.1.1.0/24", "n": "1.1.1.1"}, {"p": "5.1.0.0/24", "n": "3.3.3.3", "bp": False},
{"p": "5.1.0.0/24", "n": "3.3.3.3"}, {"p": "5.1.1.0/24", "n": "1.1.1.1", "bp": True},
{"p": "5.1.1.0/24", "n": "3.3.3.3"}, {"p": "5.1.1.0/24", "n": "3.3.3.3", "bp": False},
{"p": "99.0.0.1/32", "n": "1.1.1.1"}, {"p": "6.0.1.0/24", "n": "1.1.1.1", "bp": True},
{"p": "99.0.0.2/32", "n": "3.3.3.3"}, {"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( 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( luCommand(
"ce1", "ce1",
'vtysh -c "show bgp ipv4 uni"', 'vtysh -c "show bgp ipv4 uni"',
"10 routes and 10", "12 routes and 12",
"wait", "wait",
"Local and remote routes", "Local and remote routes",
10, 10,
) )
want = [ want = [
{"p": "5.1.2.0/24", "n": "192.168.1.1"}, {"p": "5.1.0.0/24", "n": "99.0.0.1", "bp": True},
{"p": "5.1.3.0/24", "n": "192.168.1.1"}, {"p": "5.1.1.0/24", "n": "99.0.0.1", "bp": True},
{"p": "5.4.2.0/24", "n": "192.168.1.1"}, {"p": "5.1.2.0/24", "n": "192.168.1.1", "bp": True},
{"p": "5.4.3.0/24", "n": "192.168.1.1"}, {"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( luCommand(
"ce2", "ce2",
'vtysh -c "show bgp ipv4 uni"', 'vtysh -c "show bgp ipv4 uni"',
"10 routes and 12", "12 routes and 15",
"wait", "wait",
"Local and remote routes", "Local and remote routes",
10, 10,
) )
want = [ want = [
{"p": "5.1.0.0/24", "n": "192.168.1.1"}, {"p": "5.1.0.0/24", "n": "192.168.1.1", "bp": False},
{"p": "5.1.1.0/24", "n": "192.168.1.1"}, {"p": "5.1.0.0/24", "n": "99.0.0.2", "bp": True},
{"p": "5.1.2.0/24", "n": "192.168.1.1"}, {"p": "5.1.1.0/24", "n": "192.168.1.1", "bp": False},
{"p": "5.1.3.0/24", "n": "192.168.1.1"}, {"p": "5.1.1.0/24", "n": "99.0.0.2", "bp": True},
{"p": "5.4.2.0/24", "n": "192.168.1.1"}, {"p": "5.1.2.0/24", "n": "192.168.1.1", "bp": True},
{"p": "5.4.3.0/24", "n": "192.168.1.1"}, {"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 # human readable output for debugging
luCommand("r4", 'vtysh -c "show bgp vrf r4-cust1 ipv4 uni"') 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( luCommand(
"ce3", "ce3",
'vtysh -c "show bgp ipv4 uni"', 'vtysh -c "show bgp ipv4 uni"',
"10 routes and 10", "12 routes and 14",
"wait", "wait",
"Local and remote routes", "Local and remote routes",
10, 10,
) )
# Requires bvl-bug-degenerate-no-label fix (FRR PR #2053) # Requires bvl-bug-degenerate-no-label fix (FRR PR #2053)
want = [ want = [
{"p": "5.1.0.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"}, {"p": "5.1.1.0/24", "n": "192.168.1.1", "bp": True},
{"p": "5.4.2.0/24", "n": "192.168.1.1"}, {"p": "5.4.2.0/24", "n": "192.168.1.1", "bp": True},
{"p": "5.4.3.0/24", "n": "192.168.1.1"}, {"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( luCommand(
"ce4", "ce4",
'vtysh -c "show bgp vrf ce4-cust2 ipv4 uni"', 'vtysh -c "show bgp vrf ce4-cust2 ipv4 uni"',
"10 routes and 10", "12 routes and 14",
"wait", "wait",
"Local and remote routes", "Local and remote routes",
10, 10,
) )
want = [ want = [
{"p": "5.1.0.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"}, {"p": "5.1.1.0/24", "n": "192.168.2.1", "bp": True},
{"p": "5.1.2.0/24", "n": "192.168.2.1"}, {"p": "5.1.2.0/24", "n": "192.168.2.1", "bp": True},
{"p": "5.1.3.0/24", "n": "192.168.2.1"}, {"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( 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

View File

@ -49,7 +49,7 @@ if ret != False and found != None:
luCommand( luCommand(
rtr, rtr,
'vtysh -c "show bgp ipv4 uni" | grep Display', 'vtysh -c "show bgp ipv4 uni" | grep Display',
" 10 route", " 12 route",
"wait", "wait",
"BGP routes removed", "BGP routes removed",
wait, wait,

View File

@ -18,8 +18,8 @@
# #
# want_rd_routes = [ # 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', 'bp': True},
# {'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': False},
# #
# {'rd':'10:3', 'p':'5.1.0.0/24', 'n':'3.3.3.3'}, # {'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) # ribRequireUnicastRoutes('r1','ipv4','','Customer routes in default',want_unicast_routes)
# #
from lutil import luCommand, luResult from lutil import luCommand, luResult, LUtil
import json import json
import re import re
# gpz: get rib in json form and compare against desired routes # gpz: get rib in json form and compare against desired routes
class BgpRib: class BgpRib:
def log(self, str):
LUtil.log ("BgpRib: "+ str)
def routes_include_wanted(self, pfxtbl, want, debug): def routes_include_wanted(self, pfxtbl, want, debug):
# helper function to RequireVpnRoutes # helper function to RequireVpnRoutes
for pfx in pfxtbl.iterkeys(): for pfx in pfxtbl.iterkeys():
if debug: if debug:
print "trying pfx " + pfx self.log("trying pfx %s" % pfx)
if pfx != want["p"]: if pfx != want["p"]:
if debug: if debug:
print "want pfx=" + want["p"] + ", not " + pfx self.log("want pfx=" + want["p"] + ", not " + pfx)
continue continue
if debug: if debug:
print "have pfx=" + pfx self.log("have pfx=%s" % pfx)
for r in pfxtbl[pfx]: for r in pfxtbl[pfx]:
bp = r.get("bestpath", False)
if debug: if debug:
print "trying route" self.log("trying route %s bp=%s" % (r, bp))
nexthops = r["nexthops"] nexthops = r["nexthops"]
for nh in nexthops: for nh in nexthops:
if debug: if debug:
print "trying nh " + nh["ip"] self.log("trying nh %s" % nh["ip"])
if nh["ip"] == want["n"]: if nh["ip"] == want["n"]:
if debug: if debug:
print "found " + want["n"] self.log("found %s" % want["n"])
return 1 if bp == want.get("bp", bp):
return 1
elif debug:
self.log("bestpath mismatch %s != %s" % (bp, want["bp"]))
else: else:
if debug: if debug:
print "want nh=" + want["n"] + ", not " + nh["ip"] self.log("want nh=" + want["n"] + ", not " + nh["ip"])
if debug: if debug:
print "missing route: pfx=" + want["p"] + ", nh=" + want["n"] self.log("missing route: pfx=" + want["p"] + ", nh=" + want["n"])
return 0 return 0
def RequireVpnRoutes(self, target, title, wantroutes, debug=0): def RequireVpnRoutes(self, target, title, wantroutes, debug=0):
@ -99,12 +107,12 @@ class BgpRib:
for want in wantroutes: for want in wantroutes:
found = 0 found = 0
if debug: if debug:
print "want rd " + want["rd"] self.log("want rd %s" % want["rd"])
for rd in rds.iterkeys(): for rd in rds.iterkeys():
if rd != want["rd"]: if rd != want["rd"]:
continue continue
if debug: if debug:
print "found rd " + rd self.log("found rd %s" % rd)
table = rds[rd] table = rds[rd]
if self.routes_include_wanted(table, want, debug): if self.routes_include_wanted(table, want, debug):
found = 1 found = 1
@ -115,13 +123,13 @@ class BgpRib:
luResult(target, True, title, logstr) luResult(target, True, title, logstr)
def RequireUnicastRoutes(self, target, afi, vrf, title, wantroutes, debug=0): def RequireUnicastRoutes(self, target, afi, vrf, title, wantroutes, debug=0):
logstr = "RequireVpnRoutes " + str(wantroutes) logstr = "RequireVpnRoutes %s" % str(wantroutes)
vrfstr = "" vrfstr = ""
if vrf != "": if vrf != "":
vrfstr = "vrf %s" % (vrf) vrfstr = "vrf %s" % (vrf)
if (afi != "ipv4") and (afi != "ipv6"): if (afi != "ipv4") and (afi != "ipv6"):
print "ERROR invalid afi" self.log("ERROR invalid afi")
cmdstr = "show bgp %s %s unicast" % (vrfstr, afi) cmdstr = "show bgp %s %s unicast" % (vrfstr, afi)
# non json form for humans # non json form for humans
@ -148,7 +156,11 @@ class BgpRib:
errstr = "-script ERROR: check if vrf missing" errstr = "-script ERROR: check if vrf missing"
luResult(target, False, title + errstr, logstr) luResult(target, False, title + errstr, logstr)
return return
#if debug:
# self.log("table=%s" % table)
for want in wantroutes: for want in wantroutes:
if debug:
self.log("want=%s" % want)
if not self.routes_include_wanted(table, want, debug): if not self.routes_include_wanted(table, want, debug):
luResult(target, False, title, logstr) luResult(target, False, title, logstr)
return return