Пример #1
0
    def test_handle_errors(self, mock_send_napp_event):
        """Test handle_errors method."""
        flow = MagicMock()
        self.napp._flow_mods_sent[0] = (flow, 'add')

        switch = get_switch_mock("00:00:00:00:00:00:00:01")
        switch.connection = get_connection_mock(
            0x04, get_switch_mock("00:00:00:00:00:00:00:02"))

        protocol = MagicMock()
        protocol.unpack.return_value = 'error_packet'

        switch.connection.protocol = protocol

        message = MagicMock()
        message.header.xid.value = 0
        message.error_type = 2
        message.code = 5
        event = get_kytos_event_mock(name='.*.of_core.*.ofpt_error',
                                     content={
                                         'message': message,
                                         'source': switch.connection
                                     })
        self.napp.handle_errors(event)

        mock_send_napp_event.assert_called_with(flow.switch,
                                                flow,
                                                'error',
                                                error_command='add',
                                                error_code=5,
                                                error_type=2)
Пример #2
0
    def setUp(self):
        """Execute steps before each tests.
        Set the server_name_url from kytos/of_core
        """
        self.switch_v0x01 = get_switch_mock("00:00:00:00:00:00:00:01", 0x01)
        self.switch_v0x04 = get_switch_mock("00:00:00:00:00:00:00:02", 0x04)
        self.switch_v0x01.connection = get_connection_mock(
            0x01, get_switch_mock("00:00:00:00:00:00:00:03"))
        self.switch_v0x04.connection = get_connection_mock(
            0x04, get_switch_mock("00:00:00:00:00:00:00:04"))

        patch('kytos.core.helpers.run_on_thread', lambda x: x).start()
        # pylint: disable=import-outside-toplevel
        from napps.kytos.of_core.main import Main
        self.addCleanup(patch.stopall)
        self.napp = Main(get_controller_mock())
Пример #3
0
    def setUp(self):
        """Execute steps before each tests.
        Set the server_name_url from kytos/of_core
        """
        self.switch_v0x01 = get_switch_mock("00:00:00:00:00:00:00:01")
        self.switch_v0x04 = get_switch_mock("00:00:00:00:00:00:00:02")
        self.switch_v0x01.connection = get_connection_mock(
            0x01, get_switch_mock("00:00:00:00:00:00:00:03"))
        self.switch_v0x04.connection = get_connection_mock(
            0x04, get_switch_mock("00:00:00:00:00:00:00:04"))

        patch('kytos.core.helpers.run_on_thread', lambda x: x).start()
        # pylint: disable=bad-option-value
        from napps.kytos.of_core.flow import FlowFactory
        self.addCleanup(patch.stopall)

        self.napp = FlowFactory()
Пример #4
0
    def test_connection_mock(self):
        """Test connection mock."""
        switch = MagicMock()
        connection_mock = get_connection_mock(0x04, switch, 'addr', 123)

        self.assertEqual(connection_mock.protocol.version, 0x04)
        self.assertEqual(connection_mock.switch, switch)
        self.assertEqual(connection_mock.address, 'addr')
        self.assertEqual(connection_mock.state, 123)
Пример #5
0
 def setUp(self):
     """Execute steps before each tests."""
     self.mock_controller = get_controller_mock()
     self.mock_switch = get_switch_mock('00:00:00:00:00:00:00:01', 0x04)
     self.mock_connection = get_connection_mock(0x04, self.mock_switch)