stl_ipv6_test.py revision df1e9dba
1#!/usr/bin/python
2from .stl_general_test import CStlGeneral_Test
3from trex_stl_lib.api import *
4
5class STLIPv6_Test(CStlGeneral_Test):
6    """Tests for IPv6 scan6/ping_ip """
7
8    def setUp(self):
9        CStlGeneral_Test.setUp(self)
10        print('')
11        self.stl_trex.set_service_mode(ports = [0])
12
13    def tearDown(self):
14        CStlGeneral_Test.tearDown(self)
15        self.stl_trex.set_service_mode(ports = [0], enabled = False)
16
17    def test_ipv6_ping(self):
18        ping_count = 5
19        expected_replies = 4 # allow one loss
20        results = self.stl_trex.ping_ip(src_port = 0, dst_ip = 'ff02::1', count = ping_count)
21        good_replies = len(filter(lambda result: result['status'] == 'success', results))
22        if self.is_loopback:
23            # negative test, loopback
24            if good_replies > 0:
25                self.fail('We should not respond to IPv6 in loopback at this stage, bug!\nOutput: %s' % results)
26            else:
27                print('No IPv6 replies in loopback as expected.')
28        else:
29            # positive test, DUT
30            if good_replies < expected_replies:
31                self.fail('Got only %s good replies out of %s.\nOutput: %s' % (good_replies, ping_count, results))
32            else:
33                print('Got replies from DUT as expected.')
34
35        # negative test, unknown IP
36        results = self.stl_trex.ping_ip(src_port = 0, dst_ip = '1234::1234', count = ping_count)
37        good_replies = len(filter(lambda result: result['status'] == 'success', results))
38        if good_replies > 0:
39            self.fail('We have answers from unknown IPv6, bug!\nOutput: %s' % results)
40        else:
41            print('Got no replies from unknown IPv6 as expected.')
42
43    def test_ipv6_scan6(self):
44        results = self.stl_trex.scan6(ports = 0)
45        if self.is_loopback:
46            # negative test, loopback
47            if results[0]:
48                self.fail("Scan6 found devices in loopback, we don't answer to IPv6 now, bug!\nOutput: %s" % results)
49            else:
50                print('No devices found in loopback as expected.')
51        else:
52            # positive test, DUT
53            if len(results[0]) > 1:
54                self.fail('Found more than one device at port 0: %s' % results)
55            elif len(results[0]) == 1:
56                print('Found one device as expected:\n{type:10} - {mac:20} - {ipv6}'.format(**results[0][0]))
57            else:
58                self.fail('Did not find IPv6 devices.')
59
60
61