Skip to content
Edit this page

ictdesigntools.cabling.assemblies

Cable assemblies: a cable type and what is on each end, modelled as NetBox models cables.

An Assembly is a patch cord, a trunk or a breakout. Its profile follows NetBox 4.5's cable profiles: the connectors on each end and the positions (lanes: a fiber, a pair) on each connector, written single-1c12p (one 12-position connector each end), trunk-2c1p (two single-position connectors each end, a duplex LC cord) or breakout-1c8p-8c1p (an MPO-8 fanned out to eight single-position connectors). polarity says which A lane meets which B lane, by the TIA-568 connectivity types: A straight through, B reversed, C pairs flipped. A duplex cord made A-to-B is type B (or C, the same for two lanes); an A-to-A cord is type A. lanes() lists the map, so a path can be traced lane by lane through the cable, as NetBox traces it.

Ends name a connector from data/connectors.toml with its polish and, for MPO and MMC, its pins; breakouts carry their legs. spec gives the rows of a spec sheet and bom the lines of a bill of materials; assembly_drawing draws it with the same connector components the panels use. Generic assemblies come from data/assemblies.toml (assemblies()).

>>> cord = assembly("lc-lc-duplex-om4-2m")
>>> cord.profile.slug, cord.polarity, [(l.a, l.b) for l in cord.lanes()]
('trunk-2c1p', 'B', [((1, 1), (2, 1)), ((2, 1), (1, 1))])

Profile dataclass

Profile(
    a_connectors: int,
    a_positions: int,
    b_connectors: int,
    b_positions: int,
)

Connectors and positions on each end, as a NetBox cable profile.

parse classmethod

parse(slug: str) -> Profile

A profile from its NetBox slug. Shuffle profiles are not modelled yet: NetBox remaps their positions by its own tables, so they are refused rather than guessed.

Source code in src/ictdesigntools/cabling/assemblies.py
@classmethod
def parse(cls, slug: str) -> Profile:
    """A profile from its NetBox slug. Shuffle profiles are not modelled yet: NetBox remaps
    their positions by its own tables, so they are refused rather than guessed."""
    m = _PROFILE.match(slug)
    if not m:
        raise ValueError(f"“{slug}” is not a NetBox cable profile (single-1c12p, "
                         "trunk-2c1p, breakout-1c8p-8c1p).")  # fmt: skip
    kind, ac, ap, bc, bp, shuffle = m.groups()
    if shuffle:
        raise ValueError(f"Shuffle profiles such as “{slug}” are not modelled yet.")
    if (kind == "breakout") != (bc is not None):
        raise ValueError(f"“{slug}”: a breakout names both ends, a single or trunk one.")
    p = cls(int(ac), int(ap), int(bc or ac), int(bp or ap))
    if p.kind != kind:
        raise ValueError(f"“{slug}” is a {p.kind} profile by its counts.")
    return p

Lane dataclass

Lane(a: tuple[int, int], b: tuple[int, int])

One lane of a cable: (connector, position) on end A, and where it lands on end B.

End dataclass

End(connector: str, polish: str = '', pins: str = '')

label

label(positions: int = 0) -> str

The plug, its polish and pins: LC/UPC, MPO-8/APC/pinned (a multi-fiber connector given its positions).

Source code in src/ictdesigntools/cabling/assemblies.py
def label(self, positions: int = 0) -> str:
    """The plug, its polish and pins: ``LC/UPC``, ``MPO-8/APC/pinned`` (a multi-fiber
    connector given its positions)."""
    c = connector(self.connector)
    name = re.split(r"[ -]", c.name)[0]
    if positions and c.positions > 2:
        name += f"-{positions}"
    extra = [self.polish.upper()] if self.polish else []
    return "/".join([name, *extra, *([self.pins] if self.pins else [])])

Legs dataclass

Legs(leg_length_m: float, stagger_m: float = 0.0)

A breakout's legs: where the cable fans out, how long each leg is, and the stagger between successive legs (0 for even legs).

Assembly dataclass

Assembly(
    name: str,
    type: str,
    profile: Profile,
    a: End,
    b: End,
    length: float,
    length_unit: str = "m",
    polarity: str = "A",
    legs: Legs | None = None,
    label: str = "",
    color: str = "",
    cable: str = "",
    part_number: str = "",
    slug: str = "",
    source: str = "",
    problems: tuple[str, ...] = (),
)

