/*
 * 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.
 */

/** \brief GPE locator structure
    @param is_ip4 - whether addr is IPv4 or v6
    @param weight - locator weight
    @param addr - IPv4/6 address
*/
typeonly manual_print manual_endian define gpe_locator
{
  u8 is_ip4;
  u8 weight;
  u8 addr[16];
};

/** \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;
  u8 is_add;
  u8 eid_type;
  u8 rmt_eid[16];
  u8 lcl_eid[16];
  u8 rmt_len;
  u8 lcl_len;
  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
{
  i32 retval;
  u32 context;
  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_en - enable protocol if non-zero, else disable
*/
autoreply define gpe_enable_disable
{
  u32 client_index;
  u32 context;
  u8 is_en;
};

/** \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;
  u8 is_add;
  u8 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;
};

typeonly manual_print manual_endian define gpe_fwd_entry
{
  u32 fwd_entry_index;
  u32 dp_table;
  u8 eid_type;
  u8 leid_prefix_len;
  u8 reid_prefix_len;
  u8 leid[16];
  u8 reid[16];
  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 client_index;
  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;
  u8 mode;
};

/** \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;
  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;
  u8 is_add;
  u32 table_id;
  u32 nh_sw_if_index;
  u8 is_ip4;
  u8 nh_addr[16];
};

/** \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;
  u8 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
*/
typeonly manual_print manual_endian define gpe_native_fwd_rpath
{
  u32 fib_index;
  u32 nh_sw_if_index;
  u8 is_ip4;
  u8 nh_addr[16];
};

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:
 */
 
