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