Newer
Older
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
#!bin/bash
# You must run this script as root
if [ "$EUID" -ne 0 ]; then
echo "Please run as root"
exit 1
fi
source "p4-switch-conf-common.sh"
kill_stratum() {
pkill stratum
}
delete_virtual_interfaces() {
ip netns exec ${SWITCH_NS} ip link delete ${SW_IFACE_INT}
}
delete_namespaces() {
ip netns del ${SWITCH_NS}
}
bring_interfaces_up() {
ifconfig ${SW_IFACE_DATA_EDGE} up
ifconfig ${SW_IFACE_DATA_CORP} up
}
cleanup_iptables() {
# gRPC entries
entry_no=$(iptables --line-numbers -nvL | grep ${HOST_IFACE_INT} | cut -d " " -f 1 | head -1)
iptables -D FORWARD ${entry_no}
entry_no=$(iptables --line-numbers -nvL | grep ${HOST_IFACE_INT} | cut -d " " -f 1)
iptables -D FORWARD ${entry_no}
entry_no=$(iptables --line-numbers -nvL | grep ${SW_P4RT_GRPC_PORT} | cut -d " " -f 1)
iptables -D FORWARD ${entry_no}
entry_no=$(iptables -t nat --line-numbers -nvL | grep ${SW_P4RT_GRPC_PORT} | cut -d " " -f 1)
iptables -t nat -D PREROUTING ${entry_no}
entry_no=$(iptables -t nat --line-numbers -nvL | grep ${TOPO_INT_NET} | cut -d " " -f 1)
iptables -t nat -D POSTROUTING ${entry_no}
# Check new state
echo "Forwarding tables"
iptables --line-numbers -nvL
echo -e ""
echo "NAT tables"
iptables -t nat --line-numbers -nvL
}
cleanup_tc() {
sudo tc filter del dev ${HOST_IFACE_INT} parent ffff: \
protocol all prio 2 u32 \
match u32 0 0 flowid 1:1 \
action mirred egress mirror dev ${HOST_IFACE_EXT}
sudo tc qdisc del dev ${HOST_IFACE_INT} ingress
# Check new state
echo -e ""
echo -e "Linux tc status"
tc qdisc show
}
kill_stratum
delete_virtual_interfaces
delete_namespaces
# bring_interfaces_up
cleanup_iptables
cleanup_tc
exit 0