1.       一些基本概念

标签(label ):MPLS 技术的关键。这是一个32 位的字段,20bit 的标签位,1bit 的栈底显示位,3bit EXP 位,8bit TTL 。插在第二层包头和第三层包头中间,可以插入多个标签实现其他的MPLS 技术。
 
TDP LDP TDP LDP 都是MPLS 下的标签交换协议,TDP Cisco 公司的私有技术,LDP 是公有技术。LDP 是从TDP 是继承而来的,他们之间的很多差别只是名词上的不同。
 
帧模式 信元模式:简单说,传统的IP 路由下运行MPLS 就是帧模式,在ATM 上运行MPLS 就是信元模式。他们之间有在使用TDP/LDP 的时候有许多不同!(由于实验环境的限制,我主要在学习帧模式)。
 

FIB转发信息库,这是开启CEF后形成的一个表,这个表结合了路由表,ARP表,它使得数据包转发的时候不需要再查询路由表,不再需要递归路由查询,直接根据FIB转发即可。注意:由于Cisco CEF是唯一使用FIB表的第三层交换机制,运行MPLS首先就要开启ip cef

 

LIB标签信息库,这张表里面保存了FEC对应的所有标签信息,使用show mpls ip binding查看

 

LFIB标签转发信息库,这张表是当前正在使用的标签信息,使用show mpls forward查看

 
FEC MPLS 就是针对FEC 来打标签。FEC 的划分在IGP 中根据每个路由条目,在BGP 中根据下一跳。
 

LSR标签交换路由器,就是启用了标签交换的路由器。

 

2.       实验演示

1)         拓扑

 

描述:四台路由器直连 R1 ß- àR2 ß àR3 ß àR4 ,四台路由器各开一个loopback 0 口宣告进EIGRP 

2)         基础配置

R1#sh ip int brief

Interface                   IP-Address      OK? Method Status                Protocol
Serial0/0                   12.1.1.1        YES manual up                     up       
Loopback0                   1.1.1.1         YES manual up                    up  
  

R1#sh run | b router eigrp 10

router eigrp 10
 passive-interface Loopback0
 network 1.1.1.1 0.0.0.0
 network 12.1.1.1 0.0.0.0
 no auto-summary
R2,R3,R4 配置略
 

3)         验证网络建立情况

R2#sh ip eigrp 10 nei

IP-EIGRP neighbors for process 10

H   Address  Interface       Hold Uptime   SRTT   RTO Q Seq

                            (sec)         (ms)            Cnt Num

1   23.1.1.3   Se0/1         12 00:08:34     82     492  0   10

0   12.1.1.1   Se0/0         10 00:09:01    101   606   0    3

R2#sh ip route eigrp 10

     34.0.0.0/24 is subnetted, 1 subnets

D       34.1.1.0 [90/2681856] via 23.1.1.3, 00:08:40, Serial0/1

     1.0.0.0/32 is subnetted, 1 subnets

D       1.1.1.1 [90/2297856] via 12.1.1.1, 00:09:08, Serial0/0

     3.0.0.0/32 is subnetted, 1 subnets

D       3.3.3.3 [90/2297856] via 23.1.1.3, 00:08:37, Serial0/1

     4.0.0.0/32 is subnetted, 1 subnets

D       4.4.4.4 [90/2809856] via 23.1.1.3, 00:08:21, Serial0/1

 
建立一个测试脚本进一步验证网络
R2#tclsh

R2(tcl)#foreach address {

+>(tcl)#1.1.1.1

+>(tcl)#2.2.2.2

+>(tcl)#3.3.3.3
+>(tcl)#4.4.4.4

+>(tcl)#} {

+>(tcl)#ping $address source loopback 0

+>(tcl)#}
 

Type escape sequence to abort.

Sending 5, 100-byte ICMP Echos to 1.1.1.1, timeout is 2 seconds:

Packet sent with a source address of 2.2.2.2

!!!!!

Success rate is 100 percent (5/5), round-trip min/avg/max = 28/41/52 ms

Type escape sequence to abort.

Sending 5, 100-byte ICMP Echos to 2.2.2.2, timeout is 2 seconds:

Packet sent with a source address of 2.2.2.2

!!!!!

Success rate is 100 percent (5/5), round-trip min/avg/max = 1/2/4 ms

Type escape sequence to abort.

Sending 5, 100-byte ICMP Echos to 3.3.3.3, timeout is 2 seconds:

Packet sent with a source address of 2.2.2.2

!!!!!

Success rate is 100 percent (5/5), round-trip min/avg/max = 28/36/64 ms

Type escape sequence to abort.

Sending 5, 100-byte ICMP Echos to 4.4.4.4, timeout is 2 seconds:

Packet sent with a source address of 2.2.2.2

!!!!!

Success rate is 100 percent (5/5), round-trip min/avg/max = 60/68/80 ms

通了,基础配置完成。
 

4)         建立MPSL网络

1.         首先启用CEF,这个是必须的。

2.         定义标签交换使用的协议。

3.         定义标签的范围。

