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