/*
 * Copyright (c) 2015-2016 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.0.0";

import "vnet/interface_types.api";
import "vnet/lisp-cp/lisp_types.api";

/** \brief GPE locator structure
    @param is_ip4 - whether addr is IPv4 or v6
    @param weight - locator weight
    @param addr - IPv4/6 address
*/
typedef gpe_locator
{
  u8 weight;
  vl_api_address_t addr;
};

/** \brief add or delete GPE tunnel
    @param client_index - opaque cookie to identify the sender
    @param context - sender context, to match reply w/ request
    @param is_add - add address if non-zero, else delete
    @param eid_type -
      0 : ipv4
      1 : ipv6
      2 : mac
    @param rmt_eid - remote eid
    @param lcl_eid - local eid
    @param rmt_len - remote prefix len
    @param lcl_len - local prefix len
    @param vni - virtual network identifier
    @param dp_table - vrf/bridge domain id
    @param action - negative action when 0 locators configured
    @param loc_num - number of locators
    @param locs - array of remote locators
*/
manual_print manual_endian define gpe_add_del_fwd_entry
{
  u32 client_index;
  u32 context;
  bool is_add [default=true];
  vl_api_eid_t rmt_eid;
  vl_api_eid_t lcl_eid;
  u32 vni;
  u32 dp_table;
  u8 action;
  u32 loc_num;
  vl_api_gpe_locator_t locs[loc_num];
};

define gpe_add_del_fwd_entry_reply
{
  u32 context;
  i32 retval;
  u32 fwd_entry_index;
};

/** \brief enable or disable gpe protocol
    @param client_index - opaque cookie to identify the sender
    @param context - sender context, to match reply w/ request
    @param is_enable [default=true] - enable protocol if non-zero, else disable
*/
autoreply define gpe_enable_disable
{
  u32 client_index;
  u32 context;
  bool is_enable [default=true];
};

/** \brief add or delete gpe_iface
    @param client_index - opaque cookie to identify the sender
    @param context - sender context, to match reply w/ request
    @param is_add - add address if non-zero, else delete
*/
autoreply define gpe_add_del_iface
{
  u32 client_index;
  u32 context;
  bool is_add [default=true];
  bool is_l2;
  u32 dp_table;
  u32 vni;
};

define gpe_fwd_entry_vnis_get
{
  u32 client_index;
  u32 context;
};

manual_print manual_endian define gpe_fwd_entry_vnis_get_reply
{
  u32 context;
  i32 retval;
  u32 count;
  u32 vnis[count];
};

define gpe_fwd_entries_get
{
  u32 client_index;
  u32 context;
  u32 vni;
};

typedef gpe_fwd_entry
{
  u32 fwd_entry_index;
  u32 dp_table;
  vl_api_eid_t leid;
  vl_api_eid_t reid;
  u32 vni;
  u8 action;
};

manual_print manual_endian define gpe_fwd_entries_get_reply
{
  u32 context;
  i32 retval;
  u32 count;
  vl_api_gpe_fwd_entry_t entries[count];
};

define gpe_fwd_entry_path_dump
{
  u32 client_index;
  u32 context;
  u32 fwd_entry_index;
};

manual_endian manual_print define gpe_fwd_entry_path_details
{
  u32 context;
  vl_api_gpe_locator_t lcl_loc;
  vl_api_gpe_locator_t rmt_loc;
};

/** \brief Set GPE encapsulation mode
    @param client_index - opaque cookie to identify the sender
    @param context - sender context, to match reply w/ request
    @param mode - LISP (value 0) or VXLAN (value 1)
*/
autoreply define gpe_set_encap_mode
{
  u32 client_index;
  u32 context;
  bool is_vxlan;
};

/** \brief get GPE encapsulation mode
    @param client_index - opaque cookie to identify the sender
    @param context - sender context, to match reply w/ request
    @param mode - LISP (value 0) or VXLAN (value 1)
*/
define gpe_get_encap_mode
{
  u32 client_index;
  u32 context;
};

/** \brief Reply for set_encap_mode
    @param context - returned sender context, to match reply w/ request
    @param retval - return code
    @param encap_mode - GPE encapsulation mode
*/
define gpe_get_encap_mode_reply
{
  u32 context;
  i32 retval;
  /* FIXME: gpe encap enum */
  u8 encap_mode;
};

/** \brief Add native fwd rpath
    @param context - returned sender context, to match reply w/ request
    @param retval - return code
    @param is_add - flag to indicate add or del
    @param table_id - table id for route path
    @param nh_sw_if_index - next-hop sw_if_index (~0 if not set)
    @param is_ip4 - flag to indicate if nh is ip4
    @param nh_addr - next hop ip address
*/
autoreply define gpe_add_del_native_fwd_rpath
{
  u32 client_index;
  u32 context;
  bool is_add [default=true];
  u32 table_id;
  vl_api_interface_index_t nh_sw_if_index;
  vl_api_address_t nh_addr;
};

/** \brief get GPE native fwd rpath
    @param client_index - opaque cookie to identify the sender
    @param context - sender context, to match reply w/ request
*/
define gpe_native_fwd_rpaths_get
{
  u32 client_index;
  u32 context;
  bool is_ip4;
};

/** \brief Reply for get native fwd rpath
    @param context - returned sender context, to match reply w/ request
    @param retval - return code
    @param table_id - table id for route path
    @param nh_sw_if_index - next-hop sw_if_index (~0 if not set)
    @param nh_addr - next hop address
*/
typedef gpe_native_fwd_rpath
{
  u32 fib_index;
  vl_api_interface_index_t nh_sw_if_index;
  vl_api_address_t nh_addr;
};

manual_print manual_endian define gpe_native_fwd_rpaths_get_reply
{
  u32 context;
  i32 retval;
  u32 count;
  vl_api_gpe_native_fwd_rpath_t entries[count];
};

/*
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */
