MPLS 多协议标签交换(Multiprotocol Label Switching)
LDP 标签分发协议(Label Distribution Protocol)
MPLS初衷:基于标签转发,提速。
MPLS应用:MPLS VPN ; MPLS TE流量工程traffic engine
MPLS的工作过程
当控制层面使用路由协议传递路由条目后,路由器上使用LDP/TDP为本地FIB表中每一条存在的路由条目均分配一个标签号,装载于LIB表中,同时传递给邻居,LIB中还记录邻居传递到本地标签号;之后路由器基于本地的FIB和LIB表生成LFIB(标签号的最佳对应路径)
数据层面工作时,第一跳路由器负责标签的impose,中间路由器基于标签号转发流量,进行标签号的替换,最后一跳路由器负责标签的pop。
入标签号为本地分配的标签号,出标签号为下一跳(下游)分配的标签号;存在上下游路由器的概念,基于数据层面定义
配置步骤
运行IGP
启用CEF(cisco设备默认开启CEF)
在接口上启用MPLS
物理接口启用MPLS,在标签号所有需要经过的接口上配置

拓扑说明: R1 R2 R3 R4 直连,底层IGP配置OSPF全网互通,R4上配置一个末节网络LO1 100.0.0.1/24。全网配置MPLS LDP协议实现标签转发。
R1配置
hostname R1
interface Loopback0
ip address 1.1.1.1 255.255.255.255
interface GigabitEthernet0/0
ip address 12.0.0.1 255.255.255.0
router ospf 110
router-id 1.1.1.1
network 1.1.1.1 0.0.0.0 area 0
network 12.0.0.1 0.0.0.0 area 0
//基础配置接口IP,OSPF协议互通
ip cef
mpls ip
mpls label protocol ldp
mpls label range 100 10000
mpls ldp router-id Loopback0 force
//开启IP CEF 和 MPLS IP(默认开启),配置标签转发协议为LDP,标签范围和LDP的routerID为lo0
interface GigabitEthernet0/0
mpls ip
//接口开启MPLS IP
R2配置
hostname R2
ip cef
mpls ip
mpls label range 100 10000
mpls label protocol ldp
mpls ldp router-id Loopback0 force
interface Loopback0
ip address 2.2.2.2 255.255.255.255
interface GigabitEthernet0/0
ip address 12.0.0.2 255.255.255.0
mpls ip
interface GigabitEthernet0/1
ip address 23.0.0.2 255.255.255.0
mpls ip
router ospf 110
router-id 2.2.2.2
network 2.2.2.2 0.0.0.0 area 0
network 12.0.0.2 0.0.0.0 area 0
network 23.0.0.2 0.0.0.0 area 0
R3配置
hostname R3
ip cef
mpls ip
mpls label range 100 10000
mpls label protocol ldp
mpls ldp router-id Loopback0 force
interface Loopback0
ip address 3.3.3.3 255.255.255.255
interface GigabitEthernet0/0
ip address 34.0.0.3 255.255.255.0
mpls ip
interface GigabitEthernet0/1
ip address 23.0.0.3 255.255.255.0
mpls ip
router ospf 110
router-id 3.3.3.3
network 3.3.3.3 0.0.0.0 area 0
network 23.0.0.3 0.0.0.0 area 0
network 34.0.0.3 0.0.0.0 area 0
R4 配置
hostname R4
ip cef
mpls ip
mpls label range 100 10000
mpls label protocol ldp
mpls ldp router-id Loopback0 force
interface Loopback0
ip address 4.4.4.4 255.255.255.255
interface Loopback1
ip address 100.0.0.1 255.255.255.0
ip ospf network point-to-point
//此处注意修改接口网络类型,否则ospf会根据规则默认宣告环回口路由为32位。
//如不修改,R1R2R3上不会有24位的100段标签,在R3会弹出所有标签,在有多层标签的场景下会出现故障。
interface GigabitEthernet0/0
ip address 34.0.0.4 255.255.255.0
mpls ip
router ospf 110
router-id 4.4.4.4
network 4.4.4.4 0.0.0.0 area 0
network 34.0.0.4 0.0.0.0 area 0
network 100.0.0.1 0.0.0.0 area 0
配置完成后 在各设备上查看MPLS相关配置结果
show mpls ldp neighbor 查看MPLS LDP 拓扑表

show mpls ldp bindings 查看MPLS LIB表

show mpls forwarding-table 查看MPLS LFIB表

show mpls ip binding 100.0.0.0 24 detail
查看具体路由的明细信息
