@Test public void testInferPeerIp_slash30() { assertEquals( inferPeerIp( org.batfish.datamodel.Interface.builder() .setAddress(ConcreteInterfaceAddress.parse("1.1.1.0/30")) .setName("iface") .build()), Optional.empty()); assertEquals( inferPeerIp( org.batfish.datamodel.Interface.builder() .setAddress(ConcreteInterfaceAddress.parse("1.1.1.1/30")) .setName("iface") .build()), Optional.of(Ip.parse("1.1.1.2"))); assertEquals( inferPeerIp( org.batfish.datamodel.Interface.builder() .setAddress(ConcreteInterfaceAddress.parse("1.1.1.2/30")) .setName("iface") .build()), Optional.of(Ip.parse("1.1.1.1"))); assertEquals( inferPeerIp( org.batfish.datamodel.Interface.builder() .setAddress(ConcreteInterfaceAddress.parse("1.1.1.3/30")) .setName("iface") .build()), Optional.empty()); }
@VisibleForTesting @Nonnull static Optional<Ip> inferPeerIp(Interface viIface) { if (viIface.getAllAddresses().size() != 1 || viIface.getAddress() == null || !(viIface.getAddress() instanceof ConcreteInterfaceAddress)) { return Optional.empty(); } ConcreteInterfaceAddress ifaceAddress = (ConcreteInterfaceAddress) viIface.getAllAddresses().iterator().next(); Prefix prefix = ifaceAddress.getPrefix(); if (ifaceAddress.getNetworkBits() == Prefix.MAX_PREFIX_LENGTH - 1) { return Optional.of( ifaceAddress.getIp().equals(prefix.getStartIp()) ? prefix.getEndIp() : prefix.getStartIp()); } if (ifaceAddress.getNetworkBits() == Prefix.MAX_PREFIX_LENGTH - 2) { if (ifaceAddress.getIp().equals(prefix.getStartIp()) || ifaceAddress.getIp().equals(prefix.getEndIp())) { return Optional.empty(); } return Optional.of( ifaceAddress.getIp().equals(prefix.getFirstHostIp()) ? prefix.getLastHostIp() : prefix.getFirstHostIp()); } return Optional.empty(); }
CumulusConversions { @VisibleForTesting @Nonnull static Optional<Ip> inferPeerIp(Interface viIface) { if (viIface.getAllAddresses().size() != 1 || viIface.getAddress() == null || !(viIface.getAddress() instanceof ConcreteInterfaceAddress)) { return Optional.empty(); } ConcreteInterfaceAddress ifaceAddress = (ConcreteInterfaceAddress) viIface.getAllAddresses().iterator().next(); Prefix prefix = ifaceAddress.getPrefix(); if (ifaceAddress.getNetworkBits() == Prefix.MAX_PREFIX_LENGTH - 1) { return Optional.of( ifaceAddress.getIp().equals(prefix.getStartIp()) ? prefix.getEndIp() : prefix.getStartIp()); } if (ifaceAddress.getNetworkBits() == Prefix.MAX_PREFIX_LENGTH - 2) { if (ifaceAddress.getIp().equals(prefix.getStartIp()) || ifaceAddress.getIp().equals(prefix.getEndIp())) { return Optional.empty(); } return Optional.of( ifaceAddress.getIp().equals(prefix.getFirstHostIp()) ? prefix.getLastHostIp() : prefix.getFirstHostIp()); } return Optional.empty(); } }
CumulusConversions { @VisibleForTesting @Nonnull static Optional<Ip> inferPeerIp(Interface viIface) { if (viIface.getAllAddresses().size() != 1 || viIface.getAddress() == null || !(viIface.getAddress() instanceof ConcreteInterfaceAddress)) { return Optional.empty(); } ConcreteInterfaceAddress ifaceAddress = (ConcreteInterfaceAddress) viIface.getAllAddresses().iterator().next(); Prefix prefix = ifaceAddress.getPrefix(); if (ifaceAddress.getNetworkBits() == Prefix.MAX_PREFIX_LENGTH - 1) { return Optional.of( ifaceAddress.getIp().equals(prefix.getStartIp()) ? prefix.getEndIp() : prefix.getStartIp()); } if (ifaceAddress.getNetworkBits() == Prefix.MAX_PREFIX_LENGTH - 2) { if (ifaceAddress.getIp().equals(prefix.getStartIp()) || ifaceAddress.getIp().equals(prefix.getEndIp())) { return Optional.empty(); } return Optional.of( ifaceAddress.getIp().equals(prefix.getFirstHostIp()) ? prefix.getLastHostIp() : prefix.getFirstHostIp()); } return Optional.empty(); }  }
CumulusConversions { @VisibleForTesting @Nonnull static Optional<Ip> inferPeerIp(Interface viIface) { if (viIface.getAllAddresses().size() != 1 || viIface.getAddress() == null || !(viIface.getAddress() instanceof ConcreteInterfaceAddress)) { return Optional.empty(); } ConcreteInterfaceAddress ifaceAddress = (ConcreteInterfaceAddress) viIface.getAllAddresses().iterator().next(); Prefix prefix = ifaceAddress.getPrefix(); if (ifaceAddress.getNetworkBits() == Prefix.MAX_PREFIX_LENGTH - 1) { return Optional.of( ifaceAddress.getIp().equals(prefix.getStartIp()) ? prefix.getEndIp() : prefix.getStartIp()); } if (ifaceAddress.getNetworkBits() == Prefix.MAX_PREFIX_LENGTH - 2) { if (ifaceAddress.getIp().equals(prefix.getStartIp()) || ifaceAddress.getIp().equals(prefix.getEndIp())) { return Optional.empty(); } return Optional.of( ifaceAddress.getIp().equals(prefix.getFirstHostIp()) ? prefix.getLastHostIp() : prefix.getFirstHostIp()); } return Optional.empty(); }  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 { @VisibleForTesting @Nonnull static Optional<Ip> inferPeerIp(Interface viIface) { if (viIface.getAllAddresses().size() != 1 || viIface.getAddress() == null || !(viIface.getAddress() instanceof ConcreteInterfaceAddress)) { return Optional.empty(); } ConcreteInterfaceAddress ifaceAddress = (ConcreteInterfaceAddress) viIface.getAllAddresses().iterator().next(); Prefix prefix = ifaceAddress.getPrefix(); if (ifaceAddress.getNetworkBits() == Prefix.MAX_PREFIX_LENGTH - 1) { return Optional.of( ifaceAddress.getIp().equals(prefix.getStartIp()) ? prefix.getEndIp() : prefix.getStartIp()); } if (ifaceAddress.getNetworkBits() == Prefix.MAX_PREFIX_LENGTH - 2) { if (ifaceAddress.getIp().equals(prefix.getStartIp()) || ifaceAddress.getIp().equals(prefix.getEndIp())) { return Optional.empty(); } return Optional.of( ifaceAddress.getIp().equals(prefix.getFirstHostIp()) ? prefix.getLastHostIp() : prefix.getFirstHostIp()); } return Optional.empty(); }  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; }