SR-MPLS前三个小实验

发布时间 2023-04-17 18:56:02作者: 张贺贺呀

SR-MPLS_OSPF

image-20230417184702147

前四步

第一步:完成基础配置:接口IP和OSPF

第二步:全局使能SR,没错,我们这里面的实验就是MPLS-SR,即使用MPLS-SR框架的SR,所以MPLS框架还是要配置的(所有设备)

第三步:全局使能SR(所有设备)

第四步:启用扩展OSPF(所有设备)

CX1:
	system-view immediately 
	sysn CX1
	undo dcn
	int l0
		ip add 10.0.1.1 32
	int ether1/0/0
		ip add 10.0.12.1 24
	ospf 1 router-id 10.0.1.1
	a 0
	network 10.0.1.1 0.0.0.0
	network 10.0.12.1 0.0.0.0
	
CX2:
	system-view immediately 
	sysn CX2
	undo dcn
	int l0
		ip add 10.0.2.2 32
	int ether1/0/0
		ip add 10.0.12.2 24
	int ether1/0/2
		ip add 10.0.26.2 24
	int ether1/0/1
		ip add 10.0.23.2 24
		
	
	ospf 1 router-id 10.0.2.2
	a 0
	network 10.0.2.2 0.0.0.0
	network 10.0.12.2 0.0.0.0
	network 10.0.23.2 0.0.0.0

CX3:
	system-view immediately 
	sysn CX3
	undo dcn
	int l0
		ip add 10.0.3.3 32
	int ether1/0/0
		ip add 10.0.23.3 24
	int ether1/0/1
		ip add 10.0.34.3 24
		
	
	ospf 1 router-id 10.0.3.3
	a 0
	network 10.0.3.3 0.0.0.0
	network 10.0.23.3 0.0.0.0
	network 10.0.34.3 0.0.0.0

CX4:
	system-view immediately 
	sysn CX4
	undo dcn
	int l0
		ip add 10.0.4.4 32
	int ether1/0/0
		ip add 10.0.34.4 24
	int ether1/0/1
		ip add 10.0.45.4 24
		
	
	ospf 1 router-id 10.0.4.4
	a 0
	network 10.0.4.4 0.0.0.0
	network 10.0.34.4 0.0.0.0
	network 10.0.45.4 0.0.0.0
	
CX5:
	system-view immediately 
	sysn CX5
	undo dcn
	int l0
		ip add 10.0.5.5 32
	int ether1/0/0
		ip add 10.0.45.5 24
		
	ospf 1 router-id 10.0.5.5
	a 0
	network 10.0.5.5 0.0.0.0
	network 10.0.45.5 0.0.0.0
# 全局使能MPLS
system-view immediately
 	mpls
 	quit
 
# 全局使能SR
segment-routing

# 去OSPF当中使能SR
ospf
	a 0
	opaque-capability enable
	segment-routing mpls

简单解释一下,第四行的时候全局启动SR,第七行的意思是在在OSPF内部启用10类的LSA透传功能,第八行的时候是在在OSPF内部使能MPLS-SR功能,注意看哈,几乎所有的功能配置全都在OSPF内部,足以说明MPLS-SR是以IGP协议为主了。

[CX1]dis tunnel-info all
[CX1]dis ospf lsdb opaque-area originate-router 10.0.3.3

通过第一条命令查看隧道的时候会发现是空的,因为现在没有建立隧道,为什么?如果这时候使用的LDP这时候就应该会建立完LSP了,但是现在被扩展之后的的OSPF并没有建立隧道,说明现在还没有触发建立隧道的条件,那建立隧道的条件是什么?其实很简单就是遇到其它设备通告的全局标签空间(SRGB)和索引(index),那这两者如何发送到本设备上来呢?肯定是通过OSPF的LSA呀!所以我们可以通过上述第二条命令查看对方向自己发送的LSA信息,然后我们就可以看到CX3向自己通告的10类LSA,10类的并且里面又分为三个链路状态信息:一个type-4,两个type-8,type-4描述提CX3的环回接口,而type-8所描述的信息就是CX3上两个物理链路的信息,注意查看里面并没有生成标签必需的两个信息标签空间和索引,正是因为没有这两个关键的信息,所以并没有建立隧道,如下所示,但要注意,这个时候已经出现标签了,但是这个标签没啥意义,并不能用来做数据转发或建立隧道。

