2 * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 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.
20 #include "classifier.h"
24 #include "ofp-errors.h"
27 #include "ofproto-provider.h"
28 #include "openflow/nicira-ext.h"
29 #include "openvswitch/types.h"
37 /* ofproto supports two kinds of OpenFlow connections:
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.
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.
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
53 OFCONN_PRIMARY
, /* An ordinary OpenFlow controller. */
54 OFCONN_SERVICE
/* A service connection, e.g. "ovs-ofctl". */
57 /* An asynchronous message that might need to be queued between threads. */
58 struct ofproto_async_msg
{
59 struct ovs_list list_node
; /* For queuing. */
60 uint16_t controller_id
; /* Controller ID to send to. */
62 enum ofputil_async_msg_type oam
;
66 struct ofputil_packet_in up
;
67 int max_len
; /* From action, or -1 if none. */
71 void ofproto_async_msg_free(struct ofproto_async_msg
*);
74 struct connmgr
*connmgr_create(struct ofproto
*ofproto
,
75 const char *dpif_name
, const char *local_name
);
76 void connmgr_destroy(struct connmgr
*);
78 void connmgr_run(struct connmgr
*,
79 void (*handle_openflow
)(struct ofconn
*,
80 const struct ofpbuf
*ofp_msg
));
81 void connmgr_wait(struct connmgr
*);
83 void connmgr_get_memory_usage(const struct connmgr
*, struct simap
*usage
);
85 struct ofproto
*ofconn_get_ofproto(const struct ofconn
*);
87 void connmgr_retry(struct connmgr
*);
89 /* OpenFlow configuration. */
90 bool connmgr_has_controllers(const struct connmgr
*);
91 void connmgr_get_controller_info(struct connmgr
*, struct shash
*);
92 void connmgr_free_controller_info(struct shash
*);
93 void connmgr_set_controllers(struct connmgr
*,
94 const struct ofproto_controller
[], size_t n
,
95 uint32_t allowed_versions
);
96 void connmgr_reconnect(const struct connmgr
*);
98 int connmgr_set_snoops(struct connmgr
*, const struct sset
*snoops
);
99 bool connmgr_has_snoops(const struct connmgr
*);
100 void connmgr_get_snoops(const struct connmgr
*, struct sset
*snoops
);
102 /* Individual connections to OpenFlow controllers. */
103 enum ofconn_type
ofconn_get_type(const struct ofconn
*);
105 bool ofconn_get_master_election_id(const struct ofconn
*, uint64_t *idp
);
106 bool ofconn_set_master_election_id(struct ofconn
*, uint64_t);
107 enum ofp12_controller_role
ofconn_get_role(const struct ofconn
*);
108 void ofconn_set_role(struct ofconn
*, enum ofp12_controller_role
);
110 enum ofputil_protocol
ofconn_get_protocol(const struct ofconn
*);
111 void ofconn_set_protocol(struct ofconn
*, enum ofputil_protocol
);
113 enum nx_packet_in_format
ofconn_get_packet_in_format(struct ofconn
*);
114 void ofconn_set_packet_in_format(struct ofconn
*, enum nx_packet_in_format
);
116 void ofconn_set_controller_id(struct ofconn
*, uint16_t controller_id
);
118 void ofconn_set_invalid_ttl_to_controller(struct ofconn
*, bool);
119 bool ofconn_get_invalid_ttl_to_controller(struct ofconn
*);
121 int ofconn_get_miss_send_len(const struct ofconn
*);
122 void ofconn_set_miss_send_len(struct ofconn
*, int miss_send_len
);
124 void ofconn_set_async_config(struct ofconn
*,
125 const struct ofputil_async_cfg
*);
126 struct ofputil_async_cfg
ofconn_get_async_config(const struct ofconn
*);
128 void ofconn_send_reply(const struct ofconn
*, struct ofpbuf
*);
129 void ofconn_send_replies(const struct ofconn
*, struct ovs_list
*);
130 void ofconn_send_error(const struct ofconn
*, const struct ofp_header
*request
,
133 enum ofperr
ofconn_pktbuf_retrieve(struct ofconn
*, uint32_t id
,
134 struct dp_packet
**bufferp
, ofp_port_t
*in_port
);
138 struct ofp_bundle
*ofconn_get_bundle(struct ofconn
*, uint32_t id
);
139 enum ofperr
ofconn_insert_bundle(struct ofconn
*, struct ofp_bundle
*);
140 enum ofperr
ofconn_remove_bundle(struct ofconn
*, struct ofp_bundle
*);
142 /* Logging flow_mod summaries. */
143 void ofconn_report_flow_mod(struct ofconn
*, enum ofp_flow_mod_command
);
145 /* Sending asynchronous messages. */
146 bool connmgr_wants_packet_in_on_miss(struct connmgr
*mgr
);
147 void connmgr_send_port_status(struct connmgr
*, struct ofconn
*source
,
148 const struct ofputil_phy_port
*, uint8_t reason
);
149 void connmgr_send_flow_removed(struct connmgr
*,
150 const struct ofputil_flow_removed
*);
151 void connmgr_send_async_msg(struct connmgr
*,
152 const struct ofproto_async_msg
*);
153 void ofconn_send_role_status(struct ofconn
*ofconn
, uint32_t role
,
156 void connmgr_send_requestforward(struct connmgr
*, const struct ofconn
*source
,
157 const struct ofputil_requestforward
*);
159 /* Fail-open settings. */
160 enum ofproto_fail_mode
connmgr_get_fail_mode(const struct connmgr
*);
161 void connmgr_set_fail_mode(struct connmgr
*, enum ofproto_fail_mode
);
163 /* Fail-open implementation. */
164 int connmgr_get_max_probe_interval(const struct connmgr
*);
165 bool connmgr_is_any_controller_connected(const struct connmgr
*);
166 bool connmgr_is_any_controller_admitted(const struct connmgr
*);
167 int connmgr_failure_duration(const struct connmgr
*);
169 /* In-band configuration. */
170 void connmgr_set_extra_in_band_remotes(struct connmgr
*,
171 const struct sockaddr_in
*, size_t);
172 void connmgr_set_in_band_queue(struct connmgr
*, int queue_id
);
174 /* In-band implementation. */
175 bool connmgr_has_in_band(struct connmgr
*);
177 /* Fail-open and in-band implementation. */
178 void connmgr_flushed(struct connmgr
*);
180 int connmgr_count_hidden_rules(const struct connmgr
*);
182 /* A flow monitor managed by NXST_FLOW_MONITOR and related requests. */
184 struct ofconn
*ofconn
; /* Owning 'ofconn'. */
185 struct hmap_node ofconn_node
; /* In ofconn's 'monitors' hmap. */
188 enum nx_flow_monitor_flags flags
;
193 struct minimatch match
;
196 struct ofputil_flow_monitor_request
;
198 enum ofperr
ofmonitor_create(const struct ofputil_flow_monitor_request
*,
199 struct ofconn
*, struct ofmonitor
**)
200 OVS_REQUIRES(ofproto_mutex
);
201 struct ofmonitor
*ofmonitor_lookup(struct ofconn
*, uint32_t id
)
202 OVS_REQUIRES(ofproto_mutex
);
203 void ofmonitor_destroy(struct ofmonitor
*)
204 OVS_REQUIRES(ofproto_mutex
);
206 void ofmonitor_report(struct connmgr
*, struct rule
*,
207 enum nx_flow_update_event
, enum ofp_flow_removed_reason
,
208 const struct ofconn
*abbrev_ofconn
, ovs_be32 abbrev_xid
,
209 const struct rule_actions
*old_actions
)
210 OVS_REQUIRES(ofproto_mutex
);
211 void ofmonitor_flush(struct connmgr
*) OVS_REQUIRES(ofproto_mutex
);
214 struct rule_collection
;
215 void ofmonitor_collect_resume_rules(struct ofmonitor
*, uint64_t seqno
,
216 struct rule_collection
*)
217 OVS_REQUIRES(ofproto_mutex
);
218 void ofmonitor_compose_refresh_updates(struct rule_collection
*rules
,
219 struct ovs_list
*msgs
)
220 OVS_REQUIRES(ofproto_mutex
);
222 #endif /* connmgr.h */