ofproto: Always clone packets in PACKET_IN message.
[cascardo/ovs.git] / ofproto / connmgr.h
1 /*
2  * Copyright (c) 2009, 2010, 2011 Nicira Networks.
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 "hmap.h"
21 #include "list.h"
22 #include "ofproto.h"
23 #include "openflow/nicira-ext.h"
24 #include "openvswitch/types.h"
25
26 struct nlattr;
27 struct ofconn;
28 struct ofopgroup;
29 struct ofputil_flow_removed;
30 struct ofputil_packet_in;
31 struct sset;
32
33 /* ofproto supports two kinds of OpenFlow connections:
34  *
35  *   - "Primary" connections to ordinary OpenFlow controllers.  ofproto
36  *     maintains persistent connections to these controllers and by default
37  *     sends them asynchronous messages such as packet-ins.
38  *
39  *   - "Service" connections, e.g. from ovs-ofctl.  When these connections
40  *     drop, it is the other side's responsibility to reconnect them if
41  *     necessary.  ofproto does not send them asynchronous messages by default.
42  *
43  * Currently, active (tcp, ssl, unix) connections are always "primary"
44  * connections and passive (ptcp, pssl, punix) connections are always "service"
45  * connections.  There is no inherent reason for this, but it reflects the
46  * common case.
47  */
48 enum ofconn_type {
49     OFCONN_PRIMARY,             /* An ordinary OpenFlow controller. */
50     OFCONN_SERVICE              /* A service connection, e.g. "ovs-ofctl". */
51 };
52
53 /* Basics. */
54 struct connmgr *connmgr_create(struct ofproto *ofproto,
55                                const char *dpif_name, const char *local_name);
56 void connmgr_destroy(struct connmgr *);
57
58 void connmgr_run(struct connmgr *,
59                  bool (*handle_openflow)(struct ofconn *,
60                                          struct ofpbuf *ofp_msg));
61 void connmgr_wait(struct connmgr *, bool handling_openflow);
62
63 struct ofproto *ofconn_get_ofproto(const struct ofconn *);
64
65 void connmgr_retry(struct connmgr *);
66
67 /* OpenFlow configuration. */
68 bool connmgr_has_controllers(const struct connmgr *);
69 void connmgr_get_controller_info(struct connmgr *, struct shash *);
70 void connmgr_free_controller_info(struct shash *);
71 void connmgr_set_controllers(struct connmgr *,
72                              const struct ofproto_controller[], size_t n);
73 void connmgr_reconnect(const struct connmgr *);
74
75 int connmgr_set_snoops(struct connmgr *, const struct sset *snoops);
76 bool connmgr_has_snoops(const struct connmgr *);
77 void connmgr_get_snoops(const struct connmgr *, struct sset *snoops);
78
79 /* Individual connections to OpenFlow controllers. */
80 enum ofconn_type ofconn_get_type(const struct ofconn *);
81
82 enum nx_role ofconn_get_role(const struct ofconn *);
83 void ofconn_set_role(struct ofconn *, enum nx_role);
84
85 enum nx_flow_format ofconn_get_flow_format(struct ofconn *);
86 void ofconn_set_flow_format(struct ofconn *, enum nx_flow_format);
87
88 bool ofconn_get_flow_mod_table_id(const struct ofconn *);
89 void ofconn_set_flow_mod_table_id(struct ofconn *, bool enable);
90
91 int ofconn_get_miss_send_len(const struct ofconn *);
92 void ofconn_set_miss_send_len(struct ofconn *, int miss_send_len);
93
94 void ofconn_send_reply(const struct ofconn *, struct ofpbuf *);
95 void ofconn_send_replies(const struct ofconn *, struct list *);
96 void ofconn_send_error(const struct ofconn *, const struct ofp_header *request,
97                        int error);
98
99 int ofconn_pktbuf_retrieve(struct ofconn *, uint32_t id,
100                            struct ofpbuf **bufferp, uint16_t *in_port);
101
102 bool ofconn_has_pending_opgroups(const struct ofconn *);
103 void ofconn_add_opgroup(struct ofconn *, struct list *);
104 void ofconn_remove_opgroup(struct ofconn *, struct list *,
105                            const struct ofp_header *request, int error);
106
107 /* Sending asynchronous messages. */
108 void connmgr_send_port_status(struct connmgr *, const struct ofp_phy_port *,
109                               uint8_t reason);
110 void connmgr_send_flow_removed(struct connmgr *,
111                                const struct ofputil_flow_removed *);
112 void connmgr_send_packet_in(struct connmgr *, const struct ofputil_packet_in *,
113                             const struct flow *);
114
115 /* Fail-open settings. */
116 enum ofproto_fail_mode connmgr_get_fail_mode(const struct connmgr *);
117 void connmgr_set_fail_mode(struct connmgr *, enum ofproto_fail_mode);
118
119 /* Fail-open implementation. */
120 int connmgr_get_max_probe_interval(const struct connmgr *);
121 bool connmgr_is_any_controller_connected(const struct connmgr *);
122 bool connmgr_is_any_controller_admitted(const struct connmgr *);
123 int connmgr_failure_duration(const struct connmgr *);
124 void connmgr_broadcast(struct connmgr *, struct ofpbuf *);
125
126 /* In-band configuration. */
127 void connmgr_set_extra_in_band_remotes(struct connmgr *,
128                                        const struct sockaddr_in *, size_t);
129 void connmgr_set_in_band_queue(struct connmgr *, int queue_id);
130
131 /* In-band implementation. */
132 bool connmgr_msg_in_hook(struct connmgr *, const struct flow *,
133                          const struct ofpbuf *packet);
134 bool connmgr_may_set_up_flow(struct connmgr *, const struct flow *,
135                              const struct nlattr *odp_actions,
136                              size_t actions_len);
137
138 /* Fail-open and in-band implementation. */
139 void connmgr_flushed(struct connmgr *);
140
141 #endif /* connmgr.h */