[CX1]dis ospf lsdb opaque-area originate-router 10.0.3.3

          OSPF Process 1 with Router ID 10.0.1.1
                          Area: 0.0.0.0
                  Link State Database


  Type      : Opq-Area  ##
  Ls id     : 4.0.0.0
  Adv rtr   : 10.0.3.3
  Ls age    : 103
  Len       : 28
  Options   :  E
  seq#      : 80000006
  chksum    : 0x6fc4
  Opaque Type: 4      ##
  Opaque Id: 0
  Router-Information LSA TLV information:
    SR-Algorithm TLV:
      Algorithm: SPF  ##

  Type      : Opq-Area
  Ls id     : 8.0.0.0
  Adv rtr   : 10.0.3.3
  Ls age    : 1581
  Len       : 48
  Options   :  E
  seq#      : 80000005
  chksum    : 0x8944
  Opaque Type: 8
  Opaque Id: 0
  OSPFv2 Extended Link Opaque LSA TLV information:
    OSPFv2 Extended Link TLV:
      Link Type: TransNet
      Link ID: 10.0.23.2 
      Link Data: 10.0.23.3        
      Adj-SID Sub-TLV:
        Flags: 0x60 (-|V|L|-|-|-|-|-)
        MT ID: 0 
        Weight: 0
        Label: 48080    ##

  Type      : Opq-Area
  Ls id     : 8.0.0.1
  Adv rtr   : 10.0.3.3
  Ls age    : 1581
  Len       : 52
  Options   :  E
  seq#      : 80000005
  chksum    : 0xb4e0
  Opaque Type: 8
  Opaque Id: 1
  OSPFv2 Extended Link Opaque LSA TLV information:
    OSPFv2 Extended Link TLV:
      Link Type: TransNet
      Link ID: 10.0.34.3 
      Link Data: 10.0.34.3        
      LAN Adj-SID Sub-TLV:
        Flags: 0x60 (-|V|L|-|-|-|-|-)
        MT ID: 0 
        Weight: 0
        Neighbor ID: 10.0.4.4
        Label: 48081  

第五步

第五步:接着是关键操作了,配置全局块和索引,先在CX3上配置,配置完成之后再去CX1上查看

[CX3]ospf
[CX3-ospf-1]segment-routing global-block 16000 17000
[CX3-ospf-1]int l0
[CX3-LoopBack0]ospf prefix-sid index 3

[CX1]dis ospf lsdb opaque-area originate-router 10.0.3.3
[CX1]dis ospf lsdb opaque-area originate-router 10.0.3.3

          OSPF Process 1 with Router ID 10.0.1.1
                          Area: 0.0.0.0
                  Link State Database


  Type      : Opq-Area
  Ls id     : 4.0.0.0
  Adv rtr   : 10.0.3.3
  Ls age    : 8
  Len       : 44
  Options   :  E
  seq#      : 80000007
  chksum    : 0x144a
  Opaque Type: 4
  Opaque Id: 0
  Router-Information LSA TLV information:
    SR-Algorithm TLV:
      Algorithm: SPF
    SID/Label Range TLV:
      Range Size: 1001
      SID/Label Sub-TLV:
        Label: 16000
                
  Type      : Opq-Area
  Ls id     : 7.0.0.0
  Adv rtr   : 10.0.3.3
  Ls age    : 8
  Len       : 44
  Options   :  E
  seq#      : 80000001
  chksum    : 0x1289
  Opaque Type: 7       ## 出现了七类,七类专门用来运载index的
  Opaque Id: 0
  OSPFv2 Extended Prefix Opaque LSA TLV information:
    OSPFv2 Extended Prefix TLV: 
      Route Type: Intra-Area 
      AF: IPv4-Unicast 
      Flags: 0x40 (-|N|-|-|-|-|-|-)  # N的意思10.0.3.3是一个节点,也是一个链路
      Prefix: 10.0.3.3/32 
      Prefix SID Sub-TLV:
        Flags: 0x00 (-|-|-|-|-|-|-|-)
        MT ID: 0 
        Algorithm: SPF
        Index: 3  

  Type      : Opq-Area
  Ls id     : 8.0.0.0
  Adv rtr   : 10.0.3.3
  Ls age    : 1765
  Len       : 48
  Options   :  E
  seq#      : 80000005
  chksum    : 0x8944
  Opaque Type: 8
  Opaque Id: 0
  OSPFv2 Extended Link Opaque LSA TLV information:
    OSPFv2 Extended Link TLV:
      Link Type: TransNet
      Link ID: 10.0.23.2 
      Link Data: 10.0.23.3        
      Adj-SID Sub-TLV:
        Flags: 0x60 (-|V|L|-|-|-|-|-)
        MT ID: 0 
        Weight: 0
        Label: 48080  

  Type      : Opq-Area
  Ls id     : 8.0.0.1
  Adv rtr   : 10.0.3.3
  Ls age    : 1765
  Len       : 52
  Options   :  E
  seq#      : 80000005
  chksum    : 0xb4e0
  Opaque Type: 8
  Opaque Id: 1
  OSPFv2 Extended Link Opaque LSA TLV information:
    OSPFv2 Extended Link TLV:
      Link Type: TransNet
      Link ID: 10.0.34.3 
      Link Data: 10.0.34.3        
      LAN Adj-SID Sub-TLV:
        Flags: 0x60 (-|V|L|-|-|-|-|-)
        MT ID: 0 
        Weight: 0
        Neighbor ID: 10.0.4.4
        Label: 48081  
