二、MPLS-LDP

2 MPLS-LDP

2.1 协议概述

只针对IGP路由捆绑前期,不针对BGP进行捆绑。

本地捆绑:为IPV4分配标签,并在邻居间交换。

2.2 LDP邻居关系建立过程

运行OSPF,建立LDP邻居关系,在分发标签

1、路由器均运行OSPF

2运行CEF,LOOPBACK0作为LDP的ROUTE-ID,同时设置各路由器的分配给路由前缀的标签范围(注意0-15是保留的,特殊用途),不指定范围时,默认从16开始,各个路由器都从16开始,作用于本地链路,路由器间可以重复。

3.激活接口MPLS功能,打开接口MPLS功能,激活接口标签交换协议,默认是LDP

2.2.1 设备配置

R1路由器配置:

Router(config)#router ospf 1
Router(config-router)#router-id 1.1.1.1
Router(config-router)#network 10.1.12.1 0.0.0.0 area 0
Router(config-router)#network 1.1.1.1 0.0.0.0 area 0

Router(config)#ip cef
Router(config)#mpls ldp router-id loopback 0
Router(config)#mpls label range 100 199

Router(config)#interface fastEthernet 0/0
Router(config-if)#ip address 10.1.12.1 255.255.255.0
Router(config-if)#no shutdown
Router(config-if)#mpls ip

Router(config)#interface loopback 0
Router(config-if)#ip address 1.1.1.1 255.255.255.255

R2路由器配置:

Router(config)#router ospf 1
Router(config-router)#router-id 2.2.2.2
Router(config-router)#network 10.1.12.2 0.0.0.0 area 0
Router(config-router)#network 10.1.23.2 0.0.0.0 area 0
Router(config-router)#network 2.2.2.2 0.0.0.0 area 0

Router(config)#ip cef
Router(config)#mpls ldp router-id loopback 0
Router(config)#mpls label range 200 299

Router(config)#interface fastEthernet 0/0
Router(config-if)#ip address 10.1.12.2 255.255.255.0
Router(config-if)#no shutdown
Router(config-if)#mpls ip

Router(config)#interface fastEthernet 1/0
Router(config-if)#ip address 10.1.23.2 255.255.255.0
Router(config-if)#no shutdown
Router(config-if)#mpls ip

Router(config)#interface loopback 0
Router(config-if)#ip address 2.2.2.2 255.255.255.255

R3路由器配置

Router(config)#router ospf 1
Router(config-router)#router-id 3.3.3.3
Router(config-router)#network 10.1.23.3 0.0.0.0 area 0
Router(config-router)#network 3.3.3.3 0.0.0.0 area 0

Router(config)#ip cef
Router(config)#mpls ldp router-id loopback 0
Router(config)#mpls label range 300 399

Router(config)#interface fastEthernet 1/0
Router(config-if)#ip address 10.1.23.3 255.255.255.0
Router(config-if)#no shutdown
Router(config-if)#mpls ip

Router(config)#interface loopback 0
Router(config-if)#ip address 3.3.3.3 255.255.255.255

2.2.2 LDP邻居发现

路由器之间发现并建立邻居,然后交换标签信息。

相连两个接口激活LDP协议后,就会发LDP的HELLO协议包。

HELLO包包含:ROUTER-ID(LDP的ROUTER-ID),传输IP(邻居发现完后,会话建立过程中使用传输IP作为源目地址,默认为ROUTER-ID)。

HELLO包源地址为接口IP地址,目的地址为224.0.0.2,端口号为646。

邻居发现后,地址大的发起TCP的三次握手,此时用传输IP进行TCP连接,端口一个是随机,一个是固定646。

2.2.3 LDP会话建立

TCP三次握手完成后,开始LDP会话建立

R2发送初始化协商参数消息,R1接受的话则发送自己的参数给R2并发送心跳消息,R2如果接受,则发送心跳消息。

2.2.4 LDP标签映射消息交互

会话建立连接后,开始交互消息。

R2将自己的路由前缀及捆绑的标签发送给R1,R1收到后放到自己的LFIB表中,同时R1也会将自己的消息发送个R2。

LDP邻居

