usr/src/lib/libradproto/common/protocol.x
author David Powell <david.e.powell@oracle.com>
Wed, 03 Aug 2011 13:07:44 -0700
changeset 760 5220578b3b77
parent 749 dd22ec9bff4a
child 761 ffd45e0b2905
permissions -rw-r--r--
18775 Formal protocol documentation needed

/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */

/*
 * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
 */

/*
 * rad protocol definitions
 *
 * We don't use straight RPC since we have additional requirements:
 *  - We need multiple outstanding requests that get distinct results
 *  - We need asynchronous notifications
 *
 * At the same time, we can make things simpler.  Which is good because
 * Java doesn't have an RPC client.
 */

/*
 * We programmatically impose an limit on the request size, but it is
 * still possible for the XDR-encoded content of a request to deny
 * service by specifying string, array, or opaque sizes that don't
 * match the actual amount of data sent.
 *
 * Solaris's xdr_string implementation protects us from XDR strings
 * with exaggerated sizes.  Unfortunately xdr_bytes and xdr_array do
 * not.  So that we can safely use rpcgen to implement our protocol,
 * we enforce the following limits on our non-string variable-length
 * quanities.
 */
const MAXARGS = 16;
const MAXARGLEN = 16336;

/*
 * Request definitions
 */

struct wiretime {
	hyper seconds;
	int nanos;
};

typedef string objectname<>;

typedef opaque argument<MAXARGLEN>;

struct op_invoke {
	hyper id;
	string mname<>;
	argument args<MAXARGS>;
};

struct resp_invoke {
	argument result;
};


struct op_getattr {
	hyper id;
	string attribute<>;
};

struct resp_getattr {
	argument result;
};


struct op_setattr {
	hyper id;
	string attribute<>;
	argument value;
};

/*
struct resp_setattr {
};
*/

struct op_lookup {
	objectname name;
	bool describe;
};

/* Not actually used; see xdr_object_t & datatype.x */
/*
struct resp_lookup {
	hyper objectid;
	hyper typeid;
	bool isdefined;
	( if isdefined, definition )
};
*/

struct op_define {
	hyper id;
};

/* Not actually used; see xdr_object_t & datatype.x */
/*
struct resp_define {
	( definition )
};
*/

struct op_list {
	objectname pattern;
};

struct resp_list {
	objectname objects<>;
};


struct op_subscribe {
	hyper id;
	string event<>;
};

/* resp_subscribe {}; */


struct op_unsubscribe {
	hyper id;
	string event<>;
};

/* resp_unsubscribe {}; */

/*
 * Request/response protocol
 */
struct server_hello {
	string protocol<3>;	/* Protocol name, "RAD" */
	int min_ver;		/* Minimum supported version */
	int max_ver;		/* Maximum supported version */
};

struct client_hello {
	string protocol<3>;	/* Protocol name, "RAD" */
	int ver;		/* Selected version */
	string locale<256>;	/* Client locale */
};

/* Container operations */
enum operation {
	INVOKE,
	GETATTR,
	SETATTR,
	LOOKUP,
	DEFINE,
	LIST,
	SUB,
	UNSUB
};

struct request {
	hyper serial;
	operation op;
	opaque payload<>;
};

struct fault {
	int error;
	opaque payload<>;
};

union response_data switch (bool success) {
case TRUE:
	opaque payload<>;
case FALSE:
	fault faulty;
default:
	void;
};

struct event_data {
	hyper source;
	hyper sequence;
	wiretime timestamp;	/* Seconds, nanoseconds since Epoch */
	string type<>;
	opaque payload<>;
};

union message switch (hyper serial) {
case 0:
	event_data edata;
default:
	response_data rdata;
};