class TopologyUtil {

  @Nonnull
  public static TunnelTopology computeInitialTunnelTopology(
      Map<String, Configuration> configurations) {
    Map<Prefix, List<Interface>> prefixInterfaces = computeInterfacesBucketByPrefix(configurations);
    TunnelTopology.Builder builder = TunnelTopology.builder();
    for (Entry<Prefix, List<Interface>> bucketEntry : prefixInterfaces.entrySet()) {
      Prefix p = bucketEntry.getKey();
      Set<Interface> candidateInterfaces = candidateInterfacesForPrefix(prefixInterfaces, p);

      for (Interface iface1 : bucketEntry.getValue()) {
        for (Interface iface2 : candidateInterfaces) {
          if (!isValidLayer3Adjacency(iface1, iface2)) {
            continue;
          }

          // connect only if of both of the endpoints have Tunnel interface type, and their tunnel
          // configs match
          if (iface1.getInterfaceType() == InterfaceType.TUNNEL
              && iface2.getInterfaceType() == InterfaceType.TUNNEL
              && iface1.getTunnelConfig() != null
              && iface2.getTunnelConfig() != null
              && iface1
                  .getTunnelConfig()
                  .getSourceAddress()
                  .equals(iface2.getTunnelConfig().getDestinationAddress())
              && iface1
                  .getTunnelConfig()
                  .getDestinationAddress()
                  .equals(iface2.getTunnelConfig().getSourceAddress())) {
            builder.add(NodeInterfacePair.of(iface1), NodeInterfacePair.of(iface2));
          }
        }
      }
    }
    return builder.build();
  }

  private  TopologyUtil();

}