MPLS配置
MPLS的配置
- IP可达— 使用路由协议全网可达
- 配置MPLS – LDP
[r2]mpls lsr-id 2.2.2.2 // 必须先定义mpls的router-id,要为本地设备的真实ip地址,且邻居可达,因为该地址将用于建立TCP会话,建议使用环回地址
[r2]mpls 再开启mpls协议
[r2-mpls]mpls ldp 再激活LDP协议
[r2-mpls-ldp]q
之后需要在所有标签经过的接口上开启协议
[r2]interface GigabitEthernet 0/0/1
[r2-GigabitEthernet0/0/1]mpls 先开启MPLS
[r2-GigabitEthernet0/0/1]mpls ldp 再激活LDP协议
当启动配置完成后,邻居间使用UDP报文组播收发hello包;之后基于hello包中的router-id地址进行TCP会话的建立;
[r3]display tcp status
TCPCB Tid/Soid Local Add:port Foreign Add:port VPNID State
b4cf3d64 167/6 3.3.3.3:646 4.4.4.4:50858 0 Established
b4cf3adc 167/3 3.3.3.3:50806 2.2.2.2:646 0 Established
当tcp会话建立后,邻居间基于TCP会话再建立邻居关系,生成邻居表:
[r3]display mpls ldp peer
再然后基于本地的FIB表,默认华为仅针对32位的主机路由生成标签号;存储于LIB表中,之后邻居间共享LIB表;
[r3]display fib 查看FIB表
[r4]display mpls ldp lsp 查看LIB表,装载本地和邻居为各条路由分配的标签号
最后路由器将LIB和FIB集合,生成最佳路径的标签转发规则—LFIB
[r4]display mpls lsp 查看LFIB表
注:默认华为仅针对32位主机路由分配标签
[r3]mpls
[r3-mpls]lsp-trigger all 开启功能,将针对fib表中所有路由进行标签号的分配
使用mpls解决BGP的路由黑洞
MPLS协议并不会为通过BGP协议学习的路由条目分配标签号;
而是在访问这些BGP路由目标网段时,在流量中压入到达这些网段的BGP下一跳设备地址的标签号;
例:R2从BGP邻居5.5.5.5 学习到6.6.6.0 网段的路由;R2在访问6.6.6.0 时,将在数据包中压入到达5.5.5.5ip地址的标签号,来穿越中间没有运行BGP协议的设备;实现打破路由黑洞;
注:华为设备默认不为BGP协议执行下一跳标签机制,cisco默认执行;
华为设备需要开启 route recursive-lookup tunnel 路由基于隧道进行递归查找,配置MPLS VPN时,进入vpn-instance时默认开启。
MPLS VPN
- CE将私有路由传递到PE端
- PE端在收到不同CE发送过来的相同网段路由时,使用RD值进行区分—格式X:X 32位
- PE端将附上RD的私有路由不能直接装载于本地公有路由表中,需要放置到对应的VRF(虚拟路由转发)空间内;之后再路由付RT值,用于传递到对端PE设备,对端区分信息;
VPNV4路由=普通IPV4路由+RD+RT - VPNV4路由需要MP-BGP来进行传递;对端基于RT值,将路由装载到对应的VRF空间内,再共享给对应的CE;
- 控制层面工作完成后,数据层面需要基于MPLS来工作,由于数据层面不能携带RD/RT值;
- 故mpls将在数据包中压入两层标签,外层标签用于超越中间设备,打破BGP路由黑洞; 内层标签用于对应VRF空间;
MPLS VPN配置:
1、ISP部分
- IGP路由
- MPLS域
2、配置MPLS VPN
[r2]ip vpn-instance a 创建名为a的vrf空间
[r2-vpn-instance-a]ipv4-family 进入IPV4的配置模式下
[r2-vpn-instance-a-af-ipv4]route-distinguisher 1:1 RD值
[r2-vpn-instance-a-af-ipv4]vpn-target 1:1 RT值 必须对端的PE端一致
[r2]interface GigabitEthernet 0/0/0 进入链接CE端的接口
[r2-GigabitEthernet0/0/0]ip binding vpn-instance a 关联到vrf空间
[r2-GigabitEthernet0/0/0]ip address 192.168.2.2 24 配置私有ip地址
注:在关联到vrf空间前不能配置接口ip,否则该地址的直连路由将进入公有路由表;
[r2]display ip routing-table vpn-instance a 查看空间内的私有路由表
[r2]ping -vpn-instance a 192.168.2.1 正常测试将在公有路由表中查询记录;该命令为基于VRF空间
a进行路由查询
3、PE与PE间建立MP-BPG邻居关系
[r2]bgp 2
[r2-bgp]router-id 2.2.2.2
先和对端建立正常BGP邻居关系,可用于传递正常的公网路由
[r2-bgp]pe 4.4.4.4 as-number 2
[r2-bgp]pe 4.4.4.4 connect-interface LoopBack 0
[r2-bgp]pe 4.4.4.4 next-hop-local
同时还需要再在IPV4的家族模式中,与对端建立一个VPNV4的关系,用于传递VPNV4路由
[r2-bgp]ipv4-family vpnv4
[r2-bgp-af-vpnv4]peer 4.4.4.4 enable
[r2-bgp]display bgp vpnv4 all peer 查看mp-bgp邻居关系
4、CE端与PE端交互路由
静态
CE端直接编写静态路由;
PE端编写到VRF空间内的静态路由
[r2]ip route-static vpn-instance a 192.168.1.0 24 192.168.2.1
将本地vrf空间内的静态和直连路由重发布到BGP协议传递到对端的PE
[r2]bgp 2
[r2-bgp]ipv4 vpn-instance a
[r2-bgp-a]import-route direct
[r2-bgp-a]import-route static
<r4>display bgp vpnv4 vpn-instance a routing-table 查看mp-bpg的BGP表
OSPF
CE端正常启动OSPF即可
PE端,启动VPNV4专用的ospf协议
[r4]ospf 2 vpn-instance a
[r4-ospf-2]area 0
[r4-ospf-2-area-0.0.0.0]network 192.168.3.1 0.0.0.0
之后使用双向重发布,实现路由共享
[r4]bgp 2
[r4-bgp]ipv4-family vpn-instance a
[r4-bgp-a]import-route ospf 2
[r4]ospf 2 vpn-instance a
[r4-ospf-2]import-route bgp
[r4]display mpls lsp vpn-instance a 查看双层标记的内层标签号
MPLS VPN 核心问题
1、pe-pe 隧道 标签生成是什么协议?
答:华为默认:MPLS LDP,思科:私有 TDP/LDP
2、vrf 与 vrf 远端通信 标签是谁生成的?
答:MP-BGP
3、vrf的路由是谁传递的?该路由中除了路由前缀,下一跳等常见参数还有哪些参数?
答:BGP 中的 vpnv4 协议簇;
RD值,RT值
验证实验:
基础环境
- R1,R3为IBGP关系;R2不配BGP。(MPLS)
- R6可以与R4相通;R7可以与R5相通。
配置:
R1
#
sysname R1
#
ip vpn-instance a
ipv4-family
route-distinguisher 1:1
vpn-target 1:1 export-extcommunity
vpn-target 2:1 import-extcommunity
#
ip vpn-instance b
ipv4-family
route-distinguisher 2:2
vpn-target 1:2 export-extcommunity
vpn-target 2:2 import-extcommunity
#
mpls lsr-id 1.1.1.1
mpls
#
mpls ldp
#
interface Ethernet0/0/0
ip binding vpn-instance a
ip address 16.1.1.2 255.255.255.0
#
interface Ethernet0/0/1
ip binding vpn-instance b
ip address 17.1.1.2 255.255.255.0
#
interface GigabitEthernet0/0/0
ip address 12.1.1.1 255.255.255.0
mpls
mpls ldp
#
interface LoopBack0
ip address 1.1.1.1 255.255.255.0
#
bgp 1
peer 3.3.3.3 as-number 1
peer 3.3.3.3 connect-interface LoopBack0
#
ipv4-family unicast
undo synchronization
network 1.1.1.0 255.255.255.0
peer 3.3.3.3 enable
#
ipv4-family vpnv4
policy vpn-target
peer 3.3.3.3 enable
#
ipv4-family vpn-instance a
import-route ospf 2
#
ipv4-family vpn-instance b
import-route ospf 3
#
ospf 1 router-id 1.1.1.1
area 0.0.0.0
network 12.1.1.0 0.0.0.255
network 1.1.1.1 0.0.0.0
#
ospf 2 vpn-instance a
import-route bgp
area 0.0.0.0
network 16.1.1.2 0.0.0.0
#
ospf 3 vpn-instance b
import-route bgp
area 0.0.0.0
network 17.1.1.2 0.0.0.0
#
R3
#
sysname R3
#
ip vpn-instance a
ipv4-family
route-distinguisher 1:1
vpn-target 2:1 export-extcommunity
vpn-target 1:1 import-extcommunity
#
ip vpn-instance b
ipv4-family
route-distinguisher 2:2
vpn-target 2:2 export-extcommunity
vpn-target 1:2 import-extcommunity
#
mpls lsr-id 3.3.3.3
mpls
#
mpls ldp
#
interface Ethernet0/0/0
ip address 23.1.1.2 255.255.255.0
mpls
mpls ldp
#
interface Ethernet0/0/1
ip binding vpn-instance a
ip address 34.1.1.1 255.255.255.0
#
interface GigabitEthernet0/0/0
ip binding vpn-instance b
ip address 35.1.1.1 255.255.255.0
#
interface LoopBack0
ip address 3.3.3.3 255.255.255.0
#
bgp 1
peer 1.1.1.1 as-number 1
peer 1.1.1.1 connect-interface LoopBack0
#
ipv4-family unicast
undo synchronization
network 3.3.3.0 255.255.255.0
peer 1.1.1.1 enable
#
ipv4-family vpnv4
policy vpn-target
peer 1.1.1.1 enable
#
ipv4-family vpn-instance a
import-route ospf 2
#
ipv4-family vpn-instance b
import-route ospf 3
#
ospf 1 router-id 3.3.3.3
area 0.0.0.0
network 23.1.1.0 0.0.0.255
network 3.3.3.3 0.0.0.0
#
ospf 2 vpn-instance a
import-route bgp
area 0.0.0.0
network 34.1.1.1 0.0.0.0
#
ospf 3 vpn-instance b
import-route bgp
area 0.0.0.0
network 35.1.1.1 0.0.0.0
#
在R1的g0/0/0接口抓包
由R7pingR5
查看R2,3的mpls lsp1027 > 3
3 > null
查看底层标签
1032 > R5
更新路由时,中间部分使用BGP,携带路由的各种属性信息