1. 程式人生 > >筆記 STP

筆記 STP

stp

STP
-定義
-作用
-類型
1、802.1d - STP :生成樹協議 PVST/PVST+(思科)
2、802.1w - RSTP :快速生成樹協議 PV-RSTP(思科)
3、802.1s - MSTP :多生成樹協議
-報文

PVST:per-vlan STP,即在每個 VLAN 內部都運行一個 STP (802.1d);

STP的工作過程:
1、確定交換機的角色
根交換機:整個交換網絡中,有且只有一個;
非根交換機:剩余的其他交換機,都稱之為非根交換機

    註意:
        每一個非根交換機都會計算出一條去往根交換機的最短的、
        無環、2層數據轉發路徑,並且最終該路徑是“轉發”狀態;

        選舉原則:
              比較每個交換機的 BID (bridge ID):優先級+MAC地址
              優先級:默認值為 32768 ; 2個字節;
              MAC地址:使用的是交換機的主板MAC;6個字節;
                 比較原則 - 
                       首先比較優先級,越小越好;
                       其次比較MAC地址,越小越好;

2、確定端口的角色
        根端口:在每一個非根交換機上,有且只有一個;
                距離根交換機最近的端口;

        指定端口:在每一個"網段/segment"中,有且只有一個;
                距離根交換機最近的端口;

        非指定端口:其他所有端口,都叫做“非指定端口”

3、確定端口的狀態
        down       -關閉(指的是當前端口沒有啟動STP)

        listening  -偵聽,此時偵聽的是網絡中的所有的BPDU
                          目的是為了確定交換機和端口的角色;
                          端口在該狀態停留15s;

        learning   -學習,該階段主要是學習端口上收到的數據幀
                           的源MAC地址,從而形成 MAC地址表;
                           端口在該狀態停留15s;

        forwarding -轉發(最終狀態),該狀態實現數據包的發送和接收

        blocking   -阻塞(最終狀態),該狀態不能發送和接收數據包;
                                    只能接收 BPDU。

BPDU類型:
1、配置BPDU
用於創建和維護 STP 無環轉發路徑樹
2、TCN BPDU
只有當 STP 無環轉發路徑樹(拓撲)變化的時候,才會
產生並發送。
並且是:感知到該變化的交換機,產生 TCN BPDU ,只
發送給根交換機,然後再由根交換機轉發給其他的所有
非根交換機;

STP計時器:
hello:交換機周期性發送 BPDU 的時間間隔,默認是 2s ;
forward-delay : 轉發延遲,默認時間為15s ;
max-age:最大老化時間,默認時間為 20s ;


STP參數修改(思科):
1、修改交換機的 STP 優先級 (確保網絡中有主根交換機和輔根交換機)
spanning-tree vlan x priority {value} , value 是4096的倍數

2、修改交換機的 STP 模式 (必須確保網絡的所有交換機的STP模式相同)
        spanning-tree mode  {pvst | rapid-pvst | mstp }

3、修改交換機的 端口  cost 
        interface fas0/22 (該鏈路指的是 trunk 鏈路)
           spanning-tree  vlan 3 cost {value} 
4、針對某個 VLAN ,關閉 STP 功能
        no spanning-tree vlan x 

STP參數修改(華為):
1、修改交換機的 STP 優先級:
[SW] stp priority {value} -> 必須得是4096的倍數

2、修改交換機的 STP 模式
[SW] stp mode {stp | rstp | mstp }
3、修改交換機的端口的 STP cost :
[SW]interface fas0/13
[sw-fas0/13]stp cost {value}
4、在交換機上關閉/開啟 STP :
[sw]stp disable -> 關閉 STP ;
[sw]stp enable -> 開啟 STP ,默認是開啟的;

驗證命令:
show spanning-tree vlan x ->可以查看交換機上關於 VLAN x 的 STP 信息
show spanning-tree ->可以查看交換機上關於所有VLAN的 STP 信息
show spanning-tree summary ->可以查看交換機運行的 STP 的模式;
show version -> 可以查看交換機的 base mac ;

display  stp  
display  stp brief 

註意:
交換機上的 STP 功能,默認都是開啟的;可以人工關閉;

