summaryrefslogtreecommitdiff
path: root/smoketest/scripts/cli/test_protocols_static_neighbor-proxy.py
blob: beed3156c2f11a791509126236a7175e8b3927f0 (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
#!/usr/bin/env python3
#
# Copyright VyOS maintainers and contributors <maintainers@vyos.io>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or later as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


import unittest

from base_vyostest_shim import VyOSUnitTestSHIM

from vyos.utils.system import sysctl_read
from vyos.utils.process import cmd

base_path = ['protocols', 'static', 'neighbor-proxy']
interface = 'eth0'


class TestProtocolsStaticNeighborProxy(VyOSUnitTestSHIM.TestCase):
    @classmethod
    def setUpClass(cls):
        super(TestProtocolsStaticNeighborProxy, cls).setUpClass()
        cls.cli_delete(cls, base_path)

    def tearDown(self):
        self.cli_delete(base_path)
        self.cli_commit()
        super().tearDown()

    def test_arp_proxy(self):
        address = '192.0.2.1/24'
        neighbor = '192.0.2.10'

        self.cli_set(['interfaces', 'ethernet', interface, 'address', address])
        self.cli_set(base_path + ['arp', neighbor, 'interface', interface])
        self.cli_commit()

        proxy_entries = cmd('ip -4 neigh show proxy')
        self.assertIn(f'{neighbor} dev {interface} proxy', proxy_entries)

        self.cli_delete(['interfaces', 'ethernet', interface, 'address', address])

    def test_nd_proxy(self):
        address = 'fd00::1/64'
        neighbor = 'fd00::99'
        interface2 = 'eth1'

        self.cli_set(['interfaces', 'ethernet', interface, 'address', address])
        # Add ND proxy on two interfaces
        self.cli_set(base_path + ['nd', neighbor, 'interface', interface])
        self.cli_set(base_path + ['nd', neighbor, 'interface', interface2])
        self.cli_commit()

        # Verify proxy entries are installed
        proxy_entries = cmd('ip -6 neigh show proxy')
        for iface in [interface, interface2]:
            self.assertIn(f'{neighbor} dev {iface} proxy', proxy_entries)
            # Verify proxy_ndp sysctl is enabled on both interfaces
            self.assertEqual(
                sysctl_read(['net', 'ipv6', 'conf', iface, 'proxy_ndp']), '1'
            )

        # Remove one interface
        self.cli_delete(base_path + ['nd', neighbor, 'interface', interface2])
        self.cli_commit()

        # First interface still enabled
        self.assertEqual(
            sysctl_read(['net', 'ipv6', 'conf', interface, 'proxy_ndp']), '1'
        )
        # Removed interface disabled
        self.assertEqual(
            sysctl_read(['net', 'ipv6', 'conf', interface2, 'proxy_ndp']), '0'
        )

        self.cli_delete(['interfaces', 'ethernet', interface, 'address', address])


if __name__ == '__main__':
    unittest.main(verbosity=2, failfast=VyOSUnitTestSHIM.TestCase.debug_on())