# 50.012 Lecture 18
# Ethernet

Dominant wired LAN technology. Designed in principle to be simple and cheap. Because of the simple design, it is able to be redesigned effectively over time.
## Topology

Initially, the bus topology was the prominent Ethernet topology. All nodes are in the same collision domain (can collide with each other)

However, most of the Ethernet deployed today are switch Ethernet, which has the star topology. Each "spoke" runs a separate Ethernet protocol (nodes do not collide with each other). It's a Point-to-Point communications between node and switch.
## Ethernet Frame Structure

Ethernet frame header consists of preamble, destination address, and source address.
The purpose of preamble is to help synchronize the receiver (when there is an incoming packet) and the clock (to decode the packet).
Payload is the IP packet.
The preamble has a pre-agreed pattern (7 bytes with pattern `10101010` followed by one byte with pattern `10101011`).
Ethernet frame tailer consists of CRC.
### Cyclic Redundancy Check

It is an error detection coding (similar to checksum).
In CRC, data bits, D, are treated as a (big) binary number.
Steps:
* Sender and receiver need to agree on a r+1 bit pattern (generator), G
* Calculate r CRC bits, R, such that:
* <D,R> (D concatenated with R) is exactly divisible by G (modulo 2)
* Since receiver knows G, it can divide <D,R> by G. If the remainder is non-zero, it means that there is an error. Either D is corrupted, or R is corrupted.
* For r bits CRC, we can detect all burst errors less than r+1 bits. Burst errors: errors that are clustered together, so that the first bit and the last bit of error should be within r bits. This is useful because in Link Layer, bit error is usually caused by interference, which will affect a cluster of bits.
We are free to choose the number of CRC bits (r\).
$$
D * 2^r \ XOR \ \ R
$$
$D*2^r$ is the same as shifting D by r bits.
$XOR \ \ R$ basically copies R to the r 0-bits of D.

In this example, r = 3. MSB(G) = 1, and G must be 1 bit longer than r.
### Ethernet Frame Structure (Revisited)

The size of preamble is 8 bytes long.
The size of source and destination MAC Addresses in the Ethernet frame is 6 bytes each (MAC is 48-bit long).
Type is 2 byte long.
CRC is 4 bytes long.
Total (excluding payload) is 26 bytes.
#### Address
If an adapter receives frame with matching destination address, or with broadcast address (e.g. ARP packet), it passes data in frame to network layer protocol.
Otherwise, it will be dropped.
#### Type
Indicates higher layer protocol (mostly IP but other protocols are possible)
#### CRC
Cyclic Redundancy Check at receiver. If there is an error detected, the frame is dropped.
## Properties of Ethernet
Ethernet has the following shortcomings. However, these shortcomings stem from the design choice that allows Ethernet to be very simple.
### Connectionless
Ethernet has no handshaking between sending and receiving NICs.
### Unreliable
Receiving NIC does not need to send ACK or NAK to sending NIC. Data in dropped frames are recoveredo nly if initial sender uses higher layer rdt (e.g. TCP), otherwise, the dropped data is lost.
# Switches and VLAN
## Ethernet Switch
Link-layer device takes an active role:
* Stores and forwards Ethernet frames.
* Examines incoming frame's MAC Address (since switch is a layer 2 device), selectively forward frame to one or more outgoing links when frame is to be forwarded on segment, uses CSMA/CD to access segment.
It is also transparent: hosts are unaware of presence of switches.
It is plug-and-play and self-learning: unlike routers, switches do not need to be configured. It learns by looking at the traffic that passes by it.
### Multiple Simultaneous Transmissions

If the switch has a powerful enough switching fabric, A can send to A' and B can send to B' at full speed simultaneously (full duplex). Ethernet protocol used on each incoming link.
There is no connection because the packet is terminated at the interface that is connected to the host.
There is no collision due to the existence of the switching fabric.
The switch knows which host is reachable through which interface via a switch table.
Each entry of the switch table:
* (MAC Address of host, interface to reach host, timestamp)
### Self Learning
How are entries populated and maintained in each switch:
It learns which hosts can be reached through which interface by:
* When frame is received, switch "learns" the location of the sender by using the incoming LAN segment.
* Records sender / location pair in switch table.
When a packet reaches the switch, it will record incoming link, MAC Address of sending host.
Index switch table using MAC Destination Address
```
If entry is found for destination,
then {
if destination on segment from which frame arrived, then drop frame.
else: forward frame on interface indicated by entry.
}
else flood () => forward on all interfaces except arriving interface
```
Sometimes, multiple switches are needed because of the large number of hosts.

### Interconnecting Switches
Self-learning switches can be connected together:

Learning works in the same way as single-switch.
#### Example

### Switches vs Routers

* Both are store-and-forward:
* Routers: network-layer device (examines network-layer headers)
* Switches: Link-layer device (examines link-layer headers)
* Both have forwarding tables:
* Routers: Compute tables using routing algorithms, IP Addresses
* Switches: Learn forwarding table using flooding, learning, MAC Addresses.
## VLAN
### Motivation

Consider if a CS user moves office to EE but still wants to connet to CS switch.
Single broadcast domain contains:
* All layer-2 broadcast traffic (ARP, DHCP, unknown location of destination MAC address) must cross the entire LAN.
* Security / privacy, efficiency issues.
### Port Based VLAN
VLAN is associated to a physical switch.
Switches supporting VLAN capabilities can be configured to define multiple virtual LANs over single physical LAN infrastructure.



This allows for:
* Traffic isolation: frames to/from ports 1-8 can only reach ports 1-8.
We can also define VLAN based on MAC addresses of endpoints rather than switch port.
* Dynamic membership: ports can be dynamically assigned among VLANs.
* Forwarding between VLANs: done via routing (similar to inter-AS communications). In practice vendors sell combined switches + routers.
### VLANs Spanning Multiple Switches

We can define a VLAN that spans across multiple switchs.
Implication: when we want to broadcast a packet to a subnet under the Ethernet level, everyone in the subnet will receive it (hosts who are connected to the physical switch and the VLAN).
Trunk port: carries frames between VLANs defined over multiple physical switches. Frames forwarded within VLAN between swithcse can't be vanilla 802.1 frames. They must carry VLAN ID info.

802.1q protocol adds/removes additional header fields for frames forwarded between trunk ports.
When a switch receives an Ethernet frame from a host, it will then add the VLAN ID to the packet, then send it over to the other switches so that they will be able to forward the frame to the ports with the same VLAN ID.