2 * Copyright (c) 2011-2014 M3S, Srl - Italy
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * Rapid Spanning Tree Protocol (IEEE 802.1D-2004) public interface.
21 * Martino Fornasa <mf@fornasa.it>
22 * Daniele Venturino <daniele.venturino@m3s.it>
24 * References to IEEE 802.1D-2004 standard are enclosed in square brackets.
25 * E.g. [17.3], [Table 17-1], etc.
32 #include "rstp-common.h"
33 #include "rstp-state-machines.h"
34 #include <arpa/inet.h>
36 #include <netinet/in.h>
38 #include <sys/types.h>
39 #include "byte-order.h"
40 #include "connectivity.h"
42 #include "ofproto/ofproto.h"
49 VLOG_DEFINE_THIS_MODULE(rstp
);
51 struct ovs_mutex rstp_mutex
= OVS_MUTEX_INITIALIZER
;
53 static struct list all_rstps__
= LIST_INITIALIZER(&all_rstps__
);
54 static struct list
*const all_rstps
OVS_GUARDED_BY(rstp_mutex
) = &all_rstps__
;
56 /* Internal use only. */
57 static void rstp_set_bridge_address__(struct rstp
*, rstp_identifier
)
58 OVS_REQUIRES(rstp_mutex
);
59 static void rstp_set_bridge_priority__(struct rstp
*, int new_priority
)
60 OVS_REQUIRES(rstp_mutex
);
61 static void rstp_set_bridge_ageing_time__(struct rstp
*, int new_ageing_time
)
62 OVS_REQUIRES(rstp_mutex
);
63 static void rstp_set_bridge_force_protocol_version__(struct rstp
*,
64 enum rstp_force_protocol_version
)
65 OVS_REQUIRES(rstp_mutex
);
66 static void rstp_set_bridge_hello_time__(struct rstp
*)
67 OVS_REQUIRES(rstp_mutex
);
68 static void rstp_set_bridge_max_age__(struct rstp
*, int new_max_age
)
69 OVS_REQUIRES(rstp_mutex
);
70 static void rstp_set_bridge_forward_delay__(struct rstp
*, int new_forward_delay
)
71 OVS_REQUIRES(rstp_mutex
);
72 static void rstp_set_bridge_transmit_hold_count__(struct rstp
*,
73 int new_transmit_hold_count
)
74 OVS_REQUIRES(rstp_mutex
);
75 static void rstp_set_bridge_migrate_time__(struct rstp
*)
76 OVS_REQUIRES(rstp_mutex
);
77 static void rstp_set_bridge_times__(struct rstp
*, int new_forward_delay
,
78 int new_hello_time
, int new_max_age
,
80 OVS_REQUIRES(rstp_mutex
);
82 static struct rstp_port
*rstp_get_port__(struct rstp
*rstp
,
84 OVS_REQUIRES(rstp_mutex
);
85 static void set_port_id__(struct rstp_port
*)
86 OVS_REQUIRES(rstp_mutex
);
87 static void update_port_enabled__(struct rstp_port
*)
88 OVS_REQUIRES(rstp_mutex
);
89 static void set_bridge_priority__(struct rstp
*)
90 OVS_REQUIRES(rstp_mutex
);
91 static void reinitialize_rstp__(struct rstp
*)
92 OVS_REQUIRES(rstp_mutex
);
93 static bool is_port_number_available__(struct rstp
*, int, struct rstp_port
*)
94 OVS_REQUIRES(rstp_mutex
);
95 static uint16_t rstp_first_free_number__(struct rstp
*, struct rstp_port
*)
96 OVS_REQUIRES(rstp_mutex
);
97 static void rstp_initialize_port_defaults__(struct rstp_port
*)
98 OVS_REQUIRES(rstp_mutex
);
99 static void rstp_port_set_priority__(struct rstp_port
*, int priority
)
100 OVS_REQUIRES(rstp_mutex
);
101 static void rstp_port_set_port_number__(struct rstp_port
*,
102 uint16_t port_number
)
103 OVS_REQUIRES(rstp_mutex
);
104 static void rstp_port_set_path_cost__(struct rstp_port
*, uint32_t path_cost
)
105 OVS_REQUIRES(rstp_mutex
);
106 static void rstp_port_set_administrative_bridge_port__(struct rstp_port
*,
107 uint8_t admin_port_state
,
109 OVS_REQUIRES(rstp_mutex
);
110 static void rstp_port_set_admin_edge__(struct rstp_port
*, bool admin_edge
)
111 OVS_REQUIRES(rstp_mutex
);
112 static void rstp_port_set_auto_edge__(struct rstp_port
*, bool auto_edge
)
113 OVS_REQUIRES(rstp_mutex
);
114 static void rstp_port_set_admin_point_to_point_mac__(struct rstp_port
*,
115 enum rstp_admin_point_to_point_mac_state admin_p2p_mac_state
)
116 OVS_REQUIRES(rstp_mutex
);
117 static void rstp_port_set_mcheck__(struct rstp_port
*, bool mcheck
)
118 OVS_REQUIRES(rstp_mutex
);
119 static void reinitialize_port__(struct rstp_port
*p
)
120 OVS_REQUIRES(rstp_mutex
);
123 rstp_state_name(enum rstp_state state
)
130 case RSTP_FORWARDING
:
132 case RSTP_DISCARDING
:
140 rstp_port_role_name(enum rstp_port_role role
)
145 case ROLE_DESIGNATED
:
158 /* Caller has to hold a reference to prevent 'rstp' from being deleted
159 * while taking a new reference. */
161 rstp_ref(struct rstp
*rstp
)
162 OVS_EXCLUDED(rstp_mutex
)
165 ovs_refcount_ref(&rstp
->ref_cnt
);
170 /* Frees RSTP struct when reference count reaches zero. */
172 rstp_unref(struct rstp
*rstp
)
173 OVS_EXCLUDED(rstp_mutex
)
175 if (rstp
&& ovs_refcount_unref_relaxed(&rstp
->ref_cnt
) == 1) {
176 ovs_mutex_lock(&rstp_mutex
);
178 /* Each RSTP port points back to struct rstp without holding a
179 * reference for that pointer. This is OK as we never move
180 * ports from one bridge to another, and holders always
181 * release their ports before releasing the bridge. This
182 * means that there should be not ports at this time. */
183 ovs_assert(hmap_is_empty(&rstp
->ports
));
185 list_remove(&rstp
->node
);
186 ovs_mutex_unlock(&rstp_mutex
);
192 /* Returns the port number. Mutex is needed to guard against
193 * concurrent reinitialization (which can temporarily clear the
196 rstp_port_get_number(const struct rstp_port
*p
)
197 OVS_EXCLUDED(rstp_mutex
)
201 ovs_mutex_lock(&rstp_mutex
);
202 number
= p
->port_number
;
203 ovs_mutex_unlock(&rstp_mutex
);
208 static void rstp_unixctl_tcn(struct unixctl_conn
*, int argc
,
209 const char *argv
[], void *aux
);
211 /* Decrements the State Machines' timers. */
213 rstp_tick_timers(struct rstp
*rstp
)
214 OVS_EXCLUDED(rstp_mutex
)
216 ovs_mutex_lock(&rstp_mutex
);
217 decrease_rstp_port_timers__(rstp
);
218 ovs_mutex_unlock(&rstp_mutex
);
221 /* Processes an incoming BPDU. */
223 rstp_port_received_bpdu(struct rstp_port
*rp
, const void *bpdu
,
225 OVS_EXCLUDED(rstp_mutex
)
227 ovs_mutex_lock(&rstp_mutex
);
228 /* Only process packets on ports that have RSTP enabled. */
229 if (rp
&& rp
->rstp_state
!= RSTP_DISABLED
) {
230 process_received_bpdu__(rp
, bpdu
, bpdu_size
);
232 ovs_mutex_unlock(&rstp_mutex
);
237 OVS_EXCLUDED(rstp_mutex
)
239 unixctl_command_register("rstp/tcn", "[bridge]", 0, 1, rstp_unixctl_tcn
,
243 /* Creates and returns a new RSTP instance that initially has no ports. */
245 rstp_create(const char *name
, rstp_identifier bridge_address
,
246 void (*send_bpdu
)(struct ofpbuf
*bpdu
, void *port_aux
,
249 OVS_EXCLUDED(rstp_mutex
)
253 VLOG_DBG("Creating RSTP instance");
255 rstp
= xzalloc(sizeof *rstp
);
256 rstp
->name
= xstrdup(name
);
258 /* Initialize the ports map before calling any setters,
259 * so that the state machines will see an empty ports map. */
260 hmap_init(&rstp
->ports
);
262 ovs_mutex_lock(&rstp_mutex
);
263 /* Set bridge address. */
264 rstp_set_bridge_address__(rstp
, bridge_address
);
265 /* Set default parameters values. */
266 rstp_set_bridge_priority__(rstp
, RSTP_DEFAULT_PRIORITY
);
267 rstp_set_bridge_ageing_time__(rstp
, RSTP_DEFAULT_AGEING_TIME
);
268 rstp_set_bridge_force_protocol_version__(rstp
, FPV_DEFAULT
);
269 rstp_set_bridge_forward_delay__(rstp
, RSTP_DEFAULT_BRIDGE_FORWARD_DELAY
);
270 rstp_set_bridge_hello_time__(rstp
);
271 rstp_set_bridge_max_age__(rstp
, RSTP_DEFAULT_BRIDGE_MAX_AGE
);
272 rstp_set_bridge_migrate_time__(rstp
);
273 rstp_set_bridge_transmit_hold_count__(rstp
,
274 RSTP_DEFAULT_TRANSMIT_HOLD_COUNT
);
275 rstp_set_bridge_times__(rstp
, RSTP_DEFAULT_BRIDGE_FORWARD_DELAY
,
276 RSTP_BRIDGE_HELLO_TIME
,
277 RSTP_DEFAULT_BRIDGE_MAX_AGE
, 0);
278 rstp
->send_bpdu
= send_bpdu
;
280 rstp
->changes
= false;
283 ovs_refcount_init(&rstp
->ref_cnt
);
285 list_push_back(all_rstps
, &rstp
->node
);
286 ovs_mutex_unlock(&rstp_mutex
);
288 VLOG_DBG("RSTP instance creation done");
292 /* Called by rstp_set_bridge_address() and rstp_set_bridge_priority(),
293 * it updates the bridge priority vector according to the values passed by
297 set_bridge_priority__(struct rstp
*rstp
)
298 OVS_REQUIRES(rstp_mutex
)
302 rstp
->bridge_priority
.root_bridge_id
= rstp
->bridge_identifier
;
303 rstp
->bridge_priority
.designated_bridge_id
= rstp
->bridge_identifier
;
304 VLOG_DBG("%s: new bridge identifier: "RSTP_ID_FMT
"", rstp
->name
,
305 RSTP_ID_ARGS(rstp
->bridge_identifier
));
307 /* [17.13] When the bridge address changes, recalculates all priority
310 HMAP_FOR_EACH (p
, node
, &rstp
->ports
) {
314 rstp
->changes
= true;
315 updt_roles_tree__(rstp
);
318 /* Sets the bridge address. */
320 rstp_set_bridge_address__(struct rstp
*rstp
, rstp_identifier bridge_address
)
321 OVS_REQUIRES(rstp_mutex
)
323 VLOG_DBG("%s: set bridge address to: "RSTP_ID_FMT
"", rstp
->name
,
324 RSTP_ID_ARGS(bridge_address
));
326 rstp
->address
= bridge_address
;
327 rstp
->bridge_identifier
= bridge_address
;
328 set_bridge_priority__(rstp
);
331 /* Sets the bridge address. */
333 rstp_set_bridge_address(struct rstp
*rstp
, rstp_identifier bridge_address
)
334 OVS_EXCLUDED(rstp_mutex
)
336 ovs_mutex_lock(&rstp_mutex
);
337 rstp_set_bridge_address__(rstp
, bridge_address
);
338 ovs_mutex_unlock(&rstp_mutex
);
342 rstp_get_name(const struct rstp
*rstp
)
343 OVS_EXCLUDED(rstp_mutex
)
347 ovs_mutex_lock(&rstp_mutex
);
349 ovs_mutex_unlock(&rstp_mutex
);
354 rstp_get_bridge_id(const struct rstp
*rstp
)
355 OVS_EXCLUDED(rstp_mutex
)
357 rstp_identifier bridge_id
;
359 ovs_mutex_lock(&rstp_mutex
);
360 bridge_id
= rstp
->bridge_identifier
;
361 ovs_mutex_unlock(&rstp_mutex
);
366 /* Sets the bridge priority. */
368 rstp_set_bridge_priority__(struct rstp
*rstp
, int new_priority
)
369 OVS_REQUIRES(rstp_mutex
)
371 new_priority
= ROUND_DOWN(new_priority
, RSTP_PRIORITY_STEP
);
373 if (new_priority
>= RSTP_MIN_PRIORITY
374 && new_priority
<= RSTP_MAX_PRIORITY
) {
375 VLOG_DBG("%s: set bridge priority to %d", rstp
->name
, new_priority
);
377 rstp
->priority
= new_priority
;
378 rstp
->bridge_identifier
&= 0x0000ffffffffffffULL
;
379 rstp
->bridge_identifier
|= (uint64_t)new_priority
<< 48;
380 set_bridge_priority__(rstp
);
385 rstp_set_bridge_priority(struct rstp
*rstp
, int new_priority
)
386 OVS_EXCLUDED(rstp_mutex
)
388 ovs_mutex_lock(&rstp_mutex
);
389 rstp_set_bridge_priority__(rstp
, new_priority
);
390 ovs_mutex_unlock(&rstp_mutex
);
393 /* Sets the bridge ageing time. */
395 rstp_set_bridge_ageing_time__(struct rstp
*rstp
, int new_ageing_time
)
396 OVS_REQUIRES(rstp_mutex
)
398 if (new_ageing_time
>= RSTP_MIN_AGEING_TIME
399 && new_ageing_time
<= RSTP_MAX_AGEING_TIME
) {
400 VLOG_DBG("%s: set ageing time to %d", rstp
->name
, new_ageing_time
);
402 rstp
->ageing_time
= new_ageing_time
;
407 rstp_set_bridge_ageing_time(struct rstp
*rstp
, int new_ageing_time
)
408 OVS_EXCLUDED(rstp_mutex
)
410 ovs_mutex_lock(&rstp_mutex
);
411 rstp_set_bridge_ageing_time__(rstp
, new_ageing_time
);
412 ovs_mutex_unlock(&rstp_mutex
);
415 /* Reinitializes RSTP when switching from RSTP mode to STP mode
419 reinitialize_rstp__(struct rstp
*rstp
)
420 OVS_REQUIRES(rstp_mutex
)
423 static struct hmap ports
;
426 /* Copy rstp in temp */
430 /* stop and clear rstp */
431 memset(rstp
, 0, sizeof(struct rstp
));
433 /* Initialize rstp. */
434 rstp
->name
= temp
.name
;
436 /* Initialize the ports hmap before calling any setters,
437 * so that the state machines will see an empty ports list. */
438 hmap_init(&rstp
->ports
);
440 /* Set bridge address. */
441 rstp_set_bridge_address__(rstp
, temp
.address
);
442 /* Set default parameters values. */
443 rstp_set_bridge_priority__(rstp
, RSTP_DEFAULT_PRIORITY
);
444 rstp_set_bridge_ageing_time__(rstp
, RSTP_DEFAULT_AGEING_TIME
);
445 rstp_set_bridge_forward_delay__(rstp
, RSTP_DEFAULT_BRIDGE_FORWARD_DELAY
);
446 rstp_set_bridge_hello_time__(rstp
);
447 rstp_set_bridge_max_age__(rstp
, RSTP_DEFAULT_BRIDGE_MAX_AGE
);
448 rstp_set_bridge_migrate_time__(rstp
);
449 rstp_set_bridge_transmit_hold_count__(rstp
,
450 RSTP_DEFAULT_TRANSMIT_HOLD_COUNT
);
451 rstp_set_bridge_times__(rstp
, RSTP_DEFAULT_BRIDGE_FORWARD_DELAY
,
452 RSTP_BRIDGE_HELLO_TIME
,
453 RSTP_DEFAULT_BRIDGE_MAX_AGE
, 0);
455 rstp
->send_bpdu
= temp
.send_bpdu
;
456 rstp
->aux
= temp
.aux
;
457 rstp
->node
= temp
.node
;
458 rstp
->changes
= false;
464 HMAP_FOR_EACH (p
, node
, &rstp
->ports
) {
465 reinitialize_port__(p
);
468 rstp
->ref_cnt
= temp
.ref_cnt
;
471 /* Sets the force protocol version parameter. */
473 rstp_set_bridge_force_protocol_version__(struct rstp
*rstp
,
474 enum rstp_force_protocol_version new_force_protocol_version
)
475 OVS_REQUIRES(rstp_mutex
)
477 if (new_force_protocol_version
!= rstp
->force_protocol_version
&&
478 (new_force_protocol_version
== FPV_STP_COMPATIBILITY
||
479 new_force_protocol_version
== FPV_DEFAULT
)) {
480 VLOG_DBG("%s: set bridge Force Protocol Version to %d", rstp
->name
,
481 new_force_protocol_version
);
483 /* [17.13] The Spanning Tree Protocol Entity shall be reinitialized,
484 * as specified by the assertion of BEGIN (17.18.1) in the state
485 * machine specification.
487 reinitialize_rstp__(rstp
);
488 rstp
->force_protocol_version
= new_force_protocol_version
;
489 if (rstp
->force_protocol_version
< 2) {
490 rstp
->stp_version
= true;
491 rstp
->rstp_version
= false;
493 rstp
->stp_version
= false;
494 rstp
->rstp_version
= true;
496 rstp
->changes
= true;
502 rstp_set_bridge_force_protocol_version(struct rstp
*rstp
,
503 enum rstp_force_protocol_version new_force_protocol_version
)
504 OVS_EXCLUDED(rstp_mutex
)
506 ovs_mutex_lock(&rstp_mutex
);
507 rstp_set_bridge_force_protocol_version__(rstp
, new_force_protocol_version
);
508 ovs_mutex_unlock(&rstp_mutex
);
511 /* Sets the bridge Hello Time parameter. */
513 rstp_set_bridge_hello_time__(struct rstp
*rstp
)
514 OVS_REQUIRES(rstp_mutex
)
516 VLOG_DBG("%s: set RSTP Hello Time to %d", rstp
->name
,
517 RSTP_BRIDGE_HELLO_TIME
);
518 /* 2 is the only acceptable value. */
519 rstp
->bridge_hello_time
= RSTP_BRIDGE_HELLO_TIME
;
522 /* Sets the bridge max age parameter. */
524 rstp_set_bridge_max_age__(struct rstp
*rstp
, int new_max_age
)
525 OVS_REQUIRES(rstp_mutex
)
527 if (rstp
->bridge_max_age
!= new_max_age
528 && new_max_age
>= RSTP_MIN_BRIDGE_MAX_AGE
529 && new_max_age
<= RSTP_MAX_BRIDGE_MAX_AGE
) {
531 if ((2 * (rstp
->bridge_forward_delay
- 1) >= new_max_age
)
532 && (new_max_age
>= 2 * rstp
->bridge_hello_time
)) {
533 VLOG_DBG("%s: set RSTP bridge Max Age to %d", rstp
->name
,
536 rstp
->bridge_max_age
= new_max_age
;
537 rstp
->bridge_times
.max_age
= new_max_age
;
538 rstp
->changes
= true;
539 updt_roles_tree__(rstp
);
545 rstp_set_bridge_max_age(struct rstp
*rstp
, int new_max_age
)
546 OVS_EXCLUDED(rstp_mutex
)
548 ovs_mutex_lock(&rstp_mutex
);
549 rstp_set_bridge_max_age__(rstp
, new_max_age
);
550 ovs_mutex_unlock(&rstp_mutex
);
553 /* Sets the bridge forward delay parameter. */
555 rstp_set_bridge_forward_delay__(struct rstp
*rstp
, int new_forward_delay
)
556 OVS_REQUIRES(rstp_mutex
)
558 if (rstp
->bridge_forward_delay
!= new_forward_delay
559 && new_forward_delay
>= RSTP_MIN_BRIDGE_FORWARD_DELAY
560 && new_forward_delay
<= RSTP_MAX_BRIDGE_FORWARD_DELAY
) {
561 if (2 * (new_forward_delay
- 1) >= rstp
->bridge_max_age
) {
562 VLOG_DBG("%s: set RSTP Forward Delay to %d", rstp
->name
,
564 rstp
->bridge_forward_delay
= new_forward_delay
;
565 rstp
->bridge_times
.forward_delay
= new_forward_delay
;
566 rstp
->changes
= true;
567 updt_roles_tree__(rstp
);
573 rstp_set_bridge_forward_delay(struct rstp
*rstp
, int new_forward_delay
)
574 OVS_EXCLUDED(rstp_mutex
)
576 ovs_mutex_lock(&rstp_mutex
);
577 rstp_set_bridge_forward_delay__(rstp
, new_forward_delay
);
578 ovs_mutex_unlock(&rstp_mutex
);
581 /* Sets the bridge transmit hold count parameter. */
583 rstp_set_bridge_transmit_hold_count__(struct rstp
*rstp
,
584 int new_transmit_hold_count
)
585 OVS_REQUIRES(rstp_mutex
)
587 if (new_transmit_hold_count
>= RSTP_MIN_TRANSMIT_HOLD_COUNT
588 && new_transmit_hold_count
<= RSTP_MAX_TRANSMIT_HOLD_COUNT
) {
591 VLOG_DBG("%s: set RSTP Transmit Hold Count to %d", rstp
->name
,
592 new_transmit_hold_count
);
593 /* Resetting txCount on all ports [17.13]. */
595 rstp
->transmit_hold_count
= new_transmit_hold_count
;
596 HMAP_FOR_EACH (p
, node
, &rstp
->ports
) {
603 rstp_set_bridge_transmit_hold_count(struct rstp
*rstp
,
604 int new_transmit_hold_count
)
605 OVS_EXCLUDED(rstp_mutex
)
607 ovs_mutex_lock(&rstp_mutex
);
608 rstp_set_bridge_transmit_hold_count__(rstp
, new_transmit_hold_count
);
609 ovs_mutex_unlock(&rstp_mutex
);
612 /* Sets the bridge migrate time parameter. */
614 rstp_set_bridge_migrate_time__(struct rstp
*rstp
)
615 OVS_REQUIRES(rstp_mutex
)
617 VLOG_DBG("%s: set RSTP Migrate Time to %d", rstp
->name
,
619 /* 3 is the only acceptable value */
620 rstp
->migrate_time
= RSTP_MIGRATE_TIME
;
623 /* Sets the bridge times. */
625 rstp_set_bridge_times__(struct rstp
*rstp
, int new_forward_delay
,
626 int new_hello_time
, int new_max_age
,
628 OVS_REQUIRES(rstp_mutex
)
630 VLOG_DBG("%s: set RSTP times to (%d, %d, %d, %d)", rstp
->name
,
631 new_forward_delay
, new_hello_time
, new_max_age
, new_message_age
);
632 if (new_forward_delay
>= RSTP_MIN_BRIDGE_FORWARD_DELAY
633 && new_forward_delay
<= RSTP_MAX_BRIDGE_FORWARD_DELAY
) {
634 rstp
->bridge_times
.forward_delay
= new_forward_delay
;
636 if (new_hello_time
== RSTP_BRIDGE_HELLO_TIME
) {
637 rstp
->bridge_times
.hello_time
= new_hello_time
;
639 if (new_max_age
>= RSTP_MIN_BRIDGE_MAX_AGE
640 && new_max_age
<= RSTP_MAX_BRIDGE_MAX_AGE
) {
641 rstp
->bridge_times
.max_age
= new_max_age
;
643 rstp
->bridge_times
.message_age
= new_message_age
;
646 /* Sets the port id, it is called by rstp_port_set_port_number__() or
647 * rstp_port_set_priority__().
650 set_port_id__(struct rstp_port
*p
)
651 OVS_REQUIRES(rstp_mutex
)
656 /* [9.2.7] Port identifier. */
657 p
->port_id
= p
->port_number
| (p
->priority
<< 8);
658 VLOG_DBG("%s: new RSTP port id "RSTP_PORT_ID_FMT
"", rstp
->name
,
662 /* Sets the port priority. */
664 rstp_port_set_priority__(struct rstp_port
*port
, int priority
)
665 OVS_REQUIRES(rstp_mutex
)
667 if (priority
>= RSTP_MIN_PORT_PRIORITY
668 && priority
<= RSTP_MAX_PORT_PRIORITY
) {
669 VLOG_DBG("%s, port %u: set RSTP port priority to %d", port
->rstp
->name
,
670 port
->port_number
, priority
);
672 priority
-= priority
% RSTP_STEP_PORT_PRIORITY
;
673 port
->priority
= priority
;
675 port
->selected
= false;
676 port
->reselect
= true;
680 /* Checks if a port number is available. */
682 is_port_number_available__(struct rstp
*rstp
, int n
, struct rstp_port
*port
)
683 OVS_REQUIRES(rstp_mutex
)
685 if (n
>= 1 && n
<= RSTP_MAX_PORTS
) {
686 struct rstp_port
*p
= rstp_get_port__(rstp
, n
);
688 return p
== NULL
|| p
== port
;
694 rstp_first_free_number__(struct rstp
*rstp
, struct rstp_port
*rstp_port
)
695 OVS_REQUIRES(rstp_mutex
)
699 while (free_number
<= RSTP_MAX_PORTS
) {
700 if (is_port_number_available__(rstp
, free_number
, rstp_port
)) {
705 VLOG_DBG("%s, No free port number available.", rstp
->name
);
709 /* Sets the port number. */
711 rstp_port_set_port_number__(struct rstp_port
*port
, uint16_t port_number
)
712 OVS_REQUIRES(rstp_mutex
)
714 int old_port_number
= port
->port_number
;
716 /* If new_port_number is available, use it, otherwise use the first free
717 * available port number. */
719 is_port_number_available__(port
->rstp
, port_number
, port
)
721 : rstp_first_free_number__(port
->rstp
, port
);
723 if (port
->port_number
!= old_port_number
) {
725 /* [17.13] is not clear. I suppose that a port number change
726 * should trigger reselection like a port priority change. */
727 port
->selected
= false;
728 port
->reselect
= true;
730 /* Adjust the ports hmap. */
731 if (!hmap_node_is_null(&port
->node
)) {
732 hmap_remove(&port
->rstp
->ports
, &port
->node
);
734 hmap_insert(&port
->rstp
->ports
, &port
->node
,
735 hash_int(port
->port_number
, 0));
737 VLOG_DBG("%s: set new RSTP port number %d", port
->rstp
->name
,
742 /* Converts the link speed to a port path cost [Table 17-3]. */
744 rstp_convert_speed_to_cost(unsigned int speed
)
748 value
= speed
>= 10000000 ? 2 /* 10 Tb/s. */
749 : speed
>= 1000000 ? 20 /* 1 Tb/s. */
750 : speed
>= 100000 ? 200 /* 100 Gb/s. */
751 : speed
>= 10000 ? 2000 /* 10 Gb/s. */
752 : speed
>= 1000 ? 20000 /* 1 Gb/s. */
753 : speed
>= 100 ? 200000 /* 100 Mb/s. */
754 : speed
>= 10 ? 2000000 /* 10 Mb/s. */
755 : speed
>= 1 ? 20000000 /* 1 Mb/s. */
756 : RSTP_DEFAULT_PORT_PATH_COST
; /* 100 Mb/s. */
761 /* Sets the port path cost. */
763 rstp_port_set_path_cost__(struct rstp_port
*port
, uint32_t path_cost
)
764 OVS_REQUIRES(rstp_mutex
)
766 if (path_cost
>= RSTP_MIN_PORT_PATH_COST
767 && path_cost
<= RSTP_MAX_PORT_PATH_COST
) {
768 VLOG_DBG("%s, port %u, set RSTP port path cost to %d",
769 port
->rstp
->name
, port
->port_number
, path_cost
);
771 port
->port_path_cost
= path_cost
;
772 port
->selected
= false;
773 port
->reselect
= true;
777 /* Gets the root path cost. */
779 rstp_get_root_path_cost(const struct rstp
*rstp
)
780 OVS_EXCLUDED(rstp_mutex
)
784 ovs_mutex_lock(&rstp_mutex
);
785 cost
= rstp
->root_priority
.root_path_cost
;
786 ovs_mutex_unlock(&rstp_mutex
);
790 /* Finds a port which needs to flush its own MAC learning table. A NULL
791 * pointer is returned if no port needs to flush its MAC learning table.
792 * '*port' needs to be NULL in the first call to start the iteration. If
793 * '*port' is passed as non-NULL, it must be the value set by the last
794 * invocation of this function.
796 * This function may only be called by the thread that creates and deletes
797 * ports. Otherwise this function is not thread safe, as the returned
798 * '*port' could become stale before it is used in the next invocation. */
800 rstp_check_and_reset_fdb_flush(struct rstp
*rstp
, struct rstp_port
**port
)
801 OVS_EXCLUDED(rstp_mutex
)
805 ovs_mutex_lock(&rstp_mutex
);
809 HMAP_FOR_EACH (p
, node
, &rstp
->ports
) {
816 } else { /* continue */
817 struct rstp_port
*p
= *port
;
819 HMAP_FOR_EACH_CONTINUE (p
, node
, &rstp
->ports
) {
827 /* No port needs flushing. */
830 /* fdb_flush should be reset by the filtering database
831 * once the entries are removed if rstp_version is TRUE, and
832 * immediately if stp_version is TRUE.*/
834 (*port
)->fdb_flush
= false;
836 ovs_mutex_unlock(&rstp_mutex
);
841 /* Finds a port whose state has changed, and returns the aux pointer set for
842 * the port. A NULL pointer is returned when no changed port is found. On
843 * return '*portp' contains the pointer to the rstp port that changed, or NULL
844 * if no changed port can be found.
846 * If '*portp' is passed as non-NULL, it must be the value set by the last
847 * invocation of this function.
849 * This function may only be called by the thread that creates and deletes
850 * ports. Otherwise this function is not thread safe, as the returned
851 * '*portp' could become stale before it is used in the next invocation. */
853 rstp_get_next_changed_port_aux(struct rstp
*rstp
, struct rstp_port
**portp
)
857 ovs_mutex_lock(&rstp_mutex
);
858 if (*portp
== NULL
) {
861 HMAP_FOR_EACH (p
, node
, &rstp
->ports
) {
862 if (p
->state_changed
) {
863 p
->state_changed
= false;
869 } else { /* continue */
870 struct rstp_port
*p
= *portp
;
872 HMAP_FOR_EACH_CONTINUE (p
, node
, &rstp
->ports
) {
873 if (p
->state_changed
) {
874 p
->state_changed
= false;
881 /* No changed port found. */
884 ovs_mutex_unlock(&rstp_mutex
);
890 rstp_shift_root_learned_address(struct rstp
*rstp
)
894 ovs_mutex_lock(&rstp_mutex
);
895 ret
= rstp
->root_changed
;
896 ovs_mutex_unlock(&rstp_mutex
);
902 rstp_get_old_root_aux(struct rstp
*rstp
)
906 ovs_mutex_lock(&rstp_mutex
);
907 aux
= rstp
->old_root_aux
;
908 ovs_mutex_unlock(&rstp_mutex
);
914 rstp_get_new_root_aux(struct rstp
*rstp
)
918 ovs_mutex_lock(&rstp_mutex
);
919 aux
= rstp
->new_root_aux
;
920 ovs_mutex_unlock(&rstp_mutex
);
926 rstp_reset_root_changed(struct rstp
*rstp
)
928 ovs_mutex_lock(&rstp_mutex
);
929 rstp
->root_changed
= false;
930 ovs_mutex_unlock(&rstp_mutex
);
933 /* Returns the port in 'rstp' with number 'port_number'.
935 * XXX: May only be called while concurrent deletion of ports is excluded. */
936 static struct rstp_port
*
937 rstp_get_port__(struct rstp
*rstp
, uint16_t port_number
)
938 OVS_REQUIRES(rstp_mutex
)
940 struct rstp_port
*port
;
942 ovs_assert(rstp
&& port_number
> 0 && port_number
<= RSTP_MAX_PORTS
);
944 HMAP_FOR_EACH_WITH_HASH (port
, node
, hash_int(port_number
, 0),
946 if (port
->port_number
== port_number
) {
954 rstp_get_port(struct rstp
*rstp
, uint16_t port_number
)
955 OVS_EXCLUDED(rstp_mutex
)
959 ovs_mutex_lock(&rstp_mutex
);
960 p
= rstp_get_port__(rstp
, port_number
);
961 ovs_mutex_unlock(&rstp_mutex
);
966 rstp_get_port_aux__(struct rstp
*rstp
, uint16_t port_number
)
967 OVS_REQUIRES(rstp_mutex
)
970 p
= rstp_get_port__(rstp
, port_number
);
977 /* Updates the port_enabled parameter. */
979 update_port_enabled__(struct rstp_port
*p
)
980 OVS_REQUIRES(rstp_mutex
)
982 if (p
->mac_operational
&& p
->is_administrative_bridge_port
983 == RSTP_ADMIN_BRIDGE_PORT_STATE_ENABLED
) {
984 p
->port_enabled
= true;
986 p
->port_enabled
= false;
990 /* Sets the port MAC_Operational parameter [6.4.2]. */
992 rstp_port_set_mac_operational(struct rstp_port
*p
, bool new_mac_operational
)
993 OVS_EXCLUDED(rstp_mutex
)
997 ovs_mutex_lock(&rstp_mutex
);
999 if (p
->mac_operational
!= new_mac_operational
) {
1000 p
->mac_operational
= new_mac_operational
;
1001 update_port_enabled__(p
);
1002 rstp
->changes
= true;
1005 ovs_mutex_unlock(&rstp_mutex
);
1008 /* Sets the port Administrative Bridge Port parameter. */
1010 rstp_port_set_administrative_bridge_port__(struct rstp_port
*p
,
1011 uint8_t admin_port_state
,
1013 OVS_REQUIRES(rstp_mutex
)
1015 VLOG_DBG("%s, port %u: set RSTP port admin-port-state to %d",
1016 p
->rstp
->name
, p
->port_number
, admin_port_state
);
1018 if (admin_port_state
== RSTP_ADMIN_BRIDGE_PORT_STATE_DISABLED
1019 || admin_port_state
== RSTP_ADMIN_BRIDGE_PORT_STATE_ENABLED
) {
1021 p
->is_administrative_bridge_port
= admin_port_state
;
1022 update_port_enabled__(p
);
1024 if (!initializing
) {
1025 struct rstp
*rstp
= p
->rstp
;
1027 rstp
->changes
= true;
1033 /* Sets the port oper_point_to_point_mac parameter. */
1035 rstp_port_set_oper_point_to_point_mac__(struct rstp_port
*p
,
1036 uint8_t new_oper_p2p_mac
)
1037 OVS_REQUIRES(rstp_mutex
)
1039 if (new_oper_p2p_mac
== RSTP_OPER_P2P_MAC_STATE_DISABLED
1040 || new_oper_p2p_mac
== RSTP_OPER_P2P_MAC_STATE_ENABLED
) {
1042 p
->oper_point_to_point_mac
= new_oper_p2p_mac
;
1043 update_port_enabled__(p
);
1047 /* Initializes a port with the defaults values for its parameters. */
1049 rstp_initialize_port_defaults__(struct rstp_port
*p
)
1050 OVS_REQUIRES(rstp_mutex
)
1052 rstp_port_set_administrative_bridge_port__(p
,
1053 RSTP_ADMIN_BRIDGE_PORT_STATE_ENABLED
,
1055 rstp_port_set_oper_point_to_point_mac__(p
,
1056 RSTP_OPER_P2P_MAC_STATE_ENABLED
);
1057 rstp_port_set_path_cost__(p
, RSTP_DEFAULT_PORT_PATH_COST
);
1058 rstp_port_set_admin_edge__(p
, false);
1059 rstp_port_set_auto_edge__(p
, true);
1060 rstp_port_set_mcheck__(p
, false);
1062 /* Initialize state machines. */
1063 p
->port_receive_sm_state
= PORT_RECEIVE_SM_INIT
;
1064 p
->port_protocol_migration_sm_state
= PORT_PROTOCOL_MIGRATION_SM_INIT
;
1065 p
->bridge_detection_sm_state
= BRIDGE_DETECTION_SM_INIT
;
1066 p
->port_transmit_sm_state
= PORT_TRANSMIT_SM_INIT
;
1067 p
->port_information_sm_state
= PORT_INFORMATION_SM_INIT
;
1068 p
->port_role_transition_sm_state
= PORT_ROLE_TRANSITION_SM_INIT
;
1069 p
->port_state_transition_sm_state
= PORT_STATE_TRANSITION_SM_INIT
;
1070 p
->topology_change_sm_state
= TOPOLOGY_CHANGE_SM_INIT
;
1076 reinitialize_port__(struct rstp_port
*p
)
1077 OVS_REQUIRES(rstp_mutex
)
1079 struct rstp_port temp_port
;
1084 memset(p
, 0, sizeof(struct rstp_port
));
1086 p
->ref_cnt
= temp_port
.ref_cnt
;
1088 p
->node
= temp_port
.node
;
1089 p
->aux
= temp_port
.aux
;
1090 p
->port_number
= temp_port
.port_number
;
1091 p
->port_priority
= temp_port
.port_priority
;
1092 p
->port_id
= temp_port
.port_id
;
1093 p
->rstp_state
= RSTP_DISCARDING
;
1095 rstp_initialize_port_defaults__(p
);
1097 VLOG_DBG("%s: RSTP port "RSTP_PORT_ID_FMT
" reinitialized.", rstp
->name
,
1102 reinitialize_port(struct rstp_port
*p
)
1103 OVS_EXCLUDED(rstp_mutex
)
1105 ovs_mutex_lock(&rstp_mutex
);
1106 reinitialize_port__(p
);
1107 ovs_mutex_unlock(&rstp_mutex
);
1110 /* Sets the port state. */
1112 rstp_port_set_state__(struct rstp_port
*p
, enum rstp_state state
)
1113 OVS_REQUIRES(rstp_mutex
)
1118 VLOG_DBG("%s, port %u: set RSTP port state %s -> %s", rstp
->name
,
1120 rstp_state_name(p
->rstp_state
), rstp_state_name(state
));
1122 if (state
!= p
->rstp_state
&& !p
->state_changed
) {
1123 p
->state_changed
= true;
1124 seq_change(connectivity_seq_get());
1126 p
->rstp_state
= state
;
1130 rstp_port_set_state(struct rstp_port
*p
, enum rstp_state state
)
1131 OVS_EXCLUDED(rstp_mutex
)
1133 ovs_mutex_lock(&rstp_mutex
);
1134 rstp_port_set_state__(p
, state
);
1135 ovs_mutex_unlock(&rstp_mutex
);
1138 /* Adds a RSTP port. */
1140 rstp_add_port(struct rstp
*rstp
)
1141 OVS_EXCLUDED(rstp_mutex
)
1143 struct rstp_port
*p
= xzalloc(sizeof *p
);
1145 ovs_refcount_init(&p
->ref_cnt
);
1146 hmap_node_nullify(&p
->node
);
1148 ovs_mutex_lock(&rstp_mutex
);
1150 rstp_port_set_priority__(p
, RSTP_DEFAULT_PORT_PRIORITY
);
1151 rstp_port_set_port_number__(p
, 0);
1153 rstp_initialize_port_defaults__(p
);
1154 VLOG_DBG("%s: RSTP port "RSTP_PORT_ID_FMT
" initialized.", rstp
->name
,
1157 rstp_port_set_state__(p
, RSTP_DISCARDING
);
1158 rstp
->changes
= true;
1160 VLOG_DBG("%s: added port "RSTP_PORT_ID_FMT
"", rstp
->name
, p
->port_id
);
1161 ovs_mutex_unlock(&rstp_mutex
);
1165 /* Caller has to hold a reference to prevent 'rstp_port' from being deleted
1166 * while taking a new reference. */
1168 rstp_port_ref(const struct rstp_port
*rp_
)
1169 OVS_EXCLUDED(rstp_mutex
)
1171 struct rstp_port
*rp
= CONST_CAST(struct rstp_port
*, rp_
);
1174 ovs_refcount_ref(&rp
->ref_cnt
);
1179 /* Frees RSTP struct. This can be caller by any thread. */
1181 rstp_port_unref(struct rstp_port
*rp
)
1182 OVS_EXCLUDED(rstp_mutex
)
1184 if (rp
&& ovs_refcount_unref_relaxed(&rp
->ref_cnt
) == 1) {
1187 ovs_mutex_lock(&rstp_mutex
);
1189 rstp_port_set_state__(rp
, RSTP_DISABLED
);
1190 hmap_remove(&rstp
->ports
, &rp
->node
);
1191 VLOG_DBG("%s: removed port "RSTP_PORT_ID_FMT
"", rstp
->name
,
1193 ovs_mutex_unlock(&rstp_mutex
);
1198 /* Sets the port Admin Edge parameter. */
1200 rstp_port_set_admin_edge__(struct rstp_port
*port
, bool admin_edge
)
1201 OVS_REQUIRES(rstp_mutex
)
1203 if (port
->admin_edge
!= admin_edge
) {
1204 VLOG_DBG("%s, port %u: set RSTP Admin Edge to %d", port
->rstp
->name
,
1205 port
->port_number
, admin_edge
);
1207 port
->admin_edge
= admin_edge
;
1211 /* Sets the port Auto Edge parameter. */
1213 rstp_port_set_auto_edge__(struct rstp_port
*port
, bool auto_edge
)
1214 OVS_REQUIRES(rstp_mutex
)
1216 if (port
->auto_edge
!= auto_edge
) {
1217 VLOG_DBG("%s, port %u: set RSTP Auto Edge to %d", port
->rstp
->name
,
1218 port
->port_number
, auto_edge
);
1220 port
->auto_edge
= auto_edge
;
1224 /* Sets the port admin_point_to_point_mac parameter. */
1225 static void rstp_port_set_admin_point_to_point_mac__(struct rstp_port
*port
,
1226 enum rstp_admin_point_to_point_mac_state admin_p2p_mac_state
)
1227 OVS_REQUIRES(rstp_mutex
)
1229 VLOG_DBG("%s, port %u: set RSTP port admin-point-to-point-mac to %d",
1230 port
->rstp
->name
, port
->port_number
, admin_p2p_mac_state
);
1232 if (admin_p2p_mac_state
== RSTP_ADMIN_P2P_MAC_FORCE_TRUE
) {
1233 port
->admin_point_to_point_mac
= admin_p2p_mac_state
;
1234 rstp_port_set_oper_point_to_point_mac__(port
,
1235 RSTP_OPER_P2P_MAC_STATE_ENABLED
);
1236 } else if (admin_p2p_mac_state
== RSTP_ADMIN_P2P_MAC_FORCE_FALSE
) {
1237 port
->admin_point_to_point_mac
= admin_p2p_mac_state
;
1238 rstp_port_set_oper_point_to_point_mac__(port
,
1239 RSTP_OPER_P2P_MAC_STATE_DISABLED
);
1240 } else if (admin_p2p_mac_state
== RSTP_ADMIN_P2P_MAC_AUTO
) {
1241 /* If adminPointToPointMAC is set to Auto, then the value of
1242 * operPointToPointMAC is determined in accordance with the
1243 * specific procedures defined for the MAC entity concerned, as
1244 * defined in 6.5. If these procedures determine that the MAC
1245 * entity is connected to a point-to-point LAN, then
1246 * operPointToPointMAC is set TRUE; otherwise it is set FALSE.
1247 * In the absence of a specific definition of how to determine
1248 * whether the MAC is connected to a point-to-point LAN or not,
1249 * the value of operPointToPointMAC shall be FALSE. */
1250 port
->admin_point_to_point_mac
= admin_p2p_mac_state
;
1251 rstp_port_set_oper_point_to_point_mac__(
1252 port
, RSTP_OPER_P2P_MAC_STATE_DISABLED
);
1256 /* Sets the port mcheck parameter.
1257 * [17.19.13] May be set by management to force the Port Protocol Migration
1258 * state machine to transmit RST BPDUs for a MigrateTime (17.13.9) period, to
1259 * test whether all STP Bridges (17.4) on the attached LAN have been removed
1260 * and the Port can continue to transmit RSTP BPDUs. Setting mcheck has no
1261 * effect if stpVersion (17.20.12) is TRUE, i.e., the Bridge is operating in
1262 * STP Compatibility mode.
1265 rstp_port_set_mcheck__(struct rstp_port
*port
, bool mcheck
)
1266 OVS_REQUIRES(rstp_mutex
)
1268 if (mcheck
== true && port
->rstp
->force_protocol_version
>= 2) {
1269 port
->mcheck
= true;
1271 VLOG_DBG("%s, port %u: set RSTP mcheck to %d", port
->rstp
->name
,
1272 port
->port_number
, mcheck
);
1276 /* Returns the designated bridge id. */
1278 rstp_get_designated_id(const struct rstp
*rstp
)
1279 OVS_EXCLUDED(rstp_mutex
)
1281 rstp_identifier designated_id
;
1283 ovs_mutex_lock(&rstp_mutex
);
1284 designated_id
= rstp
->root_priority
.designated_bridge_id
;
1285 ovs_mutex_unlock(&rstp_mutex
);
1287 return designated_id
;
1290 /* Returns the root bridge id. */
1292 rstp_get_root_id(const struct rstp
*rstp
)
1293 OVS_EXCLUDED(rstp_mutex
)
1295 rstp_identifier root_id
;
1297 ovs_mutex_lock(&rstp_mutex
);
1298 root_id
= rstp
->root_priority
.root_bridge_id
;
1299 ovs_mutex_unlock(&rstp_mutex
);
1304 /* Returns the designated port id. */
1306 rstp_get_designated_port_id(const struct rstp
*rstp
)
1307 OVS_EXCLUDED(rstp_mutex
)
1309 uint16_t designated_port_id
;
1311 ovs_mutex_lock(&rstp_mutex
);
1312 designated_port_id
= rstp
->root_priority
.designated_port_id
;
1313 ovs_mutex_unlock(&rstp_mutex
);
1315 return designated_port_id
;
1318 /* Return the bridge port id. */
1320 rstp_get_bridge_port_id(const struct rstp
*rstp
)
1321 OVS_EXCLUDED(rstp_mutex
)
1323 uint16_t bridge_port_id
;
1325 ovs_mutex_lock(&rstp_mutex
);
1326 bridge_port_id
= rstp
->root_priority
.bridge_port_id
;
1327 ovs_mutex_unlock(&rstp_mutex
);
1329 return bridge_port_id
;
1332 /* Returns true if the bridge believes to the be root of the spanning tree,
1336 rstp_is_root_bridge(const struct rstp
*rstp
)
1337 OVS_EXCLUDED(rstp_mutex
)
1341 ovs_mutex_lock(&rstp_mutex
);
1342 is_root
= rstp
->bridge_identifier
==
1343 rstp
->root_priority
.designated_bridge_id
;
1344 ovs_mutex_unlock(&rstp_mutex
);
1349 /* Returns the bridge ID of the bridge currently believed to be the root. */
1351 rstp_get_designated_root(const struct rstp
*rstp
)
1352 OVS_EXCLUDED(rstp_mutex
)
1354 rstp_identifier designated_root
;
1356 ovs_mutex_lock(&rstp_mutex
);
1357 designated_root
= rstp
->root_priority
.designated_bridge_id
;
1358 ovs_mutex_unlock(&rstp_mutex
);
1360 return designated_root
;
1363 /* Returns the port connecting 'rstp' to the root bridge, or a null pointer if
1364 * there is no such port.
1367 rstp_get_root_port(struct rstp
*rstp
)
1368 OVS_EXCLUDED(rstp_mutex
)
1370 struct rstp_port
*p
;
1372 ovs_mutex_lock(&rstp_mutex
);
1373 HMAP_FOR_EACH (p
, node
, &rstp
->ports
) {
1374 if (p
->port_id
== rstp
->root_port_id
) {
1375 ovs_mutex_unlock(&rstp_mutex
);
1379 ovs_mutex_unlock(&rstp_mutex
);
1383 /* Returns the state of port 'p'. */
1385 rstp_port_get_state(const struct rstp_port
*p
)
1386 OVS_EXCLUDED(rstp_mutex
)
1388 enum rstp_state state
;
1390 ovs_mutex_lock(&rstp_mutex
);
1391 state
= p
->rstp_state
;
1392 ovs_mutex_unlock(&rstp_mutex
);
1397 /* Retrieves port status. */
1399 rstp_port_get_status(const struct rstp_port
*p
, uint16_t *id
,
1400 enum rstp_state
*state
, enum rstp_port_role
*role
,
1401 rstp_identifier
*designated_bridge_id
,
1402 uint16_t *designated_port_id
,
1403 uint32_t *designated_path_cost
, int *tx_count
,
1404 int *rx_count
, int *error_count
, int *uptime
)
1405 OVS_EXCLUDED(rstp_mutex
)
1407 ovs_mutex_lock(&rstp_mutex
);
1409 *state
= p
->rstp_state
;
1412 *designated_bridge_id
= p
->port_priority
.designated_bridge_id
;
1413 *designated_port_id
= p
->port_priority
.designated_port_id
;
1414 *designated_path_cost
= p
->port_priority
.root_path_cost
;
1416 *tx_count
= p
->tx_count
;
1417 *rx_count
= p
->rx_rstp_bpdu_cnt
;
1418 *error_count
= p
->error_count
;
1419 *uptime
= p
->uptime
;
1420 ovs_mutex_unlock(&rstp_mutex
);
1424 rstp_port_set(struct rstp_port
*port
, uint16_t port_num
, int priority
,
1425 uint32_t path_cost
, bool is_admin_edge
, bool is_auto_edge
,
1426 enum rstp_admin_point_to_point_mac_state admin_p2p_mac_state
,
1427 bool admin_port_state
, bool do_mcheck
, void *aux
)
1428 OVS_EXCLUDED(rstp_mutex
)
1430 ovs_mutex_lock(&rstp_mutex
);
1432 rstp_port_set_priority__(port
, priority
);
1433 rstp_port_set_port_number__(port
, port_num
);
1434 rstp_port_set_path_cost__(port
, path_cost
);
1435 rstp_port_set_admin_edge__(port
, is_admin_edge
);
1436 rstp_port_set_auto_edge__(port
, is_auto_edge
);
1437 rstp_port_set_admin_point_to_point_mac__(port
, admin_p2p_mac_state
);
1438 rstp_port_set_administrative_bridge_port__(port
, admin_port_state
, false);
1439 rstp_port_set_mcheck__(port
, do_mcheck
);
1440 ovs_mutex_unlock(&rstp_mutex
);
1443 /* Individual setters only used by test-rstp.c. */
1445 rstp_port_set_priority(struct rstp_port
*port
, int priority
)
1446 OVS_EXCLUDED(rstp_mutex
)
1448 ovs_mutex_lock(&rstp_mutex
);
1449 rstp_port_set_priority__(port
, priority
);
1450 ovs_mutex_unlock(&rstp_mutex
);
1454 rstp_port_set_path_cost(struct rstp_port
*port
, uint32_t path_cost
)
1455 OVS_EXCLUDED(rstp_mutex
)
1457 ovs_mutex_lock(&rstp_mutex
);
1458 rstp_port_set_path_cost__(port
, path_cost
);
1459 ovs_mutex_unlock(&rstp_mutex
);
1463 rstp_port_set_aux(struct rstp_port
*port
, void *aux
)
1464 OVS_EXCLUDED(rstp_mutex
)
1466 ovs_mutex_lock(&rstp_mutex
);
1468 ovs_mutex_unlock(&rstp_mutex
);
1472 static struct rstp
*
1473 rstp_find(const char *name
)
1474 OVS_REQUIRES(rstp_mutex
)
1478 LIST_FOR_EACH (rstp
, node
, all_rstps
) {
1479 if (!strcmp(rstp
->name
, name
)) {
1487 rstp_unixctl_tcn(struct unixctl_conn
*conn
, int argc
,
1488 const char *argv
[], void *aux OVS_UNUSED
)
1489 OVS_EXCLUDED(rstp_mutex
)
1491 ovs_mutex_lock(&rstp_mutex
);
1493 struct rstp
*rstp
= rstp_find(argv
[1]);
1495 unixctl_command_reply_error(conn
, "No such RSTP object");
1498 rstp
->changes
= true;
1502 LIST_FOR_EACH (rstp
, node
, all_rstps
) {
1503 rstp
->changes
= true;
1507 unixctl_command_reply(conn
, "OK");
1510 ovs_mutex_unlock(&rstp_mutex
);