|
7 | 7 | from pyof.foundation.basic_types import BinaryData, UBInt16 |
8 | 8 | from pyof.foundation.exceptions import PackException |
9 | 9 | # Do not import new_message_from_header directly to avoid cyclic import. |
10 | | -from pyof.v0x01 import common |
11 | 10 | from pyof.v0x01.common.header import Header, Type |
12 | 11 |
|
13 | 12 | __all__ = ('ErrorMsg', 'ErrorType', 'BadActionCode', 'BadRequestCode', |
@@ -37,6 +36,20 @@ class ErrorType(IntEnum): |
37 | 36 | #: Problem in modifying Queue entry |
38 | 37 | OFPET_QUEUE_OP_FAILED = 5 |
39 | 38 |
|
| 39 | + def get_class(self): |
| 40 | + """Method used to return a Code class based on current ErrorType value. |
| 41 | +
|
| 42 | + Returns: |
| 43 | + error_code_class (IntEnum): class referenced by current error type. |
| 44 | + """ |
| 45 | + classes = {'OFPET_HELLO_FAILED': HelloFailedCode, |
| 46 | + 'OFPET_BAD_REQUEST': BadRequestCode, |
| 47 | + 'OFPET_BAD_ACTION': BadActionCode, |
| 48 | + 'OFPET_FLOW_MOD_FAILED': FlowModFailedCode, |
| 49 | + 'OFPET_PORT_MOD_FAILED': PortModFailedCode, |
| 50 | + 'OFPET_QUEUE_OP_FAILED': QueueOpFailedCode} |
| 51 | + return classes[self.name] |
| 52 | + |
40 | 53 |
|
41 | 54 | class HelloFailedCode(IntEnum): |
42 | 55 | """Error_msg 'code' values for OFPET_HELLO_FAILED. |
@@ -206,20 +219,5 @@ def pack(self, value=None): |
206 | 219 | def unpack(self, buff, offset=0): |
207 | 220 | """Unpack binary data into python object.""" |
208 | 221 | super().unpack(buff, offset) |
209 | | - self.data = self._unpack_data() |
210 | | - |
211 | | - def _unpack_data(self): |
212 | | - if self.data == b'': |
213 | | - return BinaryData() |
214 | | - # header unpacking |
215 | | - header = Header() |
216 | | - header_size = header.get_size() |
217 | | - header_data = self.data.value[:header_size] |
218 | | - header.unpack(header_data) |
219 | | - |
220 | | - # message unpacking |
221 | | - msg = common.utils.new_message_from_header(header) |
222 | | - msg_data = self.data.value[header_size:] |
223 | | - msg.unpack(msg_data) |
224 | | - |
225 | | - return msg |
| 222 | + CodeClass = ErrorType(self.error_type).get_class() |
| 223 | + self.code = CodeClass(self.code) |
0 commit comments