MPLS VPN是运营商为企业提供的专线互联服务,通过标签交换和VRF技术实现多租户隔离和高效转发。本文将深入讲解MPLS VPN的核心原理、L3VPN/L2VPN架构,以及华为设备的实战配置。

一、MPLS VPN概述

1.1 MPLS基础

1
2
3
4
5
6
7
8
9
MPLS标签结构 (32位):
┌─────────────────────────────────────────────────────────────┐
│ Label (20bit) │ EXP (3bit) │ S (1bit) │ TTL (8bit) │
└─────────────────────────────────────────────────────────────┘

Label: 标签值 (0-1048575)
EXP: 实验位,用于QoS
S: 栈底标志 (1=栈底)
TTL: 生存时间

1.2 MPLS VPN架构

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
                    MPLS骨干网
┌─────────────────────────────────────────────┐
│ │
│ ┌─────┐ ┌─────┐ ┌─────┐ │
│ │ PE1 │─────────│ P │─────────│ PE2 │ │
│ └──┬──┘ └─────┘ └──┬──┘ │
│ │ │ │
└──────┼───────────────────────────────┼──────┘
│ │
┌────▼────┐ ┌────▼────┐
│ CE1 │ │ CE2 │
│ Site-A │ │ Site-B │
└─────────┘ └─────────┘
VPN-A VPN-A

术语说明:
- CE (Customer Edge): 客户边缘设备
- PE (Provider Edge): 运营商边缘设备
- P (Provider): 运营商核心设备
- VRF (Virtual Routing and Forwarding): 虚拟路由转发

1.3 VPN类型对比

类型 层次 用途 技术
L3VPN 三层 站点互联 BGP/MPLS VPN
L2VPN 二层 二层扩展 VPLS/EVPN
L2VPN 二层 点对点 VPWS/PWE3

二、MPLS L3VPN原理

2.1 核心组件

组件 功能
VRF 虚拟路由表,实现租户隔离
RD (Route Distinguisher) 路由区分符,区分不同VPN的相同路由
RT (Route Target) 路由目标,控制路由导入导出
MP-BGP 多协议BGP,传递VPNv4路由
LDP/RSVP-TE 标签分发协议

2.2 数据转发流程

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
数据包转发过程:

Site-A (10.1.1.0/24) → Site-B (10.2.1.0/24)

1. CE1发送数据包到PE1
[IP: 10.1.1.1 → 10.2.1.1]

2. PE1查VRF路由表,添加VPN标签和传输标签
[传输标签][VPN标签][IP数据包]

3. P设备交换传输标签 (标签交换)
[新传输标签][VPN标签][IP数据包]

4. PE2弹出传输标签,根据VPN标签查VRF
[VPN标签][IP数据包] → [IP数据包]

5. PE2转发到CE2
[IP: 10.1.1.1 → 10.2.1.1]

2.3 控制平面

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
路由传递过程:

1. CE1通告路由给PE1 (OSPF/BGP/静态)
10.1.1.0/24

2. PE1将路由导入VRF,添加RD和RT
RD:100:1 + 10.1.1.0/24 = 100:1:10.1.1.0/24
RT: 100:1 (export)

3. PE1通过MP-BGP通告VPNv4路由给PE2
VPNv4: 100:1:10.1.1.0/24, RT=100:1

4. PE2根据RT导入路由到对应VRF
RT: 100:1 (import) → VRF-A

5. PE2通告路由给CE2
10.1.1.0/24

三、MPLS L3VPN配置实战

3.1 网络拓扑

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
                AS 100 (运营商)
┌─────────────────────────────────────────────────┐
│ │
│ ┌─────┐ ┌─────┐ ┌─────┐ │
│ │ PE1 │──────│ P │──────│ PE2 │ │
│ │1.1.1│ │2.2.2│ │3.3.3│ │
│ └──┬──┘ └─────┘ └──┬──┘ │
│ │ │ │
└──────┼─────────────────────────┼───────────────┘
│ │
┌────▼────┐ ┌────▼────┐
│ CE1 │ │ CE2 │
│ 4.4.4.4 │ │ 5.5.5.5 │
│Site-A │ │Site-B │
│10.1.1.0 │ │10.2.1.0 │
└─────────┘ └─────────┘
VPN-A VPN-A

3.2 P设备配置

P设备配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# P设备基础配置
<P>system-view
[P]sysname P

# Loopback接口
[P]interface LoopBack0
ip address 2.2.2.2 255.255.255.255

# 连接PE1的接口
[P]interface GigabitEthernet0/0/0
ip address 12.1.1.2 255.255.255.0
mpls
mpls ldp

