Skip to content

Commit

Permalink
Cumulus FRR assign LLAs to point-to-point OSPF interfaces (#7038)
Browse files Browse the repository at this point in the history
- enables forwarding across unnumbered links
  • Loading branch information
arifogel committed Jun 2, 2021
1 parent cd36996 commit fdf4e80
Show file tree
Hide file tree
Showing 3 changed files with 188 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import org.batfish.datamodel.MacAddress;
import org.batfish.datamodel.Prefix;
import org.batfish.datamodel.SwitchportMode;
import org.batfish.datamodel.ospf.OspfNetworkType;
import org.batfish.datamodel.vendor_family.cumulus.CumulusFamily;
import org.batfish.representation.cumulus.CumulusPortsConfiguration.PortSettings;
import org.batfish.vendor.VendorConfiguration;
Expand Down Expand Up @@ -143,17 +144,7 @@ Configuration toVendorIndependentConfiguration() {
populatePortsInterfaceProperties(c);
populateFrrInterfaceProperties(c);

// for interfaces that didn't get an address via either interfaces or FRR, give them a link
// local address if they are being used for BGP unnumbered
c.getAllInterfaces()
.forEach(
(iname, iface) -> {
if (iface.getAllAddresses().size() == 0
&& isUsedForBgpUnnumbered(iface.getName(), _frrConfiguration.getBgpProcess())) {
iface.setAddress(LINK_LOCAL_ADDRESS);
iface.setAllAddresses(ImmutableSet.of(LINK_LOCAL_ADDRESS));
}
});
addBgpUnnumberedLLAs(c);

// FRR does not generate local routes for connected routes.
c.getAllInterfaces()
Expand Down Expand Up @@ -199,6 +190,7 @@ && isUsedForBgpUnnumbered(iface.getName(), _frrConfiguration.getBgpProcess())) {
convertVxlans(c, this, vniToVrf, loopbackClagVxlanAnycastIp, loopbackVxlanLocalTunnelIp, _w);

convertOspfProcess(c, this, _w);
addOspfUnnumberedLLAs(c);
convertBgpProcess(c, this, _w);

initVendorFamily(c);
Expand All @@ -208,6 +200,49 @@ && isUsedForBgpUnnumbered(iface.getName(), _frrConfiguration.getBgpProcess())) {
return c;
}

/**
* For interfaces that didn't get an address via either interfaces or FRR, give them a link-local
* address if they are being used for BGP unnumbered.
*/
private void addBgpUnnumberedLLAs(Configuration c) {
c.getAllInterfaces()
.forEach(
(iname, iface) -> {
if (iface.getAllAddresses().size() == 0
&& isUsedForBgpUnnumbered(iface.getName(), _frrConfiguration.getBgpProcess())) {
iface.setAddress(LINK_LOCAL_ADDRESS);
iface.setAllAddresses(ImmutableSet.of(LINK_LOCAL_ADDRESS));
}
});
}

/**
* For interfaces that didn't get an address via either interfaces or FRR, give them a link-local
* address if they are being used for OSPF unnumbered.
*/
private void addOspfUnnumberedLLAs(Configuration c) {
c.getAllInterfaces()
.forEach(
(iname, iface) -> {
if (iface.getInterfaceType() != InterfaceType.LOOPBACK
&& iface.getOspfEnabled()
&& !iface.getOspfPassive()
&& iface.getOspfSettings().getNetworkType() == OspfNetworkType.POINT_TO_POINT
&& !iface.getOspfSettings().getOspfAddresses().getAddresses().isEmpty()
&& iface.getAllLinkLocalAddresses().isEmpty()) {
if (iface.getAddress() == null) {
iface.setAddress(LINK_LOCAL_ADDRESS);
}
iface.setAllAddresses(
ImmutableSet.<InterfaceAddress>builderWithExpectedSize(
iface.getAllAddresses().size() + 1)
.addAll(iface.getAllAddresses())
.add(LINK_LOCAL_ADDRESS)
.build());
}
});
}

private void populatePortsInterfaceProperties(Configuration c) {
_portsConfiguration
.getPortSettings()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
Expand Down Expand Up @@ -62,6 +63,7 @@
import org.batfish.datamodel.Interface;
import org.batfish.datamodel.InterfaceType;
import org.batfish.datamodel.Ip;
import org.batfish.datamodel.LinkLocalAddress;
import org.batfish.datamodel.OriginType;
import org.batfish.datamodel.OspfExternalType2Route;
import org.batfish.datamodel.Prefix;
Expand Down Expand Up @@ -941,6 +943,51 @@ public void testOspfAddresses() throws IOException {
}
}

@Test
public void testOspfUnnumberedLLAs() throws IOException {
Configuration c = parseConfig("ospf_link_local");
assertThat(c.getAllInterfaces(), hasKeys("swp1", "swp2", "swp3", "swp4", "swp5", "swp6", "lo"));
{
Interface iface = c.getAllInterfaces().get("swp1");
assertThat(iface.getAddress(), equalTo(ConcreteInterfaceAddress.parse("10.0.0.1/32")));
assertThat(
iface.getAllAddresses(),
containsInAnyOrder(
equalTo(ConcreteInterfaceAddress.parse("10.0.0.1/32")),
instanceOf(LinkLocalAddress.class)));
}
{
Interface iface = c.getAllInterfaces().get("swp2");
assertThat(iface.getAddress(), instanceOf(LinkLocalAddress.class));
assertThat(iface.getAllAddresses(), contains(instanceOf(LinkLocalAddress.class)));
}
{
Interface iface = c.getAllInterfaces().get("swp3");
assertNull(iface.getAddress());
assertThat(iface.getAllAddresses(), empty());
}
{
Interface iface = c.getAllInterfaces().get("swp4");
assertNull(iface.getAddress());
assertThat(iface.getAllAddresses(), empty());
}
{
Interface iface = c.getAllInterfaces().get("swp5");
assertNull(iface.getAddress());
assertThat(iface.getAllAddresses(), empty());
}
{
Interface iface = c.getAllInterfaces().get("swp6");
assertNull(iface.getAddress());
assertThat(iface.getAllAddresses(), empty());
}
{
Interface iface = c.getAllInterfaces().get("lo");
assertNull(iface.getAddress());
assertThat(iface.getAllAddresses(), empty());
}
}

@Test
public void testLoopbackInterfaceType() throws IOException {
Configuration c = parseConfig("loopback");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
ospf_link_local
# This file describes the network interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

auto swp1
iface swp1
# Should own 10.0.0.1/32, since this is the earliest declared interface that assigns it.
address 10.0.0.1/32

auto swp2
iface swp2
# Should not own 10.0.0.1/32.
address 10.0.0.1/32

auto swp3
iface swp3

auto swp4
iface swp4
# Should not own 10.0.0.1/32.
address 10.0.0.1/32

auto swp5
iface swp5
# Should not own 10.0.0.1/32.
address 10.0.0.1/32

auto swp6
iface swp6
# Should not own 10.0.0.1/32.
address 10.0.0.1/32

auto lo
iface lo
# Should not own 10.0.0.1/32.
address 10.0.0.1/32

# ports.conf --
# ports.conf --
#
# configure port speed, aggregation, and subdivision.
#
# The ports in Cumulus VX are not configurable from here.
#frr version
frr version 4.0+cl3u8
frr defaults datacenter
hostname ospf_link_local
username cumulus nopassword
!
service integrated-vtysh-config
!
log syslog informational
!
interface swp1
! Should receive LLA, since OSPF is enabled on this interface and the network type is point-to-point.
! Even though it already has an address, it needs an LLA to ensure L3 edge can come up.
ip ospf area 0
ip ospf network point-to-point
!
interface swp2
! Should receive LLA, since OSPF is enabled on this interface and the network type is point-to-point.
ip ospf area 0
ip ospf network point-to-point
!
interface swp3
! Even though OSPF is enabled on this interface and the network type is point-to-point, should
! not receive LLA since it was never assigned any addresses.
ip ospf area 0
ip ospf network point-to-point
!
interface swp4
! Since OSPF is passive on this interface, should not receive LLA.
ip ospf area 0
ip ospf network point-to-point
!
interface swp5
! Since the OSPF network type is not point-to-point on this interface, should not receive LLA.
ip ospf area 0
!
interface swp6
! Since OSPF is not enabled on this interface, should not receive LLA.
!
interface lo
! Should not receive LLA since this is a loopback, even though OSPF is enabled on this interface
! and the network type is point-to-point.
ip ospf area 0
ip ospf network point-to-point
!
router ospf
ospf router-id 1.1.1.1
passive-interface swp4
!
line vty
!

0 comments on commit fdf4e80

Please sign in to comment.