lacp: Remove LACP_[FAST|SLOW]_TIME_RX macros.
[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 /* Masks for lacp_info state member. */
25 #define LACP_STATE_ACT  0x01 /* Activity. Active or passive? */
26 #define LACP_STATE_TIME 0x02 /* Timeout. Short or long timeout? */
27 #define LACP_STATE_AGG  0x04 /* Aggregation. Is the link is bondable? */
28 #define LACP_STATE_SYNC 0x08 /* Synchronization. Is the link in up to date? */
29 #define LACP_STATE_COL  0x10 /* Collecting. Is the link receiving frames? */
30 #define LACP_STATE_DIST 0x20 /* Distributing. Is the link sending frames? */
31 #define LACP_STATE_DEF  0x40 /* Defaulted. Using default partner info? */
32 #define LACP_STATE_EXP  0x80 /* Expired. Using expired partner info? */
33
34 #define LACP_FAST_TIME_TX 1000  /* Fast transmission rate. */
35 #define LACP_SLOW_TIME_TX 30000 /* Slow transmission rate. */
36 #define LACP_RX_MULTIPLIER 3    /* Multiply by TX rate to get RX rate. */
37
38 #define LACP_INFO_LEN 15
39 struct lacp_info {
40     ovs_be16 sys_priority;            /* System priority. */
41     uint8_t sys_id[ETH_ADDR_LEN];     /* System ID. */
42     ovs_be16 key;                     /* Operational key. */
43     ovs_be16 port_priority;           /* Port priority. */
44     ovs_be16 port_id;                 /* Port ID. */
45     uint8_t state;                    /* State mask.  See LACP_STATE macros. */
46 } __attribute__((packed));
47 BUILD_ASSERT_DECL(LACP_INFO_LEN == sizeof(struct lacp_info));
48
49 #define LACP_PDU_LEN 110
50 struct lacp_pdu {
51     uint8_t subtype;          /* Always 1. */
52     uint8_t version;          /* Always 1. */
53
54     uint8_t actor_type;       /* Always 1. */
55     uint8_t actor_len;        /* Always 20. */
56     struct lacp_info actor;   /* LACP actor information. */
57     uint8_t z1[3];            /* Reserved.  Always 0. */
58
59     uint8_t partner_type;     /* Always 2. */
60     uint8_t partner_len;      /* Always 20. */
61     struct lacp_info partner; /* LACP partner information. */
62     uint8_t z2[3];            /* Reserved.  Always 0. */
63
64     uint8_t collector_type;   /* Always 3. */
65     uint8_t collector_len;    /* Always 16. */
66     ovs_be16 collector_delay; /* Maximum collector delay. Set to UINT16_MAX. */
67     uint8_t z3[64];           /* Combination of several fields.  Always 0. */
68 } __attribute__((packed));
69 BUILD_ASSERT_DECL(LACP_PDU_LEN == sizeof(struct lacp_pdu));
70
71 void compose_lacp_pdu(const struct lacp_info *actor,
72                       const struct lacp_info *partner, struct lacp_pdu *);
73
74 const struct lacp_pdu *parse_lacp_packet(const struct ofpbuf *);
75 \f
76 /* LACP Protocol Implementation. */
77
78 struct lacp_settings {
79     char *name;
80     uint8_t id[ETH_ADDR_LEN];
81     uint16_t priority;
82     bool active;
83     bool fast;
84     bool strict;
85 };
86
87 void lacp_init(void);
88 struct lacp *lacp_create(void);
89 void lacp_destroy(struct lacp *);
90
91 void lacp_configure(struct lacp *, const struct lacp_settings *);
92 bool lacp_is_active(const struct lacp *);
93
94 void lacp_process_pdu(struct lacp *, const void *slave,
95                       const struct lacp_pdu *);
96 bool lacp_negotiated(const struct lacp *);
97
98 struct lacp_slave_settings {
99     char *name;
100     uint16_t id;
101     uint16_t priority;
102 };
103
104 void lacp_slave_register(struct lacp *, void *slave_,
105                          const struct lacp_slave_settings *);
106 void lacp_slave_unregister(struct lacp *, const void *slave);
107 void lacp_slave_carrier_changed(const struct lacp *, const void *slave);
108 bool lacp_slave_may_enable(const struct lacp *, const void *slave);
109 uint16_t lacp_slave_get_port_id(const struct lacp *, const void *slave);
110 bool lacp_slave_is_current(const struct lacp *, const void *slave_);
111
112 /* Callback function for lacp_run() for sending a LACP PDU. */
113 typedef void lacp_send_pdu(void *slave, const struct lacp_pdu *);
114
115 void lacp_run(struct lacp *, lacp_send_pdu *);
116 void lacp_wait(struct lacp *);
117
118 #endif /* lacp.h */