=============================================================
MSTP的配置:

  • MST域(region),同一個域中,可以同時包含多個實例;
  • MSTI(instance),即MST 實例,一個MSTI 可以同時關聯多個 VLAN ;

    配置 MST region
    [SW]stp region-configuration
    [sw-mstp-region]region-name {string} //配置 region 的名字;
    [sw-mstp-region]instance {id} vlan x y z m n //配置關聯的VLAN
    [sw-mstp-region]active region-configuration
    [sw-mstp-region]display this
    配置 MSTI
    [sw1]stp instance {id} priority {value} <-將 SW1設置為 實例id 的根;

    驗證命令:
    display stp instance {id}
    display stp brief
    註意:
    默認情況下,所有的 VLAN 都是屬於 instance 0 ; (系統的默認instance)
    一個MSTP網絡中,可以同時包含多個 region ;
    每個MST Region 中,可以包含多個 instance (MSTI)
    屬於相同 region 的交換機上,以下參數必須相同:
    #region-name
    #實例與vlan的映射關系必須相同

    屬於同一個 region 中的多個交換機之間,可以基於 instance 進行
    流量的負載均衡和備份;

=====================================================================

STP 收斂速度比較慢 :30-50s

RSTP收斂速度要比 STP 快,因為做了以下改進:
1、發現問題比較快

2、反應/傳輸問題比較快
發現拓撲變更的交換機,會產生TCN BPDU,直接發送給與自己相連
的其他所有交換機;

3、解決問題比較快

端口角色細化:

根端口(root port ) 
指定端口 (designated port )  
替代端口(alternative port ):是根端口的備胎;
備份端口(bakcup port ):是指定端口的備胎

(邊緣端口:一般都建議關閉 STP ;或者將連接非交換機的端口,設置非邊緣端口)


端口狀態精簡化:
learning :學習
forwarding :轉發
discarding :丟棄,相當於之前 STP 中的 down / blocking / listening


案例:

1 案例1:STP算法
1.1 問題
選擇出根網橋、根端口、指定端口、被阻塞的端口。

1.2 方案
如圖-1所示:

技術分享圖片

1.3 步驟
實現此案例需要按照如下步驟進行。

1)每個廣播域選擇根網橋(Root Bridge)

每個非根網橋選擇根端口(Root Ports)
每個網段上選擇指定端口(Designated Ports)
2)結果如圖-2所示

技術分享圖片

2 案例2:配置STP
2.1 問題
首先查看當前根網橋,然後通過修改交換機的優先級來分配根網橋。

2.2 方案
使用eNSP搭建實驗環境,如圖-3所示。

技術分享圖片

2.3 步驟
實現此案例需要按照如下步驟進行。

[A]stp mode stp
[B]stp mode stp
[C]stp mode stp
[D]stp mode stp
[A]dis stp
-------[CIST Global Info][Mode STP]-------
CIST Bridge :32768.4c1f-cc3b-03cb
Config Times :Hello 2s MaxAge 20s FwDly 15s MaxHop 20
Active Times :Hello 2s MaxAge 20s FwDly 15s MaxHop 20
CIST Root/ERPC :32768.4c1f-cc17-3481 / 200000
CIST RegRoot/IRPC :32768.4c1f-cc3b-03cb / 0
CIST RootPortId :128.2
BPDU-Protection :Disabled
TC or TCN received :106
TC count per hello :0
STP Converge Mode :Normal
Time since last TC :0 days 0h:9m:8s
Number of TC :12
Last TC occurred :Ethernet0/0/2
[B]dis stp
-------[CIST Global Info][Mode STP]-------
CIST Bridge :32768.4c1f-cc17-3481
Config Times :Hello 2s MaxAge 20s FwDly 15s MaxHop 20
Active Times :Hello 2s MaxAge 20s FwDly 15s MaxHop 20
CIST Root/ERPC :32768.4c1f-cc17-3481 / 0
CIST RegRoot/IRPC :32768.4c1f-cc17-3481 / 0
CIST RootPortId :0.0
BPDU-Protection :Disabled
TC or TCN received :23
TC count per hello :0
STP Converge Mode :Normal
Time since last TC :0 days 0h:9m:52s
Number of TC :13
Last TC occurred :Ethernet0/0/4
[C]dis stp
-------[CIST Global Info][Mode STP]-------
CIST Bridge :32768.4c1f-cc50-3d65
Config Times :Hello 2s MaxAge 20s FwDly 15s MaxHop 20
Active Times :Hello 2s MaxAge 20s FwDly 15s MaxHop 20
CIST Root/ERPC :32768.4c1f-cc17-3481 / 400000
CIST RegRoot/IRPC :32768.4c1f-cc50-3d65 / 0
CIST RootPortId :128.4
BPDU-Protection :Disabled
TC or TCN received :92
TC count per hello :0
STP Converge Mode :Normal
Time since last TC :0 days 0h:10m:26s
Number of TC :11
Last TC occurred :Ethernet0/0/4
[D]dis stp
-------[CIST Global Info][Mode STP]-------
CIST Bridge :32768.4c1f-cc22-4507
Config Times :Hello 2s MaxAge 20s FwDly 15s MaxHop 20
Active Times :Hello 2s MaxAge 20s FwDly 15s MaxHop 20
CIST Root/ERPC :32768.4c1f-cc17-3481 / 200000
CIST RegRoot/IRPC :32768.4c1f-cc22-4507 / 0
CIST RootPortId :128.2
BPDU-Protection :Disabled
TC or TCN received :49
TC count per hello :0
STP Converge Mode :Normal
Time since last TC :0 days 0h:11m:12s
Number of TC :13
Last TC occurred :Ethernet0/0/2
可以看出,交換機B是根網橋。

