xref: /titanic_52/usr/src/lib/librstp/common/stpm.h (revision e4f5a11d4a234623168c1558fcdf4341e11769e1)
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 
23 /* STP machine instance : bridge per VLAN: 17.17 */
24 /* The Clause 17.13 points: "NOTE:The operation of the Bridge as a whole can
25  * be represented by the interaction between Bridge Ports specified,
26  * and by parameters of the Bridge stored in �Port 0�. This removes the
27  * need for any �per Bridge� specification elements, and helps ensure
28  * the minimum dependencies between Bridge Ports. This in turn supports
29  * the development of implementations that scale well with increasing
30  * numbers of Bridge Ports. This shift of focus to �per Port operation�
31  * for the RSTP is supported by underlying technical changes from the
32  * Spanning Tree Algorithm and Protocol (Clause 8):"
33  * Newetheless, it seems to me, the behaviour of of the bridge, its variables
34  * and functions are so distinct from Port, that I decided to design Bridge
35  * instance. I called this object 'stpm' from STP machine. I'd like to see
36  * another procedural model, more corresponding to this note on Clause 17.13 */
37 
38 #ifndef _STP_MACHINE_H__
39 #define _STP_MACHINE_H__
40 
41 #include "port.h"
42 #include "rolesel.h"
43 
44 #define TxHoldCount          3 /* 17.16.6, 17.28.2(Table 17-5) */
45 
46 typedef enum {/* 17.12, 17.16.1 */
47   FORCE_STP_COMPAT = 0,
48   NORMAL_RSTP = 2
49 } PROTOCOL_VERSION_T;
50 
51 struct stpm_t {
52   struct stpm_t*        next;
53 
54   struct port_t*        ports;
55 
56   /* The only "per bridge" state machine */
57   STATE_MACH_T*         rolesel;   /* the Port Role Selection State machione: 17.22 */
58   STATE_MACH_T*         machines;
59 
60   /* variables */
61   PROTOCOL_VERSION_T    ForceVersion;   /* 17.12, 17.16.1 */
62   BRIDGE_ID             BrId;           /* 17.17.2 */
63   TIMEVALUES_T          BrTimes;        /* 17.17.4 */
64   PORT_ID               rootPortId;     /* 17.17.5 */
65   PRIO_VECTOR_T         rootPrio;       /* 17.17.6 */
66   TIMEVALUES_T          rootTimes;      /* 17.17.7 */
67 
68   int                   vlan_id;        /* let's say: tag */
69   char*                 name;           /* name of the VLAN, maily for debugging */
70   UID_STP_MODE_T        admin_state;    /* STP_DISABLED or STP_ENABLED; type see in UiD */
71 
72   unsigned long         timeSince_Topo_Change; /* 14.8.1.1.3.b */
73   unsigned long         Topo_Change_Count;     /* 14.8.1.1.3.c */
74   unsigned char         Topo_Change;           /* 14.8.1.1.3.d */
75 };
76 
77 #ifndef __STPM_T__
78 #define __STPM_T__
79 typedef struct stpm_t STPM_T;
80 #endif
81 
82 /* Functions prototypes */
83 
84 void
85 STP_stpm_one_second (STPM_T* param);
86 
87 STPM_T*
88 STP_stpm_create (int vlan_id, char* name);
89 
90 int
91 STP_stpm_enable (STPM_T* this, UID_STP_MODE_T admin_state);
92 
93 void
94 STP_stpm_delete (STPM_T* this);
95 
96 int
97 STP_stpm_start (STPM_T* this);
98 
99 void
100 STP_stpm_stop (STPM_T* this);
101 
102 int
103 STP_stpm_update (STPM_T* this);
104 
105 BRIDGE_ID *
106 STP_compute_bridge_id (STPM_T* this);
107 
108 STPM_T *
109 STP_stpm_get_the_list (void);
110 
111 void
112 STP_stpm_update_after_bridge_management (STPM_T* this);
113 
114 int
115 STP_stpm_check_bridge_priority (STPM_T* this);
116 
117 const char*
118 STP_stpm_get_port_name_by_id (STPM_T* this, PORT_ID port_id);
119 
120 STPM_T* stpapi_stpm_find (int vlan_id);
121 
122 int stp_in_stpm_enable (int vlan_id, char* name,
123                     UID_STP_MODE_T admin_state);
124 void* stp_in_stpm_create (int vlan_id, char *name, int *err_code);
125 
126 #endif /* _STP_MACHINE_H__ */
127