Scott Baker | 761e106 | 2016-06-20 17:18:17 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Matteo Scandolo | aca8665 | 2017-08-08 13:05:27 -0700 | [diff] [blame] | 3 | # Copyright 2017-present Open Networking Foundation |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | |
| 18 | |
Scott Baker | 761e106 | 2016-06-20 17:18:17 -0700 | [diff] [blame] | 19 | function mac_to_iface { |
| 20 | MAC=$1 |
| 21 | ifconfig|grep $MAC| awk '{print $1}'|grep -v '\.' |
| 22 | } |
| 23 | |
| 24 | iptables -L > /dev/null |
| 25 | ip6tables -L > /dev/null |
| 26 | |
| 27 | STAG={{ s_tags[0] }} |
| 28 | CTAG={{ c_tags[0] }} |
| 29 | VCPE=vcpe-$STAG-$CTAG |
| 30 | |
| 31 | docker inspect $VCPE > /dev/null 2>&1 |
| 32 | if [ "$?" == 1 ] |
| 33 | then |
| 34 | docker pull andybavier/docker-vcpe |
| 35 | docker run -d --name=$VCPE --privileged=true --net=none -v /etc/$VCPE/dnsmasq.d:/etc/dnsmasq.d andybavier/docker-vcpe |
| 36 | else |
| 37 | docker start $VCPE |
| 38 | fi |
| 39 | |
| 40 | # Set up networking via pipework |
| 41 | WAN_IFACE=$( mac_to_iface {{ wan_mac }} ) |
| 42 | docker exec $VCPE ifconfig eth0 >> /dev/null || pipework $WAN_IFACE -i eth0 $VCPE {{ wan_ip }}/24@{{ wan_next_hop }} {{ wan_container_mac }} |
| 43 | |
| 44 | # LAN_IFACE=$( mac_to_iface {{ lan_mac }} ) |
| 45 | # Need to encapsulate VLAN traffic so that Neutron doesn't eat it |
| 46 | # Assumes that br-lan has been set up appropriately by a previous step |
| 47 | LAN_IFACE=br-lan |
| 48 | ifconfig $LAN_IFACE >> /dev/null |
| 49 | if [ "$?" == 0 ] |
| 50 | then |
| 51 | ifconfig $LAN_IFACE.$STAG >> /dev/null || ip link add link $LAN_IFACE name $LAN_IFACE.$STAG type vlan id $STAG |
| 52 | ifconfig $LAN_IFACE.$STAG up |
| 53 | docker exec $VCPE ifconfig eth1 >> /dev/null || pipework $LAN_IFACE.$STAG -i eth1 $VCPE 192.168.0.1/24 @$CTAG |
| 54 | fi |
| 55 | |
| 56 | #HPC_IFACE=$( mac_to_iface {{ hpc_client_mac }} ) |
| 57 | #docker exec $VCPE ifconfig eth2 >> /dev/null || pipework $HPC_IFACE -i eth2 $VCPE {{ hpc_client_ip }}/24 |
| 58 | |
| 59 | # Make sure VM's eth0 (hpc_client) has no IP address |
| 60 | #ifconfig $HPC_IFACE 0.0.0.0 |
| 61 | |
| 62 | # Now can start up dnsmasq |
| 63 | docker exec $VCPE service dnsmasq start |
| 64 | |
| 65 | # Attach to container |
| 66 | docker start -a $VCPE |