@Test public void testComputeLocalIpForBgpNeighbor_vrf() { NetworkFactory nf = new NetworkFactory(); Configuration c = nf.configurationBuilder().setConfigurationFormat(ConfigurationFormat.CUMULUS_NCLU).build(); Vrf vrf1 = nf.vrfBuilder().setOwner(c).build(); Vrf vrf2 = nf.vrfBuilder().setOwner(c).build(); org.batfish.datamodel.Interface.Builder ib = nf.interfaceBuilder().setOwner(c).setType(PHYSICAL); ib.setVrf(vrf1).setAddress(ConcreteInterfaceAddress.parse("1.1.1.1/24")).build(); ib.setVrf(vrf2).setAddress(ConcreteInterfaceAddress.parse("2.2.2.2/24")).build(); Ip remoteIp = Ip.parse("1.1.1.3"); assertThat( computeLocalIpForBgpNeighbor(remoteIp, c, vrf1.getName()), equalTo(Ip.parse("1.1.1.1"))); assertNull(computeLocalIpForBgpNeighbor(remoteIp, c, vrf2.getName())); }
@Nullable @VisibleForTesting static Ip computeLocalIpForBgpNeighbor(Ip remoteIp, Configuration c, String vrfName) { org.batfish.datamodel.Vrf vrf = c.getVrfs().get(vrfName); if (vrf == null) { return null; } return c.getAllInterfaces(vrf.getName()).values().stream() .flatMap( i -> i.getAllConcreteAddresses().stream() .filter( addr -> addr.getPrefix().containsIp(remoteIp) && !addr.getIp().equals(remoteIp))) .findFirst() .map(ConcreteInterfaceAddress::getIp) .orElse(null); }
CumulusConversions { @Nullable @VisibleForTesting static Ip computeLocalIpForBgpNeighbor(Ip remoteIp, Configuration c, String vrfName) { org.batfish.datamodel.Vrf vrf = c.getVrfs().get(vrfName); if (vrf == null) { return null; } return c.getAllInterfaces(vrf.getName()).values().stream() .flatMap( i -> i.getAllConcreteAddresses().stream() .filter( addr -> addr.getPrefix().containsIp(remoteIp) && !addr.getIp().equals(remoteIp))) .findFirst() .map(ConcreteInterfaceAddress::getIp) .orElse(null); } }
CumulusConversions { @Nullable @VisibleForTesting static Ip computeLocalIpForBgpNeighbor(Ip remoteIp, Configuration c, String vrfName) { org.batfish.datamodel.Vrf vrf = c.getVrfs().get(vrfName); if (vrf == null) { return null; } return c.getAllInterfaces(vrf.getName()).values().stream() .flatMap( i -> i.getAllConcreteAddresses().stream() .filter( addr -> addr.getPrefix().containsIp(remoteIp) && !addr.getIp().equals(remoteIp))) .findFirst() .map(ConcreteInterfaceAddress::getIp) .orElse(null); }  }
CumulusConversions { @Nullable @VisibleForTesting static Ip computeLocalIpForBgpNeighbor(Ip remoteIp, Configuration c, String vrfName) { org.batfish.datamodel.Vrf vrf = c.getVrfs().get(vrfName); if (vrf == null) { return null; } return c.getAllInterfaces(vrf.getName()).values().stream() .flatMap( i -> i.getAllConcreteAddresses().stream() .filter( addr -> addr.getPrefix().containsIp(remoteIp) && !addr.getIp().equals(remoteIp))) .findFirst() .map(ConcreteInterfaceAddress::getIp) .orElse(null); }  static @Nonnull String computeBgpCommonExportPolicyName(String vrfName); @VisibleForTesting static @Nonnull String computeBgpPeerExportPolicyName(
      String vrfName, String peerInterface); static @Nonnull String computeBgpPeerImportPolicyName(String vrf, String peer); static String computeBgpGenerationPolicyName(boolean ipv4, String vrfName, String prefix); static String computeMatchSuppressedSummaryOnlyPolicyName(String vrfName); static String computeOspfExportPolicyName(String vrfName); }
CumulusConversions { @Nullable @VisibleForTesting static Ip computeLocalIpForBgpNeighbor(Ip remoteIp, Configuration c, String vrfName) { org.batfish.datamodel.Vrf vrf = c.getVrfs().get(vrfName); if (vrf == null) { return null; } return c.getAllInterfaces(vrf.getName()).values().stream() .flatMap( i -> i.getAllConcreteAddresses().stream() .filter( addr -> addr.getPrefix().containsIp(remoteIp) && !addr.getIp().equals(remoteIp))) .findFirst() .map(ConcreteInterfaceAddress::getIp) .orElse(null); }  static @Nonnull String computeBgpCommonExportPolicyName(String vrfName); @VisibleForTesting static @Nonnull String computeBgpPeerExportPolicyName(
      String vrfName, String peerInterface); static @Nonnull String computeBgpPeerImportPolicyName(String vrf, String peer); static String computeBgpGenerationPolicyName(boolean ipv4, String vrfName, String prefix); static String computeMatchSuppressedSummaryOnlyPolicyName(String vrfName); static String computeOspfExportPolicyName(String vrfName); static final int DEFAULT_STATIC_ROUTE_ADMINISTRATIVE_DISTANCE; static final int DEFAULT_STATIC_ROUTE_METRIC; static final Ip CLAG_LINK_LOCAL_IP; static final long DEFAULT_MAX_MED; static final double SPEED_CONVERSION_FACTOR; static final double DEFAULT_LOOPBACK_BANDWIDTH; static final double DEFAULT_PORT_BANDWIDTH; }