Skip to content
Edit this page

ictdesigntools.network.roadm

ROADM networks: nodes, the fibre links between them, and what a wavelength path through them sees: loss, filter narrowing, OSNR and latency.

A reconfigurable optical add/drop multiplexer (ROADM, ITU-T G.672) has one degree for each fibre pair to a neighbouring node. A channel enters the network at one node's add port, is expressed from degree to degree through each node it passes, and leaves at the far node's drop port. Each of those is a chain of filter passes (optical.filters): in a route-and-select node a wavelength selective switch (WSS) at the input degree and another at the output, so an express path crosses two WSSs.

Network holds the nodes and links (to_graph() hands them to draw.graph). route finds the shortest path by length, and path works out, along a route:

  • the filter chain (add, then each express, then drop): its insertion loss and narrowed passband, ready for filters.check_passband;
  • the fibre loss of each link at the wavelength, from its fibre category (optical.media);
  • the OSNR, when every node after the first has a pre-amplifier on its input degrees. A node's booster, where it has one, makes up the loss of the add or express filters before the link; each pre-amplifier makes up the link (and any filter loss no booster made up). Every amplifier is one osnr.Stage, so with boosters each link is launched at the power the channel had at the add port;
  • the channel's power after every filter, amplifier and link (levels), which path_drawing draws as a span diagram over a power-level chart;
  • the received power at the drop port, and the latency: the fibre's group delay at a group index of 1.4682 (typical of G.652 fibre at 1550 nm; Corning SMF-28 Ultra data sheet), about 4.9 µs/km, plus any delay a node adds.
>>> net = Network()
>>> for name in "ABCD":
...     net.add(route_and_select(name, passband_ghz=75, preamp=Amplifier(5.5),
...                              booster=Amplifier(5.5)))
>>> net.link("A", "B", Link("G.652.D", 80))
>>> net.link("B", "C", Link("G.652.D", 70))
>>> net.link("C", "D", Link("G.652.D", 90))
>>> net.link("A", "D", Link("G.652.D", 300))
>>> net.route("A", "D")
('A', 'B', 'C', 'D')
>>> p = net.path("A", "D")
>>> p.length_km, round(p.latency_us), p.filter_loss_db, round(p.passband_ghz, 1)
(240.0, 1175, 44.0, 55.6)
>>> round(p.osnr.osnr_db, 1), p.received_dbm
(22.8, -10.0)
>>> net.degree("A")
2
>>> d = path_drawing(p)  # the span diagram over the power-level chart

RoadmError

Bases: ValueError

A node, link or path that cannot be worked out.

Roadm dataclass

Roadm(
    name: str,
    add: tuple[Filter, ...],
    drop: tuple[Filter, ...],
    express: tuple[Filter, ...],
    preamp: Amplifier | None = None,
    booster: Amplifier | None = None,
    latency_us: float = 0.0,
)

A ROADM node: the filter passes a channel crosses when it is added, dropped, or expressed from one degree to another; the pre-amplifier on each input degree and the booster on each output degree (None when the node has none). latency_us is any delay the node itself adds.

Link(
    fiber: str, length_km: float, extra_loss_db: float = 0.0
)

A fibre pair between two nodes: length_km of one fibre category, plus extra_loss_db for its connections, splices and ageing.

Level dataclass

Level(km: float, dbm: float, event: str)

The channel's power, per channel, just after an event at km along the path.

Network dataclass

Network(
    nodes: dict[Hashable, Roadm] = dict(),
    links: dict[frozenset, Link] = dict(),
)

ROADM nodes and the links between them (at most one link between two nodes).

degree

degree(n: Hashable) -> int

The node's number of line degrees: one per link.

Source code in src/ictdesigntools/network/roadm.py
def degree(self, n: Hashable) -> int:
    """The node's number of line degrees: one per link."""
    return len(self.neighbours(n))

route

route(a: Hashable, b: Hashable) -> tuple[Hashable, ...]

The shortest route from a to b by fibre length.

