xref: /illumos-gate/usr/src/lib/librstp/common/port.h (revision 69a119caa6570c7077699161b7c28b6ee9f8b0f4)
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 PORT instance : 17.18, 17.15 */
24 
25 #ifndef _STP_PORT_H__
26 #define _STP_PORT_H__
27 
28 #include "statmch.h"
29 
30 #define TIMERS_NUMBER   9
31 typedef unsigned int    PORT_TIMER_T;
32 
33 typedef enum {
34   Mine,
35   Aged,
36   Received,
37   Disabled
38 } INFO_IS_T;
39 
40 typedef enum {
41   SuperiorDesignateMsg,
42   RepeatedDesignateMsg,
43   ConfirmedRootMsg,
44   OtherMsg
45 } RCVD_MSG_T;
46 
47 typedef enum {
48   DisabledPort = 0,
49   AlternatePort,
50   BackupPort,
51   RootPort,
52   DesignatedPort,
53   NonStpPort
54 } PORT_ROLE_T;
55 
56 typedef struct port_t {
57   struct port_t*     next;
58 
59   /* per Port state machines */
60   STATE_MACH_T*     info;      /* 17.21 */
61   STATE_MACH_T*     roletrns;  /* 17.23 */
62   STATE_MACH_T*     sttrans;   /* 17.24 */
63   STATE_MACH_T*     topoch;    /* 17.25 */
64   STATE_MACH_T*     migrate;   /* 17.26 */
65   STATE_MACH_T*     transmit;  /* 17.26 */
66   STATE_MACH_T*     p2p;       /* 6.4.3, 6.5.1 */
67   STATE_MACH_T*     edge;      /*  */
68   STATE_MACH_T*     pcost;     /*  */
69 
70   STATE_MACH_T*     machines; /* list of machines */
71 
72   struct stpm_t*    owner; /* Bridge, that this port belongs to */
73 
74   /* per port Timers */
75   PORT_TIMER_T      fdWhile;      /* 17.15.1 */
76   PORT_TIMER_T      helloWhen;    /* 17.15.2 */
77   PORT_TIMER_T      mdelayWhile;  /* 17.15.3 */
78   PORT_TIMER_T      rbWhile;      /* 17.15.4 */
79   PORT_TIMER_T      rcvdInfoWhile;/* 17.15.5 */
80   PORT_TIMER_T      rrWhile;      /* 17.15.6 */
81   PORT_TIMER_T      tcWhile;      /* 17.15.7 */
82   PORT_TIMER_T      txCount;      /* 17.18.40 */
83   PORT_TIMER_T      lnkWhile;
84 
85   PORT_TIMER_T*     timers[TIMERS_NUMBER]; /*list of timers */
86 
87   Bool              agreed;        /* 17.18.1 */
88   PRIO_VECTOR_T     designPrio;    /* 17.18.2 */
89   TIMEVALUES_T      designTimes;   /* 17.18.3 */
90   Bool              forward;       /* 17.18.4 */
91   Bool              forwarding;    /* 17.18.5 */
92   INFO_IS_T         infoIs;        /* 17.18.6 */
93   Bool              initPm;        /* 17.18.7  */
94   Bool              learn;         /* 17.18.8 */
95   Bool              learning;      /* 17.18.9 */
96   Bool              mcheck;        /* 17.18.10 */
97   PRIO_VECTOR_T     msgPrio;       /* 17.18.11 */
98   TIMEVALUES_T      msgTimes;      /* 17.18.12 */
99   Bool              newInfo;       /* 17.18.13 */
100   Bool              operEdge;      /* 17.18.14 */
101   Bool              adminEdge;     /* 17.18.14 */
102   Bool              portEnabled;   /* 17.18.15 */
103   PORT_ID           port_id;       /* 17.18.16 */
104   PRIO_VECTOR_T     portPrio;      /* 17.18.17 */
105   TIMEVALUES_T      portTimes;     /* 17.18.18 */
106   Bool              proposed;      /* 17.18.19 */
107   Bool              proposing;     /* 17.18.20 */
108   Bool              rcvdBpdu;      /* 17.18.21 */
109   RCVD_MSG_T        rcvdMsg;       /* 17.18.22 */
110   Bool              rcvdRSTP;      /* 17/18.23 */
111   Bool              rcvdSTP;       /* 17.18.24 */
112   Bool              rcvdTc;        /* 17.18.25 */
113   Bool              rcvdTcAck;     /* 17.18.26 */
114   Bool              rcvdTcn;       /* 17.18.27 */
115   Bool              reRoot;        /* 17.18.28 */
116   Bool              reselect;      /* 17.18.29 */
117   PORT_ROLE_T       role;          /* 17.18.30 */
118   Bool              selected;      /* 17.18.31 */
119   PORT_ROLE_T       selectedRole;  /* 17.18.32 */
120   Bool              sendRSTP;      /* 17.18.33 */
121   Bool              sync;          /* 17.18.34 */
122   Bool              synced;        /* 17.18.35 */
123   Bool              tc;            /* 17.18.36 */
124   Bool              tcAck;         /* 17.18.37 */
125   Bool              tcProp;        /* 17.18.38 */
126 
127   Bool              updtInfo;      /* 17.18.41 */
128 
129   /* message information */
130   unsigned char     msgBpduVersion;
131   unsigned char     msgBpduType;
132   unsigned char     msgPortRole;
133   unsigned char     msgFlags;
134 
135   unsigned long     adminPCost; /* may be ADMIN_PORT_PATH_COST_AUTO */
136   unsigned long     operPCost;
137   unsigned long     operSpeed;
138   unsigned long     usedSpeed;
139   int               LinkDelay;   /* TBD: LinkDelay may be managed ? */
140   Bool              adminEnable; /* 'has LINK' */
141   Bool              wasInitBpdu;
142   Bool              admin_non_stp;
143 
144   Bool              p2p_recompute;
145   Bool              operPointToPointMac;
146   ADMIN_P2P_T       adminPointToPointMac;
147 
148   /* statistics */
149   unsigned long     rx_cfg_bpdu_cnt;
150   unsigned long     rx_rstp_bpdu_cnt;
151   unsigned long     rx_tcn_bpdu_cnt;
152 
153   unsigned long     uptime;       /* 14.8.2.1.3.a */
154 
155   int               port_index;
156   char*             port_name;
157 
158 #ifdef STP_DBG
159   unsigned int	    skip_rx;
160   unsigned int	    skip_tx;
161 #endif
162 } PORT_T;
163 
164 PORT_T*
165 STP_port_create (struct stpm_t* stpm, int port_index);
166 
167 void
168 STP_port_delete (PORT_T* this);
169 
170 int
171 STP_port_rx_bpdu (PORT_T* this, BPDU_T* bpdu, size_t len);
172 
173 void
174 STP_port_init (PORT_T* this, struct stpm_t* stpm, Bool check_link);
175 
176 #ifdef STP_DBG
177 int
178 STP_port_trace_state_machine (PORT_T* this, char* mach_name, int enadis);
179 
180 void
181 STP_port_trace_flags (char* title, PORT_T* this);
182 #endif
183 
184 #endif /*  _STP_PORT_H__ */
185 
186