cfm: Allow manual override of CFM fault status.
[cascardo/ovs.git] / lib / cfm.c
1 /*
2  * Copyright (c) 2010, 2011 Nicira Networks.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <config.h>
18 #include "cfm.h"
19
20 #include <assert.h>
21 #include <stdint.h>
22 #include <stdlib.h>
23 #include <string.h>
24
25 #include "byte-order.h"
26 #include "dynamic-string.h"
27 #include "flow.h"
28 #include "hash.h"
29 #include "hmap.h"
30 #include "ofpbuf.h"
31 #include "packets.h"
32 #include "poll-loop.h"
33 #include "timer.h"
34 #include "timeval.h"
35 #include "unixctl.h"
36 #include "vlog.h"
37
38 VLOG_DEFINE_THIS_MODULE(cfm);
39
40 #define CFM_MAX_RMPS 256
41
42 /* Ethernet destination address of CCM packets. */
43 static const uint8_t eth_addr_ccm[6] = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x30 };
44 static const uint8_t eth_addr_ccm_x[6] = {
45     0x01, 0x23, 0x20, 0x00, 0x00, 0x30
46 };
47
48 #define ETH_TYPE_CFM 0x8902
49
50 /* A 'ccm' represents a Continuity Check Message from the 802.1ag
51  * specification.  Continuity Check Messages are broadcast periodically so that
52  * hosts can determine whom they have connectivity to.
53  *
54  * The minimum length of a CCM as specified by IEEE 802.1ag is 75 bytes.
55  * Previous versions of Open vSwitch generated 74-byte CCM messages, so we
56  * accept such messages too. */
57 #define CCM_LEN 75
58 #define CCM_ACCEPT_LEN 74
59 #define CCM_MAID_LEN 48
60 #define CCM_OPCODE 1 /* CFM message opcode meaning CCM. */
61 #define CCM_RDI_MASK 0x80
62 struct ccm {
63     uint8_t  mdlevel_version; /* MD Level and Version */
64     uint8_t  opcode;
65     uint8_t  flags;
66     uint8_t  tlv_offset;
67     ovs_be32 seq;
68     ovs_be16 mpid;
69     uint8_t  maid[CCM_MAID_LEN];
70
71     /* Defined by ITU-T Y.1731 should be zero */
72     ovs_be16 interval_ms_x;      /* Transmission interval in ms. */
73     ovs_be64 mpid64;             /* MPID in extended mode. */
74     uint8_t opdown;              /* Operationally down. */
75     uint8_t  zero[5];
76
77     /* TLV space. */
78     uint8_t end_tlv;
79 } __attribute__((packed));
80 BUILD_ASSERT_DECL(CCM_LEN == sizeof(struct ccm));
81
82 struct cfm {
83     char *name;                 /* Name of this CFM object. */
84     struct hmap_node hmap_node; /* Node in all_cfms list. */
85
86     uint64_t mpid;
87     bool extended;         /* Extended mode. */
88     bool fault;            /* Indicates connectivity fault. */
89     bool unexpected_recv;  /* Received an unexpected CCM. */
90     bool opup;             /* Operational State. */
91     bool remote_opup;      /* Remote Operational State. */
92
93     int fault_override;    /* Manual override of 'fault' status.
94                               Ignored if negative. */
95
96     uint32_t seq;          /* The sequence number of our last CCM. */
97     uint8_t ccm_interval;  /* The CCM transmission interval. */
98     int ccm_interval_ms;   /* 'ccm_interval' in milliseconds. */
99     uint16_t ccm_vlan;     /* Vlan tag of CCM PDUs. */
100     uint8_t maid[CCM_MAID_LEN]; /* The MAID of this CFM. */
101
102     struct timer tx_timer;    /* Send CCM when expired. */
103     struct timer fault_timer; /* Check for faults when expired. */
104
105     struct hmap remote_mps;   /* Remote MPs. */
106
107     /* Result of cfm_get_remote_mpids(). Updated only during fault check to
108      * avoid flapping. */
109     uint64_t *rmps_array;     /* Cache of remote_mps. */
110     size_t rmps_array_len;    /* Number of rmps in 'rmps_array'. */
111 };
112
113 /* Remote MPs represent foreign network entities that are configured to have
114  * the same MAID as this CFM instance. */
115 struct remote_mp {
116     uint64_t mpid;         /* The Maintenance Point ID of this 'remote_mp'. */
117     struct hmap_node node; /* Node in 'remote_mps' map. */
118
119     bool recv;           /* CCM was received since last fault check. */
120     bool rdi;            /* Remote Defect Indicator. Indicates remote_mp isn't
121                             receiving CCMs that it's expecting to. */
122     bool opup;           /* Operational State. */
123     uint32_t seq;        /* Most recently received sequence number. */
124 };
125
126 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(20, 30);
127 static struct hmap all_cfms = HMAP_INITIALIZER(&all_cfms);
128
129 static unixctl_cb_func cfm_unixctl_show;
130 static unixctl_cb_func cfm_unixctl_set_fault;
131
132 static const uint8_t *
133 cfm_ccm_addr(const struct cfm *cfm)
134 {
135     return cfm->extended ? eth_addr_ccm_x : eth_addr_ccm;
136 }
137
138 static void
139 cfm_generate_maid(struct cfm *cfm)
140 {
141     const char *ovs_md_name = "ovs";
142     const char *ovs_ma_name = "ovs";
143     uint8_t *ma_p;
144     size_t md_len, ma_len;
145
146     memset(cfm->maid, 0, CCM_MAID_LEN);
147
148     md_len = strlen(ovs_md_name);
149     ma_len = strlen(ovs_ma_name);
150
151     assert(md_len && ma_len && md_len + ma_len + 4 <= CCM_MAID_LEN);
152
153     cfm->maid[0] = 4;                           /* MD name string format. */
154     cfm->maid[1] = md_len;                      /* MD name size. */
155     memcpy(&cfm->maid[2], ovs_md_name, md_len); /* MD name. */
156
157     ma_p = cfm->maid + 2 + md_len;
158     ma_p[0] = 2;                           /* MA name string format. */
159     ma_p[1] = ma_len;                      /* MA name size. */
160     memcpy(&ma_p[2], ovs_ma_name, ma_len); /* MA name. */
161 }
162
163 static int
164 ccm_interval_to_ms(uint8_t interval)
165 {
166     switch (interval) {
167     case 0:  NOT_REACHED(); /* Explicitly not supported by 802.1ag. */
168     case 1:  return 3;      /* Not recommended due to timer resolution. */
169     case 2:  return 10;     /* Not recommended due to timer resolution. */
170     case 3:  return 100;
171     case 4:  return 1000;
172     case 5:  return 10000;
173     case 6:  return 60000;
174     case 7:  return 600000;
175     default: NOT_REACHED(); /* Explicitly not supported by 802.1ag. */
176     }
177
178     NOT_REACHED();
179 }
180
181 static long long int
182 cfm_fault_interval(struct cfm *cfm)
183 {
184     /* According to the 802.1ag specification we should assume every other MP
185      * with the same MAID has the same transmission interval that we have.  If
186      * an MP has a different interval, cfm_process_heartbeat will register it
187      * as a fault (likely due to a configuration error).  Thus we can check all
188      * MPs at once making this quite a bit simpler.
189      *
190      * According to the specification we should check when (ccm_interval_ms *
191      * 3.5)ms have passed. */
192     return (cfm->ccm_interval_ms * 7) / 2;
193 }
194
195 static uint8_t
196 ms_to_ccm_interval(int interval_ms)
197 {
198     uint8_t i;
199
200     for (i = 7; i > 0; i--) {
201         if (ccm_interval_to_ms(i) <= interval_ms) {
202             return i;
203         }
204     }
205
206     return 1;
207 }
208
209 static uint32_t
210 hash_mpid(uint64_t mpid)
211 {
212     return hash_bytes(&mpid, sizeof mpid, 0);
213 }
214
215 static bool
216 cfm_is_valid_mpid(bool extended, uint64_t mpid)
217 {
218     /* 802.1ag specification requires MPIDs to be within the range [1, 8191].
219      * In extended mode we relax this requirement. */
220     return mpid >= 1 && (extended || mpid <= 8191);
221 }
222
223 static struct remote_mp *
224 lookup_remote_mp(const struct cfm *cfm, uint64_t mpid)
225 {
226     struct remote_mp *rmp;
227
228     HMAP_FOR_EACH_IN_BUCKET (rmp, node, hash_mpid(mpid), &cfm->remote_mps) {
229         if (rmp->mpid == mpid) {
230             return rmp;
231         }
232     }
233
234     return NULL;
235 }
236
237 void
238 cfm_init(void)
239 {
240     unixctl_command_register("cfm/show", "[interface]", 0, 1, cfm_unixctl_show,
241                              NULL);
242     unixctl_command_register("cfm/set-fault", "[interface] normal|false|true",
243                              1, 2, cfm_unixctl_set_fault, NULL);
244 }
245
246 /* Allocates a 'cfm' object called 'name'.  'cfm' should be initialized by
247  * cfm_configure() before use. */
248 struct cfm *
249 cfm_create(const char *name)
250 {
251     struct cfm *cfm;
252
253     cfm = xzalloc(sizeof *cfm);
254     cfm->name = xstrdup(name);
255     hmap_init(&cfm->remote_mps);
256     cfm_generate_maid(cfm);
257     hmap_insert(&all_cfms, &cfm->hmap_node, hash_string(cfm->name, 0));
258     cfm->remote_opup = true;
259     cfm->fault_override = -1;
260     return cfm;
261 }
262
263 void
264 cfm_destroy(struct cfm *cfm)
265 {
266     struct remote_mp *rmp, *rmp_next;
267
268     if (!cfm) {
269         return;
270     }
271
272     HMAP_FOR_EACH_SAFE (rmp, rmp_next, node, &cfm->remote_mps) {
273         hmap_remove(&cfm->remote_mps, &rmp->node);
274         free(rmp);
275     }
276
277     hmap_destroy(&cfm->remote_mps);
278     hmap_remove(&all_cfms, &cfm->hmap_node);
279     free(cfm->rmps_array);
280     free(cfm->name);
281     free(cfm);
282 }
283
284 /* Should be run periodically to update fault statistics messages. */
285 void
286 cfm_run(struct cfm *cfm)
287 {
288     if (timer_expired(&cfm->fault_timer)) {
289         long long int interval = cfm_fault_interval(cfm);
290         struct remote_mp *rmp, *rmp_next;
291         bool old_cfm_fault = cfm->fault;
292
293         cfm->fault = cfm->unexpected_recv;
294         cfm->unexpected_recv = false;
295
296         cfm->rmps_array_len = 0;
297         free(cfm->rmps_array);
298         cfm->rmps_array = xmalloc(hmap_count(&cfm->remote_mps) *
299                                   sizeof *cfm->rmps_array);
300
301         cfm->remote_opup = true;
302         HMAP_FOR_EACH_SAFE (rmp, rmp_next, node, &cfm->remote_mps) {
303
304             if (!rmp->recv) {
305                 VLOG_DBG("%s: no CCM from RMP %"PRIu64" in the last %lldms",
306                          cfm->name, rmp->mpid, interval);
307                 hmap_remove(&cfm->remote_mps, &rmp->node);
308                 free(rmp);
309             } else {
310                 rmp->recv = false;
311
312                 if (rmp->mpid == cfm->mpid) {
313                     VLOG_WARN_RL(&rl,"%s: received CCM with local MPID"
314                                  " %"PRIu64, cfm->name, rmp->mpid);
315                     cfm->fault = true;
316                 }
317
318                 if (rmp->rdi) {
319                     VLOG_DBG("%s: RDI bit flagged from RMP %"PRIu64, cfm->name,
320                              rmp->mpid);
321                     cfm->fault = true;
322                 }
323
324                 if (!rmp->opup) {
325                     cfm->remote_opup = rmp->opup;
326                 }
327
328                 cfm->rmps_array[cfm->rmps_array_len++] = rmp->mpid;
329             }
330         }
331
332         if (hmap_is_empty(&cfm->remote_mps)) {
333             cfm->fault = true;
334         }
335
336         if (old_cfm_fault != cfm->fault) {
337             VLOG_INFO_RL(&rl, "%s: CFM fault status changed to %s",
338                          cfm->name, cfm->fault ? "true" : "false");
339         }
340
341         timer_set_duration(&cfm->fault_timer, interval);
342     }
343 }
344
345 /* Should be run periodically to check if the CFM module has a CCM message it
346  * wishes to send. */
347 bool
348 cfm_should_send_ccm(struct cfm *cfm)
349 {
350     return timer_expired(&cfm->tx_timer);
351 }
352
353 /* Composes a CCM message into 'packet'.  Messages generated with this function
354  * should be sent whenever cfm_should_send_ccm() indicates. */
355 void
356 cfm_compose_ccm(struct cfm *cfm, struct ofpbuf *packet,
357                 uint8_t eth_src[ETH_ADDR_LEN])
358 {
359     struct ccm *ccm;
360
361     timer_set_duration(&cfm->tx_timer, cfm->ccm_interval_ms);
362     eth_compose(packet, cfm_ccm_addr(cfm), eth_src, ETH_TYPE_CFM, sizeof *ccm);
363
364     if (cfm->ccm_vlan) {
365         eth_push_vlan(packet, htons(cfm->ccm_vlan));
366     }
367
368     ccm = packet->l3;
369     ccm->mdlevel_version = 0;
370     ccm->opcode = CCM_OPCODE;
371     ccm->tlv_offset = 70;
372     ccm->seq = htonl(++cfm->seq);
373     ccm->flags = cfm->ccm_interval;
374     memcpy(ccm->maid, cfm->maid, sizeof ccm->maid);
375     memset(ccm->zero, 0, sizeof ccm->zero);
376     ccm->end_tlv = 0;
377
378     if (cfm->extended) {
379         ccm->mpid = htons(hash_mpid(cfm->mpid));
380         ccm->mpid64 = htonll(cfm->mpid);
381         ccm->opdown = !cfm->opup;
382     } else {
383         ccm->mpid = htons(cfm->mpid);
384         ccm->mpid64 = htonll(0);
385         ccm->opdown = 0;
386     }
387
388     if (cfm->ccm_interval == 0) {
389         assert(cfm->extended);
390         ccm->interval_ms_x = htons(cfm->ccm_interval_ms);
391     }
392
393     if (hmap_is_empty(&cfm->remote_mps)) {
394         ccm->flags |= CCM_RDI_MASK;
395     }
396 }
397
398 void
399 cfm_wait(struct cfm *cfm)
400 {
401     timer_wait(&cfm->tx_timer);
402     timer_wait(&cfm->fault_timer);
403 }
404
405 /* Configures 'cfm' with settings from 's'. */
406 bool
407 cfm_configure(struct cfm *cfm, const struct cfm_settings *s)
408 {
409     uint8_t interval;
410     int interval_ms;
411
412     if (!cfm_is_valid_mpid(s->extended, s->mpid) || s->interval <= 0) {
413         return false;
414     }
415
416     cfm->mpid = s->mpid;
417     cfm->extended = s->extended;
418     cfm->opup = s->opup;
419     interval = ms_to_ccm_interval(s->interval);
420     interval_ms = ccm_interval_to_ms(interval);
421
422     cfm->ccm_vlan = s->ccm_vlan & VLAN_VID_MASK;
423     if (cfm->extended && interval_ms != s->interval) {
424         interval = 0;
425         interval_ms = MIN(s->interval, UINT16_MAX);
426     }
427
428     if (interval != cfm->ccm_interval || interval_ms != cfm->ccm_interval_ms) {
429         cfm->ccm_interval = interval;
430         cfm->ccm_interval_ms = interval_ms;
431
432         timer_set_expired(&cfm->tx_timer);
433         timer_set_duration(&cfm->fault_timer, cfm_fault_interval(cfm));
434     }
435
436     return true;
437 }
438
439 /* Returns true if 'cfm' should process packets from 'flow'. */
440 bool
441 cfm_should_process_flow(const struct cfm *cfm, const struct flow *flow)
442 {
443     return (ntohs(flow->dl_type) == ETH_TYPE_CFM
444             && eth_addr_equals(flow->dl_dst, cfm_ccm_addr(cfm)));
445 }
446
447 /* Updates internal statistics relevant to packet 'p'.  Should be called on
448  * every packet whose flow returned true when passed to
449  * cfm_should_process_flow. */
450 void
451 cfm_process_heartbeat(struct cfm *cfm, const struct ofpbuf *p)
452 {
453     struct ccm *ccm;
454     struct eth_header *eth;
455
456     eth = p->l2;
457     ccm = ofpbuf_at(p, (uint8_t *)p->l3 - (uint8_t *)p->data, CCM_ACCEPT_LEN);
458
459     if (!ccm) {
460         VLOG_INFO_RL(&rl, "%s: Received an unparseable 802.1ag CCM heartbeat.",
461                      cfm->name);
462         return;
463     }
464
465     if (ccm->opcode != CCM_OPCODE) {
466         VLOG_INFO_RL(&rl, "%s: Received an unsupported 802.1ag message. "
467                      "(opcode %u)", cfm->name, ccm->opcode);
468         return;
469     }
470
471     /* According to the 802.1ag specification, reception of a CCM with an
472      * incorrect ccm_interval, unexpected MAID, or unexpected MPID should
473      * trigger a fault.  We ignore this requirement for several reasons.
474      *
475      * Faults can cause a controller or Open vSwitch to make potentially
476      * expensive changes to the network topology.  It seems prudent to trigger
477      * them judiciously, especially when CFM is used to check slave status of
478      * bonds. Furthermore, faults can be maliciously triggered by crafting
479      * invalid CCMs. */
480     if (memcmp(ccm->maid, cfm->maid, sizeof ccm->maid)) {
481         cfm->unexpected_recv = true;
482         VLOG_WARN_RL(&rl, "%s: Received unexpected remote MAID from MAC "
483                      ETH_ADDR_FMT, cfm->name, ETH_ADDR_ARGS(eth->eth_src));
484     } else {
485         uint8_t ccm_interval = ccm->flags & 0x7;
486         bool ccm_rdi = ccm->flags & CCM_RDI_MASK;
487         uint16_t ccm_interval_ms_x = ntohs(ccm->interval_ms_x);
488
489         struct remote_mp *rmp;
490         uint64_t ccm_mpid;
491         uint32_t ccm_seq;
492         bool ccm_opdown;
493
494         if (cfm->extended) {
495             ccm_mpid = ntohll(ccm->mpid64);
496             ccm_opdown = ccm->opdown;
497         } else {
498             ccm_mpid = ntohs(ccm->mpid);
499             ccm_opdown = false;
500         }
501         ccm_seq = ntohl(ccm->seq);
502
503         if (ccm_interval != cfm->ccm_interval) {
504             VLOG_WARN_RL(&rl, "%s: received a CCM with an invalid interval"
505                          " (%"PRIu8") from RMP %"PRIu64, cfm->name,
506                          ccm_interval, ccm_mpid);
507         }
508
509         if (cfm->extended && ccm_interval == 0
510             && ccm_interval_ms_x != cfm->ccm_interval_ms) {
511             VLOG_WARN_RL(&rl, "%s: received a CCM with an invalid extended"
512                          " interval (%"PRIu16"ms) from RMP %"PRIu64, cfm->name,
513                          ccm_interval_ms_x, ccm_mpid);
514         }
515
516         rmp = lookup_remote_mp(cfm, ccm_mpid);
517         if (!rmp) {
518             if (hmap_count(&cfm->remote_mps) < CFM_MAX_RMPS) {
519                 rmp = xzalloc(sizeof *rmp);
520                 hmap_insert(&cfm->remote_mps, &rmp->node, hash_mpid(ccm_mpid));
521             } else {
522                 cfm->unexpected_recv = true;
523                 VLOG_WARN_RL(&rl,
524                              "%s: dropped CCM with MPID %"PRIu64" from MAC "
525                              ETH_ADDR_FMT, cfm->name, ccm_mpid,
526                              ETH_ADDR_ARGS(eth->eth_src));
527             }
528         }
529
530         VLOG_DBG("%s: received CCM (seq %"PRIu32") (mpid %"PRIu64")"
531                  " (interval %"PRIu8") (RDI %s)", cfm->name, ccm_seq,
532                  ccm_mpid, ccm_interval, ccm_rdi ? "true" : "false");
533
534         if (rmp) {
535             if (rmp->seq && ccm_seq != (rmp->seq + 1)) {
536                 VLOG_WARN_RL(&rl, "%s: (mpid %"PRIu64") detected sequence"
537                              " numbers which indicate possible connectivity"
538                              " problems (previous %"PRIu32") (current %"PRIu32
539                              ")", cfm->name, ccm_mpid, rmp->seq, ccm_seq);
540             }
541
542             rmp->mpid = ccm_mpid;
543             rmp->recv = true;
544             rmp->seq = ccm_seq;
545             rmp->rdi = ccm_rdi;
546             rmp->opup = !ccm_opdown;
547         }
548     }
549 }
550
551 /* Gets the fault status of 'cfm'.  Returns true when 'cfm' has detected
552  * connectivity problems, false otherwise. */
553 bool
554 cfm_get_fault(const struct cfm *cfm)
555 {
556     if (cfm->fault_override >= 0) {
557         return cfm->fault_override;
558     }
559     return cfm->fault;
560 }
561
562 /* Gets the operational state of 'cfm'.  'cfm' is considered operationally down
563  * if it has received a CCM with the operationally down bit set from any of its
564  * remote maintenance points. Returns true if 'cfm' is operationally up. False
565  * otherwise. */
566 bool
567 cfm_get_opup(const struct cfm *cfm)
568 {
569     return cfm->remote_opup;
570 }
571
572 /* Populates 'rmps' with an array of remote maintenance points reachable by
573  * 'cfm'. The number of remote maintenance points is written to 'n_rmps'.
574  * 'cfm' retains ownership of the array written to 'rmps' */
575 void
576 cfm_get_remote_mpids(const struct cfm *cfm, const uint64_t **rmps,
577                      size_t *n_rmps)
578 {
579     *rmps = cfm->rmps_array;
580     *n_rmps = cfm->rmps_array_len;
581 }
582
583 static struct cfm *
584 cfm_find(const char *name)
585 {
586     struct cfm *cfm;
587
588     HMAP_FOR_EACH_WITH_HASH (cfm, hmap_node, hash_string(name, 0), &all_cfms) {
589         if (!strcmp(cfm->name, name)) {
590             return cfm;
591         }
592     }
593     return NULL;
594 }
595
596 static void
597 cfm_print_details(struct ds *ds, const struct cfm *cfm)
598 {
599     struct remote_mp *rmp;
600
601     ds_put_format(ds, "---- %s ----\n", cfm->name);
602     ds_put_format(ds, "MPID %"PRIu64":%s%s%s%s\n", cfm->mpid,
603                   cfm->extended ? " extended" : "",
604                   cfm_get_fault(cfm) ? " fault" : "",
605                   cfm->fault_override >= 0 ? " fault_override" : "",
606                   cfm->unexpected_recv ? " unexpected_recv" : "");
607
608     ds_put_format(ds, "\topstate: %s\n", cfm->opup ? "up" : "down");
609     ds_put_format(ds, "\tremote_opstate: %s\n",
610                   cfm->remote_opup ? "up" : "down");
611     ds_put_format(ds, "\tinterval: %dms\n", cfm->ccm_interval_ms);
612     ds_put_format(ds, "\tnext CCM tx: %lldms\n",
613                   timer_msecs_until_expired(&cfm->tx_timer));
614     ds_put_format(ds, "\tnext fault check: %lldms\n",
615                   timer_msecs_until_expired(&cfm->fault_timer));
616
617     HMAP_FOR_EACH (rmp, node, &cfm->remote_mps) {
618         ds_put_format(ds, "Remote MPID %"PRIu64":%s\n",
619                       rmp->mpid,
620                       rmp->rdi ? " rdi" : "");
621         ds_put_format(ds, "\trecv since check: %s\n",
622                       rmp->recv ? "true" : "false");
623         ds_put_format(ds, "\topstate: %s\n", rmp->opup? "up" : "down");
624     }
625 }
626
627 static void
628 cfm_unixctl_show(struct unixctl_conn *conn, int argc, const char *argv[],
629                  void *aux OVS_UNUSED)
630 {
631     struct ds ds = DS_EMPTY_INITIALIZER;
632     const struct cfm *cfm;
633
634     if (argc > 1) {
635         cfm = cfm_find(argv[1]);
636         if (!cfm) {
637             unixctl_command_reply(conn, 501, "no such CFM object");
638             return;
639         }
640         cfm_print_details(&ds, cfm);
641     } else {
642         HMAP_FOR_EACH (cfm, hmap_node, &all_cfms) {
643             cfm_print_details(&ds, cfm);
644         }
645     }
646
647     unixctl_command_reply(conn, 200, ds_cstr(&ds));
648     ds_destroy(&ds);
649 }
650
651 static void
652 cfm_unixctl_set_fault(struct unixctl_conn *conn, int argc, const char *argv[],
653                       void *aux OVS_UNUSED)
654 {
655     const char *fault_str = argv[argc - 1];
656     int fault_override;
657     struct cfm *cfm;
658
659     if (!strcasecmp("true", fault_str)) {
660         fault_override = 1;
661     } else if (!strcasecmp("false", fault_str)) {
662         fault_override = 0;
663     } else if (!strcasecmp("normal", fault_str)) {
664         fault_override = -1;
665     } else {
666         unixctl_command_reply(conn, 501, "unknown fault string");
667         return;
668     }
669
670     if (argc > 2) {
671         cfm = cfm_find(argv[1]);
672         if (!cfm) {
673             unixctl_command_reply(conn, 501, "no such CFM object");
674             return;
675         }
676         cfm->fault_override = fault_override;
677     } else {
678         HMAP_FOR_EACH (cfm, hmap_node, &all_cfms) {
679             cfm->fault_override = fault_override;
680         }
681     }
682
683     unixctl_command_reply(conn, 200, "OK");
684 }