connmgr: Move send_len from ofputil_packet_in to ofproto_packet_in.
[cascardo/ovs.git] / ofproto / connmgr.h
1 /*
2  * Copyright (c) 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
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
20 #include "classifier.h"
21 #include "hmap.h"
22 #include "list.h"
23 #include "match.h"
24 #include "ofp-errors.h"
25 #include "ofp-util.h"
26 #include "ofproto.h"
27 #include "openflow/nicira-ext.h"
28 #include "openvswitch/types.h"
29
30 struct nlattr;
31 struct ofconn;
32 struct ofopgroup;
33 struct rule;
34 struct simap;
35 struct sset;
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
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
65 /* A packet_in, with extra members to assist in queuing and routing it. */
66 struct ofproto_packet_in {
67     struct ofputil_packet_in up;
68     struct list list_node;      /* For queuing. */
69     uint16_t controller_id;     /* Controller ID to send to. */
70     int send_len;               /* Length that the action requested sending. */
71 };
72
73 /* Basics. */
74 struct connmgr *connmgr_create(struct ofproto *ofproto,
75                                const char *dpif_name, const char *local_name);
76 void connmgr_destroy(struct connmgr *);
77
78 void connmgr_run(struct connmgr *,
79                  bool (*handle_openflow)(struct ofconn *,
80                                          const struct ofpbuf *ofp_msg));
81 void connmgr_wait(struct connmgr *, bool handling_openflow);
82
83 void connmgr_get_memory_usage(const struct connmgr *, struct simap *usage);
84
85 struct ofproto *ofconn_get_ofproto(const struct ofconn *);
86
87 void connmgr_retry(struct connmgr *);
88
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 *);
97
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);
101
102 /* Individual connections to OpenFlow controllers. */
103 enum ofconn_type ofconn_get_type(const struct ofconn *);
104
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);
109
110 enum ofputil_protocol ofconn_get_protocol(const struct ofconn *);
111 void ofconn_set_protocol(struct ofconn *, enum ofputil_protocol);
112
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);
115
116 void ofconn_set_controller_id(struct ofconn *, uint16_t controller_id);
117
118 void ofconn_set_invalid_ttl_to_controller(struct ofconn *, bool);
119 bool ofconn_get_invalid_ttl_to_controller(struct ofconn *);
120
121 int ofconn_get_miss_send_len(const struct ofconn *);
122 void ofconn_set_miss_send_len(struct ofconn *, int miss_send_len);
123
124 void ofconn_set_async_config(struct ofconn *,
125                              const uint32_t master_masks[OAM_N_TYPES],
126                              const uint32_t slave_masks[OAM_N_TYPES]);
127 void ofconn_get_async_config(struct ofconn *,
128                              uint32_t *master_masks,
129                              uint32_t *slave_masks);
130
131 void ofconn_send_reply(const struct ofconn *, struct ofpbuf *);
132 void ofconn_send_replies(const struct ofconn *, struct list *);
133 void ofconn_send_error(const struct ofconn *, const struct ofp_header *request,
134                        enum ofperr);
135
136 enum ofperr ofconn_pktbuf_retrieve(struct ofconn *, uint32_t id,
137                                    struct ofpbuf **bufferp, ofp_port_t *in_port);
138
139 bool ofconn_has_pending_opgroups(const struct ofconn *);
140 void ofconn_add_opgroup(struct ofconn *, struct list *);
141 void ofconn_remove_opgroup(struct ofconn *, struct list *,
142                            const struct ofp_header *request, int error);
143
144 /* Sending asynchronous messages. */
145 void connmgr_send_port_status(struct connmgr *,
146                               const struct ofputil_phy_port *, uint8_t reason);
147 void connmgr_send_flow_removed(struct connmgr *,
148                                const struct ofputil_flow_removed *);
149 void connmgr_send_packet_in(struct connmgr *,
150                             const struct ofproto_packet_in *);
151
152 /* Fail-open settings. */
153 enum ofproto_fail_mode connmgr_get_fail_mode(const struct connmgr *);
154 void connmgr_set_fail_mode(struct connmgr *, enum ofproto_fail_mode);
155
156 /* Fail-open implementation. */
157 int connmgr_get_max_probe_interval(const struct connmgr *);
158 bool connmgr_is_any_controller_connected(const struct connmgr *);
159 bool connmgr_is_any_controller_admitted(const struct connmgr *);
160 int connmgr_failure_duration(const struct connmgr *);
161
162 /* In-band configuration. */
163 void connmgr_set_extra_in_band_remotes(struct connmgr *,
164                                        const struct sockaddr_in *, size_t);
165 void connmgr_set_in_band_queue(struct connmgr *, int queue_id);
166
167 /* In-band implementation. */
168 bool connmgr_has_in_band(struct connmgr *);
169
170 /* Fail-open and in-band implementation. */
171 void connmgr_flushed(struct connmgr *);
172
173 /* A flow monitor managed by NXST_FLOW_MONITOR and related requests. */
174 struct ofmonitor {
175     struct ofconn *ofconn;      /* Owning 'ofconn'. */
176     struct hmap_node ofconn_node; /* In ofconn's 'monitors' hmap. */
177     uint32_t id;
178
179     enum nx_flow_monitor_flags flags;
180
181     /* Matching. */
182     ofp_port_t out_port;
183     uint8_t table_id;
184     struct minimatch match;
185 };
186
187 struct ofputil_flow_monitor_request;
188
189 enum ofperr ofmonitor_create(const struct ofputil_flow_monitor_request *,
190                              struct ofconn *, struct ofmonitor **)
191     OVS_REQUIRES(ofproto_mutex);
192 struct ofmonitor *ofmonitor_lookup(struct ofconn *, uint32_t id)
193     OVS_REQUIRES(ofproto_mutex);
194 void ofmonitor_destroy(struct ofmonitor *)
195     OVS_REQUIRES(ofproto_mutex);
196
197 void ofmonitor_report(struct connmgr *, struct rule *,
198                       enum nx_flow_update_event, enum ofp_flow_removed_reason,
199                       const struct ofconn *abbrev_ofconn, ovs_be32 abbrev_xid)
200     OVS_REQUIRES(ofproto_mutex);
201 void ofmonitor_flush(struct connmgr *) OVS_REQUIRES(ofproto_mutex);
202
203
204 struct rule_collection;
205 void ofmonitor_collect_resume_rules(struct ofmonitor *, uint64_t seqno,
206                                     struct rule_collection *)
207     OVS_REQUIRES(ofproto_mutex);
208 void ofmonitor_compose_refresh_updates(struct rule_collection *rules,
209                                        struct list *msgs)
210     OVS_REQUIRES(ofproto_mutex);
211
212 #endif /* connmgr.h */