Home | History | Annotate | Line # | Download | only in agr
ieee8023ad_lacp_impl.h revision 1.1
      1 /*	$NetBSD: ieee8023ad_lacp_impl.h,v 1.1 2005/03/18 11:11:50 yamt Exp $	*/
      2 
      3 /*-
      4  * Copyright (c)2005 YAMAMOTO Takashi,
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  * SUCH DAMAGE.
     27  */
     28 
     29 #if !defined(_NET_AGR_IEEE8023AD_LACP_IMPL_H_)
     30 #define	_NET_AGR_IEEE8023AD_LACP_IMPL_H_
     31 
     32 /*
     33  * IEEE802.3ad LACP
     34  *
     35  * implementation details.
     36  */
     37 
     38 #define	LACP_TIMER_CURRENT_WHILE	0
     39 #define	LACP_TIMER_PERIODIC		1
     40 #define	LACP_TIMER_WAIT_WHILE		2
     41 #define	LACP_NTIMER			3
     42 
     43 #define	LACP_TIMER_ARM(port, timer, val) \
     44 	(port)->lp_timer[(timer)] = (val)
     45 #define	LACP_TIMER_DISARM(port, timer) \
     46 	(port)->lp_timer[(timer)] = 0
     47 #define	LACP_TIMER_ISARMED(port, timer) \
     48 	((port)->lp_timer[(timer)] > 0)
     49 
     50 struct lacp_aggregator {
     51 	TAILQ_ENTRY(lacp_aggregator) la_q;
     52 	int la_refcnt; /* number of ports which selected us */
     53 	int la_nports; /* number of distributing ports  */
     54 	TAILQ_HEAD(, lacp_port) la_ports; /* distributing ports */
     55 	struct lacp_peerinfo la_partner;
     56 	struct lacp_peerinfo la_actor;
     57 	int la_pending; /* number of ports which is waiting wait_while */
     58 };
     59 
     60 struct lacp_softc {
     61 	struct lacp_aggregator *lsc_active_aggregator;
     62 	TAILQ_HEAD(, lacp_aggregator) lsc_aggregators;
     63 	boolean_t lsc_suppress_distributing;
     64 	struct callout lsc_transit_callout;
     65 };
     66 
     67 #define	LACP_TRANSIT_DELAY	1000	/* in msec */
     68 
     69 enum lacp_selected {
     70 	LACP_UNSELECTED,
     71 	LACP_STANDBY,	/* not used in this implementation */
     72 	LACP_SELECTED,
     73 };
     74 
     75 enum lacp_mux_state {
     76 	LACP_MUX_DETACHED,
     77 	LACP_MUX_WAITING,
     78 	LACP_MUX_ATTACHED,
     79 	LACP_MUX_COLLECTING,
     80 	LACP_MUX_DISTRIBUTING,
     81 };
     82 
     83 struct lacp_port {
     84 	TAILQ_ENTRY(lacp_port) lp_dist_q;
     85 	struct agr_port *lp_agrport;
     86 	struct lacp_peerinfo lp_partner;
     87 	struct lacp_peerinfo lp_actor;
     88 #define	lp_state	lp_actor.lip_state
     89 #define	lp_key		lp_actor.lip_key
     90 	int lp_last_lacpdu_sent;
     91 	enum lacp_mux_state lp_mux_state;
     92 	enum lacp_selected lp_selected;
     93 	int lp_flags;
     94 	u_int lp_media; /* XXX redundant */
     95 	int lp_timer[LACP_NTIMER];
     96 
     97 	struct lacp_aggregator *lp_aggregator;
     98 };
     99 
    100 #define	LACPPORT_NTT		1	/* need to transmit */
    101 
    102 typedef void (*lacp_timer_func_t)(struct lacp_port *);
    103 const lacp_timer_func_t lacp_timer_funcs[LACP_NTIMER];
    104 
    105 #define	LACP_SOFTC(sc) \
    106 	(&IEEE8023AD_SOFTC(sc)->isc_lacpsc)
    107 #define	LACP_PORT(port) \
    108 	(&IEEE8023AD_PORT(port)->iport_lacpport)
    109 
    110 void lacp_run_timers(struct lacp_port *);
    111 void lacp_portinit(struct agr_port *);
    112 void lacp_portfini(struct agr_port *);
    113 int lacp_compare_peerinfo(const struct lacp_peerinfo *,
    114     const struct lacp_peerinfo *);
    115 int lacp_compare_systemid(const struct lacp_systemid *,
    116     const struct lacp_systemid *);
    117 int lacp_compare_portid(const struct lacp_portid *,
    118     const struct lacp_portid *);
    119 
    120 void lacp_select(struct lacp_port *);
    121 void lacp_unselect(struct lacp_port *);
    122 
    123 void lacp_disable_collecting(struct lacp_port *);
    124 void lacp_enable_collecting(struct lacp_port *);
    125 void lacp_disable_distributing(struct lacp_port *);
    126 void lacp_enable_distributing(struct lacp_port *);
    127 
    128 int lacp_xmit_lacpdu(struct lacp_port *);
    129 
    130 #endif /* _NET_AGR_IEEE8023AD_LACP_IMPL_H_ */
    131