2.2.5 抓包分析过程

1、R1和R2互发HELLO包消息

R1发送的HELLO包

IP协议中,源地址为10.1.12.1,目的地址为224.0.0.2

UDP中,源端口和目的端口都为646

报文的包,有LSR ID,即ROUTER-ID 1.1.1.1,HELLO报文消息中还有传输地址1.1.1.1

2、三次TCP握手

  1. LDP会话建立

地址大的一方发送初始化消息,包含一序列参数,如会话协议版本,计时器值等

4、标签映射消息交互

三条映射消息,如2.2.2.0(PREFIX)分配标签值3(GENRIC LABEL)

5、相互间的持续心跳消息

2.2.6 查看LDP邻居关系

Router#show mpls ldp neighbor
    Peer LDP Ident: 2.2.2.2:0; Local LDP Ident 1.1.1.1:0
        TCP connection: 2.2.2.2.50553 - 1.1.1.1.646
        State: Oper; Msgs sent/rcvd: 8/8; Downstream
        Up time: 00:00:29
        LDP discovery sources:
          FastEthernet0/0, Src IP addr: 10.1.12.2
        Addresses bound to peer LDP Ident:
          10.1.12.2       10.1.23.2       2.2.2.2

查看R1的LDP邻居关系,为2.2.2.2

Router#show mpls ldp neighbor
    Peer LDP Ident: 1.1.1.1:0; Local LDP Ident 2.2.2.2:0
        TCP connection: 1.1.1.1.646 - 2.2.2.2.50553
        State: Oper; Msgs sent/rcvd: 9/10; Downstream
        Up time: 00:01:48
        LDP discovery sources:
          FastEthernet0/0, Src IP addr: 10.1.12.1
        Addresses bound to peer LDP Ident:
          10.1.12.1       1.1.1.1
    Peer LDP Ident: 3.3.3.3:0; Local LDP Ident 2.2.2.2:0
        TCP connection: 3.3.3.3.26670 - 2.2.2.2.646
        State: Oper; Msgs sent/rcvd: 10/9; Downstream
        Up time: 00:01:39
        LDP discovery sources:
          FastEthernet1/0, Src IP addr: 10.1.23.3
        Addresses bound to peer LDP Ident:
          10.1.23.3       3.3.3.3

R2有两个LDP邻居,1.1.1.1和2.2.2.2

Router#show mpls ldp neighbor
    Peer LDP Ident: 2.2.2.2:0; Local LDP Ident 3.3.3.3:0
        TCP connection: 2.2.2.2.646 - 3.3.3.3.26670
        State: Oper; Msgs sent/rcvd: 10/10; Downstream
        Up time: 00:02:25
        LDP discovery sources:
          FastEthernet1/0, Src IP addr: 10.1.23.2
        Addresses bound to peer LDP Ident:
          10.1.12.2       10.1.23.2       2.2.2.2

R3有1个LDP邻居

2.2.7 查看LDP邻居发现情况

如果R1的LOOPBACK接口没有在OSPF里面宣告。

Router#show mpls ldp discovery
 Local LDP Identifier:
    2.2.2.2:0
    Discovery Sources:
    Interfaces:
        FastEthernet0/0 (ldp): xmit/recv
            LDP Id: 1.1.1.1:0
        FastEthernet1/0 (ldp): xmit/recv
            LDP Id: 3.3.3.3:0

如R2有两个邻居

Router(config)#router ospf 1
Router(config-router)#no network 1.1.1.1 0.0.0.0 area 0

这时如果R1不宣告1.1.1.1

Router#show mpls ldp neighbor
    Peer LDP Ident: 1.1.1.1:0
        No TCP connection; Downstream
        Up time: 00:08:44
        Addresses bound to peer LDP Ident:
          10.1.12.1       1.1.1.1
    Peer LDP Ident: 3.3.3.3:0; Local LDP Ident 2.2.2.2:0
        TCP connection: 3.3.3.3.26670 - 2.2.2.2.646
        State: Oper; Msgs sent/rcvd: 17/17; Downstream
        Up time: 00:08:36
        LDP discovery sources:
          FastEthernet1/0, Src IP addr: 10.1.23.3
        Addresses bound to peer LDP Ident:
          10.1.23.3       3.3.3.3

