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