Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BGP route reflector should reflect RIB-failure routes #7398

Merged
merged 1 commit into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -1049,6 +1049,9 @@ private Stream<RouteAdvertisement<Bgpv4Route>> getOutgoingRoutesForEdge(
r ->
// Received from 0.0.0.0 indicates local origination
(_exportFromBgpRib && Ip.ZERO.equals(r.getRoute().getRoute().getReceivedFromIp()))
// RIB-failure routes included
|| isReflectable(r.getRoute(), session, ourConfig)
// RIB-failure routes excluded
|| _mainRib.containsRoute(r.getRoute())));
}

Expand Down Expand Up @@ -1123,6 +1126,19 @@ private Stream<RouteAdvertisement<Bgpv4Route>> getOutgoingRoutesForEdge(
return Stream.concat(advertisementStream, neighborGeneratedRoutes);
}

private static boolean isReflectable(
AnnotatedRoute<Bgpv4Route> route, BgpSessionProperties session, BgpPeerConfig ourConfig) {
switch (session.getSessionType()) {
case IBGP:
case IBGP_UNNUMBERED:
break;
default:
return false;
}
return route.getRoute().getProtocol().equals(RoutingProtocol.IBGP)
&& ourConfig.getAddressFamily(Type.IPV4_UNICAST).getRouteReflectorClient();
}

/**
* Check whether given {@link GeneratedRoute} should be sent to a BGP neighbor. This checks
* activation conditions for the generated route, and converts it to a {@link Bgpv4Route}. No
Expand Down
Expand Up @@ -48,6 +48,7 @@
import org.batfish.datamodel.BgpPeerConfigId;
import org.batfish.datamodel.BgpProcess;
import org.batfish.datamodel.BgpSessionProperties;
import org.batfish.datamodel.Bgpv4Route;
import org.batfish.datamodel.ConcreteInterfaceAddress;
import org.batfish.datamodel.Configuration;
import org.batfish.datamodel.ConfigurationFormat;
Expand Down Expand Up @@ -230,6 +231,55 @@ public void testBgpOscillation() throws IOException {
dataPlanePlugin.computeDataPlane(batfish.getSnapshot());
}

/*
Topology:
R2
/ \
R1--R3

- R2 is a route reflector, with clients R1 and R3
- R1 sends 5.5.5.5/32 to R2 and changes its NHIP to its interface address for the R1<=>R3 link
- R2 has a static discard route for 5.5.5.5/32, so the BGP route goes into RIB-failure
- R2 should still reflect 5.5.5.5/32 to R3
*/
@Test
public void testRouteReflectorRibFailure() throws IOException {
String testrigName = "rr-rib-failure";
List<String> configurationNames = ImmutableList.of("r1", "r2", "r3");
Prefix advPrefix = Prefix.strict("5.5.5.5/32");

Batfish batfish =
BatfishTestUtils.getBatfishFromTestrigText(
TestrigText.builder()
.setConfigurationFiles(TESTRIGS_PREFIX + testrigName, configurationNames)
.build(),
_folder);
batfish.getSettings().setDataplaneEngineName(IncrementalDataPlanePlugin.PLUGIN_NAME);
batfish.computeDataPlane(batfish.getSnapshot());
DataPlane dataplane = batfish.loadDataPlane(batfish.getSnapshot());

// Check BGP RIB routes
Set<Bgpv4Route> r2BgpRibRoutes =
dataplane.getBgpRoutes().get("r2", Configuration.DEFAULT_VRF_NAME);
Set<Bgpv4Route> r3BgpRibRoutes =
dataplane.getBgpRoutes().get("r3", Configuration.DEFAULT_VRF_NAME);
assertThat(r2BgpRibRoutes, hasItem(hasPrefix(advPrefix)));
assertThat(r3BgpRibRoutes, hasItem(hasPrefix(advPrefix)));

// Check main RIB routes
Set<AbstractRoute> r2MainRibRoutes =
dataplane.getRibs().get("r2").get(Configuration.DEFAULT_VRF_NAME).getRoutes();
Set<AbstractRoute> r3MainRibRoutes =
dataplane.getRibs().get("r3").get(Configuration.DEFAULT_VRF_NAME).getRoutes();
assertThat(
r2MainRibRoutes, hasItem(allOf(hasPrefix(advPrefix), hasProtocol(RoutingProtocol.STATIC))));
assertThat(
r2MainRibRoutes,
not(hasItem(allOf(hasPrefix(advPrefix), hasProtocol(RoutingProtocol.IBGP)))));
assertThat(
r3MainRibRoutes, hasItem(allOf(hasPrefix(advPrefix), hasProtocol(RoutingProtocol.IBGP))));
}

