ieee8023ad_lacp.h revision 171247
1168561Sthompsa/*	$NetBSD: ieee8023ad_impl.h,v 1.2 2005/12/10 23:21:39 elad Exp $	*/
2168561Sthompsa
3168561Sthompsa/*-
4168561Sthompsa * Copyright (c)2005 YAMAMOTO Takashi,
5168561Sthompsa * All rights reserved.
6168561Sthompsa *
7168561Sthompsa * Redistribution and use in source and binary forms, with or without
8168561Sthompsa * modification, are permitted provided that the following conditions
9168561Sthompsa * are met:
10168561Sthompsa * 1. Redistributions of source code must retain the above copyright
11168561Sthompsa *    notice, this list of conditions and the following disclaimer.
12168561Sthompsa * 2. Redistributions in binary form must reproduce the above copyright
13168561Sthompsa *    notice, this list of conditions and the following disclaimer in the
14168561Sthompsa *    documentation and/or other materials provided with the distribution.
15168561Sthompsa *
16168561Sthompsa * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17168561Sthompsa * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18168561Sthompsa * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19168561Sthompsa * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20168561Sthompsa * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21168561Sthompsa * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22168561Sthompsa * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23168561Sthompsa * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24168561Sthompsa * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25168561Sthompsa * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26168561Sthompsa * SUCH DAMAGE.
27168561Sthompsa *
28168561Sthompsa * $FreeBSD: head/sys/net/ieee8023ad_lacp.h 171247 2007-07-05 09:18:57Z thompsa $
29168561Sthompsa */
30168561Sthompsa
31168561Sthompsa/*
32168561Sthompsa * IEEE802.3ad LACP
33168561Sthompsa *
34168561Sthompsa * implementation details.
35168561Sthompsa */
36168561Sthompsa
37168561Sthompsa#define	LACP_TIMER_CURRENT_WHILE	0
38168561Sthompsa#define	LACP_TIMER_PERIODIC		1
39168561Sthompsa#define	LACP_TIMER_WAIT_WHILE		2
40168561Sthompsa#define	LACP_NTIMER			3
41168561Sthompsa
42168561Sthompsa#define	LACP_TIMER_ARM(port, timer, val) \
43168561Sthompsa	(port)->lp_timer[(timer)] = (val)
44168561Sthompsa#define	LACP_TIMER_DISARM(port, timer) \
45168561Sthompsa	(port)->lp_timer[(timer)] = 0
46168561Sthompsa#define	LACP_TIMER_ISARMED(port, timer) \
47168561Sthompsa	((port)->lp_timer[(timer)] > 0)
48168561Sthompsa
49168561Sthompsa/*
50168561Sthompsa * IEEE802.3ad LACP
51168561Sthompsa *
52168561Sthompsa * protocol definitions.
53168561Sthompsa */
54168561Sthompsa
55168561Sthompsa#define	LACP_STATE_ACTIVITY	(1<<0)
56168561Sthompsa#define	LACP_STATE_TIMEOUT	(1<<1)
57168561Sthompsa#define	LACP_STATE_AGGREGATION	(1<<2)
58168561Sthompsa#define	LACP_STATE_SYNC		(1<<3)
59168561Sthompsa#define	LACP_STATE_COLLECTING	(1<<4)
60168561Sthompsa#define	LACP_STATE_DISTRIBUTING	(1<<5)
61168561Sthompsa#define	LACP_STATE_DEFAULTED	(1<<6)
62168561Sthompsa#define	LACP_STATE_EXPIRED	(1<<7)
63168561Sthompsa
64170599Sthompsa#define	LACP_PORT_NTT		0x00000001
65170599Sthompsa#define	LACP_PORT_MARK		0x00000002
66168561Sthompsa
67168561Sthompsa#define	LACP_STATE_BITS		\
68168561Sthompsa	"\020"			\
69168561Sthompsa	"\001ACTIVITY"		\
70168561Sthompsa	"\002TIMEOUT"		\
71168561Sthompsa	"\003AGGREGATION"	\
72168561Sthompsa	"\004SYNC"		\
73168561Sthompsa	"\005COLLECTING"	\
74168561Sthompsa	"\006DISTRIBUTING"	\
75168561Sthompsa	"\007DEFAULTED"		\
76168561Sthompsa	"\010EXPIRED"
77168561Sthompsa
78168561Sthompsa/*
79168561Sthompsa * IEEE802.3 slow protocols
80168561Sthompsa *
81168561Sthompsa * protocol (on-wire) definitions.
82168561Sthompsa *
83168561Sthompsa * XXX should be elsewhere.
84168561Sthompsa */
85168561Sthompsa
86168561Sthompsa#define	SLOWPROTOCOLS_SUBTYPE_LACP	1
87168561Sthompsa#define	SLOWPROTOCOLS_SUBTYPE_MARKER	2
88168561Sthompsa
89168561Sthompsastruct slowprothdr {
90168561Sthompsa	uint8_t		sph_subtype;
91168561Sthompsa	uint8_t		sph_version;
92168561Sthompsa} __packed;
93168561Sthompsa
94168561Sthompsa/*
95168561Sthompsa * TLV on-wire structure.
96168561Sthompsa */
97168561Sthompsa
98168561Sthompsastruct tlvhdr {
99168561Sthompsa	uint8_t		tlv_type;
100168561Sthompsa	uint8_t		tlv_length;
101168561Sthompsa	/* uint8_t tlv_value[]; */
102168561Sthompsa} __packed;
103168561Sthompsa
104168561Sthompsa/*
105168561Sthompsa * ... and our implementation.
106168561Sthompsa */
107168561Sthompsa
108168561Sthompsa#define	TLV_SET(tlv, type, length) \
109168561Sthompsa	do { \
110168561Sthompsa		(tlv)->tlv_type = (type); \
111168561Sthompsa		(tlv)->tlv_length = sizeof(*tlv) + (length); \
112168561Sthompsa	} while (/*CONSTCOND*/0)
113168561Sthompsa
114168561Sthompsastruct tlv_template {
115168561Sthompsa	uint8_t			tmpl_type;
116168561Sthompsa	uint8_t			tmpl_length;
117168561Sthompsa};
118168561Sthompsa
119168561Sthompsastruct lacp_systemid {
120168561Sthompsa	uint16_t		lsi_prio;
121168561Sthompsa	uint8_t			lsi_mac[6];
122168561Sthompsa} __packed;
123168561Sthompsa
124168561Sthompsastruct lacp_portid {
125168561Sthompsa	uint16_t		lpi_prio;
126168561Sthompsa	uint16_t		lpi_portno;
127168561Sthompsa} __packed;
128168561Sthompsa
129168561Sthompsastruct lacp_peerinfo {
130170599Sthompsa	struct lacp_systemid	lip_systemid;
131168561Sthompsa	uint16_t		lip_key;
132170599Sthompsa	struct lacp_portid	lip_portid;
133168561Sthompsa	uint8_t			lip_state;
134168561Sthompsa	uint8_t			lip_resv[3];
135168561Sthompsa} __packed;
136168561Sthompsa
137168561Sthompsastruct lacp_collectorinfo {
138168561Sthompsa	uint16_t		lci_maxdelay;
139168561Sthompsa	uint8_t			lci_resv[12];
140168561Sthompsa} __packed;
141168561Sthompsa
142168561Sthompsastruct lacpdu {
143168561Sthompsa	struct ether_header	ldu_eh;
144168561Sthompsa	struct slowprothdr	ldu_sph;
145168561Sthompsa
146168561Sthompsa	struct tlvhdr		ldu_tlv_actor;
147168561Sthompsa	struct lacp_peerinfo	ldu_actor;
148168561Sthompsa	struct tlvhdr		ldu_tlv_partner;
149168561Sthompsa	struct lacp_peerinfo	ldu_partner;
150168561Sthompsa	struct tlvhdr		ldu_tlv_collector;
151168561Sthompsa	struct lacp_collectorinfo ldu_collector;
152168561Sthompsa	struct tlvhdr		ldu_tlv_term;
153168561Sthompsa	uint8_t			ldu_resv[50];
154168561Sthompsa} __packed;
155168561Sthompsa
156169739Sthompsa/*
157169739Sthompsa * IEEE802.3ad marker protocol
158169739Sthompsa *
159169739Sthompsa * protocol (on-wire) definitions.
160169739Sthompsa */
161169739Sthompsastruct lacp_markerinfo {
162169739Sthompsa	uint16_t		mi_rq_port;
163169739Sthompsa	uint8_t			mi_rq_system[ETHER_ADDR_LEN];
164169739Sthompsa	uint32_t		mi_rq_xid;
165169739Sthompsa	uint8_t			mi_pad[2];
166169739Sthompsa} __packed;
167168561Sthompsa
168169739Sthompsastruct markerdu {
169169739Sthompsa	struct ether_header	mdu_eh;
170169739Sthompsa	struct slowprothdr	mdu_sph;
171169739Sthompsa
172169739Sthompsa	struct tlvhdr		mdu_tlv;
173169739Sthompsa	struct lacp_markerinfo	mdu_info;
174169739Sthompsa	struct tlvhdr		mdu_tlv_term;
175169739Sthompsa	uint8_t			mdu_resv[90];
176169739Sthompsa} __packed;
177169739Sthompsa
178169739Sthompsa#define	MARKER_TYPE_INFO	0x01
179169739Sthompsa#define	MARKER_TYPE_RESPONSE	0x02
180169739Sthompsa
181168561Sthompsaenum lacp_selected {
182168561Sthompsa	LACP_UNSELECTED,
183168561Sthompsa	LACP_STANDBY,	/* not used in this implementation */
184168561Sthompsa	LACP_SELECTED,
185168561Sthompsa};
186168561Sthompsa
187168561Sthompsaenum lacp_mux_state {
188168561Sthompsa	LACP_MUX_DETACHED,
189168561Sthompsa	LACP_MUX_WAITING,
190168561Sthompsa	LACP_MUX_ATTACHED,
191168561Sthompsa	LACP_MUX_COLLECTING,
192168561Sthompsa	LACP_MUX_DISTRIBUTING,
193168561Sthompsa};
194168561Sthompsa
195168561Sthompsastruct lacp_port {
196168561Sthompsa	TAILQ_ENTRY(lacp_port)	lp_dist_q;
197168561Sthompsa	LIST_ENTRY(lacp_port)	lp_next;
198168561Sthompsa	struct lacp_softc	*lp_lsc;
199168793Sthompsa	struct lagg_port	*lp_lagg;
200168561Sthompsa	struct ifnet		*lp_ifp;
201168561Sthompsa	struct lacp_peerinfo	lp_partner;
202168561Sthompsa	struct lacp_peerinfo	lp_actor;
203169739Sthompsa	struct lacp_markerinfo	lp_marker;
204168561Sthompsa#define	lp_state	lp_actor.lip_state
205168561Sthompsa#define	lp_key		lp_actor.lip_key
206169739Sthompsa#define	lp_systemid	lp_actor.lip_systemid
207168561Sthompsa	struct timeval		lp_last_lacpdu;
208168561Sthompsa	int			lp_lacpdu_sent;
209168561Sthompsa	enum lacp_mux_state	lp_mux_state;
210168561Sthompsa	enum lacp_selected	lp_selected;
211168561Sthompsa	int			lp_flags;
212168561Sthompsa	u_int			lp_media; /* XXX redundant */
213168561Sthompsa	int			lp_timer[LACP_NTIMER];
214169327Sthompsa	struct ifmultiaddr	*lp_ifma;
215168561Sthompsa
216168561Sthompsa	struct lacp_aggregator	*lp_aggregator;
217168561Sthompsa};
218168561Sthompsa
219168561Sthompsastruct lacp_aggregator {
220168561Sthompsa	TAILQ_ENTRY(lacp_aggregator)	la_q;
221168561Sthompsa	int			la_refcnt; /* num of ports which selected us */
222168561Sthompsa	int			la_nports; /* num of distributing ports  */
223168561Sthompsa	TAILQ_HEAD(, lacp_port)	la_ports; /* distributing ports */
224168561Sthompsa	struct lacp_peerinfo	la_partner;
225168561Sthompsa	struct lacp_peerinfo	la_actor;
226170599Sthompsa	int			la_pending; /* number of ports in wait_while */
227168561Sthompsa};
228168561Sthompsa
229168561Sthompsastruct lacp_softc {
230170599Sthompsa	struct lagg_softc	*lsc_softc;
231168561Sthompsa	struct lacp_aggregator	*lsc_active_aggregator;
232168561Sthompsa	TAILQ_HEAD(, lacp_aggregator) lsc_aggregators;
233168561Sthompsa	boolean_t		lsc_suppress_distributing;
234168561Sthompsa	struct callout		lsc_transit_callout;
235168561Sthompsa	struct callout		lsc_callout;
236168561Sthompsa	LIST_HEAD(, lacp_port)	lsc_ports;
237168561Sthompsa	u_int32_t		lsc_hashkey;
238169569Sthompsa	struct task		lsc_qtask;
239169569Sthompsa	struct ifqueue		lsc_queue;	/* pdu input queue */
240168561Sthompsa};
241168561Sthompsa
242168561Sthompsa#define	LACP_TYPE_ACTORINFO	1
243168561Sthompsa#define	LACP_TYPE_PARTNERINFO	2
244168561Sthompsa#define	LACP_TYPE_COLLECTORINFO	3
245168561Sthompsa
246168561Sthompsa/* timeout values (in sec) */
247168561Sthompsa#define	LACP_FAST_PERIODIC_TIME		(1)
248168561Sthompsa#define	LACP_SLOW_PERIODIC_TIME		(30)
249168561Sthompsa#define	LACP_SHORT_TIMEOUT_TIME		(3 * LACP_FAST_PERIODIC_TIME)
250168561Sthompsa#define	LACP_LONG_TIMEOUT_TIME		(3 * LACP_SLOW_PERIODIC_TIME)
251168561Sthompsa#define	LACP_CHURN_DETECTION_TIME	(60)
252168561Sthompsa#define	LACP_AGGREGATE_WAIT_TIME	(2)
253169739Sthompsa#define	LACP_TRANSIT_DELAY		3000	/* in msec */
254168561Sthompsa
255168561Sthompsa#define	LACP_STATE_EQ(s1, s2, mask)	\
256168561Sthompsa	((((s1) ^ (s2)) & (mask)) == 0)
257168561Sthompsa
258169741Sthompsa#define	LACP_SYS_PRI(peer)	(peer).lip_systemid.lsi_prio
259169741Sthompsa
260168793Sthompsa#define	LACP_PORT(_lp)	((struct lacp_port *)(_lp)->lp_psc)
261168793Sthompsa#define	LACP_SOFTC(_sc)	((struct lacp_softc *)(_sc)->sc_psc)
262168561Sthompsa
263169569Sthompsavoid		lacp_input(struct lagg_port *, struct mbuf *);
264168793Sthompsastruct lagg_port *lacp_select_tx_port(struct lagg_softc *, struct mbuf *);
265168793Sthompsaint		lacp_attach(struct lagg_softc *);
266168793Sthompsaint		lacp_detach(struct lagg_softc *);
267168793Sthompsavoid		lacp_init(struct lagg_softc *);
268168793Sthompsavoid		lacp_stop(struct lagg_softc *);
269168793Sthompsaint		lacp_port_create(struct lagg_port *);
270168793Sthompsavoid		lacp_port_destroy(struct lagg_port *);
271168793Sthompsavoid		lacp_linkstate(struct lagg_port *);
272168793Sthompsaint		lacp_port_isactive(struct lagg_port *);
273171247Sthompsavoid		lacp_req(struct lagg_softc *, caddr_t);
274171247Sthompsavoid		lacp_portreq(struct lagg_port *, caddr_t);
275168561Sthompsa
276168561Sthompsa/* following constants don't include terminating NUL */
277168561Sthompsa#define	LACP_MACSTR_MAX		(2*6 + 5)
278168561Sthompsa#define	LACP_SYSTEMPRIOSTR_MAX	(4)
279168561Sthompsa#define	LACP_SYSTEMIDSTR_MAX	(LACP_SYSTEMPRIOSTR_MAX + 1 + LACP_MACSTR_MAX)
280168561Sthompsa#define	LACP_PORTPRIOSTR_MAX	(4)
281168561Sthompsa#define	LACP_PORTNOSTR_MAX	(4)
282168561Sthompsa#define	LACP_PORTIDSTR_MAX	(LACP_PORTPRIOSTR_MAX + 1 + LACP_PORTNOSTR_MAX)
283168561Sthompsa#define	LACP_KEYSTR_MAX		(4)
284168561Sthompsa#define	LACP_PARTNERSTR_MAX	\
285168561Sthompsa	(1 + LACP_SYSTEMIDSTR_MAX + 1 + LACP_KEYSTR_MAX + 1 \
286168561Sthompsa	+ LACP_PORTIDSTR_MAX + 1)
287168561Sthompsa#define	LACP_LAGIDSTR_MAX	\
288168561Sthompsa	(1 + LACP_PARTNERSTR_MAX + 1 + LACP_PARTNERSTR_MAX + 1)
289168561Sthompsa#define	LACP_STATESTR_MAX	(255) /* XXX */
290