[CX1]

目前只有CX3向外通告了全局块和index,这上时候我们在CX1和CX2上使用dis tunnel-info all命令发现依然是空的,也就说即使现在R3向外发布了全局块和索引,也没有形成隧道,为什么?因为隧道的建立必须必须有入标签和出标签,当前CX2已经收到了CX3的全局块和索引,并且已经已经这两个信息计算出了出标签是3,为什么CX2认为去往CX3的10.0.3.3出标签是3呢?MPLS的次末跳弹出效应,CX2知道去往CX3的10.0.3.3就在自己下一跳,所以将其出标签置为3,意思是如果有数据包想通过自己(CX2)到达CX3的10.0.3.3,那自己会将其标签弹出。注意哈,这个3当前是没有地方查看的,因为出标签出入标签是成对出现的,目前CX2只计算出了出标签,而没有计算出入标签!为什么没有计算出入标签呢?出标签的计算是根据下一跳的全局块和索引生成的,按理说我们在CX2看到应该是是16003,但正是因为次末跳弹出效应导致我们看到的是3,入标签是根据本地全局块和CX3的索引生成的,而当前CX2没有配置全局块所以入标签计算不出来,我们通过”[CX2]dis segment-routing prefix mpls forwarding”也就看不到,那现在其实就只需要CX2的全局块就可以了,那我们在CX2上把全局块上就可以了吧,如下所示:

[CX2]ospf
[CX2-ospf-1]segment-routing global-block 22000 22999

OK,现在该有的条件都已经有了,那现在其实CX2到CX3之间就已经建立了单向隧道了,如下所示:

[CX2]dis tunnel-info all
Tunnel ID            Type                Destination                            
 Status
--------------------------------------------------------------------------------
--------
0x000000002900000044 srbe-lsp            10.0.3.3                               
 UP

而且,入标签和出标签都已经生成了,如下所示:

[CX2]dis segment-routing prefix mpls forwarding 

                   Segment Routing Prefix MPLS Forwarding Information
             --------------------------------------------------------------
             Role : I-Ingress, T-Transit, E-Egress, I&T-Ingress And Transit

Prefix             Label      OutLabel   Interface         NextHop          Role
  MPLSMtu   Mtu     State          
--------------------------------------------------------------------------------
---------------------------------
10.0.3.3/32        22003      3          Eth1/0/1          10.0.23.3        I&T 
  ---       1500    Active

出标签其实是16003,因次末跳的时候所以这里面显示为3;入标签22003是怎么来的呢?用自己的全局块加上10.0.3.3的索引得来的。

第六步

第六步:把CX2和CX1剩余的配置补齐

[CX2]int l0
[CX2-LoopBack0]ospf prefix-sid index 2
[CX1]int l0
[CX1-LoopBack0]ospf prefix-sid index 1
[CX1-LoopBack0]ospf
[CX1-ospf-1]segment-routing global-block 20000 21000

image-20230417152616813

OK,我们现在来一个总结:

  • CX1:全局块是20000 21000,索引是1
  • CX2:全局块是22000 22999,索引是2
  • CX3:全局块是16000 17000,索引是3

那我们在CX1角度来看一下关于10.0.3.3的入标签和出标签都是怎样形成的?

  • 出标签是由nexthop(CX2)的全局块加上10.0.3.3的索引,即22000+3=22003
  • 本地标签是由CX1自己的的全局块加上10.0.3.3的索引,即20000+3=20003

另一种方式

# 这么做范围不对,超出了全局块的限制
[CX2-LoopBack0]ospf prefix-sid absolute 16222
Warning: The prefix-sid is beyond the range of OSPF segment-routing global-block
. If this prefix-sid is configured, it is not advertised.

