]>
Commit | Line | Data |
---|---|---|
19a87e36 | 1 | /* |
2a6f78e0 | 2 | * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014 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" |
0fb7792a | 25 | #include "ofp-util.h" |
19a87e36 BP |
26 | #include "ofproto.h" |
27 | #include "openflow/nicira-ext.h" | |
28 | #include "openvswitch/types.h" | |
29 | ||
a946b636 | 30 | struct nlattr; |
19a87e36 | 31 | struct ofconn; |
7ee20df1 | 32 | struct ofopgroup; |
2b07c8b1 | 33 | struct rule; |
0d085684 | 34 | struct simap; |
81e2083f | 35 | struct sset; |
19a87e36 BP |
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 | ||
80d5aefd BP |
57 | /* The type of an OpenFlow asynchronous message. */ |
58 | enum ofconn_async_msg_type { | |
59 | OAM_PACKET_IN, /* OFPT_PACKET_IN or NXT_PACKET_IN. */ | |
60 | OAM_PORT_STATUS, /* OFPT_PORT_STATUS. */ | |
61 | OAM_FLOW_REMOVED, /* OFPT_FLOW_REMOVED or NXT_FLOW_REMOVED. */ | |
62 | OAM_N_TYPES | |
63 | }; | |
64 | ||
32260212 SH |
65 | enum ofproto_packet_in_miss_type { |
66 | /* Not generated by a flow miss or table-miss flow. */ | |
67 | OFPROTO_PACKET_IN_NO_MISS, | |
68 | ||
69 | /* The packet_in was generated directly by a table-miss flow, that is, a | |
70 | * flow with priority 0 that wildcards all fields. See OF1.3.3 section | |
71 | * 5.4. | |
72 | * | |
73 | * (Our interpretation of "directly" is "not via groups". Packet_ins | |
74 | * generated by table-miss flows via groups use | |
75 | * OFPROTO_PACKET_IN_NO_MISS.) */ | |
76 | OFPROTO_PACKET_IN_MISS_FLOW, | |
77 | ||
78 | /* The packet-in was generated directly by a table-miss, but not a | |
79 | * table-miss flow. That is, it was generated by the OpenFlow 1.0, 1.1, or | |
80 | * 1.2 table-miss behavior. */ | |
81 | OFPROTO_PACKET_IN_MISS_WITHOUT_FLOW, | |
82 | }; | |
83 | ||
0fb7792a BP |
84 | /* A packet_in, with extra members to assist in queuing and routing it. */ |
85 | struct ofproto_packet_in { | |
86 | struct ofputil_packet_in up; | |
87 | struct list list_node; /* For queuing. */ | |
f11c7538 | 88 | uint16_t controller_id; /* Controller ID to send to. */ |
d38a3c7b | 89 | int send_len; /* Length that the action requested sending. */ |
32260212 | 90 | enum ofproto_packet_in_miss_type miss_type; |
0fb7792a BP |
91 | }; |
92 | ||
19a87e36 BP |
93 | /* Basics. */ |
94 | struct connmgr *connmgr_create(struct ofproto *ofproto, | |
95 | const char *dpif_name, const char *local_name); | |
96 | void connmgr_destroy(struct connmgr *); | |
97 | ||
98 | void connmgr_run(struct connmgr *, | |
7ee20df1 | 99 | bool (*handle_openflow)(struct ofconn *, |
e03248b7 | 100 | const struct ofpbuf *ofp_msg)); |
7ee20df1 | 101 | void connmgr_wait(struct connmgr *, bool handling_openflow); |
19a87e36 | 102 | |
0d085684 BP |
103 | void connmgr_get_memory_usage(const struct connmgr *, struct simap *usage); |
104 | ||
19a87e36 BP |
105 | struct ofproto *ofconn_get_ofproto(const struct ofconn *); |
106 | ||
7ee20df1 BP |
107 | void connmgr_retry(struct connmgr *); |
108 | ||
19a87e36 BP |
109 | /* OpenFlow configuration. */ |
110 | bool connmgr_has_controllers(const struct connmgr *); | |
111 | void connmgr_get_controller_info(struct connmgr *, struct shash *); | |
72ba2ed3 | 112 | void connmgr_free_controller_info(struct shash *); |
19a87e36 | 113 | void connmgr_set_controllers(struct connmgr *, |
1d9ffc17 SH |
114 | const struct ofproto_controller[], size_t n, |
115 | uint32_t allowed_versions); | |
19a87e36 BP |
116 | void connmgr_reconnect(const struct connmgr *); |
117 | ||
81e2083f BP |
118 | int connmgr_set_snoops(struct connmgr *, const struct sset *snoops); |
119 | bool connmgr_has_snoops(const struct connmgr *); | |
120 | void connmgr_get_snoops(const struct connmgr *, struct sset *snoops); | |
19a87e36 BP |
121 | |
122 | /* Individual connections to OpenFlow controllers. */ | |
123 | enum ofconn_type ofconn_get_type(const struct ofconn *); | |
124 | ||
f4f1ea7e | 125 | bool ofconn_get_master_election_id(const struct ofconn *, uint64_t *idp); |
6ea4776b | 126 | bool ofconn_set_master_election_id(struct ofconn *, uint64_t); |
f4f1ea7e BP |
127 | enum ofp12_controller_role ofconn_get_role(const struct ofconn *); |
128 | void ofconn_set_role(struct ofconn *, enum ofp12_controller_role); | |
19a87e36 | 129 | |
e3d560db | 130 | enum ofputil_protocol ofconn_get_protocol(const struct ofconn *); |
27527aa0 | 131 | void ofconn_set_protocol(struct ofconn *, enum ofputil_protocol); |
19a87e36 | 132 | |
54834960 EJ |
133 | enum nx_packet_in_format ofconn_get_packet_in_format(struct ofconn *); |
134 | void ofconn_set_packet_in_format(struct ofconn *, enum nx_packet_in_format); | |
135 | ||
a7349929 BP |
136 | void ofconn_set_controller_id(struct ofconn *, uint16_t controller_id); |
137 | ||
f0fd1a17 PS |
138 | void ofconn_set_invalid_ttl_to_controller(struct ofconn *, bool); |
139 | bool ofconn_get_invalid_ttl_to_controller(struct ofconn *); | |
140 | ||
19a87e36 BP |
141 | int ofconn_get_miss_send_len(const struct ofconn *); |
142 | void ofconn_set_miss_send_len(struct ofconn *, int miss_send_len); | |
143 | ||
80d5aefd BP |
144 | void ofconn_set_async_config(struct ofconn *, |
145 | const uint32_t master_masks[OAM_N_TYPES], | |
146 | const uint32_t slave_masks[OAM_N_TYPES]); | |
c423b3b3 AC |
147 | void ofconn_get_async_config(struct ofconn *, |
148 | uint32_t *master_masks, | |
149 | uint32_t *slave_masks); | |
80d5aefd | 150 | |
19a87e36 | 151 | void ofconn_send_reply(const struct ofconn *, struct ofpbuf *); |
63f2140a | 152 | void ofconn_send_replies(const struct ofconn *, struct list *); |
1be5ff75 | 153 | void ofconn_send_error(const struct ofconn *, const struct ofp_header *request, |
90bf1e07 | 154 | enum ofperr); |
19a87e36 | 155 | |
90bf1e07 | 156 | enum ofperr ofconn_pktbuf_retrieve(struct ofconn *, uint32_t id, |
4e022ec0 | 157 | struct ofpbuf **bufferp, ofp_port_t *in_port); |
19a87e36 | 158 | |
7ee20df1 BP |
159 | bool ofconn_has_pending_opgroups(const struct ofconn *); |
160 | void ofconn_add_opgroup(struct ofconn *, struct list *); | |
7ee20df1 | 161 | |
777af88d AC |
162 | struct hmap *ofconn_get_bundles(struct ofconn *ofconn); |
163 | ||
696d1bcf BP |
164 | /* Logging flow_mod summaries. */ |
165 | void ofconn_report_flow_mod(struct ofconn *, enum ofp_flow_mod_command); | |
166 | ||
19a87e36 | 167 | /* Sending asynchronous messages. */ |
6b83a3c5 | 168 | bool connmgr_wants_packet_in_on_miss(struct connmgr *mgr); |
2a6f78e0 | 169 | void connmgr_send_port_status(struct connmgr *, struct ofconn *source, |
9e1fd49b | 170 | const struct ofputil_phy_port *, uint8_t reason); |
19a87e36 BP |
171 | void connmgr_send_flow_removed(struct connmgr *, |
172 | const struct ofputil_flow_removed *); | |
d8653c38 | 173 | void connmgr_send_packet_in(struct connmgr *, |
0fb7792a | 174 | const struct ofproto_packet_in *); |
00467f73 AC |
175 | void ofconn_send_role_status(struct ofconn *ofconn, uint32_t role, |
176 | uint8_t reason); | |
19a87e36 BP |
177 | |
178 | /* Fail-open settings. */ | |
179 | enum ofproto_fail_mode connmgr_get_fail_mode(const struct connmgr *); | |
180 | void connmgr_set_fail_mode(struct connmgr *, enum ofproto_fail_mode); | |
181 | ||
182 | /* Fail-open implementation. */ | |
183 | int connmgr_get_max_probe_interval(const struct connmgr *); | |
184 | bool connmgr_is_any_controller_connected(const struct connmgr *); | |
185 | bool connmgr_is_any_controller_admitted(const struct connmgr *); | |
186 | int connmgr_failure_duration(const struct connmgr *); | |
19a87e36 BP |
187 | |
188 | /* In-band configuration. */ | |
189 | void connmgr_set_extra_in_band_remotes(struct connmgr *, | |
190 | const struct sockaddr_in *, size_t); | |
191 | void connmgr_set_in_band_queue(struct connmgr *, int queue_id); | |
192 | ||
193 | /* In-band implementation. */ | |
f7f1ea29 | 194 | bool connmgr_has_in_band(struct connmgr *); |
19a87e36 BP |
195 | |
196 | /* Fail-open and in-band implementation. */ | |
197 | void connmgr_flushed(struct connmgr *); | |
198 | ||
2b07c8b1 BP |
199 | /* A flow monitor managed by NXST_FLOW_MONITOR and related requests. */ |
200 | struct ofmonitor { | |
201 | struct ofconn *ofconn; /* Owning 'ofconn'. */ | |
202 | struct hmap_node ofconn_node; /* In ofconn's 'monitors' hmap. */ | |
203 | uint32_t id; | |
204 | ||
205 | enum nx_flow_monitor_flags flags; | |
206 | ||
207 | /* Matching. */ | |
4e022ec0 | 208 | ofp_port_t out_port; |
2b07c8b1 | 209 | uint8_t table_id; |
5cb7a798 | 210 | struct minimatch match; |
2b07c8b1 BP |
211 | }; |
212 | ||
213 | struct ofputil_flow_monitor_request; | |
214 | ||
215 | enum ofperr ofmonitor_create(const struct ofputil_flow_monitor_request *, | |
4cd1bc9d BP |
216 | struct ofconn *, struct ofmonitor **) |
217 | OVS_REQUIRES(ofproto_mutex); | |
218 | struct ofmonitor *ofmonitor_lookup(struct ofconn *, uint32_t id) | |
219 | OVS_REQUIRES(ofproto_mutex); | |
220 | void ofmonitor_destroy(struct ofmonitor *) | |
221 | OVS_REQUIRES(ofproto_mutex); | |
2b07c8b1 BP |
222 | |
223 | void ofmonitor_report(struct connmgr *, struct rule *, | |
224 | enum nx_flow_update_event, enum ofp_flow_removed_reason, | |
15aaf599 BP |
225 | const struct ofconn *abbrev_ofconn, ovs_be32 abbrev_xid) |
226 | OVS_REQUIRES(ofproto_mutex); | |
4cd1bc9d | 227 | void ofmonitor_flush(struct connmgr *) OVS_REQUIRES(ofproto_mutex); |
2b07c8b1 | 228 | |
a8e547c1 BP |
229 | |
230 | struct rule_collection; | |
2b07c8b1 | 231 | void ofmonitor_collect_resume_rules(struct ofmonitor *, uint64_t seqno, |
4cd1bc9d BP |
232 | struct rule_collection *) |
233 | OVS_REQUIRES(ofproto_mutex); | |
a8e547c1 | 234 | void ofmonitor_compose_refresh_updates(struct rule_collection *rules, |
4cd1bc9d BP |
235 | struct list *msgs) |
236 | OVS_REQUIRES(ofproto_mutex); | |
2b07c8b1 | 237 | |
19a87e36 | 238 | #endif /* connmgr.h */ |