最近摆弄MPLS,发现很多人配置MPLS只是写了个简单的命令,对具体的原理解释说的很少。我们这篇文章就好好说下。

 

这是基本的拓扑图

1.为什么开发MPLS技术,它和传统的ip技术的区别?

我们知道传统的ip转发技术是基于路由表的,也就是说一个从入口来的数据包路由要检查ip 路由表才能做转发,这样的IP数据包网络,在网络设备传递数据包时,是根据数据包的IP包头信息进行交换的,也就是网络设备根据包头中的目标IP地址,来决定从哪个接口转发出去。所以在数据包当中,指导设备正确转发数据包的就是IP地址信息,而IP地址只是数据包的一个标识而已!那么我们为什么不能直接打个标签让路由通过硬件识别这个tag,从进行转发,这样岂不大大节省路由器处理数据包的时间,这就是MPLS产生的原因。不过那时还木有CEF MLS 这样的技术。

2:MPLS标签

 

其中EXP是关于qos相关的,一会说到这个

bos值是指示标签栈的,一个flow可以有多个标签,值为0,如果是栈底,就为1,在标签交互过程中只看顶部标签,这点注意

3.MPLS基本概念

入站LSR:接收没有标签的数据包,打上标签并发出

出站LSR:接收带有标签的数据包,移除标签,并发出,出站和入站LSR都是边缘LSR,所以它们同时连接了IP网络和MPLS网络。
链路中LSR:接收到带标签的数据包,对其进行操作,然后按正确的接×××换出去,所以链路中的LSR只进行标签转发
LSR操作过程
LSR可以执行三种操作:提取,添加和交换
提取,即从标签栈的顶部移除一个或多个标签,移除全部标签是出站LSR必须做的。
添加,向报文添加标签,如果没有标签,就加新的,入站LSR必须做的。
交换,收到一个有标签的报文,用新的标签交换到顶部,再发出,是链路中的LSR做的。

4.LDP工作流程

LDP是负责标签转发的协议,

(1)运行LDP的LSR发现

(2)会话的建立和维护

(3)标签映射通告
(4)使用通知来进行管理
LDP是需要像OSPF那样建邻居的,使用hello包发现和维护邻居关系,LDP会在启用了的接口上发送hello来找邻居,发送hello用UDP 646,目的地为224.0.0.2,hello时间和保持时间分别是5秒15秒。这个hello包是不能跨网段传递的,而这个hello包被称为LDP Link Hello。
R3#show mpls ldp parameters
Protocol version: 1
Downstream label generic region: min label: 16; max label: 100000
Session hold time: 180 sec; keep alive interval: 60 sec
Discovery hello: holdtime: 15 sec; interval: 5 sec
Discovery targeted hello: holdtime: 90 sec; interval: 10 sec
Downstream on Demand max hop count: 255
Downstream on Demand Path Vector Limit: 255
LDP for targeted sessions
LDP initial/maximum backoff: 15/120 sec
LDP loop detection: of

5.标签的交换过程

 

明白上下游,数据层面路由层面

R345运行mpls ,R1267ip

R1有个1.1.1.1到R6的6.6.6.6标签交换

在运行MPLS路由器上有3张表,路由表  cef表 标签转发表

R3#show ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       o - ODR, P - periodic downloaded static route

Gateway of last resort is not set

     34.0.0.0/24 is subnetted, 1 subnets
C       34.1.1.0 is directly connected, Serial0/3
     1.0.0.0/32 is subnetted, 1 subnets
D       1.1.1.1 [90/2297856] via 13.1.1.1, 00:43:06, Serial0/0
     3.0.0.0/32 is subnetted, 1 subnets
C       3.3.3.3 is directly connected, Loopback0
     4.0.0.0/32 is subnetted, 1 subnets
D       4.4.4.4 [90/2297856] via 34.1.1.4, 00:41:57, Serial0/3
     5.0.0.0/32 is subnetted, 1 subnets
D       5.5.5.5 [90/2809856] via 34.1.1.4, 00:41:17, Serial0/3
     6.0.0.0/32 is subnetted, 1 subnets
D       6.6.6.6 [90/3321856] via 34.1.1.4, 00:41:09, Serial0/3
     56.0.0.0/24 is subnetted, 1 subnets
