2 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
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.
17 /* Based on sample implementation in 802.1D-1998. Above copyright and license
18 * applies to all modifications. */
23 #include <sys/types.h>
24 #include <netinet/in.h>
25 #include <arpa/inet.h>
28 #include "byte-order.h"
29 #include "connectivity.h"
37 VLOG_DEFINE_THIS_MODULE(stp);
39 #define STP_PROTOCOL_ID 0x0000
40 #define STP_PROTOCOL_VERSION 0x00
41 #define STP_TYPE_CONFIG 0x00
42 #define STP_TYPE_TCN 0x80
45 struct stp_bpdu_header {
46 ovs_be16 protocol_id; /* STP_PROTOCOL_ID. */
47 uint8_t protocol_version; /* STP_PROTOCOL_VERSION. */
48 uint8_t bpdu_type; /* One of STP_TYPE_*. */
50 BUILD_ASSERT_DECL(sizeof(struct stp_bpdu_header) == 4);
52 enum stp_config_bpdu_flags {
53 STP_CONFIG_TOPOLOGY_CHANGE_ACK = 0x80,
54 STP_CONFIG_TOPOLOGY_CHANGE = 0x01
58 struct stp_config_bpdu {
59 struct stp_bpdu_header header; /* Type STP_TYPE_CONFIG. */
60 uint8_t flags; /* STP_CONFIG_* flags. */
61 ovs_be64 root_id; /* 8.5.1.1: Bridge believed to be root. */
62 ovs_be32 root_path_cost; /* 8.5.1.2: Cost of path to root. */
63 ovs_be64 bridge_id; /* 8.5.1.3: ID of transmitting bridge. */
64 ovs_be16 port_id; /* 8.5.1.4: Port transmitting the BPDU. */
65 ovs_be16 message_age; /* 8.5.1.5: Age of BPDU at tx time. */
66 ovs_be16 max_age; /* 8.5.1.6: Timeout for received data. */
67 ovs_be16 hello_time; /* 8.5.1.7: Time between BPDU generation. */
68 ovs_be16 forward_delay; /* 8.5.1.8: State progression delay. */
70 BUILD_ASSERT_DECL(sizeof(struct stp_config_bpdu) == 35);
74 struct stp_bpdu_header header; /* Type STP_TYPE_TCN. */
76 BUILD_ASSERT_DECL(sizeof(struct stp_tcn_bpdu) == 4);
79 bool active; /* Timer in use? */
80 int value; /* Current value of timer, counting up. */
85 void *aux; /* Auxiliary data the user may retrieve. */
86 int port_id; /* 8.5.5.1: Unique port identifier. */
87 enum stp_state state; /* 8.5.5.2: Current state. */
88 int path_cost; /* 8.5.5.3: Cost of tx/rx on this port. */
89 stp_identifier designated_root; /* 8.5.5.4. */
90 int designated_cost; /* 8.5.5.5: Path cost to root on port. */
91 stp_identifier designated_bridge; /* 8.5.5.6. */
92 int designated_port; /* 8.5.5.7: Port to send config msgs on. */
93 bool topology_change_ack; /* 8.5.5.8: Flag for next config BPDU. */
94 bool config_pending; /* 8.5.5.9: Send BPDU when hold expires? */
95 bool change_detection_enabled; /* 8.5.5.10: Detect topology changes? */
97 struct stp_timer message_age_timer; /* 8.5.6.1: Age of received info. */
98 struct stp_timer forward_delay_timer; /* 8.5.6.2: State change timer. */
99 struct stp_timer hold_timer; /* 8.5.6.3: BPDU rate limit timer. */
101 int tx_count; /* Number of BPDUs transmitted. */
102 int rx_count; /* Number of valid BPDUs received. */
103 int error_count; /* Number of bad BPDUs received. */
109 struct list node; /* Node in all_stps list. */
111 /* Static bridge data. */
112 char *name; /* Human-readable name for log messages. */
113 stp_identifier bridge_id; /* 8.5.3.7: This bridge. */
114 int max_age; /* 8.5.3.4: Time to drop received data. */
115 int hello_time; /* 8.5.3.5: Time between sending BPDUs. */
116 int forward_delay; /* 8.5.3.6: Delay between state changes. */
117 int bridge_max_age; /* 8.5.3.8: max_age when we're root. */
118 int bridge_hello_time; /* 8.5.3.9: hello_time as root. */
119 int bridge_forward_delay; /* 8.5.3.10: forward_delay as root. */
120 int rq_max_age; /* User-requested max age, in ms. */
121 int rq_hello_time; /* User-requested hello time, in ms. */
122 int rq_forward_delay; /* User-requested forward delay, in ms. */
123 int elapsed_remainder; /* Left-over msecs from last stp_tick(). */
125 /* Dynamic bridge data. */
126 stp_identifier designated_root; /* 8.5.3.1: Bridge believed to be root. */
127 unsigned int root_path_cost; /* 8.5.3.2: Cost of path to root. */
128 struct stp_port *root_port; /* 8.5.3.3: Lowest cost port to root. */
129 bool topology_change_detected; /* 8.5.3.11: Detected a topology change? */
130 bool topology_change; /* 8.5.3.12: Received topology change? */
133 struct stp_timer hello_timer; /* 8.5.4.1: Hello timer. */
134 struct stp_timer tcn_timer; /* 8.5.4.2: Topology change timer. */
135 struct stp_timer topology_change_timer; /* 8.5.4.3. */
138 struct stp_port ports[STP_MAX_PORTS];
140 /* Interface to client. */
141 bool fdb_needs_flush; /* MAC learning tables needs flushing. */
142 struct stp_port *first_changed_port;
143 void (*send_bpdu)(struct ofpbuf *bpdu, int port_no, void *aux);
149 static struct ovs_mutex mutex;
150 static struct list all_stps__ = LIST_INITIALIZER(&all_stps__);
151 static struct list *const all_stps OVS_GUARDED_BY(mutex) = &all_stps__;
153 #define FOR_EACH_ENABLED_PORT(PORT, STP) \
154 for ((PORT) = stp_next_enabled_port((STP), (STP)->ports); \
156 (PORT) = stp_next_enabled_port((STP), (PORT) + 1))
157 static struct stp_port *
158 stp_next_enabled_port(const struct stp *stp, const struct stp_port *port)
161 for (; port < &stp->ports[ARRAY_SIZE(stp->ports)]; port++) {
162 if (port->state != STP_DISABLED) {
163 return CONST_CAST(struct stp_port *, port);
169 #define MESSAGE_AGE_INCREMENT 1
171 static void stp_transmit_config(struct stp_port *) OVS_REQUIRES(mutex);
172 static bool stp_supersedes_port_info(const struct stp_port *,
173 const struct stp_config_bpdu *)
175 static void stp_record_config_information(struct stp_port *,
176 const struct stp_config_bpdu *)
178 static void stp_record_config_timeout_values(struct stp *,
179 const struct stp_config_bpdu *)
181 static bool stp_is_designated_port(const struct stp_port *)
183 static void stp_config_bpdu_generation(struct stp *) OVS_REQUIRES(mutex);
184 static void stp_transmit_tcn(struct stp *) OVS_REQUIRES(mutex);
185 static void stp_configuration_update(struct stp *) OVS_REQUIRES(mutex);
186 static bool stp_supersedes_root(const struct stp_port *root,
187 const struct stp_port *) OVS_REQUIRES(mutex);
188 static void stp_root_selection(struct stp *) OVS_REQUIRES(mutex);
189 static void stp_designated_port_selection(struct stp *) OVS_REQUIRES(mutex);
190 static void stp_become_designated_port(struct stp_port *)
192 static void stp_port_state_selection(struct stp *) OVS_REQUIRES(mutex);
193 static void stp_make_forwarding(struct stp_port *) OVS_REQUIRES(mutex);
194 static void stp_make_blocking(struct stp_port *) OVS_REQUIRES(mutex);
195 static void stp_set_port_state(struct stp_port *, enum stp_state)
197 static void stp_topology_change_detection(struct stp *) OVS_REQUIRES(mutex);
198 static void stp_topology_change_acknowledged(struct stp *)
200 static void stp_acknowledge_topology_change(struct stp_port *)
202 static void stp_received_config_bpdu(struct stp *, struct stp_port *,
203 const struct stp_config_bpdu *)
205 static void stp_received_tcn_bpdu(struct stp *, struct stp_port *)
207 static void stp_hello_timer_expiry(struct stp *) OVS_REQUIRES(mutex);
208 static void stp_message_age_timer_expiry(struct stp_port *)
210 static bool stp_is_designated_for_some_port(const struct stp *)
212 static void stp_forward_delay_timer_expiry(struct stp_port *)
214 static void stp_tcn_timer_expiry(struct stp *) OVS_REQUIRES(mutex);
215 static void stp_topology_change_timer_expiry(struct stp *)
217 static void stp_hold_timer_expiry(struct stp_port *) OVS_REQUIRES(mutex);
218 static void stp_initialize_port(struct stp_port *, enum stp_state)
220 static void stp_become_root_bridge(struct stp *) OVS_REQUIRES(mutex);
221 static void stp_update_bridge_timers(struct stp *) OVS_REQUIRES(mutex);
223 static int clamp(int x, int min, int max);
224 static int ms_to_timer(int ms);
225 static int timer_to_ms(int timer);
226 static void stp_start_timer(struct stp_timer *, int value);
227 static void stp_stop_timer(struct stp_timer *);
228 static bool stp_timer_expired(struct stp_timer *, int elapsed, int timeout);
230 static void stp_send_bpdu(struct stp_port *, const void *, size_t)
232 static void stp_unixctl_tcn(struct unixctl_conn *, int argc,
233 const char *argv[], void *aux);
238 unixctl_command_register("stp/tcn", "[bridge]", 0, 1, stp_unixctl_tcn,
242 /* Creates and returns a new STP instance that initially has no ports enabled.
244 * 'bridge_id' should be a 48-bit MAC address as returned by
245 * eth_addr_to_uint64(). 'bridge_id' may also have a priority value in its top
246 * 16 bits; if those bits are set to 0, STP_DEFAULT_BRIDGE_PRIORITY is used.
247 * (This priority may be changed with stp_set_bridge_priority().)
249 * When the bridge needs to send out a BPDU, it calls 'send_bpdu'. This
250 * callback may be called from stp_tick() or stp_received_bpdu(). The
251 * arguments to 'send_bpdu' are an STP BPDU encapsulated in 'bpdu',
252 * the spanning tree port number 'port_no' that should transmit the
253 * packet, and auxiliary data to be passed to the callback in 'aux'.
256 stp_create(const char *name, stp_identifier bridge_id,
257 void (*send_bpdu)(struct ofpbuf *bpdu, int port_no, void *aux),
260 static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;
264 if (ovsthread_once_start(&once)) {
265 /* We need a recursive mutex because stp_send_bpdu() could loop back
266 * into the stp module through a patch port. This happens
267 * intentionally as part of the unit tests. Ideally we'd ditch
268 * the call back function, but for now this is what we have. */
269 ovs_mutex_init_recursive(&mutex);
270 ovsthread_once_done(&once);
273 ovs_mutex_lock(&mutex);
274 stp = xzalloc(sizeof *stp);
275 stp->name = xstrdup(name);
276 stp->bridge_id = bridge_id;
277 if (!(stp->bridge_id >> 48)) {
278 stp->bridge_id |= (uint64_t) STP_DEFAULT_BRIDGE_PRIORITY << 48;
281 stp->rq_max_age = STP_DEFAULT_MAX_AGE;
282 stp->rq_hello_time = STP_DEFAULT_HELLO_TIME;
283 stp->rq_forward_delay = STP_DEFAULT_FWD_DELAY;
284 stp_update_bridge_timers(stp);
285 stp->max_age = stp->bridge_max_age;
286 stp->hello_time = stp->bridge_hello_time;
287 stp->forward_delay = stp->bridge_forward_delay;
289 stp->designated_root = stp->bridge_id;
290 stp->root_path_cost = 0;
291 stp->root_port = NULL;
292 stp->topology_change_detected = false;
293 stp->topology_change = false;
295 stp_stop_timer(&stp->tcn_timer);
296 stp_stop_timer(&stp->topology_change_timer);
297 stp_start_timer(&stp->hello_timer, 0);
299 stp->send_bpdu = send_bpdu;
302 stp->first_changed_port = &stp->ports[ARRAY_SIZE(stp->ports)];
303 for (p = stp->ports; p < &stp->ports[ARRAY_SIZE(stp->ports)]; p++) {
305 p->port_id = (stp_port_no(p) + 1) | (STP_DEFAULT_PORT_PRIORITY << 8);
306 p->path_cost = 19; /* Recommended default for 100 Mb/s link. */
307 stp_initialize_port(p, STP_DISABLED);
309 atomic_init(&stp->ref_cnt, 1);
311 list_push_back(all_stps, &stp->node);
312 ovs_mutex_unlock(&mutex);
317 stp_ref(const struct stp *stp_)
319 struct stp *stp = CONST_CAST(struct stp *, stp_);
322 atomic_add(&stp->ref_cnt, 1, &orig);
323 ovs_assert(orig > 0);
328 /* Destroys 'stp'. */
330 stp_unref(struct stp *stp)
338 atomic_sub(&stp->ref_cnt, 1, &orig);
339 ovs_assert(orig > 0);
341 ovs_mutex_lock(&mutex);
342 list_remove(&stp->node);
343 ovs_mutex_unlock(&mutex);
349 /* Runs 'stp' given that 'ms' milliseconds have passed. */
351 stp_tick(struct stp *stp, int ms)
356 ovs_mutex_lock(&mutex);
357 /* Convert 'ms' to STP timer ticks. Preserve any leftover milliseconds
358 * from previous stp_tick() calls so that we don't lose STP ticks when we
359 * are called too frequently. */
360 ms = clamp(ms, 0, INT_MAX - 1000) + stp->elapsed_remainder;
361 elapsed = ms_to_timer(ms);
362 stp->elapsed_remainder = ms - timer_to_ms(elapsed);
367 if (stp_timer_expired(&stp->hello_timer, elapsed, stp->hello_time)) {
368 stp_hello_timer_expiry(stp);
370 if (stp_timer_expired(&stp->tcn_timer, elapsed, stp->bridge_hello_time)) {
371 stp_tcn_timer_expiry(stp);
373 if (stp_timer_expired(&stp->topology_change_timer, elapsed,
374 stp->max_age + stp->forward_delay)) {
375 stp_topology_change_timer_expiry(stp);
377 FOR_EACH_ENABLED_PORT (p, stp) {
378 if (stp_timer_expired(&p->message_age_timer, elapsed, stp->max_age)) {
379 stp_message_age_timer_expiry(p);
382 FOR_EACH_ENABLED_PORT (p, stp) {
383 if (stp_timer_expired(&p->forward_delay_timer, elapsed,
384 stp->forward_delay)) {
385 stp_forward_delay_timer_expiry(p);
387 if (stp_timer_expired(&p->hold_timer, elapsed, ms_to_timer(1000))) {
388 stp_hold_timer_expiry(p);
393 ovs_mutex_unlock(&mutex);
397 set_bridge_id(struct stp *stp, stp_identifier new_bridge_id)
400 if (new_bridge_id != stp->bridge_id) {
404 root = stp_is_root_bridge(stp);
405 FOR_EACH_ENABLED_PORT (p, stp) {
406 if (stp_is_designated_port(p)) {
407 p->designated_bridge = new_bridge_id;
410 stp->bridge_id = new_bridge_id;
411 stp_configuration_update(stp);
412 stp_port_state_selection(stp);
413 if (stp_is_root_bridge(stp) && !root) {
414 stp_become_root_bridge(stp);
420 stp_set_bridge_id(struct stp *stp, stp_identifier bridge_id)
422 const uint64_t mac_bits = (UINT64_C(1) << 48) - 1;
423 const uint64_t pri_bits = ~mac_bits;
424 ovs_mutex_lock(&mutex);
425 set_bridge_id(stp, (stp->bridge_id & pri_bits) | (bridge_id & mac_bits));
426 ovs_mutex_unlock(&mutex);
430 stp_set_bridge_priority(struct stp *stp, uint16_t new_priority)
432 const uint64_t mac_bits = (UINT64_C(1) << 48) - 1;
433 ovs_mutex_lock(&mutex);
434 set_bridge_id(stp, ((stp->bridge_id & mac_bits)
435 | ((uint64_t) new_priority << 48)));
436 ovs_mutex_unlock(&mutex);
439 /* Sets the desired hello time for 'stp' to 'ms', in milliseconds. The actual
440 * hello time is clamped to the range of 1 to 10 seconds and subject to the
441 * relationship (bridge_max_age >= 2 * (bridge_hello_time + 1 s)). The bridge
442 * hello time is only used when 'stp' is the root bridge. */
444 stp_set_hello_time(struct stp *stp, int ms)
446 ovs_mutex_lock(&mutex);
447 stp->rq_hello_time = ms;
448 stp_update_bridge_timers(stp);
449 ovs_mutex_unlock(&mutex);
452 /* Sets the desired max age for 'stp' to 'ms', in milliseconds. The actual max
453 * age is clamped to the range of 6 to 40 seconds and subject to the
454 * relationships (2 * (bridge_forward_delay - 1 s) >= bridge_max_age) and
455 * (bridge_max_age >= 2 * (bridge_hello_time + 1 s)). The bridge max age is
456 * only used when 'stp' is the root bridge. */
458 stp_set_max_age(struct stp *stp, int ms)
460 ovs_mutex_lock(&mutex);
461 stp->rq_max_age = ms;
462 stp_update_bridge_timers(stp);
463 ovs_mutex_unlock(&mutex);
466 /* Sets the desired forward delay for 'stp' to 'ms', in milliseconds. The
467 * actual forward delay is clamped to the range of 4 to 30 seconds and subject
468 * to the relationship (2 * (bridge_forward_delay - 1 s) >= bridge_max_age).
469 * The bridge forward delay is only used when 'stp' is the root bridge. */
471 stp_set_forward_delay(struct stp *stp, int ms)
473 ovs_mutex_lock(&mutex);
474 stp->rq_forward_delay = ms;
475 stp_update_bridge_timers(stp);
476 ovs_mutex_unlock(&mutex);
479 /* Returns the name given to 'stp' in the call to stp_create(). */
481 stp_get_name(const struct stp *stp)
485 ovs_mutex_lock(&mutex);
487 ovs_mutex_unlock(&mutex);
491 /* Returns the bridge ID for 'stp'. */
493 stp_get_bridge_id(const struct stp *stp)
495 stp_identifier bridge_id;
497 ovs_mutex_lock(&mutex);
498 bridge_id = stp->bridge_id;
499 ovs_mutex_unlock(&mutex);
503 /* Returns the bridge ID of the bridge currently believed to be the root. */
505 stp_get_designated_root(const struct stp *stp)
507 stp_identifier designated_root;
509 ovs_mutex_lock(&mutex);
510 designated_root = stp->designated_root;
511 ovs_mutex_unlock(&mutex);
512 return designated_root;
515 /* Returns true if 'stp' believes itself to the be root of the spanning tree,
516 * false otherwise. */
518 stp_is_root_bridge(const struct stp *stp)
522 ovs_mutex_lock(&mutex);
523 is_root = stp->bridge_id == stp->designated_root;
524 ovs_mutex_unlock(&mutex);
528 /* Returns the cost of the path from 'stp' to the root of the spanning tree. */
530 stp_get_root_path_cost(const struct stp *stp)
534 ovs_mutex_lock(&mutex);
535 cost = stp->root_path_cost;
536 ovs_mutex_unlock(&mutex);
540 /* Returns the bridge hello time, in ms. The returned value is not necessarily
541 * the value passed to stp_set_hello_time(): it is clamped to the valid range
542 * and quantized to the STP timer resolution. */
544 stp_get_hello_time(const struct stp *stp)
548 ovs_mutex_lock(&mutex);
549 time = timer_to_ms(stp->bridge_hello_time);
550 ovs_mutex_unlock(&mutex);
554 /* Returns the bridge max age, in ms. The returned value is not necessarily
555 * the value passed to stp_set_max_age(): it is clamped to the valid range,
556 * quantized to the STP timer resolution, and adjusted to match the constraints
557 * due to the hello time. */
559 stp_get_max_age(const struct stp *stp)
563 ovs_mutex_lock(&mutex);
564 time = timer_to_ms(stp->bridge_max_age);
565 ovs_mutex_unlock(&mutex);
569 /* Returns the bridge forward delay, in ms. The returned value is not
570 * necessarily the value passed to stp_set_forward_delay(): it is clamped to
571 * the valid range, quantized to the STP timer resolution, and adjusted to
572 * match the constraints due to the forward delay. */
574 stp_get_forward_delay(const struct stp *stp)
578 ovs_mutex_lock(&mutex);
579 time = timer_to_ms(stp->bridge_forward_delay);
580 ovs_mutex_unlock(&mutex);
584 /* Returns true if something has happened to 'stp' which necessitates flushing
585 * the client's MAC learning table. Calling this function resets 'stp' so that
586 * future calls will return false until flushing is required again. */
588 stp_check_and_reset_fdb_flush(struct stp *stp)
592 ovs_mutex_lock(&mutex);
593 needs_flush = stp->fdb_needs_flush;
594 stp->fdb_needs_flush = false;
595 ovs_mutex_unlock(&mutex);
599 /* Returns the port in 'stp' with index 'port_no', which must be between 0 and
602 stp_get_port(struct stp *stp, int port_no)
604 struct stp_port *port;
606 ovs_mutex_lock(&mutex);
607 ovs_assert(port_no >= 0 && port_no < ARRAY_SIZE(stp->ports));
608 port = &stp->ports[port_no];
609 ovs_mutex_unlock(&mutex);
613 /* Returns the port connecting 'stp' to the root bridge, or a null pointer if
614 * there is no such port. */
616 stp_get_root_port(struct stp *stp)
618 struct stp_port *port;
620 ovs_mutex_lock(&mutex);
621 port = stp->root_port;
622 ovs_mutex_unlock(&mutex);
626 /* Finds a port whose state has changed. If successful, stores the port whose
627 * state changed in '*portp' and returns true. If no port has changed, stores
628 * NULL in '*portp' and returns false. */
630 stp_get_changed_port(struct stp *stp, struct stp_port **portp)
632 struct stp_port *end, *p;
633 bool changed = false;
635 ovs_mutex_lock(&mutex);
636 end = &stp->ports[ARRAY_SIZE(stp->ports)];
637 for (p = stp->first_changed_port; p < end; p++) {
638 if (p->state_changed) {
639 p->state_changed = false;
640 stp->first_changed_port = p + 1;
646 stp->first_changed_port = end;
650 ovs_mutex_unlock(&mutex);
654 /* Returns the name for the given 'state' (for use in debugging and log
657 stp_state_name(enum stp_state state)
675 /* Returns true if 'state' is one in which packets received on a port should
676 * be forwarded, false otherwise.
678 * Returns true if 'state' is STP_DISABLED, since presumably in that case the
679 * port should still work, just not have STP applied to it. */
681 stp_forward_in_state(enum stp_state state)
683 return (state & (STP_DISABLED | STP_FORWARDING)) != 0;
686 /* Returns true if 'state' is one in which MAC learning should be done on
687 * packets received on a port, false otherwise.
689 * Returns true if 'state' is STP_DISABLED, since presumably in that case the
690 * port should still work, just not have STP applied to it. */
692 stp_learn_in_state(enum stp_state state)
694 return (state & (STP_DISABLED | STP_LEARNING | STP_FORWARDING)) != 0;
697 /* Returns true if 'state' is one in which rx&tx bpdu should be done on
698 * on a port, false otherwise. */
700 stp_listen_in_state(enum stp_state state)
703 (STP_LISTENING | STP_LEARNING | STP_FORWARDING)) != 0;
706 /* Returns the name for the given 'role' (for use in debugging and log
709 stp_role_name(enum stp_role role)
714 case STP_ROLE_DESIGNATED:
716 case STP_ROLE_ALTERNATE:
718 case STP_ROLE_DISABLED:
725 /* Notifies the STP entity that bridge protocol data unit 'bpdu', which is
726 * 'bpdu_size' bytes in length, was received on port 'p'.
728 * This function may call the 'send_bpdu' function provided to stp_create(). */
730 stp_received_bpdu(struct stp_port *p, const void *bpdu, size_t bpdu_size)
732 struct stp *stp = p->stp;
733 const struct stp_bpdu_header *header;
735 ovs_mutex_lock(&mutex);
736 if (p->state == STP_DISABLED) {
740 if (bpdu_size < sizeof(struct stp_bpdu_header)) {
741 VLOG_WARN("%s: received runt %"PRIuSIZE"-byte BPDU", stp->name, bpdu_size);
747 if (header->protocol_id != htons(STP_PROTOCOL_ID)) {
748 VLOG_WARN("%s: received BPDU with unexpected protocol ID %"PRIu16,
749 stp->name, ntohs(header->protocol_id));
753 if (header->protocol_version != STP_PROTOCOL_VERSION) {
754 VLOG_DBG("%s: received BPDU with unexpected protocol version %"PRIu8,
755 stp->name, header->protocol_version);
758 switch (header->bpdu_type) {
759 case STP_TYPE_CONFIG:
760 if (bpdu_size < sizeof(struct stp_config_bpdu)) {
761 VLOG_WARN("%s: received config BPDU with invalid size %"PRIuSIZE,
762 stp->name, bpdu_size);
766 stp_received_config_bpdu(stp, p, bpdu);
770 if (bpdu_size != sizeof(struct stp_tcn_bpdu)) {
771 VLOG_WARN("%s: received TCN BPDU with invalid size %"PRIuSIZE,
772 stp->name, bpdu_size);
776 stp_received_tcn_bpdu(stp, p);
780 VLOG_WARN("%s: received BPDU of unexpected type %"PRIu8,
781 stp->name, header->bpdu_type);
788 ovs_mutex_unlock(&mutex);
791 /* Returns the STP entity in which 'p' is nested. */
793 stp_port_get_stp(struct stp_port *p)
797 ovs_mutex_lock(&mutex);
799 ovs_mutex_unlock(&mutex);
803 /* Sets the 'aux' member of 'p'.
805 * The 'aux' member will be reset to NULL when stp_port_disable() is
806 * called or stp_port_enable() is called when the port is in a Disabled
809 stp_port_set_aux(struct stp_port *p, void *aux)
811 ovs_mutex_lock(&mutex);
813 ovs_mutex_unlock(&mutex);
816 /* Returns the 'aux' member of 'p'. */
818 stp_port_get_aux(struct stp_port *p)
822 ovs_mutex_lock(&mutex);
824 ovs_mutex_unlock(&mutex);
828 /* Returns the index of port 'p' within its bridge. */
830 stp_port_no(const struct stp_port *p)
835 ovs_mutex_lock(&mutex);
837 ovs_assert(p >= stp->ports && p < &stp->ports[ARRAY_SIZE(stp->ports)]);
838 index = p - p->stp->ports;
839 ovs_mutex_unlock(&mutex);
843 /* Returns the port ID for 'p'. */
845 stp_port_get_id(const struct stp_port *p)
849 ovs_mutex_lock(&mutex);
850 port_id = p->port_id;
851 ovs_mutex_unlock(&mutex);
855 /* Returns the state of port 'p'. */
857 stp_port_get_state(const struct stp_port *p)
859 enum stp_state state;
861 ovs_mutex_lock(&mutex);
863 ovs_mutex_unlock(&mutex);
867 /* Returns the role of port 'p'. */
869 stp_port_get_role(const struct stp_port *p)
871 struct stp_port *root_port;
874 ovs_mutex_lock(&mutex);
875 root_port = p->stp->root_port;
876 if (root_port && root_port->port_id == p->port_id) {
877 role = STP_ROLE_ROOT;
878 } else if (stp_is_designated_port(p)) {
879 role = STP_ROLE_DESIGNATED;
880 } else if (p->state == STP_DISABLED) {
881 role = STP_ROLE_DISABLED;
883 role = STP_ROLE_ALTERNATE;
885 ovs_mutex_unlock(&mutex);
889 /* Retrieves BPDU transmit and receive counts for 'p'. */
891 stp_port_get_counts(const struct stp_port *p,
892 int *tx_count, int *rx_count, int *error_count)
894 ovs_mutex_lock(&mutex);
895 *tx_count = p->tx_count;
896 *rx_count = p->rx_count;
897 *error_count = p->error_count;
898 ovs_mutex_unlock(&mutex);
901 /* Disables STP on port 'p'. */
903 stp_port_disable(struct stp_port *p)
907 ovs_mutex_lock(&mutex);
909 if (p->state != STP_DISABLED) {
910 bool root = stp_is_root_bridge(stp);
911 stp_become_designated_port(p);
912 stp_set_port_state(p, STP_DISABLED);
913 p->topology_change_ack = false;
914 p->config_pending = false;
915 stp_stop_timer(&p->message_age_timer);
916 stp_stop_timer(&p->forward_delay_timer);
917 stp_configuration_update(stp);
918 stp_port_state_selection(stp);
919 if (stp_is_root_bridge(stp) && !root) {
920 stp_become_root_bridge(stp);
924 ovs_mutex_unlock(&mutex);
927 /* Enables STP on port 'p'. The port will initially be in "blocking" state. */
929 stp_port_enable(struct stp_port *p)
931 ovs_mutex_lock(&mutex);
932 if (p->state == STP_DISABLED) {
933 stp_initialize_port(p, STP_BLOCKING);
934 stp_port_state_selection(p->stp);
936 ovs_mutex_unlock(&mutex);
939 /* Sets the priority of port 'p' to 'new_priority'. Lower numerical values
940 * are interpreted as higher priorities. */
942 stp_port_set_priority(struct stp_port *p, uint8_t new_priority)
944 uint16_t new_port_id;
946 ovs_mutex_lock(&mutex);
947 new_port_id = (p->port_id & 0xff) | (new_priority << 8);
948 if (p->port_id != new_port_id) {
949 struct stp *stp = p->stp;
950 if (stp_is_designated_port(p)) {
951 p->designated_port = new_port_id;
953 p->port_id = new_port_id;
954 if (stp->bridge_id == p->designated_bridge
955 && p->port_id < p->designated_port) {
956 stp_become_designated_port(p);
957 stp_port_state_selection(stp);
960 ovs_mutex_unlock(&mutex);
963 /* Convert 'speed' (measured in Mb/s) into the path cost. */
965 stp_convert_speed_to_cost(unsigned int speed)
969 ovs_mutex_lock(&mutex);
970 ret = speed >= 10000 ? 2 /* 10 Gb/s. */
971 : speed >= 1000 ? 4 /* 1 Gb/s. */
972 : speed >= 100 ? 19 /* 100 Mb/s. */
973 : speed >= 16 ? 62 /* 16 Mb/s. */
974 : speed >= 10 ? 100 /* 10 Mb/s. */
975 : speed >= 4 ? 250 /* 4 Mb/s. */
976 : 19; /* 100 Mb/s (guess). */
977 ovs_mutex_unlock(&mutex);
981 /* Sets the path cost of port 'p' to 'path_cost'. Lower values are generally
982 * used to indicate faster links. Use stp_port_set_speed() to automatically
983 * generate a default path cost from a link speed. */
985 stp_port_set_path_cost(struct stp_port *p, uint16_t path_cost)
987 ovs_mutex_lock(&mutex);
988 if (p->path_cost != path_cost) {
989 struct stp *stp = p->stp;
990 p->path_cost = path_cost;
991 stp_configuration_update(stp);
992 stp_port_state_selection(stp);
994 ovs_mutex_unlock(&mutex);
997 /* Sets the path cost of port 'p' based on 'speed' (measured in Mb/s). */
999 stp_port_set_speed(struct stp_port *p, unsigned int speed)
1001 stp_port_set_path_cost(p, stp_convert_speed_to_cost(speed));
1004 /* Enables topology change detection on port 'p'. */
1006 stp_port_enable_change_detection(struct stp_port *p)
1008 p->change_detection_enabled = true;
1011 /* Disables topology change detection on port 'p'. */
1013 stp_port_disable_change_detection(struct stp_port *p)
1015 p->change_detection_enabled = false;
1019 stp_transmit_config(struct stp_port *p) OVS_REQUIRES(mutex)
1021 struct stp *stp = p->stp;
1022 bool root = stp_is_root_bridge(stp);
1023 if (!root && !stp->root_port) {
1026 if (p->hold_timer.active) {
1027 p->config_pending = true;
1029 struct stp_config_bpdu config;
1030 memset(&config, 0, sizeof config);
1031 config.header.protocol_id = htons(STP_PROTOCOL_ID);
1032 config.header.protocol_version = STP_PROTOCOL_VERSION;
1033 config.header.bpdu_type = STP_TYPE_CONFIG;
1035 if (p->topology_change_ack) {
1036 config.flags |= STP_CONFIG_TOPOLOGY_CHANGE_ACK;
1038 if (stp->topology_change) {
1039 config.flags |= STP_CONFIG_TOPOLOGY_CHANGE;
1041 config.root_id = htonll(stp->designated_root);
1042 config.root_path_cost = htonl(stp->root_path_cost);
1043 config.bridge_id = htonll(stp->bridge_id);
1044 config.port_id = htons(p->port_id);
1046 config.message_age = htons(0);
1048 config.message_age = htons(stp->root_port->message_age_timer.value
1049 + MESSAGE_AGE_INCREMENT);
1051 config.max_age = htons(stp->max_age);
1052 config.hello_time = htons(stp->hello_time);
1053 config.forward_delay = htons(stp->forward_delay);
1054 if (ntohs(config.message_age) < stp->max_age) {
1055 p->topology_change_ack = false;
1056 p->config_pending = false;
1057 stp_send_bpdu(p, &config, sizeof config);
1058 stp_start_timer(&p->hold_timer, 0);
1064 stp_supersedes_port_info(const struct stp_port *p,
1065 const struct stp_config_bpdu *config)
1068 if (ntohll(config->root_id) != p->designated_root) {
1069 return ntohll(config->root_id) < p->designated_root;
1070 } else if (ntohl(config->root_path_cost) != p->designated_cost) {
1071 return ntohl(config->root_path_cost) < p->designated_cost;
1072 } else if (ntohll(config->bridge_id) != p->designated_bridge) {
1073 return ntohll(config->bridge_id) < p->designated_bridge;
1075 return (ntohll(config->bridge_id) != p->stp->bridge_id
1076 || ntohs(config->port_id) <= p->designated_port);
1081 stp_record_config_information(struct stp_port *p,
1082 const struct stp_config_bpdu *config)
1085 p->designated_root = ntohll(config->root_id);
1086 p->designated_cost = ntohl(config->root_path_cost);
1087 p->designated_bridge = ntohll(config->bridge_id);
1088 p->designated_port = ntohs(config->port_id);
1089 stp_start_timer(&p->message_age_timer, ntohs(config->message_age));
1093 stp_record_config_timeout_values(struct stp *stp,
1094 const struct stp_config_bpdu *config)
1097 stp->max_age = ntohs(config->max_age);
1098 stp->hello_time = ntohs(config->hello_time);
1099 stp->forward_delay = ntohs(config->forward_delay);
1100 stp->topology_change = config->flags & STP_CONFIG_TOPOLOGY_CHANGE;
1104 stp_is_designated_port(const struct stp_port *p) OVS_REQUIRES(mutex)
1106 return (p->designated_bridge == p->stp->bridge_id
1107 && p->designated_port == p->port_id);
1111 stp_config_bpdu_generation(struct stp *stp) OVS_REQUIRES(mutex)
1115 FOR_EACH_ENABLED_PORT (p, stp) {
1116 if (stp_is_designated_port(p)) {
1117 stp_transmit_config(p);
1123 stp_transmit_tcn(struct stp *stp) OVS_REQUIRES(mutex)
1125 struct stp_port *p = stp->root_port;
1126 struct stp_tcn_bpdu tcn_bpdu;
1130 tcn_bpdu.header.protocol_id = htons(STP_PROTOCOL_ID);
1131 tcn_bpdu.header.protocol_version = STP_PROTOCOL_VERSION;
1132 tcn_bpdu.header.bpdu_type = STP_TYPE_TCN;
1133 stp_send_bpdu(p, &tcn_bpdu, sizeof tcn_bpdu);
1137 stp_configuration_update(struct stp *stp) OVS_REQUIRES(mutex)
1139 stp_root_selection(stp);
1140 stp_designated_port_selection(stp);
1141 seq_change(connectivity_seq_get());
1145 stp_supersedes_root(const struct stp_port *root, const struct stp_port *p)
1148 int p_cost = p->designated_cost + p->path_cost;
1149 int root_cost = root->designated_cost + root->path_cost;
1151 if (p->designated_root != root->designated_root) {
1152 return p->designated_root < root->designated_root;
1153 } else if (p_cost != root_cost) {
1154 return p_cost < root_cost;
1155 } else if (p->designated_bridge != root->designated_bridge) {
1156 return p->designated_bridge < root->designated_bridge;
1157 } else if (p->designated_port != root->designated_port) {
1158 return p->designated_port < root->designated_port;
1160 return p->port_id < root->port_id;
1165 stp_root_selection(struct stp *stp) OVS_REQUIRES(mutex)
1167 struct stp_port *p, *root;
1170 FOR_EACH_ENABLED_PORT (p, stp) {
1171 if (stp_is_designated_port(p)
1172 || p->designated_root >= stp->bridge_id) {
1175 if (root && !stp_supersedes_root(root, p)) {
1180 stp->root_port = root;
1182 stp->designated_root = stp->bridge_id;
1183 stp->root_path_cost = 0;
1185 stp->designated_root = root->designated_root;
1186 stp->root_path_cost = root->designated_cost + root->path_cost;
1191 stp_designated_port_selection(struct stp *stp) OVS_REQUIRES(mutex)
1195 FOR_EACH_ENABLED_PORT (p, stp) {
1196 if (stp_is_designated_port(p)
1197 || p->designated_root != stp->designated_root
1198 || stp->root_path_cost < p->designated_cost
1199 || (stp->root_path_cost == p->designated_cost
1200 && (stp->bridge_id < p->designated_bridge
1201 || (stp->bridge_id == p->designated_bridge
1202 && p->port_id <= p->designated_port))))
1204 stp_become_designated_port(p);
1210 stp_become_designated_port(struct stp_port *p) OVS_REQUIRES(mutex)
1212 struct stp *stp = p->stp;
1213 p->designated_root = stp->designated_root;
1214 p->designated_cost = stp->root_path_cost;
1215 p->designated_bridge = stp->bridge_id;
1216 p->designated_port = p->port_id;
1220 stp_port_state_selection(struct stp *stp) OVS_REQUIRES(mutex)
1224 FOR_EACH_ENABLED_PORT (p, stp) {
1225 if (p == stp->root_port) {
1226 p->config_pending = false;
1227 p->topology_change_ack = false;
1228 stp_make_forwarding(p);
1229 } else if (stp_is_designated_port(p)) {
1230 stp_stop_timer(&p->message_age_timer);
1231 stp_make_forwarding(p);
1233 p->config_pending = false;
1234 p->topology_change_ack = false;
1235 stp_make_blocking(p);
1241 stp_make_forwarding(struct stp_port *p) OVS_REQUIRES(mutex)
1243 if (p->state == STP_BLOCKING) {
1244 stp_set_port_state(p, STP_LISTENING);
1245 stp_start_timer(&p->forward_delay_timer, 0);
1250 stp_make_blocking(struct stp_port *p) OVS_REQUIRES(mutex)
1252 if (!(p->state & (STP_DISABLED | STP_BLOCKING))) {
1253 if (p->state & (STP_FORWARDING | STP_LEARNING)) {
1254 if (p->change_detection_enabled) {
1255 stp_topology_change_detection(p->stp);
1258 stp_set_port_state(p, STP_BLOCKING);
1259 stp_stop_timer(&p->forward_delay_timer);
1264 stp_set_port_state(struct stp_port *p, enum stp_state state)
1267 if (state != p->state && !p->state_changed) {
1268 p->state_changed = true;
1269 if (p < p->stp->first_changed_port) {
1270 p->stp->first_changed_port = p;
1272 seq_change(connectivity_seq_get());
1278 stp_topology_change_detection(struct stp *stp) OVS_REQUIRES(mutex)
1280 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
1282 if (stp_is_root_bridge(stp)) {
1283 stp->topology_change = true;
1284 stp_start_timer(&stp->topology_change_timer, 0);
1285 } else if (!stp->topology_change_detected) {
1286 stp_transmit_tcn(stp);
1287 stp_start_timer(&stp->tcn_timer, 0);
1289 stp->fdb_needs_flush = true;
1290 stp->topology_change_detected = true;
1291 seq_change(connectivity_seq_get());
1292 VLOG_INFO_RL(&rl, "%s: detected topology change.", stp->name);
1296 stp_topology_change_acknowledged(struct stp *stp) OVS_REQUIRES(mutex)
1298 stp->topology_change_detected = false;
1299 stp_stop_timer(&stp->tcn_timer);
1303 stp_acknowledge_topology_change(struct stp_port *p) OVS_REQUIRES(mutex)
1305 p->topology_change_ack = true;
1306 stp_transmit_config(p);
1310 stp_received_config_bpdu(struct stp *stp, struct stp_port *p,
1311 const struct stp_config_bpdu *config)
1314 if (ntohs(config->message_age) >= ntohs(config->max_age)) {
1315 VLOG_WARN("%s: received config BPDU with message age (%u) greater "
1316 "than max age (%u)",
1318 ntohs(config->message_age), ntohs(config->max_age));
1321 if (p->state != STP_DISABLED) {
1322 bool root = stp_is_root_bridge(stp);
1323 if (stp_supersedes_port_info(p, config)) {
1324 stp_record_config_information(p, config);
1325 stp_configuration_update(stp);
1326 stp_port_state_selection(stp);
1327 if (!stp_is_root_bridge(stp) && root) {
1328 stp_stop_timer(&stp->hello_timer);
1329 if (stp->topology_change_detected) {
1330 stp_stop_timer(&stp->topology_change_timer);
1331 stp_transmit_tcn(stp);
1332 stp_start_timer(&stp->tcn_timer, 0);
1335 if (p == stp->root_port) {
1336 stp_record_config_timeout_values(stp, config);
1337 stp_config_bpdu_generation(stp);
1338 if (config->flags & STP_CONFIG_TOPOLOGY_CHANGE_ACK) {
1339 stp_topology_change_acknowledged(stp);
1341 if (config->flags & STP_CONFIG_TOPOLOGY_CHANGE) {
1342 stp->fdb_needs_flush = true;
1345 } else if (stp_is_designated_port(p)) {
1346 stp_transmit_config(p);
1352 stp_received_tcn_bpdu(struct stp *stp, struct stp_port *p)
1355 if (p->state != STP_DISABLED) {
1356 if (stp_is_designated_port(p)) {
1357 stp_topology_change_detection(stp);
1358 stp_acknowledge_topology_change(p);
1364 stp_hello_timer_expiry(struct stp *stp) OVS_REQUIRES(mutex)
1366 stp_config_bpdu_generation(stp);
1367 stp_start_timer(&stp->hello_timer, 0);
1371 stp_message_age_timer_expiry(struct stp_port *p) OVS_REQUIRES(mutex)
1373 struct stp *stp = p->stp;
1374 bool root = stp_is_root_bridge(stp);
1375 stp_become_designated_port(p);
1376 stp_configuration_update(stp);
1377 stp_port_state_selection(stp);
1378 if (stp_is_root_bridge(stp) && !root) {
1379 stp->max_age = stp->bridge_max_age;
1380 stp->hello_time = stp->bridge_hello_time;
1381 stp->forward_delay = stp->bridge_forward_delay;
1382 stp_topology_change_detection(stp);
1383 stp_stop_timer(&stp->tcn_timer);
1384 stp_config_bpdu_generation(stp);
1385 stp_start_timer(&stp->hello_timer, 0);
1390 stp_is_designated_for_some_port(const struct stp *stp) OVS_REQUIRES(mutex)
1392 const struct stp_port *p;
1394 FOR_EACH_ENABLED_PORT (p, stp) {
1395 if (p->designated_bridge == stp->bridge_id) {
1403 stp_forward_delay_timer_expiry(struct stp_port *p) OVS_REQUIRES(mutex)
1405 if (p->state == STP_LISTENING) {
1406 stp_set_port_state(p, STP_LEARNING);
1407 stp_start_timer(&p->forward_delay_timer, 0);
1408 } else if (p->state == STP_LEARNING) {
1409 stp_set_port_state(p, STP_FORWARDING);
1410 if (stp_is_designated_for_some_port(p->stp)) {
1411 if (p->change_detection_enabled) {
1412 stp_topology_change_detection(p->stp);
1419 stp_tcn_timer_expiry(struct stp *stp) OVS_REQUIRES(mutex)
1421 stp_transmit_tcn(stp);
1422 stp_start_timer(&stp->tcn_timer, 0);
1426 stp_topology_change_timer_expiry(struct stp *stp) OVS_REQUIRES(mutex)
1428 stp->topology_change_detected = false;
1429 stp->topology_change = false;
1433 stp_hold_timer_expiry(struct stp_port *p) OVS_REQUIRES(mutex)
1435 if (p->config_pending) {
1436 stp_transmit_config(p);
1441 stp_initialize_port(struct stp_port *p, enum stp_state state)
1444 ovs_assert(state & (STP_DISABLED | STP_BLOCKING));
1445 stp_become_designated_port(p);
1446 stp_set_port_state(p, state);
1447 p->topology_change_ack = false;
1448 p->config_pending = false;
1449 p->change_detection_enabled = true;
1451 stp_stop_timer(&p->message_age_timer);
1452 stp_stop_timer(&p->forward_delay_timer);
1453 stp_stop_timer(&p->hold_timer);
1454 p->tx_count = p->rx_count = p->error_count = 0;
1458 stp_become_root_bridge(struct stp *stp) OVS_REQUIRES(mutex)
1460 stp->max_age = stp->bridge_max_age;
1461 stp->hello_time = stp->bridge_hello_time;
1462 stp->forward_delay = stp->bridge_forward_delay;
1463 stp_topology_change_detection(stp);
1464 stp_stop_timer(&stp->tcn_timer);
1465 stp_config_bpdu_generation(stp);
1466 stp_start_timer(&stp->hello_timer, 0);
1470 stp_start_timer(struct stp_timer *timer, int value) OVS_REQUIRES(mutex)
1472 timer->value = value;
1473 timer->active = true;
1477 stp_stop_timer(struct stp_timer *timer) OVS_REQUIRES(mutex)
1479 timer->active = false;
1483 stp_timer_expired(struct stp_timer *timer, int elapsed, int timeout)
1486 if (timer->active) {
1487 timer->value += elapsed;
1488 if (timer->value >= timeout) {
1489 timer->active = false;
1496 /* Returns the number of whole STP timer ticks in 'ms' milliseconds. There
1497 * are 256 STP timer ticks per second. */
1501 return ms * 0x100 / 1000;
1504 /* Returns the number of whole milliseconds in 'timer' STP timer ticks. There
1505 * are 256 STP timer ticks per second. */
1507 timer_to_ms(int timer)
1509 return timer * 1000 / 0x100;
1513 clamp(int x, int min, int max)
1515 return x < min ? min : x > max ? max : x;
1519 stp_update_bridge_timers(struct stp *stp) OVS_REQUIRES(mutex)
1523 ht = clamp(stp->rq_hello_time, 1000, 10000);
1524 ma = clamp(stp->rq_max_age, MAX(2 * (ht + 1000), 6000), 40000);
1525 fd = clamp(stp->rq_forward_delay, ma / 2 + 1000, 30000);
1527 stp->bridge_hello_time = ms_to_timer(ht);
1528 stp->bridge_max_age = ms_to_timer(ma);
1529 stp->bridge_forward_delay = ms_to_timer(fd);
1531 if (stp_is_root_bridge(stp)) {
1532 stp->max_age = stp->bridge_max_age;
1533 stp->hello_time = stp->bridge_hello_time;
1534 stp->forward_delay = stp->bridge_forward_delay;
1539 stp_send_bpdu(struct stp_port *p, const void *bpdu, size_t bpdu_size)
1542 struct eth_header *eth;
1543 struct llc_header *llc;
1547 pkt = ofpbuf_new(ETH_HEADER_LEN + LLC_HEADER_LEN + bpdu_size);
1548 pkt->l2 = eth = ofpbuf_put_zeros(pkt, sizeof *eth);
1549 llc = ofpbuf_put_zeros(pkt, sizeof *llc);
1550 pkt->l3 = ofpbuf_put(pkt, bpdu, bpdu_size);
1553 memcpy(eth->eth_dst, eth_addr_stp, ETH_ADDR_LEN);
1554 /* p->stp->send_bpdu() must fill in source address. */
1555 eth->eth_type = htons(pkt->size - ETH_HEADER_LEN);
1558 llc->llc_dsap = STP_LLC_DSAP;
1559 llc->llc_ssap = STP_LLC_SSAP;
1560 llc->llc_cntl = STP_LLC_CNTL;
1562 p->stp->send_bpdu(pkt, stp_port_no(p), p->stp->aux);
1569 stp_find(const char *name) OVS_REQUIRES(mutex)
1573 LIST_FOR_EACH (stp, node, all_stps) {
1574 if (!strcmp(stp->name, name)) {
1582 stp_unixctl_tcn(struct unixctl_conn *conn, int argc,
1583 const char *argv[], void *aux OVS_UNUSED)
1585 ovs_mutex_lock(&mutex);
1587 struct stp *stp = stp_find(argv[1]);
1590 unixctl_command_reply_error(conn, "no such stp object");
1593 stp_topology_change_detection(stp);
1597 LIST_FOR_EACH (stp, node, all_stps) {
1598 stp_topology_change_detection(stp);
1602 unixctl_command_reply(conn, "OK");
1605 ovs_mutex_unlock(&mutex);