Skip to content
Edit this page

ictdesigntools.network.pon

Passive optical networks: a split plan as a graph, and the loss to every ONT.

gpon builds the tree from the OLT port through splitter stages to the ONTs, with the fibre length of each run on its edge, as a draw.graph.Graph (to_networkx() hands it to networkx). ont_losses walks every path from the OLT and works out its link attenuation with optical.budget (fibre, splices, connectors, the splitters on the path and the cable margin), against the attenuation range of a PON class, so each ONT can be drawn and listed with its loss and margin. The losses are written back on the ONT nodes (loss_db, margin_db, passes), ready for draw.graph.topology.

>>> plan = gpon([8, 4], feeder_m=2000, distribution_m=[400], drop_m=60)
>>> len([n for n, a in plan.nodes.items() if a["role"] == "ont"])
32
>>> losses = ont_losses(plan)
>>> round(losses["ont-1"].loss.total_db, 2), losses["ont-1"].passes
(25.44, True)

OntLoss dataclass

OntLoss(
    ont: Hashable,
    path: tuple[Hashable, ...],
    loss: LossResult,
    range_db: tuple[float, float],
)

margin_db property

margin_db: float

Attenuation left before the class maximum (negative: over).

gpon

gpon(
    splits: Sequence[int],
    feeder_m: float,
    distribution_m: Sequence[float] = (),
    drop_m: float = 50.0,
    olt: str = "olt",
    ont_prefix: str = "ont",
) -> Graph

A split plan as a tree: splits are the splitter ratios from the OLT out ([8, 4] is a 1:8 then a 1:4 in each of its legs, 32 ONTs); feeder_m runs from the OLT to the first splitter, distribution_m from each stage to the next (one length per gap), and drop_m from the last splitter to each ONT. Node attributes: role (olt, splitter, ont), tier, and split on splitters; edge attribute length_m.

Source code in src/ictdesigntools/network/pon.py
def gpon(splits: Sequence[int], feeder_m: float, distribution_m: Sequence[float] = (),
         drop_m: float = 50.0, olt: str = "olt", ont_prefix: str = "ont") -> Graph:  # fmt: skip
    """A split plan as a tree: ``splits`` are the splitter ratios from the OLT out (``[8, 4]``
    is a 1:8 then a 1:4 in each of its legs, 32 ONTs); ``feeder_m`` runs from the OLT to the
    first splitter, ``distribution_m`` from each stage to the next (one length per gap), and
    ``drop_m`` from the last splitter to each ONT. Node attributes: ``role`` (``olt``,
    ``splitter``, ``ont``), ``tier``, and ``split`` on splitters; edge attribute ``length_m``."""
    for ratio in splits:
        if f"1x{ratio}" not in SPLITTERS:
            raise OpticalError(f"1:{ratio} is not a supported splitter ratio.")
    total = 1
    for ratio in splits:
        total *= ratio
    if total > 128:
        raise OpticalError(f"A 1:{total} split is more than a GPON port serves (1:128).")
    if len(distribution_m) not in (0, max(len(splits) - 1, 0)):
        raise OpticalError("Give one distribution length per gap between splitter stages.")
    gaps = list(distribution_m) or [0.0] * max(len(splits) - 1, 0)

    g = Graph()
    g.add_node(olt, role="olt", tier=0, label=olt.upper())
    # The first stage hangs off the OLT port; each later stage puts a splitter on every output
    # of each splitter before it; the ONTs take the last stage's outputs.
    level = [(olt, 1)]  # (node, outputs)
    for stage, ratio in enumerate(splits):
        length = feeder_m if stage == 0 else gaps[stage - 1]
        nxt = []
        for parent, outputs in level:
            for _ in range(outputs):
                name = f"s{stage + 1}-{len(nxt) + 1}"
                g.add_node(name, role="splitter", tier=stage + 1, split=f"1:{ratio}",
                           label=f"1:{ratio}")  # fmt: skip
                g.add_edge(parent, name, length_m=length)
                nxt.append((name, ratio))
        level = nxt
    count = 0
    for parent, outputs in level:
        for _ in range(outputs):
            count += 1
            name = f"{ont_prefix}-{count}"
            g.add_node(name, role="ont", tier=len(splits) + 1, label=f"ONT {count}")
            g.add_edge(parent, name, length_m=drop_m)
    return g

