]> git.proxmox.com Git - mirror_ovs.git/blame - lib/vconn-provider.h
ofp-util: New function ofputil_port_to_string().
[mirror_ovs.git] / lib / vconn-provider.h
CommitLineData
064af421 1/*
4766ce7a 2 * Copyright (c) 2008, 2009, 2010, 2012, 2013 Nicira, Inc.
064af421 3 *
a14bc59f
BP
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:
064af421 7 *
a14bc59f
BP
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.
064af421
BP
15 */
16
17#ifndef VCONN_PROVIDER_H
18#define VCONN_PROVIDER_H 1
19
20/* Provider interface to vconns, which provide a virtual connection to an
21 * OpenFlow device. */
22
064af421 23#include "vconn.h"
cb22974d 24#include "util.h"
2e3fa633 25#include "openflow/openflow-common.h"
064af421
BP
26\f
27/* Active virtual connection to an OpenFlow device. */
28
29/* Active virtual connection to an OpenFlow device.
30 *
31 * This structure should be treated as opaque by vconn implementations. */
32struct vconn {
5b712636 33 const struct vconn_class *class;
064af421
BP
34 int state;
35 int error;
4766ce7a
BP
36
37 /* OpenFlow versions. */
38 uint32_t allowed_versions; /* Bitmap of versions we will accept. */
39 uint32_t peer_versions; /* Peer's bitmap of versions it will accept. */
40 enum ofp_version version; /* Negotiated version (or 0). */
41 bool recv_any_version; /* True to receive a message of any version. */
42
4408d18a
BP
43 ovs_be32 remote_ip;
44 ovs_be16 remote_port;
45 ovs_be32 local_ip;
46 ovs_be16 local_port;
4766ce7a 47
064af421 48 char *name;
064af421
BP
49};
50
5b712636 51void vconn_init(struct vconn *, const struct vconn_class *, int connect_status,
7a25bd99
SH
52 const char *name, uint32_t allowed_versions);
53void vconn_free_data(struct vconn *vconn);
4408d18a
BP
54void vconn_set_remote_ip(struct vconn *, ovs_be32 remote_ip);
55void vconn_set_remote_port(struct vconn *, ovs_be16 remote_port);
56void vconn_set_local_ip(struct vconn *, ovs_be32 local_ip);
57void vconn_set_local_port(struct vconn *, ovs_be16 local_port);
064af421
BP
58static inline void vconn_assert_class(const struct vconn *vconn,
59 const struct vconn_class *class)
60{
cb22974d 61 ovs_assert(vconn->class == class);
064af421
BP
62}
63
64struct vconn_class {
65 /* Prefix for connection names, e.g. "nl", "tcp". */
66 const char *name;
67
68 /* Attempts to connect to an OpenFlow device. 'name' is the full
69 * connection name provided by the user, e.g. "tcp:1.2.3.4". This name is
70 * useful for error messages but must not be modified.
71 *
7a25bd99
SH
72 * 'allowed_verions' is the OpenFlow versions that may be
73 * negotiated for a connection.
74 *
064af421 75 * 'suffix' is a copy of 'name' following the colon and may be modified.
f125905c 76 * 'dscp' is the DSCP value that the new connection should use in the IP
ef8a3d14 77 * packets it sends.
064af421
BP
78 *
79 * Returns 0 if successful, otherwise a positive errno value. If
80 * successful, stores a pointer to the new connection in '*vconnp'.
81 *
82 * The open function must not block waiting for a connection to complete.
83 * If the connection cannot be completed immediately, it should return
84 * EAGAIN (not EINPROGRESS, as returned by the connect system call) and
85 * continue the connection in the background. */
7a25bd99
SH
86 int (*open)(const char *name, uint32_t allowed_versions,
87 char *suffix, struct vconn **vconnp, uint8_t dscp);
064af421
BP
88
89 /* Closes 'vconn' and frees associated memory. */
90 void (*close)(struct vconn *vconn);
91
92 /* Tries to complete the connection on 'vconn'. If 'vconn''s connection is
93 * complete, returns 0 if the connection was successful or a positive errno
94 * value if it failed. If the connection is still in progress, returns
95 * EAGAIN.
96 *
97 * The connect function must not block waiting for the connection to
98 * complete; instead, it should return EAGAIN immediately. */
99 int (*connect)(struct vconn *vconn);
100
101 /* Tries to receive an OpenFlow message from 'vconn'. If successful,
102 * stores the received message into '*msgp' and returns 0. The caller is
103 * responsible for destroying the message with ofpbuf_delete(). On
104 * failure, returns a positive errno value and stores a null pointer into
105 * '*msgp'.
106 *
107 * If the connection has been closed in the normal fashion, returns EOF.
108 *
109 * The recv function must not block waiting for a packet to arrive. If no
110 * packets have been received, it should return EAGAIN. */
111 int (*recv)(struct vconn *vconn, struct ofpbuf **msgp);
112
113 /* Tries to queue 'msg' for transmission on 'vconn'. If successful,
114 * returns 0, in which case ownership of 'msg' is transferred to the vconn.
115 * Success does not guarantee that 'msg' has been or ever will be delivered
116 * to the peer, only that it has been queued for transmission.
117 *
118 * Returns a positive errno value on failure, in which case the caller
119 * retains ownership of 'msg'.
120 *
121 * The send function must not block. If 'msg' cannot be immediately
122 * accepted for transmission, it should return EAGAIN. */
123 int (*send)(struct vconn *vconn, struct ofpbuf *msg);
124
60cb3eb8
BP
125 /* Allows 'vconn' to perform maintenance activities, such as flushing
126 * output buffers.
127 *
128 * May be null if 'vconn' doesn't have anything to do here. */
129 void (*run)(struct vconn *vconn);
130
131 /* Arranges for the poll loop to wake up when 'vconn' needs to perform
132 * maintenance activities.
133 *
134 * May be null if 'vconn' doesn't have anything to do here. */
135 void (*run_wait)(struct vconn *vconn);
136
064af421
BP
137 /* Arranges for the poll loop to wake up when 'vconn' is ready to take an
138 * action of the given 'type'. */
139 void (*wait)(struct vconn *vconn, enum vconn_wait_type type);
140};
141\f
142/* Passive virtual connection to an OpenFlow device.
143 *
144 * This structure should be treated as opaque by vconn implementations. */
145struct pvconn {
5b712636 146 const struct pvconn_class *class;
064af421 147 char *name;
7a25bd99 148 uint32_t allowed_versions;
064af421
BP
149};
150
5b712636 151void pvconn_init(struct pvconn *pvconn, const struct pvconn_class *class,
7a25bd99 152 const char *name, uint32_t allowed_versions);
064af421
BP
153static inline void pvconn_assert_class(const struct pvconn *pvconn,
154 const struct pvconn_class *class)
155{
cb22974d 156 ovs_assert(pvconn->class == class);
064af421
BP
157}
158
159struct pvconn_class {
160 /* Prefix for connection names, e.g. "ptcp", "pssl". */
161 const char *name;
162
163 /* Attempts to start listening for OpenFlow connections. 'name' is the
164 * full connection name provided by the user, e.g. "ptcp:1234". This name
165 * is useful for error messages but must not be modified.
166 *
7a25bd99
SH
167 * 'allowed_versions' is the OpenFlow protocol versions that may
168 * be negotiated for a session.
169 *
064af421 170 * 'suffix' is a copy of 'name' following the colon and may be modified.
f125905c 171 * 'dscp' is the DSCP value that the new connection should use in the IP
ef8a3d14 172 * packets it sends.
064af421
BP
173 *
174 * Returns 0 if successful, otherwise a positive errno value. If
175 * successful, stores a pointer to the new connection in '*pvconnp'.
176 *
177 * The listen function must not block. If the connection cannot be
178 * completed immediately, it should return EAGAIN (not EINPROGRESS, as
179 * returned by the connect system call) and continue the connection in the
180 * background. */
7a25bd99
SH
181 int (*listen)(const char *name, uint32_t allowed_versions,
182 char *suffix, struct pvconn **pvconnp, uint8_t dscp);
064af421
BP
183
184 /* Closes 'pvconn' and frees associated memory. */
185 void (*close)(struct pvconn *pvconn);
186
187 /* Tries to accept a new connection on 'pvconn'. If successful, stores the
188 * new connection in '*new_vconnp' and returns 0. Otherwise, returns a
189 * positive errno value.
190 *
191 * The accept function must not block waiting for a connection. If no
192 * connection is ready to be accepted, it should return EAGAIN. */
193 int (*accept)(struct pvconn *pvconn, struct vconn **new_vconnp);
194
195 /* Arranges for the poll loop to wake up when a connection is ready to be
196 * accepted on 'pvconn'. */
197 void (*wait)(struct pvconn *pvconn);
198};
199
200/* Active and passive vconn classes. */
5b712636
BP
201extern const struct vconn_class tcp_vconn_class;
202extern const struct pvconn_class ptcp_pvconn_class;
203extern const struct vconn_class unix_vconn_class;
204extern const struct pvconn_class punix_pvconn_class;
064af421 205#ifdef HAVE_OPENSSL
5b712636
BP
206extern const struct vconn_class ssl_vconn_class;
207extern const struct pvconn_class pssl_pvconn_class;
064af421
BP
208#endif
209
210#endif /* vconn-provider.h */