sttrans.c
上传用户:allwinjm
上传日期:2021-08-29
资源大小:99k
文件大小:4k
源码类别:

Internet/IE编程

开发平台:

Unix_Linux

  1. /************************************************************************ 
  2.  * RSTP library - Rapid Spanning Tree (802.1t, 802.1w) 
  3.  * Copyright (C) 2001-2003 Optical Access 
  4.  * Author: Alex Rozin 
  5.  * 
  6.  * This file is part of RSTP library. 
  7.  * 
  8.  * RSTP library is free software; you can redistribute it and/or modify it 
  9.  * under the terms of the GNU Lesser General Public License as published by the 
  10.  * Free Software Foundation; version 2.1 
  11.  * 
  12.  * RSTP library is distributed in the hope that it will be useful, but 
  13.  * WITHOUT ANY WARRANTY; without even the implied warranty of 
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser 
  15.  * General Public License for more details. 
  16.  * 
  17.  * You should have received a copy of the GNU Lesser General Public License 
  18.  * along with RSTP library; see the file COPYING.  If not, write to the Free 
  19.  * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 
  20.  * 02111-1307, USA. 
  21.  **********************************************************************/
  22. /* Port State Transition state machine : 17.24 */
  23.     
  24. #include "base.h"
  25. #include "stpm.h"
  26. #include "stp_to.h"
  27. #define STATES { 
  28.   CHOOSE(DISCARDING),   
  29.   CHOOSE(LEARNING), 
  30.   CHOOSE(FORWARDING),   
  31. }
  32. #define GET_STATE_NAME STP_sttrans_get_state_name
  33. #include "choose.h"
  34. #ifdef STRONGLY_SPEC_802_1W
  35. static Bool
  36. disableLearning (STATE_MACH_T *this)
  37. {
  38.   register PORT_T *port = this->owner.port;
  39.   return STP_OUT_set_learning (port->port_index, port->owner->vlan_id, False);
  40. }
  41. static Bool
  42. enableLearning (STATE_MACH_T *this)
  43. {
  44.   register PORT_T *port = this->owner.port;
  45.   return STP_OUT_set_learning (port->port_index, port->owner->vlan_id, True);
  46. }
  47. static Bool
  48. disableForwarding (STATE_MACH_T *this)
  49. {
  50.   register PORT_T *port = this->owner.port;
  51.   return STP_OUT_set_forwarding (port->port_index, port->owner->vlan_id, False);
  52. }
  53. static Bool
  54. enableForwarding (STATE_MACH_T *this)
  55. {
  56.   register PORT_T *port = this->owner.port;
  57.   return STP_OUT_set_forwarding (port->port_index, port->owner->vlan_id, True);
  58. }
  59. #endif
  60. void
  61. STP_sttrans_enter_state (STATE_MACH_T *this)
  62. {
  63.   register PORT_T    *port = this->owner.port;
  64.   switch (this->State) {
  65.     case BEGIN:
  66.     case DISCARDING:
  67.       port->learning = False;
  68.       port->forwarding = False;
  69. #ifdef STRONGLY_SPEC_802_1W
  70.       disableLearning (this);
  71.       disableForwarding (this);
  72. #else
  73.       STP_OUT_set_port_state (port->port_index, port->owner->vlan_id, UID_PORT_DISCARDING);
  74. #endif
  75.       break;
  76.     case LEARNING:
  77.       port->learning = True;
  78. #ifdef STRONGLY_SPEC_802_1W
  79.       enableLearning (this);
  80. #else
  81.       STP_OUT_set_port_state (port->port_index, port->owner->vlan_id, UID_PORT_LEARNING);
  82. #endif
  83.       break;
  84.     case FORWARDING:
  85.       port->tc = !port->operEdge;
  86.       port->forwarding = True;
  87. #ifdef STRONGLY_SPEC_802_1W
  88.       enableForwarding (this);
  89. #else
  90.       STP_OUT_set_port_state (port->port_index, port->owner->vlan_id, UID_PORT_FORWARDING);
  91. #endif
  92.       break;
  93.   }
  94. }
  95. Bool
  96. STP_sttrans_check_conditions (STATE_MACH_T *this)
  97. {
  98.   register PORT_T       *port = this->owner.port;
  99.   if (BEGIN == this->State) {
  100.     return STP_hop_2_state (this, DISCARDING);
  101.   }
  102.   switch (this->State) {
  103.     case DISCARDING:
  104.       if (port->learn) {
  105.         return STP_hop_2_state (this, LEARNING);
  106.       }
  107.       break;
  108.     case LEARNING:
  109.       if (port->forward) {
  110.         return STP_hop_2_state (this, FORWARDING);
  111.       }
  112.       if (!port->learn) {
  113.         return STP_hop_2_state (this, DISCARDING);
  114.       }
  115.       break;
  116.     case FORWARDING:
  117.       if (!port->forward) {
  118.         return STP_hop_2_state (this, DISCARDING);
  119.       }
  120.       break;
  121.   }
  122.   return False;
  123. }