2 * Copyright (c) 2009, 2010, 2011 Nicira Networks.
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;
34 /* ofproto supports two kinds of OpenFlow connections:
36 * - "Primary" connections to ordinary OpenFlow controllers. ofproto
37 * maintains persistent connections to these controllers and by default
38 * sends them asynchronous messages such as packet-ins.
40 * - "Service" connections, e.g. from ovs-ofctl. When these connections
41 * drop, it is the other side's responsibility to reconnect them if
42 * necessary. ofproto does not send them asynchronous messages by default.
44 * Currently, active (tcp, ssl, unix) connections are always "primary"
45 * connections and passive (ptcp, pssl, punix) connections are always "service"
46 * connections. There is no inherent reason for this, but it reflects the
50 OFCONN_PRIMARY, /* An ordinary OpenFlow controller. */
51 OFCONN_SERVICE /* A service connection, e.g. "ovs-ofctl". */
55 struct connmgr *connmgr_create(struct ofproto *ofproto,
56 const char *dpif_name, const char *local_name);
57 void connmgr_destroy(struct connmgr *);
59 void connmgr_run(struct connmgr *,
60 bool (*handle_openflow)(struct ofconn *,
61 struct ofpbuf *ofp_msg));
62 void connmgr_wait(struct connmgr *, bool handling_openflow);
64 struct ofproto *ofconn_get_ofproto(const struct ofconn *);
66 void connmgr_retry(struct connmgr *);
68 /* OpenFlow configuration. */
69 bool connmgr_has_controllers(const struct connmgr *);
70 void connmgr_get_controller_info(struct connmgr *, struct shash *);
71 void connmgr_free_controller_info(struct shash *);
72 void connmgr_set_controllers(struct connmgr *,
73 const struct ofproto_controller[], size_t n);
74 void connmgr_reconnect(const struct connmgr *);
76 int connmgr_set_snoops(struct connmgr *, const struct sset *snoops);
77 bool connmgr_has_snoops(const struct connmgr *);
78 void connmgr_get_snoops(const struct connmgr *, struct sset *snoops);
80 /* Individual connections to OpenFlow controllers. */
81 enum ofconn_type ofconn_get_type(const struct ofconn *);
83 enum nx_role ofconn_get_role(const struct ofconn *);
84 void ofconn_set_role(struct ofconn *, enum nx_role);
86 enum nx_flow_format ofconn_get_flow_format(struct ofconn *);
87 void ofconn_set_flow_format(struct ofconn *, enum nx_flow_format);
89 enum nx_packet_in_format ofconn_get_packet_in_format(struct ofconn *);
90 void ofconn_set_packet_in_format(struct ofconn *, enum nx_packet_in_format);
92 bool ofconn_get_flow_mod_table_id(const struct ofconn *);
93 void ofconn_set_flow_mod_table_id(struct ofconn *, bool enable);
95 void ofconn_set_invalid_ttl_to_controller(struct ofconn *, bool);
96 bool ofconn_get_invalid_ttl_to_controller(struct ofconn *);
98 int ofconn_get_miss_send_len(const struct ofconn *);
99 void ofconn_set_miss_send_len(struct ofconn *, int miss_send_len);
101 void ofconn_send_reply(const struct ofconn *, struct ofpbuf *);
102 void ofconn_send_replies(const struct ofconn *, struct list *);
103 void ofconn_send_error(const struct ofconn *, const struct ofp_header *request,
106 enum ofperr ofconn_pktbuf_retrieve(struct ofconn *, uint32_t id,
107 struct ofpbuf **bufferp, uint16_t *in_port);
109 bool ofconn_has_pending_opgroups(const struct ofconn *);
110 void ofconn_add_opgroup(struct ofconn *, struct list *);
111 void ofconn_remove_opgroup(struct ofconn *, struct list *,
112 const struct ofp_header *request, int error);
114 /* Sending asynchronous messages. */
115 void connmgr_send_port_status(struct connmgr *, const struct ofp_phy_port *,
117 void connmgr_send_flow_removed(struct connmgr *,
118 const struct ofputil_flow_removed *);
119 void connmgr_send_packet_in(struct connmgr *, const struct ofputil_packet_in *,
120 const struct flow *);
122 /* Fail-open settings. */
123 enum ofproto_fail_mode connmgr_get_fail_mode(const struct connmgr *);
124 void connmgr_set_fail_mode(struct connmgr *, enum ofproto_fail_mode);
126 /* Fail-open implementation. */
127 int connmgr_get_max_probe_interval(const struct connmgr *);
128 bool connmgr_is_any_controller_connected(const struct connmgr *);
129 bool connmgr_is_any_controller_admitted(const struct connmgr *);
130 int connmgr_failure_duration(const struct connmgr *);
131 void connmgr_broadcast(struct connmgr *, struct ofpbuf *);
133 /* In-band configuration. */
134 void connmgr_set_extra_in_band_remotes(struct connmgr *,
135 const struct sockaddr_in *, size_t);
136 void connmgr_set_in_band_queue(struct connmgr *, int queue_id);
138 /* In-band implementation. */
139 bool connmgr_msg_in_hook(struct connmgr *, const struct flow *,
140 const struct ofpbuf *packet);
141 bool connmgr_may_set_up_flow(struct connmgr *, const struct flow *,
142 const struct nlattr *odp_actions,
145 /* Fail-open and in-band implementation. */
146 void connmgr_flushed(struct connmgr *);
148 #endif /* connmgr.h */