# 这么做是可以的,这样标签就不用做计算了
[CX2-LoopBack0]ospf prefix-sid absolute 22222
<CX2>dis segment-routing prefix mpls forwarding 

                   Segment Routing Prefix MPLS Forwarding Information
             --------------------------------------------------------------
             Role : I-Ingress, T-Transit, E-Egress, I&T-Ingress And Transit

Prefix             Label      OutLabel   Interface         NextHop          Role  MPLSMtu   Mtu     State          
-----------------------------------------------------------------------------------------------------------------
10.0.1.1/32        22001      3          Eth1/0/0          10.0.12.1        I&T   ---       1500    Active          
10.0.3.3/32        22003      3          Eth1/0/1          10.0.23.3        I&T   ---       1500    Active          
10.0.2.2/32        22222      NULL       Loop0             127.0.0.1        E     ---       1500    Active

# 我们再从CX2上看一下
<CX1>dis segment-routing prefix mpls forwarding 

                   Segment Routing Prefix MPLS Forwarding Information
             --------------------------------------------------------------
             Role : I-Ingress, T-Transit, E-Egress, I&T-Ingress And Transit

Prefix             Label      OutLabel   Interface         NextHop          Role  MPLSMtu   Mtu     State          
-----------------------------------------------------------------------------------------------------------------
10.0.1.1/32        20001      NULL       Loop0             127.0.0.1        E     ---       1500    Active          
10.0.3.3/32        20003      22003      Eth1/0/0          10.0.12.2        I&T   ---       1500    Active          
10.0.2.2/32        20222      3          Eth1/0/0          10.0.12.2        I&T   ---       1500    Active

CX1上20222是怎么来的呢?实际上CX3向外的传的时候将22222减去了全局块,也就是把222发送出去了,CX1收到后通过下一跳也就是CX2的全局块加上222,于是就有了20222了!

SR-MPLS_ISIS

image-20230417184556671

在R3、R4、R5上做

CX3的操作:

# CX3的操作
Isis 1
	network-entity 49.0001.0000.0000.3333.00
	is-name CX3
	is-level level-2
	cost-style wide
	segment-routing mpls
	segment-routing global-block 16000 17000
int l0
	isis en
	isis prefix-sid index 3
int Ethernet 1/0/1
	isis enable


# CX4的操作
Isis 1
	network-entity 49.0001.0000.0000.4444.00
	is-name CX4
	is-level level-2
	cost-style wide
	segment-routing mpls
	segment-routing global-block 16000 17000
int l0
	isis en
	isis prefix-sid index 4
int Ethernet 1/0/0
	isis enable
int Ethernet 1/0/1
	isis enable

# CX5的操作
Isis 1
	network-entity 49.0001.0000.0000.5555.00
	is-name CX5
	is-level level-2
	cost-style wide
	segment-routing mpls
	segment-routing global-block 16000 17000
int l0
	isis en
	isis prefix-sid index 5
int Ethernet 1/0/1
	isis enable

可以做一下路由引入,将ISIS的路由条目引入到OSPF当中,会产生11类的,如下所示:

Type 10 Opaque (Area-Local Scope) Database
 Type      LinkState ID    AdvRouter        Age  Len   Sequence   Area           
 Opq-Area  4.0.0.0         10.0.1.1        1349  44    80000005   0.0.0.0        
 Opq-Area  4.0.0.0         10.0.2.2        1389  44    80000003   0.0.0.0        
 Opq-Area  4.0.0.0         10.0.3.3           2  44    80000004   0.0.0.0        
 Opq-Area  7.0.0.0         10.0.1.1        1349  44    80000002   0.0.0.0        
 Opq-Area  7.0.0.0         10.0.3.3        1478  44    80000002   0.0.0.0        
 Opq-Area  7.0.0.1         10.0.2.2         819  44    80000002   0.0.0.0        
 Opq-Area  8.0.0.0         10.0.3.3           2  52    80000003   0.0.0.0        
 Opq-Area  8.0.0.1         10.0.1.1        1596  52    80000002   0.0.0.0        
 Opq-Area  8.0.0.1         10.0.2.2        1596  48    80000002   0.0.0.0        
 Opq-Area  8.0.0.2         10.0.2.2        1593  48    80000002   0.0.0.0        

                  Type 11 Opaque (AS Scope) Database
 Type      LinkState ID    AdvRouter        Age  Len   Sequence  
 Opq-As    7.0.0.0         10.0.3.3           2  44    80000001  
 Opq-As    7.0.0.1         10.0.3.3           2  44    80000001