[A]stp priority 4096
[A]dis stp
-------[CIST Global Info][Mode STP]-------
CIST Bridge :4096 .4c1f-cc3b-03cb
Config Times :Hello 2s MaxAge 20s FwDly 15s MaxHop 20
Active Times :Hello 2s MaxAge 20s FwDly 15s MaxHop 20
CIST Root/ERPC :4096 .4c1f-cc3b-03cb / 0
CIST RegRoot/IRPC :4096 .4c1f-cc3b-03cb / 0
CIST RootPortId :0.0
BPDU-Protection :Disabled
TC or TCN received :108
TC count per hello :0
STP Converge Mode :Normal
Time since last TC :0 days 0h:0m:14s
Number of TC :15
Last TC occurred :Ethernet0/0/3
此時,根網橋已經是交換機A了。

3 案例3:配置MSTP及負載均衡
3.1 問題
配置MSTP實現多生成樹效果
配置A成為vlan 10 和 20 的主根,vlan 30 和 40 的次根
配置B成為vlan 30 和 40 的主根,vlan 10 和 20 的次根
查看配置信息
3.2 方案
使用eNSP搭建實驗環境,如圖-4所示。

技術分享圖片

3.3 步驟
實現此案例需要按照如下步驟進行。

[A]vlan batch 10 20 30 40
[A]int e0/0/2
[A-Ethernet0/0/2]port link-type trunk
[A-Ethernet0/0/2]port trunk allow-pass vlan all
[A]int e0/0/3
[A-Ethernet0/0/3]port link-type trunk
[A-Ethernet0/0/3]port trunk allow-pass vlan all
交換機B、C也同樣配置。

[A]stp region-configuration
[A-mst-region]region-name tedu
[A-mst-region]instance 1 vlan 10 20
[A-mst-region]instance 2 vlan 30 40
[A-mst-region]active region-configuration
查看配置:

[A-mst-region]dis this
#
stp region-configuration
region-name tedu
instance 1 vlan 10 20
instance 2 vlan 30 40
active region-configuration
#
return
交換機B、C也同樣配置。

3)配置主根與次根

[A]stp instance 1 priority 4096
[A]stp instance 2 priority 8192
[B]stp instance 2 priority 4096
[B]stp instance 1 priority 8192
4)驗證

