lacp: New other_config setting "lacp-force-aggregatable".
[sliver-openvswitch.git] / lib / lacp.c
1 /* Copyright (c) 2011 Nicira Networks
2  *
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:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
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.
14  */
15
16 #include <config.h>
17 #include "lacp.h"
18
19 #include <assert.h>
20 #include <stdlib.h>
21
22 #include "dynamic-string.h"
23 #include "hash.h"
24 #include "hmap.h"
25 #include "ofpbuf.h"
26 #include "packets.h"
27 #include "poll-loop.h"
28 #include "timer.h"
29 #include "timeval.h"
30 #include "unixctl.h"
31 #include "vlog.h"
32
33 VLOG_DEFINE_THIS_MODULE(lacp);
34
35 enum slave_status {
36     LACP_CURRENT,   /* Current State.  Partner up to date. */
37     LACP_EXPIRED,   /* Expired State.  Partner out of date. */
38     LACP_DEFAULTED, /* Defaulted State.  No partner. */
39 };
40
41 struct lacp {
42     struct list node;             /* Node in all_lacps list. */
43     char *name;                   /* Name of this lacp object. */
44     uint8_t sys_id[ETH_ADDR_LEN]; /* System ID. */
45     uint16_t sys_priority;        /* System Priority. */
46     bool active;                  /* Active or Passive. */
47
48     struct hmap slaves;      /* Slaves this LACP object controls. */
49     struct slave *key_slave; /* Slave whose ID will be the aggregation key. */
50
51     enum lacp_time lacp_time;  /* Fast, Slow or Custom LACP time. */
52     long long int custom_time; /* LACP_TIME_CUSTOM transmission rate. */
53     bool strict;             /* True if in strict mode. */
54     bool negotiated;         /* True if LACP negotiations were successful. */
55     bool update;             /* True if lacp_update() needs to be called. */
56     bool force_agg;          /* Forces LACP_STATE_AGG bit on all slaves. */
57 };
58
59 struct slave {
60     void *aux;                    /* Handle used to identify this slave. */
61     struct hmap_node node;        /* Node in master's slaves map. */
62
63     struct lacp *lacp;            /* LACP object containing this slave. */
64     uint16_t port_id;             /* Port ID. */
65     uint16_t port_priority;       /* Port Priority. */
66     char *name;                   /* Name of this slave. */
67
68     enum slave_status status;     /* Slave status. */
69     bool attached;                /* Attached. Traffic may flow. */
70     struct lacp_info partner;     /* Partner information. */
71     struct lacp_info ntt_actor;   /* Used to decide if we Need To Transmit. */
72     struct timer tx;              /* Next message transmission timer. */
73     struct timer rx;              /* Expected message receive timer. */
74 };
75
76 static struct list all_lacps = LIST_INITIALIZER(&all_lacps);
77
78 static void lacp_update_attached(struct lacp *);
79
80 static void slave_destroy(struct slave *);
81 static void slave_set_defaulted(struct slave *);
82 static void slave_set_expired(struct slave *);
83 static void slave_get_actor(struct slave *, struct lacp_info *actor);
84 static void slave_get_priority(struct slave *, struct lacp_info *priority);
85 static bool slave_may_tx(const struct slave *);
86 static struct slave *slave_lookup(const struct lacp *, const void *slave);
87 static bool info_tx_equal(struct lacp_info *, struct lacp_info *);
88
89 static void lacp_unixctl_show(struct unixctl_conn *, const char *args,
90                               void *aux);
91
92 /* Populates 'pdu' with a LACP PDU comprised of 'actor' and 'partner'. */
93 void
94 compose_lacp_pdu(const struct lacp_info *actor,
95                  const struct lacp_info *partner, struct lacp_pdu *pdu)
96 {
97     memset(pdu, 0, sizeof *pdu);
98
99     pdu->subtype = 1;
100     pdu->version = 1;
101
102     pdu->actor_type = 1;
103     pdu->actor_len = 20;
104     pdu->actor = *actor;
105
106     pdu->partner_type = 2;
107     pdu->partner_len = 20;
108     pdu->partner = *partner;
109
110     pdu->collector_type = 3;
111     pdu->collector_len = 16;
112     pdu->collector_delay = htons(0);
113 }
114
115 /* Parses 'b' which represents a packet containing a LACP PDU.  This function
116  * returns NULL if 'b' is malformed, or does not represent a LACP PDU format
117  * supported by OVS.  Otherwise, it returns a pointer to the lacp_pdu contained
118  * within 'b'. */
119 const struct lacp_pdu *
120 parse_lacp_packet(const struct ofpbuf *b)
121 {
122     const struct lacp_pdu *pdu;
123
124     pdu = ofpbuf_at(b, (uint8_t *)b->l3 - (uint8_t *)b->data, LACP_PDU_LEN);
125
126     if (pdu && pdu->subtype == 1
127         && pdu->actor_type == 1 && pdu->actor_len == 20
128         && pdu->partner_type == 2 && pdu->partner_len == 20) {
129         return pdu;
130     } else {
131         return NULL;
132     }
133 }
134 \f
135 /* LACP Protocol Implementation. */
136
137 /* Initializes the lacp module. */
138 void
139 lacp_init(void)
140 {
141     unixctl_command_register("lacp/show", lacp_unixctl_show, NULL);
142 }
143
144 /* Creates a LACP object. */
145 struct lacp *
146 lacp_create(void)
147 {
148     struct lacp *lacp;
149
150     lacp = xzalloc(sizeof *lacp);
151     hmap_init(&lacp->slaves);
152     list_push_back(&all_lacps, &lacp->node);
153     return lacp;
154 }
155
156 /* Destroys 'lacp' and its slaves. Does nothing if 'lacp' is NULL. */
157 void
158 lacp_destroy(struct lacp *lacp)
159 {
160     if (lacp) {
161         struct slave *slave, *next;
162
163         HMAP_FOR_EACH_SAFE (slave, next, node, &lacp->slaves) {
164             slave_destroy(slave);
165         }
166
167         hmap_destroy(&lacp->slaves);
168         list_remove(&lacp->node);
169         free(lacp->name);
170         free(lacp);
171     }
172 }
173
174 /* Configures 'lacp' with settings from 's'. */
175 void
176 lacp_configure(struct lacp *lacp, const struct lacp_settings *s)
177 {
178     if (!lacp->name || strcmp(s->name, lacp->name)) {
179         free(lacp->name);
180         lacp->name = xstrdup(s->name);
181     }
182
183     if (!eth_addr_equals(lacp->sys_id, s->id)
184         || lacp->sys_priority != s->priority
185         || lacp->strict != s->strict) {
186         memcpy(lacp->sys_id, s->id, ETH_ADDR_LEN);
187         lacp->sys_priority = s->priority;
188         lacp->strict = s->strict;
189         lacp->update = true;
190     }
191
192     lacp->active = s->active;
193     lacp->lacp_time = s->lacp_time;
194     lacp->force_agg = s->force_agg;
195     lacp->custom_time = MAX(TIME_UPDATE_INTERVAL, s->custom_time);
196 }
197
198 /* Returns true if 'lacp' is configured in active mode, false if 'lacp' is
199  * configured for passive mode. */
200 bool
201 lacp_is_active(const struct lacp *lacp)
202 {
203     return lacp->active;
204 }
205
206 /* Processes 'pdu', a parsed LACP packet received on 'slave_'.  This function
207  * should be called on all packets received on 'slave_' with Ethernet Type
208  * ETH_TYPE_LACP and parsable by parse_lacp_packet(). */
209 void
210 lacp_process_pdu(struct lacp *lacp, const void *slave_,
211                  const struct lacp_pdu *pdu)
212 {
213     struct slave *slave = slave_lookup(lacp, slave_);
214     long long int tx_rate;
215
216     switch (lacp->lacp_time) {
217     case LACP_TIME_FAST:
218         tx_rate = LACP_FAST_TIME_TX;
219         break;
220     case LACP_TIME_SLOW:
221         tx_rate = LACP_SLOW_TIME_TX;
222         break;
223     case LACP_TIME_CUSTOM:
224         tx_rate = lacp->custom_time;
225         break;
226     default: NOT_REACHED();
227     }
228
229     slave->status = LACP_CURRENT;
230     timer_set_duration(&slave->rx, LACP_RX_MULTIPLIER * tx_rate);
231
232     slave->ntt_actor = pdu->partner;
233
234     /* Update our information about our partner if it's out of date.  This may
235      * cause priorities to change so re-calculate attached status of all
236      * slaves.  */
237     if (memcmp(&slave->partner, &pdu->actor, sizeof pdu->actor)) {
238         lacp->update = true;
239         slave->partner = pdu->actor;
240     }
241 }
242
243 /* Returns true if 'lacp' has successfully negotiated with its partner.  False
244  * if 'lacp' is NULL. */
245 bool
246 lacp_negotiated(const struct lacp *lacp)
247 {
248     return lacp ? lacp->negotiated : false;
249 }
250
251 /* Registers 'slave_' as subordinate to 'lacp'.  This should be called at least
252  * once per slave in a LACP managed bond.  Should also be called whenever a
253  * slave's settings change. */
254 void
255 lacp_slave_register(struct lacp *lacp, void *slave_,
256                     const struct lacp_slave_settings *s)
257 {
258     struct slave *slave = slave_lookup(lacp, slave_);
259
260     if (!slave) {
261         slave = xzalloc(sizeof *slave);
262         slave->lacp = lacp;
263         slave->aux = slave_;
264         hmap_insert(&lacp->slaves, &slave->node, hash_pointer(slave_, 0));
265         slave_set_defaulted(slave);
266
267         if (!lacp->key_slave) {
268             lacp->key_slave = slave;
269         }
270     }
271
272     if (!slave->name || strcmp(s->name, slave->name)) {
273         free(slave->name);
274         slave->name = xstrdup(s->name);
275     }
276
277     if (slave->port_id != s->id || slave->port_priority != s->priority) {
278         slave->port_id = s->id;
279         slave->port_priority = s->priority;
280
281         lacp->update = true;
282
283         if (lacp->active || lacp->negotiated) {
284             slave_set_expired(slave);
285         }
286     }
287 }
288
289 /* Unregisters 'slave_' with 'lacp'.  */
290 void
291 lacp_slave_unregister(struct lacp *lacp, const void *slave_)
292 {
293     struct slave *slave = slave_lookup(lacp, slave_);
294
295     if (slave) {
296         slave_destroy(slave);
297         lacp->update = true;
298     }
299 }
300
301 /* This function should be called whenever the carrier status of 'slave_' has
302  * changed. */
303 void
304 lacp_slave_carrier_changed(const struct lacp *lacp, const void *slave_)
305 {
306     struct slave *slave = slave_lookup(lacp, slave_);
307
308     if (slave->status == LACP_CURRENT || slave->lacp->active) {
309         slave_set_expired(slave);
310     }
311 }
312
313 /* This function should be called before enabling 'slave_' to send or receive
314  * traffic.  If it returns false, 'slave_' should not enabled.  As a
315  * convenience, returns true if 'lacp' is NULL. */
316 bool
317 lacp_slave_may_enable(const struct lacp *lacp, const void *slave_)
318 {
319     if (lacp) {
320         struct slave *slave = slave_lookup(lacp, slave_);
321
322         /* The slave may be enabled if it's attached to an aggregator and its
323          * partner is synchronized.  The only exception is defaulted slaves.
324          * They are not required to have synchronized partners because they
325          * have no partners at all.  They will only be attached if negotiations
326          * failed on all slaves in the bond. */
327         return slave->attached && (slave->partner.state & LACP_STATE_SYNC
328                                    || slave->status == LACP_DEFAULTED);
329     } else {
330         return true;
331     }
332 }
333
334 /* Returns the port ID used for 'slave_' in LACP communications. */
335 uint16_t
336 lacp_slave_get_port_id(const struct lacp *lacp, const void *slave_)
337 {
338     struct slave *slave = slave_lookup(lacp, slave_);
339     return slave->port_id;
340 }
341
342 /* Returns true if partner information on 'slave_' is up to date.  'slave_'
343  * not being current, generally indicates a connectivity problem, or a
344  * misconfigured (or broken) partner. */
345 bool
346 lacp_slave_is_current(const struct lacp *lacp, const void *slave_)
347 {
348     return slave_lookup(lacp, slave_)->status == LACP_CURRENT;
349 }
350
351 /* This function should be called periodically to update 'lacp'. */
352 void
353 lacp_run(struct lacp *lacp, lacp_send_pdu *send_pdu)
354 {
355     struct slave *slave;
356
357     HMAP_FOR_EACH (slave, node, &lacp->slaves) {
358         if (timer_expired(&slave->rx)) {
359             if (slave->status == LACP_CURRENT) {
360                 slave_set_expired(slave);
361             } else if (slave->status == LACP_EXPIRED) {
362                 slave_set_defaulted(slave);
363             }
364         }
365     }
366
367     if (lacp->update) {
368         lacp_update_attached(lacp);
369     }
370
371     HMAP_FOR_EACH (slave, node, &lacp->slaves) {
372         struct lacp_pdu pdu;
373         struct lacp_info actor;
374
375         if (!slave_may_tx(slave)) {
376             continue;
377         }
378
379         slave_get_actor(slave, &actor);
380
381         if (timer_expired(&slave->tx)
382             || !info_tx_equal(&actor, &slave->ntt_actor)) {
383             long long int duration;
384
385             slave->ntt_actor = actor;
386             compose_lacp_pdu(&actor, &slave->partner, &pdu);
387             send_pdu(slave->aux, &pdu);
388
389             if (lacp->lacp_time == LACP_TIME_CUSTOM) {
390                 duration = lacp->custom_time;
391             } else {
392                 duration = (slave->partner.state & LACP_STATE_TIME
393                             ? LACP_FAST_TIME_TX
394                             : LACP_SLOW_TIME_TX);
395             }
396
397             timer_set_duration(&slave->tx, duration);
398         }
399     }
400 }
401
402 /* Causes poll_block() to wake up when lacp_run() needs to be called again. */
403 void
404 lacp_wait(struct lacp *lacp)
405 {
406     struct slave *slave;
407
408     HMAP_FOR_EACH (slave, node, &lacp->slaves) {
409         if (slave_may_tx(slave)) {
410             timer_wait(&slave->tx);
411         }
412
413         if (slave->status != LACP_DEFAULTED) {
414             timer_wait(&slave->rx);
415         }
416     }
417 }
418 \f
419 /* Static Helpers. */
420
421 /* Updates the attached status of all slaves controlled by 'lacp' and sets its
422  * negotiated parameter to true if any slaves are attachable. */
423 static void
424 lacp_update_attached(struct lacp *lacp)
425 {
426     struct slave *lead, *slave;
427     struct lacp_info lead_pri;
428     static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 10);
429
430     lacp->update = false;
431
432     lead = NULL;
433     HMAP_FOR_EACH (slave, node, &lacp->slaves) {
434         struct lacp_info pri;
435
436         slave->attached = true;
437
438         /* XXX: In the future allow users to configure the expected system ID.
439          * For now just special case loopback. */
440         if (eth_addr_equals(slave->partner.sys_id, slave->lacp->sys_id)) {
441             VLOG_WARN_RL(&rl, "slave %s: Loopback detected. Slave is "
442                          "connected to its own bond", slave->name);
443             slave->attached = false;
444             continue;
445         }
446
447         if (slave->status == LACP_DEFAULTED) {
448             continue;
449         }
450
451         slave_get_priority(slave, &pri);
452
453         if (!lead || memcmp(&pri, &lead_pri, sizeof pri) < 0) {
454             lead = slave;
455             lead_pri = pri;
456         }
457     }
458
459     lacp->negotiated = lead != NULL;
460
461     if (lead) {
462         HMAP_FOR_EACH (slave, node, &lacp->slaves) {
463             if (slave->status == LACP_DEFAULTED
464                 || lead->partner.key != slave->partner.key
465                 || !eth_addr_equals(lead->partner.sys_id,
466                                     slave->partner.sys_id)) {
467                 slave->attached = false;
468             }
469         }
470     } else if (lacp->strict) {
471         HMAP_FOR_EACH (slave, node, &lacp->slaves) {
472             slave->attached = false;
473         }
474     }
475 }
476
477 static void
478 slave_destroy(struct slave *slave)
479 {
480     if (slave) {
481         struct lacp *lacp = slave->lacp;
482
483         lacp->update = true;
484         hmap_remove(&lacp->slaves, &slave->node);
485
486         if (lacp->key_slave == slave) {
487             struct hmap_node *slave_node = hmap_first(&lacp->slaves);
488
489             if (slave_node) {
490                 lacp->key_slave = CONTAINER_OF(slave_node, struct slave, node);
491             } else {
492                 lacp->key_slave = NULL;
493             }
494         }
495
496         free(slave->name);
497         free(slave);
498     }
499 }
500
501 static void
502 slave_set_defaulted(struct slave *slave)
503 {
504     memset(&slave->partner, 0, sizeof slave->partner);
505
506     slave->lacp->update = true;
507     slave->status = LACP_DEFAULTED;
508 }
509
510 static void
511 slave_set_expired(struct slave *slave)
512 {
513     struct lacp *lacp = slave->lacp;
514
515     slave->status = LACP_EXPIRED;
516     slave->partner.state |= LACP_STATE_TIME;
517     slave->partner.state &= ~LACP_STATE_SYNC;
518
519     /* The spec says we should wait LACP_RX_MULTIPLIER * LACP_FAST_TIME_TX.
520      * This doesn't make sense when using custom times which can be much
521      * smaller than LACP_FAST_TIME. */
522     timer_set_duration(&slave->rx, (lacp->lacp_time == LACP_TIME_CUSTOM
523                                     ? lacp->custom_time
524                                     : LACP_RX_MULTIPLIER * LACP_FAST_TIME_TX));
525 }
526
527 static void
528 slave_get_actor(struct slave *slave, struct lacp_info *actor)
529 {
530     struct lacp *lacp = slave->lacp;
531     uint8_t state = 0;
532
533     if (lacp->active) {
534         state |= LACP_STATE_ACT;
535     }
536
537     if (lacp->lacp_time != LACP_TIME_SLOW) {
538         state |= LACP_STATE_TIME;
539     }
540
541     if (slave->attached) {
542         state |= LACP_STATE_SYNC;
543     }
544
545     if (slave->status == LACP_DEFAULTED) {
546         state |= LACP_STATE_DEF;
547     }
548
549     if (slave->status == LACP_EXPIRED) {
550         state |= LACP_STATE_EXP;
551     }
552
553     if (lacp->force_agg || hmap_count(&lacp->slaves) > 1) {
554         state |= LACP_STATE_AGG;
555     }
556
557     if (slave->attached || !lacp->negotiated) {
558         state |= LACP_STATE_COL | LACP_STATE_DIST;
559     }
560
561     actor->state = state;
562     actor->key = htons(lacp->key_slave->port_id);
563     actor->port_priority = htons(slave->port_priority);
564     actor->port_id = htons(slave->port_id);
565     actor->sys_priority = htons(lacp->sys_priority);
566     memcpy(&actor->sys_id, lacp->sys_id, ETH_ADDR_LEN);
567 }
568
569 /* Given 'slave', populates 'priority' with data representing its LACP link
570  * priority.  If two priority objects populated by this function are compared
571  * using memcmp, the higher priority link will be less than the lower priority
572  * link. */
573 static void
574 slave_get_priority(struct slave *slave, struct lacp_info *priority)
575 {
576     uint16_t partner_priority, actor_priority;
577
578     /* Choose the lacp_info of the higher priority system by comparing their
579      * system priorities and mac addresses. */
580     actor_priority = slave->lacp->sys_priority;
581     partner_priority = ntohs(slave->partner.sys_priority);
582     if (actor_priority < partner_priority) {
583         slave_get_actor(slave, priority);
584     } else if (partner_priority < actor_priority) {
585         *priority = slave->partner;
586     } else if (eth_addr_compare_3way(slave->lacp->sys_id,
587                                      slave->partner.sys_id) < 0) {
588         slave_get_actor(slave, priority);
589     } else {
590         *priority = slave->partner;
591     }
592
593     /* Key and state are not used in priority comparisons. */
594     priority->key = 0;
595     priority->state = 0;
596 }
597
598 static bool
599 slave_may_tx(const struct slave *slave)
600 {
601     return slave->lacp->active || slave->status != LACP_DEFAULTED;
602 }
603
604 static struct slave *
605 slave_lookup(const struct lacp *lacp, const void *slave_)
606 {
607     struct slave *slave;
608
609     HMAP_FOR_EACH_IN_BUCKET (slave, node, hash_pointer(slave_, 0),
610                              &lacp->slaves) {
611         if (slave->aux == slave_) {
612             return slave;
613         }
614     }
615
616     return NULL;
617 }
618
619 /* Two lacp_info structures are tx_equal if and only if they do not differ in
620  * ways which would require a lacp_pdu transmission. */
621 static bool
622 info_tx_equal(struct lacp_info *a, struct lacp_info *b)
623 {
624
625     /* LACP specification dictates that we transmit whenever the actor and
626      * remote_actor differ in the following fields: Port, Port Priority,
627      * System, System Priority, Aggregation Key, Activity State, Timeout State,
628      * Sync State, and Aggregation State. The state flags are most likely to
629      * change so are checked first. */
630     return !((a->state ^ b->state) & (LACP_STATE_ACT
631                                       | LACP_STATE_TIME
632                                       | LACP_STATE_SYNC
633                                       | LACP_STATE_AGG))
634         && a->port_id == b->port_id
635         && a->port_priority == b->port_priority
636         && a->key == b->key
637         && a->sys_priority == b->sys_priority
638         && eth_addr_equals(a->sys_id, b->sys_id);
639 }
640 \f
641 static struct lacp *
642 lacp_find(const char *name)
643 {
644     struct lacp *lacp;
645
646     LIST_FOR_EACH (lacp, node, &all_lacps) {
647         if (!strcmp(lacp->name, name)) {
648             return lacp;
649         }
650     }
651
652     return NULL;
653 }
654
655 static void
656 ds_put_lacp_state(struct ds *ds, uint8_t state)
657 {
658     if (state & LACP_STATE_ACT) {
659         ds_put_cstr(ds, "activity ");
660     }
661
662     if (state & LACP_STATE_TIME) {
663         ds_put_cstr(ds, "timeout ");
664     }
665
666     if (state & LACP_STATE_AGG) {
667         ds_put_cstr(ds, "aggregation ");
668     }
669
670     if (state & LACP_STATE_SYNC) {
671         ds_put_cstr(ds, "synchronized ");
672     }
673
674     if (state & LACP_STATE_COL) {
675         ds_put_cstr(ds, "collecting ");
676     }
677
678     if (state & LACP_STATE_DIST) {
679         ds_put_cstr(ds, "distributing ");
680     }
681
682     if (state & LACP_STATE_DEF) {
683         ds_put_cstr(ds, "defaulted ");
684     }
685
686     if (state & LACP_STATE_EXP) {
687         ds_put_cstr(ds, "expired ");
688     }
689 }
690
691 static void
692 lacp_unixctl_show(struct unixctl_conn *conn,
693                   const char *args, void *aux OVS_UNUSED)
694 {
695     struct ds ds = DS_EMPTY_INITIALIZER;
696     struct lacp *lacp;
697     struct slave *slave;
698
699     lacp = lacp_find(args);
700     if (!lacp) {
701         unixctl_command_reply(conn, 501, "no such lacp object");
702         return;
703     }
704
705     ds_put_format(&ds, "lacp: %s\n", lacp->name);
706
707     ds_put_format(&ds, "\tstatus: %s", lacp->active ? "active" : "passive");
708     if (lacp->strict) {
709         ds_put_cstr(&ds, " strict");
710     }
711     if (lacp->negotiated) {
712         ds_put_cstr(&ds, " negotiated");
713     }
714     ds_put_cstr(&ds, "\n");
715
716     ds_put_format(&ds, "\tsys_id: " ETH_ADDR_FMT "\n", ETH_ADDR_ARGS(lacp->sys_id));
717     ds_put_format(&ds, "\tsys_priority: %u\n", lacp->sys_priority);
718     ds_put_cstr(&ds, "\taggregation key: ");
719     if (lacp->key_slave) {
720         ds_put_format(&ds, "%u", lacp->key_slave->port_id);
721     } else {
722         ds_put_cstr(&ds, "none");
723     }
724     ds_put_cstr(&ds, "\n");
725
726     ds_put_cstr(&ds, "\tlacp_time: ");
727     switch (lacp->lacp_time) {
728     case LACP_TIME_FAST:
729         ds_put_cstr(&ds, "fast\n");
730         break;
731     case LACP_TIME_SLOW:
732         ds_put_cstr(&ds, "slow\n");
733         break;
734     case LACP_TIME_CUSTOM:
735         ds_put_format(&ds, "custom (%lld)\n", lacp->custom_time);
736         break;
737     default:
738         ds_put_cstr(&ds, "unknown\n");
739     }
740
741     HMAP_FOR_EACH (slave, node, &lacp->slaves) {
742         char *status;
743         struct lacp_info actor;
744
745         slave_get_actor(slave, &actor);
746         switch (slave->status) {
747         case LACP_CURRENT:
748             status = "current";
749             break;
750         case LACP_EXPIRED:
751             status = "expired";
752             break;
753         case LACP_DEFAULTED:
754             status = "defaulted";
755             break;
756         default:
757             NOT_REACHED();
758         }
759
760         ds_put_format(&ds, "\nslave: %s: %s %s\n", slave->name, status,
761                       slave->attached ? "attached" : "detached");
762         ds_put_format(&ds, "\tport_id: %u\n", slave->port_id);
763         ds_put_format(&ds, "\tport_priority: %u\n", slave->port_priority);
764
765         ds_put_format(&ds, "\n\tactor sys_id: " ETH_ADDR_FMT "\n",
766                       ETH_ADDR_ARGS(actor.sys_id));
767         ds_put_format(&ds, "\tactor sys_priority: %u\n",
768                       ntohs(actor.sys_priority));
769         ds_put_format(&ds, "\tactor port_id: %u\n",
770                       ntohs(actor.port_id));
771         ds_put_format(&ds, "\tactor port_priority: %u\n",
772                       ntohs(actor.port_priority));
773         ds_put_format(&ds, "\tactor key: %u\n",
774                       ntohs(actor.key));
775         ds_put_cstr(&ds, "\tactor state: ");
776         ds_put_lacp_state(&ds, actor.state);
777         ds_put_cstr(&ds, "\n\n");
778
779         ds_put_format(&ds, "\tpartner sys_id: " ETH_ADDR_FMT "\n",
780                       ETH_ADDR_ARGS(slave->partner.sys_id));
781         ds_put_format(&ds, "\tpartner sys_priority: %u\n",
782                       ntohs(slave->partner.sys_priority));
783         ds_put_format(&ds, "\tpartner port_id: %u\n",
784                       ntohs(slave->partner.port_id));
785         ds_put_format(&ds, "\tpartner port_priority: %u\n",
786                       ntohs(slave->partner.port_priority));
787         ds_put_format(&ds, "\tpartner key: %u\n",
788                       ntohs(slave->partner.key));
789         ds_put_cstr(&ds, "\tpartner state: ");
790         ds_put_lacp_state(&ds, slave->partner.state);
791         ds_put_cstr(&ds, "\n");
792     }
793
794     unixctl_command_reply(conn, 200, ds_cstr(&ds));
795     ds_destroy(&ds);
796 }