#!/bin/bash

#    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.

# Save trace setting
_XTRACE_NEUTRON_LAGOPUS=$(set +o | grep xtrace)
set +o xtrace

function neutron_plugin_create_nova_conf {
    :
}

function neutron_plugin_install_agent_packages {
    :
}

function is_neutron_ovs_base_plugin {
    return 1
}

function neutron_plugin_configure_debug_command {
    :
}

function neutron_plugin_configure_dhcp_agent {
    :
}

function neutron_plugin_configure_l3_agent {
    :
}

function neutron_plugin_configure_plugin_agent {
    AGENT_BINARY="$NEUTRON_BIN_DIR/neutron-lagopus-agent"

    # Install networking-lagopus
    dir=${GITDIR['networking-lagopus']}
    setup_package $dir

    if [ -n "$DPDK_PORT_MAPPINGS" ]; then
        MAPPINGS=${DPDK_PORT_MAPPINGS//,/ }
        ARRAY=( $MAPPINGS )
        BRIDGE_MAPPINGS=""
        num=1
        for map in "${ARRAY[@]}"; do
            phys=`echo $map | cut -f 2 -d "#"`
            pair="$phys:bridge0$num"
            if [ $num != "1" ]; then
                pair=",$pair"
            fi
            BRIDGE_MAPPINGS="$BRIDGE_MAPPINGS$pair"
            num=$(($num+1))
        done
        iniset /$Q_PLUGIN_CONF_FILE lagopus bridge_mappings $BRIDGE_MAPPINGS
    fi
    iniset /$Q_PLUGIN_CONF_FILE lagopus max_eth_ports $LAGOPUS_MAX_ETH_PORTS
    iniset /$Q_PLUGIN_CONF_FILE lagopus max_vlan_networks $LAGOPUS_MAX_VLAN_NETWORKS
    iniset /$Q_PLUGIN_CONF_FILE lagopus replace_dsl $LAGOPUS_REPLACE_DSL
    iniset /$Q_PLUGIN_CONF_FILE lagopus lagopus_conf_path $LAGOPUS_CONF_DIR/$LAGOPUS_CONF
    iniset /$Q_PLUGIN_CONF_FILE securitygroup firewall_driver neutron.agent.firewall.NoopFirewallDriver
}

function neutron_plugin_setup_interface_driver {
    local conf_file=$1
    # TODO: Adds lagopus interface_driver
    iniset $conf_file DEFAULT interface_driver lagopus
}


#function has_neutron_plugin_security_group {
#    # 1 means False here
#    return 0
#}

function neutron_plugin_check_adv_test_requirements {
    is_service_enabled q-agt && is_service_enabled q-dhcp && return 0
}


function has_neutron_plugin_security_group {
    return 1
}

# Restore xtrace
$_XTRACE_NEUTRON_LAGOPUS
