/*
 * 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
*/
autoreply 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];
};

/** \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_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];
};

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;
};

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