2 * Copyright (c) 2009, 2010, 2011, 2012 Nicira, Inc.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include "ofp-errors.h"
24 #include "openflow/nicira-ext.h"
25 #include "openvswitch/types.h"
30 struct ofputil_flow_removed;
31 struct ofputil_packet_in;
32 struct ofputil_phy_port;
36 /* ofproto supports two kinds of OpenFlow connections:
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.
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.
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
52 OFCONN_PRIMARY, /* An ordinary OpenFlow controller. */
53 OFCONN_SERVICE /* A service connection, e.g. "ovs-ofctl". */
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. */
65 struct connmgr *connmgr_create(struct ofproto *ofproto,
66 const char *dpif_name, const char *local_name);
67 void connmgr_destroy(struct connmgr *);
69 void connmgr_run(struct connmgr *,
70 bool (*handle_openflow)(struct ofconn *,
71 struct ofpbuf *ofp_msg));
72 void connmgr_wait(struct connmgr *, bool handling_openflow);
74 void connmgr_get_memory_usage(const struct connmgr *, struct simap *usage);
76 struct ofproto *ofconn_get_ofproto(const struct ofconn *);
78 void connmgr_retry(struct connmgr *);
80 /* OpenFlow configuration. */
81 bool connmgr_has_controllers(const struct connmgr *);
82 void connmgr_get_controller_info(struct connmgr *, struct shash *);
83 void connmgr_free_controller_info(struct shash *);
84 void connmgr_set_controllers(struct connmgr *,
85 const struct ofproto_controller[], size_t n);
86 void connmgr_reconnect(const struct connmgr *);
88 int connmgr_set_snoops(struct connmgr *, const struct sset *snoops);
89 bool connmgr_has_snoops(const struct connmgr *);
90 void connmgr_get_snoops(const struct connmgr *, struct sset *snoops);
92 /* Individual connections to OpenFlow controllers. */
93 enum ofconn_type ofconn_get_type(const struct ofconn *);
95 enum nx_role ofconn_get_role(const struct ofconn *);
96 void ofconn_set_role(struct ofconn *, enum nx_role);
98 enum ofputil_protocol ofconn_get_protocol(struct ofconn *);
99 void ofconn_set_protocol(struct ofconn *, enum ofputil_protocol);
101 enum nx_packet_in_format ofconn_get_packet_in_format(struct ofconn *);
102 void ofconn_set_packet_in_format(struct ofconn *, enum nx_packet_in_format);
104 void ofconn_set_controller_id(struct ofconn *, uint16_t controller_id);
106 void ofconn_set_invalid_ttl_to_controller(struct ofconn *, bool);
107 bool ofconn_get_invalid_ttl_to_controller(struct ofconn *);
109 int ofconn_get_miss_send_len(const struct ofconn *);
110 void ofconn_set_miss_send_len(struct ofconn *, int miss_send_len);
112 void ofconn_set_async_config(struct ofconn *,
113 const uint32_t master_masks[OAM_N_TYPES],
114 const uint32_t slave_masks[OAM_N_TYPES]);
116 void ofconn_send_reply(const struct ofconn *, struct ofpbuf *);
117 void ofconn_send_replies(const struct ofconn *, struct list *);
118 void ofconn_send_error(const struct ofconn *, const struct ofp_header *request,
121 enum ofperr ofconn_pktbuf_retrieve(struct ofconn *, uint32_t id,
122 struct ofpbuf **bufferp, uint16_t *in_port);
124 bool ofconn_has_pending_opgroups(const struct ofconn *);
125 void ofconn_add_opgroup(struct ofconn *, struct list *);
126 void ofconn_remove_opgroup(struct ofconn *, struct list *,
127 const struct ofp_header *request, int error);
129 /* Sending asynchronous messages. */
130 void connmgr_send_port_status(struct connmgr *,
131 const struct ofputil_phy_port *, uint8_t reason);
132 void connmgr_send_flow_removed(struct connmgr *,
133 const struct ofputil_flow_removed *);
134 void connmgr_send_packet_in(struct connmgr *,
135 const struct ofputil_packet_in *);
137 /* Fail-open settings. */
138 enum ofproto_fail_mode connmgr_get_fail_mode(const struct connmgr *);
139 void connmgr_set_fail_mode(struct connmgr *, enum ofproto_fail_mode);
141 /* Fail-open implementation. */
142 int connmgr_get_max_probe_interval(const struct connmgr *);
143 bool connmgr_is_any_controller_connected(const struct connmgr *);
144 bool connmgr_is_any_controller_admitted(const struct connmgr *);
145 int connmgr_failure_duration(const struct connmgr *);
147 /* In-band configuration. */
148 void connmgr_set_extra_in_band_remotes(struct connmgr *,
149 const struct sockaddr_in *, size_t);
150 void connmgr_set_in_band_queue(struct connmgr *, int queue_id);
152 /* In-band implementation. */
153 bool connmgr_msg_in_hook(struct connmgr *, const struct flow *,
154 const struct ofpbuf *packet);
155 bool connmgr_may_set_up_flow(struct connmgr *, const struct flow *,
156 const struct nlattr *odp_actions,
159 /* Fail-open and in-band implementation. */
160 void connmgr_flushed(struct connmgr *);
162 #endif /* connmgr.h */