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 * This structure should be treated as opaque by vconn implementations. */
47 struct vconn_class *class;
53 void vconn_init(struct vconn *, struct vconn_class *, int connect_status,
54 uint32_t ip, const char *name);
55 static inline void vconn_assert_class(const struct vconn *vconn,
56 const struct vconn_class *class)
58 assert(vconn->class == class);
62 /* Prefix for connection names, e.g. "nl", "tcp". */
65 /* Attempts to connect to an OpenFlow device. 'name' is the full
66 * connection name provided by the user, e.g. "nl:0", "tcp:1.2.3.4". This
67 * name is useful for error messages but must not be modified.
69 * 'suffix' is a copy of 'name' following the colon and may be modified.
71 * Returns 0 if successful, otherwise a positive errno value. If
72 * successful, stores a pointer to the new connection in '*vconnp'.
74 * The open function must not block waiting for a connection to complete.
75 * If the connection cannot be completed immediately, it should return
76 * EAGAIN (not EINPROGRESS, as returned by the connect system call) and
77 * continue the connection in the background. */
78 int (*open)(const char *name, char *suffix, struct vconn **vconnp);
80 /* Closes 'vconn' and frees associated memory. */
81 void (*close)(struct vconn *vconn);
83 /* Tries to complete the connection on 'vconn'. If 'vconn''s connection is
84 * complete, returns 0 if the connection was successful or a positive errno
85 * value if it failed. If the connection is still in progress, returns
88 * The connect function must not block waiting for the connection to
89 * complete; instead, it should return EAGAIN immediately. */
90 int (*connect)(struct vconn *vconn);
92 /* Tries to receive an OpenFlow message from 'vconn'. If successful,
93 * stores the received message into '*msgp' and returns 0. The caller is
94 * responsible for destroying the message with buffer_delete(). On
95 * failure, returns a positive errno value and stores a null pointer into
98 * If the connection has been closed in the normal fashion, returns EOF.
100 * The recv function must not block waiting for a packet to arrive. If no
101 * packets have been received, it should return EAGAIN. */
102 int (*recv)(struct vconn *vconn, struct buffer **msgp);
104 /* Tries to queue 'msg' for transmission on 'vconn'. If successful,
105 * returns 0, in which case ownership of 'msg' is transferred to the vconn.
106 * Success does not guarantee that 'msg' has been or ever will be delivered
107 * to the peer, only that it has been queued for transmission.
109 * Returns a positive errno value on failure, in which case the caller
110 * retains ownership of 'msg'.
112 * The send function must not block. If 'msg' cannot be immediately
113 * accepted for transmission, it should return EAGAIN. */
114 int (*send)(struct vconn *vconn, struct buffer *msg);
116 /* Arranges for the poll loop to wake up when 'vconn' is ready to take an
117 * action of the given 'type'. */
118 void (*wait)(struct vconn *vconn, enum vconn_wait_type type);
121 /* Passive virtual connection to an OpenFlow device.
123 * This structure should be treated as opaque by vconn implementations. */
125 struct pvconn_class *class;
129 void pvconn_init(struct pvconn *, struct pvconn_class *, const char *name);
130 static inline void pvconn_assert_class(const struct pvconn *pvconn,
131 const struct pvconn_class *class)
133 assert(pvconn->class == class);
136 struct pvconn_class {
137 /* Prefix for connection names, e.g. "ptcp", "pssl". */
140 /* Attempts to start listening for OpenFlow connections. 'name' is the
141 * full connection name provided by the user, e.g. "nl:0", "tcp:1.2.3.4".
142 * This name is useful for error messages but must not be modified.
144 * 'suffix' is a copy of 'name' following the colon and may be modified.
146 * Returns 0 if successful, otherwise a positive errno value. If
147 * successful, stores a pointer to the new connection in '*pvconnp'.
149 * The listen function must not block. If the connection cannot be
150 * completed immediately, it should return EAGAIN (not EINPROGRESS, as
151 * returned by the connect system call) and continue the connection in the
153 int (*listen)(const char *name, char *suffix, struct pvconn **pvconnp);
155 /* Closes 'pvconn' and frees associated memory. */
156 void (*close)(struct pvconn *pvconn);
158 /* Tries to accept a new connection on 'pvconn'. If successful, stores the
159 * new connection in '*new_vconnp' and returns 0. Otherwise, returns a
160 * positive errno value.
162 * The accept function must not block waiting for a connection. If no
163 * connection is ready to be accepted, it should return EAGAIN. */
164 int (*accept)(struct pvconn *pvconn, struct vconn **new_vconnp);
166 /* Arranges for the poll loop to wake up when a connection is ready to be
167 * accepted on 'pvconn'. */
168 void (*wait)(struct pvconn *pvconn);
171 /* Active and passive vconn classes. */
172 extern struct vconn_class tcp_vconn_class;
173 extern struct pvconn_class ptcp_pvconn_class;
174 extern struct vconn_class unix_vconn_class;
175 extern struct pvconn_class punix_pvconn_class;
177 extern struct vconn_class ssl_vconn_class;
178 extern struct pvconn_class pssl_pvconn_class;
181 extern struct vconn_class netlink_vconn_class;
184 #endif /* vconn-provider.h */