4.         定义建立LDP对等体使用的接口(TDP/LDP都是基于TCP来建立对等体的,与BGP一样,安全可靠,建议使用loopback接口,因为永远不会当掉)。

5.         在接口下启用mpls

6.         验证邻居建立情况。

7.         查看FIBLFIB

8.         测试标签交换。

 
1- à5: 基础配置
下面给出R1 上的相关配置
ip cef

mpls label protocol ldp

mpls label range 100 199

mpls ldp router-id Loopback0 force

 

interface Serial0/0

 description **--->R2:S0/0**
 ip address 12.1.1.1 255.255.255.0
 mpls ip 
 
上面五步已经完成了上面的五步。其实有些命令是默认的,比方说第二步可以不写,那么默认就是用TDP cisco );第三步不写一般就是随机了(cisco <16-1048575> ),第四步也可以不写,那么就是用直连接口;第1 步与第5 步是必须的!
 
6 :验证邻居建立情况
         R2#sh 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.39114

        State: Oper; Msgs sent/rcvd: 23/23; Downstream

        Up time: 00:11:53
        LDP discovery sources:
          Serial0/0, Src IP addr: 12.1.1.1
        Addresses bound to peer LDP Ident:
          12.1.1.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.24687 - 2.2.2.2.646

        State: Oper; Msgs sent/rcvd: 22/23; Downstream

        Up time: 00:11:02
        LDP discovery sources:
          Serial0/1, Src IP addr: 23.1.1.3
        Addresses bound to peer LDP Ident:
          23.1.1.3        34.1.1.3        3.3.3.3        
         如上输出所示,R2 分别与R1,R3 建立了LDP peer         
Peer LDP Ident: 1.1.1.1:0; Local LDP Ident 2.2.2.2:0 这句话的意思是说peer 间建立LDPpeer 使用的ID ,就是我们前面定义的loopback 0

TCP connection: 1.1.1.1.646 - 2.2.2.2.39114

 
TCP connection: 1.1.1.1.646 - 2.2.2.2.39114 这句话的意思是说建立peer TCP 是如何连接的,注意这里的1.1.1.1 2.2.2.2 与上面的ID 并不一定要相同,有时候就会不同,在后续的文章中会有探讨。这里使用了两个port 646 LDP 使用的端口,39114 是随机端口,安全起见。
 

Addresses bound to peer LDP Ident:

         12.1.1.1        1.1.1.1

这句话的意思说明了对等体的端口IP 。这里我研究不多。
 
其他的字面意思都够清楚了,不再赘言。
 
7. 查看FIB LFIB

R1#sh mpls ldp bindings

 tib entry: 1.1.1.1/32, rev 4
        local binding: tag: imp-null

        remote binding: tsr: 2.2.2.2:0, tag: 201

 tib entry: 2.2.2.2/32, rev 6
        local binding: tag: 101

        remote binding: tsr: 2.2.2.2:0, tag: imp-null

 tib entry: 3.3.3.3/32, rev 8
        local binding: tag: 102

        remote binding: tsr: 2.2.2.2:0, tag: 202

 tib entry: 4.4.4.4/32, rev 10
        local binding: tag: 103

        remote binding: tsr: 2.2.2.2:0, tag: 203

 tib entry: 12.1.1.0/24, rev 14
        local binding: tag: imp-null

        remote binding: tsr: 2.2.2.2:0, tag: imp-null

 tib entry: 23.1.1.0/24, rev 12
        local binding: tag: 104

        remote binding: tsr: 2.2.2.2:0, tag: imp-null

 tib entry: 34.1.1.0/24, rev 2
        local binding: tag: 100

        remote binding: tsr: 2.2.2.2:0, tag: 200

 
在基础概念中已经提到过,FIB 就是存储的是所有的标签信息,也就是路由表中的所有条目的信息。
tib entry: 1.1.1.1/32, rev 4

        local binding:  tag: imp-null

        remote binding: tsr: 2.2.2.2:0, tag: 201

tib :其实就是FIB ,只是一个不同的叫法。

Local bingdingtag: imp-null本地绑定为空

因为1.1.1.1 R1 自身的直连网段,已经到达目的地了,就不用再给自己打标签了。但是你在debug 的时候还是会发现他给自己的peer 通告一个不在空配置标签范围内的标签。如下所示:

