aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorMarcel Enguehard <mengueha+fdio@cisco.com>2017-03-31 18:34:54 +0200
committerMarcel Enguehard <mengueha+fdio@cisco.com>2017-03-31 18:34:54 +0200
commit45e0391dd7d59beef75017c212d32b0a5d3b5c2c (patch)
tree84a6ba29ee1c8169d969a93c3aa0ac4a57806255 /scripts
parent3c7c2275b2d4660b83db9495c5f6ece5c6557b43 (diff)
Topology cleanup fix + fix for requirements + fix for local physical servers
Change-Id: Ifd090122348f362a65e5d86ce62784be2821d12b Signed-off-by: Marcel Enguehard <mengueha+fdio@cisco.com>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/topo_cleanup.sh53
1 files changed, 53 insertions, 0 deletions
diff --git a/scripts/topo_cleanup.sh b/scripts/topo_cleanup.sh
new file mode 100755
index 00000000..c2e60b8e
--- /dev/null
+++ b/scripts/topo_cleanup.sh
@@ -0,0 +1,53 @@
+#!/bin/bash
+
+if [ "$#" -ne 1 ]; then
+ echo "usage: ./topo_cleanup.sh [topology_file.json]"
+ exit 1
+fi
+
+TOPOLOGY=$1
+
+function get_by_type()
+{
+ echo $(python3 -c "import json, pprint; j = json.loads(open('$1').read()); print(' '.join(r['name'] for r in j['resources'] if r['type'] == '$2'))")
+}
+
+#grep configuration from JSON
+SERVERS=$(get_by_type $TOPOLOGY LxcContainer)
+NETWORK=$(sed -n '/network/{s/.*"\([^"]*\)"$/\1/;p}' $TOPOLOGY)
+
+# delete spurious interfaces on host
+route -n | awk '{print $8}' | tail -n -2 | grep vh | sort | uniq | xargs
+
+# Remove containers
+for server in $SERVERS; do
+ (lxc stop $server; lxc delete $server) &
+done
+wait
+
+#Kill the emulators
+killall -9 wifi_emulator
+killall -9 lte_emulator
+kill -9 $(ps aux | awk '/\/usr\/bin\/python3 \/usr\/bin\/netmon/ {print $2}')
+service netmon stop
+
+# Clean ports on OVS
+for x in $(ovs-vsctl show | sed -n '/Bridge "br0"/,/Bridge/p' | grep "No such device" | sed "s/.*device \(.*\) (No such device).*/\1/" ); do echo $x; ovs-vsctl del-port br0 $x; done
+
+for i in $(ip link | grep unk | cut -d: -f 2 | cut -d @ -f 1); do ip link delete $i; done
+for i in $(ip link | grep tmp-veth | cut -d: -f 2 | cut -d @ -f 1); do ip link delete $i; done
+for i in $(ip link | grep tap- | cut -d: -f 2 | cut -d @ -f 1); do ip link delete $i; done
+for i in $(ip link | grep mv- | cut -d: -f 2 | cut -d @ -f 1); do ip link delete $i; done
+
+# Remove bridge
+echo "Removing bridge..."
+ovs-vsctl --if-exists del-br br0
+
+# Remove taps
+echo "Removing interface..."
+for i in $(ip link show | egrep "(tap|macvlan|macvtap)" | cut -d : -f 2 | cut -d @ -f 1); do echo " - delete $i"; ip link delete $i; done
+
+#Remove routes
+echo "Removing stale routes"
+NETWORK=$(echo $NETWORK | cut -d'/' -f1 | rev | cut -d"." -f2- | rev | sed "s/\./\\\\./g")
+eval $(ip route show | sed -n '/$NETWORK\./ {s/^\(.*\) dev \(.*\) scope link.*$/route del \1 dev \2;/;p}')