cfm: Don't report unexpected remote endpoints.
[sliver-openvswitch.git] / lib / cfm.h
1 /*
2  * Copyright (c) 2010 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 #ifndef CFM_H
18 #define CFM_H 1
19
20 #include <stdint.h>
21
22 #include "hmap.h"
23 #include "openvswitch/types.h"
24
25 struct flow;
26 struct ofpbuf;
27
28 /* Ethernet destination address of CCM packets. */
29 static const uint8_t eth_addr_ccm[6] OVS_UNUSED
30     = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x30 };
31
32 #define ETH_TYPE_CFM 0x8902
33
34 /* A 'ccm' represents a Continuity Check Message from the 802.1ag
35  * specification.  Continuity Check Messages are broadcast periodically so that
36  * hosts can determine who they have connectivity to. */
37 #define CCM_LEN 74
38 #define CCM_MAID_LEN 48
39 struct ccm {
40     uint8_t  mdlevel_version; /* MD Level and Version */
41     uint8_t  opcode;
42     uint8_t  flags;
43     uint8_t  tlv_offset;
44     ovs_be32 seq;
45     ovs_be16 mpid;
46     uint8_t  maid[CCM_MAID_LEN];
47     uint8_t  zero[16]; /* Defined by ITU-T Y.1731 should be zero */
48 } __attribute__((packed));
49 BUILD_ASSERT_DECL(CCM_LEN == sizeof(struct ccm));
50
51 /* A 'cfm' represent a local Maintenance Point (MP) and its Connectivity Fault
52  * Management (CFM) state machine.  Its configuration variables should be set
53  * by clients of the CFM library. */
54 struct cfm {
55     /* Configuration Variables. */
56     uint16_t mpid;              /* The MPID of this CFM. */
57     uint8_t maid[CCM_MAID_LEN]; /* The MAID of this CFM. */
58     int interval;               /* The requested transmission interval. */
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     long long recv_time; /* Time the most recent CCM was received. */
72     bool fault;          /* Indicates a connectivity fault. */
73 };
74
75 /* Remote MAIDs keep track of incoming CCM messages which have a different MAID
76  * than this CFM instance. */
77 struct remote_maid {
78     uint8_t maid[CCM_MAID_LEN]; /* The remote MAID. */
79     struct hmap_node node;      /* In 'cfm' 'x_remote_maids'. */
80
81     long long recv_time; /* Most recent receive time for this 'remote_maid'. */
82 };
83
84 struct cfm *cfm_create(void);
85
86 void cfm_destroy(struct cfm *);
87
88 void cfm_run(struct cfm *);
89
90 bool cfm_should_send_ccm(struct cfm *);
91
92 void cfm_compose_ccm(struct cfm *, struct ccm *);
93
94 void cfm_wait(struct cfm *);
95
96 bool cfm_configure(struct cfm *);
97
98 void cfm_update_remote_mps(struct cfm *, const uint16_t *mpid, size_t n_mpids);
99
100 const struct remote_mp *cfm_get_remote_mp(const struct cfm *, uint16_t mpid);
101
102 bool cfm_generate_maid(const char *md_name, const char *ma_name,
103                        uint8_t maid[CCM_MAID_LEN]);
104
105 bool cfm_should_process_flow(const struct flow *);
106
107 void cfm_process_heartbeat(struct cfm *, const struct ofpbuf *packet);
108
109 #endif /* cfm.h */