Test Failed
Pull Request — master (#414)
by Carlos Eduardo
01:55
created

TestPacketIn.test_pack()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
1
"""Packet in message tests."""
2
from unittest import TestCase
3
4
from pyof.v0x04.asynchronous.packet_in import PacketIn, PacketInReason
5
from pyof.v0x04.common.flow_match import OxmTLV, Match
6
from pyof.v0x04.common.header import Header
7
from tests.test_struct import TestStruct
8
9
10
oxmtlv = OxmTLV(oxm_class=32768,
11
                oxm_field=0,
12
                oxm_hasmask=0,
13
                oxm_value=b'\x00\x00\x00\x16')
14
15
match = Match(match_type=1,
16
              oxm_match_fields=[oxmtlv])
17
18
packetin = PacketIn(xid=0,
19
                    buffer_id=257,
20
                    total_len=81,
21
                    reason=1,
22
                    table_id=0,
23
                    cookie=18446744073709551615,
24
                    match=match,
25
                    data=81 * b'\x00')
26
27
dump = b'\x04\n\x00{\x00\x00\x00\x00\x00\x00\x01\x01\x00Q\x01\x00\xff\xff'
28
dump += b'\xff\xff\xff\xff\xff\xff\x00\x01\x00\x0c\x80\x00\x00\x04\x00\x00'
29
dump += b'\x00\x16\x00\x00\x00\x00\x00\x00'
30
dump += 81 * b'\x00'
31
32
33
class TestPacketIn(TestCase):
34
    """Test PacketIn class."""
35
36
    def test_pack(self):
37
        """Assert pack method returns a known dump."""
38
        self.assertEqual(dump, packetin.pack())
39
40
    def test_unpack(self):
41
        """Assert the known dump is unpacked correctly."""
42
        unpacked_header = Header()
43
        unpacked_header.unpack(dump[:8])
44
        packetin.update_header_length()
45
        self.assertEqual(packetin.header, unpacked_header)
46
47
        unpacked_packetin = PacketIn()
48
        unpacked_packetin.unpack(dump[8:])
49
        unpacked_packetin.header = unpacked_header
50
        self.assertEqual(packetin, unpacked_packetin)
51
52
53
class TestPacketInRaw(TestStruct):
54
    """Test PacketIn using a dump file."""
55
56
    @classmethod
57
    def setUpClass(cls):
58
        """Configure raw file and its object in parent class (TestDump)."""
59
        super().setUpClass()
60
        super().set_raw_dump_file('v0x04', 'ofpt_packet_in')
61
        super().set_raw_dump_object(PacketIn, xid=1, buffer_id=1, total_len=1,
62
                                    reason=PacketInReason.OFPR_ACTION,
63
                                    table_id=1, cookie=1, data=b'')
64
        super().set_minimum_size(34)
65