]> git.proxmox.com Git - mirror_ovs.git/blame - lib/rconn.h
netdev-linux, netdev-bsd: Make access to AF_INET socket thread-safe.
[mirror_ovs.git] / lib / rconn.h
CommitLineData
064af421 1/*
0d085684 2 * Copyright (c) 2008, 2009, 2010, 2011, 2012 Nicira, Inc.
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>
dbba996b 23#include "openvswitch/types.h"
064af421
BP
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
37struct vconn;
38struct rconn_packet_counter;
39
f125905c 40struct rconn *rconn_create(int inactivity_probe_interval,
6042457b
SH
41 int max_backoff, uint8_t dscp,
42 uint32_t allowed_versions);
f125905c 43void rconn_set_dscp(struct rconn *rc, uint8_t dscp);
e182670b 44uint32_t rconn_get_allowed_versions(const struct rconn *);
0442efd9 45uint8_t rconn_get_dscp(const struct rconn *rc);
064af421
BP
46void rconn_set_max_backoff(struct rconn *, int max_backoff);
47int rconn_get_max_backoff(const struct rconn *);
48void rconn_set_probe_interval(struct rconn *, int inactivity_probe_interval);
49int rconn_get_probe_interval(const struct rconn *);
50
eb15cdbb
BP
51void rconn_connect(struct rconn *, const char *target, const char *name);
52void rconn_connect_unreliably(struct rconn *,
53 struct vconn *, const char *name);
064af421
BP
54void rconn_reconnect(struct rconn *);
55void rconn_disconnect(struct rconn *);
56void rconn_destroy(struct rconn *);
57
58void rconn_run(struct rconn *);
59void rconn_run_wait(struct rconn *);
60struct ofpbuf *rconn_recv(struct rconn *);
61void rconn_recv_wait(struct rconn *);
62int rconn_send(struct rconn *, struct ofpbuf *, struct rconn_packet_counter *);
63int rconn_send_with_limit(struct rconn *, struct ofpbuf *,
64 struct rconn_packet_counter *, int queue_limit);
65unsigned int rconn_packets_sent(const struct rconn *);
66unsigned int rconn_packets_received(const struct rconn *);
67
68void rconn_add_monitor(struct rconn *, struct vconn *);
69
70const char *rconn_get_name(const struct rconn *);
eb15cdbb
BP
71void rconn_set_name(struct rconn *, const char *new_name);
72const char *rconn_get_target(const struct rconn *);
73
064af421
BP
74bool rconn_is_alive(const struct rconn *);
75bool rconn_is_connected(const struct rconn *);
7778bd15 76bool rconn_is_admitted(const struct rconn *);
064af421 77int rconn_failure_duration(const struct rconn *);
064af421 78
dbba996b
BP
79ovs_be32 rconn_get_remote_ip(const struct rconn *);
80ovs_be16 rconn_get_remote_port(const struct rconn *);
81ovs_be32 rconn_get_local_ip(const struct rconn *);
82ovs_be16 rconn_get_local_port(const struct rconn *);
27527aa0 83int rconn_get_version(const struct rconn *);
064af421
BP
84
85const char *rconn_get_state(const struct rconn *);
064af421 86time_t rconn_get_last_connection(const struct rconn *);
2cdcb898 87time_t rconn_get_last_disconnect(const struct rconn *);
064af421 88unsigned int rconn_get_connection_seqno(const struct rconn *);
88a20d6e 89int rconn_get_last_error(const struct rconn *);
0d085684 90unsigned int rconn_count_txqlen(const struct rconn *);
064af421 91
a6441685 92/* Counts packets and bytes queued into an rconn by a given source. */
064af421 93struct rconn_packet_counter {
a6441685
BP
94 unsigned int n_packets; /* Number of packets queued. */
95 unsigned int n_bytes; /* Number of bytes queued. */
064af421
BP
96 int ref_cnt; /* Number of owners. */
97};
98
99struct rconn_packet_counter *rconn_packet_counter_create(void);
100void rconn_packet_counter_destroy(struct rconn_packet_counter *);
a6441685
BP
101void rconn_packet_counter_inc(struct rconn_packet_counter *, unsigned n_bytes);
102void rconn_packet_counter_dec(struct rconn_packet_counter *, unsigned n_bytes);
064af421
BP
103
104#endif /* rconn.h */