想了很久才决定要写这篇文章。因为我感觉有好多可以说,并且要写出博文有点困难。还是尽力吧,不写出来可能也很快就忘了。

按照我的习惯是先上拓扑:

 

这就是我的拓扑。

实验参数如下:

IGP用OSPF,实现全网互通。

全部路由器都雇用CEF。

R1用LOOPBACK 1  =11.1.1.1 模拟外网,R5用loopback 1=55.5.5.5 模拟外网。

配置OSPF不作说明。

先介绍配置MPLS 。

R1  和R5建立IGBP关系。

在配置过程中我会故意放入一些不优的配置,以便分析。

R1#ip cef

mpls label range 100 199 这一条命令在实际应用中不要启用。在这里只是为了试验一下这条命令而已。MPLS的LDP协议是自动为我们分配标签的,这条命令的作用在于指定标签的范围。
 
mpls ldp router-id Loopback1   (记住Loopback1 没有NETWORK进BGP和OSPF的,是为了模拟来自CE的路由)
no mpls ip propagate-ttl forwarded 这条命令也很重要。 下面这一段讲解这一条命令的作用:、
 
 
   
  1. no mpls ip propagate-ttl forwarded   
  2. 这条命令的意思是,不看IP包的TTL值,因为在PE上,MPLS会copy  IP包中的TTL值填充MPLS包头
  3. 中的TTL字段。  
  4. 例如当一个数据包进入MPLS网络时,也就是刚进入PE。  
  5. 假设IP包中的TTL值=6,这时PE先减去1 ,TTL=6-15。然后将TTL填充进MPLS包头的TTL,所
  6. 以这时MPLS包头的TTL值就是5。  
  7. 之后在MPLS网络中传输时,因为在MPLS网络中是不看IP包头的,所以IP包头的TTL值不会减少,但
  8. 是MPLS的TTL值每经过一个路由器就减少1,(当减少为0时丢弃。其实当路由器收到一个TTL=1
  9. 包时就要丢弃了。)最后,在连接目的网络的PE上面,MPLS包头的TTL值先减去1 ,之后再copy 
  10. 回去覆盖了IP包头的TTL字段。这样子的话,在外部网络的用户就可以tracert  MPLS网络,得知
  11. MPLS网络的结构。  
  12. 所以我们需要这条no mpls ip propagate-ttl forwarded 命令,不要从IP包中复制TTL值,
  13. 直接填充MPLS的TTL=255.  
  14. Traceroute就是利用TTL的技术来实现的,第一次发包TTL是1,包到达下一跳后,TTL变成0,包
  15. 被丢弃,并响应一个TTL超时。然后,依次递增TTL,依次响应TTL超时,就能发现路径了。如果ISP
  16. 网络没有禁用TTL,那么客户就可以利用Traceroute探查到ISP的内部路由了,启用如下命令,防止
  17. 该事情发生。  
  18.   forwarded是指NO掉CE过来的TTL值,local是指自己的也要NO掉,一般在边界路由器打上
  19. forwarded就好,保证自己还是可以traceroute的,默认不打,两个全部NO掉。  
  20. MPLS的每个技术解释起来都有一大堆话,或许是我太啰嗦了==  
#router bgp 100
 no synchronization
 bgp router-id 1.1.1.1
 bgp log-neighbor-changes
 network 11.1.1.0 mask 255.255.255.0
 neighbor 45.1.1.5 remote-as 100
  no auto-summary
!         
!         
interface Serial0/0
 ip address 12.1.1.1 255.255.255.0
 mpls ldp discovery transport-address interface
 
 
     
  1. 这条命令的作用是用接口的地址与邻居建立LDP关系。使用直连接口地址可保证下 一跳可达。 
  2. 建立之后在R2上:
    • R2#show mpls  ldp  discovery  
    •  Local LDP Identifier:
    •     2.2.2.2:0
    •     Discovery Sources:
    •     Interfaces:
    •         Serial0/0 (ldp): xmit/recv
    •             LDP Id: 11.1.1.1:0; IP addr: 12.1.1.1; no host route
    •         FastEthernet1/0 (ldp): xmit/recv
    •             LDP Id: 3.3.3.3:0; no host route
    • 显示no host route 是正常的。
 mpls ip  
 serial restart-delay 0
