@Test public void testComputeLayer2TopologyTaggedLayer3ToTrunk() { String n1Name = "n1"; String n2Name = "n2"; String iTaggedName = "iTagged"; String iTrunkParentName = "iTrunkParent"; String iTrunkName = "iTrunk"; String iaName = "ia"; String ibName = "ib"; String icName = "ic"; String idName = "id"; int iaVlan = 10; int ibVlan = 20; int icVlan = 30; Configuration n1 = _cb.setHostname(n1Name).build(); Configuration n2 = _cb.setHostname(n2Name).build(); Vrf v1 = _vb.setOwner(n1).build(); Vrf v2 = _vb.setOwner(n2).build(); _ib.setActive(true); _ib.setOwner(n1).setVrf(v1); _ib.setName(iTaggedName).setDependencies(ImmutableList.of()).setEncapsulationVlan(null).build(); _ib.setDependencies(ImmutableList.of(new Dependency(iTaggedName, DependencyType.BIND))); _ib.setName(iaName).setEncapsulationVlan(iaVlan).build(); _ib.setName(ibName).setEncapsulationVlan(ibVlan).build(); _ib.setName(icName).setEncapsulationVlan(icVlan).build(); _ib.setName(idName).setEncapsulationVlan(null).build(); _ib.setOwner(n2).setVrf(v2); _ib.setDependencies(ImmutableList.of()).setEncapsulationVlan(null); Interface vlanA = _ib.setName(iaName).build(); vlanA.setInterfaceType(InterfaceType.VLAN); vlanA.setVlan(iaVlan); Interface vlanB = _ib.setName(ibName).build(); vlanB.setInterfaceType(InterfaceType.VLAN); vlanB.setVlan(ibVlan); Interface vlanC = _ib.setName(icName).build(); vlanC.setInterfaceType(InterfaceType.VLAN); vlanC.setVlan(icVlan); Interface vlanD = _ib.setName(idName).build(); vlanD.setInterfaceType(InterfaceType.VLAN); vlanD.setVlan(null); _ib.setName(iTrunkParentName).build(); Interface trunk = _ib.setName(iTrunkName) .setDependencies( ImmutableList.of(new Dependency(iTrunkParentName, DependencyType.BIND))) .build(); trunk.setNativeVlan(ibVlan); trunk.setAllowedVlans(IntegerSpace.builder().including(iaVlan).including(ibVlan).build()); trunk.setSwitchport(true); trunk.setSwitchportMode(SwitchportMode.TRUNK); Layer1Topology layer1LogicalTopology = layer1Topology( n1Name, iTaggedName, n2Name, iTrunkParentName ); Layer2Topology layer2Topology = computeLayer2Topology( layer1LogicalTopology, VxlanTopology.EMPTY, ImmutableMap.of(n1Name, n1, n2Name, n2)); assertTrue( "n1:ia and n2:ia are in the same broadcast domain", layer2Topology.inSameBroadcastDomain(n1Name, iaName, n2Name, iaName)); assertFalse( "n1:ib and n2:ib are NOT in the same broadcast domain", layer2Topology.inSameBroadcastDomain(n1Name, ibName, n2Name, ibName)); assertFalse( "n1:ic and n2:ic are NOT in the same broadcast domain", layer2Topology.inSameBroadcastDomain(n1Name, icName, n2Name, icName)); assertFalse( "n1:ia and n2:ib are NOT in the same broadcast domain", layer2Topology.inSameBroadcastDomain(n1Name, iaName, n2Name, ibName)); assertFalse( "n1:ia and n2:ic are NOT in the same broadcast domain", layer2Topology.inSameBroadcastDomain(n1Name, iaName, n2Name, icName)); }
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);  }