1
|
|
|
"""Testing Error Message.""" |
2
|
|
|
from pyof.foundation.basic_types import BinaryData |
3
|
|
|
from pyof.v0x01.asynchronous.error_msg import (BadRequestCode, ErrorMsg, |
4
|
|
|
ErrorType, FlowModFailedCode) |
5
|
|
|
|
6
|
|
|
from tests.test_struct import TestStruct |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
class TestErrorMessage(TestStruct): |
10
|
|
|
"""Test the Error Message.""" |
11
|
|
|
|
12
|
|
|
@classmethod |
13
|
|
|
def setUpClass(cls): |
14
|
|
|
"""Setup TestStruct.""" |
15
|
|
|
super().setUpClass() |
16
|
|
|
super().set_raw_dump_file('v0x01', 'ofpt_error_message') |
17
|
|
|
super().set_raw_dump_object(ErrorMsg, |
18
|
|
|
**TestErrorMessage.get_attributes()) |
19
|
|
|
super().set_minimum_size(12) |
20
|
|
|
|
21
|
|
|
def test_pack_error_msg(self): |
22
|
|
|
"""Test Pack a sample ErrorMessage.""" |
23
|
|
|
error_msg = ErrorMsg(**TestErrorMessage.get_attributes()) |
24
|
|
|
expected_data = b'\x01\x01\x00\x0c\x00\x00\x00\x0c\x00\x01\x00\x02' |
25
|
|
|
self.assertEqual(error_msg.pack(), expected_data) |
26
|
|
|
|
27
|
|
|
def test_unpack_error_msg(self): |
28
|
|
|
"""Test Unpack a sample ErrorMsg.""" |
29
|
|
|
packed_data = b'\x01\x01\x00\x1b\x00\x00\x00\x18\x00\x03\x00\x02FLOW' |
30
|
|
|
|
31
|
|
|
attributes = TestErrorMessage.get_attributes( |
32
|
|
|
xid=24, error_type=ErrorType.OFPET_FLOW_MOD_FAILED, |
33
|
|
|
code=FlowModFailedCode.OFPFMFC_EPERM, data=b'FLOW') |
34
|
|
|
|
35
|
|
|
unpacked = ErrorMsg(**attributes) |
36
|
|
|
|
37
|
|
|
sample_unpacked = ErrorMsg(xid=24) |
38
|
|
|
sample_unpacked.unpack(packed_data[8:]) |
39
|
|
|
|
40
|
|
|
self.assertEqual(sample_unpacked, unpacked) |
41
|
|
|
|
42
|
|
|
@staticmethod |
43
|
|
|
def get_attributes(xid=12, error_type=ErrorType.OFPET_BAD_REQUEST, |
44
|
|
|
code=BadRequestCode.OFPBRC_BAD_STAT, |
45
|
|
|
data=BinaryData('SAMPLE ASCII DATA')): |
46
|
|
|
"""Method used to create a python dict with ErroMsg attributes.""" |
47
|
|
|
return {'xid': xid, 'error_type': error_type, 'code': code, |
48
|
|
|
'data': data} |
49
|
|
|
|