cfm: cfm_run() return ccm instead of packet.
[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 "packets.h"
24
25 struct flow;
26
27 /* Ethernet destination address of CCM packets. */
28 static const uint8_t eth_addr_ccm[ETH_ADDR_LEN] OVS_UNUSED
29     = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x30 };
30
31 /* A 'cfm' represent a local Maintenance Point (MP) and its Connectivity Fault
32  * Management (CFM) state machine.  Its configuration variables should be set
33  * by clients of the CFM library. */
34 struct cfm {
35     /* Configuration Variables. */
36     uint16_t mpid;              /* The MPID of this CFM. */
37     uint8_t maid[CCM_MAID_LEN]; /* The MAID of this CFM. */
38     int interval;               /* The requested transmission interval. */
39
40     /* Statistics. */
41     struct hmap remote_mps;     /* Expected remote MPs. */
42     struct hmap x_remote_mps;   /* Unexpected remote MPs. */
43     struct hmap x_remote_maids; /* Unexpected remote MAIDs. */
44     bool fault;                 /* Indicates connectivity vaults. */
45 };
46
47 /* Remote MPs represent foreign network entities that are configured to have
48  * the same MAID as this CFM instance. */
49 struct remote_mp {
50     uint16_t mpid;         /* The Maintenance Point ID of this 'remote_mp'. */
51     struct hmap_node node; /* In 'cfm' 'remote_mps' or 'x_remote_mps'. */
52
53     long long recv_time; /* Time the most recent CCM was received. */
54     bool fault;          /* Indicates a connectivity fault. */
55 };
56
57 /* Remote MAIDs keep track of incoming CCM messages which have a different MAID
58  * than this CFM instance. */
59 struct remote_maid {
60     uint8_t maid[CCM_MAID_LEN]; /* The remote MAID. */
61     struct hmap_node node;      /* In 'cfm' 'x_remote_maids'. */
62
63     long long recv_time; /* Most recent receive time for this 'remote_maid'. */
64 };
65
66 struct cfm *cfm_create(void);
67
68 void cfm_destroy(struct cfm *);
69
70 void cfm_run(struct cfm *);
71
72 bool cfm_should_send_ccm(struct cfm *);
73
74 void cfm_compose_ccm(struct cfm *, struct ccm *);
75
76 void cfm_wait(struct cfm *);
77
78 bool cfm_configure(struct cfm *);
79
80 void cfm_update_remote_mps(struct cfm *, const uint16_t *mpid, size_t n_mpids);
81
82 const struct remote_mp *cfm_get_remote_mp(const struct cfm *, uint16_t mpid);
83
84 bool cfm_generate_maid(const char *md_name, const char *ma_name,
85                        uint8_t maid[CCM_MAID_LEN]);
86
87 bool cfm_should_process_flow(const struct flow *);
88
89 void cfm_process_heartbeat(struct cfm *, const struct ofpbuf *packet);
90
91 #endif /* cfm.h */