]>
Commit | Line | Data |
---|---|---|
064af421 | 1 | /* |
a3d1ff00 | 2 | * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 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" |
a3d1ff00 | 24 | #include "ovs-thread.h" |
064af421 BP |
25 | |
26 | /* A wrapper around vconn that provides queuing and optionally reliability. | |
27 | * | |
28 | * An rconn maintains a message transmission queue of bounded length specified | |
29 | * by the caller. The rconn does not guarantee reliable delivery of | |
30 | * queued messages: all queued messages are dropped when reconnection becomes | |
31 | * necessary. | |
32 | * | |
33 | * An rconn optionally provides reliable communication, in this sense: the | |
34 | * rconn will re-connect, with exponential backoff, when the underlying vconn | |
35 | * disconnects. | |
9f5e8906 BP |
36 | * |
37 | * | |
38 | * Thread-safety | |
39 | * ============= | |
40 | * | |
41 | * Fully thread-safe. | |
064af421 BP |
42 | */ |
43 | ||
44 | struct vconn; | |
45 | struct rconn_packet_counter; | |
46 | ||
f125905c | 47 | struct rconn *rconn_create(int inactivity_probe_interval, |
6042457b SH |
48 | int max_backoff, uint8_t dscp, |
49 | uint32_t allowed_versions); | |
f125905c | 50 | void rconn_set_dscp(struct rconn *rc, uint8_t dscp); |
e182670b | 51 | uint32_t rconn_get_allowed_versions(const struct rconn *); |
0442efd9 | 52 | uint8_t rconn_get_dscp(const struct rconn *rc); |
064af421 BP |
53 | void rconn_set_max_backoff(struct rconn *, int max_backoff); |
54 | int rconn_get_max_backoff(const struct rconn *); | |
55 | void rconn_set_probe_interval(struct rconn *, int inactivity_probe_interval); | |
56 | int rconn_get_probe_interval(const struct rconn *); | |
57 | ||
eb15cdbb BP |
58 | void rconn_connect(struct rconn *, const char *target, const char *name); |
59 | void rconn_connect_unreliably(struct rconn *, | |
60 | struct vconn *, const char *name); | |
064af421 BP |
61 | void rconn_reconnect(struct rconn *); |
62 | void rconn_disconnect(struct rconn *); | |
63 | void rconn_destroy(struct rconn *); | |
64 | ||
65 | void rconn_run(struct rconn *); | |
66 | void rconn_run_wait(struct rconn *); | |
67 | struct ofpbuf *rconn_recv(struct rconn *); | |
68 | void rconn_recv_wait(struct rconn *); | |
69 | int rconn_send(struct rconn *, struct ofpbuf *, struct rconn_packet_counter *); | |
70 | int rconn_send_with_limit(struct rconn *, struct ofpbuf *, | |
71 | struct rconn_packet_counter *, int queue_limit); | |
72 | unsigned int rconn_packets_sent(const struct rconn *); | |
73 | unsigned int rconn_packets_received(const struct rconn *); | |
74 | ||
75 | void rconn_add_monitor(struct rconn *, struct vconn *); | |
76 | ||
77 | const char *rconn_get_name(const struct rconn *); | |
eb15cdbb BP |
78 | void rconn_set_name(struct rconn *, const char *new_name); |
79 | const char *rconn_get_target(const struct rconn *); | |
80 | ||
064af421 BP |
81 | bool rconn_is_alive(const struct rconn *); |
82 | bool rconn_is_connected(const struct rconn *); | |
7778bd15 | 83 | bool rconn_is_admitted(const struct rconn *); |
064af421 | 84 | int rconn_failure_duration(const struct rconn *); |
064af421 | 85 | |
dbba996b BP |
86 | ovs_be32 rconn_get_remote_ip(const struct rconn *); |
87 | ovs_be16 rconn_get_remote_port(const struct rconn *); | |
88 | ovs_be32 rconn_get_local_ip(const struct rconn *); | |
89 | ovs_be16 rconn_get_local_port(const struct rconn *); | |
27527aa0 | 90 | int rconn_get_version(const struct rconn *); |
064af421 BP |
91 | |
92 | const char *rconn_get_state(const struct rconn *); | |
064af421 | 93 | time_t rconn_get_last_connection(const struct rconn *); |
2cdcb898 | 94 | time_t rconn_get_last_disconnect(const struct rconn *); |
064af421 | 95 | unsigned int rconn_get_connection_seqno(const struct rconn *); |
88a20d6e | 96 | int rconn_get_last_error(const struct rconn *); |
0d085684 | 97 | unsigned int rconn_count_txqlen(const struct rconn *); |
064af421 | 98 | |
a6441685 | 99 | /* Counts packets and bytes queued into an rconn by a given source. */ |
064af421 | 100 | struct rconn_packet_counter { |
a3d1ff00 BP |
101 | struct ovs_mutex mutex; |
102 | unsigned int n_packets OVS_GUARDED; /* Number of packets queued. */ | |
103 | unsigned int n_bytes OVS_GUARDED; /* Number of bytes queued. */ | |
104 | int ref_cnt OVS_GUARDED; /* Number of owners. */ | |
064af421 BP |
105 | }; |
106 | ||
107 | struct rconn_packet_counter *rconn_packet_counter_create(void); | |
108 | void rconn_packet_counter_destroy(struct rconn_packet_counter *); | |
a6441685 BP |
109 | void rconn_packet_counter_inc(struct rconn_packet_counter *, unsigned n_bytes); |
110 | void rconn_packet_counter_dec(struct rconn_packet_counter *, unsigned n_bytes); | |
064af421 | 111 | |
a3d1ff00 BP |
112 | unsigned int rconn_packet_counter_n_packets( |
113 | const struct rconn_packet_counter *); | |
114 | unsigned int rconn_packet_counter_n_bytes(const struct rconn_packet_counter *); | |
115 | ||
064af421 | 116 | #endif /* rconn.h */ |