]> git.proxmox.com Git - ovs.git/blame - lib/rconn.h
debian: Don't require ipsec_local_ip to configure IPsec
[ovs.git] / lib / rconn.h
CommitLineData
064af421 1/*
88a20d6e 2 * Copyright (c) 2008, 2009, 2010 Nicira Networks.
064af421 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 RCONN_H
18#define RCONN_H 1
19
064af421
BP
20#include <stdbool.h>
21#include <stdint.h>
22#include <time.h>
23
24/* A wrapper around vconn that provides queuing and optionally reliability.
25 *
26 * An rconn maintains a message transmission queue of bounded length specified
27 * by the caller. The rconn does not guarantee reliable delivery of
28 * queued messages: all queued messages are dropped when reconnection becomes
29 * necessary.
30 *
31 * An rconn optionally provides reliable communication, in this sense: the
32 * rconn will re-connect, with exponential backoff, when the underlying vconn
33 * disconnects.
34 */
35
36struct vconn;
37struct rconn_packet_counter;
38
064af421
BP
39struct rconn *rconn_create(int inactivity_probe_interval, int max_backoff);
40
41void rconn_set_max_backoff(struct rconn *, int max_backoff);
42int rconn_get_max_backoff(const struct rconn *);
43void rconn_set_probe_interval(struct rconn *, int inactivity_probe_interval);
44int rconn_get_probe_interval(const struct rconn *);
45
eb15cdbb
BP
46void rconn_connect(struct rconn *, const char *target, const char *name);
47void rconn_connect_unreliably(struct rconn *,
48 struct vconn *, const char *name);
064af421
BP
49void rconn_reconnect(struct rconn *);
50void rconn_disconnect(struct rconn *);
51void rconn_destroy(struct rconn *);
52
53void rconn_run(struct rconn *);
54void rconn_run_wait(struct rconn *);
55struct ofpbuf *rconn_recv(struct rconn *);
56void rconn_recv_wait(struct rconn *);
57int rconn_send(struct rconn *, struct ofpbuf *, struct rconn_packet_counter *);
58int rconn_send_with_limit(struct rconn *, struct ofpbuf *,
59 struct rconn_packet_counter *, int queue_limit);
60unsigned int rconn_packets_sent(const struct rconn *);
61unsigned int rconn_packets_received(const struct rconn *);
62
63void rconn_add_monitor(struct rconn *, struct vconn *);
64
65const char *rconn_get_name(const struct rconn *);
eb15cdbb
BP
66void rconn_set_name(struct rconn *, const char *new_name);
67const char *rconn_get_target(const struct rconn *);
68
064af421
BP
69bool rconn_is_alive(const struct rconn *);
70bool rconn_is_connected(const struct rconn *);
7778bd15 71bool rconn_is_admitted(const struct rconn *);
064af421
BP
72int rconn_failure_duration(const struct rconn *);
73bool rconn_is_connectivity_questionable(struct rconn *);
74
193456d5
JP
75uint32_t rconn_get_remote_ip(const struct rconn *);
76uint16_t rconn_get_remote_port(const struct rconn *);
77uint32_t rconn_get_local_ip(const struct rconn *);
78uint16_t rconn_get_local_port(const struct rconn *);
064af421
BP
79
80const char *rconn_get_state(const struct rconn *);
81unsigned int rconn_get_attempted_connections(const struct rconn *);
82unsigned int rconn_get_successful_connections(const struct rconn *);
83time_t rconn_get_last_connection(const struct rconn *);
7df824b7 84time_t rconn_get_last_received(const struct rconn *);
064af421
BP
85time_t rconn_get_creation_time(const struct rconn *);
86unsigned long int rconn_get_total_time_connected(const struct rconn *);
87int rconn_get_backoff(const struct rconn *);
88unsigned int rconn_get_state_elapsed(const struct rconn *);
89unsigned int rconn_get_connection_seqno(const struct rconn *);
88a20d6e 90int rconn_get_last_error(const struct rconn *);
064af421
BP
91
92/* Counts the number of packets queued into an rconn by a given source. */
93struct rconn_packet_counter {
94 int n; /* Number of packets queued. */
95 int ref_cnt; /* Number of owners. */
96};
97
98struct rconn_packet_counter *rconn_packet_counter_create(void);
99void rconn_packet_counter_destroy(struct rconn_packet_counter *);
100void rconn_packet_counter_inc(struct rconn_packet_counter *);
101void rconn_packet_counter_dec(struct rconn_packet_counter *);
102
103static inline int
104rconn_packet_counter_read(const struct rconn_packet_counter *counter)
105{
106 return counter->n;
107}
108
109#endif /* rconn.h */