ofproto: Fix remaining incorrect users of OVSP_LOCAL.
[cascardo/ovs.git] / ofproto / connmgr.h
1 /*
2  * Copyright (c) 2009, 2010, 2011, 2012 Nicira, Inc.
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 CONNMGR_H
18 #define CONNMGR_H 1
19
20 #include "classifier.h"
21 #include "hmap.h"
22 #include "list.h"
23 #include "match.h"
24 #include "ofp-errors.h"
25 #include "ofproto.h"
26 #include "openflow/nicira-ext.h"
27 #include "openvswitch/types.h"
28
29 struct nlattr;
30 struct ofconn;
31 struct ofopgroup;
32 struct ofputil_flow_removed;
33 struct ofputil_packet_in;
34 struct ofputil_phy_port;
35 struct rule;
36 struct simap;
37 struct sset;
38
39 /* ofproto supports two kinds of OpenFlow connections:
40  *
41  *   - "Primary" connections to ordinary OpenFlow controllers.  ofproto
42  *     maintains persistent connections to these controllers and by default
43  *     sends them asynchronous messages such as packet-ins.
44  *
45  *   - "Service" connections, e.g. from ovs-ofctl.  When these connections
46  *     drop, it is the other side's responsibility to reconnect them if
47  *     necessary.  ofproto does not send them asynchronous messages by default.
48  *
49  * Currently, active (tcp, ssl, unix) connections are always "primary"
50  * connections and passive (ptcp, pssl, punix) connections are always "service"
51  * connections.  There is no inherent reason for this, but it reflects the
52  * common case.
53  */
54 enum ofconn_type {
55     OFCONN_PRIMARY,             /* An ordinary OpenFlow controller. */
56     OFCONN_SERVICE              /* A service connection, e.g. "ovs-ofctl". */
57 };
58
59 /* The type of an OpenFlow asynchronous message. */
60 enum ofconn_async_msg_type {
61     OAM_PACKET_IN,              /* OFPT_PACKET_IN or NXT_PACKET_IN. */
62     OAM_PORT_STATUS,            /* OFPT_PORT_STATUS. */
63     OAM_FLOW_REMOVED,           /* OFPT_FLOW_REMOVED or NXT_FLOW_REMOVED. */
64     OAM_N_TYPES
65 };
66
67 /* Basics. */
68 struct connmgr *connmgr_create(struct ofproto *ofproto,
69                                const char *dpif_name, const char *local_name);
70 void connmgr_destroy(struct connmgr *);
71
72 void connmgr_run(struct connmgr *,
73                  bool (*handle_openflow)(struct ofconn *,
74                                          struct ofpbuf *ofp_msg));
75 void connmgr_wait(struct connmgr *, bool handling_openflow);
76
77 void connmgr_get_memory_usage(const struct connmgr *, struct simap *usage);
78
79 struct ofproto *ofconn_get_ofproto(const struct ofconn *);
80
81 void connmgr_retry(struct connmgr *);
82
83 /* OpenFlow configuration. */
84 bool connmgr_has_controllers(const struct connmgr *);
85 void connmgr_get_controller_info(struct connmgr *, struct shash *);
86 void connmgr_free_controller_info(struct shash *);
87 void connmgr_set_controllers(struct connmgr *,
88                              const struct ofproto_controller[], size_t n,
89                              uint32_t allowed_versions);
90 void connmgr_reconnect(const struct connmgr *);
91
92 int connmgr_set_snoops(struct connmgr *, const struct sset *snoops);
93 bool connmgr_has_snoops(const struct connmgr *);
94 void connmgr_get_snoops(const struct connmgr *, struct sset *snoops);
95
96 /* Individual connections to OpenFlow controllers. */
97 enum ofconn_type ofconn_get_type(const struct ofconn *);
98
99 bool ofconn_set_master_election_id(struct ofconn *, uint64_t);
100 enum nx_role ofconn_get_role(const struct ofconn *);
101 void ofconn_set_role(struct ofconn *, enum nx_role);
102
103 enum ofputil_protocol ofconn_get_protocol(const struct ofconn *);
104 void ofconn_set_protocol(struct ofconn *, enum ofputil_protocol);
105
106 enum nx_packet_in_format ofconn_get_packet_in_format(struct ofconn *);
107 void ofconn_set_packet_in_format(struct ofconn *, enum nx_packet_in_format);
108
109 void ofconn_set_controller_id(struct ofconn *, uint16_t controller_id);
110
111 void ofconn_set_invalid_ttl_to_controller(struct ofconn *, bool);
112 bool ofconn_get_invalid_ttl_to_controller(struct ofconn *);
113
114 int ofconn_get_miss_send_len(const struct ofconn *);
115 void ofconn_set_miss_send_len(struct ofconn *, int miss_send_len);
116
117 void ofconn_set_async_config(struct ofconn *,
118                              const uint32_t master_masks[OAM_N_TYPES],
119                              const uint32_t slave_masks[OAM_N_TYPES]);
120
121 void ofconn_send_reply(const struct ofconn *, struct ofpbuf *);
122 void ofconn_send_replies(const struct ofconn *, struct list *);
123 void ofconn_send_error(const struct ofconn *, const struct ofp_header *request,
124                        enum ofperr);
125
126 enum ofperr ofconn_pktbuf_retrieve(struct ofconn *, uint32_t id,
127                                    struct ofpbuf **bufferp, uint16_t *in_port);
128
129 bool ofconn_has_pending_opgroups(const struct ofconn *);
130 void ofconn_add_opgroup(struct ofconn *, struct list *);
131 void ofconn_remove_opgroup(struct ofconn *, struct list *,
132                            const struct ofp_header *request, int error);
133
134 /* Sending asynchronous messages. */
135 void connmgr_send_port_status(struct connmgr *,
136                               const struct ofputil_phy_port *, uint8_t reason);
137 void connmgr_send_flow_removed(struct connmgr *,
138                                const struct ofputil_flow_removed *);
139 void connmgr_send_packet_in(struct connmgr *,
140                             const struct ofputil_packet_in *);
141
142 /* Fail-open settings. */
143 enum ofproto_fail_mode connmgr_get_fail_mode(const struct connmgr *);
144 void connmgr_set_fail_mode(struct connmgr *, enum ofproto_fail_mode);
145
146 /* Fail-open implementation. */
147 int connmgr_get_max_probe_interval(const struct connmgr *);
148 bool connmgr_is_any_controller_connected(const struct connmgr *);
149 bool connmgr_is_any_controller_admitted(const struct connmgr *);
150 int connmgr_failure_duration(const struct connmgr *);
151
152 /* In-band configuration. */
153 void connmgr_set_extra_in_band_remotes(struct connmgr *,
154                                        const struct sockaddr_in *, size_t);
155 void connmgr_set_in_band_queue(struct connmgr *, int queue_id);
156
157 /* In-band implementation. */
158 bool connmgr_msg_in_hook(struct connmgr *, const struct flow *,
159                          const struct ofpbuf *packet);
160 bool connmgr_may_set_up_flow(struct connmgr *, const struct flow *,
161                              uint32_t local_odp_port,
162                              const struct nlattr *odp_actions,
163                              size_t actions_len);
164
165 /* Fail-open and in-band implementation. */
166 void connmgr_flushed(struct connmgr *);
167
168 /* A flow monitor managed by NXST_FLOW_MONITOR and related requests. */
169 struct ofmonitor {
170     struct ofconn *ofconn;      /* Owning 'ofconn'. */
171     struct hmap_node ofconn_node; /* In ofconn's 'monitors' hmap. */
172     uint32_t id;
173
174     enum nx_flow_monitor_flags flags;
175
176     /* Matching. */
177     uint16_t out_port;
178     uint8_t table_id;
179     struct minimatch match;
180 };
181
182 struct ofputil_flow_monitor_request;
183
184 enum ofperr ofmonitor_create(const struct ofputil_flow_monitor_request *,
185                              struct ofconn *, struct ofmonitor **);
186 struct ofmonitor *ofmonitor_lookup(struct ofconn *, uint32_t id);
187 void ofmonitor_destroy(struct ofmonitor *);
188
189 void ofmonitor_report(struct connmgr *, struct rule *,
190                       enum nx_flow_update_event, enum ofp_flow_removed_reason,
191                       const struct ofconn *abbrev_ofconn, ovs_be32 abbrev_xid);
192 void ofmonitor_flush(struct connmgr *);
193
194 void ofmonitor_collect_resume_rules(struct ofmonitor *, uint64_t seqno,
195                                     struct list *rules);
196 void ofmonitor_compose_refresh_updates(struct list *rules, struct list *msgs);
197
198 #endif /* connmgr.h */