1 /* Copyright (c) 2008 The Board of Trustees of The Leland Stanford
4 * We are making the OpenFlow specification and associated documentation
5 * (Software) available for public use and benefit with the expectation
6 * that others will use, modify and enhance the Software and contribute
7 * those enhancements back to the community. However, since we would
8 * like to make the Software available for broadest use, with as few
9 * restrictions as possible permission is hereby granted, free of
10 * charge, to any person obtaining a copy of this Software to deal in
11 * the Software under the copyrights without restriction, including
12 * without limitation the rights to use, copy, modify, merge, publish,
13 * distribute, sublicense, and/or sell copies of the Software, and to
14 * permit persons to whom the Software is furnished to do so, subject to
15 * the following conditions:
17 * The above copyright notice and this permission notice shall be
18 * included in all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
24 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
25 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
26 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 * The name and trademarks of copyright holder(s) may NOT be used in
30 * advertising or publicity pertaining to the Software or any
31 * derivatives without specific, written prior permission.
34 #ifndef VCONN_PROVIDER_H
35 #define VCONN_PROVIDER_H 1
37 /* Provider interface to vconns, which provide a virtual connection to an
43 /* Active virtual connection to an OpenFlow device. */
45 /* Active virtual connection to an OpenFlow device.
47 * This structure should be treated as opaque by vconn implementations. */
49 struct vconn_class *class;
58 void vconn_init(struct vconn *, struct vconn_class *, int connect_status,
59 uint32_t ip, const char *name);
60 static inline void vconn_assert_class(const struct vconn *vconn,
61 const struct vconn_class *class)
63 assert(vconn->class == class);
67 /* Prefix for connection names, e.g. "nl", "tcp". */
70 /* Attempts to connect to an OpenFlow device. 'name' is the full
71 * connection name provided by the user, e.g. "nl:0", "tcp:1.2.3.4". This
72 * name is useful for error messages but must not be modified.
74 * 'suffix' is a copy of 'name' following the colon and may be modified.
76 * Returns 0 if successful, otherwise a positive errno value. If
77 * successful, stores a pointer to the new connection in '*vconnp'.
79 * The open function must not block waiting for a connection to complete.
80 * If the connection cannot be completed immediately, it should return
81 * EAGAIN (not EINPROGRESS, as returned by the connect system call) and
82 * continue the connection in the background. */
83 int (*open)(const char *name, char *suffix, struct vconn **vconnp);
85 /* Closes 'vconn' and frees associated memory. */
86 void (*close)(struct vconn *vconn);
88 /* Tries to complete the connection on 'vconn'. If 'vconn''s connection is
89 * complete, returns 0 if the connection was successful or a positive errno
90 * value if it failed. If the connection is still in progress, returns
93 * The connect function must not block waiting for the connection to
94 * complete; instead, it should return EAGAIN immediately. */
95 int (*connect)(struct vconn *vconn);
97 /* Tries to receive an OpenFlow message from 'vconn'. If successful,
98 * stores the received message into '*msgp' and returns 0. The caller is
99 * responsible for destroying the message with ofpbuf_delete(). On
100 * failure, returns a positive errno value and stores a null pointer into
103 * If the connection has been closed in the normal fashion, returns EOF.
105 * The recv function must not block waiting for a packet to arrive. If no
106 * packets have been received, it should return EAGAIN. */
107 int (*recv)(struct vconn *vconn, struct ofpbuf **msgp);
109 /* Tries to queue 'msg' for transmission on 'vconn'. If successful,
110 * returns 0, in which case ownership of 'msg' is transferred to the vconn.
111 * Success does not guarantee that 'msg' has been or ever will be delivered
112 * to the peer, only that it has been queued for transmission.
114 * Returns a positive errno value on failure, in which case the caller
115 * retains ownership of 'msg'.
117 * The send function must not block. If 'msg' cannot be immediately
118 * accepted for transmission, it should return EAGAIN. */
119 int (*send)(struct vconn *vconn, struct ofpbuf *msg);
121 /* Arranges for the poll loop to wake up when 'vconn' is ready to take an
122 * action of the given 'type'. */
123 void (*wait)(struct vconn *vconn, enum vconn_wait_type type);
126 /* Passive virtual connection to an OpenFlow device.
128 * This structure should be treated as opaque by vconn implementations. */
130 struct pvconn_class *class;
134 void pvconn_init(struct pvconn *, struct pvconn_class *, const char *name);
135 static inline void pvconn_assert_class(const struct pvconn *pvconn,
136 const struct pvconn_class *class)
138 assert(pvconn->class == class);
141 struct pvconn_class {
142 /* Prefix for connection names, e.g. "ptcp", "pssl". */
145 /* Attempts to start listening for OpenFlow connections. 'name' is the
146 * full connection name provided by the user, e.g. "nl:0", "tcp:1.2.3.4".
147 * This name is useful for error messages but must not be modified.
149 * 'suffix' is a copy of 'name' following the colon and may be modified.
151 * Returns 0 if successful, otherwise a positive errno value. If
152 * successful, stores a pointer to the new connection in '*pvconnp'.
154 * The listen function must not block. If the connection cannot be
155 * completed immediately, it should return EAGAIN (not EINPROGRESS, as
156 * returned by the connect system call) and continue the connection in the
158 int (*listen)(const char *name, char *suffix, struct pvconn **pvconnp);
160 /* Closes 'pvconn' and frees associated memory. */
161 void (*close)(struct pvconn *pvconn);
163 /* Tries to accept a new connection on 'pvconn'. If successful, stores the
164 * new connection in '*new_vconnp' and returns 0. Otherwise, returns a
165 * positive errno value.
167 * The accept function must not block waiting for a connection. If no
168 * connection is ready to be accepted, it should return EAGAIN. */
169 int (*accept)(struct pvconn *pvconn, struct vconn **new_vconnp);
171 /* Arranges for the poll loop to wake up when a connection is ready to be
172 * accepted on 'pvconn'. */
173 void (*wait)(struct pvconn *pvconn);
176 /* Active and passive vconn classes. */
177 extern struct vconn_class tcp_vconn_class;
178 extern struct pvconn_class ptcp_pvconn_class;
179 extern struct vconn_class unix_vconn_class;
180 extern struct pvconn_class punix_pvconn_class;
182 extern struct vconn_class ssl_vconn_class;
183 extern struct pvconn_class pssl_pvconn_class;
186 extern struct vconn_class netlink_vconn_class;
189 #endif /* vconn-provider.h */