Split View: [컴퓨터 네트워크] 15. 링크 계층: 오류 검출과 다중 접속 프로토콜
[컴퓨터 네트워크] 15. 링크 계층: 오류 검출과 다중 접속 프로토콜
링크 계층: 오류 검출과 다중 접속 프로토콜
링크 계층(Link Layer)은 인접한 두 노드 사이에서 프레임을 안전하게 전달하는 역할을 담당합니다. 네트워크 계층이 호스트 간 패킷 전달을 책임진다면, 링크 계층은 한 홉(hop) 단위의 통신을 담당합니다.
이 글에서는 링크 계층의 서비스, 오류 검출 기법, 그리고 공유 매체에서의 다중 접속(Multiple Access) 프로토콜을 살펴봅니다.
1. 링크 계층 서비스
1.1 기본 서비스
링크 계층이 제공하는 서비스
=============================
1. 프레이밍 (Framing)
- 네트워크 계층 데이터그램을 프레임으로 캡슐화
- 프레임 헤더에 MAC 주소 포함
2. 링크 접속 (Link Access)
- 공유 매체에서의 접속 제어 (다중 접속 프로토콜)
- MAC 주소를 사용한 프레임 전달
3. 신뢰적 전달 (Reliable Delivery)
- 오류율이 높은 링크(무선)에서 ARQ 사용
- 유선 링크에서는 보통 사용하지 않음
4. 오류 검출 및 정정
- 비트 오류 검출: 패리티, CRC 등
- 오류 정정: FEC (Forward Error Correction)
1.2 구현 위치
링크 계층은 주로 NIC(Network Interface Card) 에 구현됩니다. NIC의 하드웨어 칩이 프레이밍, CRC 계산, MAC 프로토콜 등을 처리합니다.
링크 계층 구현
================
[애플리케이션 계층]
[트랜스포트 계층] CPU / 소프트웨어
[네트워크 계층]
-----------------------
[링크 계층] NIC (하드웨어 + 펌웨어)
[물리 계층]
2. 오류 검출 기법
2.1 패리티 비트 (Parity Bit)
가장 단순한 오류 검출 방법으로, 데이터 비트에 패리티 비트 하나를 추가합니다.
단일 패리티 비트 (짝수 패리티)
===============================
데이터: 1011010
패리티 비트: 0 (1의 개수가 짝수가 되도록)
전송: 10110100
수신: 10110110 (5번째 비트 오류)
1의 개수: 5 (홀수) --> 오류 검출!
한계: 짝수 개의 비트가 동시에 오류나면 검출 불가
2차원 패리티: 행과 열 모두에 패리티 비트를 추가하여 단일 비트 오류를 정정할 수도 있습니다.
2차원 패리티
==============
데이터 + 행 패리티:
1 0 1 1 | 1
0 1 1 0 | 0
1 1 0 1 | 1
----------
0 0 0 0 (열 패리티)
오류 발생:
1 0 1 1 | 1
0 1 0 0 | 0 <-- 행 패리티 불일치
1 1 0 1 | 1
----------
0 0 1 0 <-- 열 패리티 불일치
^
3번째 열, 2번째 행 --> 오류 위치 특정 및 정정 가능
2.2 인터넷 체크섬 (Internet Checksum)
트랜스포트 계층(TCP, UDP)에서 사용하는 간단한 오류 검출 방법입니다.
인터넷 체크섬 계산
====================
1. 데이터를 16비트 워드 단위로 분할
2. 모든 워드를 1의 보수 덧셈
3. 결과의 1의 보수를 체크섬으로 사용
예시:
워드 1: 0110 0110 0110 0000
워드 2: 0101 0101 0101 0101
-------------------------
합계: 1011 1011 1011 0101
체크섬: 0100 0100 0100 1010 (1의 보수)
검증: 수신 측에서 체크섬 포함 모든 워드를 더하면
결과가 1111 1111 1111 1111 이어야 함
2.3 CRC (Cyclic Redundancy Check)
CRC는 링크 계층에서 가장 널리 사용되는 강력한 오류 검출 방법입니다. 다항식 나눗셈을 기반으로 합니다.
CRC 계산 과정
===============
1. 생성 다항식 G 결정 (송신자와 수신자가 공유)
예: G = 1001 (x^3 + 1), r = 3비트
2. 데이터 D에 r개의 0을 붙임
D = 101110, D * 2^r = 101110 000
3. D * 2^r을 G로 XOR 나눗셈하여 나머지 R을 구함
101110 000 / 1001
----------------
101110 000
XOR 1001
--------
0101 10 000
XOR 1001
--------
0000 1000 0
XOR 1001
------
0001 0
나머지 R = 011
4. 전송 비트: D와 R을 연결 = 101110 011
5. 수신 측: 수신 비트를 G로 나누어 나머지 = 0이면 오류 없음
2.4 CRC의 오류 검출 능력
CRC의 강력한 검출 능력
========================
r비트 CRC로 검출 가능한 오류:
- 모든 단일 비트 오류
- 모든 2비트 오류 (적절한 G 선택 시)
- 홀수 개의 비트 오류 (G가 x+1을 인수로 포함 시)
- r비트 이하의 연속 오류 (burst error)
표준 CRC 다항식:
CRC-8: x^8 + x^2 + x + 1
CRC-16: x^16 + x^15 + x^2 + 1
CRC-32: 이더넷, WiFi, ZIP 등에서 사용
32비트 나머지로 매우 강력한 검출
3. 다중 접속 프로토콜
여러 노드가 하나의 공유 브로드캐스트 링크를 사용할 때, 동시 전송으로 인한 충돌(collision)을 해결해야 합니다.
3.1 분류
다중 접속 프로토콜 분류
=========================
1. 채널 분할 (Channel Partitioning)
- TDMA, FDMA, CDMA
- 충돌 없지만 비효율적
2. 랜덤 접속 (Random Access)
- ALOHA, Slotted ALOHA, CSMA, CSMA/CD
- 충돌 허용, 감지/복구 메커니즘
3. 순번 방식 (Taking-Turns)
- 폴링, 토큰 패싱
- 중간 타협점
4. 채널 분할 프로토콜
4.1 TDMA (Time Division Multiple Access)
시간을 고정 크기의 슬롯으로 나누고, 각 노드에 전용 슬롯을 할당합니다.
TDMA 동작
==========
시간 프레임:
[슬롯1][슬롯2][슬롯3][슬롯4][슬롯1][슬롯2][슬롯3][슬롯4]
노드A 노드B 노드C 노드D 노드A 노드B 노드C 노드D
장점: 충돌 없음
단점: 노드 A만 데이터가 있어도 자기 슬롯에서만 전송 가능
--> 채널 대역폭의 1/N만 사용 가능 (낭비)
4.2 FDMA (Frequency Division Multiple Access)
주파수 대역을 나누어 각 노드에 전용 주파수를 할당합니다.
FDMA 동작
==========
주파수
^
| [노드 D 대역]
| [노드 C 대역]
| [노드 B 대역]
| [노드 A 대역]
+--------------------> 시간
TDMA와 동일한 장단점
- 충돌 없지만 대역폭 낭비
5. 랜덤 접속 프로토콜
5.1 ALOHA
하와이 대학에서 개발된 최초의 랜덤 접속 프로토콜입니다.
Pure ALOHA
===========
동작:
1. 전송할 프레임이 있으면 즉시 전송
2. 충돌 발생 시 확률 p로 즉시 재전송, (1-p)로 대기
시간:
[A 전송]
[B 전송] <-- A와 겹침, 충돌!
[A 재전송]
[C 전송] <-- 충돌 없음
최대 효율: 1/(2e) = 약 18%
(채널 용량의 18%만 실제 전송에 사용)
5.2 Slotted ALOHA
시간을 슬롯으로 나누고, 슬롯 시작 시점에만 전송을 허용하여 충돌 가능 구간을 줄입니다.
Slotted ALOHA
===============
시간 슬롯:
| 슬롯 1 | 슬롯 2 | 슬롯 3 | 슬롯 4 | 슬롯 5 |
| A 전송 | A+B 충돌| B 전송 | | C 전송 |
| 성공 | 실패 | 성공 | 비어있음| 성공 |
최대 효율: 1/e = 약 37%
(Pure ALOHA의 2배)
가정:
- 모든 프레임이 같은 크기
- 시간이 슬롯으로 동기화
- 슬롯 시작 시점에만 전송 시작
5.3 CSMA (Carrier Sense Multiple Access)
전송 전에 채널을 청취(carrier sense)하여, 다른 노드가 전송 중이면 대기합니다.
CSMA 동작
==========
1. 채널 감지 (Listen before talk)
- 채널이 비어있으면 --> 전송
- 채널이 사용 중이면 --> 대기
2. 그래도 충돌이 발생하는 이유: 전파 지연!
시간
|
| A가 전송 시작
| [A의 신호가 B에 도달하는 중...]
| B가 채널을 감지: "비어있네!" --> B도 전송 시작
| [충돌 발생!]
v
전파 지연이 클수록 충돌 확률 증가
5.4 CSMA/CD (CSMA with Collision Detection)
충돌을 감지하면 즉시 전송을 중단하여 채널 낭비를 줄입니다. 이더넷에서 사용하는 방식입니다.
CSMA/CD 동작 과정
====================
1. NIC가 프레임을 수신하면 채널 감지
2. 채널이 비어있으면 전송 시작
3. 전송 중 충돌 감지:
a. 전송 즉시 중단
b. 잼(Jam) 신호 전송 (48비트)
c. 이진 지수 백오프 (Binary Exponential Backoff)
이진 지수 백오프:
n번째 충돌 후, 0 ~ (2^n - 1) 중 랜덤 선택하여 대기
1번째 충돌: 0 또는 1 중 선택
2번째 충돌: 0, 1, 2, 3 중 선택
3번째 충돌: 0 ~ 7 중 선택
...
10번째 충돌: 0 ~ 1023 중 선택 (최대 10까지)
5.5 CSMA/CD 효율
CSMA/CD 효율 공식
====================
효율 = 1 / (1 + 5 * d_prop / d_trans)
d_prop: 최대 전파 지연 (두 노드 간 최대 거리)
d_trans: 최대 크기 프레임의 전송 시간
특성:
- d_prop -> 0 이면 효율 -> 1 (이상적)
- d_trans -> 무한대 이면 효율 -> 1
- 큰 프레임, 짧은 거리에서 효율적
6. 순번 방식 (Taking-Turns) 프로토콜
6.1 폴링 (Polling)
마스터 노드가 각 슬레이브 노드를 순서대로 지정하여 전송 기회를 부여합니다.
폴링 프로토콜
===============
[마스터]
|
|--> "노드 A, 전송하세요" --> [노드 A] 전송
|
|--> "노드 B, 전송하세요" --> [노드 B] 전송 (데이터 없음, 패스)
|
|--> "노드 C, 전송하세요" --> [노드 C] 전송
|
|--> 다시 노드 A부터...
단점:
- 폴링 오버헤드 (폴링 메시지)
- 폴링 지연 (순서를 기다림)
- 마스터 노드 고장 시 전체 네트워크 마비 (단일 장애 지점)
6.2 토큰 패싱 (Token Passing)
특수한 토큰 프레임이 노드 사이를 순환하며, 토큰을 가진 노드만 전송할 수 있습니다.
토큰 패싱 프로토콜
====================
[A] --> [B] --> [C] --> [D]
^ |
|_______________________|
(토큰 순환)
동작:
1. 토큰이 A에 도착
2. A에 데이터가 있으면: 데이터 전송 후 토큰을 B로 전달
3. A에 데이터가 없으면: 토큰을 바로 B로 전달
4. 반복
장점: 공정성 보장, 충돌 없음
단점:
- 토큰 오버헤드
- 토큰 분실 시 복구 필요
- 한 노드 고장 시 네트워크 장애
7. 다중 접속 프로토콜 비교
프로토콜 비교 요약
====================
프로토콜 | 효율 | 지연 | 공정성 | 복잡도
-----------+----------+--------+--------+--------
TDMA | 낮음(1/N) | 보장 | 공정 | 단순
FDMA | 낮음(1/N) | 보장 | 공정 | 단순
Pure ALOHA | 18% | 가변 | 공정 | 단순
Slotted ALOHA | 37% | 가변 | 공정 | 단순
CSMA/CD | 높음 | 가변 | 공정 | 중간
폴링 | 높음 | 폴링지연| 가변 | 중간
토큰 | 높음 | 토큰지연| 공정 | 높음
8. 정리
| 개념 | 핵심 내용 |
|---|---|
| 패리티 비트 | 가장 단순한 오류 검출, 짝수 오류 미검출 |
| CRC | 다항식 나눗셈 기반, 강력한 burst 오류 검출 |
| CSMA/CD | 감지 후 전송, 충돌 시 즉시 중단 + 백오프 |
| Slotted ALOHA | 슬롯 동기화로 효율 37% |
| 이진 지수 백오프 | 충돌 반복 시 대기 범위 2배씩 증가 |
| 폴링 | 마스터가 순서 지정, 단일 장애 지점 위험 |
| 토큰 패싱 | 토큰 보유 노드만 전송, 공정하지만 오버헤드 |
다음 글에서는 링크 계층의 대표적 구현인 이더넷, 링크 계층 스위치, 그리고 VLAN을 살펴보겠습니다.
참고 자료
- James F. Kurose, Keith W. Ross, "Computer Networking: A Top-Down Approach", 6th Edition, Chapter 5
- IEEE 802.3 - Ethernet Standard
- Andrew S. Tanenbaum, "Computer Networks", 5th Edition, Chapter 4
[Computer Networking] 15. Link Layer: Error Detection and Multiple Access Protocols
Link Layer: Error Detection and Multiple Access Protocols
The Link Layer is responsible for safely delivering frames between two adjacent nodes. While the network layer handles packet delivery between hosts, the link layer handles communication on a per-hop basis.
In this post, we examine the link layer's services, error detection techniques, and Multiple Access protocols for shared media.
1. Link Layer Services
1.1 Basic Services
Services Provided by the Link Layer
======================================
1. Framing
- Encapsulates network layer datagrams into frames
- Includes MAC addresses in frame header
2. Link Access
- Access control on shared media (multiple access protocols)
- Frame delivery using MAC addresses
3. Reliable Delivery
- Uses ARQ on error-prone links (wireless)
- Usually not used on wired links
4. Error Detection and Correction
- Bit error detection: parity, CRC, etc.
- Error correction: FEC (Forward Error Correction)
1.2 Implementation Location
The link layer is primarily implemented in the NIC (Network Interface Card). The NIC's hardware chip handles framing, CRC computation, MAC protocol, and more.
Link Layer Implementation
===========================
[Application Layer]
[Transport Layer] CPU / Software
[Network Layer]
-----------------------
[Link Layer] NIC (Hardware + Firmware)
[Physical Layer]
2. Error Detection Techniques
2.1 Parity Bit
The simplest error detection method, adding a single parity bit to the data bits.
Single Parity Bit (Even Parity)
=================================
Data: 1011010
Parity bit: 0 (so that the count of 1s is even)
Transmitted: 10110100
Received: 10110110 (5th bit error)
Count of 1s: 5 (odd) --> Error detected!
Limitation: Cannot detect even number of simultaneous bit errors
Two-Dimensional Parity: Adding parity bits to both rows and columns can even correct single-bit errors.
Two-Dimensional Parity
========================
Data + Row Parity:
1 0 1 1 | 1
0 1 1 0 | 0
1 1 0 1 | 1
----------
0 0 0 0 (Column parity)
Error occurred:
1 0 1 1 | 1
0 1 0 0 | 0 <-- Row parity mismatch
1 1 0 1 | 1
----------
0 0 1 0 <-- Column parity mismatch
^
3rd column, 2nd row --> Error location identified and correctable
2.2 Internet Checksum
A simple error detection method used by the transport layer (TCP, UDP).
Internet Checksum Computation
================================
1. Divide data into 16-bit words
2. Add all words using one's complement addition
3. Take the one's complement of the result as the checksum
Example:
Word 1: 0110 0110 0110 0000
Word 2: 0101 0101 0101 0101
-------------------------
Sum: 1011 1011 1011 0101
Checksum: 0100 0100 0100 1010 (one's complement)
Verification: At receiver, adding all words including checksum
should yield 1111 1111 1111 1111
2.3 CRC (Cyclic Redundancy Check)
CRC is the most widely used and powerful error detection method at the link layer. It is based on polynomial division.
CRC Computation Process
=========================
1. Determine generator polynomial G (shared by sender and receiver)
Example: G = 1001 (x^3 + 1), r = 3 bits
2. Append r zeros to data D
D = 101110, D * 2^r = 101110 000
3. Compute remainder R by XOR division of D * 2^r by G
101110 000 / 1001
----------------
101110 000
XOR 1001
--------
0101 10 000
XOR 1001
--------
0000 1000 0
XOR 1001
------
0001 0
Remainder R = 011
4. Transmitted bits: Concatenate D and R = 101110 011
5. Receiver: Divide received bits by G, remainder = 0 means no error
2.4 Error Detection Capability of CRC
CRC's Strong Detection Capability
====================================
Errors detectable with r-bit CRC:
- All single-bit errors
- All 2-bit errors (with appropriate G selection)
- Odd number of bit errors (if G contains x+1 as factor)
- Burst errors of r bits or fewer
Standard CRC Polynomials:
CRC-8: x^8 + x^2 + x + 1
CRC-16: x^16 + x^15 + x^2 + 1
CRC-32: Used in Ethernet, WiFi, ZIP, etc.
Very strong detection with 32-bit remainder
3. Multiple Access Protocols
When multiple nodes share a single broadcast link, collisions from simultaneous transmission must be resolved.
3.1 Classification
Multiple Access Protocol Classification
==========================================
1. Channel Partitioning
- TDMA, FDMA, CDMA
- No collisions but inefficient
2. Random Access
- ALOHA, Slotted ALOHA, CSMA, CSMA/CD
- Collisions allowed, detection/recovery mechanisms
3. Taking-Turns
- Polling, Token Passing
- Middle ground compromise
4. Channel Partitioning Protocols
4.1 TDMA (Time Division Multiple Access)
Time is divided into fixed-size slots, and each node is assigned a dedicated slot.
TDMA Operation
================
Time frame:
[Slot1][Slot2][Slot3][Slot4][Slot1][Slot2][Slot3][Slot4]
NodeA NodeB NodeC NodeD NodeA NodeB NodeC NodeD
Advantage: No collisions
Disadvantage: Even if only Node A has data, it can only transmit in its slot
--> Only 1/N of channel bandwidth usable (waste)
4.2 FDMA (Frequency Division Multiple Access)
The frequency band is divided and each node is assigned a dedicated frequency.
FDMA Operation
================
Frequency
^
| [Node D band]
| [Node C band]
| [Node B band]
| [Node A band]
+--------------------> Time
Same pros/cons as TDMA
- No collisions but bandwidth waste
5. Random Access Protocols
5.1 ALOHA
The first random access protocol, developed at the University of Hawaii.
Pure ALOHA
===========
Operation:
1. If a frame is ready, transmit immediately
2. On collision, retransmit immediately with probability p, wait with (1-p)
Time:
[A transmits]
[B transmits] <-- Overlaps with A, collision!
[A retransmits]
[C transmits] <-- No collision
Maximum efficiency: 1/(2e) = ~18%
(Only 18% of channel capacity used for actual transmission)
5.2 Slotted ALOHA
Time is divided into slots, and transmission is only allowed at slot boundaries, reducing the collision window.
Slotted ALOHA
===============
Time slots:
| Slot 1 | Slot 2 | Slot 3 | Slot 4 | Slot 5 |
| A sends | A+B col.| B sends | | C sends |
| Success | Failure | Success | Empty | Success |
Maximum efficiency: 1/e = ~37%
(Twice Pure ALOHA)
Assumptions:
- All frames are the same size
- Time is synchronized into slots
- Transmission starts only at slot boundaries
5.3 CSMA (Carrier Sense Multiple Access)
Before transmitting, the channel is listened to (carrier sense). If another node is transmitting, wait.
CSMA Operation
================
1. Carrier Sense (Listen before talk)
- Channel idle --> Transmit
- Channel busy --> Wait
2. Why collisions still occur: Propagation delay!
Time
|
| A starts transmitting
| [A's signal traveling toward B...]
| B senses channel: "Idle!" --> B also starts transmitting
| [Collision!]
v
The greater the propagation delay, the higher the collision probability
5.4 CSMA/CD (CSMA with Collision Detection)
Detects collisions and immediately stops transmission to reduce channel waste. This is the method used by Ethernet.
CSMA/CD Operation
====================
1. NIC receives frame and senses channel
2. If channel is idle, start transmission
3. Collision detected during transmission:
a. Stop transmission immediately
b. Send Jam signal (48 bits)
c. Binary Exponential Backoff
Binary Exponential Backoff:
After nth collision, randomly choose from 0 ~ (2^n - 1) and wait
1st collision: Choose from 0 or 1
2nd collision: Choose from 0, 1, 2, 3
3rd collision: Choose from 0 ~ 7
...
10th collision: Choose from 0 ~ 1023 (capped at 10)
5.5 CSMA/CD Efficiency
CSMA/CD Efficiency Formula
=============================
Efficiency = 1 / (1 + 5 * d_prop / d_trans)
d_prop: Maximum propagation delay (max distance between two nodes)
d_trans: Transmission time for maximum-size frame
Properties:
- d_prop -> 0: efficiency -> 1 (ideal)
- d_trans -> infinity: efficiency -> 1
- Efficient with large frames and short distances
6. Taking-Turns Protocols
6.1 Polling
A master node designates each slave node in order, granting transmission opportunities.
Polling Protocol
==================
[Master]
|
|--> "Node A, your turn" --> [Node A] transmits
|
|--> "Node B, your turn" --> [Node B] transmits (no data, pass)
|
|--> "Node C, your turn" --> [Node C] transmits
|
|--> Back to Node A...
Disadvantages:
- Polling overhead (polling messages)
- Polling latency (waiting for turn)
- Single point of failure if master node fails
6.2 Token Passing
A special token frame circulates among nodes, and only the node holding the token can transmit.
Token Passing Protocol
========================
[A] --> [B] --> [C] --> [D]
^ |
|_______________________|
(Token circulation)
Operation:
1. Token arrives at A
2. If A has data: transmit data, then pass token to B
3. If A has no data: pass token directly to B
4. Repeat
Advantages: Fairness guaranteed, no collisions
Disadvantages:
- Token overhead
- Recovery needed if token is lost
- Network failure if one node fails
7. Multiple Access Protocol Comparison
Protocol Comparison Summary
==============================
Protocol | Efficiency | Delay | Fairness | Complexity
-------------+------------+----------+----------+-----------
TDMA | Low (1/N) | Guaranteed| Fair | Simple
FDMA | Low (1/N) | Guaranteed| Fair | Simple
Pure ALOHA | 18% | Variable | Fair | Simple
Slotted ALOHA| 37% | Variable | Fair | Simple
CSMA/CD | High | Variable | Fair | Medium
Polling | High | Poll delay| Variable| Medium
Token | High | Token delay| Fair | High
8. Summary
| Concept | Key Points |
|---|---|
| Parity Bit | Simplest error detection, misses even-count errors |
| CRC | Polynomial division based, strong burst error detection |
| CSMA/CD | Sense then transmit, stop immediately on collision + backoff |
| Slotted ALOHA | Slot synchronization for 37% efficiency |
| Binary Exp. Backoff | Wait range doubles with each collision |
| Polling | Master assigns turns, single point of failure risk |
| Token Passing | Only token holder transmits, fair but has overhead |
In the next post, we will examine Ethernet, link-layer switches, and VLANs as representative implementations of the link layer.
References
- James F. Kurose, Keith W. Ross, "Computer Networking: A Top-Down Approach", 6th Edition, Chapter 5
- IEEE 802.3 - Ethernet Standard
- Andrew S. Tanenbaum, "Computer Networks", 5th Edition, Chapter 4