1. Topology
CE1------[R1(PE1)---R2(P)---R3(ASBR1)]------[R4(ASBR2)----R5(PE2)]----------CE2
                              [AS 100]                                              [AS 200]

2. 基本原理
    域内的PE与ASBR之间建立IBGP邻居,ASBR之间建立BGP邻居,PE之间建立MP-EBGP邻居。PE之间的可达性,是通过BGP路由学习,进而建立MPLS Tunnel来保证的。原理有点小复杂。
3. 标签分配过程 (PE2到PE1)
    ××× 私网标签由PE1直接分配给PE2;
    到PE2 Loopback接口地址的公网标签是由BGP来逐跳分发的。
    需要说明的是,由于PE的Loopback接口地址是通过BGP学习到的,BGP路由的特点是下一跳可能不直接可达,所以需要递归查找,在MPLS网络中,就需要额外建立一条Tunnel。在本例中,ASBR1分配给PE1到PE2的Loopback接口地址的标签,但PE1并不能直接到达ASBR1,它将通过 R2到达,所以R3/R2/R1会逐跳分配到ASBR1 Loopback接口地址的标签,这个标签是由LDP分发的。
4. 标签转发过程 (PE1到PE2)
    PE1,通过查找VRF标签转发表,查到到×××目的网络的私网标签和下一跳(PE2);递归查找公网标签转发表,查到到PE2 Loopback接口地址的公网标签和下一跳(ASBR1),递归查找公网标签转发表,查到到ASBR1的公网标签;PE1封装3层标签,将报文转发给 P;
    P,根据外层标签执行标签交换,由于是倒数第二跳,弹出1层标签;P发送给ASBR1的报文携带2层标签;
    ASBR1,根据外层标签执行标签交换,将携带2层标签的报文转发给ASBR2;
    ASBR2,根据外层标签执行标签交换,由于是倒数第二跳,弹出外层标签;ASBR2发送给PE2的报文只携带1层×××标签;
    PE2,根据×××标签执行转发。由于是最后一跳,弹出×××标签,CE 收到的是纯IP报文。
    
5. 特点
    ASBR上不需要感知×××的存在,只需要PE来维护×××路由和私网标签转发表。
    P路由器上不需要知道到其他AS的公网路由,只需要PE维护到AS外的公网路由即可。
    协议层面比较复杂
    
6. 各LSR上的相关表项
- R1 (PE1 in AS 100)
到ASBR1 Loopback地址的标签表项,由P通过LDP分配
C3600-R1#show mpls forwarding-table                                            
Local  Outgoing    Prefix            Bytes tag  Outgoing   Next Hop            
tag    tag or VC   or Tunnel Id      switched   interface                            
19     17          3.3.3.3/32        0          Fa0/0      172.16.12.2                
到PE2 Loopback接口地址的标签表项,由ASBR1通过MP-IBGP分配
C3600-R1#sho ip bgp labels                                                      
Network          Next Hop         In Label/Out Label                            
5.5.5.5/32       3.3.3.3          nolabel/21                                    
                                                                                
到×××目的网络的标签表项,由PE2通过MP-EBGP分配                                            
C3600-R1#show ip bgp ***v4 all labels                                          
   Network          Next Hop      In label/Out label                            
Route Distinguisher: 100:1 (***-a)                                                                    
   10.58.1.0/24     5.5.5.5         nolabel/19                                  
到×××目的网络的标签栈 {17 21 19}
C3600-R1#show ip cef vrf ***-a 10.58.1.0                                        
10.58.1.0/24, version 31, epoch 0, cached adjacency 172.16.12.2                
0 packets, 0 bytes                                                              
  tag information set                                                          
    local tag: ×××-route-head                                                  
    fast tag rewrite with Fa0/0, 172.16.12.2, tags imposed: {17 21 19}          
  via 5.5.5.5, 0 dependencies, recursive                                        
    next hop 172.16.12.2, FastEthernet0/0 via 5.5.5.5/32                        
    valid cached adjacency                                                      
    tag rewrite with Fa0/0, 172.16.12.2, tags imposed: {17 21 19}                          

- R2 (P in AS 100)
P路由器感知不到××× 的存在,也感知不到PE2的存在,只维护域内的公网LSP
C3600-R2#show mpls forwarding-table                                            
Local  Outgoing    Prefix            Bytes tag  Outgoing   Next Hop            
tag    tag or VC   or Tunnel Id      switched   interface                              
17     Pop tag     3.3.3.3/32        50306      Fa1/0      172.16.23.3                          
- R3 (ASBR1 in AS 100)
ASBR不感知×××的存在,但能够感知到PE2的存在,它需要维护到PE2的公网 LSP
这个公网标签是通过MP-BGP分配的              
C3600-R3#show ip bgp labels                                                    
Network          Next Hop         In Label/Out Label                                                              
5.5.5.5/32       172.16.34.4      21/17                                        
                                                                                                                          
C3600-R3#show mpls forwarding-table                                            
Local  Outgoing    Prefix            Bytes tag  Outgoing   Next Hop            
tag    tag or VC   or Tunnel Id      switched   interface                              
21     17          5.5.5.5/32        7860       Fa1/0      172.16.34.4          
- R4 (ASBR2 in AS 200)
ASBR2同样感知不到×××的存在,但能够感知到PE2的存在,它需要维护到PE2的公网LSP
这个公网标签是通过MP-BGP分配的,倒数第二跳,弹出操作
C3600-R4#show mpls forwarding-table                                            
Local  Outgoing    Prefix            Bytes tag  Outgoing   Next Hop            
tag    tag or VC   or Tunnel Id      switched   interface                            
17     Pop tag     5.5.5.5/32        3351       Fa1/0      172.16.45.5                  
                                                        
C3600-R4#sho ip bgp labels                                                      
Network          Next Hop         In Label/Out Label                                                                
5.5.5.5/32       172.16.45.5      17/nolabel
- R5 (PE2 in AS 200)
×××标签信息
C3600-R5#show ip bgp ***v4 all labels                                          
   Network          Next Hop      In label/Out label                            
Route Distinguisher: 100:1 (***-a)                              
   10.58.1.0/24     0.0.0.0         19/aggregate(***-a)

C3600-R1#traceroute vrf ***-a 10.58.1.5                                        
                                                                                
Type escape sequence to abort.                                                  
Tracing the route to 10.58.1.5                                                
                                                                                
  1 172.16.12.2 [MPLS: Labels 17/21/19 Exp 0] 204 msec 260 msec 260 msec        
  2 172.16.23.3 [MPLS: Labels 21/19 Exp 0] 332 msec 248 msec 212 msec          
  3 172.16.34.4 [MPLS: Labels 17/19 Exp 0] 224 msec 128 msec 268 msec          
  4 10.58.1.5 [MPLS: Label 19 Exp 0] 212 msec 312 msec *                
7. 额外配置
1)由于到PE Loopback地址的公网标签都是MP-BGP分发的,所以需要在ASBR和PE上配置BGP分发标签功能            
neighbor 172.16.34.4 send-label  
2)由于到PE Loopback地址的路由都是通过BGP学到的,当PE之间建立起EBGP邻居之后,他们的Loopback接口地址的路由同样会通过这个EBGP邻居之间进行发送,而先前是通过IBGP学习到的,EBGP学习到的路由会优于IBGP,所以更新后会导致到PE Loopback接口地址的路由的下一跳是PE Loopback接口地址,导致死循环。解决这问题应使用策略路由进行路由发布控制。