R2没有R1的邻居了

Router#show mpls ldp discovery
 Local LDP Identifier:
    2.2.2.2:0
    Discovery Sources:
    Interfaces:
        FastEthernet0/0 (ldp): xmit/recv
            LDP Id: 1.1.1.1:0; no route
        FastEthernet1/0 (ldp): xmit/recv
            LDP Id: 3.3.3.3:0

则再次查看,显示NO ROUTE.

Router(config)#router ospf 1
Router(config-router)#network 1.1.1.1 0.0.0.0 area 0

加回来

2.3 PHP(倒数第二跳弹出)机制

2.3.1 Imp-null

没有PHP之前,关键点在C,C收到标签包后,会首先在LFIB表中查找,查到是POP,去掉标签后变成IP包,再接着在FIB表中查IP。

有了后,C路由器发现是直连路由,C路由器会分配一个特殊的标签IMPLICIT NULL空。C传给B时,标签值为3,B收到3后,会理解为POP。B弹出后直接给C IP包,C就不用查LFIB标了,直接查FIB表就可以了。

Router#show mpls ldp bindings
  lib entry: 1.1.1.1/32, rev 4
        local binding:  label: imp-null
        remote binding: lsr: 2.2.2.2:0, label: 201
  lib entry: 2.2.2.2/32, rev 8
        local binding:  label: 101
        remote binding: lsr: 2.2.2.2:0, label: imp-null
  lib entry: 3.3.3.3/32, rev 6
        local binding:  label: 100
        remote binding: lsr: 2.2.2.2:0, label: 200
  lib entry: 10.1.12.0/24, rev 2
        local binding:  label: imp-null
        remote binding: lsr: 2.2.2.2:0, label: imp-null
  lib entry: 10.1.23.0/24, rev 10
        local binding:  label: 102
        remote binding: lsr: 2.2.2.2:0, label: imp-null

默认都是PHP,如配置中的R1,对于1.1.1.1位LOOPBACK接口,分配的标签为IMP-NULL。

在R1和R2间抓包在,在R1上执行

Router#clear mpls ldp neighbor *

找到1.1.1.1给2.2.2.2发送的映射消息

找到FEC中前缀PREFIX为1.1.1.1的LABEL MAPPING MESSAGE路由,对应的标签值GENERIC LABEL为3。

即R1给R2发送1.1.1.1的路由时,标签捆绑的标签值为3,R2收到后放入LIB表中。

R2#show mpls ldp bindings
  lib entry: 1.1.1.1/32, rev 10
        local binding:  label: 201
        remote binding: lsr: 3.3.3.3:0, label: 302
        remote binding: lsr: 1.1.1.1:0, label: imp-null
  lib entry: 2.2.2.2/32, rev 6
        local binding:  label: imp-null
        remote binding: lsr: 3.3.3.3:0, label: 300
        remote binding: lsr: 1.1.1.1:0, label: 101
  lib entry: 3.3.3.3/32, rev 8
        local binding:  label: 200
        remote binding: lsr: 3.3.3.3:0, label: imp-null
        remote binding: lsr: 1.1.1.1:0, label: 100
  lib entry: 10.1.12.0/24, rev 2
        local binding:  label: imp-null
        remote binding: lsr: 3.3.3.3:0, label: 301
        remote binding: lsr: 1.1.1.1:0, label: imp-null
  lib entry: 10.1.23.0/24, rev 4
        local binding:  label: imp-null
        remote binding: lsr: 3.3.3.3:0, label: imp-null
        remote binding: lsr: 1.1.1.1:0, label: 102

R2中,1.1.1.1的路由中,remote binding: lsr: 1.1.1.1:0, label: imp-null为空。

R2#show mpls forwarding-table
Local  Outgoing      Prefix            Bytes Label   Outgoing   Next Hop
Label  Label or VC   or Tunnel Id      Switched      interface
200    Pop Label     3.3.3.3/32        0             Fa1/0      10.1.23.3
201    Pop Label     1.1.1.1/32        0             Fa0/0      10.1.12.1

则R2中LFIB对应的为POP

注意标签为3是在控制层面,数据层面不会出现标签值为3的,因为3表示弹出,就变成IP包了。

2.3.2 Exp-null

对于IMPLICIT NULL

控制层面:本地分配IMP-NULL,告诉邻居为3,R2收到后为IMP-NULL,R2也会发给邻居,R1也会维护为R2的本地标签。

数据层面:R1发数据,压入标签后给R2,R2查LFIB表,出口为POP(因为R3给的标签值为3),变成IP包给R3。

在某些特殊情况下,R2弹出标签后给R3,标签头包含了很多信息,把整个信息都弹除了,里面部分信息还是有用的,如EXP位做QOS。会导致流量工程不连续,这事如果想保留标签头。可以使用EXPLICIT NULL。

在R3上激活EXPLICIT NULL后,R3给R2的标签就不再是3了,而是0,R2的LFIB就不是POP了。

如在R3上做:

R3(config)#mpls ldp explicit-null
R2#show mpls ldp bindings
  lib entry: 1.1.1.1/32, rev 10
        local binding:  label: 201
        remote binding: lsr: 3.3.3.3:0, label: 302
        remote binding: lsr: 1.1.1.1:0, label: imp-null
  lib entry: 2.2.2.2/32, rev 6
        local binding:  label: imp-null
        remote binding: lsr: 3.3.3.3:0, label: 300
        remote binding: lsr: 1.1.1.1:0, label: 101
  lib entry: 3.3.3.3/32, rev 8
        local binding:  label: 200
        remote binding: lsr: 1.1.1.1:0, label: 100
        remote binding: lsr: 3.3.3.3:0, label: exp-null
  lib entry: 10.1.12.0/24, rev 2
        local binding:  label: imp-null
        remote binding: lsr: 3.3.3.3:0, label: 301
        remote binding: lsr: 1.1.1.1:0, label: imp-null
  lib entry: 10.1.23.0/24, rev 4
        local binding:  label: imp-null
        remote binding: lsr: 1.1.1.1:0, label: 102
        remote binding: lsr: 3.3.3.3:0, label: exp-null

R2上看到R3过来的:remote binding: lsr: 3.3.3.3:0, label: exp-null

R2#show mpls forwarding-table
Local  Outgoing      Prefix            Bytes Label   Outgoing   Next Hop
Label  Label or VC   or Tunnel Id      Switched      interface
200    explicit-n    3.3.3.3/32        0             Fa1/0      10.1.23.3
201    Pop Label     1.1.1.1/32        0             Fa0/0      10.1.12.1

这时为explicit-n,即0,不再是POP

意味着R3把捆绑的标签0给了R2,当R2给R3时,就不再是POP了,R2会把标签置换为0给R3,保留了标签头其他信息,(标签值为3不会出现在标签数据里,但是0可以)。

2.4 MPLS标签

2.4.1 标签空间

2.4.2 LDP非直连邻居

2.4.3 帧模式-标签分配

Router#show mpls ldp bindings
  lib entry: 1.1.1.1/32, rev 2
        local binding:  label: imp-null
        remote binding: lsr: 2.2.2.2:0, label: 200
  lib entry: 2.2.2.2/32, rev 4
        local binding:  label: 100
        remote binding: lsr: 2.2.2.2:0, label: imp-null
  lib entry: 3.3.3.3/32, rev 6
        local binding:  label: 101
        remote binding: lsr: 2.2.2.2:0, label: 201
  lib entry: 10.1.12.0/24, rev 8
        local binding:  label: imp-null
        remote binding: lsr: 2.2.2.2:0, label: imp-null
  lib entry: 10.1.23.0/24, rev 10
        local binding:  label: 102
        remote binding: lsr: 2.2.2.2:0, label: imp-null

LIB表,路由和标签的绑定

Router#show mpls forwarding-table
Local  Outgoing      Prefix            Bytes Label   Outgoing   Next Hop
Label  Label or VC   or Tunnel Id      Switched      interface
100    Pop Label     2.2.2.2/32        0             Fa0/0      10.1.12.2
101    201           3.3.3.3/32        0             Fa0/0      10.1.12.2
102    Pop Label     10.1.23.0/24      0             Fa0/0      10.1.12.2

LFIB表,本次标签,出口标签,前缀,出接口,下一跳

2.4.3.1 构建IP路由表

2.4.3.2 分配并分发标签、维护LIB

自己分配并分发给邻居,比如此处B给X分配标签201

邻居间互相分发后的效果,如B除了分发给ACE邻居外,还会从ACE邻居收到X的标签信息

2.4.3.3 维护LFIB

B根据自己路由表的下一跳C,B的LFIB表中本地是自己,下一跳是C的标签。

由于IP包到A,A查询FIB表,显示需要压入标签201;

转给B,B收到帧,根据帧类型,判断标签包,根据标签201查LFIB,查到出栈口为301,则B将标签头置换为301;

转给C,C拿301去LFIB表查,查到是POP,则弹出301,变成IP包传给D;

D收到IP包后,查FIB表,发现是本地直连,则通过本地直连传给本地。

2.4.3.4 小结

路由器依赖IGP协议构建路由表,唯独不会为BGP分配。

2.4.4 MPLS网络收敛

网络稳定以后,

B的RIB路由表下一跳是C;

B的FIB表路由下一跳是C,且需要压入标签301;

B的LIB路由器有针对X的本地ACE标签,而B的FIB表下一跳是C。

B的LFIB表则表示去往X,下一跳标签是301,出接口是C。

收敛后,BC间断开,B感知后 ,B的IGP协议重新收敛,RIB中下一跳为E,FIB表中表示压入标签为501,由于B中有所有邻居的标签,则B的LFIB表也会变依据此变。

链路抖动后变好了,IGP先收敛,接着是LDP

IGP收敛后,RIB会恢复为C,由于先IGP,然后LDP,这时C的标签还没有传给B,B不知道C向哪走,这事LFIB就会用UNTAGGED标识。B直接把IP包给C。

C的邻居关系早晚会给B,B会重新更新自己的LFIB表。

2.4.5 路由汇总影响

控制层面:C上汇总,产生了两条路由,AB这时学到的是汇总路由,汇总路由C始发,C会分配两个标签,其中给本地的为POP,即PHP机制。

数据层面:发数据时,B由于PHP机制会POP后成IP包给C。C收到IP包,查询FIB,发现需要压标签后给D,D查LFIB表,弹出标签后,把IP包给E。虽然到了目的地,中间经历多次压栈,入栈操作。而且在MPLS VPN环境中,可能会出问题。

2.4.6 保留标签

重点了解标签0和标签3

2.4.6.1 IMP-NULL:标签3

2.4.6.2 EXP-NULL:标签0

2.5 MPLS环路检测TTL

2.5.1 TTL propatation

对于边界路由器,IP头中有TTL,进入后,MPLS的TTL会拷贝

橘黄色代表IP包,黄色代表MPLS包

IP包TTL为5,A路由器收到后,需要压标签进入MPLS网络,A首先会给IP包的TTL减1,为4,同时需要压入标签头,标签头的TTL字段会拷贝IP包中的TTL。

在MPLS网络中,IP包头的TTL不会变,但是标签头,每经过一次路由器,标签头的TTL会减1。

传到C后,由于PHP机制,标签头会被弹出,C首先把标签头的TTL减1,同时把TTL值复制到IP头的TTL字段。

2.5.2 TTL扩散行为

SWAP,标签置换,三层标签,置换时,只处理顶层标签,栈顶减1。

PUSH,压入标签,现有顶层为249,查找FIB表,需要压入新的标签时,这时先把栈顶减1,再拷贝顶层TTL,作为新压入标签的TTL值。

POP,弹出标签,现有顶层为249,先把顶层标签TTL减1,并拷贝到第二层标签的TTL值。

2.5.3 潜在问题

TRACERT的TTL为1时,进入后为0,返回失败

TRACERT的TTL为2时,到B时为0,这时就知道了B的地址,依次循环下去,就知道了内部网络地址了。

解决办法就是关闭TTL PROPATATION,关闭后就不在复制值了,而是会给标签一个新的255TTL值。

发表回复