!         
 
R2:
ip cef
no ip domain lookup
mpls label range 200 299
mpls ldp router-id Loopback0 
 
R3:

 

ip cef
no ip domain lookup
mpls label range 300 399
mpls ldp router-id Loopback0 

 

R4:

 

ip cef
no ip domain lookup
mpls label range 400 499
mpls ldp router-id Loopback0 
R5:
ip cef
mpls label range 500 599
no mpls ip propagate-ttl forwarded
interface Loopback0
 ip address 5.5.5.5 255.255.255.0
 
        
interface Loopback1
 ip address 55.5.5.5 255.255.255.0
 ip ospf network point-to-point
!         
interface Serial0/0
 ip address 45.1.1.5 255.255.255.0
 mpls ldp discovery transport-address interface
 mpls ip  
 serial restart-delay 0
 
router ospf 100
 router-id 5.5.5.5
 log-adjacency-changes
 network 5.5.5.5 0.0.0.0 area 0
 network 45.1.1.5 0.0.0.0 area 0
!         
router bgp 100
 no synchronization
 bgp router-id 5.5.5.5
 bgp log-neighbor-changes
 network 55.5.5.0 mask 255.255.255.0
 neighbor 12.1.1.1 remote-as 100
 no auto-summary
 
mpls ldp router-id Loopback1
!         
 
大体的配置已经帖出来了。
下面讲一个其中的关健点,次末节路由的一个问题。
注意一下我的BPG配置中建立邻居的IP地址,是对方的接口地址。
 
 neighbor 45.1.1.5 remote-as 100
 neighbor 12.1.1.1 remote-as 100
学习MPLS最难的是跟踪标签。下面我们就来跟踪一下标签。
 
 
  
  1. R1#show mpls  forwarding-table   
  2. Local  Outgoing    Prefix            Bytes tag  Outgoing   Next Hop     
  3. tag    tag or VC   or Tunnel Id      switched   interface               
  4. 100    200         34.1.1.0/24       0          Se0/0      point2point   
  5. 101    Untagged    2.2.2.2/32        0          Se0/0      point2point   
  6. 102    202         3.3.3.3/32        0          Se0/0      point2point   
  7. 103    203         4.4.4.4/32        0          Se0/0      point2point   
  8. 104    204         5.5.5.5/32        0          Se0/0      point2point   
  9. 105    Pop tag     23.1.1.0/24       0          Se0/0      point2point   
  10. 106    205         45.1.1.0/24       0          Se0/0      point2point   
 
 
  
  1. R2#show mpls  forwarding-table  
  2. Local  Outgoing    Prefix            Bytes tag  Outgoing   Next Hop     
  3. tag    tag or VC   or Tunnel Id      switched   interface               
  4. 200    Pop tag     34.1.1.0/24       0          Fa1/0      23.1.1.3      
  5. 201    Untagged    1.1.1.1/32        0          Se0/0      point2point   
  6. 202    Untagged    3.3.3.3/32        0          Fa1/0      23.1.1.3      
  7. 203    302         4.4.4.4/32        0          Fa1/0      23.1.1.3      
  8. 204    Untagged    5.5.5.5/32        0          Fa1/0      23.1.1.3      
  9. 205    305         45.1.1.0/24       0          Fa1/0      23.1.1.3      
  10. R2# 

 

 

 
  
  1. R3#show mpls  for  
  2. Local  Outgoing    Prefix            Bytes tag  Outgoing   Next Hop     
  3. tag    tag or VC   or Tunnel Id      switched   interface               
  4. 300    201         1.1.1.1/32        0          Fa0/0      23.1.1.2      
  5. 301    Untagged    2.2.2.2/32        0          Fa0/0      23.1.1.2      
  6. 302    Untagged    4.4.4.4/32        0          Fa0/1      34.1.1.4      
  7. 303    403         5.5.5.5/32        77         Fa0/1      34.1.1.4      
  8. 304    Pop tag     12.1.1.0/24       635        Fa0/0      23.1.1.2      
  9. 305    Pop tag     45.1.1.0/24       5747       Fa0/1      34.1.1.4     

