]> git.proxmox.com Git - mirror_ovs.git/blame - lib/jsonrpc.h
Revert "dpif-netdev: includes microsecond delta in meter bucket calculation".
[mirror_ovs.git] / lib / jsonrpc.h
CommitLineData
f2129093 1/*
8cf6bbb1 2 * Copyright (c) 2009, 2010, 2012, 2013, 2017 Nicira, Inc.
f2129093
BP
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 JSONRPC_H
18#define JSONRPC_H 1
19
20/* This is an implementation of the JSON-RPC 1.0 specification defined at
21 * http://json-rpc.org/wiki/specification. */
22
23#include <stdbool.h>
24#include <stddef.h>
f125905c 25#include "openvswitch/types.h"
f2129093
BP
26
27struct json;
28struct jsonrpc_msg;
0d11f523 29struct pstream;
0b3e7a8b 30struct reconnect_stats;
f2129093 31struct stream;
8cf6bbb1 32struct svec;
f2129093
BP
33\f
34/* API for a JSON-RPC stream. */
35
efc295d2 36/* Default port numbers.
0d11f523 37 *
efc295d2 38 * OVSDB_OLD_PORT defines the original port number used by OVS.
d4763d1d 39 * OVSDB_PORT defines the official port number assigned by IANA. */
efc295d2
JP
40#define OVSDB_OLD_PORT 6632
41#define OVSDB_PORT 6640
0d11f523 42
f125905c
MM
43int jsonrpc_stream_open(const char *name, struct stream **, uint8_t dscp);
44int jsonrpc_pstream_open(const char *name, struct pstream **, uint8_t dscp);
0d11f523 45
f2129093
BP
46struct jsonrpc *jsonrpc_open(struct stream *);
47void jsonrpc_close(struct jsonrpc *);
48
49void jsonrpc_run(struct jsonrpc *);
50void jsonrpc_wait(struct jsonrpc *);
51
f2129093
BP
52int jsonrpc_get_status(const struct jsonrpc *);
53size_t jsonrpc_get_backlog(const struct jsonrpc *);
3a8d38c8 54unsigned int jsonrpc_get_received_bytes(const struct jsonrpc *);
f2129093
BP
55const char *jsonrpc_get_name(const struct jsonrpc *);
56
57int jsonrpc_send(struct jsonrpc *, struct jsonrpc_msg *);
58int jsonrpc_recv(struct jsonrpc *, struct jsonrpc_msg **);
59void jsonrpc_recv_wait(struct jsonrpc *);
60
61int jsonrpc_send_block(struct jsonrpc *, struct jsonrpc_msg *);
62int jsonrpc_recv_block(struct jsonrpc *, struct jsonrpc_msg **);
d0632593
BP
63int jsonrpc_transact_block(struct jsonrpc *, struct jsonrpc_msg *,
64 struct jsonrpc_msg **);
f2129093
BP
65
66/* Messages. */
67enum jsonrpc_msg_type {
68 JSONRPC_REQUEST, /* Request. */
69 JSONRPC_NOTIFY, /* Notification. */
70 JSONRPC_REPLY, /* Successful reply. */
71 JSONRPC_ERROR /* Error reply. */
72};
73
74struct jsonrpc_msg {
75 enum jsonrpc_msg_type type;
76 char *method; /* Request or notification only. */
77 struct json *params; /* Request or notification only. */
78 struct json *result; /* Successful reply only. */
79 struct json *error; /* Error reply only. */
80 struct json *id; /* Request or reply only. */
81};
82
83struct jsonrpc_msg *jsonrpc_create_request(const char *method,
20bed8be
BP
84 struct json *params,
85 struct json **idp);
f2129093
BP
86struct jsonrpc_msg *jsonrpc_create_notify(const char *method,
87 struct json *params);
88struct jsonrpc_msg *jsonrpc_create_reply(struct json *result,
89 const struct json *id);
90struct jsonrpc_msg *jsonrpc_create_error(struct json *error,
91 const struct json *id);
92
1b1d2e6d
BP
93struct jsonrpc_msg *jsonrpc_msg_clone(const struct jsonrpc_msg *);
94
f2129093
BP
95const char *jsonrpc_msg_type_to_string(enum jsonrpc_msg_type);
96char *jsonrpc_msg_is_valid(const struct jsonrpc_msg *);
97void jsonrpc_msg_destroy(struct jsonrpc_msg *);
98
99char *jsonrpc_msg_from_json(struct json *, struct jsonrpc_msg **);
100struct json *jsonrpc_msg_to_json(struct jsonrpc_msg *);
1b1d2e6d
BP
101
102char *jsonrpc_msg_to_string(const struct jsonrpc_msg *);
dcbb691b
BP
103\f
104/* A JSON-RPC session with reconnection. */
105
fba6bd1d 106struct jsonrpc_session *jsonrpc_session_open(const char *name, bool retry);
8cf6bbb1
BP
107struct jsonrpc_session *jsonrpc_session_open_multiple(const struct svec *,
108 bool retry);
e879d33e
MM
109struct jsonrpc_session *jsonrpc_session_open_unreliably(struct jsonrpc *,
110 uint8_t);
dcbb691b
BP
111void jsonrpc_session_close(struct jsonrpc_session *);
112
1b1d2e6d
BP
113struct jsonrpc *jsonrpc_session_steal(struct jsonrpc_session *);
114
dcbb691b
BP
115void jsonrpc_session_run(struct jsonrpc_session *);
116void jsonrpc_session_wait(struct jsonrpc_session *);
117
118size_t jsonrpc_session_get_backlog(const struct jsonrpc_session *);
119const char *jsonrpc_session_get_name(const struct jsonrpc_session *);
8cf6bbb1 120size_t jsonrpc_session_get_n_remotes(const struct jsonrpc_session *);
dcbb691b
BP
121
122int jsonrpc_session_send(struct jsonrpc_session *, struct jsonrpc_msg *);
123struct jsonrpc_msg *jsonrpc_session_recv(struct jsonrpc_session *);
124void jsonrpc_session_recv_wait(struct jsonrpc_session *);
125
4931f33a 126bool jsonrpc_session_is_alive(const struct jsonrpc_session *);
dcbb691b
BP
127bool jsonrpc_session_is_connected(const struct jsonrpc_session *);
128unsigned int jsonrpc_session_get_seqno(const struct jsonrpc_session *);
0b3e7a8b 129int jsonrpc_session_get_status(const struct jsonrpc_session *);
fba6bd1d 130int jsonrpc_session_get_last_error(const struct jsonrpc_session *);
0b3e7a8b
AE
131void jsonrpc_session_get_reconnect_stats(const struct jsonrpc_session *,
132 struct reconnect_stats *);
133
705d7a39 134void jsonrpc_session_enable_reconnect(struct jsonrpc_session *);
dcbb691b 135void jsonrpc_session_force_reconnect(struct jsonrpc_session *);
f2129093 136
94db5407 137void jsonrpc_session_set_max_backoff(struct jsonrpc_session *,
b5f0fe21 138 int max_backoff);
94db5407
BP
139void jsonrpc_session_set_probe_interval(struct jsonrpc_session *,
140 int probe_interval);
f125905c
MM
141void jsonrpc_session_set_dscp(struct jsonrpc_session *,
142 uint8_t dscp);
d6db7b3c 143const char *jsonrpc_session_get_id(const struct jsonrpc_session *);
94db5407 144
f2129093 145#endif /* jsonrpc.h */