lib: Move vconn.h to <openvswitch/vconn.h>
[cascardo/ovs.git] / include / openvswitch / vconn.h
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 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 OPENVSWITCH_VCONN_H
18 #define OPENVSWITCH_VCONN_H 1
19
20 #include <stdbool.h>
21 #include <openvswitch/list.h>
22 #include <openvswitch/types.h>
23 #include <openflow/openflow.h>
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 struct ofpbuf;
30 struct vconn_class;
31 struct pvconn_class;
32
33 /* This structure should be treated as opaque by vconn implementations. */
34 struct vconn {
35     const struct vconn_class *class;
36     int state;
37     int error;
38
39     /* OpenFlow versions. */
40     uint32_t allowed_versions;  /* Bitmap of versions we will accept. */
41     uint32_t peer_versions;     /* Peer's bitmap of versions it will accept. */
42     enum ofp_version version;   /* Negotiated version (or 0). */
43     bool recv_any_version;      /* True to receive a message of any version. */
44
45     char *name;
46 };
47
48 void vconn_usage(bool active, bool passive, bool bootstrap);
49
50 /* Active vconns: virtual connections to OpenFlow devices. */
51 int vconn_verify_name(const char *name);
52 int vconn_open(const char *name, uint32_t allowed_versions, uint8_t dscp,
53                struct vconn **vconnp);
54 void vconn_close(struct vconn *);
55 const char *vconn_get_name(const struct vconn *);
56
57 uint32_t vconn_get_allowed_versions(const struct vconn *vconn);
58 void vconn_set_allowed_versions(struct vconn *vconn,
59                                 uint32_t allowed_versions);
60 int vconn_get_version(const struct vconn *);
61 void vconn_set_recv_any_version(struct vconn *);
62
63 int vconn_connect(struct vconn *);
64 int vconn_recv(struct vconn *, struct ofpbuf **);
65 int vconn_send(struct vconn *, struct ofpbuf *);
66 int vconn_recv_xid(struct vconn *, ovs_be32 xid, struct ofpbuf **);
67 int vconn_transact(struct vconn *, struct ofpbuf *, struct ofpbuf **);
68 int vconn_transact_noreply(struct vconn *, struct ofpbuf *, struct ofpbuf **);
69 int vconn_transact_multiple_noreply(struct vconn *, struct ovs_list *requests,
70                                     struct ofpbuf **replyp);
71
72 void vconn_run(struct vconn *);
73 void vconn_run_wait(struct vconn *);
74
75 int vconn_get_status(const struct vconn *);
76
77 int vconn_open_block(const char *name, uint32_t allowed_versions, uint8_t dscp,
78                      struct vconn **);
79 int vconn_connect_block(struct vconn *);
80 int vconn_send_block(struct vconn *, struct ofpbuf *);
81 int vconn_recv_block(struct vconn *, struct ofpbuf **);
82
83 enum vconn_wait_type {
84     WAIT_CONNECT,
85     WAIT_RECV,
86     WAIT_SEND
87 };
88 void vconn_wait(struct vconn *, enum vconn_wait_type);
89 void vconn_connect_wait(struct vconn *);
90 void vconn_recv_wait(struct vconn *);
91 void vconn_send_wait(struct vconn *);
92
93 /* Passive vconns: virtual listeners for incoming OpenFlow connections.
94  *
95  * This structure should be treated as opaque by vconn implementations. */
96 struct pvconn {
97     const struct pvconn_class *class;
98     char *name;
99     uint32_t allowed_versions;
100 };
101 int pvconn_verify_name(const char *name);
102 int pvconn_open(const char *name, uint32_t allowed_versions, uint8_t dscp,
103                 struct pvconn **pvconnp);
104 const char *pvconn_get_name(const struct pvconn *);
105 void pvconn_close(struct pvconn *);
106 int pvconn_accept(struct pvconn *, struct vconn **);
107 void pvconn_wait(struct pvconn *);
108
109 #ifdef __cplusplus
110 }
111 #endif
112
113 #endif /* vconn.h */