lacp: New "lacp-heartbeat" mode.
[cascardo/ovs.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 enum lacp_time {
79     LACP_TIME_FAST,
80     LACP_TIME_SLOW,
81     LACP_TIME_CUSTOM
82 };
83
84 struct lacp_settings {
85     char *name;
86     uint8_t id[ETH_ADDR_LEN];
87     uint16_t priority;
88     bool active;
89     enum lacp_time lacp_time;
90     long long int custom_time;
91     bool heartbeat;
92 };
93
94 void lacp_init(void);
95 struct lacp *lacp_create(void);
96 void lacp_destroy(struct lacp *);
97
98 void lacp_configure(struct lacp *, const struct lacp_settings *);
99 bool lacp_is_active(const struct lacp *);
100
101 void lacp_process_pdu(struct lacp *, const void *slave,
102                       const struct lacp_pdu *);
103 bool lacp_negotiated(const struct lacp *);
104
105 struct lacp_slave_settings {
106     char *name;
107     uint16_t id;
108     uint16_t priority;
109     uint16_t key;
110 };
111
112 void lacp_slave_register(struct lacp *, void *slave_,
113                          const struct lacp_slave_settings *);
114 void lacp_slave_unregister(struct lacp *, const void *slave);
115 void lacp_slave_carrier_changed(const struct lacp *, const void *slave);
116 bool lacp_slave_may_enable(const struct lacp *, const void *slave);
117 uint16_t lacp_slave_get_port_id(const struct lacp *, const void *slave);
118 bool lacp_slave_is_current(const struct lacp *, const void *slave_);
119
120 /* Callback function for lacp_run() for sending a LACP PDU. */
121 typedef void lacp_send_pdu(void *slave, const struct lacp_pdu *);
122
123 void lacp_run(struct lacp *, lacp_send_pdu *);
124 void lacp_wait(struct lacp *);
125
126 #endif /* lacp.h */