@Test public void testComputeLocalIpForBgpNeighbor() { Ip remoteIp = Ip.parse("1.1.1.1"); NetworkFactory nf = new NetworkFactory(); Configuration c = nf.configurationBuilder().setConfigurationFormat(ConfigurationFormat.CUMULUS_NCLU).build(); String vrfName = "vrf"; Vrf vrf = nf.vrfBuilder().setName(vrfName).setOwner(c).build(); org.batfish.datamodel.Interface.Builder ib = nf.interfaceBuilder().setVrf(vrf); InterfaceAddress addr1 = ConcreteInterfaceAddress.create(Ip.parse("2.2.2.2"), 24); ib.setType(PHYSICAL).setOwner(c).setName("i1").setAddress(addr1).build(); assertNull(computeLocalIpForBgpNeighbor(remoteIp, c, vrfName)); InterfaceAddress addr2 = ConcreteInterfaceAddress.create(remoteIp, 24); ib.setType(PHYSICAL).setOwner(c).setName("i2").setAddress(addr2).build(); assertNull(computeLocalIpForBgpNeighbor(remoteIp, c, vrfName)); Ip ifaceIp = Ip.parse("1.1.1.2"); InterfaceAddress addr3 = ConcreteInterfaceAddress.create(ifaceIp, 24); ib.setType(PHYSICAL).setOwner(c).setName("i3").setAddress(addr3).build(); assertThat(computeLocalIpForBgpNeighbor(remoteIp, c, vrfName), equalTo(ifaceIp)); }
@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; }