1 源碼
rstplib.1.1.02/times.c,times.h
2 功能
定義了涉及端口、網橋、消息等元素的時間信息結構體,提供了基本操作接口。
3 代碼簡析
/* 一個消息從根網橋發出後,它的消息年齡的初值是0,其它網橋端口收到一個優越的配置
* 消息後,如果消息年齡超過最大年齡,那麼丟棄該消息,否則將消息年齡加上一個量,再
* 傳播出去,因此消息傳播的網橋數是有限的
*/
typedef struct timevalues_t {
unsigned short MessageAge; //消息年齡
unsigned short MaxAge;//最大年齡
unsigned short ForwardDelay;//轉發延遲
unsigned short HelloTime;//會話週期
} TIMEVALUES_T;
對應BPDUs傳遞的時間參數:
typedef struct bpdu_body_t {
…
unsigned char message_age[2];
unsigned char max_age[2];
unsigned char hello_time[2];
unsigned char forward_delay[2];
} BPDU_BODY_T;
/* BPDU -> TIMEVALUES_T */
void STP_get_times (IN BPDU_BODY_T *b, OUT TIMEVALUES_T *v);
/* TIMEVALUES_T -> BPDU */
void STP_set_times (IN TIMEVALUES_T *v, OUT BPDU_BODY_T *b);
/* 比較兩個TIMEVALUES_T 變量,按字段定義優先級依次比較 */
int STP_compare_times (IN TIMEVALUES_T *t1, IN TIMEVALUES_T *t2);
4 用途
有如下變量用到了此時間結構:portTimes、msgTimes、bridgeTime、rootTimes、designatedTimes。
4.1 portTimes
端口時間,包含端口的時間參數(Message Age, Max Age, Forward Delay, and Hello Time),用在本端口發送的BPDUs中。
例程:
static void build_config_bpdu (PORT_T* port, Bool set_topo_ack_flag)
{
…
STP_set_times (&port->portTimes, &bpdu_packet.body);
}
4.2 msgTimes
消息時間,包括BPDUs傳遞的時間參數(Message Age, Max Age, Forward Delay, and Hello Time)。
例程:
rcvBpdu( )函數中,下面三個條件同時滿足才返回RepeatedDesignateMsg:
(1) 消息是從指定端口發出:(該BPDU是RST BPDU && BPDU的Port Role==Designated)
(2) msgPriority==portPriority – 消息優先級與端口優先級相同
(3) msgTimes==portTimes – 消息時間與端口時間相同
情形 - 消息來自父網橋指定端口,並且它的優先級向量和時間信息都沒有任何變化。
static RCVD_MSG_T rcvBpdu (STATE_MACH_T* this)
{
/*消息是從指定端口發出 */
if ( BPDU_CONFIG_TYPE == port->msgBpduType ||
RSTP _PORT_ROLE_DESGN == port->msgPortRole) {
/* msgPriority == portPriority */
if (! STP_VECT_compare_vector (&port->msgPrio,&port->portPrio) &&
/* msgTimes == portTimes */
! STP_compare_times (&port->msgTimes, &port->portTimes)) {
return RepeatedDesignateMsg;
}
}
…
}
4.3 bridgeTime
網橋時間,有4個成員:Bridge Forward Delay、Bridge Hello Time、Bridge Max Age、Message Age=0,前3個參數只能通過管理進行配置,updtRolesBridge()用來計算rootTimes變量。
static void updtRolesBridge (STATE_MACH_T* this)
{
…
STP_copy_times (&stpm->rootTimes, &stpm->BrTimes);
…
}
4.4 rootTimes
根時間信息,包含網橋的時間參數:Message Age, Max Age, Forward Delay, and Hello Time:
1) 如果根優先級向量是網橋優先級向量,即本網橋是根網橋,則根時間 = BridgeTimes
2) 否則,根時間來自根端口(根路徑優先級向量最好的那個端口)的portTimes()
Max Age, Forward Delay, and Hello Time = 根端口的portTimes的相應成員
Message Age = Message Age +╔ max(1,1/16 Max Age)╗
4.5 designatedTimes
指定時間,包含時間參數(Message Age, Max Age,Forward Delay, and Hello Time),當updtInfo==TRUE時用來更新端口時間portTimes,designatedTimes的值由updtRolesBridge()從rootTimes拷貝而來。
4.5 時間傳遞路線
(1) msgTimes -> portTimes -> BPDUs -> msgTimes;
(2) 管理員 -> BridgeTimes -> rootTimes -> designatedTimes。