/*
 * 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 Configure BFD feature
    @param client_index - opaque cookie to identify the sender
    @param context - sender context, to match reply w/ request
    @param slow_timer - slow timer (seconds)
    @param min_tx - desired min tx interval
    @param min_rx - desired min rx interval
    @param detect_mult - desired detection multiplier
*/
define bfd_set_config {
  u32 client_index;
  u32 context;
  u32 slow_timer;
  u32 min_tx;
  u32 min_rx;
  u8 detect_mult;
};

/** \brief Configure BFD feature response
    @param context - sender context, to match reply w/ request
    @param retval - return code for the request
*/
define bfd_set_config_reply {
  u32 context;
  i32 retval;
};

/** \brief Get BFD configuration
*/
define bfd_get_config {
  u32 client_index;
  u32 context;
};

/** \brief Get BFD configuration response
    @param context - sender context, to match reply w/ request
    @param retval - return code for the request
    @param slow_timer - slow timer (seconds)
    @param min_tx - desired min tx interval
    @param min_rx - desired min rx interval
    @param detect_mult - desired detection multiplier
*/
define bfd_get_config_reply {
  u32 client_index;
  u32 context;
  u32 slow_timer;
  u32 min_tx;
  u32 min_rx;
  u8 detect_mult;
};

/** \brief Add UDP BFD session on interface
    @param client_index - opaque cookie to identify the sender
    @param context - sender context, to match reply w/ request
    @param sw_if_index - sw index of the interface
    @param desired_min_tx - desired min transmit interval (microseconds)
    @param required_min_rx - required min receive interval (microseconds)
    @param detect_mult - detect multiplier (# of packets missed between connection goes down)
    @param local_addr - local address
    @param peer_addr - peer address
    @param is_ipv6 - local_addr, peer_addr are IPv6 if non-zero, otherwise IPv4
*/
define bfd_udp_add {
  u32 client_index;
  u32 context;
  u32 sw_if_index;
  u32 desired_min_tx;
  u32 required_min_rx;
  u8 local_addr[16];
  u8 peer_addr[16];
  u8 is_ipv6;
  u8 detect_mult;
};

/** \brief Add UDP BFD session response
    @param context - sender context, to match reply w/ request
    @param retval - return code for the request
    @param bs_index - index of the session created
*/
define bfd_udp_add_reply {
  u32 context;
  i32 retval;
  u32 bs_index;
};

/** \brief Delete UDP BFD session on interface
    @param client_index - opaque cookie to identify the sender
    @param context - sender context, to match reply w/ request
    @param sw_if_index - sw index of the interface
    @param local_addr - local address
    @param peer_addr - peer address
    @param is_ipv6 - local_addr, peer_addr are IPv6 if non-zero, otherwise IPv4
*/
define bfd_udp_del {
  u32 client_index;
  u32 context;
  u32 sw_if_index;
  u8 local_addr[16];
  u8 peer_addr[16];
  u8 is_ipv6;
};

/** \brief Delete UDP BFD session response
    @param context - sender context, to match reply w/ request
    @param retval - return code for the request
*/
define bfd_udp_del_reply {
  u32 context;
  i32 retval;
};

/** \brief Get all BFD sessions
    @param client_index - opaque cookie to identify the sender
    @param context - sender context, to match reply w/ request
*/
define bfd_udp_session_dump {
  u32 client_index;
  u32 context;
};

/** \brief BFD session details structure
    @param context - sender context, to match reply w/ request
    @param bs_index - index of the session
    @param sw_if_index - sw index of the interface
    @param local_addr - local address
    @param peer_addr - peer address
    @param is_ipv6 - local_addr, peer_addr are IPv6 if non-zero, otherwise IPv4
    @param state - session state
*/
define bfd_udp_session_details {
  u32 context;
  u32 bs_index; 
  u32 sw_if_index;
  u8 local_addr[16];
  u8 peer_addr[16];
  u8 is_ipv6;
  u8 state;
};

/** \brief Set flags of BFD session
    @param client_index - opaque cookie to identify the sender
    @param context - sender context, to match reply w/ request
    @param bs_index - index of the bfd session to set flags on
    @param admin_up_down - set the admin state, 1 = up, 0 = down
*/
define bfd_session_set_flags {
  u32 client_index;
  u32 context;
  u32 bs_index;
  u8 admin_up_down;
};

/** \brief Reply to bfd_session_set_flags 
    @param context - sender context which was passed in the request
    @param retval - return code of the set flags request
*/
define bfd_session_set_flags_reply
{
  u32 context;
  i32 retval;
};

/** \brief Register for BFD events
    @param client_index - opaque cookie to identify the sender
    @param context - sender context, to match reply w/ request
    @param enable_disable - 1 => register for events, 0 => cancel registration
    @param pid - sender's pid
*/
define want_bfd_events
{
  u32 client_index;
  u32 context;
  u32 enable_disable;
  u32 pid;
};

/** \brief Reply for BFD events registration
    @param context - returned sender context, to match reply w/ request
    @param retval - return code
*/
define want_bfd_events_reply
{
  u32 context;
  i32 retval;
};

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