1. 程式人生 > >STP 抓包分析

STP 抓包分析

stp

# STP(Spanning-Tree Protocol,生成樹協議)的工作原理,在分層網絡中存在冗余鏈路的情況下容易引起流量環路,使用STP能夠動態的管理這些冗余鏈路;當某臺交換機的一條連接丟失時,另一條鏈路能迅速取代失敗鏈路,並且不會產生流量環路。文章主要包括下面幾點內容:冗余拓撲中存在的問題、生成樹協議、生成樹收斂、利用生成樹實現負載均衡等。

# 1、STP交換機角色
# 根交換機(root bridge)和非根交換機(none root bridge)
# 首先要知道什麽是BID(Bridge ID,橋ID),因為根交換機的選舉是基於BID的,BID由三部分組成——優先級、發送交換機的MAC地址、Extended System ID(擴展系統ID,可選項);BID一共8個字節,其中優先級2個字節,MAC地址6個字節。優先級包括Priority 4bit(4096*n)和Extended System ID 12bit(pvst協議和rapid-pvst協議采用vlan id,MST 采用instance id);在進行BID比較時,先比較橋優先級,優先級值小的為根橋;當橋優先級值相等時,再比較橋的背板MAC地址,MAC地址小的為根橋。

IOU1#sh spanning-tree
VLAN0001
  Spanning tree enabled protocol ieee     # 表示交換機使用的生成樹協議是"PVST+",這也是思科默認的生成樹協議
  Root ID    Priority    32769            # 表示根交換機的優先級是32769,
             Address     aabb.cc00.0800   # 根交換機的MAC地址  
             This bridge is the root      # 表示當前這臺交換機就是根交換機  
             Hello Time   2 sec  Max Age 20 sec  Forward Delay 15 sec    # BPDU發送間隔默認2秒,最大存在時間是20秒,轉發延時是15秒。

  Bridge ID  Priority    32769  (priority 32768 sys-id-ext 1)    # Extended System ID是1,所以總優先級就是32768+1=32769
             Address     aabb.cc00.0800   
             Hello Time   2 sec  Max Age 20 sec  Forward Delay 15 sec
             Aging Time  300 sec

Interface           Role Sts Cost      Prio.Nbr Type
------------------- ---- --- --------- -------- --------------------------------
Et1/1               Desg FWD 100       128.6    Shr 
Et1/2               Desg FWD 100       128.7    Shr 
Et1/3               Desg FWD 100       128.8    Shr 

IOU2#sh spanning-tree
VLAN0001
  Spanning tree enabled protocol ieee
  Root ID    Priority    32769
             Address     aabb.cc00.0800
             Cost        100
             Port        10 (Ethernet2/1)
             Hello Time   2 sec  Max Age 20 sec  Forward Delay 15 sec

  Bridge ID  Priority    32769  (priority 32768 sys-id-ext 1)
             Address     aabb.cc00.0d00
             Hello Time   2 sec  Max Age 20 sec  Forward Delay 15 sec
             Aging Time  300 sec

Interface           Role Sts Cost      Prio.Nbr Type
------------------- ---- --- --------- -------- --------------------------------
Et2/1               Root FWD 100       128.10   Shr 
Et2/3               Altn BLK 100       128.12   Shr 
Et3/3               Altn BLK 100       128.16   Shr 

IOU3#sh spanning-tree
VLAN0001
  Spanning tree enabled protocol ieee
  Root ID    Priority    32769
             Address     aabb.cc00.0800
             Cost        100                # 端口cost :100
             Port        14 (Ethernet3/1)   # Ethernet3/1 為 10M
             Hello Time   2 sec  Max Age 20 sec  Forward Delay 15 sec

  Bridge ID  Priority    32769  (priority 32768 sys-id-ext 1)
             Address     aabb.cc00.0a00
             Hello Time   2 sec  Max Age 20 sec  Forward Delay 15 sec
             Aging Time  300 sec

Interface           Role Sts Cost      Prio.Nbr Type
------------------- ---- --- --------- -------- --------------------------------
Et3/1               Root FWD 100       128.14   Shr 
Et3/2               Desg FWD 100       128.15   Shr 
Et3/3               Desg FWD 100       128.16   Shr
# 2、端口cost和路徑cost
# 根交換機被選舉出來後,計算其他交換機到根交換機的cost,STA考慮兩種cost,端口cost和路徑cost,路徑cost是從根交換機出發到最終交換機入方向的端口cost總和,也就是說在上面的拓撲圖圖三中,假設SW1是根交換機,想要改變SW3到根交換機SW1的花費,應該在SW3的fa0/1來改變,而不是在SW1的fa0/3端口上改變。
# 如果一臺交換機有多條路徑到達根交換機,這臺交換機會選擇路徑花費最小的那條,下面是默認的端口cost參照表:
# 10G -- 2,1G -- 4,100M -- 19,10M -- 100

# 3、BPDU結構淺析
# BPDU包含12個字段
Frame 1417: 60 bytes on wire (480 bits), 60 bytes captured (480 bits) on interface 0
IEEE 802.3 Ethernet 
Logical-Link Control
Spanning Tree Protocol
    Protocol Identifier: Spanning Tree Protocol (0x0000)
    Protocol Version Identifier: Spanning Tree (0)
    BPDU Type: Configuration (0x00)
    BPDU flags: 0x00        # 標記域,包含TC(Topology Change,拓撲改變)比特位,TCA(Topology Change Acknowledgment,拓撲改變確認)比特位。
    Root Identifier: 32768 / 1 / aa:bb:cc:00:08:00      # Root ID:包含了根交換機的BID。
    Root Path Cost: 0                                   # Cost of path:到根交換機的路徑花費。
    Bridge Identifier: 32768 / 1 / aa:bb:cc:00:08:00    # Bridge ID:轉發BPDU的交換機的BID。
    Port identifier: 0x8007                             # Port ID:轉發BPDU的交換機的PID,PID等於端口優先級(默認128)加端口號,
    Message Age: 0                                      # Message age:BPDU已經存在的時間。
    Max Age: 20                                         # Max age:BPDU最大存在時間。
    Hello Time: 2                                       # Hello time:根交換機發送配置信息的間隔時間,默認2秒。
    Forward Delay: 15                                   # Forward Delay:轉發延時,默認15秒。 

# STP端口角色
# 1)根端口(Root Port,RP):轉發並接收BPDU;每個非根交換機上有且僅有一個根端口,
# 2)指派端口(Designated Port,DP):轉發並自身發送BPDU;網絡上除根端口外,所有允許轉發流量的端口,每個網段都有一個指派端口,根交換機上的端口都是指派端口。
# 3)非指派端口:只接收BPDU;既不是根端口也不是指派端口,這種端口雖然是激活的但是會被堵塞(Blocking)用來阻止環路,根端口和指派端口都處於轉發(Forwarding)狀態。
# 4)禁用端口:被管理員使用"shutdown"命令關閉的端口稱作禁用端口,禁用端口不參與生成樹算法。


STP 抓包分析