ofp-util: Work on decoding OF1.1 flow_mods.
[openvswitch] / lib / rconn.h
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012 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 RCONN_H
18 #define RCONN_H 1
19
20 #include <stdbool.h>
21 #include <stdint.h>
22 #include <time.h>
23 #include "openvswitch/types.h"
24
25 /* A wrapper around vconn that provides queuing and optionally reliability.
26  *
27  * An rconn maintains a message transmission queue of bounded length specified
28  * by the caller.  The rconn does not guarantee reliable delivery of
29  * queued messages: all queued messages are dropped when reconnection becomes
30  * necessary.
31  *
32  * An rconn optionally provides reliable communication, in this sense: the
33  * rconn will re-connect, with exponential backoff, when the underlying vconn
34  * disconnects.
35  */
36
37 struct vconn;
38 struct rconn_packet_counter;
39
40 struct rconn *rconn_create(int inactivity_probe_interval,
41                            int max_backoff, uint8_t dscp);
42 void rconn_set_dscp(struct rconn *rc, uint8_t dscp);
43 uint8_t rconn_get_dscp(const struct rconn *rc);
44 void rconn_set_max_backoff(struct rconn *, int max_backoff);
45 int rconn_get_max_backoff(const struct rconn *);
46 void rconn_set_probe_interval(struct rconn *, int inactivity_probe_interval);
47 int rconn_get_probe_interval(const struct rconn *);
48
49 void rconn_connect(struct rconn *, const char *target, const char *name);
50 void rconn_connect_unreliably(struct rconn *,
51                               struct vconn *, const char *name);
52 void rconn_reconnect(struct rconn *);
53 void rconn_disconnect(struct rconn *);
54 void rconn_destroy(struct rconn *);
55
56 void rconn_run(struct rconn *);
57 void rconn_run_wait(struct rconn *);
58 struct ofpbuf *rconn_recv(struct rconn *);
59 void rconn_recv_wait(struct rconn *);
60 int rconn_send(struct rconn *, struct ofpbuf *, struct rconn_packet_counter *);
61 int rconn_send_with_limit(struct rconn *, struct ofpbuf *,
62                           struct rconn_packet_counter *, int queue_limit);
63 unsigned int rconn_packets_sent(const struct rconn *);
64 unsigned int rconn_packets_received(const struct rconn *);
65
66 void rconn_add_monitor(struct rconn *, struct vconn *);
67
68 const char *rconn_get_name(const struct rconn *);
69 void rconn_set_name(struct rconn *, const char *new_name);
70 const char *rconn_get_target(const struct rconn *);
71
72 bool rconn_is_alive(const struct rconn *);
73 bool rconn_is_connected(const struct rconn *);
74 bool rconn_is_admitted(const struct rconn *);
75 int rconn_failure_duration(const struct rconn *);
76
77 ovs_be32 rconn_get_remote_ip(const struct rconn *);
78 ovs_be16 rconn_get_remote_port(const struct rconn *);
79 ovs_be32 rconn_get_local_ip(const struct rconn *);
80 ovs_be16 rconn_get_local_port(const struct rconn *);
81 int rconn_get_version(const struct rconn *);
82
83 const char *rconn_get_state(const struct rconn *);
84 unsigned int rconn_get_attempted_connections(const struct rconn *);
85 unsigned int rconn_get_successful_connections(const struct rconn *);
86 time_t rconn_get_last_connection(const struct rconn *);
87 time_t rconn_get_last_disconnect(const struct rconn *);
88 time_t rconn_get_last_received(const struct rconn *);
89 time_t rconn_get_creation_time(const struct rconn *);
90 unsigned long int rconn_get_total_time_connected(const struct rconn *);
91 int rconn_get_backoff(const struct rconn *);
92 unsigned int rconn_get_state_elapsed(const struct rconn *);
93 unsigned int rconn_get_connection_seqno(const struct rconn *);
94 int rconn_get_last_error(const struct rconn *);
95 unsigned int rconn_count_txqlen(const struct rconn *);
96
97 /* Counts packets and bytes queued into an rconn by a given source. */
98 struct rconn_packet_counter {
99     unsigned int n_packets;     /* Number of packets queued. */
100     unsigned int n_bytes;       /* Number of bytes queued. */
101     int ref_cnt;                /* Number of owners. */
102 };
103
104 struct rconn_packet_counter *rconn_packet_counter_create(void);
105 void rconn_packet_counter_destroy(struct rconn_packet_counter *);
106 void rconn_packet_counter_inc(struct rconn_packet_counter *, unsigned n_bytes);
107 void rconn_packet_counter_dec(struct rconn_packet_counter *, unsigned n_bytes);
108
109 #endif /* rconn.h */