]> git.proxmox.com Git - ovs.git/blame - lib/vconn.h
Update primary code license to Apache 2.0.
[ovs.git] / lib / vconn.h
CommitLineData
064af421
BP
1/*
2 * Copyright (c) 2008, 2009 Nicira Networks.
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_H
18#define VCONN_H 1
19
20#include <assert.h>
21#include <stdbool.h>
22#include <stddef.h>
23#include <stdint.h>
24
25#include "flow.h"
26
27struct ofpbuf;
28struct ofp_action_header;
29struct ofp_header;
30struct ofp_match;
31struct ofp_stats_reply;
32struct pvconn;
33struct vconn;
34
35void vconn_usage(bool active, bool passive, bool bootstrap);
36
37/* Active vconns: virtual connections to OpenFlow devices. */
38int vconn_open(const char *name, int min_version, struct vconn **);
39void vconn_close(struct vconn *);
40const char *vconn_get_name(const struct vconn *);
41uint32_t vconn_get_ip(const struct vconn *);
42int vconn_connect(struct vconn *);
43int vconn_recv(struct vconn *, struct ofpbuf **);
44int vconn_send(struct vconn *, struct ofpbuf *);
45int vconn_recv_xid(struct vconn *, uint32_t xid, struct ofpbuf **);
46int vconn_transact(struct vconn *, struct ofpbuf *, struct ofpbuf **);
47
48int vconn_open_block(const char *name, int min_version, struct vconn **);
49int vconn_send_block(struct vconn *, struct ofpbuf *);
50int vconn_recv_block(struct vconn *, struct ofpbuf **);
51
52enum vconn_wait_type {
53 WAIT_CONNECT,
54 WAIT_RECV,
55 WAIT_SEND
56};
57void vconn_wait(struct vconn *, enum vconn_wait_type);
58void vconn_connect_wait(struct vconn *);
59void vconn_recv_wait(struct vconn *);
60void vconn_send_wait(struct vconn *);
61
62/* Passive vconns: virtual listeners for incoming OpenFlow connections. */
63int pvconn_open(const char *name, struct pvconn **);
64const char *pvconn_get_name(const struct pvconn *);
65void pvconn_close(struct pvconn *);
66int pvconn_accept(struct pvconn *, int min_version, struct vconn **);
67void pvconn_wait(struct pvconn *);
68
69/* OpenFlow protocol utility functions. */
70void *make_openflow(size_t openflow_len, uint8_t type, struct ofpbuf **);
71void *make_openflow_xid(size_t openflow_len, uint8_t type,
72 uint32_t xid, struct ofpbuf **);
73void *put_openflow(size_t openflow_len, uint8_t type, struct ofpbuf *);
74void *put_openflow_xid(size_t openflow_len, uint8_t type, uint32_t xid,
75 struct ofpbuf *);
76void update_openflow_length(struct ofpbuf *);
77struct ofpbuf *make_flow_mod(uint16_t command, const flow_t *,
78 size_t actions_len);
79struct ofpbuf *make_add_flow(const flow_t *, uint32_t buffer_id,
80 uint16_t max_idle, size_t actions_len);
81struct ofpbuf *make_del_flow(const flow_t *);
82struct ofpbuf *make_add_simple_flow(const flow_t *,
83 uint32_t buffer_id, uint16_t out_port,
84 uint16_t max_idle);
85struct ofpbuf *make_packet_out(const struct ofpbuf *packet, uint32_t buffer_id,
86 uint16_t in_port,
87 const struct ofp_action_header *,
88 size_t n_actions);
89struct ofpbuf *make_buffered_packet_out(uint32_t buffer_id,
90 uint16_t in_port, uint16_t out_port);
91struct ofpbuf *make_unbuffered_packet_out(const struct ofpbuf *packet,
92 uint16_t in_port, uint16_t out_port);
93struct ofpbuf *make_echo_request(void);
94struct ofpbuf *make_echo_reply(const struct ofp_header *rq);
95int check_ofp_message(const struct ofp_header *, uint8_t type, size_t size);
96int check_ofp_message_array(const struct ofp_header *, uint8_t type,
97 size_t size, size_t array_elt_size,
98 size_t *n_array_elts);
99int check_ofp_packet_out(const struct ofp_header *, struct ofpbuf *data,
100 int *n_actions, int max_ports);
101
102struct flow_stats_iterator {
103 const uint8_t *pos, *end;
104};
105const struct ofp_flow_stats *flow_stats_first(struct flow_stats_iterator *,
106 const struct ofp_stats_reply *);
107const struct ofp_flow_stats *flow_stats_next(struct flow_stats_iterator *);
108
109struct actions_iterator {
110 const union ofp_action *pos, *end;
111};
112const union ofp_action *actions_first(struct actions_iterator *,
113 const union ofp_action *,
114 size_t n_actions);
115const union ofp_action *actions_next(struct actions_iterator *);
116int validate_actions(const union ofp_action *, size_t n_actions,
117 int max_ports);
118
119void normalize_match(struct ofp_match *);
120
121static inline int
122ofp_mkerr(uint16_t type, uint16_t code)
123{
124 assert(type > 0 && type <= 0x7fff);
125 return (type << 16) | code;
126}
127
128#endif /* vconn.h */