]> git.proxmox.com Git - mirror_ovs.git/blame - lib/stp.h
cirrus: Use FreeBSD 12.2.
[mirror_ovs.git] / lib / stp.h
CommitLineData
829a7d02 1/*
e0edde6f 2 * Copyright (c) 2008, 2011 Nicira, Inc.
829a7d02
JP
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#ifndef STP_H
18#define STP_H 1
19
20/* This is an implementation of Spanning Tree Protocol as described in IEEE
21 * 802.1D-1998, clauses 8 and 9. Section numbers refer to this standard. */
22
23#include <stdbool.h>
24#include <stdint.h>
25#include "compiler.h"
26#include "util.h"
27
cf62fa4c 28struct dp_packet;
829a7d02 29
829a7d02
JP
30/* Bridge and port priorities that should be used by default. */
31#define STP_DEFAULT_BRIDGE_PRIORITY 32768
32#define STP_DEFAULT_PORT_PRIORITY 128
33
3310b570
JP
34/* Default time values. */
35#define STP_DEFAULT_MAX_AGE 20000
36#define STP_DEFAULT_HELLO_TIME 2000
37#define STP_DEFAULT_FWD_DELAY 15000
38
829a7d02
JP
39/* Bridge identifier. Top 16 bits are a priority value (numerically lower
40 * values are higher priorities). Bottom 48 bits are MAC address of bridge. */
41typedef uint64_t stp_identifier;
42
3310b570
JP
43
44#define STP_ID_FMT "%04"PRIx16".%012"PRIx64
45#define STP_ID_ARGS(stp_id) \
46 (uint16_t)((stp_id) >> 48), \
47 (uint64_t)((stp_id) & 0xffffffffffffULL)
48
49#define STP_PORT_ID_FMT "%04"PRIx16
50
829a7d02
JP
51/* Basic STP functionality. */
52#define STP_MAX_PORTS 255
fe4a02e4 53void stp_init(void);
829a7d02 54struct stp *stp_create(const char *name, stp_identifier bridge_id,
cf62fa4c 55 void (*send_bpdu)(struct dp_packet *bpdu, int port_no,
829a7d02
JP
56 void *aux),
57 void *aux);
bd54dbcd
EJ
58struct stp *stp_ref(const struct stp *);
59void stp_unref(struct stp *);
829a7d02
JP
60void stp_tick(struct stp *, int ms);
61void stp_set_bridge_id(struct stp *, stp_identifier bridge_id);
62void stp_set_bridge_priority(struct stp *, uint16_t new_priority);
63void stp_set_hello_time(struct stp *, int ms);
64void stp_set_max_age(struct stp *, int ms);
65void stp_set_forward_delay(struct stp *, int ms);
66
67/* STP properties. */
68const char *stp_get_name(const struct stp *);
69stp_identifier stp_get_bridge_id(const struct stp *);
70stp_identifier stp_get_designated_root(const struct stp *);
71bool stp_is_root_bridge(const struct stp *);
72int stp_get_root_path_cost(const struct stp *);
73int stp_get_hello_time(const struct stp *);
74int stp_get_max_age(const struct stp *);
75int stp_get_forward_delay(const struct stp *);
6ae50723 76bool stp_check_and_reset_fdb_flush(struct stp *);
829a7d02
JP
77
78/* Obtaining STP ports. */
79struct stp_port *stp_get_port(struct stp *, int port_no);
80struct stp_port *stp_get_root_port(struct stp *);
81bool stp_get_changed_port(struct stp *, struct stp_port **portp);
82
83/* State of an STP port.
84 *
85 * A port is in exactly one state at any given time, but distinct bits are used
3310b570
JP
86 * for states to allow testing for more than one state with a bit mask.
87 *
88 * The STP_DISABLED state means that the port is disabled by management.
89 * In our implementation, this state means that the port does not
90 * participate in the spanning tree, but it still forwards traffic as if
91 * it were in the STP_FORWARDING state. This may be different from
92 * other implementations.
93 *
94 * The following diagram describes the various states and what they are
95 * allowed to do in OVS:
96 *
bacdb85a
AW
97 * FWD LRN TX_BPDU RX_BPDU FWD_BPDU
98 * --- --- ------- ------- --------
99 * Disabled Y - - - Y
100 * Blocking - - - Y -
101 * Listening - - Y Y Y
102 * Learning - Y Y Y Y
103 * Forwarding Y Y Y Y Y
104 *
105 *
106 * FWD: the port should forward any incoming non-stp-BPDU
107 * packets.
108 *
109 * LRN: the port should conduct MAC learning on packets received.
110 *
111 * TX_BPDU/RX_BPDU: the port could generate/consume bpdus.
112 *
113 * FWD_BPDU: the port should should always forward the BPDUS,
114 * whether they are generated by the port or received
115 * as incoming packets.
3310b570
JP
116 *
117 * Once again, note that the disabled state forwards traffic, which is
118 * likely different than the spec would indicate.
119 */
829a7d02 120enum stp_state {
3310b570 121 STP_DISABLED = 1 << 0, /* 8.4.5: See note above. */
829a7d02
JP
122 STP_LISTENING = 1 << 1, /* 8.4.2: Not learning or relaying frames. */
123 STP_LEARNING = 1 << 2, /* 8.4.3: Learning but not relaying frames. */
124 STP_FORWARDING = 1 << 3, /* 8.4.4: Learning and relaying frames. */
125 STP_BLOCKING = 1 << 4 /* 8.4.1: Initial boot state. */
126};
127const char *stp_state_name(enum stp_state);
128bool stp_forward_in_state(enum stp_state);
129bool stp_learn_in_state(enum stp_state);
bacdb85a 130bool stp_should_forward_bpdu(enum stp_state);
829a7d02 131
3310b570
JP
132/* Role of an STP port. */
133enum stp_role {
134 STP_ROLE_ROOT, /* Path to root bridge. */
135 STP_ROLE_DESIGNATED, /* Path to LAN segments. */
136 STP_ROLE_ALTERNATE, /* Backup path to root bridge. */
137 STP_ROLE_DISABLED /* Port does not participate in STP. */
138};
139const char *stp_role_name(enum stp_role);
140
829a7d02
JP
141void stp_received_bpdu(struct stp_port *, const void *bpdu, size_t bpdu_size);
142
143struct stp *stp_port_get_stp(struct stp_port *);
11306274 144void stp_port_set_name(struct stp_port *, const char *);
3310b570
JP
145void stp_port_set_aux(struct stp_port *, void *);
146void *stp_port_get_aux(struct stp_port *);
829a7d02
JP
147int stp_port_no(const struct stp_port *);
148enum stp_state stp_port_get_state(const struct stp_port *);
80740385
JP
149void stp_port_get_counts(const struct stp_port *,
150 int *tx_count, int *rx_count, int *error_count);
926c9a4a 151void stp_port_get_status(const struct stp_port *p,
152 int *port_id, enum stp_state *state, enum stp_role *role);
829a7d02
JP
153void stp_port_enable(struct stp_port *);
154void stp_port_disable(struct stp_port *);
155void stp_port_set_priority(struct stp_port *, uint8_t new_priority);
3310b570 156uint16_t stp_convert_speed_to_cost(unsigned int speed);
829a7d02
JP
157void stp_port_set_path_cost(struct stp_port *, uint16_t path_cost);
158void stp_port_set_speed(struct stp_port *, unsigned int speed);
159void stp_port_enable_change_detection(struct stp_port *);
160void stp_port_disable_change_detection(struct stp_port *);
161
162#endif /* stp.h */