ont_losses

ont_losses(
    g: Graph,
    root: Hashable = "olt",
    pon_class: str = "gpon-b-plus",
    wavelength_nm: int = 1490,
    connectors_per_splitter: int = 2,
    end_connectors: int = 2,
    splices_per_run: int = 2,
    margin_db: float = DEFAULT_MARGIN,
    write: bool = True,
) -> dict[Hashable, OntLoss]

The link attenuation from root to every ONT (role == "ont"): fibre over the path's length_m, splices_per_run on each run, a connector pair at each end and connectors_per_splitter at each splitter, the splitters' insertion loss (split "1:n", or insertion_loss_db), plus the cable margin; checked against the attenuation range of pon_class (gpon-b-plus, gpon-c-plus …). With write the results go on the ONT nodes as loss_db, margin_db and passes.

Source code in src/ictdesigntools/network/pon.py
def ont_losses(g: Graph, root: Hashable = "olt", pon_class: str = "gpon-b-plus",
               wavelength_nm: int = 1490, connectors_per_splitter: int = 2,
               end_connectors: int = 2, splices_per_run: int = 2,
               margin_db: float = DEFAULT_MARGIN,
               write: bool = True) -> dict[Hashable, OntLoss]:  # fmt: skip
    """The link attenuation from ``root`` to every ONT (``role == "ont"``): fibre over the path's
    ``length_m``, ``splices_per_run`` on each run, a connector pair at each end and
    ``connectors_per_splitter`` at each splitter, the splitters' insertion loss (``split``
    ``"1:n"``, or ``insertion_loss_db``), plus the cable margin; checked against the attenuation
    range of ``pon_class`` (``gpon-b-plus``, ``gpon-c-plus`` …). With ``write`` the results go on
    the ONT nodes as ``loss_db``, ``margin_db`` and ``passes``."""
    if pon_class not in PON_CLASSES:
        raise OpticalError(f"Unknown PON class “{pon_class}” (use {', '.join(PON_CLASSES)}).")
    low, high = PON_CLASSES[pon_class].attenuation_range_db
    nbrs = g.neighbours()
    length = {}
    for e in g.edges:
        length[e.u, e.v] = length[e.v, e.u] = float(e.attrs.get("length_m", 0.0))
    parent = {root: None}
    order = [root]
    for n in order:
        for m in sorted(nbrs[n], key=str):
            if m not in parent:
                parent[m] = n
                order.append(m)
    out = {}
    for n, attrs in g.nodes.items():
        if attrs.get("role") != "ont" or n not in parent:
            continue
        path = [n]
        while parent[path[-1]] is not None:
            path.append(parent[path[-1]])
        path.reverse()
        metres = sum(length[a, b] for a, b in zip(path, path[1:], strict=False))
        splitters = [g.nodes[p] for p in path if g.nodes[p].get("role") == "splitter"]
        split_loss = sum(_splitter_loss(s) for s in splitters)
        loss = calculate_loss(LossInput(
            wavelength_nm=wavelength_nm, length_km=metres / 1000,
            connector_count=end_connectors + connectors_per_splitter * len(splitters),
            splice_count=splices_per_run * (len(path) - 1), other_loss_db=split_loss,
            margin_db=margin_db, budget_db=high,
        ))  # fmt: skip
        out[n] = OntLoss(n, tuple(path), loss, (low, high))
        if write:
            attrs.update(loss_db=round(loss.total_db, 2), margin_db=round(out[n].margin_db, 2),
                         passes=out[n].passes)  # fmt: skip
    return out