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

/** \file

    This file defines vpe control-plane API messages for
    the Linux kernel TAP device driver
*/

vl_api_version 1.0.0

/** \brief Initialize a new tap interface with the given paramters 
    @param client_index - opaque cookie to identify the sender
    @param context - sender context, to match reply w/ request
    @param use_random_mac - let the system generate a unique mac address
    @param tap_name - name to associate with the new interface
    @param mac_address - mac addr to assign to the interface if use_radom not set
*/
define tap_connect
{
  u32 client_index;
  u32 context;
  u8 use_random_mac;
  u8 tap_name[64];
  u8 mac_address[6];
  u8 renumber;
  u32 custom_dev_instance;
  u8 ip4_address_set;
  u8 ip4_address[4];
  u8 ip4_mask_width;
  u8 ip6_address_set;
  u8 ip6_address[16];
  u8 ip6_mask_width;
  u8 tag[64];
};

/** \brief Reply for tap connect request
    @param context - returned sender context, to match reply w/ request
    @param retval - return code
    @param sw_if_index - software index allocated for the new tap interface
*/
define tap_connect_reply
{
  u32 context;
  i32 retval;
  u32 sw_if_index;
};

/** \brief Modify a tap interface with the given paramters 
    @param client_index - opaque cookie to identify the sender
    @param context - sender context, to match reply w/ request
    @param sw_if_index - interface index of existing tap interface
    @param use_random_mac - let the system generate a unique mac address
    @param tap_name - name to associate with the new interface
    @param mac_address - mac addr to assign to the interface if use_radom not set
*/
define tap_modify
{
  u32 client_index;
  u32 context;
  u32 sw_if_index;
  u8 use_random_mac;
  u8 tap_name[64];
  u8 mac_address[6];
  u8 renumber;
  u32 custom_dev_instance;
};

/** \brief Reply for tap modify request
    @param context - returned sender context, to match reply w/ request
    @param retval - return code
    @param sw_if_index - software index if the modified tap interface
*/
define tap_modify_reply
{
  u32 context;
  i32 retval;
  u32 sw_if_index;
};

/** \brief Delete tap interface
    @param client_index - opaque cookie to identify the sender
    @param context - sender context, to match reply w/ request
    @param sw_if_index - interface index of existing tap interface
*/
autoreply define tap_delete
{
  u32 client_index;
  u32 context;
  u32 sw_if_index;
};

/** \brief Dump tap interfaces request */
define sw_interface_tap_dump
{
  u32 client_index;
  u32 context;
};

/** \brief Reply for tap dump request
    @param sw_if_index - software index of tap interface
    @param dev_name - Linux tap device name
*/
define sw_interface_tap_details
{
  u32 context;
  u32 sw_if_index;
  u8 dev_name[64];
};
