/* Hey Emacs use -*- mode: C -*- */
/*
 * Copyright (c) 2015 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

option version = "2.1.0";

/*
 * Define services not following the normal conventions here
 */
service {
  rpc memclnt_rx_thread_suspend returns null;
  rpc memclnt_read_timeout returns null;
  rpc rx_thread_exit returns null;
  rpc trace_plugin_msg_ids returns null;
};

/*
 * Create a client registration
 */
define memclnt_create {
  option deprecated;

    u32 context;                /* opaque value to be returned in the reply */
    i32 ctx_quota;              /* requested punt context quota */
    u64 input_queue;            /* client's queue */
    string name[64];            /* for show, find by name, whatever */
    u32 api_versions[8];        /* client-server pairs use as desired */
};

define memclnt_create_reply {
  option deprecated;

    u32 context;                /* opaque value from the create request */
    i32 response;               /* Non-negative = success */
    u64 handle;                 /* handle by which vlib knows this client */
    u32 index;                  /* index, used e.g. by API trace replay */
    u64 message_table;          /* serialized message table in shmem */
};

/*
 * Delete a client registration
 */
define memclnt_delete {
    u32 index;                  /* index, used e.g. by API trace replay */
    u64 handle;               /* handle by which vlib knows this client */
    bool do_cleanup;		/* vlib to cleanup the registration */
};

define memclnt_delete_reply {
    i32 response;               /* Non-negative = success */
    u64 handle;               /* in case the client wonders */
};

/*
 * Client RX thread exit
 */
define rx_thread_exit {
    u8 dummy;
};

/*
 * Client RX thread suspend
 */
define memclnt_rx_thread_suspend {
    u8 dummy;
};

/*
 * Client read timeout
 */
define memclnt_read_timeout {
    u8 dummy;
};

/*
 * RPC
 */
autoreply define rpc_call {
    u32 client_index;
    u32 context;
    u64 function;
    u8 multicast;
    u8 need_barrier_sync;
    u8 send_reply;
    u32 data_len;
    u8 data[data_len];
};

/*
 * Lookup message-ID base by name
 */
define get_first_msg_id {
    u32 client_index;
    u32 context;
    string name[64];
};

define get_first_msg_id_reply {
    u32 context;
    i32 retval;
    u16 first_msg_id;
};

/*
 * Get API version table (includes built-in and plugins)
 */
typedef module_version {
  u32 major;
  u32 minor;
  u32 patch;
  string name[64];
};
define api_versions {
  u32 client_index;
  u32 context;
};
define api_versions_reply {
  u32 context;
  i32 retval;
  u32 count;
  vl_api_module_version_t api_versions[count];
};

/*
 * Trace the plugin message-id allocator
 * so we stand a chance of dealing with different sets of plugins
 * at api trace replay time
 */

define trace_plugin_msg_ids
{
    u32 client_index;
    u32 context;
    string plugin_name[128];
    u16 first_msg_id;
    u16 last_msg_id;
};

typedef message_table_entry
{
  u16 index;
  string name[64];
};

/*
 * Create a socket client registration.
 */
define sockclnt_create {
    u32 context;                /* opaque value to be returned in the reply */
    string name[64];                /* for show, find by name, whatever */
};

define sockclnt_create_reply {
    u32 client_index;
    u32 context;                /* opaque value from the create request */
    i32 response;               /* Non-negative = success */
    u32 index;                  /* index, used e.g. by API trace replay */
    u16 count;
    vl_api_message_table_entry_t message_table[count];
};

/*
 * Delete a client registration
 */
define sockclnt_delete {
    u32 client_index;
    u32 context;
    u32 index;                  /* index, used e.g. by API trace replay */
};

define sockclnt_delete_reply {
    u32 context;
    i32 response;               /* Non-negative = success */
};

/*
 * Initialize shm api over socket api
 */
autoreply define sock_init_shm {
    u32 client_index;
    u32 context;
    u32 requested_size;
    u8 nitems;
    u64 configs[nitems];
};

/* define sock_init_shm_reply {
    u32 client_index;
    u32 context;
    i32 retval;
}; */

/*
 * Memory client ping / response
 * Only sent on inactive connections
 */
autoreply define memclnt_keepalive
{
  u32 client_index;
  u32 context;
};

/** \brief Control ping from client to api server request
    @param client_index - opaque cookie to identify the sender
    @param context - sender context, to match reply w/ request
*/
define control_ping
{
  u32 client_index;
  u32 context;
};

/** \brief Control ping from the client to the server response
    @param client_index - opaque cookie to identify the sender
    @param context - sender context, to match reply w/ request
    @param retval - return code for the request
    @param vpe_pid - the pid of the vpe, returned by the server
*/
define control_ping_reply
{
  u32 context;
  i32 retval;
  u32 client_index;
  u32 vpe_pid;
};

define memclnt_create_v2 {
    u32 context;                /* opaque value to be returned in the reply */
    i32 ctx_quota;              /* requested punt context quota */
    u64 input_queue;            /* client's queue */
    string name[64];            /* for show, find by name, whatever */
    u32 api_versions[8];        /* client-server pairs use as desired */
    bool keepalive[default=true];  /* dead client scan keepalives */
};

define memclnt_create_v2_reply {
    u32 context;                /* opaque value from the create request */
    i32 response;               /* Non-negative = success */
    u64 handle;                 /* handle by which vlib knows this client */
    u32 index;                  /* index, used e.g. by API trace replay */
    u64 message_table;          /* serialized message table in shmem */
};

define get_api_json {
    u32 client_index;
    u32 context;
};

define get_api_json_reply {
    u32 context;
    i32 retval;
    string json[];
};
