ofproto: New feature to notify controllers of flow table changes.
[cascardo/ovs.git] / ofproto / connmgr.h
1 /*
2  * Copyright (c) 2009, 2010, 2011, 2012 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 "ofp-errors.h"
24 #include "ofproto.h"
25 #include "openflow/nicira-ext.h"
26 #include "openvswitch/types.h"
27
28 struct nlattr;
29 struct ofconn;
30 struct ofopgroup;
31 struct ofputil_flow_removed;
32 struct ofputil_packet_in;
33 struct ofputil_phy_port;
34 struct rule;
35 struct simap;
36 struct sset;
37
38 /* ofproto supports two kinds of OpenFlow connections:
39  *
40  *   - "Primary" connections to ordinary OpenFlow controllers.  ofproto
41  *     maintains persistent connections to these controllers and by default
42  *     sends them asynchronous messages such as packet-ins.
43  *
44  *   - "Service" connections, e.g. from ovs-ofctl.  When these connections
45  *     drop, it is the other side's responsibility to reconnect them if
46  *     necessary.  ofproto does not send them asynchronous messages by default.
47  *
48  * Currently, active (tcp, ssl, unix) connections are always "primary"
49  * connections and passive (ptcp, pssl, punix) connections are always "service"
50  * connections.  There is no inherent reason for this, but it reflects the
51  * common case.
52  */
53 enum ofconn_type {
54     OFCONN_PRIMARY,             /* An ordinary OpenFlow controller. */
55     OFCONN_SERVICE              /* A service connection, e.g. "ovs-ofctl". */
56 };
57
58 /* The type of an OpenFlow asynchronous message. */
59 enum ofconn_async_msg_type {
60     OAM_PACKET_IN,              /* OFPT_PACKET_IN or NXT_PACKET_IN. */
61     OAM_PORT_STATUS,            /* OFPT_PORT_STATUS. */
62     OAM_FLOW_REMOVED,           /* OFPT_FLOW_REMOVED or NXT_FLOW_REMOVED. */
63     OAM_N_TYPES
64 };
65
66 /* Basics. */
67 struct connmgr *connmgr_create(struct ofproto *ofproto,
68                                const char *dpif_name, const char *local_name);
69 void connmgr_destroy(struct connmgr *);
70
71 void connmgr_run(struct connmgr *,
72                  bool (*handle_openflow)(struct ofconn *,
73                                          struct ofpbuf *ofp_msg));
74 void connmgr_wait(struct connmgr *, bool handling_openflow);
75
76 void connmgr_get_memory_usage(const struct connmgr *, struct simap *usage);
77
78 struct ofproto *ofconn_get_ofproto(const struct ofconn *);
79
80 void connmgr_retry(struct connmgr *);
81
82 /* OpenFlow configuration. */
83 bool connmgr_has_controllers(const struct connmgr *);
84 void connmgr_get_controller_info(struct connmgr *, struct shash *);
85 void connmgr_free_controller_info(struct shash *);
86 void connmgr_set_controllers(struct connmgr *,
87                              const struct ofproto_controller[], size_t n);
88 void connmgr_reconnect(const struct connmgr *);
89
90 int connmgr_set_snoops(struct connmgr *, const struct sset *snoops);
91 bool connmgr_has_snoops(const struct connmgr *);
92 void connmgr_get_snoops(const struct connmgr *, struct sset *snoops);
93
94 /* Individual connections to OpenFlow controllers. */
95 enum ofconn_type ofconn_get_type(const struct ofconn *);
96
97 enum nx_role ofconn_get_role(const struct ofconn *);
98 void ofconn_set_role(struct ofconn *, enum nx_role);
99
100 enum ofputil_protocol ofconn_get_protocol(struct ofconn *);
101 void ofconn_set_protocol(struct ofconn *, enum ofputil_protocol);
102
103 enum nx_packet_in_format ofconn_get_packet_in_format(struct ofconn *);
104 void ofconn_set_packet_in_format(struct ofconn *, enum nx_packet_in_format);
105
106 void ofconn_set_controller_id(struct ofconn *, uint16_t controller_id);
107
108 void ofconn_set_invalid_ttl_to_controller(struct ofconn *, bool);
109 bool ofconn_get_invalid_ttl_to_controller(struct ofconn *);
110
111 int ofconn_get_miss_send_len(const struct ofconn *);
112 void ofconn_set_miss_send_len(struct ofconn *, int miss_send_len);
113
114 void ofconn_set_async_config(struct ofconn *,
115                              const uint32_t master_masks[OAM_N_TYPES],
116                              const uint32_t slave_masks[OAM_N_TYPES]);
117
118 void ofconn_send_reply(const struct ofconn *, struct ofpbuf *);
119 void ofconn_send_replies(const struct ofconn *, struct list *);
120 void ofconn_send_error(const struct ofconn *, const struct ofp_header *request,
121                        enum ofperr);
122
123 enum ofperr ofconn_pktbuf_retrieve(struct ofconn *, uint32_t id,
124                                    struct ofpbuf **bufferp, uint16_t *in_port);
125
126 bool ofconn_has_pending_opgroups(const struct ofconn *);
127 void ofconn_add_opgroup(struct ofconn *, struct list *);
128 void ofconn_remove_opgroup(struct ofconn *, struct list *,
129                            const struct ofp_header *request, int error);
130
131 /* Sending asynchronous messages. */
132 void connmgr_send_port_status(struct connmgr *,
133                               const struct ofputil_phy_port *, uint8_t reason);
134 void connmgr_send_flow_removed(struct connmgr *,
135                                const struct ofputil_flow_removed *);
136 void connmgr_send_packet_in(struct connmgr *,
137                             const struct ofputil_packet_in *);
138
139 /* Fail-open settings. */
140 enum ofproto_fail_mode connmgr_get_fail_mode(const struct connmgr *);
141 void connmgr_set_fail_mode(struct connmgr *, enum ofproto_fail_mode);
142
143 /* Fail-open implementation. */
144 int connmgr_get_max_probe_interval(const struct connmgr *);
145 bool connmgr_is_any_controller_connected(const struct connmgr *);
146 bool connmgr_is_any_controller_admitted(const struct connmgr *);
147 int connmgr_failure_duration(const struct connmgr *);
148
149 /* In-band configuration. */
150 void connmgr_set_extra_in_band_remotes(struct connmgr *,
151                                        const struct sockaddr_in *, size_t);
152 void connmgr_set_in_band_queue(struct connmgr *, int queue_id);
153
154 /* In-band implementation. */
155 bool connmgr_msg_in_hook(struct connmgr *, const struct flow *,
156                          const struct ofpbuf *packet);
157 bool connmgr_may_set_up_flow(struct connmgr *, const struct flow *,
158                              const struct nlattr *odp_actions,
159                              size_t actions_len);
160
161 /* Fail-open and in-band implementation. */
162 void connmgr_flushed(struct connmgr *);
163
164 /* A flow monitor managed by NXST_FLOW_MONITOR and related requests. */
165 struct ofmonitor {
166     struct ofconn *ofconn;      /* Owning 'ofconn'. */
167     struct hmap_node ofconn_node; /* In ofconn's 'monitors' hmap. */
168     uint32_t id;
169
170     enum nx_flow_monitor_flags flags;
171
172     /* Matching. */
173     uint16_t out_port;
174     uint8_t table_id;
175     struct cls_rule match;
176 };
177
178 struct ofputil_flow_monitor_request;
179
180 enum ofperr ofmonitor_create(const struct ofputil_flow_monitor_request *,
181                              struct ofconn *, struct ofmonitor **);
182 struct ofmonitor *ofmonitor_lookup(struct ofconn *, uint32_t id);
183 void ofmonitor_destroy(struct ofmonitor *);
184
185 void ofmonitor_report(struct connmgr *, struct rule *,
186                       enum nx_flow_update_event, enum ofp_flow_removed_reason,
187                       const struct ofconn *abbrev_ofconn, ovs_be32 abbrev_xid);
188 void ofmonitor_flush(struct connmgr *);
189
190 void ofmonitor_collect_resume_rules(struct ofmonitor *, uint64_t seqno,
191                                     struct list *rules);
192 void ofmonitor_compose_refresh_updates(struct list *rules, struct list *msgs);
193
194 #endif /* connmgr.h */