TExcelTAD
Home › Computer Networking › Network Topologies

Network Topologies

A topology is the shape of a network: which nodes are connected to which. The physical topology describes how the cables actually run; the logical topology describes how data flows. They are not always the same: classic Token Ring was wired as a star but behaved logically as a ring.

The common shapes

Topology Shape Pros Cons
Bus every node taps one shared cable cheap, little cable one break kills the segment; collisions
Ring each node links to two neighbours in a loop predictable, no collisions with tokens one failure can break the ring (unless dual ring)
Star every node links to a central switch easy to add/remove nodes, faults isolated the centre is a single point of failure
Mesh nodes link to many (full mesh: all) others very resilient, many paths lots of links and ports
Tree (hierarchical) stars connected to stars scales well, easy to organise upper levels are critical
Hybrid a mix of the above fits real needs more complex

Almost every modern wired LAN is a star (or a tree of stars): each computer has its own cable to a switch port. Internet backbones and data centres use partial meshes for redundancy.

Counting links

A topology's cost is roughly its number of links. A full mesh of n nodes needs a link between every pair, which grows fast:

python · try it yourself
def links(topology, n):
    if topology == "bus":
        return 1                    # one shared cable
    if topology == "ring":
        return n
    if topology == "star":
        return n                    # n nodes + 1 central switch
    if topology == "full mesh":
        return n * (n - 1) // 2
    raise ValueError(topology)

print(f"{'nodes':>5} {'ring':>6} {'star':>6} {'full mesh':>10}")
for n in [4, 10, 50, 200]:
    print(f"{n:>5} {links('ring', n):>6} {links('star', n):>6} {links('full mesh', n):>10}")
nodes   ring   star  full mesh
    4      4      4          6
   10     10     10         45
   50     50     50       1225
  200    200    200      19900

200 nodes in a full mesh need almost 20,000 cables. That is why full meshes are only used for a handful of core routers.

Representing a topology as a graph

Networks are naturally graphs: nodes are devices, edges are links. Storing a topology as an adjacency list lets a program answer questions like "how many hops from A to E?" with breadth-first search. Here is a small office network:

python · try it yourself
from collections import deque

topology = {
    "Core":    ["Floor1", "Floor2"],
    "Floor1":  ["Core", "PC1", "PC2"],
    "Floor2":  ["Core", "PC3", "Printer"],
    "PC1":     ["Floor1"],
    "PC2":     ["Floor1"],
    "PC3":     ["Floor2"],
    "Printer": ["Floor2"],
}

def hops_from(start):
    hops = {start: 0}
    queue = deque([start])
    while queue:
        node = queue.popleft()
        for neighbour in sorted(topology[node]):
            if neighbour not in hops:
                hops[neighbour] = hops[node] + 1
                queue.append(neighbour)
    return hops

for node, h in hops_from("Core").items():
    print(f"{node:<8} {h} hop(s)")
print("PC1 -> Printer:", hops_from("PC1")["Printer"], "hops")
Core     0 hop(s)
Floor1   1 hop(s)
Floor2   1 hop(s)
PC1      2 hop(s)
PC2      2 hop(s)
PC3      2 hop(s)
Printer  2 hop(s)
PC1 -> Printer: 4 hops

This is a tree topology: switches per floor, joined by a core switch.

What happens when a link fails?

Resilience is the main reason to add extra links. Let's remove links one at a time and check whether every node can still reach every other node:

python · try it yourself
def connected(nodes, edges):
    adj = {n: set() for n in nodes}
    for a, b in edges:
        adj[a].add(b)
        adj[b].add(a)
    seen, stack = set(), [nodes[0]]
    while stack:
        n = stack.pop()
        if n not in seen:
            seen.add(n)
            stack.extend(adj[n] - seen)
    return len(seen) == len(nodes)

nodes = ["A", "B", "C", "D"]
designs = {
    "star (hub H)": (nodes + ["H"], [("H", n) for n in nodes]),
    "ring":         (nodes, [("A", "B"), ("B", "C"), ("C", "D"), ("D", "A")]),
    "full mesh":    (nodes, [(a, b) for i, a in enumerate(nodes) for b in nodes[i + 1:]]),
}

for name, (ns, es) in designs.items():
    survives = sum(connected(ns, [e for e in es if e != broken]) for broken in es)
    print(f"{name:<13} links={len(es)}  survives {survives}/{len(es)} single-link failures")
star (hub H)  links=4  survives 0/4 single-link failures
ring          links=4  survives 4/4 single-link failures
full mesh     links=6  survives 6/6 single-link failures

The star loses a node whenever one of its links breaks (that node is cut off). The ring survives any single failure but not two. The mesh survives everything, at the price of more links.

Note: Redundant links in a switched LAN create loops, which Ethernet cannot tolerate on its own. Switches run the Spanning Tree Protocol (STP) to block redundant links until they are needed. You will see why loops are a problem in the switching lesson.

Test yourself

Which topology is used by nearly all modern wired office LANs?

  1. Bus
  2. Ring
  3. Star (or tree of stars)
  4. Full mesh

How many links does a full mesh of 6 nodes need?

  1. 6
  2. 12
  3. 15
  4. 36

What is the main weakness of a star topology?

  1. It needs n(n-1)/2 cables
  2. The central device is a single point of failure
  3. Data must pass through every node
  4. Nodes cannot be added