]> git.proxmox.com Git - mirror_ovs.git/blame - lib/jsonrpc.h
vswitchd: Update IPv6 controller examples to use OpenFlow port.
[mirror_ovs.git] / lib / jsonrpc.h
CommitLineData
f2129093 1/*
fba6bd1d 2 * Copyright (c) 2009, 2010, 2012, 2013 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
BP
31struct stream;
32\f
33/* API for a JSON-RPC stream. */
34
efc295d2 35/* Default port numbers.
0d11f523 36 *
efc295d2
JP
37 * OVSDB_OLD_PORT defines the original port number used by OVS.
38 * OVSDB_PORT defines the official port number assigned by IANA. By
39 * default, we still uses OVSDB_OLD_PORT, but we present a warning that
40 * that will change. */
41#define OVSDB_OLD_PORT 6632
42#define OVSDB_PORT 6640
0d11f523 43
f125905c
MM
44int jsonrpc_stream_open(const char *name, struct stream **, uint8_t dscp);
45int jsonrpc_pstream_open(const char *name, struct pstream **, uint8_t dscp);
0d11f523 46
f2129093
BP
47struct jsonrpc *jsonrpc_open(struct stream *);
48void jsonrpc_close(struct jsonrpc *);
49
50void jsonrpc_run(struct jsonrpc *);
51void jsonrpc_wait(struct jsonrpc *);
52
f2129093
BP
53int jsonrpc_get_status(const struct jsonrpc *);
54size_t jsonrpc_get_backlog(const struct jsonrpc *);
3a8d38c8 55unsigned int jsonrpc_get_received_bytes(const struct jsonrpc *);
f2129093
BP
56const char *jsonrpc_get_name(const struct jsonrpc *);
57
58int jsonrpc_send(struct jsonrpc *, struct jsonrpc_msg *);
59int jsonrpc_recv(struct jsonrpc *, struct jsonrpc_msg **);
60void jsonrpc_recv_wait(struct jsonrpc *);
61
62int jsonrpc_send_block(struct jsonrpc *, struct jsonrpc_msg *);
63int jsonrpc_recv_block(struct jsonrpc *, struct jsonrpc_msg **);
d0632593
BP
64int jsonrpc_transact_block(struct jsonrpc *, struct jsonrpc_msg *,
65 struct jsonrpc_msg **);
f2129093
BP
66
67/* Messages. */
68enum jsonrpc_msg_type {
69 JSONRPC_REQUEST, /* Request. */
70 JSONRPC_NOTIFY, /* Notification. */
71 JSONRPC_REPLY, /* Successful reply. */
72 JSONRPC_ERROR /* Error reply. */
73};
74
75struct jsonrpc_msg {
76 enum jsonrpc_msg_type type;
77 char *method; /* Request or notification only. */
78 struct json *params; /* Request or notification only. */
79 struct json *result; /* Successful reply only. */
80 struct json *error; /* Error reply only. */
81 struct json *id; /* Request or reply only. */
82};
83
84struct jsonrpc_msg *jsonrpc_create_request(const char *method,
20bed8be
BP
85 struct json *params,
86 struct json **idp);
f2129093
BP
87struct jsonrpc_msg *jsonrpc_create_notify(const char *method,
88 struct json *params);
89struct jsonrpc_msg *jsonrpc_create_reply(struct json *result,
90 const struct json *id);
91struct jsonrpc_msg *jsonrpc_create_error(struct json *error,
92 const struct json *id);
93
94const char *jsonrpc_msg_type_to_string(enum jsonrpc_msg_type);
95char *jsonrpc_msg_is_valid(const struct jsonrpc_msg *);
96void jsonrpc_msg_destroy(struct jsonrpc_msg *);
97
98char *jsonrpc_msg_from_json(struct json *, struct jsonrpc_msg **);
99struct json *jsonrpc_msg_to_json(struct jsonrpc_msg *);
dcbb691b
BP
100\f
101/* A JSON-RPC session with reconnection. */
102
fba6bd1d 103struct jsonrpc_session *jsonrpc_session_open(const char *name, bool retry);
e879d33e
MM
104struct jsonrpc_session *jsonrpc_session_open_unreliably(struct jsonrpc *,
105 uint8_t);
dcbb691b
BP
106void jsonrpc_session_close(struct jsonrpc_session *);
107
108void jsonrpc_session_run(struct jsonrpc_session *);
109void jsonrpc_session_wait(struct jsonrpc_session *);
110
111size_t jsonrpc_session_get_backlog(const struct jsonrpc_session *);
112const char *jsonrpc_session_get_name(const struct jsonrpc_session *);
113
114int jsonrpc_session_send(struct jsonrpc_session *, struct jsonrpc_msg *);
115struct jsonrpc_msg *jsonrpc_session_recv(struct jsonrpc_session *);
116void jsonrpc_session_recv_wait(struct jsonrpc_session *);
117
4931f33a 118bool jsonrpc_session_is_alive(const struct jsonrpc_session *);
dcbb691b
BP
119bool jsonrpc_session_is_connected(const struct jsonrpc_session *);
120unsigned int jsonrpc_session_get_seqno(const struct jsonrpc_session *);
0b3e7a8b 121int jsonrpc_session_get_status(const struct jsonrpc_session *);
fba6bd1d 122int jsonrpc_session_get_last_error(const struct jsonrpc_session *);
0b3e7a8b
AE
123void jsonrpc_session_get_reconnect_stats(const struct jsonrpc_session *,
124 struct reconnect_stats *);
125
705d7a39 126void jsonrpc_session_enable_reconnect(struct jsonrpc_session *);
dcbb691b 127void jsonrpc_session_force_reconnect(struct jsonrpc_session *);
f2129093 128
94db5407
BP
129void jsonrpc_session_set_max_backoff(struct jsonrpc_session *,
130 int max_backofF);
131void jsonrpc_session_set_probe_interval(struct jsonrpc_session *,
132 int probe_interval);
f125905c
MM
133void jsonrpc_session_set_dscp(struct jsonrpc_session *,
134 uint8_t dscp);
94db5407 135
f2129093 136#endif /* jsonrpc.h */