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