datapath-windows: Rename switch context's nameHashArray and vport's nameLink login...
[cascardo/ovs.git] / lib / cfm.h
1 /* Copyright (c) 2010, 2011 Nicira, Inc.
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 struct netdev;
27 struct flow_wildcards;
28
29 #define CFM_RANDOM_VLAN UINT16_MAX
30
31 #define CFM_FAULT_REASONS                  \
32     CFM_FAULT_REASON(RECV, recv)           \
33     CFM_FAULT_REASON(RDI, rdi)             \
34     CFM_FAULT_REASON(MAID, maid)           \
35     CFM_FAULT_REASON(LOOPBACK, loopback)   \
36     CFM_FAULT_REASON(OVERFLOW, overflow)   \
37     CFM_FAULT_REASON(OVERRIDE, override)
38
39 enum cfm_fault_bit_index {
40 #define CFM_FAULT_REASON(NAME, STR) CFM_FAULT_INDEX_##NAME,
41     CFM_FAULT_REASONS
42 #undef CFM_FAULT_REASON
43     CFM_FAULT_N_REASONS
44 };
45
46 enum cfm_fault_reason {
47 #define CFM_FAULT_REASON(NAME, STR) \
48     CFM_FAULT_##NAME = 1 << CFM_FAULT_INDEX_##NAME,
49     CFM_FAULT_REASONS
50 #undef CFM_FAULT_REASON
51 };
52
53 struct cfm_settings {
54     uint64_t mpid;              /* The MPID of this CFM. */
55     int interval;               /* The requested transmission interval. */
56     bool extended;              /* Run in extended mode. */
57     bool demand;                /* Run in demand mode. */
58     bool opup;                  /* Operational State. */
59     uint16_t ccm_vlan;          /* CCM Vlan tag. Zero if none.
60                                    CFM_RANDOM_VLAN if random. */
61     uint8_t ccm_pcp;            /* CCM Priority. Zero if none. */
62
63     bool check_tnl_key;         /* Verify inbound packet key? */
64 };
65
66 /* CFM status query. */
67 struct cfm_status {
68     /* 0 if not faulted, otherwise a combination of one or more reasons. */
69     enum cfm_fault_reason faults;
70
71     /* 0 if the remote CFM endpoint is operationally down,
72      * 1 if the remote CFM endpoint is operationally up,
73      * -1 if we don't know because the remote CFM endpoint is not in extended
74      * mode. */
75     int remote_opstate;
76
77     uint64_t flap_count;
78
79     /* Ordinarily a "health status" in the range 0...100 inclusive, with 0
80      * being worst and 100 being best, or -1 if the health status is not
81      * well-defined. */
82     int health;
83
84     /* MPIDs of remote maintenance points whose CCMs have been received. */
85     uint64_t *rmps;
86     size_t n_rmps;
87 };
88
89 void cfm_init(void);
90 struct cfm *cfm_create(const struct netdev *);
91 struct cfm *cfm_ref(const struct cfm *);
92 void cfm_unref(struct cfm *);
93 void cfm_run(struct cfm *);
94 bool cfm_should_send_ccm(struct cfm *);
95 void cfm_compose_ccm(struct cfm *, struct ofpbuf *packet, uint8_t eth_src[6]);
96 void cfm_wait(struct cfm *);
97 bool cfm_configure(struct cfm *, const struct cfm_settings *);
98 void cfm_set_netdev(struct cfm *, const struct netdev *);
99 bool cfm_should_process_flow(const struct cfm *cfm, const struct flow *,
100                              struct flow_wildcards *);
101 void cfm_process_heartbeat(struct cfm *, const struct ofpbuf *packet);
102 bool cfm_check_status_change(struct cfm *);
103 int cfm_get_fault(const struct cfm *);
104 uint64_t cfm_get_flap_count(const struct cfm *);
105 int cfm_get_health(const struct cfm *);
106 int cfm_get_opup(const struct cfm *);
107 void cfm_get_remote_mpids(const struct cfm *, uint64_t **rmps, size_t *n_rmps);
108 void cfm_get_status(const struct cfm *, struct cfm_status *);
109 const char *cfm_fault_reason_to_str(int fault);
110
111 long long int cfm_wake_time(struct cfm*);
112 #endif /* cfm.h */