xref: /titanic_41/usr/src/lib/librstp/common/stp_in.h (revision 491f61a1e1c1fc54a47bbcf53dbbbe1293b93b27)
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  /* This file contains prototypes for API from an operation
24     system to the RSTP */
25 
26 #ifndef _STP_API_H__
27 #define _STP_API_H__
28 
29 #include <sys/types.h>
30 
31 #define STP_DBG 1
32 
33 /************************
34  * Common base constants
35  ************************/
36 
37 #ifndef INOUT
38 #  define IN      /* consider as comments near 'input' parameters */
39 #  define OUT     /* consider as comments near 'output' parameters */
40 #  define INOUT   /* consider as comments near 'input/output' parameters */
41 #endif
42 
43 #ifndef Zero
44 #  define Zero        0
45 #  define One         1
46 #endif
47 
48 #ifndef Bool
49 #  define Bool        int
50 #  define False       0
51 #  define True        1
52 #endif
53 
54 /********************************************
55  * constants: default values and linitations
56  *********************************************/
57 
58 /* bridge configuration */
59 
60 #define DEF_BR_PRIO 32768
61 #define MIN_BR_PRIO 0
62 #define MAX_BR_PRIO 61440
63 
64 #define DEF_BR_HELLOT   2
65 #define MIN_BR_HELLOT   1
66 #define MAX_BR_HELLOT   10
67 
68 #define DEF_BR_MAXAGE   20
69 #define MIN_BR_MAXAGE   6
70 #define MAX_BR_MAXAGE   40
71 
72 #define DEF_BR_FWDELAY  15
73 #define MIN_BR_FWDELAY  4
74 #define MAX_BR_FWDELAY  30
75 
76 #define	IEEE_TIMER_SCALE	256
77 
78 /* Note that this works with unscaled values */
79 #define	CHECK_BRIDGE_CONFIG(cfg) \
80 	(2 * (cfg.forward_delay - 1) >= cfg.max_age && \
81 	cfg.max_age >= 2 * (cfg.hello_time + 1))
82 
83 /*
84  * These macros provide limits and tests for displaying comprehensible errors.
85  */
86 #define	NO_MAXAGE(cfg) ((cfg.forward_delay - 1) < (cfg.hello_time + 1))
87 #define	MIN_FWDELAY_NOM(cfg)	\
88 	(cfg.hello_time < MIN_BR_FWDELAY - 2 ? MIN_BR_FWDELAY : \
89 	cfg.hello_time + 2)
90 #define	MAX_HELLOTIME_NOM(cfg)	\
91 	(cfg.forward_delay > MAX_BR_HELLOT + 2 ? MAX_BR_HELLOT : \
92 	cfg.forward_delay - 2)
93 
94 #define	SMALL_MAXAGE(cfg)	(cfg.max_age < 2 * (cfg.hello_time + 1))
95 #define	MIN_MAXAGE(cfg)	\
96 	(cfg.hello_time < (MIN_BR_MAXAGE / 2 - 1) ? MIN_BR_MAXAGE : \
97 	(2 * (cfg.hello_time + 1)))
98 #define	MAX_HELLOTIME(cfg)	\
99 	(cfg.max_age > 2 * (MAX_BR_HELLOT + 1) ? MAX_BR_HELLOT : \
100 	(cfg.max_age / 2 - 1))
101 
102 #define	MIN_FWDELAY(cfg)	(cfg.max_age / 2 + 1)
103 #define	MAX_MAXAGE(cfg)	\
104 	(cfg.forward_delay > (MAX_BR_MAXAGE / 2 + 1) ? MAX_BR_MAXAGE : \
105 	(2 * (cfg.forward_delay - 1)))
106 
107 #define	CAPPED_MAXAGE(cfg)	(cfg.forward_delay < (MAX_BR_MAXAGE / 2 + 1))
108 #define	FLOORED_MAXAGE(cfg)	(cfg.hello_time > (MIN_BR_MAXAGE / 2 - 1))
109 
110 #define DEF_FORCE_VERS  2 /* NORMAL_RSTP */
111 
112 /* port configuration */
113 
114 #define DEF_PORT_PRIO   128
115 #define MIN_PORT_PRIO   0
116 #define MAX_PORT_PRIO   240 /* in steps of 16 */
117 
118 #define DEF_ADMIN_NON_STP   False
119 #define DEF_ADMIN_EDGE      True
120 #define DEF_LINK_DELAY      3 /* see edge.c */
121 #define DEF_P2P         P2P_AUTO
122 
123 #include <uid_stp.h>
124 #include <stp_bpdu.h>
125 
126 #ifndef __STPM_T__
127 #define __STPM_T__
128 struct stpm_t;
129 typedef struct stpm_t STPM_T;
130 #endif
131 #ifndef __STP_VECTORS_T__
132 #define __STP_VECTORS_T__
133 struct stp_vectors;
134 typedef struct stp_vectors STP_VECTORS_T;
135 #endif
136 
137 /* Section 1: Create/Delete/Start/Stop the RSTP instance */
138 
139 void /* init the engine */
140 STP_IN_init (STP_VECTORS_T *vectors);
141 
142 int
143 STP_IN_stpm_create (int vlan_id, char* name);
144 
145 int
146 STP_IN_stpm_delete (int vlan_id);
147 
148 int
149 STP_IN_port_add (int vlan_id, int port_index);
150 
151 int
152 STP_IN_port_remove (int vlan_id, int port_index);
153 
154 int
155 STP_IN_stop_all (void);
156 
157 int
158 STP_IN_delete_all (void);
159 
160 /* Section 2. "Get" management */
161 
162 Bool
163 STP_IN_get_is_stpm_enabled (int vlan_id);
164 
165 int
166 STP_IN_stpm_get_vlan_id_by_name (char* name, int* vlan_id);
167 
168 int
169 STP_IN_stpm_get_name_by_vlan_id (int vlan_id, char* name, size_t buffsize);
170 
171 const char*
172 STP_IN_get_error_explanation (int rstp_err_no);
173 
174 int
175 STP_IN_stpm_get_cfg (int vlan_id, UID_STP_CFG_T* uid_cfg);
176 
177 int
178 STP_IN_stpm_get_state (int vlan_id, UID_STP_STATE_T* entry);
179 
180 int
181 STP_IN_port_get_cfg (int vlan_id, int port_index, UID_STP_PORT_CFG_T* uid_cfg);
182 
183 int
184 STP_IN_port_get_state (int vlan_id, UID_STP_PORT_STATE_T* entry);
185 
186 const char *
187 STP_IN_state2str(RSTP_PORT_STATE);
188 
189 /* Section 3. "Set" management */
190 
191 int
192 STP_IN_stpm_set_cfg (int vlan_id,
193                      UID_STP_CFG_T* uid_cfg);
194 
195 int
196 STP_IN_port_set_cfg (int vlan_id, int port_index,
197                      UID_STP_PORT_CFG_T* uid_cfg);
198 
199 #ifdef STP_DBG
200 int STP_IN_dbg_set_port_trace (char *mach_name, int enadis,
201     int vlan_id, int port_index);
202 #endif
203 
204 /* Section 4. RSTP functionality events */
205 
206 int
207 STP_IN_one_second (void);
208 
209 int /* for Link UP/DOWN */
210 STP_IN_enable_port (int port_index, Bool enable);
211 
212 int /* call it, when port speed has been changed, speed in Kb/s  */
213 STP_IN_changed_port_speed (int port_index, long speed);
214 
215 int /* call it, when current port duplex mode has been changed  */
216 STP_IN_changed_port_duplex (int port_index);
217 
218 int
219 STP_IN_check_bpdu_header (BPDU_T* bpdu, size_t len);
220 
221 int
222 STP_IN_rx_bpdu (int vlan_id, int port_index, BPDU_T* bpdu, size_t len);
223 
224 void
225 STP_IN_get_bridge_id(int vlan_id, unsigned short *priority, unsigned char *mac);
226 
227 #endif /* _STP_API_H__ */
228