[A]dis stp instance 1
-------[MSTI 1 Global Info]-------
MSTI Bridge ID :4096.4c1f-cc87-1de7
MSTI RegRoot/IRPC :4096.4c1f-cc87-1de7 / 0
MSTI RootPortId :0.0
Master Bridge :32768.4c1f-cc0d-76bc
Cost to Master :200000
TC received :5
TC count per hello :0
Time since last TC :0 days 0h:3m:6s
Number of TC :4
Last TC occurred :Ethernet0/0/2
----[Port2(Ethernet0/0/2)][FORWARDING]----
Port Role :Designated Port
Port Priority :128
Port Cost(Dot1T ) :Config=auto / Active=200000
Designated Bridge/Port :4096.4c1f-cc87-1de7 / 128.2
Port Times :RemHops 20
TC or TCN send :4
TC or TCN received :3
----[Port3(Ethernet0/0/3)][FORWARDING]----
Port Role :Designated Port
Port Priority :128
Port Cost(Dot1T ) :Config=auto / Active=200000
Designated Bridge/Port :4096.4c1f-cc87-1de7 / 128.3
Port Times :RemHops 20
TC or TCN send :2
TC or TCN received :2
[A]dis stp instance 2
-------[MSTI 2 Global Info]-------
MSTI Bridge ID :8192.4c1f-cc87-1de7
MSTI RegRoot/IRPC :4096.4c1f-cc0d-76bc / 200000
MSTI RootPortId :128.2
Master Bridge :32768.4c1f-cc0d-76bc
Cost to Master :200000
TC received :4
TC count per hello :0
Time since last TC :0 days 0h:3m:49s
Number of TC :4
Last TC occurred :Ethernet0/0/2
----[Port2(Ethernet0/0/2)][FORWARDING]----
Port Role :Root Port
Port Priority :128
Port Cost(Dot1T ) :Config=auto / Active=200000
Designated Bridge/Port :4096.4c1f-cc0d-76bc / 128.1
Port Times :RemHops 20
TC or TCN send :4
TC or TCN received :3
----[Port3(Ethernet0/0/3)][FORWARDING]----
Port Role :Designated Port
Port Priority :128
Port Cost(Dot1T ) :Config=auto / Active=200000
Designated Bridge/Port :8192.4c1f-cc87-1de7 / 128.3
Port Times :RemHops 19
TC or TCN send :2
TC or TCN received :1
[B]dis stp instance 1
-------[MSTI 1 Global Info]-------
MSTI Bridge ID :8192.4c1f-cc0d-76bc
MSTI RegRoot/IRPC :4096.4c1f-cc87-1de7 / 200000
MSTI RootPortId :128.1
Master Bridge :32768.4c1f-cc0d-76bc
Cost to Master :0
TC received :4
TC count per hello :0
Time since last TC :0 days 0h:5m:26s
Number of TC :4
Last TC occurred :Ethernet0/0/3
----[Port1(Ethernet0/0/1)][FORWARDING]----
Port Role :Root Port
Port Priority :128
Port Cost(Dot1T ) :Config=auto / Active=200000
Designated Bridge/Port :4096.4c1f-cc87-1de7 / 128.2
Port Times :RemHops 20
TC or TCN send :3
TC or TCN received :4
----[Port3(Ethernet0/0/3)][FORWARDING]----
Port Role :Designated Port
Port Priority :128
Port Cost(Dot1T ) :Config=auto / Active=200000
Designated Bridge/Port :8192.4c1f-cc0d-76bc / 128.3
Port Times :RemHops 19
TC or TCN send :1
TC or TCN received :0
[B]dis stp instance 2
-------[MSTI 2 Global Info]-------
MSTI Bridge ID :4096.4c1f-cc0d-76bc
MSTI RegRoot/IRPC :4096.4c1f-cc0d-76bc / 0
MSTI RootPortId :0.0
Master Bridge :32768.4c1f-cc0d-76bc
Cost to Master :0
TC received :6
TC count per hello :0
Time since last TC :0 days 0h:6m:4s
Number of TC :5
Last TC occurred :Ethernet0/0/3
----[Port1(Ethernet0/0/1)][FORWARDING]----
Port Role :Designated Port
Port Priority :128
Port Cost(Dot1T ) :Config=auto / Active=200000
Designated Bridge/Port :4096.4c1f-cc0d-76bc / 128.1
Port Times :RemHops 20
TC or TCN send :3
TC or TCN received :4
----[Port3(Ethernet0/0/3)][FORWARDING]----
Port Role :Designated Port
Port Priority :128
Port Cost(Dot1T ) :Config=auto / Active=200000
Designated Bridge/Port :4096.4c1f-cc0d-76bc / 128.3
Port Times :RemHops 20
TC or TCN send :2
TC or TCN received :2
[C]dis stp instance 1
-------[MSTI 1 Global Info]-------
MSTI Bridge ID :32768.4c1f-ccb8-32b8
MSTI RegRoot/IRPC :4096.4c1f-cc87-1de7 / 200000
MSTI RootPortId :128.1
Master Bridge :32768.4c1f-cc0d-76bc
Cost to Master :200000
TC received :3
TC count per hello :0
Time since last TC :0 days 0h:6m:58s
Number of TC :3
Last TC occurred :Ethernet0/0/1
----[Port1(Ethernet0/0/1)][FORWARDING]----
Port Role :Root Port
Port Priority :128
Port Cost(Dot1T ) :Config=auto / Active=200000
Designated Bridge/Port :4096.4c1f-cc87-1de7 / 128.3
Port Times :RemHops 20
TC or TCN send :2
TC or TCN received :2
----[Port2(Ethernet0/0/2)][DISCARDING]----
Port Role :Alternate Port
Port Priority :128
Port Cost(Dot1T ) :Config=auto / Active=200000
Designated Bridge/Port :8192.4c1f-cc0d-76bc / 128.3
Port Times :RemHops 19
TC or TCN send :0
TC or TCN received :1
[C]dis stp instance 2
-------[MSTI 2 Global Info]-------
MSTI Bridge ID :32768.4c1f-ccb8-32b8
MSTI RegRoot/IRPC :4096.4c1f-cc0d-76bc / 200000
MSTI RootPortId :128.2
Master Bridge :32768.4c1f-cc0d-76bc
Cost to Master :200000
TC received :4
TC count per hello :0
Time since last TC :0 days 0h:7m:32s
Number of TC :4
Last TC occurred :Ethernet0/0/2
----[Port1(Ethernet0/0/1)][DISCARDING]----
Port Role :Alternate Port
Port Priority :128
Port Cost(Dot1T ) :Config=auto / Active=200000
Designated Bridge/Port :8192.4c1f-cc87-1de7 / 128.3
Port Times :RemHops 19
TC or TCN send :1
TC or TCN received :2
----[Port2(Ethernet0/0/2)][FORWARDING]----
Port Role :Root Port
Port Priority :128
Port Cost(Dot1T ) :Config=auto / Active=200000
Designated Bridge/Port :4096.4c1f-cc0d-76bc / 128.3
Port Times :RemHops 20
TC or TCN send :2
TC or TCN received :2
查看負載均衡:

