2 * Copyright (c) 2008, 2009 Nicira Networks.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
28 struct ofp_action_header;
31 struct ofp_stats_reply;
35 void vconn_usage(bool active, bool passive, bool bootstrap);
37 /* Active vconns: virtual connections to OpenFlow devices. */
38 int vconn_open(const char *name, int min_version, struct vconn **);
39 void vconn_close(struct vconn *);
40 const char *vconn_get_name(const struct vconn *);
41 uint32_t vconn_get_ip(const struct vconn *);
42 int vconn_connect(struct vconn *);
43 int vconn_recv(struct vconn *, struct ofpbuf **);
44 int vconn_send(struct vconn *, struct ofpbuf *);
45 int vconn_recv_xid(struct vconn *, uint32_t xid, struct ofpbuf **);
46 int vconn_transact(struct vconn *, struct ofpbuf *, struct ofpbuf **);
48 int vconn_open_block(const char *name, int min_version, struct vconn **);
49 int vconn_send_block(struct vconn *, struct ofpbuf *);
50 int vconn_recv_block(struct vconn *, struct ofpbuf **);
52 enum vconn_wait_type {
57 void vconn_wait(struct vconn *, enum vconn_wait_type);
58 void vconn_connect_wait(struct vconn *);
59 void vconn_recv_wait(struct vconn *);
60 void vconn_send_wait(struct vconn *);
62 /* Passive vconns: virtual listeners for incoming OpenFlow connections. */
63 int pvconn_open(const char *name, struct pvconn **);
64 const char *pvconn_get_name(const struct pvconn *);
65 void pvconn_close(struct pvconn *);
66 int pvconn_accept(struct pvconn *, int min_version, struct vconn **);
67 void pvconn_wait(struct pvconn *);
69 /* OpenFlow protocol utility functions. */
70 void *make_openflow(size_t openflow_len, uint8_t type, struct ofpbuf **);
71 void *make_openflow_xid(size_t openflow_len, uint8_t type,
72 uint32_t xid, struct ofpbuf **);
73 void *put_openflow(size_t openflow_len, uint8_t type, struct ofpbuf *);
74 void *put_openflow_xid(size_t openflow_len, uint8_t type, uint32_t xid,
76 void update_openflow_length(struct ofpbuf *);
77 struct ofpbuf *make_flow_mod(uint16_t command, const flow_t *,
79 struct ofpbuf *make_add_flow(const flow_t *, uint32_t buffer_id,
80 uint16_t max_idle, size_t actions_len);
81 struct ofpbuf *make_del_flow(const flow_t *);
82 struct ofpbuf *make_add_simple_flow(const flow_t *,
83 uint32_t buffer_id, uint16_t out_port,
85 struct ofpbuf *make_packet_out(const struct ofpbuf *packet, uint32_t buffer_id,
87 const struct ofp_action_header *,
89 struct ofpbuf *make_buffered_packet_out(uint32_t buffer_id,
90 uint16_t in_port, uint16_t out_port);
91 struct ofpbuf *make_unbuffered_packet_out(const struct ofpbuf *packet,
92 uint16_t in_port, uint16_t out_port);
93 struct ofpbuf *make_echo_request(void);
94 struct ofpbuf *make_echo_reply(const struct ofp_header *rq);
95 int check_ofp_message(const struct ofp_header *, uint8_t type, size_t size);
96 int 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);
99 int check_ofp_packet_out(const struct ofp_header *, struct ofpbuf *data,
100 int *n_actions, int max_ports);
102 struct flow_stats_iterator {
103 const uint8_t *pos, *end;
105 const struct ofp_flow_stats *flow_stats_first(struct flow_stats_iterator *,
106 const struct ofp_stats_reply *);
107 const struct ofp_flow_stats *flow_stats_next(struct flow_stats_iterator *);
109 struct actions_iterator {
110 const union ofp_action *pos, *end;
112 const union ofp_action *actions_first(struct actions_iterator *,
113 const union ofp_action *,
115 const union ofp_action *actions_next(struct actions_iterator *);
116 int validate_actions(const union ofp_action *, size_t n_actions,
119 void normalize_match(struct ofp_match *);
122 ofp_mkerr(uint16_t type, uint16_t code)
124 assert(type > 0 && type <= 0x7fff);
125 return (type << 16) | code;