@Test public void testComputeLayer2TopologyCrossVni() { String s1Name = "s1"; String s2Name = "s2"; String swp1Name = "SWP1"; String swp2Name = "SWP2"; int vlanId = 2; int vni = 10002; String vrfName = "v1"; Configuration s1 = _cb.setHostname(s1Name).build(); Configuration s2 = _cb.setHostname(s2Name).build(); Vrf v1 = _vb.setOwner(s1).setName(vrfName).build(); Vrf v2 = _vb.setOwner(s2).setName(vrfName).build(); _ib.setActive(true); _ib.setAccessVlan(vlanId).setSwitchport(true).setSwitchportMode(SwitchportMode.ACCESS); _ib.setOwner(s1).setVrf(v1).setName(swp1Name).build(); _ib.setOwner(s2).setVrf(v2).setName(swp2Name).build(); Layer2Vni.Builder vnb = testBuilder() .setBumTransportIps(ImmutableSortedSet.of(Ip.FIRST_MULTICAST_IP)) .setBumTransportMethod(BumTransportMethod.MULTICAST_GROUP) .setVlan(vlanId) .setVni(vni); v1.addLayer2Vni(vnb.build()); v2.addLayer2Vni(vnb.build()); MutableGraph<VxlanNode> graph = GraphBuilder.undirected().allowsSelfLoops(false).build(); graph.putEdge(new VxlanNode(s1Name, vni), new VxlanNode(s2Name, vni)); VxlanTopology vxlanTopology = new VxlanTopology(graph); Layer1Topology layer1Topology = new Layer1Topology(ImmutableList.of()); assertTrue( computeLayer2Topology( layer1Topology, vxlanTopology, ImmutableMap.of(s1Name, s1, s2Name, s2)) .inSameBroadcastDomain( new Layer2Node(s1Name, swp1Name, vlanId), new Layer2Node(s2Name, swp2Name, vlanId))); }
public static @Nonnull Layer2Topology computeLayer2Topology( @Nonnull Layer1Topology layer1LogicalTopology, VxlanTopology vxlanTopology, @Nonnull Map<String, Configuration> configurations) { Layer2Topology.Builder l2TopologyBuilder = Layer2Topology.builder(); Map<Layer1Node, Set<Layer1Node>> parentChildrenMap = computeParentChildrenMap(configurations); layer1LogicalTopology .getGraph() .edges() .forEach( layer1Edge -> computeLayer2EdgesForLayer1Edge( layer1Edge, configurations, l2TopologyBuilder::addEdge, parentChildrenMap)); Set<String> nodesWithL1Edge = layer1LogicalTopology.getGraph().edges().stream() .flatMap(edge -> Stream.of(edge.getNode1(), edge.getNode2())) .map(Layer1Node::getHostname) .collect(ImmutableSet.toImmutableSet()); Set<String> nodesWithVxlan = vxlanTopology.getGraph().edges().stream() .flatMap(edge -> Stream.of(edge.nodeU(), edge.nodeV())) .map(VxlanNode::getHostname) .collect(ImmutableSet.toImmutableSet()); Set<String> nodesWithUsefulL2SelfEdges = ImmutableSet.<String>builder().addAll(nodesWithL1Edge).addAll(nodesWithVxlan).build(); configurations.values().stream() .filter(c -> nodesWithUsefulL2SelfEdges.contains(c.getHostname())) .forEach(c -> computeLayer2SelfEdges(c, l2TopologyBuilder::addEdge)); computeVniInterNodeEdges(vxlanTopology).forEach(l2TopologyBuilder::addEdge); return l2TopologyBuilder.build(); }
TopologyUtil { public static @Nonnull Layer2Topology computeLayer2Topology( @Nonnull Layer1Topology layer1LogicalTopology, VxlanTopology vxlanTopology, @Nonnull Map<String, Configuration> configurations) { Layer2Topology.Builder l2TopologyBuilder = Layer2Topology.builder(); Map<Layer1Node, Set<Layer1Node>> parentChildrenMap = computeParentChildrenMap(configurations); layer1LogicalTopology .getGraph() .edges() .forEach( layer1Edge -> computeLayer2EdgesForLayer1Edge( layer1Edge, configurations, l2TopologyBuilder::addEdge, parentChildrenMap)); Set<String> nodesWithL1Edge = layer1LogicalTopology.getGraph().edges().stream() .flatMap(edge -> Stream.of(edge.getNode1(), edge.getNode2())) .map(Layer1Node::getHostname) .collect(ImmutableSet.toImmutableSet()); Set<String> nodesWithVxlan = vxlanTopology.getGraph().edges().stream() .flatMap(edge -> Stream.of(edge.nodeU(), edge.nodeV())) .map(VxlanNode::getHostname) .collect(ImmutableSet.toImmutableSet()); Set<String> nodesWithUsefulL2SelfEdges = ImmutableSet.<String>builder().addAll(nodesWithL1Edge).addAll(nodesWithVxlan).build(); configurations.values().stream() .filter(c -> nodesWithUsefulL2SelfEdges.contains(c.getHostname())) .forEach(c -> computeLayer2SelfEdges(c, l2TopologyBuilder::addEdge)); computeVniInterNodeEdges(vxlanTopology).forEach(l2TopologyBuilder::addEdge); return l2TopologyBuilder.build(); } }
TopologyUtil { public static @Nonnull Layer2Topology computeLayer2Topology( @Nonnull Layer1Topology layer1LogicalTopology, VxlanTopology vxlanTopology, @Nonnull Map<String, Configuration> configurations) { Layer2Topology.Builder l2TopologyBuilder = Layer2Topology.builder(); Map<Layer1Node, Set<Layer1Node>> parentChildrenMap = computeParentChildrenMap(configurations); layer1LogicalTopology .getGraph() .edges() .forEach( layer1Edge -> computeLayer2EdgesForLayer1Edge( layer1Edge, configurations, l2TopologyBuilder::addEdge, parentChildrenMap)); Set<String> nodesWithL1Edge = layer1LogicalTopology.getGraph().edges().stream() .flatMap(edge -> Stream.of(edge.getNode1(), edge.getNode2())) .map(Layer1Node::getHostname) .collect(ImmutableSet.toImmutableSet()); Set<String> nodesWithVxlan = vxlanTopology.getGraph().edges().stream() .flatMap(edge -> Stream.of(edge.nodeU(), edge.nodeV())) .map(VxlanNode::getHostname) .collect(ImmutableSet.toImmutableSet()); Set<String> nodesWithUsefulL2SelfEdges = ImmutableSet.<String>builder().addAll(nodesWithL1Edge).addAll(nodesWithVxlan).build(); configurations.values().stream() .filter(c -> nodesWithUsefulL2SelfEdges.contains(c.getHostname())) .forEach(c -> computeLayer2SelfEdges(c, l2TopologyBuilder::addEdge)); computeVniInterNodeEdges(vxlanTopology).forEach(l2TopologyBuilder::addEdge); return l2TopologyBuilder.build(); } private  TopologyUtil(); }
TopologyUtil { public static @Nonnull Layer2Topology computeLayer2Topology( @Nonnull Layer1Topology layer1LogicalTopology, VxlanTopology vxlanTopology, @Nonnull Map<String, Configuration> configurations) { Layer2Topology.Builder l2TopologyBuilder = Layer2Topology.builder(); Map<Layer1Node, Set<Layer1Node>> parentChildrenMap = computeParentChildrenMap(configurations); layer1LogicalTopology .getGraph() .edges() .forEach( layer1Edge -> computeLayer2EdgesForLayer1Edge( layer1Edge, configurations, l2TopologyBuilder::addEdge, parentChildrenMap)); Set<String> nodesWithL1Edge = layer1LogicalTopology.getGraph().edges().stream() .flatMap(edge -> Stream.of(edge.getNode1(), edge.getNode2())) .map(Layer1Node::getHostname) .collect(ImmutableSet.toImmutableSet()); Set<String> nodesWithVxlan = vxlanTopology.getGraph().edges().stream() .flatMap(edge -> Stream.of(edge.nodeU(), edge.nodeV())) .map(VxlanNode::getHostname) .collect(ImmutableSet.toImmutableSet()); Set<String> nodesWithUsefulL2SelfEdges = ImmutableSet.<String>builder().addAll(nodesWithL1Edge).addAll(nodesWithVxlan).build(); configurations.values().stream() .filter(c -> nodesWithUsefulL2SelfEdges.contains(c.getHostname())) .forEach(c -> computeLayer2SelfEdges(c, l2TopologyBuilder::addEdge)); computeVniInterNodeEdges(vxlanTopology).forEach(l2TopologyBuilder::addEdge); return l2TopologyBuilder.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 Layer2Topology computeLayer2Topology( @Nonnull Layer1Topology layer1LogicalTopology, VxlanTopology vxlanTopology, @Nonnull Map<String, Configuration> configurations) { Layer2Topology.Builder l2TopologyBuilder = Layer2Topology.builder(); Map<Layer1Node, Set<Layer1Node>> parentChildrenMap = computeParentChildrenMap(configurations); layer1LogicalTopology .getGraph() .edges() .forEach( layer1Edge -> computeLayer2EdgesForLayer1Edge( layer1Edge, configurations, l2TopologyBuilder::addEdge, parentChildrenMap)); Set<String> nodesWithL1Edge = layer1LogicalTopology.getGraph().edges().stream() .flatMap(edge -> Stream.of(edge.getNode1(), edge.getNode2())) .map(Layer1Node::getHostname) .collect(ImmutableSet.toImmutableSet()); Set<String> nodesWithVxlan = vxlanTopology.getGraph().edges().stream() .flatMap(edge -> Stream.of(edge.nodeU(), edge.nodeV())) .map(VxlanNode::getHostname) .collect(ImmutableSet.toImmutableSet()); Set<String> nodesWithUsefulL2SelfEdges = ImmutableSet.<String>builder().addAll(nodesWithL1Edge).addAll(nodesWithVxlan).build(); configurations.values().stream() .filter(c -> nodesWithUsefulL2SelfEdges.contains(c.getHostname())) .forEach(c -> computeLayer2SelfEdges(c, l2TopologyBuilder::addEdge)); computeVniInterNodeEdges(vxlanTopology).forEach(l2TopologyBuilder::addEdge); return l2TopologyBuilder.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);  }