summaryrefslogtreecommitdiff
path: root/devstack/csr1kv/cisco_router
blob: f1a58c833d95eb0b1805309d786e9cfacd0923c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# Cisco router service plugin
# ---------------------------

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

Q_CISCO_DEFAULT_ROUTER_TYPE=${Q_CISCO_DEFAULT_ROUTER_TYPE:-ASR1k_router}

CISCO_ROUTER_PLUGIN=networking_cisco.plugins.cisco.service_plugins.cisco_router_plugin.CiscoRouterPlugin
CISCO_DEVMGR_PLUGIN=networking_cisco.plugins.cisco.service_plugins.cisco_device_manager_plugin.CiscoDeviceManagerPlugin

CISCO_ROUTER_PLUGIN_CONF_FILE=cisco_router_plugin.ini
CISCO_DEVMGR_PLUGIN_CONF_FILE=cisco_device_manager_plugin.ini

PLUGIN_CONFIG_DIR=$NEUTRON_CONF_DIR/plugins/cisco
NET_CISCO_CONF_DIR=$DIR_CISCO/etc/neutron/plugins/cisco

function neutron_cisco_router_configure_common() {
    Q_L3_ENABLED=True
    Q_L3_ROUTER_PER_TENANT=True

    _clear_L3_plugin

    _neutron_service_plugin_class_add $CISCO_DEVMGR_PLUGIN
    _neutron_service_plugin_class_add $CISCO_ROUTER_PLUGIN

    mkdir -p $PLUGIN_CONFIG_DIR

    cp $NET_CISCO_CONF_DIR/$CISCO_ROUTER_PLUGIN_CONF_FILE $PLUGIN_CONFIG_DIR/
    cp $NET_CISCO_CONF_DIR/$CISCO_DEVMGR_PLUGIN_CONF_FILE $PLUGIN_CONFIG_DIR/

    Q_CISCO_ROUTER_PLUGIN_CONF_FILE=$PLUGIN_CONFIG_DIR/$CISCO_ROUTER_PLUGIN_CONF_FILE
    Q_CISCO_DEVMGR_PLUGIN_CONF_FILE=$PLUGIN_CONFIG_DIR/$CISCO_DEVMGR_PLUGIN_CONF_FILE

    Q_PLUGIN_EXTRA_CONF_FILES=(${Q_PLUGIN_EXTRA_CONF_FILES[@]} $Q_CISCO_ROUTER_PLUGIN_CONF_FILE)
    Q_PLUGIN_EXTRA_CONF_FILES=(${Q_PLUGIN_EXTRA_CONF_FILES[@]} $Q_CISCO_DEVMGR_PLUGIN_CONF_FILE)

    # Copy policy.json from networking-cisco/etc to the neutron/etc folder
    echo "Copying policy.json from ${DIR_CISCO}/etc/ to ${NEUTRON_CONF_DIR}"
    cp $DIR_CISCO/etc/policy.json $Q_POLICY_FILE

    _inject_deployer_config

    _patch_neutron_legacy

    iniset $Q_CISCO_ROUTER_PLUGIN_CONF_FILE routing default_router_type $Q_CISCO_DEFAULT_ROUTER_TYPE

 }

function neutron_cisco_router_configure_driver() {
    :
}

function neutron_cisco_router_stop() {
    :
}

# inject any deployer provided configurations
function _inject_deployer_config() {
    ROUTER_INJECT_FILE=$TOP_DIR/cisco_router_plugin.inject
    # inject any deployer provided configurations
    if [[ -f $ROUTER_INJECT_FILE ]]; then
        cat $ROUTER_INJECT_FILE >> $Q_CISCO_ROUTER_PLUGIN_CONF_FILE
    fi

    # Inject device manager configs
    DEVMGR_INJECT_FILE=$TOP_DIR/cisco_device_manager_plugin.inject
    if [[ -f $DEVMGR_INJECT_FILE ]]; then
        cat $DEVMGR_INJECT_FILE >> $Q_CISCO_DEVMGR_PLUGIN_CONF_FILE
    fi
}


function _clear_L3_plugin() {
    if [[  ,${Q_SERVICE_PLUGIN_CLASSES}, =~ ,${ML2_L3_PLUGIN}, ]]; then
        echo "Found L3 plugin configured..Proceeding to delete it"

        Q_SERVICE_PLUGIN_CLASSES=${Q_SERVICE_PLUGIN_CLASSES##$ML2_L3_PLUGIN}
        echo "service plugins="$Q_SERVICE_PLUGIN_CLASSES
    fi
}


# lines in neutron-legacy that need to be changed to be compatible with cisco router plugin
TO_REPLACE[0]=$(cat <<'EOF'
ROUTER_GW_IP=`neutron port-list -c fixed_ips -c device_owner | grep router_gateway | awk -F '"' -v subnet_id=$PUB_SUBNET_ID '$4 == subnet_id { print $8; }'`;
EOF
)
TO_REPLACE[1]=$(cat <<'EOF'
IPV6_ROUTER_GW_IP=`neutron port-list -c fixed_ips | grep $ipv6_pub_subnet_id | awk -F '"' -v subnet_id=$ipv6_pub_subnet_id '$4 == subnet_id { print $8; }'`;
EOF
)

REPLACE_WITH[0]=$(cat <<'EOF'
ROUTER_GW_IP=`neutron port-list -c fixed_ips -c device_owner -c device_id | awk -F '|' -v router_id=$ROUTER_ID -v subnet_id=$PUB_SUBNET_ID '/gateway/ { gsub(" ", "", $4); if ($4 == router_id) { split($2, res, "\\\""); if (res[4] == subnet_id) print res[8]; } }'`;
EOF
)
REPLACE_WITH[1]=$(cat <<'EOF'
IPV6_ROUTER_GW_IP=`neutron port-list -c fixed_ips -c device_id | awk -F '|' -v router_id=$ROUTER_ID -v subnet_id=$ipv6_pub_subnet_id '{ gsub(" ", "", $3); if ($3 == router_id) { split($2, res, "\\\""); if (res[4] == subnet_id) print res[8]; } }'`;
EOF
)

function _patch_neutron_legacy() {
    # Redefine functions in neutron-legacy that configure v4 and v6 routers so gateway ip is determined in a way compatible with our plugin
    original_definition=$(declare -f _neutron_configure_router_v4)
    new_definition=$(echo "$original_definition" | awk -v to_replace="${TO_REPLACE[0]}" -v replace_with="${REPLACE_WITH[0]}" '{ match($0, /^ */); if (substr($0, RLENGTH+1) == to_replace) print substr($0, 1, RLENGTH)replace_with; else print $0; }')
    eval "$new_definition"
    original_definition=$(declare -f _neutron_configure_router_v6)
    new_definition=$(echo "$original_definition" | awk -v to_replace="${TO_REPLACE[1]}" -v replace_with="${REPLACE_WITH[1]}" '{ match($0, /^ */); if (substr($0, RLENGTH+1) == to_replace) print substr($0, 1, RLENGTH)replace_with; else print $0; }')
    eval "$new_definition"
}

# Restore xtrace
$MY_XTRACE