Skip to content

Commit

Permalink
FRR: Adding support for interface shutdown command (#6169)
Browse files Browse the repository at this point in the history
  • Loading branch information
kylehoferamzn committed Sep 3, 2020
1 parent 452f008 commit f69d5c9
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,11 @@ SERVICE
'service'
;

SHUTDOWN
:
'shutdown'
;

SOFT_RECONFIGURATION
:
'soft-reconfiguration'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@ s_interface
| si_ip
| si_ipv6
| si_no
| si_shutdown
)*
;

si_shutdown
:
SHUTDOWN NEWLINE
;

si_ip
:
IP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
import org.batfish.grammar.cumulus_frr.CumulusFrrParser.Sbnp_remote_asContext;
import org.batfish.grammar.cumulus_frr.CumulusFrrParser.Sbnp_update_sourceContext;
import org.batfish.grammar.cumulus_frr.CumulusFrrParser.Si_descriptionContext;
import org.batfish.grammar.cumulus_frr.CumulusFrrParser.Si_shutdownContext;
import org.batfish.grammar.cumulus_frr.CumulusFrrParser.Siip_addressContext;
import org.batfish.grammar.cumulus_frr.CumulusFrrParser.Siipo_areaContext;
import org.batfish.grammar.cumulus_frr.CumulusFrrParser.Siipo_costContext;
Expand Down Expand Up @@ -632,6 +633,11 @@ public void exitS_interface(S_interfaceContext ctx) {
_currentInterface = null;
}

@Override
public void exitSi_shutdown(Si_shutdownContext ctx) {
_currentInterface.setShutdown(true);
}

@Override
public void exitSiip_address(Siip_addressContext ctx) {
if (_currentInterface == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ private static void populateFrrInterfaceProperties(Configuration c, FrrInterface
if (iface.getAlias() != null) {
viIface.setDescription(iface.getAlias());
}
if (iface.getShutdown()) {
viIface.setActive(false);
}
if (!iface.getIpAddresses().isEmpty()) {
viIface.setAddress(iface.getIpAddresses().get(0));
viIface.setAllAddresses(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class FrrInterface implements Serializable {
private final @Nonnull List<ConcreteInterfaceAddress> _ipAddresses;
private final @Nonnull String _name;
private final @Nullable String _vrfName;
private boolean _shutdown = false;

private @Nullable OspfInterface _ospf;

Expand Down Expand Up @@ -51,6 +52,14 @@ public void setAlias(@Nullable String alias) {
return _vrfName;
}

public boolean getShutdown() {
return _shutdown;
}

public void setShutdown(@Nonnull Boolean shutdown) {
_shutdown = shutdown;
}

@Nullable
public OspfInterface getOspf() {
return _ospf;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1602,6 +1602,18 @@ public void testSetInterfaceIpAddress() {
equalTo(ImmutableList.of(ConcreteInterfaceAddress.parse("1.1.1.1/30"))));
}

@Test
public void testSetInterfaceShutdown() {
parseLines("interface eth1", "shutdown");
assertTrue(_frr.getInterfaces().get("eth1").getShutdown());
}

@Test
public void testGetInterfaceShutdown() {
parseLines("interface eth1", "ip address 1.1.1.1/30");
assertFalse(_frr.getInterfaces().get("eth1").getShutdown());
}

@Test
public void testFRRDefaultTraditional() {
parse("frr defaults traditional\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,58 @@ public void testToInterface_sub_inactive() {
.getActive());
}

@Test
public void testToVIConfigIntfShut() {
InterfacesInterface vsIface = new InterfacesInterface("swp1");
CumulusFrrConfiguration frrConfiguration = new CumulusFrrConfiguration();

CumulusConcatenatedConfiguration vsConfig =
CumulusConcatenatedConfiguration.builder()
.setHostname("c")
.addInterfaces(ImmutableMap.of(vsIface.getName(), vsIface))
.setFrrConfiguration(frrConfiguration)
.build();

// Setup the FRR Interface
FrrInterface frrInterface = new FrrInterface("swp1");
frrInterface.setShutdown(true);
frrConfiguration.getInterfaces().put("swp1", frrInterface);

// Convert - method under test
Configuration c = vsConfig.toVendorIndependentConfiguration();

assertFalse(c.getAllInterfaces().get(vsIface.getName()).getActive());

// Flip the shutdown status around and test again.
frrInterface.setShutdown(false);
frrConfiguration.getInterfaces().put("swp1", frrInterface);
c = vsConfig.toVendorIndependentConfiguration();

assertTrue(c.getAllInterfaces().get(vsIface.getName()).getActive());
}

@Test
public void testToVIConfigIntfNoShut() {
InterfacesInterface vsIface = new InterfacesInterface("swp1");
CumulusFrrConfiguration frrConfiguration = new CumulusFrrConfiguration();

CumulusConcatenatedConfiguration vsConfig =
CumulusConcatenatedConfiguration.builder()
.setHostname("c")
.addInterfaces(ImmutableMap.of(vsIface.getName(), vsIface))
.setFrrConfiguration(frrConfiguration)
.build();

// Setup the FRR Interface
FrrInterface frrInterface = new FrrInterface("swp1");
frrConfiguration.getInterfaces().put("swp1", frrInterface);

// Convert - method under test
Configuration c = vsConfig.toVendorIndependentConfiguration();

assertTrue(c.getAllInterfaces().get(vsIface.getName()).getActive());
}

/** Tests that interfaces are assigned LLAs iff needed */
@Test
public void testInterface_assignLla() {
Expand Down

0 comments on commit f69d5c9

Please sign in to comment.