@Test public void testComputeLayer3Topology() { String c1Name = "c1"; String c2Name = "c2"; String c1i1Name = "c1i1"; String c2i1Name = "c2i1"; Layer1Node l1c1i1 = new Layer1Node(c1Name, c1i1Name); Layer1Node l1c2i1 = new Layer1Node(c2Name, c2i1Name); Layer2Node c1i1 = new Layer2Node(c1Name, c1i1Name, null); Layer2Node c2i1 = new Layer2Node(c2Name, c2i1Name, null); Edge c1i1c2i1 = Edge.of(c1Name, c1i1Name, c2Name, c2i1Name); Edge c2i1c1i1 = Edge.of(c2Name, c2i1Name, c1Name, c1i1Name); Configuration c1 = _cb.setHostname(c1Name).build(); Vrf v1 = _vb.setOwner(c1).build(); _ib.setOwner(c1).setVrf(v1).setActive(true); Configuration c2 = _cb.setHostname(c2Name).build(); Vrf v2 = _vb.setOwner(c2).build(); _ib.setOwner(c2).setVrf(v2); ConcreteInterfaceAddress p1Addr1 = ConcreteInterfaceAddress.parse("1.0.0.1/24"); ConcreteInterfaceAddress p1Addr2 = ConcreteInterfaceAddress.parse("1.0.0.2/24"); ConcreteInterfaceAddress p2Addr1 = ConcreteInterfaceAddress.parse("2.0.0.1/24"); Layer1Topology rawL1AllPresent = new Layer1Topology( ImmutableList.of(new Layer1Edge(l1c1i1, l1c2i1), new Layer1Edge(l1c2i1, l1c1i1))); Layer1Topology rawL1NonePresent = new Layer1Topology(ImmutableList.of()); Layer2Topology sameDomain = Layer2Topology.fromDomains(ImmutableList.of(ImmutableSet.of(c1i1, c2i1))); Layer2Topology differentDomains = Layer2Topology.fromDomains(ImmutableList.of(ImmutableSet.of(c1i1), ImmutableSet.of(c2i1))); { _ib.setOwner(c1).setVrf(v1).setName(c1i1Name).setAddress(p1Addr1).build(); _ib.setOwner(c2).setVrf(v2).setName(c2i1Name).setAddress(p1Addr2).build(); Map<String, Configuration> configs = ImmutableMap.of(c1Name, c1, c2Name, c2); Topology layer3Topology = computeRawLayer3Topology(rawL1AllPresent, Layer1Topology.EMPTY, sameDomain, configs); assertThat(layer3Topology.getEdges(), containsInAnyOrder(c1i1c2i1, c2i1c1i1)); } { _ib.setOwner(c1).setVrf(v1).setName(c1i1Name).setAddress(p1Addr1).build(); _ib.setOwner(c2).setVrf(v2).setName(c2i1Name).setAddress(p2Addr1).build(); Map<String, Configuration> configs = ImmutableMap.of(c1Name, c1, c2Name, c2); Topology layer3Topology = computeRawLayer3Topology( rawL1AllPresent, Layer1Topology.EMPTY, differentDomains, configs); assertThat(layer3Topology.getEdges(), empty()); } { _ib.setOwner(c1).setVrf(v1).setName(c1i1Name).setAddress(p1Addr1).build(); _ib.setOwner(c2).setVrf(v2).setName(c2i1Name).setAddress(p2Addr1).build(); Map<String, Configuration> configs = ImmutableMap.of(c1Name, c1, c2Name, c2); Topology layer3Topology = computeRawLayer3Topology(rawL1AllPresent, Layer1Topology.EMPTY, sameDomain, configs); assertThat(layer3Topology.getEdges(), empty()); } { _ib.setOwner(c1).setVrf(v1).setName(c1i1Name).setAddress(p1Addr1).build(); _ib.setOwner(c2).setVrf(v2).setName(c2i1Name).setAddress(p1Addr2).build(); Map<String, Configuration> configs = ImmutableMap.of(c1Name, c1, c2Name, c2); Topology layer3Topology = computeRawLayer3Topology( rawL1AllPresent, Layer1Topology.EMPTY, differentDomains, configs); assertThat(layer3Topology.getEdges(), empty()); } { _ib.setOwner(c1).setVrf(v1).setName(c1i1Name).setAddress(p1Addr1).build(); _ib.setOwner(c2).setVrf(v2).setName(c2i1Name).setAddress(p1Addr2).build(); Map<String, Configuration> configs = ImmutableMap.of(c1Name, c1, c2Name, c2); Topology layer3Topology = computeRawLayer3Topology( rawL1NonePresent, Layer1Topology.EMPTY, differentDomains, configs); assertThat(layer3Topology.getEdges(), containsInAnyOrder(c1i1c2i1, c2i1c1i1)); } }
public static @Nonnull Topology computeLayer3Topology( Topology rawLayer3Topology, Set<Edge> overlayEdges) { return new Topology( ImmutableSortedSet.<Edge>naturalOrder() .addAll(rawLayer3Topology.getEdges()) .addAll(overlayEdges) .build()); }
TopologyUtil { public static @Nonnull Topology computeLayer3Topology( Topology rawLayer3Topology, Set<Edge> overlayEdges) { return new Topology( ImmutableSortedSet.<Edge>naturalOrder() .addAll(rawLayer3Topology.getEdges()) .addAll(overlayEdges) .build()); } }
TopologyUtil { public static @Nonnull Topology computeLayer3Topology( Topology rawLayer3Topology, Set<Edge> overlayEdges) { return new Topology( ImmutableSortedSet.<Edge>naturalOrder() .addAll(rawLayer3Topology.getEdges()) .addAll(overlayEdges) .build()); } private  TopologyUtil(); }
TopologyUtil { public static @Nonnull Topology computeLayer3Topology( Topology rawLayer3Topology, Set<Edge> overlayEdges) { return new Topology( ImmutableSortedSet.<Edge>naturalOrder() .addAll(rawLayer3Topology.getEdges()) .addAll(overlayEdges) .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 { public static @Nonnull Topology computeLayer3Topology( Topology rawLayer3Topology, Set<Edge> overlayEdges) { return new Topology( ImmutableSortedSet.<Edge>naturalOrder() .addAll(rawLayer3Topology.getEdges()) .addAll(overlayEdges) .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);  }