summaryrefslogtreecommitdiff
path: root/smoketest/scripts/cli/test_system_ipv6.py
blob: 6fe58701bc5d2ed34b2360d7d8b9111c98b70037 (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env python3
#
# Copyright (C) 2021-2022 VyOS maintainers and contributors
#
# 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.template import is_ipv4
from vyos.util import read_file
from vyos.util import is_ipv6_enabled
from vyos.validate import is_intf_addr_assigned

base_path = ['system', 'ipv6']

file_forwarding = '/proc/sys/net/ipv6/conf/all/forwarding'
file_disable = '/proc/sys/net/ipv6/conf/all/disable_ipv6'
file_dad = '/proc/sys/net/ipv6/conf/all/accept_dad'
file_multipath = '/proc/sys/net/ipv6/fib_multipath_hash_policy'

class TestSystemIPv6(VyOSUnitTestSHIM.TestCase):
    def tearDown(self):
        self.cli_delete(base_path)
        self.cli_commit()

    def test_system_ipv6_forwarding(self):
        # Test if IPv6 forwarding can be disabled globally, default is '1'
        # which means forwearding enabled
        self.assertEqual(read_file(file_forwarding), '1')

        self.cli_set(base_path + ['disable-forwarding'])
        self.cli_commit()

        self.assertEqual(read_file(file_forwarding), '0')

    def test_system_ipv6_disable(self):
        # Verify previous "enable" state
        self.assertEqual(read_file(file_disable), '0')
        self.assertTrue(is_ipv6_enabled())

        loopbacks = ['127.0.0.1', '::1']
        for addr in loopbacks:
            self.assertTrue(is_intf_addr_assigned('lo', addr))

        # Do not assign any IPv6 address on interfaces, this requires a reboot
        # which can not be tested, but we can read the config file :)
        self.cli_set(base_path + ['disable'])
        self.cli_commit()

        # Verify configuration file
        self.assertEqual(read_file(file_disable), '1')
        self.assertFalse(is_ipv6_enabled())

        for addr in loopbacks:
            if is_ipv4(addr):
                self.assertTrue(is_intf_addr_assigned('lo', addr))
            else:
                self.assertFalse(is_intf_addr_assigned('lo', addr))

    def test_system_ipv6_strict_dad(self):
        # This defaults to 1
        self.assertEqual(read_file(file_dad), '1')

        # Do not assign any IPv6 address on interfaces, this requires a reboot
        # which can not be tested, but we can read the config file :)
        self.cli_set(base_path + ['strict-dad'])
        self.cli_commit()

        # Verify configuration file
        self.assertEqual(read_file(file_dad), '2')

    def test_system_ipv6_multipath(self):
        # This defaults to 0
        self.assertEqual(read_file(file_multipath), '0')

        # Do not assign any IPv6 address on interfaces, this requires a reboot
        # which can not be tested, but we can read the config file :)
        self.cli_set(base_path + ['multipath', 'layer4-hashing'])
        self.cli_commit()

        # Verify configuration file
        self.assertEqual(read_file(file_multipath), '1')

    def test_system_ipv6_neighbor_table_size(self):
        # Maximum number of entries to keep in the ARP cache, the
        # default is 8192

        gc_thresh3 = '/proc/sys/net/ipv6/neigh/default/gc_thresh3'
        gc_thresh2 = '/proc/sys/net/ipv6/neigh/default/gc_thresh2'
        gc_thresh1 = '/proc/sys/net/ipv6/neigh/default/gc_thresh1'
        self.assertEqual(read_file(gc_thresh3), '8192')
        self.assertEqual(read_file(gc_thresh2), '4096')
        self.assertEqual(read_file(gc_thresh1), '1024')

        for size in [1024, 2048, 4096, 8192, 16384, 32768]:
            self.cli_set(base_path + ['neighbor', 'table-size', str(size)])
            self.cli_commit()

            self.assertEqual(read_file(gc_thresh3), str(size))
            self.assertEqual(read_file(gc_thresh2), str(size // 2))
            self.assertEqual(read_file(gc_thresh1), str(size // 8))

if __name__ == '__main__':
    unittest.main(verbosity=2)