A cable assembly, with NetBox's cable field names where NetBox has them (type, length, length_unit, label, color, profile).

end_label

end_label(side: str) -> str

A or B: how many of which plug, as 8 × LC/UPC.

Source code in src/ictdesigntools/cabling/assemblies.py
def end_label(self, side: str) -> str:
    """``A`` or ``B``: how many of which plug, as ``8 × LC/UPC``."""
    p = self.profile
    end, n, positions = ((self.a, p.a_connectors, p.a_positions) if side == "A"
                         else (self.b, p.b_connectors, p.b_positions))  # fmt: skip
    return f"{n} × {end.label(positions)}"

lanes

lanes() -> list[Lane]

Each lane from end A to end B, by the profile and the polarity: lanes are counted connector by connector, position by position, on both ends; type A keeps the count, type B reverses it, type C swaps each pair.

Source code in src/ictdesigntools/cabling/assemblies.py
def lanes(self) -> list[Lane]:
    """Each lane from end A to end B, by the profile and the polarity: lanes are counted
    connector by connector, position by position, on both ends; type A keeps the count,
    type B reverses it, type C swaps each pair."""
    p = self.profile
    n = p.lanes

    def at(k: int, positions: int) -> tuple[int, int]:
        return k // positions + 1, k % positions + 1

    out = []
    for k in range(n):
        j = {"A": k, "B": n - 1 - k, "C": k ^ 1}[self.polarity]
        out.append(Lane(at(k, p.a_positions), at(j, p.b_positions)))
    return out

assemblies cached

assemblies() -> dict[str, Assembly]

The generic assemblies in data/assemblies.toml, by slug.

Source code in src/ictdesigntools/cabling/assemblies.py
@cache
def assemblies() -> dict[str, Assembly]:
    """The generic assemblies in ``data/assemblies.toml``, by slug."""
    return {r["slug"]: _assembly(r) for r in rows("assemblies", "assembly")}

spec

spec(asm: Assembly) -> list[tuple[str, str]]

The rows of a spec sheet, as (field, value).

Source code in src/ictdesigntools/cabling/assemblies.py
def spec(asm: Assembly) -> list[tuple[str, str]]:
    """The rows of a spec sheet, as (field, value)."""
    p = asm.profile
    out = [
        ("Name", asm.name),
        ("Cable type", asm.type),
        ("Profile", f"{p.slug} ({p.lanes} lanes)"),
        ("End A", asm.end_label("A")),
        ("End B", asm.end_label("B")),
        ("Length", f"{asm.length:g} {asm.length_unit}"),
        ("Polarity", f"Type {asm.polarity} (TIA-568)"),
    ]
    if asm.legs:
        stagger = f", staggered {asm.legs.stagger_m:g} m" if asm.legs.stagger_m else ""
        out.append(("Legs", f"{asm.legs.leg_length_m:g} m{stagger}"))
    for name, v in (("Label", asm.label), ("Colour", asm.color),
                    ("Part number", asm.part_number)):  # fmt: skip
        if v:
            out.append((name, v))
    return out

bom

bom(items: list[Assembly]) -> list[tuple]

Bill of materials lines: one per distinct assembly, with its count (see BOM_HEADER).

Source code in src/ictdesigntools/cabling/assemblies.py
def bom(items: list[Assembly]) -> list[tuple]:
    """Bill of materials lines: one per distinct assembly, with its count (see ``BOM_HEADER``)."""
    counts = Counter(items)
    return [
        (n, a.name, a.type, a.profile.slug, a.end_label("A"), a.end_label("B"),
         f"{a.length:g} {a.length_unit}", a.part_number)
        for a, n in counts.items()
    ]  # fmt: skip

assembly_drawing

assembly_drawing(
    asm: Assembly, detail: str = "detailed"
) -> Drawing

The assembly from the side, cable length not to scale: end A's connectors on the left, the cable, and end B's connectors (on legs from the breakout for a breakout) on the right, the length dimensioned, and the lane map under it.

detail="detailed" draws each plug from parts.plugs at 1:1 (its housing in the TIA-568 colour for the cable type and polish) with each end's mating face enlarged below, fiber positions numbered; "simple" draws plain bodies with the panel footprints.

