@Test public void testComputeInitialTunnelTopology() { _cb.setConfigurationFormat(ConfigurationFormat.CISCO_IOS); Configuration c1 = _cb.build(); Configuration c2 = _cb.build(); Ip ip1 = Ip.parse("1.1.1.1"); Ip ip2 = Ip.parse("1.1.1.2"); Ip ip3 = Ip.parse("1.1.1.3"); Ip ip4 = Ip.parse("1.1.1.4"); int subnetMask = 24; Ip underlayIp1 = Ip.parse("4.4.4.1"); Ip underlayIp2 = Ip.parse("4.4.4.2"); Interface i1 = _ib.setOwner(c1) .setAddress(ConcreteInterfaceAddress.create(ip1, subnetMask)) .setType(InterfaceType.TUNNEL) .setTunnelConfig( TunnelConfiguration.builder() .setSourceAddress(underlayIp1) .setDestinationAddress(underlayIp2) .build()) .build(); Interface i2 = _ib.setOwner(c2) .setAddress(ConcreteInterfaceAddress.create(ip2, subnetMask)) .setType(InterfaceType.TUNNEL) .setTunnelConfig( TunnelConfiguration.builder() .setSourceAddress(underlayIp2) .setDestinationAddress(underlayIp1) .build()) .build(); _ib.setOwner(c2) .setAddress(ConcreteInterfaceAddress.create(ip3, subnetMask)) .setType(InterfaceType.PHYSICAL) .build(); _ib.setOwner(c2) .setAddress(ConcreteInterfaceAddress.create(ip4, subnetMask)) .setType(InterfaceType.TUNNEL) .setTunnelConfig( TunnelConfiguration.builder() .setSourceAddress(Ip.parse("4.4.4.4")) .setDestinationAddress(underlayIp1) .build()) .build(); assertThat( computeInitialTunnelTopology(ImmutableMap.of(c1.getHostname(), c1, c2.getHostname(), c2)) .asEdgeSet(), containsInAnyOrder(new Edge(i1, i2), new Edge(i2, i1))); }
@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; } 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(); }
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; } 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(); } }
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; } 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(); }
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; } 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(); static @Nonnull Layer1Topology cleanLayer1PhysicalTopology(
      @Nonnull Layer1Topology rawLayer1Topology,
      @Nonnull Map<String, Configuration> configurations); static @Nonnull Optional<Layer1Topology> unionLayer1PhysicalTopologies(
      Optional<Layer1Topology> topology1, Optional<Layer1Topology> topology2); static @Nonnull Layer2Topology computeLayer2Topology(
      @Nonnull Layer1Topology layer1LogicalTopology,
      VxlanTopology vxlanTopology,
      @Nonnull Map<String, Configuration> configurations); static @Nonnull Topology computeRawLayer3Topology(
      @Nonnull Optional<Layer1Topology> rawLayer1PhysicalTopology,
      @Nonnull Optional<Layer1Topology> layer1LogicalTopology,
      @Nonnull Optional<Layer2Topology> layer2Topology,
      @Nonnull Map<String, Configuration> configurations); static @Nonnull Topology computeLayer3Topology(
      Topology rawLayer3Topology, Set<Edge> overlayEdges); static @Nullable Interface getInterface(
      @Nonnull Layer1Node layer1Node, @Nonnull Map<String, Configuration> configurations); static @Nullable Interface getInterface(
      @Nonnull Layer2Node layer2Node, @Nonnull Map<String, Configuration> configurations); static IpsecTopology computeIpsecTopology(Map<String, Configuration> configurations); static Map<String, Set<Interface>> computeNodeInterfaces(
      Map<String, Configuration> configurations); static Topology synthesizeL3Topology(Map<String, Configuration> configurations); static @Nonnull Layer1Topology computeLayer1LogicalTopology(
      Layer1Topology layer1PhysicalTopology, Map<String, Configuration> configurations); @Nonnull static TunnelTopology computeInitialTunnelTopology(
      Map<String, Configuration> configurations); @Nonnull static TunnelTopology pruneUnreachableTunnelEdges(
      TunnelTopology initialTunnelTopology,
      NetworkConfigurations configurations,
      TracerouteEngine tracerouteEngine); }
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; } 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(); static @Nonnull Layer1Topology cleanLayer1PhysicalTopology(
      @Nonnull Layer1Topology rawLayer1Topology,
      @Nonnull Map<String, Configuration> configurations); static @Nonnull Optional<Layer1Topology> unionLayer1PhysicalTopologies(
      Optional<Layer1Topology> topology1, Optional<Layer1Topology> topology2); static @Nonnull Layer2Topology computeLayer2Topology(
      @Nonnull Layer1Topology layer1LogicalTopology,
      VxlanTopology vxlanTopology,
      @Nonnull Map<String, Configuration> configurations); static @Nonnull Topology computeRawLayer3Topology(
      @Nonnull Optional<Layer1Topology> rawLayer1PhysicalTopology,
      @Nonnull Optional<Layer1Topology> layer1LogicalTopology,
      @Nonnull Optional<Layer2Topology> layer2Topology,
      @Nonnull Map<String, Configuration> configurations); static @Nonnull Topology computeLayer3Topology(
      Topology rawLayer3Topology, Set<Edge> overlayEdges); static @Nullable Interface getInterface(
      @Nonnull Layer1Node layer1Node, @Nonnull Map<String, Configuration> configurations); static @Nullable Interface getInterface(
      @Nonnull Layer2Node layer2Node, @Nonnull Map<String, Configuration> configurations); static IpsecTopology computeIpsecTopology(Map<String, Configuration> configurations); static Map<String, Set<Interface>> computeNodeInterfaces(
      Map<String, Configuration> configurations); static Topology synthesizeL3Topology(Map<String, Configuration> configurations); static @Nonnull Layer1Topology computeLayer1LogicalTopology(
      Layer1Topology layer1PhysicalTopology, Map<String, Configuration> configurations); @Nonnull static TunnelTopology computeInitialTunnelTopology(
      Map<String, Configuration> configurations); @Nonnull static TunnelTopology pruneUnreachableTunnelEdges(
      TunnelTopology initialTunnelTopology,
      NetworkConfigurations configurations,
      TracerouteEngine tracerouteEngine);  }