Source code in src/ictdesigntools/network/roadm.py
def route(self, a: Hashable, b: Hashable) -> tuple[Hashable, ...]:
    """The shortest route from ``a`` to ``b`` by fibre length."""
    for n in (a, b):
        if n not in self.nodes:
            raise RoadmError(f"No node {n!r}.")
    best = {a: 0.0}
    prev: dict[Hashable, Hashable] = {}
    heap = [(0.0, 0, a)]
    tie = 0
    while heap:
        d, _, n = heapq.heappop(heap)
        if n == b:
            break
        if d > best[n]:
            continue
        for m in self.neighbours(n):
            nd = d + self.between(n, m).length_km
            if nd < best.get(m, math.inf):
                best[m], prev[m] = nd, n
                tie += 1
                heapq.heappush(heap, (nd, tie, m))
    if b not in best:
        raise RoadmError(f"No route from {a!r} to {b!r}.")
    out = [b]
    while out[-1] != a:
        out.append(prev[out[-1]])
    return tuple(reversed(out))

path

path(
    a: Hashable,
    b: Hashable | None = None,
    *,
    route: Sequence[Hashable] | None = None,
    wavelength_nm: float = 1550.0,
    launch_dbm: float = 0.0,
) -> PathResult

A wavelength path added at a and dropped at b along the shortest route (or along route, a list of nodes), with launch_dbm per channel at the add port.

Source code in src/ictdesigntools/network/roadm.py
def path(self, a: Hashable, b: Hashable | None = None, *,
         route: Sequence[Hashable] | None = None, wavelength_nm: float = 1550.0,
         launch_dbm: float = 0.0) -> PathResult:  # fmt: skip
    """A wavelength path added at ``a`` and dropped at ``b`` along the shortest route (or
    along ``route``, a list of nodes), with ``launch_dbm`` per channel at the add port."""
    hops = tuple(route) if route is not None else self.route(a, b)
    if len(hops) < 2:
        raise RoadmError("A path joins at least two nodes.")
    nodes = [self.nodes[n] for n in hops]
    links = [self.between(x, y) for x, y in zip(hops, hops[1:], strict=False)]
    before = [nodes[0].add, *(n.express for n in nodes[1:-1])]  # the filters before each link
    chain = tuple(f for group in (*before, nodes[-1].drop) for f in group)
    shaped = any(f.passband_ghz is not None for f in chain)
    fibre = sum(lk.loss_db(wavelength_nm) for lk in links)
    drop_loss = cascade_loss_db(nodes[-1].drop)

    amplified = all(n.preamp is not None for n in nodes[1:])
    stages: list[Stage] = []
    levels = [Level(0.0, launch_dbm, f"{hops[0]} add port")]
    power, km = launch_dbm, 0.0

    def step(event: str, loss: float = 0.0, amp: Amplifier | None = None,
             made_up: float = 0.0) -> None:  # fmt: skip
        """A loss, or an amplifier making up the ``made_up`` dB since the last one."""
        nonlocal power
        if amp is None:
            power -= loss
        else:
            stages.append(Stage(made_up, amp))
            power += made_up if amp.gain_db is None else amp.gain_db
        levels.append(Level(km, power, event))

    for i, (sender, f, lk, receiver) in enumerate(
            zip(nodes, before, links, nodes[1:], strict=False)):  # fmt: skip
        pending = cascade_loss_db(f)
        if pending:
            step(f"{hops[i]} {'add' if i == 0 else 'express'} filters", pending)
        if amplified and sender.booster is not None:
            step(f"{hops[i]} booster", amp=sender.booster, made_up=pending)
            pending = 0.0
        span = lk.loss_db(wavelength_nm)
        km += lk.length_km
        step(f"{hops[i + 1]} input", span)
        if amplified:
            step(f"{hops[i + 1]} pre-amplifier", amp=receiver.preamp, made_up=pending + span)
    step(f"{hops[-1]} drop port", drop_loss)

    osnr = link_osnr(launch_dbm, stages, wavelength_nm=wavelength_nm) if amplified else None
    received = power

    return PathResult(
        route=hops,
        filters=chain,
        filter_loss_db=cascade_loss_db(chain),
        passband_ghz=cascade_passband_ghz(chain) if shaped else None,
        fibre_loss_db=round(fibre, 6),
        length_km=float(sum(lk.length_km for lk in links)),
        latency_us=sum(lk.latency_us for lk in links) + sum(n.latency_us for n in nodes),
        received_dbm=received,
        osnr=osnr,
        levels=tuple(levels),
        links=tuple(links),
        wavelength_nm=wavelength_nm,
    )

