]>
git.proxmox.com Git - ovs.git/blob - lib/stp.h
2 * Copyright (c) 2008, 2011 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.
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. */
30 /* LLC field values used for STP frames. */
31 #define STP_LLC_SSAP 0x42
32 #define STP_LLC_DSAP 0x42
33 #define STP_LLC_CNTL 0x03
35 /* Bridge and port priorities that should be used by default. */
36 #define STP_DEFAULT_BRIDGE_PRIORITY 32768
37 #define STP_DEFAULT_PORT_PRIORITY 128
39 /* Default time values. */
40 #define STP_DEFAULT_MAX_AGE 20000
41 #define STP_DEFAULT_HELLO_TIME 2000
42 #define STP_DEFAULT_FWD_DELAY 15000
44 /* Bridge identifier. Top 16 bits are a priority value (numerically lower
45 * values are higher priorities). Bottom 48 bits are MAC address of bridge. */
46 typedef uint64_t stp_identifier
;
49 #define STP_ID_FMT "%04"PRIx16".%012"PRIx64
50 #define STP_ID_ARGS(stp_id) \
51 (uint16_t)((stp_id) >> 48), \
52 (uint64_t)((stp_id) & 0xffffffffffffULL)
54 #define STP_PORT_ID_FMT "%04"PRIx16
56 /* Basic STP functionality. */
57 #define STP_MAX_PORTS 255
59 struct stp
*stp_create(const char *name
, stp_identifier bridge_id
,
60 void (*send_bpdu
)(struct ofpbuf
*bpdu
, int port_no
,
63 struct stp
*stp_ref(const struct stp
*);
64 void stp_unref(struct stp
*);
65 void stp_tick(struct stp
*, int ms
);
66 void stp_set_bridge_id(struct stp
*, stp_identifier bridge_id
);
67 void stp_set_bridge_priority(struct stp
*, uint16_t new_priority
);
68 void stp_set_hello_time(struct stp
*, int ms
);
69 void stp_set_max_age(struct stp
*, int ms
);
70 void stp_set_forward_delay(struct stp
*, int ms
);
73 const char *stp_get_name(const struct stp
*);
74 stp_identifier
stp_get_bridge_id(const struct stp
*);
75 stp_identifier
stp_get_designated_root(const struct stp
*);
76 bool stp_is_root_bridge(const struct stp
*);
77 int stp_get_root_path_cost(const struct stp
*);
78 int stp_get_hello_time(const struct stp
*);
79 int stp_get_max_age(const struct stp
*);
80 int stp_get_forward_delay(const struct stp
*);
81 bool stp_check_and_reset_fdb_flush(struct stp
*);
83 /* Obtaining STP ports. */
84 struct stp_port
*stp_get_port(struct stp
*, int port_no
);
85 struct stp_port
*stp_get_root_port(struct stp
*);
86 bool stp_get_changed_port(struct stp
*, struct stp_port
**portp
);
88 /* State of an STP port.
90 * A port is in exactly one state at any given time, but distinct bits are used
91 * for states to allow testing for more than one state with a bit mask.
93 * The STP_DISABLED state means that the port is disabled by management.
94 * In our implementation, this state means that the port does not
95 * participate in the spanning tree, but it still forwards traffic as if
96 * it were in the STP_FORWARDING state. This may be different from
97 * other implementations.
99 * The following diagram describes the various states and what they are
100 * allowed to do in OVS:
102 * FWD LRN TX_BPDU RX_BPDU
103 * --- --- ------- -------
110 * Once again, note that the disabled state forwards traffic, which is
111 * likely different than the spec would indicate.
114 STP_DISABLED
= 1 << 0, /* 8.4.5: See note above. */
115 STP_LISTENING
= 1 << 1, /* 8.4.2: Not learning or relaying frames. */
116 STP_LEARNING
= 1 << 2, /* 8.4.3: Learning but not relaying frames. */
117 STP_FORWARDING
= 1 << 3, /* 8.4.4: Learning and relaying frames. */
118 STP_BLOCKING
= 1 << 4 /* 8.4.1: Initial boot state. */
120 const char *stp_state_name(enum stp_state
);
121 bool stp_forward_in_state(enum stp_state
);
122 bool stp_learn_in_state(enum stp_state
);
124 /* Role of an STP port. */
126 STP_ROLE_ROOT
, /* Path to root bridge. */
127 STP_ROLE_DESIGNATED
, /* Path to LAN segments. */
128 STP_ROLE_ALTERNATE
, /* Backup path to root bridge. */
129 STP_ROLE_DISABLED
/* Port does not participate in STP. */
131 const char *stp_role_name(enum stp_role
);
133 void stp_received_bpdu(struct stp_port
*, const void *bpdu
, size_t bpdu_size
);
135 struct stp
*stp_port_get_stp(struct stp_port
*);
136 void stp_port_set_aux(struct stp_port
*, void *);
137 void *stp_port_get_aux(struct stp_port
*);
138 int stp_port_no(const struct stp_port
*);
139 int stp_port_get_id(const struct stp_port
*);
140 enum stp_state
stp_port_get_state(const struct stp_port
*);
141 enum stp_role
stp_port_get_role(const struct stp_port
*);
142 void stp_port_get_counts(const struct stp_port
*,
143 int *tx_count
, int *rx_count
, int *error_count
);
144 void stp_port_enable(struct stp_port
*);
145 void stp_port_disable(struct stp_port
*);
146 void stp_port_set_priority(struct stp_port
*, uint8_t new_priority
);
147 uint16_t stp_convert_speed_to_cost(unsigned int speed
);
148 void stp_port_set_path_cost(struct stp_port
*, uint16_t path_cost
);
149 void stp_port_set_speed(struct stp_port
*, unsigned int speed
);
150 void stp_port_enable_change_detection(struct stp_port
*);
151 void stp_port_disable_change_detection(struct stp_port
*);