]> git.proxmox.com Git - mirror_ovs.git/blame - ofproto/connmgr.h
connmgr: Use 'ofproto_mutex' to protect ofconns from being destroyed.
[mirror_ovs.git] / ofproto / connmgr.h
CommitLineData
19a87e36 1/*
f4f1ea7e 2 * Copyright (c) 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
19a87e36
BP
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
2b07c8b1 20#include "classifier.h"
19a87e36
BP
21#include "hmap.h"
22#include "list.h"
81a76618 23#include "match.h"
90bf1e07 24#include "ofp-errors.h"
19a87e36
BP
25#include "ofproto.h"
26#include "openflow/nicira-ext.h"
27#include "openvswitch/types.h"
28
a946b636 29struct nlattr;
19a87e36 30struct ofconn;
7ee20df1 31struct ofopgroup;
19a87e36 32struct ofputil_flow_removed;
78bd1cd0 33struct ofputil_packet_in;
9e1fd49b 34struct ofputil_phy_port;
2b07c8b1 35struct rule;
0d085684 36struct simap;
81e2083f 37struct sset;
19a87e36
BP
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 */
54enum ofconn_type {
55 OFCONN_PRIMARY, /* An ordinary OpenFlow controller. */
56 OFCONN_SERVICE /* A service connection, e.g. "ovs-ofctl". */
57};
58
80d5aefd
BP
59/* The type of an OpenFlow asynchronous message. */
60enum 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
19a87e36
BP
67/* Basics. */
68struct connmgr *connmgr_create(struct ofproto *ofproto,
69 const char *dpif_name, const char *local_name);
70void connmgr_destroy(struct connmgr *);
71
72void connmgr_run(struct connmgr *,
7ee20df1 73 bool (*handle_openflow)(struct ofconn *,
e03248b7 74 const struct ofpbuf *ofp_msg));
7ee20df1 75void connmgr_wait(struct connmgr *, bool handling_openflow);
19a87e36 76
0d085684
BP
77void connmgr_get_memory_usage(const struct connmgr *, struct simap *usage);
78
19a87e36
BP
79struct ofproto *ofconn_get_ofproto(const struct ofconn *);
80
7ee20df1
BP
81void connmgr_retry(struct connmgr *);
82
19a87e36
BP
83/* OpenFlow configuration. */
84bool connmgr_has_controllers(const struct connmgr *);
85void connmgr_get_controller_info(struct connmgr *, struct shash *);
72ba2ed3 86void connmgr_free_controller_info(struct shash *);
19a87e36 87void connmgr_set_controllers(struct connmgr *,
1d9ffc17
SH
88 const struct ofproto_controller[], size_t n,
89 uint32_t allowed_versions);
19a87e36
BP
90void connmgr_reconnect(const struct connmgr *);
91
81e2083f
BP
92int connmgr_set_snoops(struct connmgr *, const struct sset *snoops);
93bool connmgr_has_snoops(const struct connmgr *);
94void connmgr_get_snoops(const struct connmgr *, struct sset *snoops);
19a87e36
BP
95
96/* Individual connections to OpenFlow controllers. */
97enum ofconn_type ofconn_get_type(const struct ofconn *);
98
f4f1ea7e 99bool ofconn_get_master_election_id(const struct ofconn *, uint64_t *idp);
6ea4776b 100bool ofconn_set_master_election_id(struct ofconn *, uint64_t);
f4f1ea7e
BP
101enum ofp12_controller_role ofconn_get_role(const struct ofconn *);
102void ofconn_set_role(struct ofconn *, enum ofp12_controller_role);
19a87e36 103
e3d560db 104enum ofputil_protocol ofconn_get_protocol(const struct ofconn *);
27527aa0 105void ofconn_set_protocol(struct ofconn *, enum ofputil_protocol);
19a87e36 106
54834960
EJ
107enum nx_packet_in_format ofconn_get_packet_in_format(struct ofconn *);
108void ofconn_set_packet_in_format(struct ofconn *, enum nx_packet_in_format);
109
a7349929
BP
110void ofconn_set_controller_id(struct ofconn *, uint16_t controller_id);
111
f0fd1a17
PS
112void ofconn_set_invalid_ttl_to_controller(struct ofconn *, bool);
113bool ofconn_get_invalid_ttl_to_controller(struct ofconn *);
114
19a87e36
BP
115int ofconn_get_miss_send_len(const struct ofconn *);
116void ofconn_set_miss_send_len(struct ofconn *, int miss_send_len);
117
80d5aefd
BP
118void ofconn_set_async_config(struct ofconn *,
119 const uint32_t master_masks[OAM_N_TYPES],
120 const uint32_t slave_masks[OAM_N_TYPES]);
c423b3b3
AC
121void ofconn_get_async_config(struct ofconn *,
122 uint32_t *master_masks,
123 uint32_t *slave_masks);
80d5aefd 124
19a87e36 125void ofconn_send_reply(const struct ofconn *, struct ofpbuf *);
63f2140a 126void ofconn_send_replies(const struct ofconn *, struct list *);
1be5ff75 127void ofconn_send_error(const struct ofconn *, const struct ofp_header *request,
90bf1e07 128 enum ofperr);
19a87e36 129
90bf1e07 130enum ofperr ofconn_pktbuf_retrieve(struct ofconn *, uint32_t id,
4e022ec0 131 struct ofpbuf **bufferp, ofp_port_t *in_port);
19a87e36 132
7ee20df1
BP
133bool ofconn_has_pending_opgroups(const struct ofconn *);
134void ofconn_add_opgroup(struct ofconn *, struct list *);
135void ofconn_remove_opgroup(struct ofconn *, struct list *,
136 const struct ofp_header *request, int error);
137
19a87e36 138/* Sending asynchronous messages. */
9e1fd49b
BP
139void connmgr_send_port_status(struct connmgr *,
140 const struct ofputil_phy_port *, uint8_t reason);
19a87e36
BP
141void connmgr_send_flow_removed(struct connmgr *,
142 const struct ofputil_flow_removed *);
d8653c38
BP
143void connmgr_send_packet_in(struct connmgr *,
144 const struct ofputil_packet_in *);
19a87e36
BP
145
146/* Fail-open settings. */
147enum ofproto_fail_mode connmgr_get_fail_mode(const struct connmgr *);
148void connmgr_set_fail_mode(struct connmgr *, enum ofproto_fail_mode);
149
150/* Fail-open implementation. */
151int connmgr_get_max_probe_interval(const struct connmgr *);
152bool connmgr_is_any_controller_connected(const struct connmgr *);
153bool connmgr_is_any_controller_admitted(const struct connmgr *);
154int connmgr_failure_duration(const struct connmgr *);
19a87e36
BP
155
156/* In-band configuration. */
157void connmgr_set_extra_in_band_remotes(struct connmgr *,
158 const struct sockaddr_in *, size_t);
159void connmgr_set_in_band_queue(struct connmgr *, int queue_id);
160
161/* In-band implementation. */
f7f1ea29 162bool connmgr_has_in_band(struct connmgr *);
19a87e36
BP
163
164/* Fail-open and in-band implementation. */
165void connmgr_flushed(struct connmgr *);
166
2b07c8b1
BP
167/* A flow monitor managed by NXST_FLOW_MONITOR and related requests. */
168struct ofmonitor {
169 struct ofconn *ofconn; /* Owning 'ofconn'. */
170 struct hmap_node ofconn_node; /* In ofconn's 'monitors' hmap. */
171 uint32_t id;
172
173 enum nx_flow_monitor_flags flags;
174
175 /* Matching. */
4e022ec0 176 ofp_port_t out_port;
2b07c8b1 177 uint8_t table_id;
5cb7a798 178 struct minimatch match;
2b07c8b1
BP
179};
180
181struct ofputil_flow_monitor_request;
182
183enum ofperr ofmonitor_create(const struct ofputil_flow_monitor_request *,
184 struct ofconn *, struct ofmonitor **);
185struct ofmonitor *ofmonitor_lookup(struct ofconn *, uint32_t id);
186void ofmonitor_destroy(struct ofmonitor *);
187
188void ofmonitor_report(struct connmgr *, struct rule *,
189 enum nx_flow_update_event, enum ofp_flow_removed_reason,
15aaf599
BP
190 const struct ofconn *abbrev_ofconn, ovs_be32 abbrev_xid)
191 OVS_REQUIRES(ofproto_mutex);
2b07c8b1
BP
192void ofmonitor_flush(struct connmgr *);
193
a8e547c1
BP
194
195struct rule_collection;
2b07c8b1 196void ofmonitor_collect_resume_rules(struct ofmonitor *, uint64_t seqno,
a8e547c1
BP
197 struct rule_collection *);
198void ofmonitor_compose_refresh_updates(struct rule_collection *rules,
199 struct list *msgs);
2b07c8b1 200
19a87e36 201#endif /* connmgr.h */