[A]dis stp bri
MSTID Port Role STP State Protection
0 Ethernet0/0/2 ROOT FORWARDING NONE
0 Ethernet0/0/3 DESI FORWARDING NONE
1 Ethernet0/0/2 DESI FORWARDING NONE
1 Ethernet0/0/3 DESI FORWARDING NONE
2 Ethernet0/0/2 ROOT FORWARDING NONE
2 Ethernet0/0/3 DESI FORWARDING NONE
[B]dis stp bri
MSTID Port Role STP State Protection
0 Ethernet0/0/1 DESI FORWARDING NONE
0 Ethernet0/0/3 DESI FORWARDING NONE
1 Ethernet0/0/1 ROOT FORWARDING NONE
1 Ethernet0/0/3 DESI FORWARDING NONE
2 Ethernet0/0/1 DESI FORWARDING NONE
2 Ethernet0/0/3 DESI FORWARDING NONE
[C]dis stp bri
MSTID Port Role STP State Protection
0 Ethernet0/0/1 ALTE DISCARDING NONE
0 Ethernet0/0/2 ROOT FORWARDING NONE
1 Ethernet0/0/1 ROOT FORWARDING NONE
1 Ethernet0/0/2 ALTE DISCARDING NONE
2 Ethernet0/0/1 ALTE DISCARDING NONE
2 Ethernet0/0/2 ROOT FORWARDING NONE
C上VLAN 10 20的流量通過Ethernet0/0/1口到A,VLAN 30 40的流量通過Ethernet0/0/2口到B,實現了鏈路的負載均衡。

筆記 STP