# 连接PE2的接口
[P]interface GigabitEthernet0/0/1
ip address 23.1.1.1 255.255.255.0
mpls
mpls ldp

# OSPF配置 (Underlay)
[P]ospf 1 router-id 2.2.2.2
area 0.0.0.0
network 2.2.2.2 0.0.0.0
network 12.1.1.0 0.0.0.255
network 23.1.1.0 0.0.0.255

# MPLS全局配置
[P]mpls lsr-id 2.2.2.2
[P]mpls
[P]mpls ldp

3.3 PE1设备配置

PE1配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# PE1基础配置
<PE1>system-view
[PE1]sysname PE1

# Loopback接口
[PE1]interface LoopBack0
ip address 1.1.1.1 255.255.255.255

# 连接P的接口
[PE1]interface GigabitEthernet0/0/0
ip address 12.1.1.1 255.255.255.0
mpls
mpls ldp

# OSPF配置 (Underlay)
[PE1]ospf 1 router-id 1.1.1.1
area 0.0.0.0
network 1.1.1.1 0.0.0.0
network 12.1.1.0 0.0.0.255

# MPLS全局配置
[PE1]mpls lsr-id 1.1.1.1
[PE1]mpls
[PE1]mpls ldp

# 创建VPN实例
[PE1]ip vpn-instance VPN-A
ipv4-family
route-distinguisher 100:1
vpn-target 100:1 export-extcommunity
vpn-target 100:1 import-extcommunity

# 连接CE1的接口 (绑定VPN实例)
[PE1]interface GigabitEthernet0/0/1
ip binding vpn-instance VPN-A
ip address 192.168.1.1 255.255.255.0

# PE-CE路由协议 (OSPF)
[PE1]ospf 100 vpn-instance VPN-A
area 0.0.0.0
network 192.168.1.0 0.0.0.255

# 或使用BGP作为PE-CE协议
[PE1]bgp 100
ipv4-family vpn-instance VPN-A
peer 192.168.1.2 as-number 65001
import-route ospf 100

# MP-BGP配置 (VPNv4)
[PE1]bgp 100
peer 3.3.3.3 as-number 100
peer 3.3.3.3 connect-interface LoopBack0

ipv4-family unicast
undo peer 3.3.3.3 enable

ipv4-family vpnv4
peer 3.3.3.3 enable

3.4 PE2设备配置

PE2配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# PE2基础配置
<PE2>system-view
[PE2]sysname PE2

# Loopback接口
[PE2]interface LoopBack0
ip address 3.3.3.3 255.255.255.255

# 连接P的接口
[PE2]interface GigabitEthernet0/0/0
ip address 23.1.1.2 255.255.255.0
mpls
mpls ldp

# OSPF配置 (Underlay)
[PE2]ospf 1 router-id 3.3.3.3
area 0.0.0.0
network 3.3.3.3 0.0.0.0
network 23.1.1.0 0.0.0.255

# MPLS全局配置
[PE2]mpls lsr-id 3.3.3.3
[PE2]mpls
[PE2]mpls ldp

# 创建VPN实例
[PE2]ip vpn-instance VPN-A
ipv4-family
route-distinguisher 100:1
vpn-target 100:1 export-extcommunity
vpn-target 100:1 import-extcommunity

# 连接CE2的接口
[PE2]interface GigabitEthernet0/0/1
ip binding vpn-instance VPN-A
ip address 192.168.2.1 255.255.255.0

# PE-CE路由协议
[PE2]ospf 100 vpn-instance VPN-A
area 0.0.0.0
network 192.168.2.0 0.0.0.255

# MP-BGP配置
[PE2]bgp 100
peer 1.1.1.1 as-number 100
peer 1.1.1.1 connect-interface LoopBack0

ipv4-family unicast
undo peer 1.1.1.1 enable

ipv4-family vpnv4
peer 1.1.1.1 enable

3.5 CE设备配置

CE配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# CE1配置
<CE1>system-view
[CE1]sysname CE1

[CE1]interface LoopBack0
ip address 4.4.4.4 255.255.255.255

[CE1]interface GigabitEthernet0/0/0
ip address 192.168.1.2 255.255.255.0

[CE1]interface GigabitEthernet0/0/1
ip address 10.1.1.1 255.255.255.0

# OSPF配置
[CE1]ospf 1 router-id 4.4.4.4
area 0.0.0.0
network 4.4.4.4 0.0.0.0
network 192.168.1.0 0.0.0.255
network 10.1.1.0 0.0.0.255

# CE2配置
<CE2>system-view
[CE2]sysname CE2

[CE2]interface LoopBack0
ip address 5.5.5.5 255.255.255.255

[CE2]interface GigabitEthernet0/0/0
ip address 192.168.2.2 255.255.255.0