@Test
public void testEbgpAcceptSameNeighborID() throws IOException {
String testrigName = "ebgp-accept-routerid-match";
Expand Down
@@ -0,0 +1,34 @@
!RANCID-CONTENT-TYPE: cisco
!
hostname r1
!
interface Loopback0
ip address 1.1.1.1 255.255.255.255
!
interface GigabitEthernet0/1
ip address 10.12.0.1 255.255.255.0
!
interface GigabitEthernet0/2
ip address 10.13.0.1 255.255.255.0
!
router bgp 1
bgp router-id 1.1.1.1
neighbor 2.2.2.2 remote-as 1
neighbor 2.2.2.2 update-source Loopback0
!
address-family ipv4
redistribute static route-map rs
neighbor 2.2.2.2 activate
neighbor 2.2.2.2 soft-reconfiguration inbound
exit-address-family
!
ip route 2.2.2.2 255.255.255.255 10.12.0.2
ip route 5.5.5.5 255.255.255.255 Null0
!
ip prefix-list five seq 5 permit 5.5.5.5/32
!
route-map rs permit 100
match ip address prefix-list five
set ip next-hop 10.13.0.1
!
end
@@ -0,0 +1,35 @@
!RANCID-CONTENT-TYPE: cisco
!
hostname r2
!
interface Loopback0
ip address 2.2.2.2 255.255.255.255
!
interface GigabitEthernet0/1
ip address 10.12.0.2 255.255.255.0
!
interface GigabitEthernet0/2
ip address 10.23.0.2 255.255.255.0
!
router bgp 1
bgp router-id 2.2.2.2
neighbor 1.1.1.1 remote-as 1
neighbor 1.1.1.1 update-source Loopback0
neighbor 3.3.3.3 remote-as 1
neighbor 3.3.3.3 update-source Loopback0
!
address-family ipv4
neighbor 1.1.1.1 activate
neighbor 1.1.1.1 route-reflector-client
neighbor 1.1.1.1 soft-reconfiguration inbound
neighbor 3.3.3.3 activate
neighbor 3.3.3.3 route-reflector-client
neighbor 3.3.3.3 soft-reconfiguration inbound
exit-address-family
!
ip route 1.1.1.1 255.255.255.255 10.12.0.1
ip route 3.3.3.3 255.255.255.255 10.23.0.3
ip route 5.5.5.5 255.255.255.255 Null0
ip route 10.13.0.1 255.255.255.255 10.12.0.1
!
end
@@ -0,0 +1,26 @@
!RANCID-CONTENT-TYPE: cisco
!
hostname r3
!
interface Loopback0
ip address 3.3.3.3 255.255.255.255
!
interface GigabitEthernet0/1
ip address 10.13.0.3 255.255.255.0
!
interface GigabitEthernet0/2
ip address 10.23.0.3 255.255.255.0
!
router bgp 1
bgp router-id 3.3.3.3
neighbor 2.2.2.2 remote-as 1
neighbor 2.2.2.2 update-source Loopback0
!
address-family ipv4
neighbor 2.2.2.2 activate
neighbor 2.2.2.2 soft-reconfiguration inbound
exit-address-family
!
ip route 2.2.2.2 255.255.255.255 10.23.0.2
!
end