File: param.py

package info (click to toggle)
mtr 0.95-1.1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 900 kB
  • sloc: ansic: 10,325; python: 572; makefile: 164; sh: 141
file content (83 lines) | stat: -rwxr-xr-x 2,593 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/env python
#
#   mtr  --  a network diagnostic tool
#   Copyright (C) 2016  Matt Kimball
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License version 2 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, write to the Free Software Foundation, Inc.,
#   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#

'''Test probe customization parameters'''

import sys
import unittest

import mtrpacket


@unittest.skipIf(sys.platform == 'cygwin', 'No Cygwin test')
class TestParameters(mtrpacket.MtrPacketTest):
    'Use parameter arguments to mtr-packet and examine the resulting packet'

    def test_size(self):
        'Test probes sent with an explicit packet size'

        with mtrpacket.PacketListen('-4') as listen:
            cmd = '20 send-probe ip-4 127.0.0.1 size 512'

            self.write_command(cmd)

        self.assertEqual(listen.attrib['size'], '512')

    def test_pattern(self):
        'Test probes are filled with the requested bit pattern'

        with mtrpacket.PacketListen('-4') as listen:
            cmd = '20 send-probe ip-4 127.0.0.1 bit-pattern 44'

            self.write_command(cmd)

        self.assertEqual(listen.attrib['bitpattern'], '44')

    def test_tos(self):
        'Test setting the TOS field'

        with mtrpacket.PacketListen('-4') as listen:
            cmd = '20 send-probe ip-4 127.0.0.1 tos 62'

            self.write_command(cmd)

        self.assertEqual(listen.attrib['tos'], '62')


@unittest.skipIf(sys.platform == 'cygwin', 'No Cygwin test')
class TestIPv6Parameters(mtrpacket.MtrPacketTest):
    'Test packet parameter customization for IPv6'

    @unittest.skipUnless(mtrpacket.HAVE_IPV6, 'No IPv6')
    def test_param(self):
        'Test a variety of packet parameters'

        with mtrpacket.PacketListen('-6') as listen:
            param = 'size 256 bit-pattern 51 tos 77'
            cmd = '20 send-probe ip-6 ::1 ' + param

            self.write_command(cmd)

        self.assertEqual(listen.attrib['size'], '256')
        self.assertEqual(listen.attrib['bitpattern'], '51')


if __name__ == '__main__':
    mtrpacket.check_running_as_root()
    unittest.main()