#include <vnet/vnet.h>
#include <vnet/plugin/plugin.h>

static clib_error_t *
vpn_ethernet_admin_up_down(vnet_main_t *vnm, u32 hw_if_index,
    u32 flags)
{
    u32 hw_flags = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
        VNET_HW_INTERFACE_FLAG_LINK_UP : 0;
    vnet_hw_interface_set_flags(vnm, hw_if_index, hw_flags);
    return 0;
}

VNET_DEVICE_CLASS(ethernet_demo_device_class) = {
    .name = "DEMO",
    .admin_up_down_function = vpn_ethernet_admin_up_down
};

VNET_DEVICE_CLASS_TX_FN(ethernet_demo_device_class)
(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
{
    return frame->n_vectors;
}

VNET_HW_INTERFACE_CLASS(demo_if_class) = {
    .name = "demo",
    .flags = VNET_HW_INTERFACE_CLASS_FLAG_P2P,
};

static clib_error_t *
create_demo_interface_command_f(vlib_main_t *vm,
    unformat_input_t *input,
    vlib_cli_command_t *cmd)
{
    vnet_register_interface(vnet_get_main(),
        ethernet_demo_device_class.index,
        0, demo_if_class.index, 0);

    return 0;
}

VLIB_CLI_COMMAND(create_demo_interface_command, static) = {
    .path = "demo interface",
    .short_help = "demo interface",
    .function = create_demo_interface_command_f,
};

VLIB_PLUGIN_REGISTER() = {
    .version = PROJECT_VERSION,
    .description = "DEMO",
};