Skip to content

Commit

Permalink
FOT test refactoring (faucetsdn#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
grafnu authored Oct 20, 2020
1 parent 2c66ef7 commit 419b76a
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 67 deletions.
14 changes: 5 additions & 9 deletions bin/net_clean
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
#!/bin/bash

echo Killing any old instances of forch...
pids=`ps ax |
fgrep forch |
fgrep -v fgrep |
fgrep -v grep |
fgrep -v net_clean |
awk '{print $1}'`
sudo kill $pids || true
pids=`ps ax | fgrep forch | fgrep bash` | xargs -r kill $pids

echo Cleaning docker images...
for image in forch/faucet forch/faux forch/gauge forch/controller; do
Expand Down Expand Up @@ -42,8 +36,10 @@ sudo /etc/init.d/openvswitch-switch restart
echo Cleaning veth...
veths=`ip link | fgrep @| sed 's/@.*//' | awk '{ print $2 }'`
for veth in $veths; do
echo Deleting veth $veth
sudo ip link del $veth
if [ -d /sys/class/net/$veth ]; then
echo Deleting veth $veth
sudo ip link del $veth
fi
done

echo Cleaning netnses...
Expand Down
6 changes: 3 additions & 3 deletions bin/run_controller
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ if [ $IMAGE == "forch/controller" ] && [[ $faucet_id =~ ^[0-9]+$ ]]; then
for file in $INSTDIR/forch/*; do docker cp $file $CONTAINER:/etc/faucet/; done
# docker exec $CONTAINER /usr/bin/gauge --ryu-config-file=${GAUGE_RYU_CONF} --ryu-ofp-tcp-listen-port=${GAUGE_LISTEN_PORT} --ryu-wsapi-host=${WSAPI_LISTEN_HOST} --ryu-wsapi-port=${WSAPI_LISTEN_PORT} --ryu-app=ryu.app.ofctl_rest &
pid=$(docker inspect --format="{{ .State.Pid }}" $cid)
data_intf_name=data_faucet_$faucet_id
sudo ip link add $data_intf_name type veth peer name data0 netns $pid
sudo ip link set $data_intf_name up
tap_intf_name=cntrl_tap_$faucet_id
sudo ip link add $tap_intf_name type veth peer name data0 netns $pid
sudo ip link set $tap_intf_name up
docker exec $CONTAINER ip addr add 192.168.2.$faucet_id dev data0
docker exec $CONTAINER ip link set data0 up
fi
Expand Down
2 changes: 1 addition & 1 deletion bin/run_faucet
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ cid=$(docker run -d --privileged --name $CONTAINER \

if [ $IMAGE == "forch/faucet" ] && [[ $faucet_id =~ ^[0-9]+$ ]]; then
pid=$(docker inspect --format="{{ .State.Pid }}" $cid)
data_intf_name=data_faucet_$faucet_id
data_intf_name=cntrl_tap_$faucet_id
sudo ip link add $data_intf_name type veth peer name data0 netns $pid
sudo ip link set $data_intf_name up
docker exec $CONTAINER ip link add link data0 name data0.272 type vlan id 272
Expand Down
5 changes: 2 additions & 3 deletions bin/setup_stack
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,12 @@ for index in 1; do
fi
done

echo Connecting faux interfaces
echo Connecting faux interfaces...
add_faux corp 1 0 dnsmasq
add_faux t2sw1 1 1
add_faux t2sw2 1 2
add_faux t2sw3 1 3 $faux_dhcp
add_iface t1sw1 4 cntrl_tap_1

dcount=${devices:-3}
scount=${switches:-3}
Expand All @@ -144,8 +145,6 @@ if [ -n "$devices" ]; then
echo Adding extra device num $fnum
add_faux t2sw1 $fnum $fnum
done
else
add_iface t1sw1 4 data_faucet_1
fi

if [ -n "$switches" ]; then
Expand Down
8 changes: 4 additions & 4 deletions bin/stack_functions
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ function add_link {
iface_b=$br_b-eth$pt_b

echo Adding $iface_a linked $iface_b
sudo ip link del $iface_a || true
sudo ip link del $iface_b || true
sudo ip link del $iface_a 2> /dev/null || true
sudo ip link del $iface_b 2> /dev/null || true
sudo ip link add $iface_a type veth peer name $iface_b
sudo ifconfig $iface_a up
sudo ifconfig $iface_b up
Expand Down Expand Up @@ -89,8 +89,8 @@ function add_oeth {
iface_b=$3

echo Adding $iface_a linked to $iface_b
sudo ip link del $iface_a || true
sudo ip link del $iface_b || true
sudo ip link del $iface_a 2> /dev/null || true
sudo ip link del $iface_b 2> /dev/null || true
sudo ip link add $iface_a type veth peer name $iface_b
sudo ifconfig $iface_a up
sudo ovs-vsctl add-port $br_a $iface_a -- set interface $iface_a ofport_request=$pt_a
Expand Down
2 changes: 1 addition & 1 deletion etc/Dockerfile.controller
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

FROM faucet/python3:5.0.1

RUN apk add -q tcpdump iptables sudo linux-headers openvswitch libstdc++
RUN apk add -q tcpdump iptables sudo linux-headers openvswitch libstdc++ coreutils

COPY faucet/ /faucet-src/
RUN /faucet-src/docker/install-faucet.sh && rm -rf /faucet-src/.git
Expand Down
8 changes: 4 additions & 4 deletions etc/docker_images.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
forch/controller a20697ff53b7
forch/faucet cb7f514dc541
forch/faux 5177277688bf
forch/gauge fc90779146ac
forch/controller aaa6ef4603ad
forch/faucet 2057f112f51d
forch/faux 38b4bfe3bf7f
forch/gauge fc2c1e4a156a
8 changes: 4 additions & 4 deletions forch/forchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,11 +716,11 @@ def _validate_config(self, config):
is_egress = 1 if 'lacp' in if_obj else 0
is_stack = 1 if 'stack' in if_obj else 0
is_access = 1 if 'native_vlan' in if_obj else 0
is_trunk = 1 if if_obj['description'] == 'trunk' else 0
is_tap = 1 if if_obj['description'] == 'tap' else 0
is_mirror = 1 if if_obj['description'] == 'mirror' else 0
if (is_egress + is_stack + is_access + is_trunk + is_mirror) != 1:
warnings.append((if_key, 'misconfigured interface config: %d %d %d' %
(is_egress, is_stack, is_access)))
if (is_egress + is_stack + is_access + is_tap + is_mirror) != 1:
warnings.append((if_key, 'misconfigured interface config: %d %d %d %d %d' %
(is_egress, is_stack, is_access, is_tap, is_mirror)))
if 'loop_protect_external' in if_obj:
warnings.append((if_key, 'deprecated loop_protect_external'))
if is_access and 'max_hosts' not in if_obj:
Expand Down
2 changes: 1 addition & 1 deletion testing/python_lib/integration_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def tcpdump_helper(*args, **kwargs):

def _setup_stack(self):
options = self.stack_options
print("stack_options = %s", str(options))
print("stack_options = %s" % str(options))
stack_args = []
stack_args.extend(['local'] if options.get('local') else [])
devices = options.get('devices')
Expand Down
73 changes: 38 additions & 35 deletions testing/python_lib/test_fot.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,6 @@
)


class FotConfigTest(IntegrationTestBase):
"""Test suite for dynamic config changes"""

def test_stack_connectivity(self):
"""Test to build stack and check for connectivity"""
print('Running test_stack_connectivity')
self.assertTrue(self._ping_host('forch-faux-1', '192.168.1.2'))
self.assertFalse(self._ping_host('forch-faux-1', '192.168.1.12'))

def test_fot_sequester(self):
"""Test to check if OT trunk sequesters traffic as expected"""
self.assertTrue(self._ping_host('forch-faux-1', '192.168.1.2'))

config = self._read_faucet_config()
interface = config['dps']['nz-kiwi-t2sw1']['interfaces'][1]
interface['native_vlan'] = 272
self._write_faucet_config(config)
time.sleep(5)
self.assertTrue(self._ping_host('forch-faux-1', '192.168.2.1'))
self.assertFalse(self._ping_host('forch-faux-1', '192.168.1.2'))


class FotFaucetizerTestCase(FaucetizerTestBase):
"""Faucetizer test"""

Expand Down Expand Up @@ -261,16 +239,39 @@ def test_ports_states(self):
self._verify_received_device_placements(expired_received_device_placements)


class FotContainerTest(IntegrationTestBase):
class FotSequesterTest(IntegrationTestBase):
"""Base class for sequestering integration tests"""

def _sequester_device(self):
config = self._read_faucet_config()
interface = config['dps']['nz-kiwi-t2sw1']['interfaces'][1]
interface['native_vlan'] = 272
self._write_faucet_config(config)
time.sleep(5)


class FotConfigTest(FotSequesterTest):
"""Simple config change tests for fot"""

def test_fot_sequester(self):
"""Test to check if OT trunk sequesters traffic as expected"""
self.assertTrue(self._ping_host('forch-faux-1', '192.168.1.2'))
self.assertFalse(self._ping_host('forch-faux-1', '192.168.2.1'))

self._sequester_device()

self.assertFalse(self._ping_host('forch-faux-1', '192.168.1.2'))
self.assertTrue(self._ping_host('forch-faux-1', '192.168.2.1'))


class FotContainerTest(FotSequesterTest):
"""Test suite for dynamic config changes"""

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.stack_options['fot'] = True
self.stack_options['local'] = True

def test_dhcp_reflection(self):
"""Test to check DHCP reflection when on test VLAN"""
def _internal_dhcp(self, on_vlan):
def dhclient_method(container=None):
def run_dhclient():
try:
Expand All @@ -279,19 +280,21 @@ def run_dhclient():
except Exception as e:
print(e)
return run_dhclient
config = self._read_faucet_config()
tcpdump_text = self.tcpdump_helper('faux-eth0', 'port 67 or port 68', packets=10,
funcs=[dhclient_method(container='forch-faux-1')],
timeout=10, docker_host='forch-faux-1')
self.assertTrue(re.search("DHCP.*Reply", tcpdump_text))
interface = config['dps']['nz-kiwi-t2sw1']['interfaces'][1]
interface['native_vlan'] = 272
self._write_faucet_config(config)
time.sleep(5)
tcpdump_text = self.tcpdump_helper('faux-eth0', 'port 67 or port 68', packets=10,
funcs=[dhclient_method(container='forch-faux-1')],
timeout=10, docker_host='forch-faux-1')
self.assertTrue(re.search("DHCP.*Reply", tcpdump_text))
vlan_text = self.tcpdump_helper('data0', 'vlan 272 and port 67', packets=10,
funcs=[dhclient_method(container='forch-faux-1')],
timeout=10, docker_host='forch-controller-1')
self.assertEqual(on_vlan, bool(re.search("DHCP.*Reply", vlan_text)))

def test_dhcp_reflection(self):
"""Test to check DHCP reflection when on test VLAN"""
self._internal_dhcp(False)
self._sequester_device()
self._internal_dhcp(True)


if __name__ == '__main__':
unittest.main()
2 changes: 1 addition & 1 deletion topo/bond/faucet/faucet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dps:
priority: 1
interfaces:
4:
description: trunk
description: tap
tagged_vlans: [171, 272]
6:
description: "to t1sw2 port 6"
Expand Down
2 changes: 1 addition & 1 deletion topo/scale/faucet/faucet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dps:
priority: 1
interfaces:
4:
description: trunk
description: tap
tagged_vlans: [272]
6:
description: "to t1sw2 port 6"
Expand Down

0 comments on commit 419b76a

Please sign in to comment.