Leaf-spine (two-tier Clos) fabrics: the graph, and what each leaf can carry.
leaf_spine builds the fabric as a draw.graph.Graph: every leaf linked to every spine
(uplinks links to each, drawn as one edge with a count), and optionally the servers under
each leaf. fabric_report gives each leaf's downlink and uplink capacity, its
oversubscription ratio and the number of equal-cost paths between two leaves, the figures a
fabric is sized by.
>>> fabric = leaf_spine(spines=4, leaves=8, uplink_gbps=400, downlinks=48, downlink_gbps=100)
>>> r = fabric_report(fabric)
>>> r.oversubscription, r.ecmp_paths
(3.0, 4)
FabricReport(
spines: int,
leaves: int,
downlink_gbps: float,
uplink_gbps: float,
ecmp_paths: int,
)
Downlink to uplink capacity at a leaf (3.0 means 3:1).
Capacity between the leaves and the spines, all leaves together.
leaf_spine(
spines: int,
leaves: int,
uplink_gbps: float,
downlinks: int,
downlink_gbps: float,
uplinks: int = 1,
servers: int = 0,
server_links: int = 1,
) -> Graph
A two-tier fabric: spines × leaves, each leaf with uplinks links of
uplink_gbps to every spine and downlinks ports of downlink_gbps towards servers.
servers adds that many server nodes under each leaf (for drawing; capacity comes from
downlinks). Node attributes: role, tier; leaves also downlinks and
downlink_gbps. Edge attributes: speed (e.g. "400G"), gbps.
Source code in src/ictdesigntools/network/clos.py
| def leaf_spine(spines: int, leaves: int, uplink_gbps: float, downlinks: int,
downlink_gbps: float, uplinks: int = 1, servers: int = 0,
server_links: int = 1) -> Graph: # fmt: skip
"""A two-tier fabric: ``spines`` × ``leaves``, each leaf with ``uplinks`` links of
``uplink_gbps`` to every spine and ``downlinks`` ports of ``downlink_gbps`` towards servers.
``servers`` adds that many server nodes under each leaf (for drawing; capacity comes from
``downlinks``). Node attributes: ``role``, ``tier``; leaves also ``downlinks`` and
``downlink_gbps``. Edge attributes: ``speed`` (e.g. ``"400G"``), ``gbps``."""
if spines < 1 or leaves < 1 or uplinks < 1:
raise ValueError("A fabric needs at least one spine, one leaf and one uplink.")
g = Graph(multigraph=uplinks > 1)
for s in range(1, spines + 1):
g.add_node(f"spine{s}", role="spine", tier=0)
for leaf in range(1, leaves + 1):
name = f"leaf{leaf}"
g.add_node(name, role="leaf", tier=1, downlinks=downlinks, downlink_gbps=downlink_gbps)
for s in range(1, spines + 1):
for k in range(uplinks):
g.add_edge(f"spine{s}", name, key=k, speed=_speed(uplink_gbps), gbps=uplink_gbps)
for h in range(1, servers + 1):
server = f"{name}-srv{h}"
g.add_node(server, role="server", tier=2)
for k in range(server_links):
g.add_edge(name, server, key=k, speed=_speed(downlink_gbps), gbps=downlink_gbps)
return g
|
Capacity figures for a fabric from leaf_spine (or any graph with role spine and
leaf nodes, gbps on the edges and downlinks / downlink_gbps on leaves).
Source code in src/ictdesigntools/network/clos.py
| def fabric_report(g: Graph) -> FabricReport:
"""Capacity figures for a fabric from ``leaf_spine`` (or any graph with ``role`` ``spine`` and
``leaf`` nodes, ``gbps`` on the edges and ``downlinks`` / ``downlink_gbps`` on leaves)."""
spines = [n for n, a in g.nodes.items() if a.get("role") == "spine"]
leaves = [n for n, a in g.nodes.items() if a.get("role") == "leaf"]
if not spines or not leaves:
raise ValueError("The graph has no spine or no leaf nodes.")
spine_set = set(spines)
leaf = leaves[0]
up = [e for e in g.edges if leaf in (e.u, e.v) and ({e.u, e.v} & spine_set)]
up_gbps = sum(float(e.attrs.get("gbps", 0)) for e in up)
a = g.nodes[leaf]
down_gbps = float(a.get("downlinks", 0)) * float(a.get("downlink_gbps", 0))
return FabricReport(len(spines), len(leaves), down_gbps, up_gbps, ecmp_paths=len(up))
|