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