def test_hex_array_bytearray(self): """ Test hex_array() with bytearray type. """ expected_result = '0x01 0x02 0x03 0x04' data = bytearray(b'\x01\x02\x03\x04') eq_(expected_result, utils.hex_array(data))
def msg(datapath, version, msg_type, msg_len, xid, buf): exp = None try: assert len(buf) >= msg_len except AssertionError as e: exp = e msg_parser = _MSG_PARSERS.get(version) if msg_parser is None: raise exception.OFPUnknownVersion(version=version) try: msg = msg_parser(datapath, version, msg_type, msg_len, xid, buf) except exception.OFPTruncatedMessage as e: raise e except: LOG.exception( 'Encountered an error while parsing OpenFlow packet from switch. ' 'This implies the switch sent a malformed OpenFlow packet. ' 'version 0x%02x msg_type %d msg_len %d xid %d buf %s', version, msg_type, msg_len, xid, utils.hex_array(buf)) msg = None if exp: raise exp return msg
def test_hex_array_string(self): """ Test hex_array() with str type. """ expected_result = '0x01 0x02 0x03 0x04' data = b'\x01\x02\x03\x04' eq_(expected_result, utils.hex_array(data))
def test_hex_array_bytes(self): """ Test hex_array() with bytes type. (Python3 only) """ if six.PY2: return expected_result = '0x01 0x02 0x03 0x04' data = bytes(b'\x01\x02\x03\x04') eq_(expected_result, utils.hex_array(data))
def OF_error_msg_handler(self, event): msg = event.msg try: (version, msg_type, msg_len, xid) = ofproto_parser.header(msg.data) os_ken_msg = ofproto_parser.msg( self._datapath, version, msg_type, msg_len - ofproto_common.OFP_HEADER_SIZE, xid, msg.data) LOG.error('OFPErrorMsg received: %s', os_ken_msg) except Exception: LOG.error('Unrecognized OFPErrorMsg received: ' 'type=0x%(type)02x code=0x%(code)02x ' 'message=%(msg)s', {'type': msg.type, 'code': msg.code, 'msg': utils.hex_array(msg.data)})