1 /* Copyright (c) 2011, 2012, 2013, 2014, 2015 Nicira, Inc.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
21 #include "connectivity.h"
22 #include "openvswitch/dynamic-string.h"
24 #include "openvswitch/hmap.h"
25 #include "dp-packet.h"
26 #include "ovs-atomic.h"
28 #include "poll-loop.h"
30 #include "openvswitch/shash.h"
34 #include "openvswitch/vlog.h"
37 VLOG_DEFINE_THIS_MODULE(lacp
);
39 /* Masks for lacp_info state member. */
40 #define LACP_STATE_ACT 0x01 /* Activity. Active or passive? */
41 #define LACP_STATE_TIME 0x02 /* Timeout. Short or long timeout? */
42 #define LACP_STATE_AGG 0x04 /* Aggregation. Is the link is bondable? */
43 #define LACP_STATE_SYNC 0x08 /* Synchronization. Is the link in up to date? */
44 #define LACP_STATE_COL 0x10 /* Collecting. Is the link receiving frames? */
45 #define LACP_STATE_DIST 0x20 /* Distributing. Is the link sending frames? */
46 #define LACP_STATE_DEF 0x40 /* Defaulted. Using default partner info? */
47 #define LACP_STATE_EXP 0x80 /* Expired. Using expired partner info? */
49 #define LACP_FAST_TIME_TX 1000 /* Fast transmission rate. */
50 #define LACP_SLOW_TIME_TX 30000 /* Slow transmission rate. */
51 #define LACP_RX_MULTIPLIER 3 /* Multiply by TX rate to get RX rate. */
53 #define LACP_INFO_LEN 15
56 ovs_be16 sys_priority
; /* System priority. */
57 struct eth_addr sys_id
; /* System ID. */
58 ovs_be16 key
; /* Operational key. */
59 ovs_be16 port_priority
; /* Port priority. */
60 ovs_be16 port_id
; /* Port ID. */
61 uint8_t state
; /* State mask. See LACP_STATE macros. */
63 BUILD_ASSERT_DECL(LACP_INFO_LEN
== sizeof(struct lacp_info
));
65 #define LACP_PDU_LEN 110
67 uint8_t subtype
; /* Always 1. */
68 uint8_t version
; /* Always 1. */
70 uint8_t actor_type
; /* Always 1. */
71 uint8_t actor_len
; /* Always 20. */
72 struct lacp_info actor
; /* LACP actor information. */
73 uint8_t z1
[3]; /* Reserved. Always 0. */
75 uint8_t partner_type
; /* Always 2. */
76 uint8_t partner_len
; /* Always 20. */
77 struct lacp_info partner
; /* LACP partner information. */
78 uint8_t z2
[3]; /* Reserved. Always 0. */
80 uint8_t collector_type
; /* Always 3. */
81 uint8_t collector_len
; /* Always 16. */
82 ovs_be16 collector_delay
; /* Maximum collector delay. Set to UINT16_MAX. */
83 uint8_t z3
[64]; /* Combination of several fields. Always 0. */
85 BUILD_ASSERT_DECL(LACP_PDU_LEN
== sizeof(struct lacp_pdu
));
90 LACP_CURRENT
, /* Current State. Partner up to date. */
91 LACP_EXPIRED
, /* Expired State. Partner out of date. */
92 LACP_DEFAULTED
, /* Defaulted State. No partner. */
96 struct ovs_list node
; /* Node in all_lacps list. */
97 char *name
; /* Name of this lacp object. */
98 struct eth_addr sys_id
; /* System ID. */
99 uint16_t sys_priority
; /* System Priority. */
100 bool active
; /* Active or Passive. */
102 struct hmap slaves
; /* Slaves this LACP object controls. */
103 struct slave
*key_slave
; /* Slave whose ID will be the aggregation key. */
105 bool fast
; /* True if using fast probe interval. */
106 bool negotiated
; /* True if LACP negotiations were successful. */
107 bool update
; /* True if lacp_update() needs to be called. */
108 bool fallback_ab
; /* True if fallback to active-backup on LACP failure. */
110 struct ovs_refcount ref_cnt
;
114 void *aux
; /* Handle used to identify this slave. */
115 struct hmap_node node
; /* Node in master's slaves map. */
117 struct lacp
*lacp
; /* LACP object containing this slave. */
118 uint16_t port_id
; /* Port ID. */
119 uint16_t port_priority
; /* Port Priority. */
120 uint16_t key
; /* Aggregation Key. 0 if default. */
121 char *name
; /* Name of this slave. */
123 enum slave_status status
; /* Slave status. */
124 bool attached
; /* Attached. Traffic may flow. */
125 struct lacp_info partner
; /* Partner information. */
126 struct lacp_info ntt_actor
; /* Used to decide if we Need To Transmit. */
127 struct timer tx
; /* Next message transmission timer. */
128 struct timer rx
; /* Expected message receive timer. */
130 uint32_t count_rx_pdus
; /* dot3adAggPortStatsLACPDUsRx */
131 uint32_t count_rx_pdus_bad
; /* dot3adAggPortStatsIllegalRx */
132 uint32_t count_tx_pdus
; /* dot3adAggPortStatsLACPDUsTx */
135 static struct ovs_mutex mutex
;
136 static struct ovs_list all_lacps__
= OVS_LIST_INITIALIZER(&all_lacps__
);
137 static struct ovs_list
*const all_lacps
OVS_GUARDED_BY(mutex
) = &all_lacps__
;
139 static void lacp_update_attached(struct lacp
*) OVS_REQUIRES(mutex
);
141 static void slave_destroy(struct slave
*) OVS_REQUIRES(mutex
);
142 static void slave_set_defaulted(struct slave
*) OVS_REQUIRES(mutex
);
143 static void slave_set_expired(struct slave
*) OVS_REQUIRES(mutex
);
144 static void slave_get_actor(struct slave
*, struct lacp_info
*actor
)
146 static void slave_get_priority(struct slave
*, struct lacp_info
*priority
)
148 static bool slave_may_tx(const struct slave
*)
150 static struct slave
*slave_lookup(const struct lacp
*, const void *slave
)
152 static bool info_tx_equal(struct lacp_info
*, struct lacp_info
*)
155 static unixctl_cb_func lacp_unixctl_show
;
157 /* Populates 'pdu' with a LACP PDU comprised of 'actor' and 'partner'. */
159 compose_lacp_pdu(const struct lacp_info
*actor
,
160 const struct lacp_info
*partner
, struct lacp_pdu
*pdu
)
162 memset(pdu
, 0, sizeof *pdu
);
171 pdu
->partner_type
= 2;
172 pdu
->partner_len
= 20;
173 pdu
->partner
= *partner
;
175 pdu
->collector_type
= 3;
176 pdu
->collector_len
= 16;
177 pdu
->collector_delay
= htons(0);
180 /* Parses 'b' which represents a packet containing a LACP PDU. This function
181 * returns NULL if 'b' is malformed, or does not represent a LACP PDU format
182 * supported by OVS. Otherwise, it returns a pointer to the lacp_pdu contained
184 static const struct lacp_pdu
*
185 parse_lacp_packet(const struct dp_packet
*p
)
187 const struct lacp_pdu
*pdu
;
189 pdu
= dp_packet_at(p
, (uint8_t *)dp_packet_l3(p
) - (uint8_t *)dp_packet_data(p
),
192 if (pdu
&& pdu
->subtype
== 1
193 && pdu
->actor_type
== 1 && pdu
->actor_len
== 20
194 && pdu
->partner_type
== 2 && pdu
->partner_len
== 20) {
201 /* LACP Protocol Implementation. */
203 /* Initializes the lacp module. */
207 unixctl_command_register("lacp/show", "[port]", 0, 1,
208 lacp_unixctl_show
, NULL
);
212 lacp_lock(void) OVS_ACQUIRES(mutex
)
214 static struct ovsthread_once once
= OVSTHREAD_ONCE_INITIALIZER
;
216 if (ovsthread_once_start(&once
)) {
217 ovs_mutex_init_recursive(&mutex
);
218 ovsthread_once_done(&once
);
220 ovs_mutex_lock(&mutex
);
224 lacp_unlock(void) OVS_RELEASES(mutex
)
226 ovs_mutex_unlock(&mutex
);
229 /* Creates a LACP object. */
231 lacp_create(void) OVS_EXCLUDED(mutex
)
235 lacp
= xzalloc(sizeof *lacp
);
236 hmap_init(&lacp
->slaves
);
237 ovs_refcount_init(&lacp
->ref_cnt
);
240 ovs_list_push_back(all_lacps
, &lacp
->node
);
246 lacp_ref(const struct lacp
*lacp_
)
248 struct lacp
*lacp
= CONST_CAST(struct lacp
*, lacp_
);
250 ovs_refcount_ref(&lacp
->ref_cnt
);
255 /* Destroys 'lacp' and its slaves. Does nothing if 'lacp' is NULL. */
257 lacp_unref(struct lacp
*lacp
) OVS_EXCLUDED(mutex
)
259 if (lacp
&& ovs_refcount_unref_relaxed(&lacp
->ref_cnt
) == 1) {
260 struct slave
*slave
, *next
;
263 HMAP_FOR_EACH_SAFE (slave
, next
, node
, &lacp
->slaves
) {
264 slave_destroy(slave
);
267 hmap_destroy(&lacp
->slaves
);
268 ovs_list_remove(&lacp
->node
);
275 /* Configures 'lacp' with settings from 's'. */
277 lacp_configure(struct lacp
*lacp
, const struct lacp_settings
*s
)
280 ovs_assert(!eth_addr_is_zero(s
->id
));
283 if (!lacp
->name
|| strcmp(s
->name
, lacp
->name
)) {
285 lacp
->name
= xstrdup(s
->name
);
288 if (!eth_addr_equals(lacp
->sys_id
, s
->id
)
289 || lacp
->sys_priority
!= s
->priority
) {
290 lacp
->sys_id
= s
->id
;
291 lacp
->sys_priority
= s
->priority
;
295 lacp
->active
= s
->active
;
296 lacp
->fast
= s
->fast
;
298 if (lacp
->fallback_ab
!= s
->fallback_ab_cfg
) {
299 lacp
->fallback_ab
= s
->fallback_ab_cfg
;
306 /* Returns true if 'lacp' is configured in active mode, false if 'lacp' is
307 * configured for passive mode. */
309 lacp_is_active(const struct lacp
*lacp
) OVS_EXCLUDED(mutex
)
318 /* Processes 'packet' which was received on 'slave_'. This function should be
319 * called on all packets received on 'slave_' with Ethernet Type ETH_TYPE_LACP.
322 lacp_process_packet(struct lacp
*lacp
, const void *slave_
,
323 const struct dp_packet
*packet
)
326 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(1, 5);
327 const struct lacp_pdu
*pdu
;
328 long long int tx_rate
;
332 slave
= slave_lookup(lacp
, slave_
);
336 slave
->count_rx_pdus
++;
338 pdu
= parse_lacp_packet(packet
);
340 slave
->count_rx_pdus_bad
++;
341 VLOG_WARN_RL(&rl
, "%s: received an unparsable LACP PDU.", lacp
->name
);
345 slave
->status
= LACP_CURRENT
;
346 tx_rate
= lacp
->fast
? LACP_FAST_TIME_TX
: LACP_SLOW_TIME_TX
;
347 timer_set_duration(&slave
->rx
, LACP_RX_MULTIPLIER
* tx_rate
);
349 slave
->ntt_actor
= pdu
->partner
;
351 /* Update our information about our partner if it's out of date. This may
352 * cause priorities to change so re-calculate attached status of all
354 if (memcmp(&slave
->partner
, &pdu
->actor
, sizeof pdu
->actor
)) {
356 slave
->partner
= pdu
->actor
;
363 /* Returns the lacp_status of the given 'lacp' object (which may be NULL). */
365 lacp_status(const struct lacp
*lacp
) OVS_EXCLUDED(mutex
)
368 enum lacp_status ret
;
371 ret
= lacp
->negotiated
? LACP_NEGOTIATED
: LACP_CONFIGURED
;
375 /* Don't take 'mutex'. It might not even be initialized, since we
376 * don't know that any lacp object has been created. */
377 return LACP_DISABLED
;
381 /* Registers 'slave_' as subordinate to 'lacp'. This should be called at least
382 * once per slave in a LACP managed bond. Should also be called whenever a
383 * slave's settings change. */
385 lacp_slave_register(struct lacp
*lacp
, void *slave_
,
386 const struct lacp_slave_settings
*s
)
392 slave
= slave_lookup(lacp
, slave_
);
394 slave
= xzalloc(sizeof *slave
);
397 hmap_insert(&lacp
->slaves
, &slave
->node
, hash_pointer(slave_
, 0));
398 slave_set_defaulted(slave
);
400 if (!lacp
->key_slave
) {
401 lacp
->key_slave
= slave
;
405 if (!slave
->name
|| strcmp(s
->name
, slave
->name
)) {
407 slave
->name
= xstrdup(s
->name
);
410 if (slave
->port_id
!= s
->id
411 || slave
->port_priority
!= s
->priority
412 || slave
->key
!= s
->key
) {
413 slave
->port_id
= s
->id
;
414 slave
->port_priority
= s
->priority
;
419 if (lacp
->active
|| lacp
->negotiated
) {
420 slave_set_expired(slave
);
426 /* Unregisters 'slave_' with 'lacp'. */
428 lacp_slave_unregister(struct lacp
*lacp
, const void *slave_
)
434 slave
= slave_lookup(lacp
, slave_
);
436 slave_destroy(slave
);
442 /* This function should be called whenever the carrier status of 'slave_' has
443 * changed. If 'lacp' is null, this function has no effect.*/
445 lacp_slave_carrier_changed(const struct lacp
*lacp
, const void *slave_
)
454 slave
= slave_lookup(lacp
, slave_
);
459 if (slave
->status
== LACP_CURRENT
|| slave
->lacp
->active
) {
460 slave_set_expired(slave
);
468 slave_may_enable__(struct slave
*slave
) OVS_REQUIRES(mutex
)
470 /* The slave may be enabled if it's attached to an aggregator and its
471 * partner is synchronized.*/
472 return slave
->attached
&& (slave
->partner
.state
& LACP_STATE_SYNC
473 || (slave
->lacp
&& slave
->lacp
->fallback_ab
474 && slave
->status
== LACP_DEFAULTED
));
477 /* This function should be called before enabling 'slave_' to send or receive
478 * traffic. If it returns false, 'slave_' should not enabled. As a
479 * convenience, returns true if 'lacp' is NULL. */
481 lacp_slave_may_enable(const struct lacp
*lacp
, const void *slave_
)
489 slave
= slave_lookup(lacp
, slave_
);
490 ret
= slave
? slave_may_enable__(slave
) : false;
498 /* Returns true if partner information on 'slave_' is up to date. 'slave_'
499 * not being current, generally indicates a connectivity problem, or a
500 * misconfigured (or broken) partner. */
502 lacp_slave_is_current(const struct lacp
*lacp
, const void *slave_
)
509 slave
= slave_lookup(lacp
, slave_
);
510 ret
= slave
? slave
->status
!= LACP_DEFAULTED
: false;
515 /* This function should be called periodically to update 'lacp'. */
517 lacp_run(struct lacp
*lacp
, lacp_send_pdu
*send_pdu
) OVS_EXCLUDED(mutex
)
522 HMAP_FOR_EACH (slave
, node
, &lacp
->slaves
) {
523 if (timer_expired(&slave
->rx
)) {
524 enum slave_status old_status
= slave
->status
;
526 if (slave
->status
== LACP_CURRENT
) {
527 slave_set_expired(slave
);
528 } else if (slave
->status
== LACP_EXPIRED
) {
529 slave_set_defaulted(slave
);
531 if (slave
->status
!= old_status
) {
532 seq_change(connectivity_seq_get());
538 lacp_update_attached(lacp
);
541 HMAP_FOR_EACH (slave
, node
, &lacp
->slaves
) {
542 struct lacp_info actor
;
544 if (!slave_may_tx(slave
)) {
548 slave_get_actor(slave
, &actor
);
550 if (timer_expired(&slave
->tx
)
551 || !info_tx_equal(&actor
, &slave
->ntt_actor
)) {
552 long long int duration
;
555 slave
->ntt_actor
= actor
;
556 compose_lacp_pdu(&actor
, &slave
->partner
, &pdu
);
557 send_pdu(slave
->aux
, &pdu
, sizeof pdu
);
558 slave
->count_tx_pdus
++;
560 duration
= (slave
->partner
.state
& LACP_STATE_TIME
562 : LACP_SLOW_TIME_TX
);
564 timer_set_duration(&slave
->tx
, duration
);
565 seq_change(connectivity_seq_get());
571 /* Causes poll_block() to wake up when lacp_run() needs to be called again. */
573 lacp_wait(struct lacp
*lacp
) OVS_EXCLUDED(mutex
)
578 HMAP_FOR_EACH (slave
, node
, &lacp
->slaves
) {
579 if (slave_may_tx(slave
)) {
580 timer_wait(&slave
->tx
);
583 if (slave
->status
!= LACP_DEFAULTED
) {
584 timer_wait(&slave
->rx
);
590 /* Static Helpers. */
592 /* Updates the attached status of all slaves controlled by 'lacp' and sets its
593 * negotiated parameter to true if any slaves are attachable. */
595 lacp_update_attached(struct lacp
*lacp
) OVS_REQUIRES(mutex
)
597 struct slave
*lead
, *slave
;
598 struct lacp_info lead_pri
;
600 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(1, 10);
602 lacp
->update
= false;
606 HMAP_FOR_EACH (slave
, node
, &lacp
->slaves
) {
607 struct lacp_info pri
;
609 slave
->attached
= false;
611 /* XXX: In the future allow users to configure the expected system ID.
612 * For now just special case loopback. */
613 if (eth_addr_equals(slave
->partner
.sys_id
, slave
->lacp
->sys_id
)) {
614 VLOG_WARN_RL(&rl
, "slave %s: Loopback detected. Slave is "
615 "connected to its own bond", slave
->name
);
619 if (slave
->status
== LACP_DEFAULTED
) {
620 if (lacp
->fallback_ab
) {
621 slave
->attached
= true;
626 slave
->attached
= true;
627 slave_get_priority(slave
, &pri
);
628 bool enable
= slave_may_enable__(slave
);
631 || enable
> lead_enable
632 || (enable
== lead_enable
633 && memcmp(&pri
, &lead_pri
, sizeof pri
) < 0)) {
635 lead_enable
= enable
;
640 lacp
->negotiated
= lead
!= NULL
;
643 HMAP_FOR_EACH (slave
, node
, &lacp
->slaves
) {
644 if ((lacp
->fallback_ab
&& slave
->status
== LACP_DEFAULTED
)
645 || lead
->partner
.key
!= slave
->partner
.key
646 || !eth_addr_equals(lead
->partner
.sys_id
,
647 slave
->partner
.sys_id
)) {
648 slave
->attached
= false;
655 slave_destroy(struct slave
*slave
) OVS_REQUIRES(mutex
)
658 struct lacp
*lacp
= slave
->lacp
;
661 hmap_remove(&lacp
->slaves
, &slave
->node
);
663 if (lacp
->key_slave
== slave
) {
664 struct hmap_node
*slave_node
= hmap_first(&lacp
->slaves
);
667 lacp
->key_slave
= CONTAINER_OF(slave_node
, struct slave
, node
);
669 lacp
->key_slave
= NULL
;
679 slave_set_defaulted(struct slave
*slave
) OVS_REQUIRES(mutex
)
681 memset(&slave
->partner
, 0, sizeof slave
->partner
);
683 slave
->lacp
->update
= true;
684 slave
->status
= LACP_DEFAULTED
;
688 slave_set_expired(struct slave
*slave
) OVS_REQUIRES(mutex
)
690 slave
->status
= LACP_EXPIRED
;
691 slave
->partner
.state
|= LACP_STATE_TIME
;
692 slave
->partner
.state
&= ~LACP_STATE_SYNC
;
694 timer_set_duration(&slave
->rx
, LACP_RX_MULTIPLIER
* LACP_FAST_TIME_TX
);
698 slave_get_actor(struct slave
*slave
, struct lacp_info
*actor
)
701 struct lacp
*lacp
= slave
->lacp
;
706 state
|= LACP_STATE_ACT
;
710 state
|= LACP_STATE_TIME
;
713 if (slave
->attached
) {
714 state
|= LACP_STATE_SYNC
;
717 if (slave
->status
== LACP_DEFAULTED
) {
718 state
|= LACP_STATE_DEF
;
721 if (slave
->status
== LACP_EXPIRED
) {
722 state
|= LACP_STATE_EXP
;
725 if (hmap_count(&lacp
->slaves
) > 1) {
726 state
|= LACP_STATE_AGG
;
729 if (slave
->attached
|| !lacp
->negotiated
) {
730 state
|= LACP_STATE_COL
| LACP_STATE_DIST
;
733 key
= lacp
->key_slave
->key
;
735 key
= lacp
->key_slave
->port_id
;
738 actor
->state
= state
;
739 actor
->key
= htons(key
);
740 actor
->port_priority
= htons(slave
->port_priority
);
741 actor
->port_id
= htons(slave
->port_id
);
742 actor
->sys_priority
= htons(lacp
->sys_priority
);
743 actor
->sys_id
= lacp
->sys_id
;
746 /* Given 'slave', populates 'priority' with data representing its LACP link
747 * priority. If two priority objects populated by this function are compared
748 * using memcmp, the higher priority link will be less than the lower priority
751 slave_get_priority(struct slave
*slave
, struct lacp_info
*priority
)
754 uint16_t partner_priority
, actor_priority
;
756 /* Choose the lacp_info of the higher priority system by comparing their
757 * system priorities and mac addresses. */
758 actor_priority
= slave
->lacp
->sys_priority
;
759 partner_priority
= ntohs(slave
->partner
.sys_priority
);
760 if (actor_priority
< partner_priority
) {
761 slave_get_actor(slave
, priority
);
762 } else if (partner_priority
< actor_priority
) {
763 *priority
= slave
->partner
;
764 } else if (eth_addr_compare_3way(slave
->lacp
->sys_id
,
765 slave
->partner
.sys_id
) < 0) {
766 slave_get_actor(slave
, priority
);
768 *priority
= slave
->partner
;
771 /* Key and state are not used in priority comparisons. */
777 slave_may_tx(const struct slave
*slave
) OVS_REQUIRES(mutex
)
779 return slave
->lacp
->active
|| slave
->status
!= LACP_DEFAULTED
;
782 static struct slave
*
783 slave_lookup(const struct lacp
*lacp
, const void *slave_
) OVS_REQUIRES(mutex
)
787 HMAP_FOR_EACH_IN_BUCKET (slave
, node
, hash_pointer(slave_
, 0),
789 if (slave
->aux
== slave_
) {
797 /* Two lacp_info structures are tx_equal if and only if they do not differ in
798 * ways which would require a lacp_pdu transmission. */
800 info_tx_equal(struct lacp_info
*a
, struct lacp_info
*b
)
803 /* LACP specification dictates that we transmit whenever the actor and
804 * remote_actor differ in the following fields: Port, Port Priority,
805 * System, System Priority, Aggregation Key, Activity State, Timeout State,
806 * Sync State, and Aggregation State. The state flags are most likely to
807 * change so are checked first. */
808 return !((a
->state
^ b
->state
) & (LACP_STATE_ACT
812 && a
->port_id
== b
->port_id
813 && a
->port_priority
== b
->port_priority
815 && a
->sys_priority
== b
->sys_priority
816 && eth_addr_equals(a
->sys_id
, b
->sys_id
);
820 lacp_find(const char *name
) OVS_REQUIRES(mutex
)
824 LIST_FOR_EACH (lacp
, node
, all_lacps
) {
825 if (!strcmp(lacp
->name
, name
)) {
834 ds_put_lacp_state(struct ds
*ds
, uint8_t state
)
836 if (state
& LACP_STATE_ACT
) {
837 ds_put_cstr(ds
, " activity");
840 if (state
& LACP_STATE_TIME
) {
841 ds_put_cstr(ds
, " timeout");
844 if (state
& LACP_STATE_AGG
) {
845 ds_put_cstr(ds
, " aggregation");
848 if (state
& LACP_STATE_SYNC
) {
849 ds_put_cstr(ds
, " synchronized");
852 if (state
& LACP_STATE_COL
) {
853 ds_put_cstr(ds
, " collecting");
856 if (state
& LACP_STATE_DIST
) {
857 ds_put_cstr(ds
, " distributing");
860 if (state
& LACP_STATE_DEF
) {
861 ds_put_cstr(ds
, " defaulted");
864 if (state
& LACP_STATE_EXP
) {
865 ds_put_cstr(ds
, " expired");
870 lacp_print_details(struct ds
*ds
, struct lacp
*lacp
) OVS_REQUIRES(mutex
)
872 struct shash slave_shash
= SHASH_INITIALIZER(&slave_shash
);
873 const struct shash_node
**sorted_slaves
= NULL
;
878 ds_put_format(ds
, "---- %s ----\n", lacp
->name
);
879 ds_put_format(ds
, "\tstatus: %s", lacp
->active
? "active" : "passive");
880 if (lacp
->negotiated
) {
881 ds_put_cstr(ds
, " negotiated");
883 ds_put_cstr(ds
, "\n");
885 ds_put_format(ds
, "\tsys_id: " ETH_ADDR_FMT
"\n", ETH_ADDR_ARGS(lacp
->sys_id
));
886 ds_put_format(ds
, "\tsys_priority: %u\n", lacp
->sys_priority
);
887 ds_put_cstr(ds
, "\taggregation key: ");
888 if (lacp
->key_slave
) {
889 ds_put_format(ds
, "%u", lacp
->key_slave
->key
890 ? lacp
->key_slave
->key
891 : lacp
->key_slave
->port_id
);
893 ds_put_cstr(ds
, "none");
895 ds_put_cstr(ds
, "\n");
897 ds_put_cstr(ds
, "\tlacp_time: ");
899 ds_put_cstr(ds
, "fast\n");
901 ds_put_cstr(ds
, "slow\n");
904 HMAP_FOR_EACH (slave
, node
, &lacp
->slaves
) {
905 shash_add(&slave_shash
, slave
->name
, slave
);
907 sorted_slaves
= shash_sort(&slave_shash
);
909 for (i
= 0; i
< shash_count(&slave_shash
); i
++) {
911 struct lacp_info actor
;
913 slave
= sorted_slaves
[i
]->data
;
914 slave_get_actor(slave
, &actor
);
915 switch (slave
->status
) {
923 status
= "defaulted";
929 ds_put_format(ds
, "\nslave: %s: %s %s\n", slave
->name
, status
,
930 slave
->attached
? "attached" : "detached");
931 ds_put_format(ds
, "\tport_id: %u\n", slave
->port_id
);
932 ds_put_format(ds
, "\tport_priority: %u\n", slave
->port_priority
);
933 ds_put_format(ds
, "\tmay_enable: %s\n", (slave_may_enable__(slave
)
934 ? "true" : "false"));
936 ds_put_format(ds
, "\n\tactor sys_id: " ETH_ADDR_FMT
"\n",
937 ETH_ADDR_ARGS(actor
.sys_id
));
938 ds_put_format(ds
, "\tactor sys_priority: %u\n",
939 ntohs(actor
.sys_priority
));
940 ds_put_format(ds
, "\tactor port_id: %u\n",
941 ntohs(actor
.port_id
));
942 ds_put_format(ds
, "\tactor port_priority: %u\n",
943 ntohs(actor
.port_priority
));
944 ds_put_format(ds
, "\tactor key: %u\n",
946 ds_put_cstr(ds
, "\tactor state:");
947 ds_put_lacp_state(ds
, actor
.state
);
948 ds_put_cstr(ds
, "\n\n");
950 ds_put_format(ds
, "\tpartner sys_id: " ETH_ADDR_FMT
"\n",
951 ETH_ADDR_ARGS(slave
->partner
.sys_id
));
952 ds_put_format(ds
, "\tpartner sys_priority: %u\n",
953 ntohs(slave
->partner
.sys_priority
));
954 ds_put_format(ds
, "\tpartner port_id: %u\n",
955 ntohs(slave
->partner
.port_id
));
956 ds_put_format(ds
, "\tpartner port_priority: %u\n",
957 ntohs(slave
->partner
.port_priority
));
958 ds_put_format(ds
, "\tpartner key: %u\n",
959 ntohs(slave
->partner
.key
));
960 ds_put_cstr(ds
, "\tpartner state:");
961 ds_put_lacp_state(ds
, slave
->partner
.state
);
962 ds_put_cstr(ds
, "\n");
965 shash_destroy(&slave_shash
);
970 lacp_unixctl_show(struct unixctl_conn
*conn
, int argc
, const char *argv
[],
971 void *aux OVS_UNUSED
) OVS_EXCLUDED(mutex
)
973 struct ds ds
= DS_EMPTY_INITIALIZER
;
978 lacp
= lacp_find(argv
[1]);
980 unixctl_command_reply_error(conn
, "no such lacp object");
983 lacp_print_details(&ds
, lacp
);
985 LIST_FOR_EACH (lacp
, node
, all_lacps
) {
986 lacp_print_details(&ds
, lacp
);
990 unixctl_command_reply(conn
, ds_cstr(&ds
));
997 /* Extract a snapshot of the current state and counters for a slave port.
998 Return false if the slave is not active. */
1000 lacp_get_slave_stats(const struct lacp
*lacp
, const void *slave_
, struct lacp_slave_stats
*stats
)
1003 struct slave
*slave
;
1004 struct lacp_info actor
;
1007 ovs_mutex_lock(&mutex
);
1009 slave
= slave_lookup(lacp
, slave_
);
1012 slave_get_actor(slave
, &actor
);
1013 stats
->dot3adAggPortActorSystemID
= actor
.sys_id
;
1014 stats
->dot3adAggPortPartnerOperSystemID
= slave
->partner
.sys_id
;
1015 stats
->dot3adAggPortAttachedAggID
= (lacp
->key_slave
->key
?
1016 lacp
->key_slave
->key
:
1017 lacp
->key_slave
->port_id
);
1019 /* Construct my admin-state. Assume aggregation is configured on. */
1020 stats
->dot3adAggPortActorAdminState
= LACP_STATE_AGG
;
1022 stats
->dot3adAggPortActorAdminState
|= LACP_STATE_ACT
;
1025 stats
->dot3adAggPortActorAdminState
|= LACP_STATE_TIME
;
1027 /* XXX Not sure how to know the partner admin state. It
1028 * might have to be captured and remembered during the
1029 * negotiation phase.
1031 stats
->dot3adAggPortPartnerAdminState
= 0;
1033 stats
->dot3adAggPortActorOperState
= actor
.state
;
1034 stats
->dot3adAggPortPartnerOperState
= slave
->partner
.state
;
1036 /* Read out the latest counters */
1037 stats
->dot3adAggPortStatsLACPDUsRx
= slave
->count_rx_pdus
;
1038 stats
->dot3adAggPortStatsIllegalRx
= slave
->count_rx_pdus_bad
;
1039 stats
->dot3adAggPortStatsLACPDUsTx
= slave
->count_tx_pdus
;
1043 ovs_mutex_unlock(&mutex
);