to_graph

to_graph() -> Graph

The network as a draw.graph.Graph for draw.graph.topology: nodes with role="roadm" and their degree; edges with length_km and fiber.

Source code in src/ictdesigntools/network/roadm.py
def to_graph(self) -> Graph:
    """The network as a ``draw.graph.Graph`` for ``draw.graph.topology``: nodes with
    ``role="roadm"`` and their ``degree``; edges with ``length_km`` and ``fiber``."""
    g = Graph()
    for name in self.nodes:
        g.add_node(name, role="roadm", degree=self.degree(name), label=str(name))
    for pair, lk in self.links.items():
        u, v = sorted(pair, key=str)
        g.add_edge(u, v, length_km=lk.length_km, fiber=lk.fiber,
                   label=f"{lk.length_km:g} km")  # fmt: skip
    return g

route_and_select

route_and_select(
    name: str,
    wss_loss_db: float = 6.0,
    passband_ghz: float | None = None,
    order: float = 3.0,
    mux_loss_db: float = 4.0,
    preamp: Amplifier | None = None,
    booster: Amplifier | None = None,
) -> Roadm

A route-and-select node: a WSS on each input and output degree, and a mux/demux (or multicast switch) on the add/drop side. Expressing a channel crosses two WSSs; adding or dropping crosses one WSS and the mux or demux. Losses are typical planning values: replace them with the data sheet's.

Source code in src/ictdesigntools/network/roadm.py
def route_and_select(name: str, wss_loss_db: float = 6.0, passband_ghz: float | None = None,
                     order: float = 3.0, mux_loss_db: float = 4.0,
                     preamp: Amplifier | None = None,
                     booster: Amplifier | None = None) -> Roadm:  # fmt: skip
    """A route-and-select node: a WSS on each input and output degree, and a mux/demux (or
    multicast switch) on the add/drop side. Expressing a channel crosses two WSSs; adding or
    dropping crosses one WSS and the mux or demux. Losses are typical planning values: replace
    them with the data sheet's."""
    wss = Filter("wss", wss_loss_db, passband_ghz=passband_ghz, order=order)
    return Roadm(name, add=(Filter("mux", mux_loss_db), wss),
                 drop=(wss, Filter("demux", mux_loss_db)), express=(wss, wss),
                 preamp=preamp, booster=booster)  # fmt: skip

path_drawing

path_drawing(
    p: PathResult, width_mm: float = 240.0, title: str = ""
) -> Drawing

The path as a span diagram (nodes, links and amplifiers, spaced by distance) over a chart of the channel's power along it, in mm. Each step of the chart is an event in p.levels: a filter's loss, an amplifier's gain, or a link's loss along its length.