看到一个奇怪的地方 了吧??为什么是POP,明明只是R3而已,应该不是次末节路由才对。可是这个现象是什么回事?

原因是这样的,我们回过头来看一下,我们的BPG建立邻居是用这样地址来建立邻居的:

 R1:neighbor 12.1.1.1 remote-as 100

 R5:neighbor 45.1.1.5 remote-as 100

对于R1来说,与45.1.1.5建立了邻居,对于45.1.1.0这个网络,R3就是次末节路由。所以显示是POP。我不知道这样讲清不清楚。简单地说,R3是45.1.1.0这个网络的次末节路由。

那么如何解决这个问题呢?

R1:neighbor 5.5.5.5 remote-as 100 

        neighbor 5.5.5.5 update-source lo0 

R5:neighbor 1.1.1.1 remote-as 100

      neighbor 1.1.1.1 update-source lo0

接下来分析另一个问题:

 
  
  1. R2#show mpls  forwarding-table   
  2. Local  Outgoing    Prefix            Bytes tag  Outgoing   Next Hop      
  3. tag    tag or VC   or Tunnel Id      switched   interface                
  4. 200    Pop tag     34.1.1.0/24       0          Fa1/0      23.1.1.3       
  5. 201    Untagged    1.1.1.1/32        0          Se0/0      point2point    
  6. 202    Untagged    3.3.3.3/32        0          Fa1/0      23.1.1.3       
  7. 203    302         4.4.4.4/32        0          Fa1/0      23.1.1.3       
  8. 204    Untagged    5.5.5.5/32        0          Fa1/0      23.1.1.3       
  9. 205    305         45.1.1.0/24       0          Fa1/0      23.1.1.3       
  10. R2#  
 
  
  1. R4#show mpls  forwarding-table   
  2. Local  Outgoing    Prefix            Bytes tag  Outgoing   Next Hop     
  3. tag    tag or VC   or Tunnel Id      switched   interface               
  4. 400    300         1.1.1.1/32        0          Fa1/0      34.1.1.3      
  5. 401    301         2.2.2.2/32        0          Fa1/0      34.1.1.3      
  6. 402    Untagged    3.3.3.3/32        0          Fa1/0      34.1.1.3      
  7. 403    Untagged    5.5.5.5/32        63         Se0/0      point2point   
  8. 404    Pop tag     23.1.1.0/24       0          Fa1/0      34.1.1.3      
  9. 405    304         12.1.1.0/24       6416       Fa1/0      34.1.1.3      

 注意红色字体的部分。untagged是什么意思?

uptagged跟pop的一个不同的地方是,pop只弹出一层标签,而untagged弹出全部标签。

另外,在这里显示untagged表示,这个路由是自己发现的,而不是由邻居告诉我的,发生一次untagged意味着这个标签的所有标签全部冲突。全部弹出。

看一下R4


 
  
  1. R4#show mpls  ldp  bindings  
  2.   tib entry: 1.1.1.1/32, rev 15 
  3.         local binding:  tag: 402 
  4.         remote binding: tsr: 3.3.3.3:0, tag: 300 
  5.         remote binding: tsr: 55.5.5.5:0, tag: 503 
  6.   tib entry: 2.2.2.2/32, rev 17 
  7.         local binding:  tag: 403 
  8.         remote binding: tsr: 3.3.3.3:0, tag: 301 
  9.         remote binding: tsr: 55.5.5.5:0, tag: 504 
  10.   tib entry: 3.3.3.0/24, rev 22 
  11.         remote binding: tsr: 3.3.3.3:0, tag: imp-null 
  12.   tib entry: 3.3.3.3/32, rev 19 
  13.         local binding:  tag: 404 
  14.         remote binding: tsr: 55.5.5.5:0, tag: 505 
  15.   tib entry: 4.4.4.0/24, rev 5 
  16.         local binding:  tag: imp-null 
  17.   tib entry: 4.4.4.4/32, rev 9 
  18.         remote binding: tsr: 55.5.5.5:0, tag: 500 
  19.         remote binding: tsr: 3.3.3.3:0, tag: 303 
  20.   tib entry: 5.5.5.0/24, rev 8 
  21.         remote binding: tsr: 55.5.5.5:0, tag: imp-null 
  22.   tib entry: 5.5.5.5/32, rev 11 
  23.         local binding:  tag: 400 
  24.         remote binding: tsr: 3.3.3.3:0, tag: 304 

