MPLS技术详解3:LDP实验与配置实践
本文详细介绍了MPLS LDP的实验配置与故障排除。内容从启用分布式CEF开始,逐步深入到LDP的全局配置、Router ID设置及Graceful-Restart(平滑重启)机制及其计时器。重点探讨了IGP(OSPF)与LDP的集成,包括LDP自动配置和LDP-IGP同步机制,并通过日志分析了同步失败的常见原因。此外,文档还全面讲解了LDP认证的多种方式(如面向邻居、全局、Fallback、Rollover)及会话保护机制,并触及了选择性标签分配,是理解和实践MPLS LDP的实用指南。
1. 启用CEF
- 启用CEF,它是MPLS实现的前提。Distributed分布式,是将包交换的责任从主CPU到线卡的转发引擎(通常是ASIC或是NPU)上。
- 通过查看CEF的Summary来查看是否启用。
R4(config)#ip cef distributed # 查看是否启用CEF
R4# show ip cef summary
IPv4 CEF is enabled for distributed and running
VRF Default31 prefixes (31/0 fwd/non-fwd)Table id 0x0Database epoch: 2 (31 entries at this epoch)# 查看CEF表的细节
R4#show ip cef
Prefix Next Hop Interface
0.0.0.0/0 no route
0.0.0.0/8 drop
0.0.0.0/32 receive
1.1.1.1/32 172.16.0.1 GigabitEthernet1# 查看目的地址的表项
R4# show ip cef 1.1.1.3
1.1.1.3/32nexthop 172.16.0.1 GigabitEthernet1nexthop 172.16.0.9 GigabitEthernet2# 查看前缀的表项,我喜欢加longer-prefixes的展示格式
R4# show ip cef 1.1.1.3/32 longer-prefixes
Prefix Next Hop Interface
1.1.1.3/32 172.16.0.1 GigabitEthernet1172.16.0.9 GigabitEthernet2
2. 启用LDP
- 全局启用LDP作为MPLS的标签分发协议。
- 设置LDP的RID为环回地址。
- 设置LDP的Graceful-Restart
- 接口下启用MPLS转发功能。
- 查看邻居和邻居发现的信息。
# 全局启用LDP作为MPLS的标签分发协议
R4(config)#mpls label protocol ldp
# 防止自己或对等体的LDP进程重启导致的丢包
R4(config)#mpls ldp graceful-restart
# 使用逻辑接口是为了LDP会话的稳定性
R4(config)#mpls ldp router-id loopback 0# 接口下启用MPLS转发功能
R4(config)#int gi1
R4(config-if)#mpls ip# 查看启用了MPLS的接口
R4#show mpls interfaces
Interface IP Tunnel BGP Static Operational
GigabitEthernet1 Yes (ldp) No No No Yes
GigabitEthernet2 Yes (ldp) No No No Yes # 查看LDP的邻居
R1#show mpls ldp neighbor Peer LDP Ident: 1.1.1.4:0; Local LDP Ident 1.1.1.1:0TCP connection: 1.1.1.4.17404 - 1.1.1.1.646State: Oper; Msgs sent/rcvd: 43/43; DownstreamUp time: 00:22:35LDP discovery sources:GigabitEthernet1, Src IP addr: 172.16.0.2Addresses bound to peer LDP Ident:172.16.0.2 172.16.0.10 1.1.1.4 # 查看LDP发现的状态
R1#show mpls ldp discovery Local LDP Identifier:1.1.1.1:0Discovery Sources:Interfaces:GigabitEthernet1 (ldp): xmit/recvLDP Id: 1.1.1.4:0GigabitEthernet2 (ldp): xmitGigabitEthernet3 (ldp): xmit
2.1 平滑重启
Graceful-Restart是在LDP控制层面重启时,依然保持从对等体学到的标签映射,数据层面依然依据现有的LFIB进行数据的转发。
平滑重启有三个计时器:
- 最长恢复时间计时器:路由器预期恢复LDP状态和会话的时间,也是要求对等体等待的时间。
- 转发状态保持计时器:对等体在恢复LDP会话前维持转发状态的时间。
- 邻居保活计时器:对等体保留LDP邻居记录的时间。
R4(config)#mpls ldp graceful-restart timers ?forwarding-holding Forwarding State Holding timemax-recovery Max-Recovery timeneighbor-liveness Neighbor-Liveness time# 查看这平滑重启计时器的默认值
R4#show mpls ldp graceful-restart
LDP Graceful Restart is enabled
Neighbor Liveness Timer: 120 seconds
Max Recovery Time: 120 seconds
Forwarding State Holding Time: 600 seconds
Down Neighbor Database (0 records):
Graceful Restart-enabled Sessions:VRF default:Peer LDP Ident: 1.1.1.1:0, State: estab
3. IGP下关联MPLS
3.1 IGP自动配置LDP
路由协议(OSPF,IS-IS)下为运行了该路由协议的接口自动开启MPLS转发功能。如果某些接口不需要自动配置,可以手动禁用。
R1(config)#router ospf 1
R1(config-router)#mpls ldp autoconfig# 查看MPLS接口的细节可以看到是通过接口配置还是IGP配置
R1#show mpls interfaces detail
Interface GigabitEthernet1:IP labeling enabled (ldp) :IGP configMTU = 1500
R4#show mpls interfaces detail
Interface GigabitEthernet1:IP labeling enabled (ldp) :Interface configMTU = 1500# 在启用OSPF的LDP自动配置后,禁用此配置到某一个接口
R1(config-if)#no mpls ldp igp autoconfig
3.2 IGP和LDP同步
路由协议(OSPF,IS-IS,EIGRP)下启用IGP和LDP的同步功能。
正常情况下,接口起来后,会先形成OSPF邻居关系,然后建立LDP会话并开始交换标签映射消息。在OSPF邻居起来了,但是LDP的标签交换并没有结束,可能会出现路由表里有路由却没有标签的情况。在这种情况下,MPLS的流量会被迫改为IP转发,并被P路由器丢弃,因为P路由器并没有启用BGP。
保证这条链路不被使用的机制是,在LDP没有完成标签交换之前,IGP通告这条链路的LSA时会将Metric设置成最大。可以手动调整等待LDP的时间。
- 未设置holddown time,IGP会无限等待LDP同步结束。
- 设置了holddown time,会经过设置的时间才会通告IGP标签交换结束。
R1(config)#router ospf 1
R1(config-router)#mpls ldp syncR2#show mpls ldp igp sync all GigabitEthernet1:LDP configured; LDP-IGP Synchronization enabled.Sync status: sync achieved; peer reachable.Sync delay time: 0 seconds (0 seconds left)IGP holddown time: infinite.Peer LDP Ident: 1.1.1.4:0 (GR)IGP enabled: OSPF 1# holddown的时间单位是ms
R2(config)#mpls ldp igp sync holddown ?<1-2147483647> Hold down time in millisecondsR2(config)#mpls ldp igp sync holddown 12000
R2#show mpls ldp igp sync all GigabitEthernet1:LDP configured; LDP-IGP Synchronization enabled.Sync status: sync achieved; peer reachable.Sync delay time: 0 seconds (0 seconds left)IGP holddown time: 12000 milliseconds.Peer LDP Ident: 1.1.1.4:0 (GR)IGP enabled: OSPF 1# 从Log里可以看出来LDP的邻居起来以后,IGP应该是会等待LDP,但是模拟器的原因导致功能失败了。
*Oct 18 06:58:03.065: %LINK-3-UPDOWN: Interface GigabitEthernet1, changed state to up
*Oct 18 06:58:03.220: %LDP-5-NBRCHG: LDP Neighbor 1.1.1.4:0 (1) is UP
*Oct 18 06:58:03.221: %LDP-3-ISYNC: Failed to associate interface Gi1 with neighbor 1.1.1.4:0
*Oct 18 06:58:04.128: %LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet1, changed state to up
*Oct 18 06:58:12.397: %OSPF-5-ADJCHG: Process 1, Nbr 1.1.1.4 on GigabitEthernet1 from LOADING to FULL,
4. 认证
LDP没有原生的认证机制,使用TCP的认证来建立TCP会话。
4.1 面向邻居配置认证
- 如果对等体之间的TCP连接建立来了,再添加密码,则TCP连接不会断。
- 断开一下接口,再重新建立TCP连接,则会提示对端没有配置密码。
- 使用哪个地址建立的TCP连接,就选neighbor谁来设置密码。
R1(config)#mpls ldp neighbor 1.1.1.4 password cisco123R1#show mpls ldp neighbor detail Peer LDP Ident: 1.1.1.4:0; Local LDP Ident 1.1.1.1:0TCP connection: 1.1.1.4.17404 - 1.1.1.1.646Password: not required, none, in useState: Oper; Msgs sent/rcvd: 200/199; Downstream; Last TIB rev sent 33Up time: 02:38:45; UID: 2; Peer Id 1LDP discovery sources:GigabitEthernet1; Src IP addr: 172.16.0.2 holdtime: 15000 ms, hello interval: 5000 ms# 接口shut和no shut之后,会有下面的日志信息
*Oct 18 07:59:22.990: %TCP-6-BADAUTH: No MD5 digest from 1.1.1.4(26569) to 1.1.1.1(646) tableid - 0
如果R1对R4设置了LDP密码,而R4没有设置密码的情况下。
- R1的接口,物理和协议都是Up的,OSPF接口也是Up的。
- R4的接口,物理和协议都是Up的,OSPF接口是Down的,报错是等待LDP。
通过查看TCP连接的信息可以看到R1没有显示TCP连接的信息,因为R4的LDP RID更大,由R4发起向对象646端口的TCP连接。因此,可以看见R4有一条TCP连接的记录,它发出的SYN没有收确认信息,所以就卡在SYNSENT的状态。而R1在收到对方尝试TCP连接的时候需要检查密码,而R4没有设置密码,因此R1直接丢弃TCP的请求,R1处就没有显示TCP连接。
当两端的密码都配上之后,TCP的连接就建立来了。查看LDP邻居详情可以看到TCP连接后面有MD5 on的标识。
R1#show ip ospf interface gi1
GigabitEthernet1 is up, line protocol is up Internet Address 172.16.0.1/30, Interface ID 7, Area 0Attached via Network StatementProcess ID 1, Router ID 1.1.1.1, Network Type POINT_TO_POINT, Cost: 1Topology-MTID Cost Disabled Shutdown Topology Name0 1 no no BasePrefix-suppression is enabledTransmit Delay is 1 sec, State POINT_TO_POINTTimer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5oob-resync timeout 40Hello due in 00:00:02Neighbor Count is 0, Adjacent neighbor count is 0 Suppress hello for 0 neighbor(s)R4#show ip ospf interface gi1
GigabitEthernet1 is up, line protocol is up Internet Address 172.16.0.2/30, Interface ID 7, Area 0Attached via Network StatementProcess ID 1, Router ID 1.1.1.4, Network Type POINT_TO_POINT, Cost: 1Topology-MTID Cost Disabled Shutdown Topology Name0 1 no no BasePrefix-suppression is enabledTransmit Delay is 1 sec, State DOWN (waiting for LDP)Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5oob-resync timeout 40# 发现TCP连接是由R4请求的,但是没有建立起来。R1是被动的,所以没有TCP连接的记录。
R1#show tcp brief
TCB Local Address Foreign Address (state)
7F65C0211000 1.1.1.1.646 1.1.1.3.31155 ESTABR4#show tcp brief
TCB Local Address Foreign Address (state)
7F7E245641F8 1.1.1.4.52033 1.1.1.2.646 ESTAB
7F7E2D2EA088 1.1.1.4.39382 1.1.1.1.646 SYNSENT# 当两端都配置密码之后,可以看到TCP连接后面显示MD5 on。
R4#show mpls ldp neighbor gigabitEthernet 1 detail Peer LDP Ident: 1.1.1.1:0; Local LDP Ident 1.1.1.4:0TCP connection: 1.1.1.1.646 - 1.1.1.4.33494; MD5 on# 查看LDP的邻居密码使用情况。R4的Password后面有neighbor,R1的是none。
R1#show mpls ldp neighbor password current Peer LDP Ident: 1.1.1.3:0; Local LDP Ident 1.1.1.1:0TCP connection: 1.1.1.3.31155 - 1.1.1.1.646Password: not required, none, in useState: Oper; Msgs sent/rcvd: 238/234Peer LDP Ident: 1.1.1.4:0; Local LDP Ident 1.1.1.1:0TCP connection: 1.1.1.4.41088 - 1.1.1.1.646Password: not required, neighbor, in useState: Oper; Msgs sent/rcvd: 43/46
4.2 全局配置
- Required: 全局设置LDP认证,默认是对所有对等体要求认证,也可以后挂ACL来选择需要认证的对等体。
- Option: 通过Option选项可以对不同的对等体使用不同的密码。
- Fallback:如果没有对对等体明确配置密码,则使用这个默认的密码。
- Rollover:在需要更新密码的时候,如果直接更新密码,这LPD的会话会断开。通过Rollover来同时设置主(旧密码)和从(新密码)两个密码,并设置切换的时间周期。这周期内,会接受2个密码。周期结束后,新密码变成主密码。旧密码不在被接受了。这保证了密码更新的平滑进行。
R2(config)#mpls ldp password ?fallback Specifies a fallback password will followoption LDP password optionsrequired MD5 password is required for the peerrollover LDP password rollover parameters# 匹配R3的LDP RID
R2#show run | s ip access-list
ip access-list standard 110 permit 1.1.1.3# 对R3使用认证,但是还没有配置密码,有如下的日志信息。
R2(config)#mpls ldp password required for 1 *Oct 18 10:11:59.401: %LDP-5-NBRCHG: LDP Neighbor 1.1.1.3:0 (0) is DOWN (Session MD5 password changed)
*Oct 18 10:12:01.817: %LDP-4-PWD: MD5 protection is required for peer 1.1.1.3:0, no password configured# 为ACL 1的LDP对等体设置密码,这时日志改为没有从对端收到MD5摘要
R2(config)#mpls ldp password option 10 for 1 cisco123
*Oct 18 10:14:24.908: %TCP-6-BADAUTH: No MD5 digest from 1.1.1.3(18036) to 1.1.1.2(646) tableid - 0# 对端直接对邻居设置密码
R3(config)#mpls ldp neighbor 1.1.1.2 password cisco123# 通过全局设置的方式,可以看到对R3的Password要求是required, option 10, in use。
R2#show mpls ldp neighbor password Peer LDP Ident: 1.1.1.4:0; Local LDP Ident 1.1.1.2:0TCP connection: 1.1.1.4.17998 - 1.1.1.2.646Password: not required, none, in useState: Oper; Msgs sent/rcvd: 49/49Peer LDP Ident: 1.1.1.3:0; Local LDP Ident 1.1.1.2:0TCP connection: 1.1.1.3.15477 - 1.1.1.2.646Password: required, option 10, in useState: Oper; Msgs sent/rcvd: 20/19
4.3 Keychain模式
在更新密码时,除了使用4.2的Rollover模式外。还可以使用跟OSPF一样的Keychain模式,通过在一个Keychain下设置不同的key和不同的生效和接收时间来保持密码更新的平滑进行。
# keychain的配置参考OSPF协议的介绍
R2(config)#mpls ldp password option 20 for 1 key-chain ldp-pwd
5. 会话保护机制
LDP对等体之间通过Hello来进行对等体的发现,Hello消息是发送到直连链路上的组播地址上,这也被称为Link Hello。如果LDP对等体不是直连的,则需要通过Targeted Hello,单播发送到给对等体。
在未启用LDP的会话保护机制的时候,如果LDP对等体之间的链路故障,则LDP会话对断开,所有从对等体学到的标签映射都会被清除。启用了会话保护机制后,会额外使用Targeted Hello建立一个新的Hello邻接。当直连链路故障后,由于IP可达,Targeted Hello邻接没有收到影响,因此LDP的会话没有断开。
启用了会话保护后,除了Link Hello外增加了Targeted Hello的邻接。在本地看,都是自己是主动,对端是被动,收发的状态也都是有发有收。
# 没有开启会话保护功能前,发现是通过直连链路。
R4#show mpls ldp discovery Local LDP Identifier:1.1.1.4:0Discovery Sources:Interfaces:GigabitEthernet1 (ldp): xmit/recvLDP Id: 1.1.1.1:0GigabitEthernet2 (ldp): xmit/recvLDP Id: 1.1.1.2:0# 配置会话保护
R4(config)#mpls ldp session protection # 除了Link Hello外,还显示了Targeted Hello。
R4#show mpls ldp discovery Local LDP Identifier:1.1.1.4:0Discovery Sources:Interfaces:GigabitEthernet1 (ldp): xmit/recvLDP Id: 1.1.1.1:0GigabitEthernet2 (ldp): xmit/recvLDP Id: 1.1.1.2:0Targeted Hellos:1.1.1.4 -> 1.1.1.2 (ldp): active/passive, xmit/recvLDP Id: 1.1.1.2:01.1.1.4 -> 1.1.1.1 (ldp): active/passive, xmit/recvLDP Id: 1.1.1.1:0
当到R1的直连链路断掉后,Link Hello显示已经没有了,Targeted Hello显示依然在。因为在邻居状态里,LDP发现的选项里减少了直连链路的选项。
R4#show mpls ldp discovery Local LDP Identifier:1.1.1.4:0Discovery Sources:Interfaces:GigabitEthernet2 (ldp): xmit/recvLDP Id: 1.1.1.2:0Targeted Hellos:1.1.1.4 -> 1.1.1.2 (ldp): active/passive, xmit/recvLDP Id: 1.1.1.2:01.1.1.4 -> 1.1.1.1 (ldp): active/passive, xmit/recvLDP Id: 1.1.1.1:0R4#show mpls ldp neighbor detail Peer LDP Ident: 1.1.1.2:0; Local LDP Ident 1.1.1.4:0LDP discovery sources:GigabitEthernet2; Src IP addr: 172.16.0.9 holdtime: 15000 ms, hello interval: 5000 msTargeted Hello 1.1.1.4 -> 1.1.1.2, active, passive;holdtime: infinite, hello interval: 10000 msPeer LDP Ident: 1.1.1.1:0; Local LDP Ident 1.1.1.4:0LDP discovery sources:Targeted Hello 1.1.1.4 -> 1.1.1.1, active, passive;holdtime: infinite, hello interval: 10000 ms
默认的保护时间是永久,可以手动设置保护的时间。当链路故障时,会话保护机制启用,计时器打开。计时器超时后,将断开会话连接。
R4(config)#mpls ldp session protection duration 30# 没有故障的时候
R4#show mpls ldp neighbor detail Peer LDP Ident: 1.1.1.1:0; Local LDP Ident 1.1.1.4:0LDP Session Protection enabled, state: Readyduration: 30 seconds# 链路故障后,状态从Ready变成Protecting,计时器开始倒计时
*Oct 18 09:36:51.786: %LDP-5-SP: 1.1.1.1:0: session hold up initiatedR4#show mpls ldp neighbor detail Peer LDP Ident: 1.1.1.1:0; Local LDP Ident 1.1.1.4:0LDP Session Protection enabled, state: Protectingduration: 30 secondsholdup time remaining: 6 seconds# 计时器超时后,收到日志消息,会话保护机制关闭了远程会话。
*Oct 18 09:37:22.057: %LDP-5-NBRCHG: LDP Neighbor 1.1.1.1:0 (0) is DOWN (Session Protection disabled targeted session)
除了设置会话保护生效的时间外,还可以设置为哪个邻居设置会话保护,默认是所有邻居。通过ACL来设置要保护的邻居,没有匹配到的邻居,则不会开启会话保护。
# 为ACL 1抓取的邻居设置会话保护
R4#show run | s ip access-list
ip access-list standard 110 permit 1.1.1.1 log
R4(config)#mpls ldp session protection for 1 duration 30# 没有被保护的对等体在Discovery的选项里就只有一个源。
R4#show mpls ldp neighbor brief
Peer LDP id Uptime NSR GR Discovery Address Labels
----------- ------ --- -- --------- ------- ------
1.1.1.1:0 00:06:54 N Y 2 4 15
1.1.1.2:0 00:00:12 N Y 1 4 16
6. 选择性分配标签
LDP默认为RIB里所有的前缀分配标签并通告给其他对等体。
# Area 1没有开启OSPF的prefix-suppression,所以还有链路的前缀
R2#show mpls ldp bindings lib entry: 172.16.1.0/30, rev 26local binding: label: 26remote binding: lsr: 1.1.1.4:0, label: 26remote binding: lsr: 1.1.1.3:0, label: 26lib entry: 172.16.1.8/29, rev 28local binding: label: 27remote binding: lsr: 1.1.1.4:0, label: 27remote binding: lsr: 1.1.1.3:0, label: 27
可以通过prefix-list来指定为哪些前缀分配标签,有用的标签大部分是路由的下一跳的,也可能是PE的BGP的下一跳。也可以指定host-routes来只给/32的前缀分配标签。
R1(config)#mpls ldp label
R1(config-ldp-lbl)#allocate global ?host-routes allocate local label for host routes onlyprefix-list Specify a prefix list for local label filtering<cr> <cr># 非主机路由已经没有本地标签了。
R2#show mpls ldp bindings lib entry: 172.16.1.0/30, rev 39no local bindingremote binding: lsr: 1.1.1.3:0, label: 26remote binding: lsr: 1.1.1.4:0, label: 26lib entry: 172.16.1.8/29, rev 40no local bindingremote binding: lsr: 1.1.1.3:0, label: 27remote binding: lsr: 1.1.1.4:0, label: 27R1#show mpls forwarding-table 172.16.1.8 29
Local Outgoing Prefix Bytes Label Outgoing Next Hop
Label Label or Tunnel Id Switched interface
None No Label 172.16.1.8/29 0 Gi3 172.16.1.2
📚 延伸阅读
更多内容持续更新于我的博客:https://www.zenseek.site