Source code in src/ictdesigntools/network/roadm.py
def path_drawing(p: PathResult, width_mm: float = 240.0, title: str = "") -> Drawing:
    """The path as a span diagram (nodes, links and amplifiers, spaced by distance) over a
    chart of the channel's power along it, in mm. Each step of the chart is an event in
    ``p.levels``: a filter's loss, an amplifier's gain, or a link's loss along its length."""
    total = p.length_km or 1.0
    left, chart_top, chart_h = 18.0, 30.0, 70.0
    styles = {
        "node": Style(fill="#ffffff", stroke=INK, width=0.35),
        "amp": Style(fill="#f1f0ec", stroke=INK, width=0.3),
        "link": Style(stroke=INK, width=0.5),
        "label": Style(color=INK),
        "muted": Style(color=MUTED),
        "grid": Style(stroke="#d8d6cf", width=0.15),
        "level": Style(stroke="#1f6feb", width=0.5),
    }

    def x_at(km: float) -> float:
        return left + km / total * width_mm

    head = title or f"{p.route[0]} to {p.route[-1]}"
    summary = [f"{p.length_km:g} km", f"fibre {p.fibre_loss_db:.1f} dB",
               f"filters {p.filter_loss_db:.1f} dB", f"{p.latency_us:.0f} µs",
               f"received {p.received_dbm:.1f} dBm"]  # fmt: skip
    if p.osnr is not None:
        summary.append(f"OSNR {p.osnr.osnr_db:.1f} dB")
    d = Drawing(units="mm", stroke=0.3, font=2.4, title=head, desc=", ".join(summary) + ".",
                styles=styles)  # fmt: skip
    d.add(Text(left, 2.0, f"{head} · {' · '.join(summary)}", 3.0, anchor="start",
               style="label"))  # fmt: skip

    # The span diagram.
    y = 14.0
    kms = [0.0]
    for lk in p.links:
        kms.append(kms[-1] + lk.length_km)
    for i, (name, km) in enumerate(zip(p.route, kms, strict=True)):
        x = x_at(km)
        if i:
            x0 = x_at(kms[i - 1]) + _NODE_W / 2
            d.add(Line(x0, y, x - _NODE_W / 2, y, style="link"))
            lk_km = km - kms[i - 1]
            loss = p.links[i - 1].loss_db(p.wavelength_nm)
            d.add(Text((x0 + x - _NODE_W / 2) / 2, y - 2.2, f"{lk_km:g} km · {loss:.1f} dB",
                       2.2, style="muted"))  # fmt: skip
        d.add(Rect(x - _NODE_W / 2, y - _NODE_H / 2, _NODE_W, _NODE_H, style="node",
                   title=f"ROADM {name}"))  # fmt: skip
        d.add(Text(x, y, str(name), 2.6, style="label"))
        events = {lv.event for lv in p.levels if lv.km == km}
        if f"{name} pre-amplifier" in events:
            d.add(_amp_shape(x - _NODE_W / 2 - _AMP / 2 - 0.5, y + 5.5, f"{name} pre-amplifier"))
        if f"{name} booster" in events:
            d.add(_amp_shape(x + _NODE_W / 2 + _AMP / 2 + 0.5, y + 5.5, f"{name} booster"))

    # The power-level chart.
    lo = math.floor(min(lv.dbm for lv in p.levels) / 5) * 5
    hi = math.ceil(max(lv.dbm for lv in p.levels) / 5) * 5
    hi = hi if hi > lo else lo + 5

    def y_at(dbm: float) -> float:
        return chart_top + (hi - dbm) / (hi - lo) * chart_h

    for v in range(int(lo), int(hi) + 1, 5):
        d.add(Line(left - _NODE_W / 2, y_at(v), left + width_mm + _NODE_W / 2, y_at(v),
                   style="grid"))  # fmt: skip
        d.add(Text(left - _NODE_W / 2 - 1.5, y_at(v), f"{v}", 2.2, anchor="end", style="muted"))
    d.add(Text(left - _NODE_W / 2, chart_top - 4.0, "dBm per channel", 2.2, anchor="start",
               style="muted"))  # fmt: skip
    for km in kms:
        d.add(Line(x_at(km), chart_top, x_at(km), chart_top + chart_h, style="grid"))
    # Each node's events are stepped across its box: in at its left edge, out at its right.
    points: list[tuple[float, float]] = []
    groups: dict[float, list[Level]] = {}
    for lv in p.levels:
        groups.setdefault(lv.km, []).append(lv)
    for km in kms:
        events = groups.get(km, [])
        arriving = [lv for lv in events if lv.event.endswith(" input")]
        inside = [lv for lv in events if lv not in arriving]
        x0, x1 = x_at(km) - _NODE_W / 2, x_at(km) + _NODE_W / 2
        for lv in arriving:
            points.append((x0, y_at(lv.dbm)))
        for j, lv in enumerate(inside):
            x = x0 + (j + 0.5) * (x1 - x0) / len(inside)
            if points:
                points.append((x, points[-1][1]))
            points.append((x, y_at(lv.dbm)))
        if km != kms[-1]:
            points.append((x1, points[-1][1]))
    d.add(Polyline(tuple(points), style="level", title="Channel power"))
    end = p.levels[-1]
    d.add(Text(points[-1][0] + 1.5, y_at(end.dbm), f"{end.dbm:.1f} dBm", 2.2, anchor="start",
               style="label"))  # fmt: skip
    return d.fit(4)