Split View: [컴퓨터 네트워크] 13. 라우팅 알고리즘: Link-State와 Distance-Vector
[컴퓨터 네트워크] 13. 라우팅 알고리즘: Link-State와 Distance-Vector
라우팅 알고리즘: Link-State와 Distance-Vector
라우팅 알고리즘은 송신 호스트에서 수신 호스트까지의 최적 경로를 결정합니다. 네트워크를 그래프로 모델링하고, 노드 간 최소 비용 경로를 계산하는 것이 핵심입니다.
이 글에서는 두 가지 대표적인 라우팅 알고리즘인 Link-State(LS) 알고리즘과 Distance-Vector(DV) 알고리즘을 다루며, 각각의 장단점과 문제점을 분석합니다.
1. 네트워크의 그래프 모델
네트워크는 노드(라우터)와 에지(링크)로 구성된 가중치 그래프로 모델링됩니다.
네트워크 그래프 예시
=====================
2
(u) -------> (v)
| \ |
1| \5 |3
| \ |
v v v
(x)---(w)---->(y)---->(z)
3 1 2
c(u,v) = 2, c(u,x) = 1, c(u,w) = 5
c(v,y) = 3, c(x,w) = 3, c(w,y) = 1
c(y,z) = 2
목표: 출발 노드에서 모든 다른 노드까지의 최소 비용 경로를 찾는 것
2. 라우팅 알고리즘 분류
라우팅 알고리즘 분류
======================
1. 정보 범위에 따라:
- 전역적 (Global): 모든 노드의 정보를 알고 계산 --> Link-State
- 분산적 (Decentralized): 이웃 정보만으로 반복 계산 --> Distance-Vector
2. 동작 방식에 따라:
- 정적 (Static): 경로가 거의 변하지 않음
- 동적 (Dynamic): 네트워크 변화에 따라 주기적으로 재계산
3. 부하 민감도에 따라:
- 부하 민감 (Load-Sensitive): 링크 혼잡도를 비용에 반영
- 부하 비민감 (Load-Insensitive): 현재 인터넷 라우팅 방식
3. Link-State 알고리즘 (다익스트라 알고리즘)
3.1 기본 원리
Link-State 알고리즘은 네트워크의 전체 토폴로지 정보를 기반으로 동작합니다. 각 노드가 자신의 링크 상태 정보를 네트워크 전체에 브로드캐스트하고, 모든 노드가 동일한 정보를 갖게 되면 다익스트라 알고리즘으로 최단 경로를 계산합니다.
3.2 알고리즘 동작
다익스트라 알고리즘 (Dijkstra's Algorithm)
===========================================
초기화:
N' = 출발 노드 u
D(v) = c(u,v) (직접 연결된 이웃의 비용)
무한대 (직접 연결되지 않은 노드)
반복:
1. N'에 포함되지 않은 노드 중 D(w)가 최소인 노드 w를 선택
2. w를 N'에 추가
3. w의 이웃 v에 대해:
D(v) = min(D(v), D(w) + c(w,v))
4. 모든 노드가 N'에 포함될 때까지 반복
3.3 실행 예시
위의 그래프에서 노드 u를 출발점으로 다익스트라 알고리즘을 실행합니다.
다익스트라 실행 과정 (출발: u)
===============================
단계 | N' | D(v) | D(w) | D(x) | D(y) | D(z)
-----+-----------+------+------+------+------+------
0 | u | 2 | 5 | 1 | inf | inf
1 | u,x | 2 | 4 | 1 | inf | inf
2 | u,x,v | 2 | 4 | 1 | 5 | inf
3 | u,x,v,w | 2 | 4 | 1 | 5 | inf
4 | u,x,v,w,y | 2 | 4 | 1 | 5 | 7
5 | 모든 노드 | 2 | 4 | 1 | 5 | 7
최단 경로 트리:
u -> v: 비용 2 (직접)
u -> x: 비용 1 (직접)
u -> w: 비용 4 (u -> x -> w)
u -> y: 비용 5 (u -> v -> y 또는 u -> x -> w -> y)
u -> z: 비용 7 (u -> ... -> y -> z)
3.4 시간 복잡도
기본 구현의 시간 복잡도는 O(n^2)이며, 우선순위 큐(힙)를 사용하면 O(n log n)으로 개선할 수 있습니다.
3.5 진동 문제 (Oscillation)
링크 비용이 트래픽 부하에 따라 변하면, 라우팅이 진동(oscillation)할 수 있습니다.
LS 진동 문제 예시
==================
시점 1: A -> B 경로로 대부분의 트래픽이 흐름
--> A -> B 링크 비용 증가
시점 2: 모든 노드가 A -> C -> D -> B 경로로 전환
--> A -> C 링크 비용 증가
시점 3: 다시 A -> B 경로로 전환 (진동 반복)
해결책: 라우팅 업데이트 시점을 랜덤화
4. Distance-Vector 알고리즘 (벨만-포드)
4.1 기본 원리
Distance-Vector 알고리즘은 분산적으로 동작합니다. 각 노드는 이웃에게만 자신의 거리 벡터(모든 목적지까지의 추정 비용)를 전달하고, 이웃의 정보를 기반으로 자신의 거리 벡터를 갱신합니다.
4.2 벨만-포드 방정식
노드 x에서 목적지 y까지의 최소 비용 d(x,y)는 다음과 같이 계산됩니다.
벨만-포드 방정식
=================
d(x, y) = min { c(x, v) + d(v, y) }
v
여기서 v는 x의 모든 이웃 노드
의미: x에서 y까지의 최소 비용은
= x에서 이웃 v까지의 비용 + v에서 y까지의 최소 비용
이 값이 최소인 이웃 v를 통해 이동
4.3 알고리즘 동작 과정
DV 알고리즘 동작
==================
각 노드 x는 다음을 유지:
- c(x,v): 이웃 v까지의 링크 비용
- Dx: x의 거리 벡터 (모든 목적지까지의 추정 비용)
- Dv: 각 이웃 v의 거리 벡터
동작:
1. 초기화: 직접 연결된 이웃은 링크 비용, 나머지는 무한대
2. 이웃으로부터 거리 벡터를 수신하면:
Dx(y) = min { c(x,v) + Dv(y) } (모든 이웃 v에 대해)
3. 자신의 거리 벡터가 변경되면 모든 이웃에게 전송
4. 변화가 없을 때까지 반복
4.4 실행 예시
DV 알고리즘 실행 (3노드 예시)
===============================
토폴로지:
x ---7--- y
| / |
1 / 1
| 2 |
z --------+
초기 거리 벡터:
Dx = [0, 7, 1] (x->x, x->y, x->z)
Dy = [7, 0, 1] (y->x, y->y, y->z)
Dz = [1, 1, 0] (z->x, z->y, z->z)
1단계: 각 노드가 이웃의 DV를 수신하고 갱신
노드 x 갱신:
Dx(y) = min(c(x,y)+Dy(y), c(x,z)+Dz(y))
= min(7+0, 1+1) = 2
Dx(z) = min(c(x,y)+Dy(z), c(x,z)+Dz(z))
= min(7+1, 1+0) = 1
갱신 후 Dx = [0, 2, 1] (x->y가 7에서 2로 변경)
2단계: 변경된 DV를 이웃에게 전파, 더 이상 변화 없으면 종료
5. Count-to-Infinity 문제
5.1 문제 발생 시나리오
DV 알고리즘의 가장 큰 문제는 bad news travels slowly, 즉 링크 비용이 증가할 때 수렴이 매우 느리다는 것입니다.
Count-to-Infinity 예시
========================
토폴로지: x ---4--- y ---1--- z
초기 거리 벡터:
Dy(x) = 4, Dz(x) = 5 (z -> y -> x)
링크 변경: c(x,y) = 4 --> 60
y 갱신: Dy(x) = min(60, 1+Dz(x)) = min(60, 1+5) = 6
(z를 경유하면 6이라고 생각, 하지만 z도 y를 경유!)
z 갱신: Dz(x) = min(1+Dy(x)) = 1+6 = 7
y 갱신: Dy(x) = min(60, 1+7) = 8
z 갱신: Dz(x) = 1+8 = 9
... 계속 1씩 증가하면서 44번 반복 후에야 수렴!
5.2 해결책: Poisoned Reverse
Poisoned Reverse는 라우팅 루프를 방지하는 기법입니다. z가 y를 경유하여 x에 도달한다면, z는 y에게 x까지의 거리를 무한대로 알려줍니다.
Poisoned Reverse 동작
======================
z는 y를 통해 x에 도달 (z -> y -> x)
z가 y에게 알리는 정보:
Dz(x) = 무한대 (실제로는 5이지만 y에게는 무한대로 알림)
이유: z가 y를 경유하므로, y가 z를 경유하는 루프 방지
링크 변경 c(x,y) = 60 발생 시:
y 갱신: Dy(x) = min(60, 1+무한대) = 60
y가 z에게 Dy(x)=60 전달
z 갱신: Dz(x) = min(1+60) = 61
--> 즉시 올바른 값으로 수렴!
5.3 Poisoned Reverse의 한계
Poisoned Reverse는 두 노드 사이의 루프만 방지할 수 있습니다. 3개 이상의 노드가 관여하는 루프에는 효과가 없습니다.
6. LS와 DV 알고리즘 비교
Link-State vs Distance-Vector
================================
항목 | Link-State (LS) | Distance-Vector (DV)
------------------+----------------------+----------------------
정보 범위 | 전체 네트워크 토폴로지 | 이웃의 거리 벡터만
메시지 복잡도 | O(N x E) 메시지 | 수렴까지 가변적
수렴 속도 | O(N^2) 빠름 | 느림 (루프 가능)
견고성 | 각 노드 독립 계산 | 오류가 전파될 수 있음
| (오류 영향 제한적) | (잘못된 DV 전파)
메모리 요구 | 전체 토폴로지 저장 | 이웃 DV만 저장
실제 사용 | OSPF, IS-IS | RIP, BGP (경로 벡터)
6.1 메시지 복잡도
- LS: 각 노드가 링크 상태를 모든 노드에 브로드캐스트. N개 노드, E개 링크에서 O(N x E) 메시지
- DV: 이웃 간에만 교환하지만, 수렴까지의 메시지 수가 불확실
6.2 수렴 속도
- LS: O(N^2) 또는 O(N log N)에 수렴
- DV: 수렴 속도가 불확실하고, count-to-infinity 문제 발생 가능
6.3 견고성 (Robustness)
- LS: 한 노드가 잘못된 링크 비용을 알려도, 다른 노드들은 자체적으로 최단 경로를 계산하므로 영향이 제한적
- DV: 한 노드의 잘못된 거리 벡터가 네트워크 전체로 전파될 수 있음
7. 라우팅 알고리즘의 실제 적용
실제 프로토콜과 알고리즘
==========================
라우팅 프로토콜 | 기반 알고리즘 | 사용 범위
-----------------+--------------+------------------
RIP | DV | 소규모 AS 내부
OSPF | LS | 대규모 AS 내부
IS-IS | LS | ISP 네트워크
BGP | 경로 벡터 | AS 간 (인터넷 전체)
EIGRP | DV 개선 | Cisco 네트워크
8. 핵심 정리
| 개념 | 핵심 내용 |
|---|---|
| Link-State | 전체 토폴로지 기반, 다익스트라 알고리즘 사용 |
| Distance-Vector | 이웃 정보만 사용, 벨만-포드 방정식 기반 |
| 벨만-포드 방정식 | d(x,y) = min over v of c(x,v) + d(v,y) |
| Count-to-infinity | DV에서 링크 비용 증가 시 수렴 지연 문제 |
| Poisoned Reverse | 경유 노드에 무한대 비용을 알려 루프 방지 |
| LS 진동 | 부하 민감 비용 시 경로 진동, 랜덤화로 해결 |
다음 글에서는 이러한 라우팅 알고리즘이 실제 인터넷에서 어떻게 적용되는지, OSPF와 BGP 프로토콜을 통해 알아보겠습니다.
참고 자료
- James F. Kurose, Keith W. Ross, "Computer Networking: A Top-Down Approach", 6th Edition, Chapter 4
- E. W. Dijkstra, "A Note on Two Problems in Connexion with Graphs", 1959
- R. Bellman, "On a Routing Problem", 1958
[Computer Networking] 13. Routing Algorithms: Link-State and Distance-Vector
Routing Algorithms: Link-State and Distance-Vector
Routing algorithms determine the optimal path from a sending host to a receiving host. The key is to model the network as a graph and compute the least-cost path between nodes.
In this post, we cover two representative routing algorithms: the Link-State (LS) algorithm and the Distance-Vector (DV) algorithm, analyzing each one's strengths, weaknesses, and potential issues.
1. Graph Model of a Network
A network is modeled as a weighted graph consisting of nodes (routers) and edges (links).
Network Graph Example
======================
2
(u) -------> (v)
| \ |
1| \5 |3
| \ |
v v v
(x)---(w)---->(y)---->(z)
3 1 2
c(u,v) = 2, c(u,x) = 1, c(u,w) = 5
c(v,y) = 3, c(x,w) = 3, c(w,y) = 1
c(y,z) = 2
Goal: Find the least-cost path from a source node to all other nodes.
2. Classification of Routing Algorithms
Routing Algorithm Classification
==================================
1. By information scope:
- Global: Knows all node information, then computes --> Link-State
- Decentralized: Iterative computation using only neighbor info --> Distance-Vector
2. By operation mode:
- Static: Routes rarely change
- Dynamic: Periodically recalculated as network changes
3. By load sensitivity:
- Load-Sensitive: Reflects link congestion in cost
- Load-Insensitive: Current Internet routing approach
3. Link-State Algorithm (Dijkstra's Algorithm)
3.1 Basic Principle
The Link-State algorithm operates based on complete topology information of the network. Each node broadcasts its link state information to the entire network, and once all nodes have the same information, they compute shortest paths using Dijkstra's algorithm.
3.2 Algorithm Operation
Dijkstra's Algorithm
======================
Initialization:
N' = source node u
D(v) = c(u,v) (cost of directly connected neighbors)
infinity (nodes not directly connected)
Loop:
1. Select node w not in N' with minimum D(w)
2. Add w to N'
3. For each neighbor v of w:
D(v) = min(D(v), D(w) + c(w,v))
4. Repeat until all nodes are in N'
3.3 Execution Example
Running Dijkstra's algorithm from node u on the graph above:
Dijkstra Execution (Source: u)
================================
Step | N' | D(v) | D(w) | D(x) | D(y) | D(z)
-----+-----------+------+------+------+------+------
0 | u | 2 | 5 | 1 | inf | inf
1 | u,x | 2 | 4 | 1 | inf | inf
2 | u,x,v | 2 | 4 | 1 | 5 | inf
3 | u,x,v,w | 2 | 4 | 1 | 5 | inf
4 | u,x,v,w,y | 2 | 4 | 1 | 5 | 7
5 | all nodes | 2 | 4 | 1 | 5 | 7
Shortest path tree:
u -> v: cost 2 (direct)
u -> x: cost 1 (direct)
u -> w: cost 4 (u -> x -> w)
u -> y: cost 5 (u -> v -> y or u -> x -> w -> y)
u -> z: cost 7 (u -> ... -> y -> z)
3.4 Time Complexity
The basic implementation has O(n^2) time complexity, which can be improved to O(n log n) using a priority queue (heap).
3.5 Oscillation Problem
When link costs change based on traffic load, routing can oscillate.
LS Oscillation Problem Example
================================
Time 1: Most traffic flows via A -> B path
--> A -> B link cost increases
Time 2: All nodes switch to A -> C -> D -> B path
--> A -> C link cost increases
Time 3: Switch back to A -> B path (oscillation repeats)
Solution: Randomize routing update timing
4. Distance-Vector Algorithm (Bellman-Ford)
4.1 Basic Principle
The Distance-Vector algorithm operates in a decentralized manner. Each node only sends its distance vector (estimated costs to all destinations) to its neighbors, and updates its own distance vector based on neighbors' information.
4.2 Bellman-Ford Equation
The minimum cost d(x,y) from node x to destination y is computed as follows:
Bellman-Ford Equation
======================
d(x, y) = min { c(x, v) + d(v, y) }
v
where v ranges over all neighbors of x
Meaning: The minimum cost from x to y is
= cost from x to neighbor v + minimum cost from v to y
Travel via the neighbor v that minimizes this value
4.3 Algorithm Operation
DV Algorithm Operation
========================
Each node x maintains:
- c(x,v): link cost to neighbor v
- Dx: distance vector of x (estimated cost to all destinations)
- Dv: distance vector of each neighbor v
Operation:
1. Initialize: link cost for directly connected neighbors, infinity for the rest
2. When receiving a distance vector from a neighbor:
Dx(y) = min { c(x,v) + Dv(y) } (for all neighbors v)
3. If own distance vector changed, send to all neighbors
4. Repeat until no changes
4.4 Execution Example
DV Algorithm Execution (3-node example)
=========================================
Topology:
x ---7--- y
| / |
1 / 1
| 2 |
z --------+
Initial distance vectors:
Dx = [0, 7, 1] (x->x, x->y, x->z)
Dy = [7, 0, 1] (y->x, y->y, y->z)
Dz = [1, 1, 0] (z->x, z->y, z->z)
Step 1: Each node receives neighbors' DV and updates
Node x update:
Dx(y) = min(c(x,y)+Dy(y), c(x,z)+Dz(y))
= min(7+0, 1+1) = 2
Dx(z) = min(c(x,y)+Dy(z), c(x,z)+Dz(z))
= min(7+1, 1+0) = 1
Updated Dx = [0, 2, 1] (x->y changed from 7 to 2)
Step 2: Propagate changed DV to neighbors, terminate when no more changes
5. Count-to-Infinity Problem
5.1 Problem Scenario
The biggest problem with the DV algorithm is that bad news travels slowly -- convergence is very slow when link costs increase.
Count-to-Infinity Example
===========================
Topology: x ---4--- y ---1--- z
Initial distance vectors:
Dy(x) = 4, Dz(x) = 5 (z -> y -> x)
Link change: c(x,y) = 4 --> 60
y update: Dy(x) = min(60, 1+Dz(x)) = min(60, 1+5) = 6
(thinks going via z costs 6, but z also goes via y!)
z update: Dz(x) = min(1+Dy(x)) = 1+6 = 7
y update: Dy(x) = min(60, 1+7) = 8
z update: Dz(x) = 1+8 = 9
... keeps incrementing by 1, converges only after 44 iterations!
5.2 Solution: Poisoned Reverse
Poisoned Reverse is a technique to prevent routing loops. If z reaches x via y, then z tells y that its distance to x is infinity.
Poisoned Reverse Operation
============================
z reaches x via y (z -> y -> x)
Information z tells y:
Dz(x) = infinity (actually 5, but reports infinity to y)
Reason: Since z goes via y, prevent loop where y goes via z
When link change c(x,y) = 60 occurs:
y update: Dy(x) = min(60, 1+infinity) = 60
y sends Dy(x)=60 to z
z update: Dz(x) = min(1+60) = 61
--> Converges to correct value immediately!
5.3 Limitations of Poisoned Reverse
Poisoned Reverse can only prevent loops between two nodes. It is ineffective for loops involving three or more nodes.
6. Comparing LS and DV Algorithms
Link-State vs Distance-Vector
================================
Item | Link-State (LS) | Distance-Vector (DV)
-------------------+-----------------------+------------------------
Information Scope | Full network topology | Only neighbor DVs
Message Complexity | O(N x E) messages | Variable until convergence
Convergence Speed | O(N^2) fast | Slow (loops possible)
Robustness | Independent computation| Errors can propagate
| (limited error impact) | (wrong DV propagation)
Memory Requirement | Store full topology | Store only neighbor DVs
Practical Use | OSPF, IS-IS | RIP, BGP (path vector)
6.1 Message Complexity
- LS: Each node broadcasts link state to all nodes. O(N x E) messages for N nodes and E links
- DV: Exchanged only between neighbors, but total messages until convergence is uncertain
6.2 Convergence Speed
- LS: Converges in O(N^2) or O(N log N)
- DV: Convergence speed is uncertain, count-to-infinity problem possible
6.3 Robustness
- LS: Even if one node advertises incorrect link costs, other nodes compute shortest paths independently, limiting the impact
- DV: An incorrect distance vector from one node can propagate across the entire network
7. Practical Application of Routing Algorithms
Protocols and Algorithms in Practice
======================================
Routing Protocol | Algorithm | Scope
------------------+----------------+------------------
RIP | DV | Small AS interior
OSPF | LS | Large AS interior
IS-IS | LS | ISP networks
BGP | Path Vector | Inter-AS (entire Internet)
EIGRP | Enhanced DV | Cisco networks
8. Key Summary
| Concept | Key Points |
|---|---|
| Link-State | Based on full topology, uses Dijkstra's algorithm |
| Distance-Vector | Uses only neighbor info, based on Bellman-Ford |
| Bellman-Ford Eq. | d(x,y) = min over v of c(x,v) + d(v,y) |
| Count-to-infinity | DV convergence delay when link cost increases |
| Poisoned Reverse | Reports infinity cost to transit node to prevent loops |
| LS Oscillation | Route oscillation with load-sensitive costs, solved by randomization |
In the next post, we will see how these routing algorithms are applied in the real Internet through OSPF and BGP protocols.
References
- James F. Kurose, Keith W. Ross, "Computer Networking: A Top-Down Approach", 6th Edition, Chapter 4
- E. W. Dijkstra, "A Note on Two Problems in Connexion with Graphs", 1959
- R. Bellman, "On a Routing Problem", 1958