@Test public void testMiniFatTreeExtension() throws IOException { File inFile = constructGraph( 6, 16, "incl_range(2,5)", "set(0,1)", "incl_range(2,5)", "2 0\n0 2\n2 1\n1 2\n3 0\n0 3\n3 1\n1 3\n4 0\n0 4\n4 1\n1 4\n5 0\n0 5\n5 1\n1 5" ); File tempOut = File.createTempFile("topology", ".tmp"); TopologyServerExtender extender = new TopologyServerExtender(inFile.getAbsolutePath(), tempOut.getAbsolutePath()); extender.extendRegular(7); assertTrue(inFile.delete()); Pair<Graph, GraphDetails> res = GraphReader.read(tempOut.getAbsolutePath()); GraphDetails details = res.getRight(); assertEquals(34, details.getNumNodes()); assertEquals(72, details.getNumEdges()); assertTrue(details.isAutoExtended()); assertEquals(createSet(2, 3, 4, 5), details.getTorNodeIds()); assertEquals(createSet(0, 1), details.getSwitchNodeIds()); Set<Integer> servers = new HashSet<>(); for (int i = 6; i < 34; i++ ) { servers.add(i); } assertEquals(servers, details.getServerNodeIds()); for (int i = 6; i < 34; i++ ) { assertEquals((int) details.getTorIdOfServer(i), 2 + (int) Math.floor((double) (i - 6) / 7.0)); } for (int i = 2; i <= 5; i++ ) { Set<Integer> torServers = new HashSet<>(); for (int j = 6 + (i - 2) * 7; j < 6 + (i - 1) * 7; j++ ) { torServers.add(j); } assertEquals(torServers, details.getServersOfTor(i)); } assertTrue(tempOut.delete()); }
public void extendRegular(int serversPerTransportLayerNode) { Pair<Graph, GraphDetails> original = GraphReader.read(topologyFileNameIn); Graph graph = original.getLeft(); GraphDetails details = original.getRight(); if (!details.getTorNodeIds().equals(details.getServerNodeIds())) { throw new IllegalArgumentException( "Only a topology of which all its ToRs are marked as servers, " + "and nothing else, is possible to be extended." ); } try { System.out.println( "Extending topology file \"" + topologyFileNameIn + "\" by adding " + serversPerTransportLayerNode + " servers to each ToR." ); System.out.print("Writing to output topology file..."); BufferedWriter outputWriter = new BufferedWriter(new FileWriter(topologyFileNameOut)); outputWriter.write("# Extension with " + serversPerTransportLayerNode + " servers/TL node of topology file \"" + topologyFileNameIn + "\"\n\n"); int originalN = details.getNumNodes(); int additionalNodes = serversPerTransportLayerNode * details.getServerNodeIds().size(); int newN = originalN + additionalNodes; outputWriter.write("# Extended details\n"); outputWriter.write("|V|=" + newN + "\n"); outputWriter.write("|E|=" + (details.getNumEdges() + additionalNodes * 2) + "\n"); outputWriter.write("AutoExtended=true\n"); outputWriter.write("Servers=incl_range(" + originalN + ", " + (newN - 1) + ")\n"); outputWriter.write("Switches=set(" + StringUtils.join(details.getSwitchNodeIds(), ",") + ")\n"); outputWriter.write("ToRs=set(" + StringUtils.join(details.getTorNodeIds(), ",") + ")\n\n"); outputWriter.write("# Original " + details.getNumEdges() + " links:\n"); for (Vertex v : graph.getVertexList()) { for (Vertex w : graph.getAdjacentVertices(v)) { outputWriter.write(v.getId() + " " + w.getId() + "\n"); } } outputWriter.write("\n# Extended " + (additionalNodes * 2) + " links:\n"); int addedSoFar = 0; for (Integer nodeId : details.getTorNodeIds()) { for (int s = 0; s < serversPerTransportLayerNode; s++) { outputWriter.write((originalN + addedSoFar) + " " + nodeId + "\n"); outputWriter.write(nodeId + " " + (originalN + addedSoFar) + "\n"); addedSoFar++; } } outputWriter.close(); System.out.println(" done."); } catch (IOException e) { throw new RuntimeException("TopologyServerExtender: failed to read/write a topology file: " + e.getMessage()); } }
TopologyServerExtender { public void extendRegular(int serversPerTransportLayerNode) { Pair<Graph, GraphDetails> original = GraphReader.read(topologyFileNameIn); Graph graph = original.getLeft(); GraphDetails details = original.getRight(); if (!details.getTorNodeIds().equals(details.getServerNodeIds())) { throw new IllegalArgumentException( "Only a topology of which all its ToRs are marked as servers, " + "and nothing else, is possible to be extended." ); } try { System.out.println( "Extending topology file \"" + topologyFileNameIn + "\" by adding " + serversPerTransportLayerNode + " servers to each ToR." ); System.out.print("Writing to output topology file..."); BufferedWriter outputWriter = new BufferedWriter(new FileWriter(topologyFileNameOut)); outputWriter.write("# Extension with " + serversPerTransportLayerNode + " servers/TL node of topology file \"" + topologyFileNameIn + "\"\n\n"); int originalN = details.getNumNodes(); int additionalNodes = serversPerTransportLayerNode * details.getServerNodeIds().size(); int newN = originalN + additionalNodes; outputWriter.write("# Extended details\n"); outputWriter.write("|V|=" + newN + "\n"); outputWriter.write("|E|=" + (details.getNumEdges() + additionalNodes * 2) + "\n"); outputWriter.write("AutoExtended=true\n"); outputWriter.write("Servers=incl_range(" + originalN + ", " + (newN - 1) + ")\n"); outputWriter.write("Switches=set(" + StringUtils.join(details.getSwitchNodeIds(), ",") + ")\n"); outputWriter.write("ToRs=set(" + StringUtils.join(details.getTorNodeIds(), ",") + ")\n\n"); outputWriter.write("# Original " + details.getNumEdges() + " links:\n"); for (Vertex v : graph.getVertexList()) { for (Vertex w : graph.getAdjacentVertices(v)) { outputWriter.write(v.getId() + " " + w.getId() + "\n"); } } outputWriter.write("\n# Extended " + (additionalNodes * 2) + " links:\n"); int addedSoFar = 0; for (Integer nodeId : details.getTorNodeIds()) { for (int s = 0; s < serversPerTransportLayerNode; s++) { outputWriter.write((originalN + addedSoFar) + " " + nodeId + "\n"); outputWriter.write(nodeId + " " + (originalN + addedSoFar) + "\n"); addedSoFar++; } } outputWriter.close(); System.out.println(" done."); } catch (IOException e) { throw new RuntimeException("TopologyServerExtender: failed to read/write a topology file: " + e.getMessage()); } } }
TopologyServerExtender { public void extendRegular(int serversPerTransportLayerNode) { Pair<Graph, GraphDetails> original = GraphReader.read(topologyFileNameIn); Graph graph = original.getLeft(); GraphDetails details = original.getRight(); if (!details.getTorNodeIds().equals(details.getServerNodeIds())) { throw new IllegalArgumentException( "Only a topology of which all its ToRs are marked as servers, " + "and nothing else, is possible to be extended." ); } try { System.out.println( "Extending topology file \"" + topologyFileNameIn + "\" by adding " + serversPerTransportLayerNode + " servers to each ToR." ); System.out.print("Writing to output topology file..."); BufferedWriter outputWriter = new BufferedWriter(new FileWriter(topologyFileNameOut)); outputWriter.write("# Extension with " + serversPerTransportLayerNode + " servers/TL node of topology file \"" + topologyFileNameIn + "\"\n\n"); int originalN = details.getNumNodes(); int additionalNodes = serversPerTransportLayerNode * details.getServerNodeIds().size(); int newN = originalN + additionalNodes; outputWriter.write("# Extended details\n"); outputWriter.write("|V|=" + newN + "\n"); outputWriter.write("|E|=" + (details.getNumEdges() + additionalNodes * 2) + "\n"); outputWriter.write("AutoExtended=true\n"); outputWriter.write("Servers=incl_range(" + originalN + ", " + (newN - 1) + ")\n"); outputWriter.write("Switches=set(" + StringUtils.join(details.getSwitchNodeIds(), ",") + ")\n"); outputWriter.write("ToRs=set(" + StringUtils.join(details.getTorNodeIds(), ",") + ")\n\n"); outputWriter.write("# Original " + details.getNumEdges() + " links:\n"); for (Vertex v : graph.getVertexList()) { for (Vertex w : graph.getAdjacentVertices(v)) { outputWriter.write(v.getId() + " " + w.getId() + "\n"); } } outputWriter.write("\n# Extended " + (additionalNodes * 2) + " links:\n"); int addedSoFar = 0; for (Integer nodeId : details.getTorNodeIds()) { for (int s = 0; s < serversPerTransportLayerNode; s++) { outputWriter.write((originalN + addedSoFar) + " " + nodeId + "\n"); outputWriter.write(nodeId + " " + (originalN + addedSoFar) + "\n"); addedSoFar++; } } outputWriter.close(); System.out.println(" done."); } catch (IOException e) { throw new RuntimeException("TopologyServerExtender: failed to read/write a topology file: " + e.getMessage()); } } TopologyServerExtender(String topologyFileNameIn, String topologyFileNameOut); }
TopologyServerExtender { public void extendRegular(int serversPerTransportLayerNode) { Pair<Graph, GraphDetails> original = GraphReader.read(topologyFileNameIn); Graph graph = original.getLeft(); GraphDetails details = original.getRight(); if (!details.getTorNodeIds().equals(details.getServerNodeIds())) { throw new IllegalArgumentException( "Only a topology of which all its ToRs are marked as servers, " + "and nothing else, is possible to be extended." ); } try { System.out.println( "Extending topology file \"" + topologyFileNameIn + "\" by adding " + serversPerTransportLayerNode + " servers to each ToR." ); System.out.print("Writing to output topology file..."); BufferedWriter outputWriter = new BufferedWriter(new FileWriter(topologyFileNameOut)); outputWriter.write("# Extension with " + serversPerTransportLayerNode + " servers/TL node of topology file \"" + topologyFileNameIn + "\"\n\n"); int originalN = details.getNumNodes(); int additionalNodes = serversPerTransportLayerNode * details.getServerNodeIds().size(); int newN = originalN + additionalNodes; outputWriter.write("# Extended details\n"); outputWriter.write("|V|=" + newN + "\n"); outputWriter.write("|E|=" + (details.getNumEdges() + additionalNodes * 2) + "\n"); outputWriter.write("AutoExtended=true\n"); outputWriter.write("Servers=incl_range(" + originalN + ", " + (newN - 1) + ")\n"); outputWriter.write("Switches=set(" + StringUtils.join(details.getSwitchNodeIds(), ",") + ")\n"); outputWriter.write("ToRs=set(" + StringUtils.join(details.getTorNodeIds(), ",") + ")\n\n"); outputWriter.write("# Original " + details.getNumEdges() + " links:\n"); for (Vertex v : graph.getVertexList()) { for (Vertex w : graph.getAdjacentVertices(v)) { outputWriter.write(v.getId() + " " + w.getId() + "\n"); } } outputWriter.write("\n# Extended " + (additionalNodes * 2) + " links:\n"); int addedSoFar = 0; for (Integer nodeId : details.getTorNodeIds()) { for (int s = 0; s < serversPerTransportLayerNode; s++) { outputWriter.write((originalN + addedSoFar) + " " + nodeId + "\n"); outputWriter.write(nodeId + " " + (originalN + addedSoFar) + "\n"); addedSoFar++; } } outputWriter.close(); System.out.println(" done."); } catch (IOException e) { throw new RuntimeException("TopologyServerExtender: failed to read/write a topology file: " + e.getMessage()); } } TopologyServerExtender(String topologyFileNameIn, String topologyFileNameOut); void extendRegular(int serversPerTransportLayerNode); }
TopologyServerExtender { public void extendRegular(int serversPerTransportLayerNode) { Pair<Graph, GraphDetails> original = GraphReader.read(topologyFileNameIn); Graph graph = original.getLeft(); GraphDetails details = original.getRight(); if (!details.getTorNodeIds().equals(details.getServerNodeIds())) { throw new IllegalArgumentException( "Only a topology of which all its ToRs are marked as servers, " + "and nothing else, is possible to be extended." ); } try { System.out.println( "Extending topology file \"" + topologyFileNameIn + "\" by adding " + serversPerTransportLayerNode + " servers to each ToR." ); System.out.print("Writing to output topology file..."); BufferedWriter outputWriter = new BufferedWriter(new FileWriter(topologyFileNameOut)); outputWriter.write("# Extension with " + serversPerTransportLayerNode + " servers/TL node of topology file \"" + topologyFileNameIn + "\"\n\n"); int originalN = details.getNumNodes(); int additionalNodes = serversPerTransportLayerNode * details.getServerNodeIds().size(); int newN = originalN + additionalNodes; outputWriter.write("# Extended details\n"); outputWriter.write("|V|=" + newN + "\n"); outputWriter.write("|E|=" + (details.getNumEdges() + additionalNodes * 2) + "\n"); outputWriter.write("AutoExtended=true\n"); outputWriter.write("Servers=incl_range(" + originalN + ", " + (newN - 1) + ")\n"); outputWriter.write("Switches=set(" + StringUtils.join(details.getSwitchNodeIds(), ",") + ")\n"); outputWriter.write("ToRs=set(" + StringUtils.join(details.getTorNodeIds(), ",") + ")\n\n"); outputWriter.write("# Original " + details.getNumEdges() + " links:\n"); for (Vertex v : graph.getVertexList()) { for (Vertex w : graph.getAdjacentVertices(v)) { outputWriter.write(v.getId() + " " + w.getId() + "\n"); } } outputWriter.write("\n# Extended " + (additionalNodes * 2) + " links:\n"); int addedSoFar = 0; for (Integer nodeId : details.getTorNodeIds()) { for (int s = 0; s < serversPerTransportLayerNode; s++) { outputWriter.write((originalN + addedSoFar) + " " + nodeId + "\n"); outputWriter.write(nodeId + " " + (originalN + addedSoFar) + "\n"); addedSoFar++; } } outputWriter.close(); System.out.println(" done."); } catch (IOException e) { throw new RuntimeException("TopologyServerExtender: failed to read/write a topology file: " + e.getMessage()); } } TopologyServerExtender(String topologyFileNameIn, String topologyFileNameOut); void extendRegular(int serversPerTransportLayerNode);  }