D       56.1.1.0 [90/3193856] via 34.1.1.4, 00:41:18, Serial0/3
     13.0.0.0/24 is subnetted, 1 subnets
C       13.1.1.0 is directly connected, Serial0/0
     45.0.0.0/24 is subnetted, 1 subnets
D       45.1.1.0 [90/2681856] via 34.1.1.4, 00:41:23, Serial0/3

R3#show ip cef  
Prefix              Next Hop             Interface
0.0.0.0/0           drop                 Null0 (default route handler entry)
0.0.0.0/32          receive
1.1.1.1/32          13.1.1.1             Serial0/0
3.3.3.3/32          receive
4.4.4.4/32          34.1.1.4             Serial0/3
5.5.5.5/32          34.1.1.4             Serial0/3
6.6.6.6/32          34.1.1.4             Serial0/3
13.1.1.0/24         attached             Serial0/0
13.1.1.0/32         receive
13.1.1.3/32         receive
13.1.1.255/32       receive
34.1.1.0/24         attached             Serial0/3
34.1.1.0/32         receive
34.1.1.3/32         receive
34.1.1.255/32       receive
45.1.1.0/24         34.1.1.4             Serial0/3
56.1.1.0/24         34.1.1.4             Serial0/3
224.0.0.0/4         drop
224.0.0.0/24        receive
255.255.255.255/32  receive

R3#show mpls forwarding-table
Local  Outgoing    Prefix            Bytes tag  Outgoing   Next Hop   
tag    tag or VC   or Tunnel Id      switched   interface             
16     Untagged    1.1.1.1/32        0          Se0/0      point2point 
17     Pop tag     4.4.4.4/32        0          Se0/3      point2point 
18     Pop tag     45.1.1.0/24       0          Se0/3      point2point 
19     19          5.5.5.5/32        0          Se0/3      point2point 
20     20          56.1.1.0/24       0          Se0/3      point2point 
22     22          6.6.6.6/32        0          Se0/3      point2point

 虽然一条路由可以打了多标签,但是中间的LSR只根据最顶部的标签便可以做出转发。但是,每台LSR的转发表里都会为一条路由显示两个标签,一个是本地标签,一个是远程标签,要显示两个标签,是因为一台LSR收到数据包之后,就查看它的顶部标签,如果这个标签是某一条相应的本地标签,那么就从相应的接口发出去,同时在发出去的时候,就将数据包的顶部标签改为与这个本地标签对应的远程标签

我们从R5上开始看

R5#show mpls for
Local  Outgoing    Prefix            Bytes tag  Outgoing   Next Hop   
tag    tag or VC   or Tunnel Id      switched   interface             
16     Pop tag     4.4.4.4/32        0          Se0/2      point2point 
17     Pop tag     34.1.1.0/24       0          Se0/2      point2point 
18     16          3.3.3.3/32        0          Se0/2      point2point 
19     17          13.1.1.0/24       0          Se0/2      point2point 
20     18          1.1.1.1/32        0          Se0/2      point2point 
21     Untagged    6.6.6.6/32        1224       Se0/0      point2point

木有local标签是21,而出标签是untagged因为R6是ip网络

R4#show mpls for
Local  Outgoing    Prefix            Bytes tag  Outgoing   Next Hop   
tag    tag or VC   or Tunnel Id      switched   interface             
16     Pop tag     3.3.3.3/32        0          Se0/3      point2point 
17     Pop tag     13.1.1.0/24       1152       Se0/3      point2point 
18     16          1.1.1.1/32        0          Se0/3      point2point 
19     Pop tag     5.5.5.5/32        0          Se0/2      point2point 
20     Pop tag     56.1.1.0/24       0          Se0/2      point2point 
22     21          6.6.6.6/32        432        Se0/2      point2point

关于6.6.6.6路由条目在R4上local 是22 出标签21,意思就是凡事收到6.6.6.6路由条目把出标签是21并从s0/2口转发出去,我们发现R4的出标签就是R5的local标签,这也就是LDP协议的所在

