datapath-windows: Update OVS_SWITCH_CONTEXT: external and internal port
[cascardo/ovs.git] / lib / rstp-common.h
1 /*
2  * Copyright (c) 2011-2014 M3S, Srl - Italy
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /*
18  * Rapid Spanning Tree Protocol (IEEE 802.1D-2004) common header file.
19  *
20  * Authors:
21  *         Martino Fornasa <mf@fornasa.it>
22  *         Daniele Venturino <daniele.venturino@m3s.it>
23  *
24  * References to IEEE 802.1D-2004 standard are enclosed in square brackets.
25  * E.g. [17.3], [Table 17-1], etc.
26  *
27  */
28
29 #ifndef RSTP_COMMON_H
30 #define RSTP_COMMON_H 1
31
32 #include "rstp.h"
33 #include <stdbool.h>
34 #include <stdint.h>
35 #include "hmap.h"
36 #include "list.h"
37 #include "ovs-atomic.h"
38 #include "packets.h"
39
40 enum admin_port_state {
41     RSTP_ADMIN_BRIDGE_PORT_STATE_DISABLED = 0,
42     RSTP_ADMIN_BRIDGE_PORT_STATE_ENABLED = 1
43 };
44
45 enum oper_p2p_mac_state {
46     RSTP_OPER_P2P_MAC_STATE_DISABLED = 0,
47     RSTP_OPER_P2P_MAC_STATE_ENABLED = 1
48 };
49
50 /* State enumerations for state machines defined in rstp-state-machines.c */
51 enum port_receive_state_machine {
52     PORT_RECEIVE_SM_INIT,
53     PORT_RECEIVE_SM_DISCARD_EXEC,
54     PORT_RECEIVE_SM_DISCARD,
55     PORT_RECEIVE_SM_RECEIVE_EXEC,
56     PORT_RECEIVE_SM_RECEIVE
57 };
58 enum port_transmit_state_machine {
59     PORT_TRANSMIT_SM_INIT,
60     PORT_TRANSMIT_SM_TRANSMIT_INIT_EXEC,
61     PORT_TRANSMIT_SM_TRANSMIT_INIT,
62     PORT_TRANSMIT_SM_TRANSMIT_PERIODIC_EXEC,
63     PORT_TRANSMIT_SM_TRANSMIT_PERIODIC,
64     PORT_TRANSMIT_SM_IDLE_EXEC,
65     PORT_TRANSMIT_SM_IDLE,
66     PORT_TRANSMIT_SM_TRANSMIT_CONFIG_EXEC,
67     PORT_TRANSMIT_SM_TRANSMIT_CONFIG,
68     PORT_TRANSMIT_SM_TRANSMIT_TCN_EXEC,
69     PORT_TRANSMIT_SM_TRANSMIT_TCN,
70     PORT_TRANSMIT_SM_TRANSMIT_RSTP_EXEC,
71     PORT_TRANSMIT_SM_TRANSMIT_RSTP
72 };
73 enum bridge_detection_state_machine {
74     BRIDGE_DETECTION_SM_INIT,
75     BRIDGE_DETECTION_SM_EDGE_EXEC,
76     BRIDGE_DETECTION_SM_EDGE,
77     BRIDGE_DETECTION_SM_NOT_EDGE_EXEC,
78     BRIDGE_DETECTION_SM_NOT_EDGE
79 };
80 enum port_protocol_migration_state_machine {
81     PORT_PROTOCOL_MIGRATION_SM_INIT,
82     PORT_PROTOCOL_MIGRATION_SM_CHECKING_RSTP_EXEC,
83     PORT_PROTOCOL_MIGRATION_SM_CHECKING_RSTP,
84     PORT_PROTOCOL_MIGRATION_SM_SELECTING_STP_EXEC,
85     PORT_PROTOCOL_MIGRATION_SM_SELECTING_STP,
86     PORT_PROTOCOL_MIGRATION_SM_SENSING_EXEC,
87     PORT_PROTOCOL_MIGRATION_SM_SENSING
88 };
89 enum port_information_state_machine {
90     PORT_INFORMATION_SM_INIT,
91     PORT_INFORMATION_SM_DISABLED_EXEC,
92     PORT_INFORMATION_SM_DISABLED,
93     PORT_INFORMATION_SM_AGED_EXEC,
94     PORT_INFORMATION_SM_AGED,
95     PORT_INFORMATION_SM_UPDATE_EXEC,
96     PORT_INFORMATION_SM_UPDATE,
97     PORT_INFORMATION_SM_CURRENT_EXEC,
98     PORT_INFORMATION_SM_CURRENT,
99     PORT_INFORMATION_SM_RECEIVE_EXEC,
100     PORT_INFORMATION_SM_RECEIVE,
101     PORT_INFORMATION_SM_OTHER_EXEC,
102     PORT_INFORMATION_SM_OTHER,
103     PORT_INFORMATION_SM_NOT_DESIGNATED_EXEC,
104     PORT_INFORMATION_SM_NOT_DESIGNATED,
105     PORT_INFORMATION_SM_INFERIOR_DESIGNATED_EXEC,
106     PORT_INFORMATION_SM_INFERIOR_DESIGNATED,
107     PORT_INFORMATION_SM_REPEATED_DESIGNATED_EXEC,
108     PORT_INFORMATION_SM_REPEATED_DESIGNATED,
109     PORT_INFORMATION_SM_SUPERIOR_DESIGNATED_EXEC,
110     PORT_INFORMATION_SM_SUPERIOR_DESIGNATED
111 };
112 enum port_role_selection_state_machine {
113     PORT_ROLE_SELECTION_SM_INIT,
114     PORT_ROLE_SELECTION_SM_INIT_BRIDGE_EXEC,
115     PORT_ROLE_SELECTION_SM_INIT_BRIDGE,
116     PORT_ROLE_SELECTION_SM_ROLE_SELECTION_EXEC,
117     PORT_ROLE_SELECTION_SM_ROLE_SELECTION
118 };
119 enum port_role_transition_state_machine {
120     PORT_ROLE_TRANSITION_SM_INIT,
121     PORT_ROLE_TRANSITION_SM_INIT_PORT_EXEC,
122     PORT_ROLE_TRANSITION_SM_DISABLE_PORT_EXEC,
123     PORT_ROLE_TRANSITION_SM_DISABLE_PORT,
124     PORT_ROLE_TRANSITION_SM_DISABLED_PORT_EXEC,
125     PORT_ROLE_TRANSITION_SM_DISABLED_PORT,
126     PORT_ROLE_TRANSITION_SM_ROOT_PORT_EXEC,
127     PORT_ROLE_TRANSITION_SM_ROOT_PORT,
128     PORT_ROLE_TRANSITION_SM_REROOT_EXEC,
129     PORT_ROLE_TRANSITION_SM_ROOT_AGREED_EXEC,
130     PORT_ROLE_TRANSITION_SM_ROOT_PROPOSED_EXEC,
131     PORT_ROLE_TRANSITION_SM_ROOT_FORWARD_EXEC,
132     PORT_ROLE_TRANSITION_SM_ROOT_LEARN_EXEC,
133     PORT_ROLE_TRANSITION_SM_REROOTED_EXEC,
134     PORT_ROLE_TRANSITION_SM_DESIGNATED_PORT_EXEC,
135     PORT_ROLE_TRANSITION_SM_DESIGNATED_PORT,
136     PORT_ROLE_TRANSITION_SM_DESIGNATED_RETIRED_EXEC,
137     PORT_ROLE_TRANSITION_SM_DESIGNATED_SYNCED_EXEC,
138     PORT_ROLE_TRANSITION_SM_DESIGNATED_PROPOSE_EXEC,
139     PORT_ROLE_TRANSITION_SM_DESIGNATED_FORWARD_EXEC,
140     PORT_ROLE_TRANSITION_SM_DESIGNATED_LEARN_EXEC,
141     PORT_ROLE_TRANSITION_SM_DESIGNATED_DISCARD_EXEC,
142     PORT_ROLE_TRANSITION_SM_ALTERNATE_PORT_EXEC,
143     PORT_ROLE_TRANSITION_SM_ALTERNATE_PORT,
144     PORT_ROLE_TRANSITION_SM_ALTERNATE_AGREED,
145     PORT_ROLE_TRANSITION_SM_ALTERNATE_PROPOSED_EXEC,
146     PORT_ROLE_TRANSITION_SM_BLOCK_PORT_EXEC,
147     PORT_ROLE_TRANSITION_SM_BLOCK_PORT,
148     PORT_ROLE_TRANSITION_SM_BACKUP_PORT_EXEC
149 };
150 enum port_state_transition_state_machine {
151     PORT_STATE_TRANSITION_SM_INIT,
152     PORT_STATE_TRANSITION_SM_DISCARDING_EXEC,
153     PORT_STATE_TRANSITION_SM_DISCARDING,
154     PORT_STATE_TRANSITION_SM_LEARNING_EXEC,
155     PORT_STATE_TRANSITION_SM_LEARNING,
156     PORT_STATE_TRANSITION_SM_FORWARDING_EXEC,
157     PORT_STATE_TRANSITION_SM_FORWARDING
158 };
159 enum topology_change_state_machine {
160     TOPOLOGY_CHANGE_SM_INIT,
161     TOPOLOGY_CHANGE_SM_INACTIVE_EXEC,
162     TOPOLOGY_CHANGE_SM_INACTIVE,
163     TOPOLOGY_CHANGE_SM_LEARNING_EXEC,
164     TOPOLOGY_CHANGE_SM_LEARNING,
165     TOPOLOGY_CHANGE_SM_DETECTED_EXEC,
166     TOPOLOGY_CHANGE_SM_ACTIVE_EXEC,
167     TOPOLOGY_CHANGE_SM_ACTIVE,
168     TOPOLOGY_CHANGE_SM_ACKNOWLEDGED_EXEC,
169     TOPOLOGY_CHANGE_SM_PROPAGATING_EXEC,
170     TOPOLOGY_CHANGE_SM_NOTIFIED_TC_EXEC,
171     TOPOLOGY_CHANGE_SM_NOTIFIED_TCN_EXEC,
172 };
173
174
175 /* [17.18.4, 17.13, Table 17-1]. */
176 struct rstp_times {
177     /* [17.13.5 - Bridge Forward Delay] The delay (expressed in seconds) used
178      * by STP Bridges (17.4) to transition Root and Designated Ports to
179      * Forwarding (Table 17-1).
180      * Default = 15.0 s. Values in range 4.0 - 30.0
181      */
182     uint16_t forward_delay;
183
184     /* [17.13.6 - Bridge Hello Time]
185      * The interval between periodic transmissions of Configuration Messages
186      * by Designated Ports (Table 17-1).
187      * Default = 2.0 s. Fixed value
188      */
189     uint16_t hello_time;
190
191     /* [17.13.8 - Bridge Max Age]
192      * The maximum age of the information transmitted by the Bridge when it is
193      * the Root Bridge (Table 17-1).
194      * Default = 20.0 s. Values in range 6.0 - 40.0 */
195     uint16_t max_age;
196
197     uint16_t message_age;
198 };
199
200 /* Priority vector [17.6] */
201 struct rstp_priority_vector {
202     rstp_identifier root_bridge_id;
203     uint32_t root_path_cost;
204     rstp_identifier designated_bridge_id;
205     uint16_t designated_port_id;
206     uint16_t bridge_port_id;
207 };
208
209 enum rstp_bpdu_type {
210     CONFIGURATION_BPDU = 0x0,
211     TOPOLOGY_CHANGE_NOTIFICATION_BPDU = 0x80,
212     RAPID_SPANNING_TREE_BPDU = 0x2
213 };
214
215 enum rstp_bpdu_flag {
216     BPDU_FLAG_TOPCHANGE = 0x01,
217     BPDU_FLAG_PROPOSAL = 0x02,
218     BPDU_FLAG_LEARNING = 0x10,
219     BPDU_FLAG_FORWARDING = 0x20,
220     BPDU_FLAG_AGREEMENT = 0x40,
221     BPDU_FLAG_TOPCHANGEACK = 0x80
222 };
223
224 /* Rapid Spanning Tree BPDU [9.3.3] */
225 OVS_PACKED(
226 struct rstp_bpdu {
227     ovs_be16 protocol_identifier;
228     uint8_t protocol_version_identifier;
229     uint8_t bpdu_type;
230     uint8_t flags;
231     ovs_be64 root_bridge_id;
232     ovs_be32 root_path_cost;
233     ovs_be64 designated_bridge_id;
234     ovs_be16 designated_port_id;
235     ovs_be16 message_age;
236     ovs_be16 max_age;
237     ovs_be16 hello_time;
238     ovs_be16 forward_delay;
239     uint8_t version1_length;
240     uint8_t padding[7];
241 });
242
243 enum rstp_admin_point_to_point_mac_state {
244     RSTP_ADMIN_P2P_MAC_FORCE_TRUE,
245     RSTP_ADMIN_P2P_MAC_FORCE_FALSE,
246     RSTP_ADMIN_P2P_MAC_FORCE_AUTO
247 };
248
249 enum rstp_info_is {
250     INFO_IS_DISABLED,
251     INFO_IS_RECEIVED,
252     INFO_IS_AGED,
253     INFO_IS_MINE
254 };
255
256 enum rstp_rcvd_info {
257     SUPERIOR_DESIGNATED_INFO,
258     REPEATED_DESIGNATED_INFO,
259     INFERIOR_DESIGNATED_INFO,
260     INFERIOR_ROOT_ALTERNATE_INFO,
261     OTHER_INFO
262 };
263
264 struct rstp_port {
265     struct ovs_refcount ref_cnt;
266
267     struct rstp *rstp OVS_GUARDED_BY(rstp_mutex);
268     struct hmap_node node OVS_GUARDED_BY(rstp_mutex); /* In rstp->ports. */
269     void *aux OVS_GUARDED_BY(rstp_mutex);
270     struct rstp_bpdu received_bpdu_buffer OVS_GUARDED_BY(rstp_mutex);
271     /*************************************************************************
272      * MAC status parameters
273      ************************************************************************/
274     /* [6.4.2 - MAC_Operational]
275      * The value of this parameter is TRUE if [...] the MAC entity can be used
276      * to transmit and/or receive frames, and its use is permitted by
277      * management.
278      */
279     bool mac_operational OVS_GUARDED_BY(rstp_mutex);
280
281     /* [14.8.2.2] Administrative Bridge Port State */
282     bool is_administrative_bridge_port OVS_GUARDED_BY(rstp_mutex);
283
284     /* [6.4.3 - operPointToPointMAC]
285      *  a) True. The MAC is connected to a point-to-point LAN; i.e., there is
286      *     at most one other system attached to the LAN.
287      *  b) False. The MAC is connected to a non-point-to-point LAN; i.e.,
288      *     there can be more than one other system attached to the LAN.
289      *
290      *  If adminPointToPointMAC is set to ForceTrue, then operPointToPointMAC
291      *  shall be set True. If adminPointToPointMAC is set to ForceFalse, then
292      *  operPointToPointMAC shall be set False.
293      */
294     bool oper_point_to_point_mac OVS_GUARDED_BY(rstp_mutex);
295
296     /* [6.4.3 - adminPointToPointMAC]
297      *  a) ForceTrue. The administrator requires the MAC to be treated as if it
298      *     is connected to a point-to-point LAN, regardless of any indications
299      *     to the contrary that are generated by the MAC entity.
300      *  b) ForceFalse. The administrator requires the MAC to be treated as
301      *     connected to a non-point-to-point LAN, regardless of any indications
302      *     to the contrary that are generated by the MAC entity.
303      *  c) Auto. The administrator requires the point-to-point status of the
304      *     MAC to be determined in accordance with the specific MAC procedures
305      *     defined in 6.5.
306      */
307     enum rstp_admin_point_to_point_mac_state admin_point_to_point_mac OVS_GUARDED_BY(rstp_mutex);
308
309
310     /*************************************************************************
311      * [17.3 - RSTP performance parameters] Set by management actions on the
312      * bridge
313      *************************************************************************/
314
315     /* [17.13.1 - Admin Edge Port]
316      * The AdminEdgePort parameter for the Port (14.8.2).
317      */
318     bool admin_edge OVS_GUARDED_BY(rstp_mutex);
319
320     /* [17.13.3 - AutoEdge]
321      *  The AutoEdgePort parameter for the Port (14.8.2).
322      */
323     bool auto_edge OVS_GUARDED_BY(rstp_mutex);
324
325
326     /*************************************************************************
327      * The following variables are set by management actions on the bridge
328      ************************************************************************/
329
330     /* Port number and priority
331      * >=1 (max 12 bits [9.2.7])
332      */
333     uint16_t port_number OVS_GUARDED_BY(rstp_mutex);
334
335     /* Port priority
336      * Range: 0-240 in steps of 16 (table 17-2)
337      */
338     uint8_t priority OVS_GUARDED_BY(rstp_mutex);
339
340     /* [17.13.11 - PortPathCost]
341      * The Port's contribution, when it is the Root Port, to the Root Path Cost
342      * (17.3.1, 17.5, 17.6) for the Bridge.
343      */
344     uint32_t port_path_cost OVS_GUARDED_BY(rstp_mutex);
345
346     /*************************************************************************
347      * The following variables are defined in [17.17 - State machine timers]
348      ************************************************************************/
349     /* [17.17.1 - edgeDelayWhile]
350      * The Edge Delay timer. The time remaining, in the absence of a received
351      * BPDU, before this port is identified as an operEdgePort.
352      */
353     uint16_t edge_delay_while OVS_GUARDED_BY(rstp_mutex);
354
355     /* [17.17.2 - fdWhile]
356      * The Forward Delay timer. Used to delay Port State transitions until
357      * other Bridges have received spanning tree information.
358      */
359     uint16_t fd_while OVS_GUARDED_BY(rstp_mutex);
360
361     /* [17.17.3 - helloWhen]
362      * The Hello timer. Used to ensure that at least one BPDU is transmitted by
363      * a Designated Port in each HelloTime period.
364      */
365     uint16_t hello_when OVS_GUARDED_BY(rstp_mutex);
366
367     /* [17.17.4 - mdelayWhile]
368      * The Migration Delay timer. Used by the Port Protocol Migration state
369      * machine to allow time for another RSTP Bridge on the same LAN to
370      * synchronize its migration state with this Port before the receipt of a
371      * BPDU can cause this Port to change the BPDU types it transmits.
372      * Initialized to MigrateTime (17.13.9).
373      */
374     uint16_t mdelay_while OVS_GUARDED_BY(rstp_mutex);
375
376     /* [17.17.5 - rbWhile]
377      * The Recent Backup timer. Maintained at its initial value, twice
378      * HelloTime, while the Port is a Backup Port.
379      */
380     uint16_t rb_while OVS_GUARDED_BY(rstp_mutex);
381
382     /* [17.17.6 - rcvdInfoWhile]
383      * The Received Info timer. The time remaining before the spanning tree
384      * information received by this Port [portPriority (17.19.21) and portTimes
385      * (17.19.22)] is aged out if not refreshed by the receipt of a further
386      * Configuration Message.
387      */
388     uint16_t rcvd_info_while OVS_GUARDED_BY(rstp_mutex);
389
390     /* [17.17.7 - rrWhile]
391      * The Recent Root timer.
392      */
393     uint16_t rr_while OVS_GUARDED_BY(rstp_mutex);
394
395     /* [17.17.8 - tcWhile]
396      * The Topology Change timer. TCN Messages are sent while this timer is
397      * running.
398      */
399     uint16_t tc_while OVS_GUARDED_BY(rstp_mutex);
400
401
402     /*************************************************************************
403      * The following variables are defined in [17.19 - Per-Port variables]
404      ************************************************************************/
405
406     /* [17.19.1 - ageingTime]
407      * Filtering database entries for this Port are aged out after ageingTime
408      * has elapsed since they were first created or refreshed by the Learning
409      * Process.
410      * The value of this parameter is normally Ageing Time (7.9.2, Table 7-5),
411      * and is changed to FwdDelay (17.20.6) for a period of FwdDelay after
412      * fdbFlush (17.19.7) is set by the topology change state machine if
413      * stpVersion (17.19.7) is TRUE.
414      */
415     uint32_t ageing_time OVS_GUARDED_BY(rstp_mutex);
416
417     /* [17.19.2 - agree]
418      * Set if synced is set for all other Ports. An RST BPDU with the Agreement
419      * flag set is transmitted and proposed is reset when agree is first set,
420      * and when proposed is set.
421      * Initialized by Port Information state machine.
422      */
423     bool agree OVS_GUARDED_BY(rstp_mutex);
424
425     /* [17.19.3 - agreed]
426      * Set when an RST BPDU is received with a Port Role of Root, Alternate, or
427      * Backup Port, the Agreement flag set, and a message priority the same or
428      * worse than the port priority. When agreed is set, the Designated Port
429      * knows that its neighbouring Bridge has confirmed that it can proceed to
430      * the Forwarding state without further delay.
431      * Initialized by Port Information state machine.
432      */
433     bool agreed OVS_GUARDED_BY(rstp_mutex);
434
435     /* [17.19.4 - designatedPriority]
436      * The first four components of the Port's designated priority vector
437      * value, as defined in 17.6. The fifth component of the designated
438      * priority vector value is portId (17.19.19).
439      * (Fifth component of the structure must not be used)
440      */
441     struct rstp_priority_vector designated_priority_vector OVS_GUARDED_BY(rstp_mutex);
442
443     /* [17.19.5 - designatedTimes]
444      * The designatedTimes variable comprises the set of timer parameter values
445      * (Message Age, Max Age, Forward Delay, and Hello Time) that used to
446      * update Port Times when updtInfo is set. Updated by the updtRolesTree()
447      * procedure (17.21.25).
448      */
449     struct rstp_times designated_times OVS_GUARDED_BY(rstp_mutex);
450
451     /* [17.19.6 - disputed] */
452     bool disputed OVS_GUARDED_BY(rstp_mutex);
453
454     /* [17.19.7 - fdbFlush]
455      * A boolean. Set by the topology change state machine to instruct the
456      * filtering database to remove all entries for this Port, immediately if
457      * rstpVersion (17.20.11) is TRUE, or by rapid ageing (17.19.1) if
458      * stpVersion (17.20.12) is TRUE. Reset by the filtering database once the
459      * entries are
460      * removed if rstpVersion is TRUE, and immediately if stpVersion is TRUE.
461      */
462     uint8_t fdb_flush OVS_GUARDED_BY(rstp_mutex);
463
464     /* [17.19.8 - forward]
465      * Initialized by Port State Transition state machine.
466      */
467     bool forward OVS_GUARDED_BY(rstp_mutex);
468
469     /* [17.19.9 - forwarding]
470      * Initialized by Port State Transition state machine.
471      */
472     bool forwarding OVS_GUARDED_BY(rstp_mutex);
473
474     /* [17.19.10 - infoIs]
475      * A variable that takes the values Mine, Aged, Received, or Disabled, to
476      * indicate the origin/state of the Port's Spanning Tree information
477      * (portInfo) held for the Port, as follows:
478      *  a) If infoIs is Received, the port has received current (not aged out)
479      *     information from the Designated Bridge for the attached LAN (a
480      *     point-to-point bridge link being a special case of a LAN).
481      *  b) If infoIs is Mine, information for the port has been derived from
482      *     the Root Port for the Bridge (with the addition of root port cost
483      *     information). This includes the possibility that the Root Port is
484      *     "Port 0," i.e., the bridge is the Root Bridge for the Bridged Local
485      *     Area Network.
486      *  c) If infoIs is Aged, information from the Root Bridge has been aged
487      *     out. Just as for "reselect" (see 17.19.34), the state machine does
488      *     not formally allow the "Aged" state to persist. However, if there is
489      *     a delay in recomputing the new root port, correct processing of a
490      *     received BPDU is specified.
491      *  d) Finally if the port is disabled, infoIs is Disabled.
492      */
493     enum rstp_info_is info_is OVS_GUARDED_BY(rstp_mutex);
494
495     /* [17.19.11 - learn]
496      * Initialized by Port State Transition state machine.
497      */
498     bool learn OVS_GUARDED_BY(rstp_mutex);
499
500     /* [17.19.12 - learning]
501      * Initialized by Port State Transition state machine.
502      */
503     bool learning OVS_GUARDED_BY(rstp_mutex);
504
505     /* [17.19.13 - mcheck]
506      * A boolean. May be set by management to force the Port Protocol Migration
507      * state machine to transmit RST BPDUs for a MigrateTime (17.13.9) period,
508      * to test whether all STP Bridges (17.4) on the attached LAN have been
509      * removed and the Port can continue to transmit RSTP BPDUs. Setting mcheck
510      * has no effect if stpVersion (17.20.12) is TRUE, i.e., the Bridge is
511      * operating in STP Compatibility mode.
512      */
513     bool mcheck OVS_GUARDED_BY(rstp_mutex);
514
515     /* [17.19.14 - msgPriority]
516      * The first four components of the message priority vector conveyed in a
517      * received BPDU, as defined in 17.6.
518      * (Fifth component of the structure must not be used).
519      */
520     struct rstp_priority_vector msg_priority OVS_GUARDED_BY(rstp_mutex);
521
522     /* [17.19.15 - msgTimes]
523      * The msgTimes variable comprises the timer parameter values (Message Age,
524      * Max Age, Forward Delay, and Hello Time) conveyed in a received BPDU.
525      */
526     struct rstp_times msg_times OVS_GUARDED_BY(rstp_mutex);
527
528     /* [17.19.16 - newInfo]
529      * A boolean. Set if a BPDU is to be transmitted. Reset by the Port
530      * Transmit state machine.
531      */
532     bool new_info OVS_GUARDED_BY(rstp_mutex);
533
534     /* [17.19.17 - operEdge]
535      * A boolean. The value of the operEdgePort parameter, as determined by the
536      * operation of the Bridge Detection state machine (17.25).
537      */
538     bool oper_edge OVS_GUARDED_BY(rstp_mutex);
539
540     /* [17.19.18 - portEnabled]
541      * A boolean. Set if the Bridge's MAC Relay Entity and Spanning Tree
542      * Protocol Entity can use the MAC Service provided by the Port's MAC
543      * entity to transmit and receive frames to and from the attached LAN,
544      * i.e., portEnabled is TRUE if and only if:
545      *    a) MAC_Operational (6.4.2) is TRUE; and
546      *    b) Administrative Bridge Port State (14.8.2.2) for the Port is
547      *       Enabled; and
548      *    c) AuthControlledPortStatus is Authorized [if the port is a network
549      *       access port (IEEE Std 802.1X)].
550      */
551     bool port_enabled OVS_GUARDED_BY(rstp_mutex);
552
553     /* [17.19.19 - portId]
554      * The Port Identifier. This variable forms the fifth component of the port
555      * priority and designated priority vectors defined in 17.6.
556      */
557     uint16_t port_id OVS_GUARDED_BY(rstp_mutex);
558
559     /* [17.19.21 - portPriority]
560      * The first four components of the Port's port priority vector value, as
561      * defined in 17.6.
562      * (Fifth component of the structure must not be used)
563      */
564     struct rstp_priority_vector port_priority OVS_GUARDED_BY(rstp_mutex);
565
566     /* [17.19.22 - portTimes]
567      * The portTimes variable comprises the Port's timer parameter values
568      * (Message Age, Max Age, Forward Delay, and Hello Time). These timer
569      * values are used in BPDUs transmitted from the Port.
570      */
571     struct rstp_times port_times OVS_GUARDED_BY(rstp_mutex);
572
573     /* [17.19.23 - proposed]
574      * Set when an RST BPDU with a Designated Port role and the Proposal flag
575      * set is received. If agree is not set, proposed causes sync to be set for
576      * all other Ports.of the Bridge.
577      */
578     bool proposed OVS_GUARDED_BY(rstp_mutex);
579
580     /* [17.19.24 - proposing]
581      * Set by a Designated Port that is not Forwarding, and conveyed to the
582      * Root Port or Alternate Port of a neighboring Bridge in the Proposal flag
583      * of an RST BPDU (9.3.3).
584      */
585     bool proposing OVS_GUARDED_BY(rstp_mutex);
586
587     /* [17.19.25 - rcvdBPDU]
588      * A boolean. Set by system dependent processes, this variable notifies the
589      * Port Receive state machine (17.23) when a valid (9.3.4) Configuration,
590      * TCN, or RST BPDU (9.3.1, 9.3.2, 9.3.3) is received on the Port. Reset
591      * by the Port Receive state machine.
592      */
593     bool rcvd_bpdu OVS_GUARDED_BY(rstp_mutex);
594
595     /* [17.19.26 - rcvdInfo]
596      * Set to the result of the rcvInfo() procedure (17.21.8).
597      */
598     enum rstp_rcvd_info rcvd_info OVS_GUARDED_BY(rstp_mutex);
599
600     /* [17.19.27 - rcvdMsg] */
601     bool rcvd_msg OVS_GUARDED_BY(rstp_mutex);
602
603     /* [17.19.28 - rcvdRSTP] */
604     bool rcvd_rstp OVS_GUARDED_BY(rstp_mutex);
605
606     /* [17.19.29 - rcvdSTP] */
607     bool rcvd_stp OVS_GUARDED_BY(rstp_mutex);
608
609     /* [17.19.30 - rcvdTc] */
610     bool rcvd_tc OVS_GUARDED_BY(rstp_mutex);
611
612     /* [17.19.31 - rcvdTcAck] */
613     bool rcvd_tc_ack OVS_GUARDED_BY(rstp_mutex);
614
615     /* [17.19.32 - rcvdTcn] */
616     bool rcvd_tcn OVS_GUARDED_BY(rstp_mutex);
617
618     /* [17.19.33 - reRoot] */
619     bool re_root OVS_GUARDED_BY(rstp_mutex);
620
621     /* [17.19.34 - reselect] */
622     bool reselect OVS_GUARDED_BY(rstp_mutex);
623
624     /* [17.19.35 - role]
625      * The assigned Port Role (17.7).
626      */
627     enum rstp_port_role role OVS_GUARDED_BY(rstp_mutex);
628
629     /* [17.19.36 - selected]
630      * A boolean. See 17.28, 17.21.16.
631      */
632     bool selected OVS_GUARDED_BY(rstp_mutex);
633
634     /* [17.19.37 - selectedRole]
635      * The newly computed role for the Port (17.7, 17.28, 17.21.25, 17.19.35).
636      */
637     enum rstp_port_role selected_role OVS_GUARDED_BY(rstp_mutex);
638
639     /* [17.19.38 - sendRSTP]
640      * A boolean. See 17.24, 17.26.
641      */
642     bool send_rstp OVS_GUARDED_BY(rstp_mutex);
643
644     /* [17.19.39 - sync]
645      * A boolean. See 17.10.
646      */
647     bool sync OVS_GUARDED_BY(rstp_mutex);
648
649     /* [17.19.40 - synced]
650      * A boolean. See 17.10.
651      */
652     bool synced OVS_GUARDED_BY(rstp_mutex);
653
654     /* [17.19.41 - tcAck]
655      * A boolean. Set if a Configuration Message with a topology change
656      * acknowledge flag set is to be transmitted.
657      */
658     bool tc_ack OVS_GUARDED_BY(rstp_mutex);
659
660     /* [17.19.42 - tcProp]
661      * A boolean. Set by the Topology Change state machine of any other Port,
662      * to indicate that a topology change should be propagated through this
663      * Port.
664      */
665     bool tc_prop OVS_GUARDED_BY(rstp_mutex);
666
667     /* [17.19.43 - tick]
668      * A boolean. See 17.22.
669      */
670     bool tick OVS_GUARDED_BY(rstp_mutex);
671
672     /* [17.19.44 - txCount]
673      * A counter. Incremented by the Port Transmission (17.26) state machine on
674      * every BPDU transmission, and decremented used by the Port Timers state
675      * machine (17.22) once a second. Transmissions are delayed if txCount
676      * reaches TxHoldCount (17.13.12).
677      */
678     uint16_t tx_count OVS_GUARDED_BY(rstp_mutex);
679
680     /* [17.19.45 - updtInfo]
681      * A boolean. Set by the Port Role Selection state machine (17.28,
682      * 17.21.25) to tell the Port Information state machine that it should copy
683      * designatedPriority to portPriority and designatedTimes to portTimes.
684      */
685     bool updt_info OVS_GUARDED_BY(rstp_mutex);
686
687     /* Counter for RSTP received frames - for rstpd */
688     uint32_t rx_rstp_bpdu_cnt;
689
690     /* Counter for bad RSTP received frames */
691     uint32_t error_count OVS_GUARDED_BY(rstp_mutex);
692
693     /* [14.8.2.1.3] Outputs
694      * a) Uptime count in seconds of the time elapsed since the Port was last
695      *    reset or initialized.
696      */
697     uint32_t uptime OVS_GUARDED_BY(rstp_mutex);
698
699     enum rstp_state rstp_state OVS_GUARDED_BY(rstp_mutex);
700     bool state_changed OVS_GUARDED_BY(rstp_mutex);
701
702     /* Per-port state machines state */
703     enum port_receive_state_machine port_receive_sm_state OVS_GUARDED_BY(rstp_mutex);
704     enum port_protocol_migration_state_machine port_protocol_migration_sm_state OVS_GUARDED_BY(rstp_mutex);
705     enum bridge_detection_state_machine bridge_detection_sm_state OVS_GUARDED_BY(rstp_mutex);
706     enum port_transmit_state_machine port_transmit_sm_state OVS_GUARDED_BY(rstp_mutex);
707     enum port_information_state_machine port_information_sm_state OVS_GUARDED_BY(rstp_mutex);
708     enum port_role_transition_state_machine port_role_transition_sm_state OVS_GUARDED_BY(rstp_mutex);
709     enum port_state_transition_state_machine port_state_transition_sm_state OVS_GUARDED_BY(rstp_mutex);
710     enum topology_change_state_machine topology_change_sm_state OVS_GUARDED_BY(rstp_mutex);
711 };
712
713 struct rstp {
714     struct list node OVS_GUARDED_BY(rstp_mutex);   /* In rstp instances list */
715     char *name;     /* Bridge name. */
716
717     /* Changes in last SM execution. */
718     bool changes OVS_GUARDED_BY(rstp_mutex);
719
720     /* Per-bridge state machines state */
721     enum port_role_selection_state_machine port_role_selection_sm_state OVS_GUARDED_BY(rstp_mutex);
722
723     /* Bridge MAC address
724      * (stored in the least significant 48 bits of rstp_identifier).
725      */
726     rstp_identifier address OVS_GUARDED_BY(rstp_mutex); /* [7.12.5] */
727
728     /* Bridge priority */
729     uint16_t priority OVS_GUARDED_BY(rstp_mutex);      /* Valid values: 0-61440 in steps of 4096 */
730
731     /*************************************************************************
732      * [17.3 - RSTP performance parameters]
733      ************************************************************************/
734
735     /* [17.13]
736      * The Spanning Tree Protocol Entity shall be reinitialized, as specified
737      * by the assertion of BEGIN (17.18.1) in the state machine specification,
738      * if the following parameters are modified:
739      *  a) Force Protocol Version (17.13.4)
740      *
741      * The spanning tree priority vectors and Port Role assignments for a
742      * Bridge shall be recomputed, as specified by the operation of the Port
743      * Role Selection state machine (17.28) by clearing selected (17.19.36) and
744      * setting reselect (17.19.34) for any Port or Ports for which the
745      * following parameters are modified:
746      *  b) Bridge Identifier Priority (17.13.7)
747      *  c) Port Identifier Priority (17.13.10)
748      *  d) Port Path Cost (17.13.11)
749      *
750      * If the Transmit Hold Count is modified the value of txCount (17.19.44)
751      * for all Ports shall be set to zero.
752      *
753      * The RSTP specification permits changes in other performance parameters
754      * without exceptional actions.
755      */
756
757
758     /* [17.13.2 - Ageing Time]
759      * The Ageing Time parameter for the Bridge (7.9.2, Table 7-5).
760      */
761     uint32_t ageing_time OVS_GUARDED_BY(rstp_mutex);
762
763     /* [17.13.4 - Force Protocol Version]
764      * The Force Protocol Version parameter for the Bridge (17.4, 14.8.1).
765      * This can take the value 0 (STP Compatibility mode) or 2 (the default,
766      * normal operation).
767      */
768     enum rstp_force_protocol_version force_protocol_version OVS_GUARDED_BY(rstp_mutex);
769
770     /* [17.13.5 - Bridge Forward Delay]
771      *  The delay used by STP Bridges (17.4) to transition Root and Designated
772      * Ports to Forwarding (Table 17-1).
773      */
774     uint16_t bridge_forward_delay OVS_GUARDED_BY(rstp_mutex);
775
776     /* [17.13.6 - Bridge Hello Time]
777      *  The interval between periodic transmissions of Configuration Messages
778      * by Designated Ports (Table 17-1).
779      */
780     uint16_t bridge_hello_time OVS_GUARDED_BY(rstp_mutex);
781
782     /* [17.13.8 - Bridge Max Age]
783      * The maximum age of the information transmitted by the Bridge when it is
784      * the Root Bridge (Table 17-1).
785      */
786     uint16_t bridge_max_age OVS_GUARDED_BY(rstp_mutex);
787
788     /* [17.13.9 - Migrate Time]
789      * The initial value of the mdelayWhile and edgeDelayWhile timers (17.17.4,
790      * 17.17.1), fixed for all RSTP implementations conforming to this
791      * specification (Table 17-1).
792      */
793     uint16_t migrate_time OVS_GUARDED_BY(rstp_mutex);
794
795     /* [17.13.12 - Transmit Hold Count]
796      * The Transmit Hold Count (Table 17-1) used by the Port Transmit state
797      * machine to limit transmission rate.
798      */
799     uint16_t transmit_hold_count OVS_GUARDED_BY(rstp_mutex);
800
801
802     /*************************************************************************
803      * The following variables are defined in [17.18 - Per-Bridge variables]
804      ************************************************************************/
805
806     /* [17.18.1 - BEGIN]
807      * A Boolean controlled by the system initialization (17.16). If TRUE
808      * causes all state machines, including per Port state machines, to
809      * continuously execute their initial state.
810      */
811     bool begin OVS_GUARDED_BY(rstp_mutex);
812
813     /* [17.18.2 BridgeIdentifier]
814      * The unique Bridge Identifier assigned to this Bridge, comprising two
815      * components: the Bridge Identifier Priority, which may be modified by
816      * management (see 9.2.5 and 14.8.1.2) and is the more significant when
817      * Bridge Identifiers are compared, and a component derived from the Bridge
818      * Address (7.12.5), which guarantees uniqueness of the Bridge Identifiers
819      * of different Bridges.
820      */
821     rstp_identifier bridge_identifier OVS_GUARDED_BY(rstp_mutex);
822
823     /* [17.8.3 BridgePriority]
824      * The bridge priority vector, as defined in 17.6. The first (RootBridgeID)
825      * and third (DesignatedBridgeID) components are both equal to the value
826      * of the Bridge Identifier (17.18.2). The other components are zero.
827      */
828     struct rstp_priority_vector bridge_priority OVS_GUARDED_BY(rstp_mutex);
829
830     /* [17.18.4 - BridgeTimes]
831      * BridgeTimes comprises four components: the current values of Bridge
832      * Forward Delay, Bridge Hello Time, Bridge Max Age (17.13, Table 17-1),
833      * and a Message Age of zero.
834      */
835     struct rstp_times bridge_times OVS_GUARDED_BY(rstp_mutex);
836
837     /* [17.18.6 - rootPriority]
838      * The first four components of the Bridge's root priority vector, as
839      * defined in 17.6.
840      */
841     struct rstp_priority_vector root_priority OVS_GUARDED_BY(rstp_mutex);
842
843     /* [17.18.5 - rootPortId]
844      * The Port Identifier of the Root Port. This is the fifth component of
845      * the root priority vector, as defined in 17.6.
846      */
847     uint16_t root_port_id OVS_GUARDED_BY(rstp_mutex);
848
849     /* [17.18.7 - rootTimes]
850      * The rootTimes variable comprises the Bridge's operational timer
851      * parameter values (Message Age, Max Age, Forward Delay, and Hello Time),
852      * derived from the values stored in portTimes (17.19.22) for the Root Port
853      * or from BridgeTimes (17.18.4).
854      */
855     struct rstp_times root_times OVS_GUARDED_BY(rstp_mutex);
856
857     /* 17.20 State machine conditions and parameters */
858
859     /* [17.20.11] rstpVersion
860      * TRUE if Force Protocol Version (17.13.4) is greater than or equal to 2.
861      */
862     bool rstp_version OVS_GUARDED_BY(rstp_mutex);
863
864     /* [17.20.12] stpVersion
865      * TRUE if Force Protocol Version (17.13.4) is less than 2.
866      */
867     bool stp_version OVS_GUARDED_BY(rstp_mutex);
868
869     /* Ports */
870     struct hmap ports OVS_GUARDED_BY(rstp_mutex);
871
872     struct ovs_refcount ref_cnt;
873
874     /* Interface to client. */
875     void (*send_bpdu)(struct ofpbuf *bpdu, void *port_aux, void *rstp_aux);
876     void *aux;
877 };
878
879 #endif /* rstp-common.h */