Routing
1. Lecture 13: Link Layer Recap and Routing Algorithms
1.1. Administrative and lecture context
The lecture begins with a short clarification about exam coverage: the relevant material includes everything from the beginning of the course up to the following Tuesday lecture.
The instructor also recommends attending the Tuesday lecture because it will put concepts from different layers together into one scenario.
1.2. Recap: Longest Prefix Matching
The lecture starts by revisiting forwarding-table lookup with CIDR prefixes.
A router may have multiple matching prefixes for a destination IP address. The rule is:
Choose the longest matching prefix.
For example, suppose the forwarding table contains prefixes such as:
134.96.0.0/16 134.96.240.0/20 134.96.252.0/24 134.96.252.192/28 134.96.252.196/30
For a destination address, the router compares the destination bits with each prefix. A /30 prefix is more specific than a /28 prefix, which is more specific than /24, /20, and /16.
The router first checks whether the most specific prefix matches. If it does not, it checks the next less-specific prefix. The first matching prefix in this decreasing-specificity order is the longest matching prefix.
The instructor emphasized that this can be understood simply as bit comparison:
- a
/30prefix means the first 30 bits must match; - a
/28prefix means the first 28 bits must match; - a
/24prefix means the first 24 bits must match; - and so on.
1.3. Recap: Link Layer and MAC Addresses
The network layer uses IP addresses, while the link layer uses MAC addresses.
An IP address is used to identify a network-layer destination and to support routing across networks. In contrast, a MAC address identifies a network interface on a local link.
Ethernet MAC addresses are usually 48 bits long.
The first 24 bits typically identify a vendor block, and the vendor assigns the remaining bits to devices it manufactures. In principle, MAC addresses are globally unique, although in practice they can be spoofed or randomized.
A frame on the link layer contains at least:
- source MAC address;
- destination MAC address;
- payload, often an IP datagram.
The important point is:
The IP destination may be far away, but the MAC destination is only the next hop on the current link.
1.4. Address Resolution Protocol: ARP in IPv4
1.4.1. Why ARP is needed
Suppose host A wants to send an IP datagram to host B on the same local network.
A knows B’s IP address, but to create an Ethernet frame, A also needs B’s MAC address.
IPv4 uses ARP, the Address Resolution Protocol, to map IP addresses to MAC addresses inside a local network.
Each device maintains an ARP table, conceptually like this:
IP address MAC address TTL 192.168.1.10 aa:bb:cc:dd:ee:ff ...
The TTL is important because mappings are soft state. A host may leave the network, another device may later receive the same IP address, or the mapping may otherwise become stale.
1.4.2. ARP request
If A does not know B’s MAC address, A sends an ARP request.
The request is sent as a link-layer broadcast:
Destination MAC = ff:ff:ff:ff:ff:ff
This is the Ethernet broadcast address. In binary it is all ones; in hexadecimal it is written as all ff.
The ARP request says, in effect:
Who has this IP address? Please tell me your MAC address.
Every device on the local link receives the broadcast frame.
1.4.3. ARP reply
Only the device whose IP address matches the target IP should answer.
The ARP reply does not need to be broadcast. It can be sent directly back to the requester because the ARP request already contained the requester’s source MAC address.
After receiving the reply, A stores the mapping in its ARP table and can send the actual Ethernet frame.
1.4.4. ARP security issue
ARP has no built-in authentication.
Because every device can see ARP requests, a malicious host can spoof replies and claim:
That IP address belongs to my MAC address.
This is the basis of ARP spoofing or ARP poisoning attacks.
There are defenses, but the instructor described them as awkward and not very clean compared with having security built into the protocol.
1.4.5. ARP is local
ARP only works on the local link.
If A wants to send to an IP address outside its own subnet, A does not ARP for the final destination. Instead, A sends the frame to the MAC address of its default gateway.
So the logic is:
Destination IP inside my subnet? Yes -> ARP for destination IP directly. No -> ARP for default gateway's IP, then send frame to gateway MAC.
The IP destination remains the final destination, but the Ethernet destination is the next hop.
1.5. Neighbor Discovery Protocol in IPv6
IPv6 does not use ARP.
Instead, IPv6 uses the Neighbor Discovery Protocol, NDP.
Important differences:
- ARP is a layer-2 protocol in IPv4.
- NDP is based on ICMPv6 and is therefore part of layer 3.
- IPv6 avoids pure broadcast and uses multicast-based mechanisms.
1.5.1. IPv6 link-local addresses
IPv6 devices can create link-local addresses.
Historically, the interface identifier part of an IPv6 address could be derived from the MAC address. The MAC address is 48 bits, while the IPv6 interface identifier is often 64 bits.
The old EUI-64-style transformation roughly worked by:
- splitting the MAC address into two 24-bit halves;
- inserting
ff:fein the middle; - flipping one specific bit.
This allowed a device to automatically create a likely unique link-local address.
1.5.2. Privacy concern
If the interface identifier is derived from a globally unique MAC address, then the device may be trackable across networks.
For example, if a phone keeps the same interface identifier while moving between networks, observers can recognize it.
Therefore, modern systems often randomize the interface identifier. Some systems, such as Apple devices in some scenarios, may also randomize the MAC address when joining networks.
1.5.3. NDP neighbor table
NDP creates a neighbor table, conceptually similar to an ARP table:
IPv6 address / interface identifier -> MAC address, TTL
Instead of broadcasting to everyone, a node sends a Neighbor Solicitation to a solicited-node multicast address derived from the target IPv6 address. This reduces unnecessary processing by unrelated hosts.
The target replies with a Neighbor Advertisement.
1.6. Sending Across Two LANs via a Router
The lecture then puts the network and link layers together.
Suppose host A is in one LAN and host B is in another LAN, with router R in between.
A knows:
- B’s IP address, usually via DNS;
- the IP address of its default gateway R;
- R’s MAC address, after ARP/NDP.
When A sends to B:
- A creates an IP datagram:
- source IP = A’s IP;
- destination IP = B’s IP.
- A encapsulates the datagram in an Ethernet frame:
- source MAC = A’s MAC;
- destination MAC = R’s MAC.
- Router R receives the frame because the destination MAC is R’s MAC.
- R removes the layer-2 header and inspects the IP datagram.
- R looks at the destination IP address and uses its forwarding table to choose the outgoing interface.
- R creates a new Ethernet frame on the next link:
- source MAC = R’s MAC on the outgoing interface;
- destination MAC = B’s MAC, if B is directly reachable on that LAN.
- B receives the frame and passes the IP datagram upward.
The key rule:
IP addresses normally stay the same across the path, but MAC addresses change at every link.
This is true unless mechanisms such as NAT are involved.
1.7. Hubs and Switches: Question from the Lecture
A student asked how communication works if switches are in the network.
The instructor clarified:
- A hub is basically a layer-1 device.
- It repeats incoming bits to all other ports.
- It does not remember where MAC addresses are.
A switch is smarter:
- It observes source MAC addresses of incoming frames.
- It learns which MAC address is reachable through which port.
- It builds a switching table.
- If it knows the destination MAC, it forwards only to the correct port.
- If it does not know the destination MAC, it floods the frame to all ports except the incoming one.
The switch does not become the destination MAC address of ordinary traffic. The host still sends to the destination host’s MAC address, or to the router’s MAC address if the packet must leave the subnet.
The switch is mostly transparent to hosts.
1.8. Routing Algorithms
The lecture then moves from link-layer forwarding to routing algorithms.
Routing is modeled using graphs.
1.8.1. Graph abstraction
A network can be represented as a graph:
\[ G = (N, E) \]
where:
- \(N\) is the set of nodes, typically routers;
- \(E\) is the set of edges, typically links.
A path is a sequence of connected routers/edges.
Each edge can have a cost:
\[ c(x, y) \]
The cost may represent different things:
- always 1, if only hop count matters;
- inverse of bandwidth, so low-bandwidth links get higher cost;
- congestion, so congested links become more expensive.
Routing algorithms try to find a good path, usually the least-cost path.
However, the instructor noted that in real Internet routing, other factors such as policy and money can be more important than pure shortest path.
1.9. Classification of Routing Algorithms
Routing algorithms can be classified along two dimensions.
1.9.1. Global vs. decentralized information
- Global information: Link-state algorithms
In a link-state approach:
- every router knows the complete topology;
- every router knows all link costs;
- every router can independently compute shortest paths.
Dijkstra’s algorithm is the main example.
This works better in smaller or controlled networks.
- Decentralized information: Distance-vector algorithms
In a distance-vector approach:
- a router initially knows only its directly connected neighbors;
- it knows the costs to those neighbors;
- it exchanges distance information with neighbors;
- over time, information propagates through the network.
Bellman-Ford is the basis for distance-vector routing.
1.10. Link-State Routing and Dijkstra’s Algorithm
1.10.1. Basic idea
Dijkstra’s algorithm is used in link-state routing.
All nodes have the same topology and cost information. Each node then runs Dijkstra from itself as the source.
The result is a shortest-path tree rooted at that node.
From the shortest-path tree, the router derives its forwarding table.
1.10.2. Notation
The lecture uses the following notation:
- \(c(i,j)\): cost from node \(i\) to node \(j\);
- infinite if \(i\) and \(j\) are not direct neighbors.
- \(D(v)\): current known cost from the source to node \(v\).
- \(p(v)\): predecessor of \(v\) on the current best path.
- \(N'\): set of nodes whose least-cost path is already known.
1.10.3. Algorithm intuition
Start at source node A.
Initially:
\[ N' = \{A\} \]
For each node \(v\):
- if \(v\) is adjacent to A, set \(D(v) = c(A,v)\);
- otherwise set \(D(v) = \infty\).
Then repeat:
- choose the node \(w\) not in \(N'\) with the smallest \(D(w)\);
- add \(w\) to \(N'\);
- update all neighbors \(v\) of \(w\):
\[ D(v) = \min(D(v), D(w) + c(w,v)) \]
This means:
The best known path to \(v\) is either the old one, or the path to \(w\) plus the edge from \(w\) to \(v\).
1.10.4. Example from the lecture
In the example, the algorithm computes shortest paths from node A.
At the beginning, A directly knows the costs to its neighbors B, C, and D. Other nodes are set to infinity.
Then:
- D is selected first because A can reach D with cost 1.
- From D, paths to C and E may improve.
- E is selected next.
- From E, the path to C improves and F becomes reachable.
- B is selected next.
- Then C and F are processed.
The final result is a shortest-path tree from A.
From that tree, A only needs the next hop for each destination. For example:
Destination B -> use link (A,B) Destination D -> use link (A,D) Destination E -> use link (A,D) Destination C -> use link (A,D) Destination F -> use link (A,D)
A does not need the full path in the forwarding table. It only needs to know which outgoing link to use next.
1.10.5. Complexity and discussion
With \(n\) nodes, each iteration needs to find the next minimum-distance node.
Depending on the data structure, the complexity can be:
- \(O(n^2)\);
- \(O(n \log n)\) or similar with better data structures.
The instructor also mentioned that link-state routing can have oscillation problems if link costs depend on current traffic load.
For example:
- a link becomes expensive because many routers use it;
- routers recompute paths and move traffic elsewhere;
- the old link becomes cheap again;
- routers move traffic back.
One mitigation is randomized update timing, so not every router recomputes at exactly the same time.
1.10.6. Link-state and SDN
The instructor briefly connected link-state/global knowledge to Software-Defined Networking.
In SDN:
- forwarding devices can be simpler;
- a central controller has global network information;
- the controller computes forwarding tables;
- the controller installs those tables in routers/switches.
This can be useful in controlled environments such as data centers.
But it has disadvantages:
- centralized controller can become a single point of failure;
- it requires control over the whole network;
- it is not suitable for the entire Internet.
1.11. Distance-Vector Routing and Bellman-Ford
1.11.1. Basic idea
Distance-vector routing does not require every router to know the full topology.
Each node knows:
- its neighbors;
- the cost to each neighbor;
- its own current distance vector;
- the distance vectors advertised by neighbors.
A distance vector is a list of estimated costs from this node to every destination.
For node \(x\):
\[ D_x(y) \]
means node \(x\)’s current estimate of the least cost to destination \(y\).
1.11.2. Bellman-Ford equation
The least-cost path from \(x\) to \(y\) can be computed as:
\[ d_x(y) = \min_v \{ c(x,v) + d_v(y) \} \]
where \(v\) ranges over the neighbors of \(x\).
Meaning:
To reach destination \(y\), node \(x\) considers each neighbor \(v\). The total cost is the cost from \(x\) to \(v\), plus \(v\)’s cost to \(y\). Choose the minimum.
The neighbor that gives the minimum becomes the next hop.
1.11.3. Bellman-Ford example
Suppose \(u\) wants to reach \(z\).
It has neighbors \(v\), \(x\), and \(w\).
If:
\[ d_v(z)=5 \] \[ d_x(z)=3 \] \[ d_w(z)=3 \]
and the link costs from \(u\) are:
\[ c(u,v)=2 \] \[ c(u,x)=1 \] \[ c(u,w)=5 \]
then:
\[ d_u(z) = \min \{2+5, 1+3, 5+3\} \]
\[ d_u(z) = \min \{7,4,8\} = 4 \]
So \(u\) should send via \(x\).
The important point is that \(u\) does not need to know the complete path from \(x\) to \(z\). It only needs to know that \(x\) claims it can reach \(z\) with cost 3.
1.11.4. Distance-vector algorithm
At each node \(x\):
- Initialize distances:
- distance to itself is 0;
- distance to direct neighbors is the link cost;
- distance to other nodes is infinity.
- Periodically send the current distance vector to neighbors.
- When receiving a neighbor’s distance vector, recompute:
\[ D_x(y) = \min_v \{ c(x,v) + D_v(y) \} \]
for every destination \(y\).
- If the distance vector changes, notify neighbors.
The algorithm is:
- iterative;
- asynchronous;
- distributed.
There is no central controller and no global topology knowledge.
1.12. Link Cost Changes in Distance-Vector Routing
1.12.1. Good news travels fast
If a link becomes better, the improvement can propagate quickly.
Example:
- initially, cost \(x-y = 4\);
- later, cost \(x-y = 1\);
- \(y\) notices the local change;
- \(y\) updates its distance vector;
- \(y\) tells \(z\);
- \(z\) realizes it can reach \(x\) more cheaply through \(y\).
This is called:
Good news travels fast.
1.12.2. Bad news travels slowly
If a link becomes worse, distance-vector routing can react badly.
Example:
- initially, \(y\) reaches \(x\) with cost 4;
- \(z\) reaches \(x\) through \(y\) with cost 5;
- then the direct \(x-y\) cost increases to 60.
Now \(y\) sees:
- direct path to \(x\): cost 60;
- path via \(z\): cost \(1 + 5 = 6\).
So \(y\) incorrectly believes it can reach \(x\) via \(z\) with cost 6.
But \(z\)’s path to \(x\) was actually going through \(y\).
This creates a routing loop.
Then:
- \(z\) updates its cost to 7;
- \(y\) updates to 8;
- \(z\) updates to 9;
- and so on.
This is the count-to-infinity problem.
In the example, the instructor said it would take many iterations before the algorithm stabilizes.
1.12.3. Count-to-infinity problem
The count-to-infinity problem happens because routers do not know the full topology.
A router only knows that a neighbor claims some distance. It does not know whether that neighbor’s path goes back through itself.
So two routers may keep increasing their estimates gradually before finally discovering that the route is bad.
1.12.4. Poisoned reverse
A mitigation is poisoned reverse.
If \(z\) routes through \(y\) to reach \(x\), then \(z\) tells \(y\):
\[ D_z(x) = \infty \]
This prevents \(y\) from trying to reach \(x\) through \(z\).
In simple cases, this breaks the loop.
However, poisoned reverse does not completely solve count-to-infinity in all topologies, especially when loops involve more than two routers.
1.13. Comparing Link-State and Distance-Vector Algorithms
1.13.1. Message complexity
Link-state algorithms distribute topology/link-state information broadly.
Distance-vector algorithms only exchange updates with direct neighbors.
1.13.2. Speed of convergence
Link-state algorithms can converge quickly if all routers receive consistent topology information, but they may oscillate if costs depend on traffic.
Distance-vector algorithms can converge slowly and may suffer from routing loops and count-to-infinity.
1.13.3. Robustness
In link-state routing:
- a broken router may advertise an incorrect link cost;
- each router still computes its own table independently.
In distance-vector routing:
- a broken router may advertise incorrect path costs;
- other routers use those advertised costs;
- errors can propagate through the network.
1.14. Lecture 13 Summary
The lecture connected the network layer and link layer, then introduced routing algorithms.
Main points:
- IP addresses are used across the network path.
- MAC addresses are used only on the current link.
- ARP maps IPv4 addresses to MAC addresses.
- IPv6 uses Neighbor Discovery instead of ARP.
- Routers decapsulate and re-encapsulate frames at each hop.
- MAC addresses change hop by hop; IP addresses normally remain end-to-end.
- Routing can be modeled using graphs.
- Link-state routing uses global topology information and Dijkstra’s algorithm.
- Distance-vector routing uses neighbor distance information and Bellman-Ford.
- Distance-vector routing can suffer from count-to-infinity.
- Poisoned reverse helps but is not a complete solution.
2. Lecture 14: Routing Overview, LAN Interconnection, and NAT
2.1. Administrative notes
The lecture begins with exam-related comments.
There will be no complicated arithmetic requiring many repeated steps, such as 25 steps of RTT estimation or timeout calculation.
The exam does not allow calculators.
Students should bring normal identification and student ID.
A handwritten cheat sheet is allowed and recommended. The instructor emphasized that writing it yourself is useful for learning, even if it is not heavily used during the exam.
2.2. Network Layer: Data Plane and Control Plane
The network layer can be divided into two parts:
- data plane;
- control plane.
2.2.1. Data plane
The data plane is local and per-router.
It decides how a datagram arriving on an input port is forwarded to an output port.
The data plane uses:
- packet header fields;
- forwarding table entries.
Forwarding can be implemented very efficiently, often in hardware.
2.2.2. Control plane
The control plane is network-wide logic.
It determines how datagrams should be routed along an end-to-end path from source host to destination host.
There are two main control-plane approaches:
- per-router control plane;
- Software-Defined Networking control plane.
2.2.3. Per-router control plane
In the traditional model, every router runs routing logic.
Each router has:
- forwarding hardware/software;
- local forwarding table;
- routing algorithm component.
The routing components in different routers exchange information and compute routes.
2.2.4. SDN control plane
In Software-Defined Networking, the control logic is moved out of routers and into a remote controller.
The controller:
- collects network information;
- computes forwarding tables;
- installs forwarding rules in routers/switches.
This can work well in controlled environments such as data centers.
The instructor noted that it is less suitable for very large networks such as a national ISP network, where centralizing everything would be difficult.
2.3. Network Service Models
A network-layer service model defines what kind of service the network provides to datagrams or flows.
Possible services for individual datagrams include:
- guaranteed delivery;
- guaranteed delivery within a maximum delay, e.g. less than 40 ms.
Possible services for a flow include:
- in-order delivery;
- guaranteed minimum bandwidth;
- restrictions on changes in inter-packet spacing.
2.3.1. Internet best-effort service
The Internet provides best-effort service.
This means there are no guarantees for:
- successful delivery;
- delay;
- ordering;
- bandwidth.
Packets may be:
- lost;
- delayed;
- delivered out of order;
- sent over different paths.
2.3.2. Other service models
The lecture briefly contrasts the Internet with other models, such as ATM:
- Constant Bit Rate;
- Available Bit Rate.
There are also Internet QoS(Quality of Service)-related approaches such as:
- IntServ (Integrated Service);
- DiffServ (Differentiated Services).
These try to provide stronger guarantees, but the instructor emphasized that they are not generally used as the scalable service model of the global Internet.
2.3.3. Why best effort succeeded
Best effort succeeded because it is simple.
The Internet is a network of networks. Different operators can build and manage their own networks as long as they interoperate using the basic best-effort model.
This makes deployment easier.
Performance can still be good enough most of the time because of:
- sufficient bandwidth provisioning;
- content distribution networks;
- replicated services;
- congestion control for elastic traffic.
The instructor also mentioned that some special environments need stronger guarantees, for example:
- autonomous driving or sensor-control networks;
- financial trading networks.
These may require strict timing constraints, unlike the general Internet.
2.4. Forwarding vs. Routing
Forwarding and routing are related but different.
2.4.1. Forwarding
Forwarding is the local process of moving a packet from an input interface to an output interface.
It uses:
- the forwarding table;
- information in the packet header.
Forwarding is the data-plane function.
2.4.2. Routing
Routing is the process by which forwarding tables are built and maintained.
It uses:
- routing protocols;
- routing algorithms;
- routing information from other routers.
Routing is the control-plane function.
2.4.3. Routing and forwarding together
Routing determines the forwarding table.
Forwarding uses the forwarding table to handle actual packets.
A router does not run the full routing algorithm for every packet. The expensive control-plane work happens separately, and the packet fast path only performs lookup and forwarding.
2.5. Recap: Routing Algorithm Classification
The lecture briefly repeats the classification from Lecture 13.
Routing algorithms may be:
- link-state, using global topology information;
- distance-vector, using decentralized neighbor information.
They may also be:
- static, where routes change slowly;
- dynamic, where routes update in response to changes.
2.6. Internet Routing and Scalability
The previous graph model is idealized.
It assumes:
- all routers are identical;
- the network is flat;
- every router could know about every destination.
This is not true in the real Internet.
2.6.1. Scale problem
The Internet has an enormous number of destinations.
If every router had to store a route to every destination, routing tables would become too large.
If every router exchanged full routing information with every other router, routing updates would consume too much bandwidth.
The instructor emphasized that routing information should not swamp the links; links should primarily carry user/application traffic.
2.6.2. Administrative autonomy
The Internet is a network of networks.
Each network operator wants to control routing inside its own network.
Therefore, Internet routing is organized using autonomous systems.
2.7. Autonomous Systems
An Autonomous System, or AS, is a collection of routers under one administrative control.
An AS is not necessarily a geographically small region. Large ASes may span countries or continents.
2.7.1. Intra-AS routing
Intra-AS routing, also called intra-domain routing, happens inside one AS.
Routers within the same AS usually run the same intra-domain routing protocol.
Different ASes may use different internal routing protocols.
2.7.2. Inter-AS routing
Inter-AS routing, also called inter-domain routing, happens between ASes.
Gateway or border routers connect one AS to another AS.
Inter-AS routing tells an AS which external destinations are reachable through which neighboring ASes.
2.7.3. Interaction between intra-AS and inter-AS routing
The forwarding table is configured by both intra-AS and inter-AS routing.
For internal destinations:
- intra-AS routing determines the forwarding entries.
For external destinations:
- inter-AS routing learns reachability information;
- intra-AS routing determines how to reach the correct gateway router.
Example:
If a router in AS1 receives a packet for a destination outside AS1, AS1 must know:
- whether the destination is reachable via AS2 or AS3;
- which AS1 border router should be used;
- how to route internally to that border router.
The main purpose of this hierarchy is scalability and administrative autonomy.
2.8. Ethernet
The lecture then shifts back to the link layer and LAN interconnection.
Ethernet is the dominant wired LAN technology.
It was:
- the first widely used LAN technology;
- simple;
- cheap;
- able to evolve across many speeds.
The slides mention Ethernet speeds from 10 Mbps to 100 Gbps, and the instructor noted that newer and faster hardware exists as well.
2.8.1. Ethernet topology: bus vs. star
Older Ethernet used a bus topology.
In a bus:
- all nodes share the same medium;
- all nodes are in the same collision domain;
- frames can collide.
Modern Ethernet usually uses a star topology.
In a star:
- hosts connect to a central switch;
- each host has a separate link to the switch;
- collisions are avoided or greatly reduced;
- full-duplex communication is possible.
2.8.2. Ethernet standards
Ethernet has many physical variants.
They share a common MAC protocol and frame format, but may differ in:
- speed;
- copper vs. fiber;
- physical-layer encoding.
Examples include:
- 100BASE-TX;
- 100BASE-FX;
- 1 Gbps Ethernet;
- 10 Gbps Ethernet;
- 100 Gbps Ethernet.
2.9. Why Not One Big LAN?
The lecture asks why we do not just put everything into one huge LAN.
Problems:
- all stations would share bandwidth;
- cable length is limited;
- the collision domain would become too large;
- the number of stations is limited;
- flat addressing does not scale well;
- broadcast traffic would become problematic.
Therefore, we need devices that interconnect LAN segments.
2.10. Hubs
A hub is a physical-layer device.
It works as a repeater.
When a hub receives bits on one interface, it repeats them to all other interfaces.
A hub does not inspect frames and does not learn MAC addresses.
2.10.1. Hub properties
Hubs:
- operate at bit level;
- do not isolate collision domains;
- can be arranged in a hierarchy;
- are simple and inexpensive;
- can extend physical distance.
But hubs have major limitations:
- all attached devices still share the same collision domain;
- collisions can happen across the whole hub-based LAN;
- loops can cause broadcast storms.
The instructor mentioned an anecdote where a loop created in a building network caused the network to go down.
2.11. Switches and Bridges
A bridge or switch is a link-layer device.
It is more intelligent than a hub.
A switch:
- stores and forwards Ethernet frames;
- examines the Ethernet frame header;
- selectively forwards frames based on destination MAC address;
- buffers frames;
- isolates collision domains.
2.11.1. Switches are transparent
Hosts do not need to know that switches exist.
The switch’s MAC address is not normally used as the destination MAC for traffic passing through it.
A switch may have a MAC address for management purposes, but that is not relevant for normal host-to-host forwarding through the switch.
2.11.2. Plug-and-play and self-learning
Switches are plug-and-play.
They do not need manual configuration for basic forwarding.
They learn automatically by observing frames.
2.12. Switch Self-Learning
Each switch maintains a switch table.
A switch table entry contains:
MAC address -> interface, TTL/timestamp
When a frame arrives, the switch records:
- the source MAC address;
- the incoming interface.
This tells the switch where the sender is located.
2.12.1. Unknown destination: flooding
If the switch does not know the destination MAC address, it floods the frame:
Forward the frame on all interfaces except the one it arrived on.
This is similar to hub behavior for that frame.
2.12.2. Known destination: selective forwarding
If the switch knows the destination MAC address:
- if the destination is on the same interface the frame came from, drop it;
- otherwise forward it only on the interface listed in the switch table.
2.12.3. Example
If A sends to A’ and the switch table is initially empty:
- switch learns that A is reachable via interface 1;
- destination A’ is unknown;
- switch floods the frame;
- A’ replies;
- switch learns that A’ is reachable via interface 4;
- reply to A is forwarded only to interface 1.
After this, communication between A and A’ can be selective rather than flooded.
2.12.4. Interconnecting multiple switches
Self-learning works even with multiple switches.
If A sends to G through a network of switches:
- each switch learns where A is based on the incoming interface;
- unknown destinations are flooded;
- when G replies, switches learn where G is;
- future frames can be forwarded more selectively.
2.13. Switches: Advantages
Switches have several advantages over hubs:
- higher total throughput;
- simultaneous transfers on different links;
- each link can be its own collision domain;
- can connect different Ethernet types;
- transparent to hosts;
- plug-and-play;
- self-learning.
However, switches still operate in a flat layer-2 space.
They do not provide the same hierarchical scaling as routers.
2.14. Switches vs. Routers
Both switches and routers are store-and-forward devices, but they operate at different layers.
2.14.1. Switches
Switches are link-layer devices.
They inspect Ethernet headers and forward based on MAC addresses.
Their tables are built by:
- filtering;
- learning;
- spanning tree algorithms.
Switches are good for small networks, for example a few hundred hosts.
2.14.2. Routers
Routers are network-layer devices.
They inspect IP headers and forward based on IP prefixes.
Their tables are built using routing protocols and routing algorithms.
Routers are better for large networks with thousands or more hosts.
2.14.3. Layer-3 switches
The lecture briefly mentions layer-3 switches.
A layer-3 switch combines switching and routing functionality, but may have limitations compared with a full router.
2.15. Switches vs. Routers: Pros and Cons
2.15.1. Switches
Advantages:
- simple operation;
- plug-and-play;
- low processing overhead;
- transparent to hosts.
Disadvantages:
- restricted topologies;
- need spanning tree to avoid loops;
- single broadcast domain unless VLANs or routing are used;
- no strong protection against broadcast storms;
- flat MAC address space does not scale globally.
2.15.2. Routers
Advantages:
- support arbitrary topologies;
- use TTL and routing protocols to limit cycles;
- can provide traffic isolation;
- can implement firewall policies;
- support hierarchical IP routing.
Disadvantages:
- more complex;
- require IP configuration;
- higher processing requirements;
- not as plug-and-play as switches.
2.16. Hub / Switch / Router Comparison
A rough comparison:
Hub Switch Router
Traffic isolation no yes yes
Plug and play yes yes no
Optimal routing no no yes
Cut-through yes depends no
The exact behavior of switches can vary. Some switches may support cut-through forwarding, while store-and-forward switches wait for the full frame before forwarding.
2.17. Network Address Translation: NAT
The lecture ends with NAT.
The instructor described NAT as one of the bigger evils in networking, although it is widely used.
2.17.1. Motivation
NAT allows a local network to use one globally routable IP address as seen from the outside world.
Inside the local network, devices use private addresses, for example:
10.0.0.1 10.0.0.2 10.0.0.3 10.0.0.4
The local network might be:
10.0.0.0/24
The NAT router has:
- an internal private address, e.g.
10.0.0.1; - an external public address, e.g.
138.76.29.7.
All outgoing packets appear externally to come from the NAT router’s public address.
NAT is a workaround for IPv4 address exhaustion.
2.17.2. Private networks can reuse addresses
Many home networks can all use the same private range, such as:
10.0.0.0/24 192.168.0.0/24
These addresses are not globally unique.
They only need to be unique inside the local network.
2.17.3. NAT implementation
A NAT router modifies outgoing packets.
For an outgoing packet:
Source: 10.0.0.1:3345 Destination: 128.119.40.186:80
the NAT router may rewrite it to:
Source: 138.76.29.7:5001 Destination: 128.119.40.186:80
It stores the mapping in a NAT translation table:
WAN side LAN side 138.76.29.7:5001 -> 10.0.0.1:3345
When the reply arrives:
Source: 128.119.40.186:80 Destination: 138.76.29.7:5001
the NAT router looks up the translation table and rewrites the destination:
Source: 128.119.40.186:80 Destination: 10.0.0.1:3345
Then it forwards the packet to the internal host.
2.17.4. Why ports are needed
If multiple internal hosts share one public IP address, the NAT router needs more than just the IP address to distinguish connections.
It usually uses transport-layer ports.
This means NAT is not purely a layer-3 operation.
The router must inspect and modify layer-4 information such as TCP or UDP port numbers.
2.17.5. NAT state
NAT devices keep state.
They must remember translation entries so that incoming replies can be mapped back to the correct internal host.
This state is usually temporary and can time out.
Therefore, NAT can break long-idle connections or peer-to-peer scenarios.
2.17.6. NAT and the end-to-end principle
Originally, the Internet was designed around the end-to-end principle:
Any host with a global IP address should, in principle, be able to communicate directly with any other host.
NAT breaks this idea.
Devices behind NAT are not directly reachable from the outside unless extra configuration is used.
For example:
- port forwarding;
- NAT traversal;
- VPNs;
- relay servers.
This is a problem for peer-to-peer applications and games.
The instructor mentioned that people often use VPN-like tools to create a direct-looking network with friends because NAT makes direct connection difficult.
2.17.7. NAT is not a firewall
The instructor emphasized:
NAT is not a firewall.
NAT may have firewall-like side effects because unsolicited inbound connections often fail without a translation entry.
But this is not the same as deliberate security policy enforcement.
A proper firewall should still be used.
2.17.8. Carrier-grade NAT
Sometimes a home router does not even receive a globally routable public IPv4 address.
Instead:
- devices are behind the home NAT;
- the home router is itself behind another NAT at the ISP.
This is carrier-grade NAT.
It is common in mobile networks and some ISPs.
Multiple layers of NAT make peer-to-peer communication and inbound reachability even harder.
2.17.9. NAT and protocol ossification
NAT contributes to protocol ossification.
Because many NAT devices expect TCP or UDP ports in specific places, it becomes difficult to deploy new transport protocols.
The instructor mentioned QUIC as an example: QUIC runs over UDP partly because UDP passes through NATs and middleboxes more easily than a completely new transport protocol would.
2.17.10. NAT limitations
A NAT with one public IP address has a limited number of port numbers.
The slides mention that a 16-bit port-number field gives more than 60,000 simultaneous connections for one public address.
This sounds large, but it is still a limit, especially with many users or carrier-grade NAT.
2.17.11. IPv6 as the cleaner solution
The instructor’s view is that IPv6 is the proper solution to address shortage.
With enough globally routable addresses, NAT is not needed as an address-conservation workaround.
2.18. Lecture 14 Summary
Main points:
- The network layer has a data plane and a control plane.
- Forwarding is local packet movement; routing builds and maintains forwarding tables.
- The Internet uses a best-effort service model.
- Best effort has no delivery, delay, ordering, or bandwidth guarantees.
- Best effort succeeded because it is simple and scalable.
- Real Internet routing is not flat; it uses autonomous systems.
- Intra-AS routing handles routing inside one AS.
- Inter-AS routing handles reachability between ASes.
- Ethernet is the dominant wired LAN technology.
- Hubs repeat bits and do not isolate collision domains.
- Switches learn MAC-to-interface mappings and selectively forward frames.
- Switches are transparent and plug-and-play, but layer-2 switching does not scale globally.
- Routers operate at layer 3 and provide hierarchical routing and stronger isolation.
- NAT maps private internal addresses and ports to public external addresses and ports.
- NAT is widely used because of IPv4 exhaustion, but it violates the end-to-end principle.
- NAT is not a firewall.
- NAT complicates peer-to-peer applications and new transport protocols.
- IPv6 is the cleaner long-term solution to address shortage.