Source code in src/ictdesigntools/cabling/assemblies.py
def assembly_drawing(asm: Assembly, detail: str = "detailed") -> Drawing:
    """The assembly from the side, cable length not to scale: end A's connectors on the left,
    the cable, and end B's connectors (on legs from the breakout for a breakout) on the right,
    the length dimensioned, and the lane map under it.

    ``detail="detailed"`` draws each plug from ``parts.plugs`` at 1:1 (its housing in the
    TIA-568 colour for the cable type and polish) with each end's mating face enlarged below,
    fiber positions numbered; ``"simple"`` draws plain bodies with the panel footprints."""
    if detail not in ("detailed", "simple"):
        raise ValueError("detail is detailed or simple.")
    from ..parts.plugs import PART_STYLES, plug, plug_face, plug_side, plugs, tone_for

    p = asm.profile
    detailed = detail == "detailed" and asm.a.connector in plugs() and asm.b.connector in plugs()
    if detailed:
        pa, pb = plug(asm.a.connector), plug(asm.b.connector)
        len_a, len_b = pa.body_mm + pa.boot_mm, pb.body_mm + pb.boot_mm
        pitch = max(pa.housing_h_mm, pb.housing_h_mm) + 6.0
        cord_a, cord_b = pa.cable_mm, pb.cable_mm  # the cable meets each boot at its size
    else:
        len_a = len_b = BODY_MM + BOOT_MM
        pitch = 16.0
        cord_a = cord_b = 2.2
    n = max(p.a_connectors, p.b_connectors)
    height = n * pitch
    styles = {
        "cable": Style(stroke="#5f5e58", width=cord_a),
        "leg": Style(stroke="#5f5e58", width=cord_b if asm.legs else cord_a),
        "boot": Style(fill="#d6d5cf", stroke=MUTED, width=0.35),
        "body": Style(fill="#f1f0ec", stroke=INK, width=0.35),
        "furcation": Style(fill="#3c3b37", stroke=INK, width=0.35),
        "label": Style(color=INK),
        "quiet": Style(color=MUTED),
        "port": Style(fill="#1d1c1a", stroke="#8f8e84", width=0.3),
        "port-core": Style(fill="#5f5e58"),
        **(PART_STYLES if detailed else {}),
    }
    lanes = asm.lanes()
    lane_rows = (len(lanes) + 3) // 4
    face_h = 46.0 if detailed else 0.0
    total_h = height + 34 + face_h + lane_rows * 5 + 10
    width = 2 * 22 + len_a + len_b + CABLE_MM + (LEG_MM if asm.legs else 0)
    d = Drawing(view=(-4, -14, width + 8, total_h + 14), units="mm", stroke=0.35, font=3.0,
                title=asm.name, desc=f"{p.slug}, type {asm.polarity}, {asm.length:g} "
                f"{asm.length_unit}. Cable length not to scale"
                f"{'; plugs 1:1, bodies schematic' if detailed else ''}.",
                styles=styles)  # fmt: skip
    d.add(Text(0, -8, truncate(asm.name, 4.0, width), 4.0, anchor="start", style="label"))
    mid = height / 2

    def simple(x: float, y: float, end: End, k: int, left: bool) -> None:
        """A connector: face, body and boot, pointing outwards."""
        face = connector_component(end.connector)
        c = connector(end.connector)
        scale_h = min(c.height_mm, pitch - 4)
        fx = x - 6 if left else x + 6
        d.add(Use(face, translate(fx, y), title=f"{end.label()} {k}"))
        # Face outwards, then body, then the boot towards the cable.
        body = x if left else x - BODY_MM
        boot = x + BODY_MM if left else x - BODY_MM - BOOT_MM
        d.add(Rect(body, y - scale_h / 2, BODY_MM, scale_h, rx=1, style="body"))
        d.add(Rect(boot, y - scale_h / 3, BOOT_MM, scale_h * 2 / 3, rx=2, style="boot"))
        d.add(Text(fx, y + pitch / 2 - 0.5, str(k), 2.4, style="quiet"))

    def fine(x: float, y: float, end: End, k: int, left: bool, positions: int) -> None:
        """A detailed plug at 1:1, its mating face at x, pointing outwards."""
        tone = tone_for(asm.type, end.polish)
        side = plug_side(end.connector, tone)
        t = translate(x, y) if left else translate(x, y) @ Transform.mirror_x()
        d.add(Use(side, t, title=f"{end.label(positions)} {k}"))
        lx = x - 4 if left else x + 4
        d.add(Text(lx, y + 1, str(k), 2.4, anchor="end" if left else "start", style="quiet"))

    xa = 22.0
    ea = xa + len_a  # where the cable leaves end A
    ys_a = [mid + (i - (p.a_connectors - 1) / 2) * pitch for i in range(p.a_connectors)]
    xb = ea + CABLE_MM + (LEG_MM if asm.legs else 0)  # where end B's boots start
    ys_b = [mid + (i - (p.b_connectors - 1) / 2) * pitch for i in range(p.b_connectors)]
    for i, y in enumerate(ys_a, 1):
        if detailed:
            fine(xa, y, asm.a, i, True, p.a_positions)
        else:
            simple(xa, y, asm.a, i, True)
    for i, y in enumerate(ys_b, 1):
        if detailed:
            fine(xb + len_b, y, asm.b, i, False, p.b_positions)
        else:
            simple(xb + len_b, y, asm.b, i, False)
    # The cable, joining the boots: a trunk bundles at each end, a breakout at its furcation.
    # A multi-cord trunk (a duplex zipcord) runs its cords apart for a third of the way, then
    # joins: split = 0.3 of the cable from each end, each cord curving in over BEND_MM.
    split = CABLE_MM * 0.3
    join_a, join_b = ea + split, (ea + CABLE_MM if asm.legs else xb - split)
    if p.a_connectors == 1:  # one plug: the cable runs straight out of its boot
        join_a = ea
    if p.b_connectors == 1:
        join_b = xb
    # Legs and bundled cords leave and arrive level, curving between, as they lie on a bench.
    leg = "leg" if asm.legs else "cable"
    for y in ys_a if join_a > ea else ():
        bend = join_a - BEND_MM
        d.add(Polyline((((ea, y),) + tuple(s_curve((bend, y), (join_a, mid)))), style="cable"))
    d.add(Line(join_a, mid, join_b, mid, style="cable"))
    for y in ys_b if join_b < xb else ():
        if asm.legs:  # legs fan out from the furcation all the way to their plugs
            d.add(Polyline(tuple(s_curve((join_b, mid), (xb, y))), style=leg))
        else:
            bend = join_b + BEND_MM
            pts = tuple(s_curve((join_b, mid), (bend, y))) + ((xb, y),)
            d.add(Polyline(pts, style=leg))
    if asm.legs:
        d.add(Rect(join_b - 7, mid - 2.6, 14, 5.2, rx=2.6, style="furcation", title="Furcation"))
        legs = f"Legs {asm.legs.leg_length_m:g} m"
        if asm.legs.stagger_m:
            legs += f", staggered {asm.legs.stagger_m:g} m"
        d.add(Text((join_b + xb) / 2, mid - height / 2 - 3, legs, 2.6, style="quiet"))
    d.add(Dim(xa, height + 6, xb + len_b, height + 6,
              f"{asm.length:g} {asm.length_unit}", -4))  # fmt: skip
    y = height + 18
    if detailed:
        # Each end's mating face, enlarged, key up, as seen looking into the plug.
        ends = ((xa + 10, asm.a, p.a_positions, "A", pa),
                (xb + len_b - 10, asm.b, p.b_positions, "B", pb))  # fmt: skip
        for x, end, positions, name, pl in ends:
            mag = min(3.0, (face_h - 8) / max(pl.housing_w_mm, pl.housing_h_mm + 1.6))
            face = plug_face(end.connector, positions if pl.ferrule == "mt" else 0,
                             end.pins, tone_for(asm.type, end.polish))  # fmt: skip
            d.add(Use(face, translate(x, y + face_h / 2 - 4) @ scale(mag),
                      title=f"End {name} face"))  # fmt: skip
            d.add(Text(x, y + face_h - 6, f"End {name} face ×{mag:.3g}", 2.4, style="quiet"))
        y += face_h
    d.add(Text(0, y, f"A: {asm.end_label('A')} · B: {asm.end_label('B')} · {p.slug} · "
               f"type {asm.polarity} · {asm.type}", 2.8,
               anchor="start", style="label"))  # fmt: skip
    # The lane map, four to a row: A connector.position → B connector.position.
    for k, lane in enumerate(lanes):
        r, c = divmod(k, 4)
        text = f"A{lane.a[0]}.{lane.a[1]} → B{lane.b[0]}.{lane.b[1]}"
        d.add(Text(c * (width / 4), y + 8 + r * 5, text, 2.6, anchor="start",
                   style="quiet"))  # fmt: skip
    return d