293fc454d2f0d7ca1f9ae857ccf361949927b86a
[sliver-openvswitch.git] / lib / lacp.h
1 /*
2  * Copyright (c) 2011 Nicira Networks.
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 LACP_H
18 #define LACP_H 1
19
20 #include <stdbool.h>
21 #include <stdint.h>
22 #include "packets.h"
23
24 /* LACP Protocol Implementation. */
25
26 enum lacp_time {
27     LACP_TIME_FAST,                   /* LACP fast mode. */
28     LACP_TIME_SLOW,                   /* LACP slow mode. */
29     LACP_TIME_CUSTOM                  /* Nonstandard custom mode. */
30 };
31
32 enum lacp_status {
33     LACP_NEGOTIATED,                  /* Successful LACP negotations. */
34     LACP_CONFIGURED,                  /* LACP is enabled but not negotiated. */
35     LACP_DISABLED                     /* LACP is not enabled. */
36 };
37
38 struct lacp_settings {
39     char *name;                       /* Name (for debugging). */
40     uint8_t id[ETH_ADDR_LEN];         /* System ID. Must be nonzero. */
41     uint16_t priority;                /* System priority. */
42     bool active;                      /* Active or passive mode? */
43     enum lacp_time lacp_time;         /* Probe rate. */
44     long long int custom_time;        /* Probe interval if LACP_TIME_CUSTOM. */
45     bool heartbeat;                   /* Heartbeat mode. */
46 };
47
48 void lacp_init(void);
49 struct lacp *lacp_create(void);
50 void lacp_destroy(struct lacp *);
51
52 void lacp_configure(struct lacp *, const struct lacp_settings *);
53 bool lacp_is_active(const struct lacp *);
54
55 void lacp_process_packet(struct lacp *, const void *slave,
56                          const struct ofpbuf *packet);
57 enum lacp_status lacp_status(const struct lacp *);
58
59 struct lacp_slave_settings {
60     char *name;                       /* Name (for debugging). */
61     uint16_t id;                      /* Port ID. */
62     uint16_t priority;                /* Port priority. */
63     uint16_t key;                     /* Aggregation key. */
64 };
65
66 void lacp_slave_register(struct lacp *, void *slave_,
67                          const struct lacp_slave_settings *);
68 void lacp_slave_unregister(struct lacp *, const void *slave);
69 void lacp_slave_carrier_changed(const struct lacp *, const void *slave);
70 bool lacp_slave_may_enable(const struct lacp *, const void *slave);
71 uint16_t lacp_slave_get_port_id(const struct lacp *, const void *slave);
72 bool lacp_slave_is_current(const struct lacp *, const void *slave_);
73
74 /* Callback function for lacp_run() for sending a LACP PDU. */
75 typedef void lacp_send_pdu(void *slave, const void *pdu, size_t pdu_size);
76
77 void lacp_run(struct lacp *, lacp_send_pdu *);
78 void lacp_wait(struct lacp *);
79
80 #endif /* lacp.h */