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