def _negotiate(self, connection, message): """Handle hello messages. This method will handle the incoming hello message by client and deal with negotiation. Parameters: event (KytosMessageInHello): KytosMessageInHelloEvent """ if message.versions: version = self._get_version_from_bitmask(message.versions) else: version = self._get_version_from_header(message.header.version) log.debug('connection %s: negotiated version - %s', connection.id, str(version)) if version is None: self.fail_negotiation(connection, message) raise NegotiationException() version_utils = self.of_core_version_utils[version] version_utils.say_hello(self.controller, connection) connection.protocol.name = 'openflow' connection.protocol.version = version connection.protocol.unpack = unpack connection.protocol.state = 'sending_features' self.send_features_request(connection) log.debug('Connection %s: Hello complete', connection.id)
def test_handle_raw_in(self, *args): """Test handle_raw_in.""" (mock_emit_message_in, mock_negotiate, mock_of_slicer) = args mock_packets = MagicMock() mock_data = MagicMock() mock_connection = MagicMock() mock_connection.is_new.side_effect = [True, False, True, False] mock_connection.is_during_setup.return_value = False mock_of_slicer.return_value = [[mock_packets, mock_packets], b''] name = 'kytos/core.openflow.raw.in' content = {'source': mock_connection, 'new_data': mock_data} mock_event = get_kytos_event_mock(name=name, content=content) self.napp.handle_raw_in(mock_event) mock_negotiate.assert_called() mock_emit_message_in.assert_called() # Test Fail mock_negotiate.side_effect = NegotiationException('Foo') self.napp.handle_raw_in(mock_event) self.assertEqual(mock_connection.close.call_count, 1) mock_connection.close.call_count = 0 mock_connection.protocol.unpack.side_effect = AttributeError() self.napp.handle_raw_in(mock_event) self.assertEqual(mock_connection.close.call_count, 1)