1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
|
/************************************************************************
* RSTP library - Rapid Spanning Tree (802.1t, 802.1w)
* Copyright (C) 2001-2003 Optical Access
* Author: Alex Rozin
*
* This file is part of RSTP library.
*
* RSTP library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation; version 2.1
*
* RSTP library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with RSTP library; see the file COPYING. If not, write to the Free
* Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
**********************************************************************/
/* STP PORT instance : 17.18, 17.15 */
#include "base.h"
#include "stpm.h"
#include "stp_in.h"
/* #include "rolesel.h" */
#include "portinfo.h"
#include "roletrns.h"
#include "sttrans.h"
#include "topoch.h"
#include "migrate.h"
#include "transmit.h"
#include "p2p.h"
#include "pcost.h"
#include "edge.h"
#include "stp_to.h" /* for STP_OUT_get_port_name & STP_OUT_get_port_link_status */
int port_trace_flags;
PORT_T *
STP_port_create (STPM_T* stpm, int port_index)
{
PORT_T* this;
UID_STP_PORT_CFG_T port_cfg;
register int iii;
unsigned short port_prio;
/* check, if the port has just been added */
for (this = stpm->ports; this; this = this->next) {
if (this->port_index == port_index) {
return NULL;
}
}
STP_NEW_IN_LIST(this, PORT_T, stpm->ports, "port create");
this->owner = stpm;
this->machines = NULL;
this->port_index = port_index;
this->port_name = strdup (STP_OUT_get_port_name (port_index));
this->uptime = 0;
STP_OUT_get_init_port_cfg (stpm->vlan_id, port_index, &port_cfg);
port_prio = port_cfg.port_priority;
this->admin_non_stp = port_cfg.admin_non_stp;
this->adminEdge = port_cfg.admin_edge;
this->adminPCost = port_cfg.admin_port_path_cost;
this->adminPointToPointMac = port_cfg.admin_point2point;
this->LinkDelay = DEF_LINK_DELAY;
this->port_id = (port_prio << 8) + port_index;
iii = 0;
this->timers[iii++] = &this->fdWhile;
this->timers[iii++] = &this->helloWhen;
this->timers[iii++] = &this->mdelayWhile;
this->timers[iii++] = &this->rbWhile;
this->timers[iii++] = &this->rcvdInfoWhile;
this->timers[iii++] = &this->rrWhile;
this->timers[iii++] = &this->tcWhile;
this->timers[iii++] = &this->txCount;
this->timers[iii++] = &this->lnkWhile;
/* create and bind port state machines */
STP_STATE_MACH_IN_LIST(topoch);
STP_STATE_MACH_IN_LIST(migrate);
STP_STATE_MACH_IN_LIST(p2p);
STP_STATE_MACH_IN_LIST(edge);
STP_STATE_MACH_IN_LIST(pcost)
STP_STATE_MACH_IN_LIST(info);
STP_STATE_MACH_IN_LIST(roletrns);
STP_STATE_MACH_IN_LIST(sttrans);
STP_STATE_MACH_IN_LIST(transmit);
#ifdef STP_DBG
#if 0
this->roletrns->ignoreHop2State = 14; /* DESIGNATED_PORT; */
this->info->ignoreHop2State = 3; /* CURRENT */
this->transmit->ignoreHop2State = 3; /* IDLE */
this->edge->ignoreHop2State = 0; /* DISABLED; */
#endif
#if 0
this->info->debug = 1;
this->pcost->debug = 1;
this->p2p->debug = 1;
this->edge->debug = 1;
this->migrate->debug = 1;
this->sttrans->debug = 1;
this->topoch->debug = 1;
this->roletrns->debug = 1;
#endif
this->sttrans->debug = 1;
#endif
return this;
}
void
STP_port_init (PORT_T* this, STPM_T* stpm, Bool check_link)
{
if (check_link) {
this->adminEnable = STP_OUT_get_port_link_status (this->port_index);
STP_VECT_create (&this->designPrio,
&stpm->BrId,
0,
&stpm->BrId,
this->port_id,
this->port_id);
STP_copy_times (&this->designTimes, &stpm->rootTimes);
}
/* reset timers */
this->fdWhile =
this->helloWhen =
this->mdelayWhile =
this->rbWhile =
this->rcvdInfoWhile =
this->rrWhile =
this->tcWhile =
this->txCount = 0;
this->msgPortRole = RSTP_PORT_ROLE_UNKN;
this->selectedRole = DisabledPort;
this->sendRSTP = True;
this->operSpeed = STP_OUT_get_port_oper_speed (this->port_index);
this->p2p_recompute = True;
}
void
STP_port_delete (PORT_T* this)
{
STPM_T* stpm;
register PORT_T* prev;
register PORT_T* tmp;
register STATE_MACH_T* stater;
register void* pv;
stpm = this->owner;
free (this->port_name);
for (stater = this->machines; stater; ) {
pv = (void*) stater->next;
STP_state_mach_delete (stater);
stater = (STATE_MACH_T*) pv;
}
prev = NULL;
for (tmp = stpm->ports; tmp; tmp = tmp->next) {
if (tmp->port_index == this->port_index) {
if (prev) {
prev->next = this->next;
} else {
stpm->ports = this->next;
}
STP_FREE(this, "stp instance");
break;
}
prev = tmp;
}
}
int
STP_port_rx_bpdu (PORT_T* this, BPDU_T* bpdu, size_t len)
{
STP_info_rx_bpdu (this, bpdu, len);
return 0;
}
#ifdef STP_DBG
int STP_port_trace_state_machine (PORT_T* this, char* mach_name, int enadis)
{
STATE_MACH_T *stater;
int nmatch = 0;
for (stater = this->machines; stater; stater = stater->next) {
if (! strcmp (mach_name, "all") || ! strcmp (mach_name, stater->name)) {
if (stater->debug != enadis)
{
stp_trace ("port %s on %s trace %-8s (was %s) now %s",
this->port_name, this->owner->name,
stater->name,
stater->debug ? " enabled" :"disabled",
enadis ? " enabled" :"disabled");
}
stater->debug = enadis;
nmatch++;
}
}
if (nmatch == 0) {
stp_trace("port %s no such state machine as '%s'", this->port_name,
mach_name);
return STP_No_Such_State_Machine;
}
return 0;
}
void STP_port_trace_flags (char* title, PORT_T* this)
{
unsigned long flag = 0L;
if (!port_trace_flags) return;
if (this->reRoot) flag |= 0x000001L;
if (this->sync) flag |= 0x000002L;
if (this->synced) flag |= 0x000004L;
if (this->proposed) flag |= 0x000010L;
if (this->proposing) flag |= 0x000020L;
if (this->agreed) flag |= 0x000040L;
if (this->updtInfo) flag |= 0x000080L;
if (this->operEdge) flag |= 0x000100L;
stp_trace (" %-12s: flags=0x%04lx fdWhile=%d port=%s", title, flag, this->fdWhile, this->port_name);
}
#endif
|