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