奇怪吧?为什么有一个是24位的,有一个是32位的?而且32位的那一条路由的下一跳是3.3.3.3????

R5:interface Loopback0

 ip address 5.5.5.5 255.255.255.0

配置时是24位的。所以MPLS将它发送给R4 。
再看32位的,这是OSPF学习到的路由,OSPF认为LOOPBACK口的都是32位的,所以R4的路由表学习到的是32位的路由,下一跳指向45.1.1.5

 

 
       
  1. R4#show ip route   
  2. Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP 
  3.        D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area  
  4.        N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 
  5.        E1 - OSPF external type 1, E2 - OSPF external type 2 
  6.        i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2 
  7.        ia - IS-IS inter area, * - candidate default, U - per-user static route 
  8.        o - ODR, P - periodic downloaded static route 
  9.  
  10. Gateway of last resort is not set 
  11.  
  12.      34.0.0.0/24 is subnetted, 1 subnets 
  13. C       34.1.1.0 is directly connected, FastEthernet1/0 
  14.      1.0.0.0/24 is subnetted, 1 subnets 
  15. O       1.1.1.0 [110/67] via 34.1.1.3, 00:09:54, FastEthernet1/0 
  16.      2.0.0.0/24 is subnetted, 1 subnets 
  17. O       2.2.2.0 [110/3] via 34.1.1.3, 00:09:54, FastEthernet1/0 
  18.      3.0.0.0/24 is subnetted, 1 subnets 
  19. O       3.3.3.0 [110/2] via 34.1.1.3, 00:09:54, FastEthernet1/0 
  20.      4.0.0.0/24 is subnetted, 1 subnets 
  21. C       4.4.4.0 is directly connected, Loopback0 
  22.      5.0.0.0/32 is subnetted, 1 subnets 
  23. O       5.5.5.5 [110/65] via 45.1.1.5, 00:09:54, Serial0/0 
  24.      23.0.0.0/24 is subnetted, 1 subnets 
  25. O       23.1.1.0 [110/2] via 34.1.1.3, 00:09:56, FastEthernet1/0 
  26.      12.0.0.0/24 is subnetted, 1 subnets 
  27. O       12.1.1.0 [110/66] via 34.1.1.3, 00:09:56, FastEthernet1/0 
  28.      45.0.0.0/24 is subnetted, 1 subnets 
  29. C       45.1.1.0 is directly connected, Serial0/0 

  1.  tib entry: 5.5.5.0/24, rev 8 
  2.         remote binding: tsr: 55.5.5.5:0, tag: imp-null 
  3. 这是R5发送给R4 的,但是R4本身没有这条路由,所以本身没有给 这条路由分配标签。
     

  1.  tib entry: 5.5.5.5/32, rev 11 
  2.         local binding:  tag: 400 
  3.         remote binding: tsr: 3.3.3.3:0, tag: 304 
  4. 这是R3分发给R4的,因为R4本身也有这条5.5.5.5/32的路由,所以本身也会为这条路由分发标签。
     

5.5.5.5/32这条路由的下一跳是45.1.1.5,而标签表中:

  1.  tib entry: 5.5.5.5/32, rev 11 
  2.         local binding:  tag: 400 
  3.         remote binding: tsr: 3.3.3.3:0, tag: 304 

下一跳是3.3.3.3,这是矛盾的。所以这一标签不可用。

但是对于5.5.5.5/32这条路由,R4认为R5没有给自己这条路由,所以就untagged  了。

虽然这不影响整个网张的连通,你可以试一下,可以ping通整个网络。

但是显然影响到标签的连续性。MPLS网络最重要的是就标签的连续性问题,标签分配的不合理,生期可能会很麻烦。

所以这个问题是必须解决的。解决方法很简单,就是在每个路由器每个loopback 口启用:

ip ospf network point-to-point

这样就可以了。

这篇文章就到此为止了。不知道逻辑有没有混乱。如果有读者看了的话,觉得很混乱的,可以批评。