R3#show mpls for
Local  Outgoing    Prefix            Bytes tag  Outgoing   Next Hop   
tag    tag or VC   or Tunnel Id      switched   interface             
16     Untagged    1.1.1.1/32        0          Se0/0      point2point 
17     Pop tag     4.4.4.4/32        0          Se0/3      point2point 
18     Pop tag     45.1.1.0/24       0          Se0/3      point2point 
19     19          5.5.5.5/32        0          Se0/3      point2point 
20     20          56.1.1.0/24       0          Se0/3      point2point 
22     22          6.6.6.6/32        0          Se0/3      point2point

之所以是两个22,local那个22是路由随意打得,木有啥实际意思

6.标签的定义

隐式空3标签

在MPLS网络中,P路由器是完全按照标签交换的,而边缘路由器PE是同时连接了MPLS网络和IP网络,因此,一个数据包在MPLS网络中传输到PE路由器的时候,PE路由器的工作是:结束标签交换过程,从而转入IP网络,而转入IP网络就要执行IP地址的查找。那么从此可以看出,一个标签数据包到达PE路由器之后,PE路由器第一步开始根据数据包的标签去查找LFIB表,通过查找LFIB之后发现已经不再是标签交换了,第二步就马上转入查IP路由表,最终在IP路由表里查到了结果,从IP网络中发出去。很明显,PE路由器既然最后不可能使用标签交换,而要使用IP交换的,又何必去查了LFIB表才知道结果呢。所以就考虑到一个方法,能不能让PE的上一跳路由器不要为数据包打标签,直接改成IP数据包就行了,这样上一跳路由器没有写标签,那么PE在收到数据包之后,就能马上查IP路由表而做出转发。在这里,要让PE的上一跳路由器不要为数据打标签而直接改成IP数据包,这还得需要PE来告诉它才行。正常情况下,PE路由器是告诉上一跳正常的标签,上一跳将这个标签变成远程标签,但现在,PE路由器就不应该告诉上一跳正常的标签,它告诉的是隐式空(标签号为3)标签,所以收到标签为3的LSR,就不会在数据包发给下一跳时打上标签。这种终点使用隐式空标签来告诉上一跳不要打标签的行为叫倒数第二跳移除(PHP)行为,所以一台收到隐式空标签的LSR,相应出口就不再是一个远程标签,而应该在outgoing显示为pop。这种上一跳标签移除称为标签弹出。
注:在IOS中,PHP这种行为是默认的,但只会为直连路由和聚合路由通告隐式空3,但3不会明写。
显示空标签
显示空的功能是在隐式空的基础上的,IPv4标签号为0,IPv6为2。
因为标签中EXP用于QOS,前一跳移除后,这些信息也没了,可能希望保留,所以是上一跳将标签变为0,来告诉终点不用为0查找LFIB,只看EXP,所以只关心QOS效果,这样也省事。
路由器报警标签1,只是需要特别注意,并且软件转发。
未保留的都可以用,20个bit,是16-1048575,IOS默认是16-10 0000,IGP够了,但BGP可能不够,可以查看和修改标签范围。

7.最后才是配置命令

mpls label protocol ldp
interface Loopback0
 ip address 3.3.3.3 255.255.255.255
interface Serial0/0
 ip address 13.1.1.3 255.255.255.0
 serial restart-delay 0
interface Serial0/1
 ip address 23.1.1.3 255.255.255.0
 serial restart-delay 0
interface Serial0/3
 ip address 34.1.1.3 255.255.255.0
 mpls ip
 serial restart-delay 0
router eigrp 100
 network 3.3.3.0 0.0.0.255
 network 13.1.1.0 0.0.0.255
 network 23.1.1.0 0.0.0.255
 network 34.1.1.0 0.0.0.255
 no auto-summary
mpls ldp router-id Loopback0 force

R3#show mpls int
Interface              IP            Tunnel   Operational
Serial0/3              Yes (ldp)     No       Yes        
还有一点说下

R3#show mpls ldp discovery de
 Local LDP Identifier:
    3.3.3.3:0
    Discovery Sources:
    Interfaces:
        Serial0/3 (ldp): xmit/recv
            Enabled: Interface config
            Hello interval: 5000 ms; Transport IP addr: 3.3.3.3 (必须保证可以连通)
            LDP Id: 4.4.4.4:0
              Src IP addr: 34.1.1.4; Transport IP addr: 4.4.4.4
              Hold time: 15 sec; Proposed local/peer: 15/15 sec
              Reachable via 4.4.4.4/32