/*
 * 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 = "1.1.1";
import "vnet/fib/fib_types.api";
import "vnet/ip/ip_types.api";
import "vnet/interface_types.api";

/** \brief Bind/Unbind an MPLS local label to an IP prefix. i.e. create
           a per-prefix label entry.
    @param client_index - opaque cookie to identify the sender
    @param context - sender context, to match reply w/ request
    @param mb_mpls_table_id - The MPLS table-id the MPLS entry will be added in
    @param mb_label - The MPLS label value to bind
    @param mb_ip_table_id - The IP table-id of the IP prefix to bind to.
    @param mb_is_bind - Bind or unbind
    @param mb_is_ip4 - The prefix to bind to is IPv4
    @param mb_prefix - IP prefix
*/
autoreply define mpls_ip_bind_unbind
{
  u32 client_index;
  u32 context;
  u32 mb_mpls_table_id;
  u32 mb_label;
  u32 mb_ip_table_id;
  bool mb_is_bind;
  vl_api_prefix_t mb_prefix;
};

typedef mpls_tunnel
{
  vl_api_interface_index_t mt_sw_if_index;
  u32 mt_tunnel_index;
  bool mt_l2_only;
  bool mt_is_multicast;
  string mt_tag[64];
  u8 mt_n_paths;
  vl_api_fib_path_t mt_paths[mt_n_paths];
};

define mpls_tunnel_add_del
{
  u32 client_index;
  u32 context;
  bool mt_is_add [default=true];
  vl_api_mpls_tunnel_t mt_tunnel;
};

/** \brief Reply for MPLS tunnel add / del request
    @param context - returned sender context, to match reply w/ request
    @param retval - return code
    @param sw_if_index - SW interface index of the tunnel created
*/
define mpls_tunnel_add_del_reply
{
  u32 context;
  i32 retval;
  vl_api_interface_index_t sw_if_index;
  u32 tunnel_index;
};

/** \brief Dump mpls eth tunnel table
    @param client_index - opaque cookie to identify the sender
    @param sw_if_index - sw_if_index of the MPLS tunnel
                         (as returned from the create)
*/
define mpls_tunnel_dump
{
  u32 client_index;
  u32 context;
  vl_api_interface_index_t sw_if_index;
};

/** \brief mpls tunnel details
*/
manual_endian manual_print define mpls_tunnel_details
{
  u32 context;
  vl_api_mpls_tunnel_t mt_tunnel;
};

/** \brief MPLS Route Add / del route
    @param client_index - opaque cookie to identify the sender
    @param context - sender context, to match reply w/ request
    @param mt_table_id - The MPLS table-id the route is added in
    @param mt_is_add - Is this a route add or delete
    @param mt_name - A client provided name/tag for the table. If this
                     is not set by the client, then VPP will generate
		     something meaningfull.
*/
typedef mpls_table
{
  u32 mt_table_id;
  string mt_name[64];
};
autoreply define mpls_table_add_del
{
  u32 client_index;
  u32 context;
  bool  mt_is_add [default=true];
  vl_api_mpls_table_t mt_table;
};

/** \brief Dump MPLS fib table
    @param client_index - opaque cookie to identify the sender
*/
define mpls_table_dump
{
  u32 client_index;
  u32 context;
};

define mpls_table_details
{
  u32 context;
  vl_api_mpls_table_t mt_table;
};

/** \brief MPLS Route
    @param mr_table_id - The MPLS table-id the route is added in
    @param mr_label - The MPLS label value
    @param mr_eos - The End of stack bit
    @param mr_eos_proto - If EOS then this is the DPO packect's proto post pop
    @param mr_is_multicast - Is this a multicast route
    @param mr_n_paths - The number of paths
    @param mr_paths - The paths
*/
typedef mpls_route
{
  u32 mr_table_id;
  u32 mr_label;
  /* TODO: check data type */
  u8 mr_eos;
  u8 mr_eos_proto;
  bool mr_is_multicast;
  u8 mr_n_paths;
  vl_api_fib_path_t mr_paths[mr_n_paths];
};

/** \brief MPLS Route Add / del route
    @param client_index - opaque cookie to identify the sender
    @param context - sender context, to match reply w/ request
    @param mr_table_id - The MPLS table-id the route is added in
    @param mr_is_add - Is this a route add or delete
    @param mr_is_multipath - Is this route update a multipath - i.e. is this
                             a path addition to an existing route
    @param mr_route - The Route
*/
define mpls_route_add_del
{
  u32 client_index;
  u32 context;
  bool mr_is_add;
  bool mr_is_multipath;
  vl_api_mpls_route_t mr_route;
};

define mpls_route_add_del_reply
{
  u32 context;
  i32 retval;
  u32 stats_index;
};

/** \brief Dump MPLS fib table
    @param client_index - opaque cookie to identify the sender
*/
define mpls_route_dump
{
  u32 client_index;
  u32 context;
  vl_api_mpls_table_t table;
};

/** \brief mpls FIB table response
    @param table_id - MPLS fib table id
    @param s_bit - End-of-stack bit
    @param label - MPLS label value
    @param count - the number of fib_path in path
    @param path  - array of of fib_path structures
*/
manual_endian manual_print define mpls_route_details
{
  u32 context;
  vl_api_mpls_route_t mr_route;
};

/** \brief Enable or Disable MPLS on and interface
    @param client_index - opaque cookie to identify the sender
    @param context - sender context, to match reply w/ request
    @param sw_if_index - index of the interface
    @param enable - if non-zero enable, else disable
*/
autoreply define sw_interface_set_mpls_enable
{
  u32 client_index;
  u32 context;
  vl_api_interface_index_t sw_if_index;
  bool enable [default=true];
};

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