*Mar 1 01:18:20.291: tagcon: peer 1.1.1.1:0 (pp 0x64962BDC): advertise 2.2.2.2/32(Default-IP-Routing-Table), label 3 (imp-null) (#6)

这个标签值是3.这个标签代表一个空标签,pop tag就是根据这个标签值来实现的。详细的内容会在后面的有讲述。

 

Remote bindingtsr: 2.2.2.2:0, tag: 201 远程绑定:标签交换路由器(tsr):2.2.2.2,打标签201

这句话的意思就是,告诉2.2.2.2 这个tsr ,到1.1.1.1 这个网段,你打标签201 后再转发过来。
本地绑定和远程绑定是一个相对的概念,自身网段的本地绑定就是自己邻居针对这个网段的远程绑定。
我们看看R2 FIB 1.1.1.1 条目

R2#sh mpls ip bind

 1.1.1.1/32

        in label:    201      

        out label:    imp-null lsr: 1.1.1.1:0        inuse

        out label:    30        lsr: 3.3.3.3:0

….OMITED
如上所示,远程绑定为空。
 
再看看一个非直连网段是如何打标签的

 tib entry: 2.2.2.2/32, rev 6

        local binding: tag: 101

        remote binding: tsr: 2.2.2.2:0, tag: imp-null

2.2.2.2 是从R2 接收到的,本地绑定是101 ,远程绑定为空。本地绑定为101 就是说如果我要发一个包到2.2.2.2 ,那么我就打上标签101 然后发出去。远程绑定为空,这是因为2.2.2.2 R2 的直连网段,所以R2 没有给自己的网段打标签。
再来看一个非直连网段,且不是与自己直连邻居的直连网段如何打标签
tib entry: 3.3.3.3/32, rev 8

        local binding: tag: 102

        remote binding: tsr: 2.2.2.2:0, tag: 202

3.3.3.3 R3 的直连网段,所以这里的远程绑定不再是空了。R1 要去往这个网段要经过R2 ,本地绑定是102 ,远程绑定是202 ,那么R1 如果发送一个数据包去3.3.3.3 ,该如何绑定呢?
它会打上202 然后发送出去。
102 会发送给其他的邻居,如果R1 后面还有其他peer 需要经过R1 到达R3 的话,这个102 就会出现在他们的远程绑定中。
 
更深入的内容会在后续的文章中慢慢探讨。标签是如何打的如何交换的很重要,以后可以单独单间一个复杂点的环境细细的研究一下。
 
再看LFIB

R2#sh mpls forwarding-table

Local Outgoing    Prefix            Bytes tag Outgoing   Next Hop   

tag    tag or VC   or Tunnel Id      switched   interface             

200    Pop tag     34.1.1.0/24       0          Se0/1      point2point 

201    Pop tag     1.1.1.1/32        0          Se0/0      point2point 

202    Pop tag     3.3.3.3/32        0          Se0/1      point2point 

203    32          4.4.4.4/32        0          Se0/1      point2point

清爽多了!
这里要重点学习pop tag ,即“倒数第二跳弹出”机制,为了提供转发效率。在上面的输出中,R2 是到达1.1.1.1 3.3.3.3 34.1.1.0 的倒数第二跳,那么我们还打一个标签转发到目的地有没有必要?没必要!因为多了一道拆包的工序啊,先拆标签,再拆第三层IP 包头,没必要啊,直接拆IP 包头就可以了,反正这一步是少不了的。那么拆标签这道工序就是无谓的,可以省掉。也就是说,最后一跳路由器告诉倒数第二跳路由器,“我已经是目的地了, 你发一个空标签过来就行了”。那么倒数第二跳路由器就会pop tag
Pop tag 后发送过去的是一个空标签,这个标签使用的是一个特殊的标签值:3 。在本文的稍前部分曾引用过一个debug 输出如下所示:

*Mar 1 01:18:20.291: tagcon: peer 1.1.1.1:0 (pp 0x64962BDC): advertise 2.2.2.2/32(Default-IP-Routing-Table), label 3 (imp-null) (#6)

这是R2 发给peer R1 的,意思就是告诉R1 2.2.2.2 是我的直连网段,你以后发送到达这个网段的数据包达标签订饿时候,打空标签!
空标签有隐式空标签和显式空标签之分。后者是为了实现EXP 位的功能,即MPLS 中的QoS 。具体内容在《MPLS 技术架构》中有描述。
 
还可以查看CEF 对某个具体网段的转发信息,在学习MPLS ××× 的时候会得到很有用的信息。
R2#sh ip cef 4.4.4.4

4.4.4.4/32, version 21, epoch 0, cached adjacency to Serial0/1

0 packets, 0 bytes

 tag information set

    local tag: 203

    fast tag rewrite with Se0/1, point2point, tags imposed: {32}

 via 23.1.1.3, Serial0/1, 0 dependencies

    next hop 23.1.1.3, Serial0/1

    valid cached adjacency

tag rewrite with Se0/1, point2point, tags imposed: {32}

 
8. 测试标签交换
R1#tra 4.4.4.4
Type escape sequence to abort.
Tracing the route to 4.4.4.4

 1  12.1.1.2 [MPLS: Label 203 Exp 0] 148 msec 72 msec 112 msec

 2  23.1.1.3 [MPLS: Label 32 Exp 0] 140 msec 72 msec 112 msec

 3  34.1.1.4 92 msec * 68 msec
 
下面是整个LSP 的标签交换的LFIB
R1#sh mpls for | in 4.4.4.4
108     203         4.4.4.4/32        0          Se0/0      point2point
R2#sh mpls for | in 4.4.4.4
203     32          4.4.4.4/32        432        Se0/1      point2point
R3#sh mpls for | in 4.4.4.4

32     Pop tag     4.4.4.4/32    1224       Se0/2      point2point 

R4#sh mpls for | in 4.4.4.4
none
 
这样就不难理解了。
好,今天告一段落!