Test Failed
Pull Request — master (#392)
by
unknown
01:22
created

TestMatch.setUp()   B

Complexity

Conditions 1

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 26
rs 8.8571
cc 1
1
"""Testing FlowMatch structure."""
2
import unittest
3
4
from pyof.v0x04.common import flow_match as fm
5
6
7
class TestMatch(unittest.TestCase):
8
    """Test Match structure."""
9
10
    def setUp(self):
11
        """Basic setup for test."""
12
        self.oxm1 = fm.OxmTLV(fm.OxmClass.OFPXMC_OPENFLOW_BASIC,  # class
13
                              fm.OxmOfbMatchField.OFPXMT_OFB_IN_PORT,  # field
14
                              0,  # mask
15
                              b'abc')  # value
16
        self.oxm2 = fm.OxmTLV(fm.OxmClass.OFPXMC_EXPERIMENTER,
17
                              2,
18
                              0,
19
                              b'de')
20
        self.oxm3 = fm.OxmTLV(fm.OxmClass.OFPXMC_OPENFLOW_BASIC,
21
                              fm.OxmOfbMatchField.OFPXMT_OFB_IN_PHY_PORT,
22
                              0,
23
                              b'fghi')
24
25
        self.match = fm.Match(
26
            match_type=fm.MatchType.OFPMT_OXM,
27
            oxm_match_fields=fm.OxmMatchFields([self.oxm1, self.oxm2,
28
                                                self.oxm3]))
29
30
        self.oxm1_packet = b'\x80\x00\x00\x03abc'
31
        self.oxm2_packet = b'\x80\x00\x00\x02ab'
32
        self.oxm3_packet = b'\x80\x00\x00\x04fghi'
33
34
        self.match_packet = (b'\x00\x01\x00\x19' + self.oxm1_packet +
35
                             self.oxm2_packet + self.oxm3_packet + b'\x00' * 7)
36
37
    def test_get_size(self):
38
        """[Common/FlowMatch] - size 40."""
39
        self.assertEqual(self.match.get_size(), 32)
40
41
    def test_pack_unpack(self):
42
        """[Common/FlowMatch] - packing and unpacking."""
43
        packet = self.match.pack()
44
        unpacked = fm.Match()
45
        unpacked.unpack(packet)
46
        self.assertEqual(self.message.pack(), unpacked.pack())
47
48
    def test_pack(self):
49
        """[Common/FlowMatch] - packing."""
50
        for oxm, oxm_packet in zip([self.oxm1, self.oxm2, self.oxm3,
51
                                    self.match],
52
                                   [self.oxm1_packet, self.oxm2_packet,
53
                                    self.oxm3_packet, self.match_packet]):
54
            self.assertEqual(oxm, oxm_packet)
55
56
    def test_unpack(self):
57
        """[Common/FlowMatch] - unpacking."""
58
        match = fm.Match()
59
        match.unpack(self.match_packet)
60