[CE2]interface GigabitEthernet0/0/1
ip address 10.2.1.1 255.255.255.0

# OSPF配置
[CE2]ospf 1 router-id 5.5.5.5
area 0.0.0.0
network 5.5.5.5 0.0.0.0
network 192.168.2.0 0.0.0.255
network 10.2.1.0 0.0.0.255

四、多VPN实例配置

4.1 Hub-Spoke拓扑

Hub-Spoke配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Hub-Spoke拓扑 (总部-分支)
# Hub站点可以访问所有Spoke
# Spoke之间必须经过Hub

# Hub站点PE配置
[PE-Hub]ip vpn-instance VPN-HUB
ipv4-family
route-distinguisher 100:100
vpn-target 100:1 import-extcommunity # 导入所有Spoke路由
vpn-target 100:100 export-extcommunity # 导出Hub路由

# Spoke站点PE配置
[PE-Spoke1]ip vpn-instance VPN-SPOKE1
ipv4-family
route-distinguisher 100:1
vpn-target 100:100 import-extcommunity # 仅导入Hub路由
vpn-target 100:1 export-extcommunity # 导出Spoke路由

[PE-Spoke2]ip vpn-instance VPN-SPOKE2
ipv4-family
route-distinguisher 100:2
vpn-target 100:100 import-extcommunity
vpn-target 100:2 export-extcommunity

4.2 Full-Mesh拓扑

Full-Mesh配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Full-Mesh拓扑 (所有站点互通)
# 所有站点使用相同的RT

# 站点1
[PE1]ip vpn-instance VPN-FULL
ipv4-family
route-distinguisher 100:1
vpn-target 100:100 export-extcommunity
vpn-target 100:100 import-extcommunity

# 站点2
[PE2]ip vpn-instance VPN-FULL
ipv4-family
route-distinguisher 100:2
vpn-target 100:100 export-extcommunity
vpn-target 100:100 import-extcommunity

# 站点3
[PE3]ip vpn-instance VPN-FULL
ipv4-family
route-distinguisher 100:3
vpn-target 100:100 export-extcommunity
vpn-target 100:100 import-extcommunity

4.3 Extranet (跨VPN访问)

Extranet配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# VPN-A和VPN-B需要互访共享服务器

# VPN-A配置
[PE1]ip vpn-instance VPN-A
ipv4-family
route-distinguisher 100:1
vpn-target 100:1 export-extcommunity
vpn-target 100:1 import-extcommunity
vpn-target 100:999 import-extcommunity # 导入共享服务

# VPN-B配置
[PE2]ip vpn-instance VPN-B
ipv4-family
route-distinguisher 100:2
vpn-target 100:2 export-extcommunity
vpn-target 100:2 import-extcommunity
vpn-target 100:999 import-extcommunity # 导入共享服务

# 共享服务VPN配置
[PE3]ip vpn-instance VPN-SHARED
ipv4-family
route-distinguisher 100:999
vpn-target 100:999 export-extcommunity
vpn-target 100:1 import-extcommunity # 导入VPN-A路由
vpn-target 100:2 import-extcommunity # 导入VPN-B路由

五、MPLS L2VPN

5.1 VPWS (点对点)

VPWS配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# VPWS (Virtual Private Wire Service)
# 点对点二层VPN

# PE1配置
[PE1]interface GigabitEthernet0/0/1
description To-CE1
l2 binding vsi vpws1

[PE1]vsi vpws1 static
pwsignal ldp
vsi-id 100
peer 3.3.3.3

# PE2配置
[PE2]interface GigabitEthernet0/0/1
description To-CE2
l2 binding vsi vpws1

[PE2]vsi vpws1 static
pwsignal ldp
vsi-id 100
peer 1.1.1.1

5.2 VPLS (多点)

VPLS配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# VPLS (Virtual Private LAN Service)
# 多点二层VPN

# PE1配置
[PE1]vsi vpls1 static
pwsignal ldp
vsi-id 200
peer 3.3.3.3
peer 4.4.4.4

[PE1]interface GigabitEthernet0/0/1
l2 binding vsi vpls1

# PE2配置
[PE2]vsi vpls1 static
pwsignal ldp
vsi-id 200
peer 1.1.1.1
peer 4.4.4.4

[PE2]interface GigabitEthernet0/0/1
l2 binding vsi vpls1

# PE3配置
[PE3]vsi vpls1 static
pwsignal ldp
vsi-id 200
peer 1.1.1.1
peer 3.3.3.3

[PE3]interface GigabitEthernet0/0/1
l2 binding vsi vpls1

六、QoS与流量工程

6.1 MPLS QoS

QoS配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 流量分类
[PE1]traffic classifier voice
if-match dscp ef

