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