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