xref: /onnv-gate/usr/src/lib/librstp/common/p2p.c (revision 10491:8893b747ecdf)
1*10491SRishi.Srivatsavai@Sun.COM /************************************************************************
2*10491SRishi.Srivatsavai@Sun.COM  * RSTP library - Rapid Spanning Tree (802.1t, 802.1w)
3*10491SRishi.Srivatsavai@Sun.COM  * Copyright (C) 2001-2003 Optical Access
4*10491SRishi.Srivatsavai@Sun.COM  * Author: Alex Rozin
5*10491SRishi.Srivatsavai@Sun.COM  *
6*10491SRishi.Srivatsavai@Sun.COM  * This file is part of RSTP library.
7*10491SRishi.Srivatsavai@Sun.COM  *
8*10491SRishi.Srivatsavai@Sun.COM  * RSTP library is free software; you can redistribute it and/or modify it
9*10491SRishi.Srivatsavai@Sun.COM  * under the terms of the GNU Lesser General Public License as published by the
10*10491SRishi.Srivatsavai@Sun.COM  * Free Software Foundation; version 2.1
11*10491SRishi.Srivatsavai@Sun.COM  *
12*10491SRishi.Srivatsavai@Sun.COM  * RSTP library is distributed in the hope that it will be useful, but
13*10491SRishi.Srivatsavai@Sun.COM  * WITHOUT ANY WARRANTY; without even the implied warranty of
14*10491SRishi.Srivatsavai@Sun.COM  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
15*10491SRishi.Srivatsavai@Sun.COM  * General Public License for more details.
16*10491SRishi.Srivatsavai@Sun.COM  *
17*10491SRishi.Srivatsavai@Sun.COM  * You should have received a copy of the GNU Lesser General Public License
18*10491SRishi.Srivatsavai@Sun.COM  * along with RSTP library; see the file COPYING.  If not, write to the Free
19*10491SRishi.Srivatsavai@Sun.COM  * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20*10491SRishi.Srivatsavai@Sun.COM  * 02111-1307, USA.
21*10491SRishi.Srivatsavai@Sun.COM  **********************************************************************/
22*10491SRishi.Srivatsavai@Sun.COM 
23*10491SRishi.Srivatsavai@Sun.COM /* Point To Point MAC mode selection machine : 6.4.3, 6.5.1 */
24*10491SRishi.Srivatsavai@Sun.COM 
25*10491SRishi.Srivatsavai@Sun.COM #include "base.h"
26*10491SRishi.Srivatsavai@Sun.COM #include "stpm.h"
27*10491SRishi.Srivatsavai@Sun.COM #include "stp_to.h" /* for STP_OUT_get_duplex */
28*10491SRishi.Srivatsavai@Sun.COM 
29*10491SRishi.Srivatsavai@Sun.COM #define STATES { \
30*10491SRishi.Srivatsavai@Sun.COM   CHOOSE(INIT),     \
31*10491SRishi.Srivatsavai@Sun.COM   CHOOSE(RECOMPUTE),    \
32*10491SRishi.Srivatsavai@Sun.COM   CHOOSE(STABLE)    \
33*10491SRishi.Srivatsavai@Sun.COM }
34*10491SRishi.Srivatsavai@Sun.COM 
35*10491SRishi.Srivatsavai@Sun.COM #define GET_STATE_NAME STP_p2p_get_state_name
36*10491SRishi.Srivatsavai@Sun.COM #include "choose.h"
37*10491SRishi.Srivatsavai@Sun.COM 
38*10491SRishi.Srivatsavai@Sun.COM static Bool
computeP2P(PORT_T * port)39*10491SRishi.Srivatsavai@Sun.COM computeP2P (PORT_T *port)
40*10491SRishi.Srivatsavai@Sun.COM {
41*10491SRishi.Srivatsavai@Sun.COM     switch (port->adminPointToPointMac) {
42*10491SRishi.Srivatsavai@Sun.COM       case P2P_FORCE_TRUE:
43*10491SRishi.Srivatsavai@Sun.COM         return True;
44*10491SRishi.Srivatsavai@Sun.COM       case P2P_FORCE_FALSE:
45*10491SRishi.Srivatsavai@Sun.COM         return False;
46*10491SRishi.Srivatsavai@Sun.COM       default:
47*10491SRishi.Srivatsavai@Sun.COM       case P2P_AUTO:
48*10491SRishi.Srivatsavai@Sun.COM         return STP_OUT_get_duplex (port->port_index);
49*10491SRishi.Srivatsavai@Sun.COM     }
50*10491SRishi.Srivatsavai@Sun.COM }
51*10491SRishi.Srivatsavai@Sun.COM 
52*10491SRishi.Srivatsavai@Sun.COM void
STP_p2p_enter_state(STATE_MACH_T * s)53*10491SRishi.Srivatsavai@Sun.COM STP_p2p_enter_state (STATE_MACH_T* s)
54*10491SRishi.Srivatsavai@Sun.COM {
55*10491SRishi.Srivatsavai@Sun.COM   register PORT_T* port = s->owner.port;
56*10491SRishi.Srivatsavai@Sun.COM 
57*10491SRishi.Srivatsavai@Sun.COM   switch (s->State) {
58*10491SRishi.Srivatsavai@Sun.COM     case BEGIN:
59*10491SRishi.Srivatsavai@Sun.COM     case INIT:
60*10491SRishi.Srivatsavai@Sun.COM       port->p2p_recompute = True;
61*10491SRishi.Srivatsavai@Sun.COM       break;
62*10491SRishi.Srivatsavai@Sun.COM     case RECOMPUTE:
63*10491SRishi.Srivatsavai@Sun.COM       port->operPointToPointMac = computeP2P (port);
64*10491SRishi.Srivatsavai@Sun.COM       port->p2p_recompute = False;
65*10491SRishi.Srivatsavai@Sun.COM       break;
66*10491SRishi.Srivatsavai@Sun.COM     case STABLE:
67*10491SRishi.Srivatsavai@Sun.COM       break;
68*10491SRishi.Srivatsavai@Sun.COM   }
69*10491SRishi.Srivatsavai@Sun.COM }
70*10491SRishi.Srivatsavai@Sun.COM 
71*10491SRishi.Srivatsavai@Sun.COM Bool
STP_p2p_check_conditions(STATE_MACH_T * s)72*10491SRishi.Srivatsavai@Sun.COM STP_p2p_check_conditions (STATE_MACH_T* s)
73*10491SRishi.Srivatsavai@Sun.COM {
74*10491SRishi.Srivatsavai@Sun.COM   register PORT_T* port = s->owner.port;
75*10491SRishi.Srivatsavai@Sun.COM 
76*10491SRishi.Srivatsavai@Sun.COM   switch (s->State) {
77*10491SRishi.Srivatsavai@Sun.COM     case BEGIN:
78*10491SRishi.Srivatsavai@Sun.COM     case INIT:
79*10491SRishi.Srivatsavai@Sun.COM       return STP_hop_2_state (s, STABLE);
80*10491SRishi.Srivatsavai@Sun.COM     case RECOMPUTE:
81*10491SRishi.Srivatsavai@Sun.COM       return STP_hop_2_state (s, STABLE);
82*10491SRishi.Srivatsavai@Sun.COM     case STABLE:
83*10491SRishi.Srivatsavai@Sun.COM       if (port->p2p_recompute) {
84*10491SRishi.Srivatsavai@Sun.COM         return STP_hop_2_state (s, RECOMPUTE);
85*10491SRishi.Srivatsavai@Sun.COM       }
86*10491SRishi.Srivatsavai@Sun.COM       break;
87*10491SRishi.Srivatsavai@Sun.COM   }
88*10491SRishi.Srivatsavai@Sun.COM   return False;
89*10491SRishi.Srivatsavai@Sun.COM }
90*10491SRishi.Srivatsavai@Sun.COM 
91