[PE1]traffic classifier video
if-match dscp af41

[PE1]traffic classifier data
if-match dscp af21

# 流量行为
[PE1]traffic behavior voice-behavior
remark mpls-exp 5

[PE1]traffic behavior video-behavior
remark mpls-exp 4

[PE1]traffic behavior data-behavior
remark mpls-exp 2

# 流量策略
[PE1]traffic policy mpls-qos
classifier voice behavior voice-behavior
classifier video behavior video-behavior
classifier data behavior data-behavior

# 应用到接口
[PE1]interface GigabitEthernet0/0/0
traffic-policy mpls-qos outbound

6.2 MPLS TE

TE配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# MPLS流量工程配置

# 全局配置
[PE1]mpls
[PE1]mpls te
[PE1]mpls rsvp-te

# 接口配置
[PE1]interface GigabitEthernet0/0/0
mpls
mpls te
mpls rsvp-te
mpls te bandwidth max-reservable-bandwidth 1000000
mpls te bandwidth bc0 800000

# OSPF TE扩展
[PE1]ospf 1
opaque-capability enable
area 0.0.0.0
mpls-te enable

# 创建TE隧道
[PE1]interface Tunnel1
ip address unnumbered interface LoopBack0
tunnel-protocol mpls te
destination 3.3.3.3
mpls te tunnel-id 1
mpls te bandwidth ct0 100000
mpls te path explicit-path path1
mpls te commit

# 显式路径
[PE1]explicit-path path1
next hop 12.1.1.2
next hop 23.1.1.2

七、故障排查

7.1 常用查看命令

排查命令
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# MPLS基础
display mpls lsp
display mpls ldp session
display mpls ldp peer
display mpls ldp interface

# VPN实例
display ip vpn-instance
display ip vpn-instance VPN-A
display ip routing-table vpn-instance VPN-A

# BGP VPNv4
display bgp vpnv4 all peer
display bgp vpnv4 all routing-table
display bgp vpnv4 vpn-instance VPN-A routing-table

# 标签信息
display mpls lsp verbose
display mpls ldp lsp

# L2VPN
display vsi
display vsi vpws1 verbose
display pw all

# 流量统计
display interface GigabitEthernet0/0/0 statistics
display mpls te tunnel-interface

7.2 常见问题排查

故障排查
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
问题1: VPN路由不通
排查步骤:
1. 检查VRF配置
display ip vpn-instance VPN-A

2. 检查RT配置
display ip vpn-instance VPN-A verbose

3. 检查BGP邻居
display bgp vpnv4 all peer

4. 检查VPNv4路由
display bgp vpnv4 all routing-table

5. 检查MPLS LSP
display mpls lsp

问题2: MPLS标签不分配
排查步骤:
1. 检查LDP会话
display mpls ldp session

2. 检查LDP邻居
display mpls ldp peer

3. 检查接口MPLS配置
display mpls ldp interface

4. 检查IGP路由
display ip routing-table

问题3: PE-CE路由不学习
排查步骤:
1. 检查PE-CE接口状态
display interface GigabitEthernet0/0/1

2. 检查PE-CE路由协议
display ospf peer vpn-instance VPN-A

3. 检查路由导入
display bgp vpnv4 vpn-instance VPN-A routing-table

八、最佳实践

8.1 设计建议

维度 建议
RD规划 使用PE Loopback:VPN-ID格式
RT规划 根据拓扑需求设计导入导出
PE-CE协议 优先使用BGP,便于策略控制
冗余设计 双PE接入,多路径负载
QoS 端到端QoS策略一致

8.2 部署检查清单

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
□ Underlay网络
□ IGP邻居建立
□ Loopback可达
□ MPLS LDP会话

□ VPN配置
□ VRF创建
□ RD/RT配置
□ 接口绑定VRF

□ BGP配置
□ MP-BGP邻居
□ VPNv4地址族
□ 路由通告

□ PE-CE配置
□ 路由协议配置
□ 路由导入导出

□ 验证测试
□ VPN路由学习
□ 端到端连通性
□ QoS策略生效

九、总结

MPLS VPN是企业广域网互联的核心技术,通过标签交换和VRF实现高效、安全的多租户网络。关键要点:

  1. 理解架构:CE-PE-P-PE-CE的层次结构
  2. 掌握RD/RT:RD区分路由,RT控制导入导出
  3. 熟悉MP-BGP:VPNv4路由传递的核心
  4. 灵活拓扑:Full-Mesh、Hub-Spoke、Extranet
  5. QoS保障:端到端的服务质量

MPLS VPN虽然正在被SD-WAN等新技术补充,但在运营商网络中仍是主流方案。