ofproto: Do straightforward removal of asynchronous flow operations.
[cascardo/ovs.git] / ofproto / connmgr.h
1 /*
2  * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014 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 "ofp-util.h"
26 #include "ofproto.h"
27 #include "openflow/nicira-ext.h"
28 #include "openvswitch/types.h"
29
30 struct nlattr;
31 struct ofconn;
32 struct rule;
33 struct simap;
34 struct sset;
35
36 /* ofproto supports two kinds of OpenFlow connections:
37  *
38  *   - "Primary" connections to ordinary OpenFlow controllers.  ofproto
39  *     maintains persistent connections to these controllers and by default
40  *     sends them asynchronous messages such as packet-ins.
41  *
42  *   - "Service" connections, e.g. from ovs-ofctl.  When these connections
43  *     drop, it is the other side's responsibility to reconnect them if
44  *     necessary.  ofproto does not send them asynchronous messages by default.
45  *
46  * Currently, active (tcp, ssl, unix) connections are always "primary"
47  * connections and passive (ptcp, pssl, punix) connections are always "service"
48  * connections.  There is no inherent reason for this, but it reflects the
49  * common case.
50  */
51 enum ofconn_type {
52     OFCONN_PRIMARY,             /* An ordinary OpenFlow controller. */
53     OFCONN_SERVICE              /* A service connection, e.g. "ovs-ofctl". */
54 };
55
56 /* The type of an OpenFlow asynchronous message. */
57 enum ofconn_async_msg_type {
58     OAM_PACKET_IN,              /* OFPT_PACKET_IN or NXT_PACKET_IN. */
59     OAM_PORT_STATUS,            /* OFPT_PORT_STATUS. */
60     OAM_FLOW_REMOVED,           /* OFPT_FLOW_REMOVED or NXT_FLOW_REMOVED. */
61     OAM_N_TYPES
62 };
63
64 enum ofproto_packet_in_miss_type {
65     /* Not generated by a flow miss or table-miss flow. */
66     OFPROTO_PACKET_IN_NO_MISS,
67
68     /* The packet_in was generated directly by a table-miss flow, that is, a
69      * flow with priority 0 that wildcards all fields.  See OF1.3.3 section
70      * 5.4.
71      *
72      * (Our interpretation of "directly" is "not via groups".  Packet_ins
73      * generated by table-miss flows via groups use
74      * OFPROTO_PACKET_IN_NO_MISS.) */
75     OFPROTO_PACKET_IN_MISS_FLOW,
76
77     /* The packet-in was generated directly by a table-miss, but not a
78      * table-miss flow.  That is, it was generated by the OpenFlow 1.0, 1.1, or
79      * 1.2 table-miss behavior. */
80     OFPROTO_PACKET_IN_MISS_WITHOUT_FLOW,
81 };
82
83 /* A packet_in, with extra members to assist in queuing and routing it. */
84 struct ofproto_packet_in {
85     struct ofputil_packet_in up;
86     struct list list_node;      /* For queuing. */
87     uint16_t controller_id;     /* Controller ID to send to. */
88     int send_len;               /* Length that the action requested sending. */
89     enum ofproto_packet_in_miss_type miss_type;
90 };
91
92 /* Basics. */
93 struct connmgr *connmgr_create(struct ofproto *ofproto,
94                                const char *dpif_name, const char *local_name);
95 void connmgr_destroy(struct connmgr *);
96
97 void connmgr_run(struct connmgr *,
98                  void (*handle_openflow)(struct ofconn *,
99                                          const struct ofpbuf *ofp_msg));
100 void connmgr_wait(struct connmgr *);
101
102 void connmgr_get_memory_usage(const struct connmgr *, struct simap *usage);
103
104 struct ofproto *ofconn_get_ofproto(const struct ofconn *);
105
106 void connmgr_retry(struct connmgr *);
107
108 /* OpenFlow configuration. */
109 bool connmgr_has_controllers(const struct connmgr *);
110 void connmgr_get_controller_info(struct connmgr *, struct shash *);
111 void connmgr_free_controller_info(struct shash *);
112 void connmgr_set_controllers(struct connmgr *,
113                              const struct ofproto_controller[], size_t n,
114                              uint32_t allowed_versions);
115 void connmgr_reconnect(const struct connmgr *);
116
117 int connmgr_set_snoops(struct connmgr *, const struct sset *snoops);
118 bool connmgr_has_snoops(const struct connmgr *);
119 void connmgr_get_snoops(const struct connmgr *, struct sset *snoops);
120
121 /* Individual connections to OpenFlow controllers. */
122 enum ofconn_type ofconn_get_type(const struct ofconn *);
123
124 bool ofconn_get_master_election_id(const struct ofconn *, uint64_t *idp);
125 bool ofconn_set_master_election_id(struct ofconn *, uint64_t);
126 enum ofp12_controller_role ofconn_get_role(const struct ofconn *);
127 void ofconn_set_role(struct ofconn *, enum ofp12_controller_role);
128
129 enum ofputil_protocol ofconn_get_protocol(const struct ofconn *);
130 void ofconn_set_protocol(struct ofconn *, enum ofputil_protocol);
131
132 enum nx_packet_in_format ofconn_get_packet_in_format(struct ofconn *);
133 void ofconn_set_packet_in_format(struct ofconn *, enum nx_packet_in_format);
134
135 void ofconn_set_controller_id(struct ofconn *, uint16_t controller_id);
136
137 void ofconn_set_invalid_ttl_to_controller(struct ofconn *, bool);
138 bool ofconn_get_invalid_ttl_to_controller(struct ofconn *);
139
140 int ofconn_get_miss_send_len(const struct ofconn *);
141 void ofconn_set_miss_send_len(struct ofconn *, int miss_send_len);
142
143 void ofconn_set_async_config(struct ofconn *,
144                              const uint32_t master_masks[OAM_N_TYPES],
145                              const uint32_t slave_masks[OAM_N_TYPES]);
146 void ofconn_get_async_config(struct ofconn *,
147                              uint32_t *master_masks,
148                              uint32_t *slave_masks);
149
150 void ofconn_send_reply(const struct ofconn *, struct ofpbuf *);
151 void ofconn_send_replies(const struct ofconn *, struct list *);
152 void ofconn_send_error(const struct ofconn *, const struct ofp_header *request,
153                        enum ofperr);
154
155 enum ofperr ofconn_pktbuf_retrieve(struct ofconn *, uint32_t id,
156                                    struct ofpbuf **bufferp, ofp_port_t *in_port);
157
158 struct hmap *ofconn_get_bundles(struct ofconn *ofconn);
159
160 /* Logging flow_mod summaries. */
161 void ofconn_report_flow_mod(struct ofconn *, enum ofp_flow_mod_command);
162
163 /* Sending asynchronous messages. */
164 bool connmgr_wants_packet_in_on_miss(struct connmgr *mgr);
165 void connmgr_send_port_status(struct connmgr *, struct ofconn *source,
166                               const struct ofputil_phy_port *, uint8_t reason);
167 void connmgr_send_flow_removed(struct connmgr *,
168                                const struct ofputil_flow_removed *);
169 void connmgr_send_packet_in(struct connmgr *,
170                             const struct ofproto_packet_in *);
171 void ofconn_send_role_status(struct ofconn *ofconn, uint32_t role,
172                              uint8_t reason);
173
174 /* Fail-open settings. */
175 enum ofproto_fail_mode connmgr_get_fail_mode(const struct connmgr *);
176 void connmgr_set_fail_mode(struct connmgr *, enum ofproto_fail_mode);
177
178 /* Fail-open implementation. */
179 int connmgr_get_max_probe_interval(const struct connmgr *);
180 bool connmgr_is_any_controller_connected(const struct connmgr *);
181 bool connmgr_is_any_controller_admitted(const struct connmgr *);
182 int connmgr_failure_duration(const struct connmgr *);
183
184 /* In-band configuration. */
185 void connmgr_set_extra_in_band_remotes(struct connmgr *,
186                                        const struct sockaddr_in *, size_t);
187 void connmgr_set_in_band_queue(struct connmgr *, int queue_id);
188
189 /* In-band implementation. */
190 bool connmgr_has_in_band(struct connmgr *);
191
192 /* Fail-open and in-band implementation. */
193 void connmgr_flushed(struct connmgr *);
194
195 /* A flow monitor managed by NXST_FLOW_MONITOR and related requests. */
196 struct ofmonitor {
197     struct ofconn *ofconn;      /* Owning 'ofconn'. */
198     struct hmap_node ofconn_node; /* In ofconn's 'monitors' hmap. */
199     uint32_t id;
200
201     enum nx_flow_monitor_flags flags;
202
203     /* Matching. */
204     ofp_port_t out_port;
205     uint8_t table_id;
206     struct minimatch match;
207 };
208
209 struct ofputil_flow_monitor_request;
210
211 enum ofperr ofmonitor_create(const struct ofputil_flow_monitor_request *,
212                              struct ofconn *, struct ofmonitor **)
213     OVS_REQUIRES(ofproto_mutex);
214 struct ofmonitor *ofmonitor_lookup(struct ofconn *, uint32_t id)
215     OVS_REQUIRES(ofproto_mutex);
216 void ofmonitor_destroy(struct ofmonitor *)
217     OVS_REQUIRES(ofproto_mutex);
218
219 void ofmonitor_report(struct connmgr *, struct rule *,
220                       enum nx_flow_update_event, enum ofp_flow_removed_reason,
221                       const struct ofconn *abbrev_ofconn, ovs_be32 abbrev_xid)
222     OVS_REQUIRES(ofproto_mutex);
223 void ofmonitor_flush(struct connmgr *) OVS_REQUIRES(ofproto_mutex);
224
225
226 struct rule_collection;
227 void ofmonitor_collect_resume_rules(struct ofmonitor *, uint64_t seqno,
228                                     struct rule_collection *)
229     OVS_REQUIRES(ofproto_mutex);
230 void ofmonitor_compose_refresh_updates(struct rule_collection *rules,
231                                        struct list *msgs)
232     OVS_REQUIRES(ofproto_mutex);
233
234 #endif /* connmgr.h */