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。