Add support for OFPFC_MODIFY Flow Mod command.
[sliver-openvswitch.git] / include / stp.h
1 /* Copyright (c) 2008 The Board of Trustees of The Leland Stanford
2  * Junior University
3  *
4  * We are making the OpenFlow specification and associated documentation
5  * (Software) available for public use and benefit with the expectation
6  * that others will use, modify and enhance the Software and contribute
7  * those enhancements back to the community. However, since we would
8  * like to make the Software available for broadest use, with as few
9  * restrictions as possible permission is hereby granted, free of
10  * charge, to any person obtaining a copy of this Software to deal in
11  * the Software under the copyrights without restriction, including
12  * without limitation the rights to use, copy, modify, merge, publish,
13  * distribute, sublicense, and/or sell copies of the Software, and to
14  * permit persons to whom the Software is furnished to do so, subject to
15  * the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be
18  * included in all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23  * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
24  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
25  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
26  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27  * SOFTWARE.
28  *
29  * The name and trademarks of copyright holder(s) may NOT be used in
30  * advertising or publicity pertaining to the Software or any
31  * derivatives without specific, written prior permission.
32  */
33
34 #ifndef STP_H
35 #define STP_H 1
36
37 /* This is an implementation of Spanning Tree Protocol as described in IEEE
38  * 802.1D-1998, clauses 8 and 9.  Section numbers refer to this standard.  */
39
40 #include <stdbool.h>
41 #include <stdint.h>
42 #include "compiler.h"
43 #include "util.h"
44
45 /* Ethernet address used as the destination for STP frames. */
46 extern const uint8_t stp_eth_addr[6];
47
48 /* LLC field values used for STP frames. */
49 #define STP_LLC_SSAP 0x42
50 #define STP_LLC_DSAP 0x42
51 #define STP_LLC_CNTL 0x03
52
53 /* Bridge identifier.  Top 16 bits are a priority value (numerically lower
54  * values are higher priorities).  Bottom 48 bits are MAC address of bridge. */
55 typedef uint64_t stp_identifier;
56
57 /* Basic STP functionality. */
58 #define STP_MAX_PORTS 255
59 struct stp *stp_create(const char *name, stp_identifier bridge_id,
60                        void (*send_bpdu)(const void *bpdu, size_t bpdu_size,
61                                          int port_no, void *aux),
62                        void *aux);
63 void stp_destroy(struct stp *);
64 void stp_tick(struct stp *, int elapsed);
65 void stp_set_bridge_priority(struct stp *, uint16_t new_priority);
66
67 /* STP properties. */
68 const char *stp_get_name(const struct stp *);
69 stp_identifier stp_get_bridge_id(const struct stp *);
70 stp_identifier stp_get_designated_root(const struct stp *);
71 bool stp_is_root_bridge(const struct stp *);
72 int stp_get_root_path_cost(const struct stp *);
73
74 /* Obtaining STP ports. */
75 struct stp_port *stp_get_port(struct stp *, int port_no);
76 struct stp_port *stp_get_root_port(struct stp *);
77 bool stp_get_changed_port(struct stp *, struct stp_port **portp);
78
79 /* State of an STP port.
80  *
81  * A port is in exactly one state at any given time, but distinct bits are used
82  * for states to allow testing for more than one state with a bit mask. */
83 enum stp_state {
84     STP_DISABLED = 1 << 0,       /* 8.4.5: Disabled by management. */
85     STP_LISTENING = 1 << 1,      /* 8.4.2: Not learning or relaying frames. */
86     STP_LEARNING = 1 << 2,       /* 8.4.3: Learning but not relaying frames. */
87     STP_FORWARDING = 1 << 3,     /* 8.4.4: Learning and relaying frames. */
88     STP_BLOCKING = 1 << 4        /* 8.4.1: Initial boot state. */
89 };
90 const char *stp_state_name(enum stp_state);
91 bool stp_forward_in_state(enum stp_state);
92 bool stp_learn_in_state(enum stp_state);
93
94 void stp_received_bpdu(struct stp_port *, const void *bpdu, size_t bpdu_size);
95
96 struct stp *stp_port_get_stp(struct stp_port *);
97 int stp_port_no(const struct stp_port *);
98 enum stp_state stp_port_get_state(const struct stp_port *);
99 void stp_port_enable(struct stp_port *);
100 void stp_port_disable(struct stp_port *);
101 void stp_port_set_priority(struct stp_port *, uint8_t new_priority);
102 void stp_port_set_path_cost(struct stp_port *, unsigned int path_cost);
103 void stp_port_set_speed(struct stp_port *, unsigned int speed);
104 void stp_port_enable_change_detection(struct stp_port *);
105 void stp_port_disable_change_detection(struct stp_port *);
106
107 #endif /* stp.h */