cfm: Migrate cfm/show unixctl command to CFM module.
[sliver-openvswitch.git] / lib / cfm.h
1 /* Copyright (c) 2010, 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 #ifndef CFM_H
17 #define CFM_H 1
18
19 #include <stdint.h>
20
21 #include "hmap.h"
22 #include "openvswitch/types.h"
23
24 struct flow;
25 struct ofpbuf;
26
27 /* Ethernet destination address of CCM packets. */
28 static const uint8_t eth_addr_ccm[6] OVS_UNUSED
29     = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x30 };
30
31 #define ETH_TYPE_CFM 0x8902
32
33 /* A 'ccm' represents a Continuity Check Message from the 802.1ag
34  * specification.  Continuity Check Messages are broadcast periodically so that
35  * hosts can determine who they have connectivity to. */
36 #define CCM_LEN 74
37 #define CCM_MAID_LEN 48
38 struct ccm {
39     uint8_t  mdlevel_version; /* MD Level and Version */
40     uint8_t  opcode;
41     uint8_t  flags;
42     uint8_t  tlv_offset;
43     ovs_be32 seq;
44     ovs_be16 mpid;
45     uint8_t  maid[CCM_MAID_LEN];
46     uint8_t  zero[16]; /* Defined by ITU-T Y.1731 should be zero */
47 } __attribute__((packed));
48 BUILD_ASSERT_DECL(CCM_LEN == sizeof(struct ccm));
49
50 /* A 'cfm' represent a local Maintenance Point (MP) and its Connectivity Fault
51  * Management (CFM) state machine.  Its configuration variables should be set
52  * by clients of the CFM library. */
53 struct cfm {
54     /* Configuration Variables. */
55     uint16_t mpid;              /* The MPID of this CFM. */
56     uint8_t maid[CCM_MAID_LEN]; /* The MAID of this CFM. */
57     int interval;               /* The requested transmission interval. */
58     const char *name;           /* Name of this CFM object. */
59
60     /* Statistics. */
61     struct hmap remote_mps;     /* Expected remote MPs. */
62     bool fault;                 /* Indicates connectivity vaults. */
63 };
64
65 /* Remote MPs represent foreign network entities that are configured to have
66  * the same MAID as this CFM instance. */
67 struct remote_mp {
68     uint16_t mpid;         /* The Maintenance Point ID of this 'remote_mp'. */
69     struct hmap_node node; /* In 'cfm' 'remote_mps' or 'x_remote_mps'. */
70
71     bool recv;           /* CCM was received since last fault check. */
72     bool fault;          /* Indicates a connectivity fault. */
73 };
74
75 void cfm_init(void);
76
77 struct cfm *cfm_create(void);
78
79 void cfm_destroy(struct cfm *);
80
81 void cfm_run(struct cfm *);
82
83 bool cfm_should_send_ccm(struct cfm *);
84
85 void cfm_compose_ccm(struct cfm *, struct ccm *);
86
87 void cfm_wait(struct cfm *);
88
89 bool cfm_configure(struct cfm *);
90
91 void cfm_update_remote_mps(struct cfm *, const uint16_t *mpid, size_t n_mpids);
92
93 const struct remote_mp *cfm_get_remote_mp(const struct cfm *, uint16_t mpid);
94
95 bool cfm_generate_maid(const char *md_name, const char *ma_name,
96                        uint8_t maid[CCM_MAID_LEN]);
97
98 bool cfm_should_process_flow(const struct flow *);
99
100 void cfm_process_heartbeat(struct cfm *, const struct ofpbuf *packet);
101
102 #endif /* cfm.h */