Passed
Pull Request — master (#129)
by Carlos
02:56
created

TestMain.test_event_add_flow()   A

Complexity

Conditions 1

Size

Total Lines 10
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nop 2
dl 0
loc 10
rs 9.95
c 0
b 0
f 0
1
"""Test Main methods."""
2
from unittest import TestCase
3
from unittest.mock import MagicMock, patch
4
5
from kytos.lib.helpers import (get_connection_mock, get_controller_mock,
6
                               get_kytos_event_mock, get_switch_mock,
7
                               get_test_client)
8
9
10
# pylint: disable=protected-access, too-many-public-methods
11
class TestMain(TestCase):
12
    """Tests for the Main class."""
13
14
    API_URL = 'http://localhost:8181/api/kytos/flow_manager'
15
16
    def setUp(self):
17
        patch('kytos.core.helpers.run_on_thread', lambda x: x).start()
18
        # pylint: disable=import-outside-toplevel
19
        from napps.kytos.flow_manager.main import Main
20
21
        self.addCleanup(patch.stopall)
22
23
        controller = get_controller_mock()
24
        self.switch_01 = get_switch_mock("00:00:00:00:00:00:00:01", 0x04)
25
        self.switch_01.is_enabled.return_value = True
26
        self.switch_01.flows = []
27
28
        self.switch_02 = get_switch_mock("00:00:00:00:00:00:00:02", 0x04)
29
        self.switch_02.is_enabled.return_value = False
30
        self.switch_02.flows = []
31
32
        controller.switches = {"00:00:00:00:00:00:00:01": self.switch_01,
33
                               "00:00:00:00:00:00:00:02": self.switch_02}
34
35
        self.napp = Main(controller)
36
37
    def test_rest_list_without_dpid(self):
38
        """Test list rest method withoud dpid."""
39
        flow_dict = {
40
            "priority": 13,
41
            "cookie": 84114964,
42
            "command": "add",
43
            "match": {"dl_dst": "00:15:af:d5:38:98"},
44
        }
45
        flow_dict_2 = {
46
            "priority": 18,
47
            "cookie": 84114964,
48
            "command": "add",
49
            "match": {"dl_dst": "00:15:af:d5:38:98"},
50
        }
51
        flow_1 = MagicMock()
52
        flow_1.as_dict.return_value = flow_dict
53
        flow_2 = MagicMock()
54
        flow_2.as_dict.return_value = flow_dict_2
55
        self.switch_01.flows.append(flow_1)
56
        self.switch_02.flows.append(flow_2)
57
58
        api = get_test_client(self.napp.controller, self.napp)
59
        url = f'{self.API_URL}/v2/flows'
60
61
        response = api.get(url)
62
        expected = {
63
            '00:00:00:00:00:00:00:01': {'flows': [flow_dict]},
64
            '00:00:00:00:00:00:00:02': {'flows': [flow_dict_2]},
65
        }
66
        self.assertEqual(response.json, expected)
67
        self.assertEqual(response.status_code, 200)
68
69
    def test_rest_list_with_dpid(self):
70
        """Test list rest method with dpid."""
71
        flow_dict = {
72
            "priority": 13,
73
            "cookie": 84114964,
74
            "command": "add",
75
            "match": {"dl_dst": "00:15:af:d5:38:98"},
76
        }
77
        flow_1 = MagicMock()
78
        flow_1.as_dict.return_value = flow_dict
79
        self.switch_01.flows.append(flow_1)
80
81
        api = get_test_client(self.napp.controller, self.napp)
82
        url = f'{self.API_URL}/v2/flows/00:00:00:00:00:00:00:01'
83
84
        response = api.get(url)
85
        expected = {'00:00:00:00:00:00:00:01': {'flows': [flow_dict]}}
86
87
        self.assertEqual(response.json, expected)
88
        self.assertEqual(response.status_code, 200)
89
90
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
91
    def test_rest_add_and_delete_without_dpid(self, mock_install_flows):
92
        """Test add and delete rest method without dpid."""
93
        api = get_test_client(self.napp.controller, self.napp)
94
95
        for method in ['flows', 'delete']:
96
            url = f'{self.API_URL}/v2/{method}'
97
98
            response_1 = api.post(url, json={'data': '123'})
99
            response_2 = api.post(url)
100
101
            self.assertEqual(response_1.status_code, 200)
102
            self.assertEqual(response_2.status_code, 404)
103
104
        self.assertEqual(mock_install_flows.call_count, 2)
105
106
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
107
    def test_rest_add_and_delete_with_dpid(self, mock_install_flows):
108
        """Test add and delete rest method with dpid."""
109
        api = get_test_client(self.napp.controller, self.napp)
110
111
        for method in ['flows', 'delete']:
112
            url_1 = f'{self.API_URL}/v2/{method}/00:00:00:00:00:00:00:01'
113
            url_2 = f'{self.API_URL}/v2/{method}/00:00:00:00:00:00:00:02'
114
            url_3 = f'{self.API_URL}/v2/{method}/00:00:00:00:00:00:00:03'
115
116
            response_1 = api.post(url_1)
117
            response_2 = api.post(url_1, json={'data': '123'})
118
            response_3 = api.post(url_2, json={'data': '123'})
119
            response_4 = api.post(url_3, json={'data': '123'})
120
121
            self.assertEqual(response_1.status_code, 404)
122
            self.assertEqual(response_2.status_code, 200)
123
            if method == 'flows':
124
                self.assertEqual(response_3.status_code, 404)
125
            else:
126
                self.assertEqual(response_3.status_code, 200)
127
            self.assertEqual(response_4.status_code, 404)
128
129
        self.assertEqual(mock_install_flows.call_count, 3)
130
131
    def test_get_all_switches_enabled(self):
132
        """Test _get_all_switches_enabled method."""
133
        switches = self.napp._get_all_switches_enabled()
134
135
        self.assertEqual(switches, [self.switch_01])
136
137 View Code Duplication
    @patch('napps.kytos.flow_manager.main.Main._store_changed_flows')
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
138
    @patch('napps.kytos.flow_manager.main.Main._send_napp_event')
139
    @patch('napps.kytos.flow_manager.main.Main._add_flow_mod_sent')
140
    @patch('napps.kytos.flow_manager.main.Main._send_flow_mod')
141
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
142
    def test_install_flows(self, *args):
143
        """Test _install_flows method."""
144
        (mock_flow_factory, mock_send_flow_mod, mock_add_flow_mod_sent,
145
         mock_send_napp_event, _) = args
146
        serializer = MagicMock()
147
        flow = MagicMock()
148
        flow_mod = MagicMock()
149
150
        flow.as_of_add_flow_mod.return_value = flow_mod
151
        serializer.from_dict.return_value = flow
152
        mock_flow_factory.return_value = serializer
153
154
        flows_dict = {'flows': [MagicMock()]}
155
        switches = [self.switch_01]
156
        self.napp._install_flows('add', flows_dict, switches)
157
158
        mock_send_flow_mod.assert_called_with(flow.switch, flow_mod)
159
        mock_add_flow_mod_sent.assert_called_with(flow_mod.header.xid,
160
                                                  flow, 'add')
161
        mock_send_napp_event.assert_called_with(self.switch_01, flow, 'add')
162
163 View Code Duplication
    @patch('napps.kytos.flow_manager.main.Main._store_changed_flows')
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
164
    @patch('napps.kytos.flow_manager.main.Main._send_napp_event')
165
    @patch('napps.kytos.flow_manager.main.Main._add_flow_mod_sent')
166
    @patch('napps.kytos.flow_manager.main.Main._send_flow_mod')
167
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
168
    def test_install_flows_with_delete_strict(self, *args):
169
        """Test _install_flows method with strict delete command."""
170
        (mock_flow_factory, mock_send_flow_mod, mock_add_flow_mod_sent,
171
         mock_send_napp_event, _) = args
172
        serializer = MagicMock()
173
        flow = MagicMock()
174
        flow_mod = MagicMock()
175
176
        flow.as_of_strict_delete_flow_mod.return_value = flow_mod
177
        serializer.from_dict.return_value = flow
178
        mock_flow_factory.return_value = serializer
179
180
        flows_dict = {'flows': [MagicMock()]}
181
        switches = [self.switch_01]
182
        self.napp._install_flows('delete_strict', flows_dict, switches)
183
184
        mock_send_flow_mod.assert_called_with(flow.switch, flow_mod)
185
        mock_add_flow_mod_sent.assert_called_with(flow_mod.header.xid,
186
                                                  flow, 'delete_strict')
187
        mock_send_napp_event.assert_called_with(self.switch_01, flow,
188
                                                'delete_strict')
189
190
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
191
    def test_event_add_flow(self, mock_install_flows):
192
        """Test event_add_flow method."""
193
        dpid = "00:00:00:00:00:00:00:01"
194
        mock_flow_dict = MagicMock()
195
        event = get_kytos_event_mock(name='kytos.flow_manager.flows.install',
196
                                     content={'dpid': dpid,
197
                                              'flow_dict': mock_flow_dict})
198
        self.napp.event_add_flow(event)
199
        mock_install_flows.assert_called()
200
201
    def test_add_flow_mod_sent(self):
202
        """Test _add_flow_mod_sent method."""
203
        xid = 0
204
        flow = MagicMock()
205
206
        self.napp._add_flow_mod_sent(xid, flow, 'add')
207
208
        self.assertEqual(self.napp._flow_mods_sent[xid], (flow, 'add'))
209
210
    @patch('kytos.core.buffers.KytosEventBuffer.put')
211
    def test_send_flow_mod(self, mock_buffers_put):
212
        """Test _send_flow_mod method."""
213
        switch = get_switch_mock("00:00:00:00:00:00:00:01", 0x04)
214
        flow_mod = MagicMock()
215
216
        self.napp._send_flow_mod(switch, flow_mod)
217
218
        mock_buffers_put.assert_called()
219
220
    @patch('kytos.core.buffers.KytosEventBuffer.put')
221
    def test_send_napp_event(self, mock_buffers_put):
222
        """Test _send_napp_event method."""
223
        switch = get_switch_mock("00:00:00:00:00:00:00:01", 0x04)
224
        flow = MagicMock()
225
226
        for command in ['add', 'delete', 'delete_strict', 'error']:
227
            self.napp._send_napp_event(switch, flow, command)
228
229
        self.assertEqual(mock_buffers_put.call_count, 4)
230
231
    @patch('napps.kytos.flow_manager.main.Main._send_napp_event')
232
    def test_handle_errors(self, mock_send_napp_event):
233
        """Test handle_errors method."""
234
        flow = MagicMock()
235
        self.napp._flow_mods_sent[0] = (flow, 'add')
236
237
        switch = get_switch_mock("00:00:00:00:00:00:00:01")
238
        switch.connection = get_connection_mock(
239
            0x04, get_switch_mock("00:00:00:00:00:00:00:02"))
240
241
        protocol = MagicMock()
242
        protocol.unpack.return_value = 'error_packet'
243
244
        switch.connection.protocol = protocol
245
246
        message = MagicMock()
247
        message.header.xid.value = 0
248
        message.error_type = 2
249
        message.code = 5
250
        event = get_kytos_event_mock(name='.*.of_core.*.ofpt_error',
251
                                     content={'message': message,
252
                                              'source': switch.connection})
253
        self.napp.handle_errors(event)
254
255
        mock_send_napp_event.assert_called_with(flow.switch, flow, 'error',
256
                                                error_command='add',
257
                                                error_code=5, error_type=2)
258
259
    @patch("napps.kytos.flow_manager.main.StoreHouse.get_data")
260
    def test_load_flows(self, mock_storehouse):
261
        """Test load flows."""
262
        self.napp._load_flows()
263
        mock_storehouse.assert_called()
264
265
    @patch("napps.kytos.flow_manager.main.Main._install_flows")
266
    def test_resend_stored_flows(self, mock_install_flows):
267
        """Test resend stored flows."""
268
        dpid = "00:00:00:00:00:00:00:01"
269
        switch = get_switch_mock(dpid, 0x04)
270
        mock_event = MagicMock()
271
        flow = {"command": "add", "flow": MagicMock()}
272
273
        flows = {"flow_list": [flow]}
274
        mock_event.content = {"switch": switch}
275
        self.napp.controller.switches = {dpid: switch}
276
        self.napp.stored_flows = {dpid: flows}
277
        self.napp.resend_stored_flows(mock_event)
278
        mock_install_flows.assert_called()
279
280
    @patch("napps.kytos.of_core.flow.FlowFactory.get_class")
281
    @patch("napps.kytos.flow_manager.main.StoreHouse.save_flow")
282
    def test_store_changed_flows(self, mock_save_flow, _):
283
        """Test store changed flows."""
284
        dpid = "00:00:00:00:00:00:00:01"
285
        switch = get_switch_mock(dpid, 0x04)
286
        switch.id = dpid
287
        flow = {
288
            "priority": 17,
289
            "cookie": 84114964,
290
            "command": "add",
291
            "match": {"dl_dst": "00:15:af:d5:38:98"},
292
        }
293
        match_fields = {
294
            "priority": 17,
295
            "cookie": 84114964,
296
            "command": "add",
297
            "dl_dst": "00:15:af:d5:38:98",
298
        }
299
        flows = {"flow": flow}
300
301
        command = "add"
302
        flow_list = {
303
            "flow_list": [
304
                {"match_fields": match_fields, "command": "delete",
305
                 "flow": flow}
306
            ]
307
        }
308
        self.napp.stored_flows = {dpid: flow_list}
309
        self.napp._store_changed_flows(command, flows, switch)
310
        mock_save_flow.assert_called()
311
312
        self.napp.stored_flows = {}
313
        self.napp._store_changed_flows(command, flows, switch)
314
        mock_save_flow.assert_called()
315
316 View Code Duplication
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
317
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
318
    def test_check_switch_consistency_add(self, *args):
319
        """Test check_switch_consistency method.
320
321
        This test checks the case when a flow is missing in switch and have the
322
        ADD command.
323
        """
324
        (mock_flow_factory, mock_install_flows) = args
325
        dpid = "00:00:00:00:00:00:00:01"
326
        switch = get_switch_mock(dpid, 0x04)
327
        switch.flows = []
328
329
        flow_1 = MagicMock()
330
        flow_1.as_dict.return_value = {'flow_1': 'data'}
331
332
        flow_list = [{"command": "add",
333
                      "flow": {'flow_1': 'data'}
334
                      }]
335
        serializer = MagicMock()
336
337
        mock_flow_factory.return_value = serializer
338
        self.napp.stored_flows = {dpid: {"flow_list": flow_list}}
339
        self.napp.check_switch_consistency(switch)
340
        mock_install_flows.assert_called()
341
342 View Code Duplication
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
343
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
344
    def test_check_switch_consistency_delete(self, *args):
345
        """Test check_switch_consistency method.
346
347
        This test checks the case when a flow is missing in switch and have the
348
        DELETE command.
349
        """
350
        (mock_flow_factory, mock_install_flows) = args
351
        dpid = "00:00:00:00:00:00:00:01"
352
        switch = get_switch_mock(dpid, 0x04)
353
354
        flow_1 = MagicMock()
355
        flow_1.as_dict.return_value = {'flow_1': 'data'}
356
357
        flow_list = [{"command": "delete",
358
                      "flow": {'flow_1': 'data'}
359
                      }]
360
        serializer = MagicMock()
361
        serializer.from_dict.return_value = flow_1
362
363
        switch.flows = [flow_1]
364
365
        mock_flow_factory.return_value = serializer
366
        self.napp.stored_flows = {dpid: {"flow_list": flow_list}}
367
        self.napp.check_switch_consistency(switch)
368
        mock_install_flows.assert_called()
369
370 View Code Duplication
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
371
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
372
    def test_check_storehouse_consistency(self, *args):
373
        """Test check_storehouse_consistency method.
374
375
        This test checks the case when a flow is missing in storehouse.
376
        """
377
        (mock_flow_factory, mock_install_flows) = args
378
        dpid = "00:00:00:00:00:00:00:01"
379
        switch = get_switch_mock(dpid, 0x04)
380
381
        flow_1 = MagicMock()
382
        flow_1.as_dict.return_value = {'flow_1': 'data'}
383
384
        switch.flows = [flow_1]
385
386
        flow_list = [{"command": "add",
387
                      "flow": {'flow_2': 'data'}
388
                      }]
389
        serializer = MagicMock()
390
391
        mock_flow_factory.return_value = serializer
392
        self.napp.stored_flows = {dpid: {"flow_list": flow_list}}
393
        self.napp.check_storehouse_consistency(switch)
394
        mock_install_flows.assert_called()
395
396 View Code Duplication
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
397
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
398
    @patch("napps.kytos.flow_manager.main.StoreHouse.save_flow")
399
    def test_no_strict_delete(self, *args):
400
        """Test the non-strict matching method.
401
402
        Test non-strict matching to delete a Flow using a cookie.
403
        """
404
        (mock_save_flow, _, _) = args
405
        dpid = "00:00:00:00:00:00:00:01"
406
        switch = get_switch_mock(dpid, 0x04)
407
        switch.id = dpid
408
        stored_flow = {
409
            "command": "add",
410
            "flow": {
411
                "actions": [{"action_type": "set_vlan", "vlan_id": 300}],
412
                "cookie": 6191162389751548793,
413
                "match": {"dl_vlan": 300, "in_port": 1},
414
            },
415
        }
416
        stored_flow2 = {
417
            "command": "add",
418
            "flow": {
419
                "actions": [],
420
                "cookie": 4961162389751548787,
421
                "match": {"in_port": 2},
422
            },
423
        }
424
        flow_to_install = {
425
            "cookie": 6191162389751548793,
426
            "cookie_mask": 18446744073709551615,
427
        }
428
        flow_list = {"flow_list": [stored_flow, stored_flow2]}
429
        command = "delete"
430
        self.napp.stored_flows = {dpid: flow_list}
431
432
        self.napp._store_changed_flows(command, flow_to_install, switch)
433
        mock_save_flow.assert_called()
434
        self.assertEqual(len(self.napp.stored_flows), 1)
435
436 View Code Duplication
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
437
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
438
    @patch("napps.kytos.flow_manager.main.StoreHouse.save_flow")
439
    def test_no_strict_delete_with_ipv4(self, *args):
440
        """Test the non-strict matching method.
441
442
        Test non-strict matching to delete a Flow using IPv4.
443
        """
444
        (mock_save_flow, _, _) = args
445
        dpid = "00:00:00:00:00:00:00:01"
446
        switch = get_switch_mock(dpid, 0x04)
447
        switch.id = dpid
448
        stored_flow = {
449
            "command": "add",
450
            "flow": {
451
                "priority": 10,
452
                "cookie": 84114904,
453
                "match": {
454
                    "ipv4_src": "192.168.1.120",
455
                    "ipv4_dst": "192.168.0.2",
456
                },
457
                "actions": [],
458
            },
459
        }
460
        stored_flow2 = {
461
            "command": "add",
462
            "flow": {
463
                "actions": [],
464
                "cookie": 4961162389751548787,
465
                "match": {"in_port": 2},
466
            },
467
        }
468
        flow_to_install = {"match": {"ipv4_src": '192.168.1.1/24'}}
469
        flow_list = {"flow_list": [stored_flow, stored_flow2]}
470
        command = "delete"
471
        self.napp.stored_flows = {dpid: flow_list}
472
473
        self.napp._store_changed_flows(command, flow_to_install, switch)
474
        mock_save_flow.assert_called()
475
        self.assertEqual(len(self.napp.stored_flows[dpid]['flow_list']), 2)
476
477 View Code Duplication
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
478
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
479
    @patch("napps.kytos.flow_manager.main.StoreHouse.save_flow")
480
    def test_no_strict_delete_with_ipv4_fail(self, *args):
481
        """Test the non-strict matching method.
482
483
        Test non-strict Fail case matching to delete a Flow using IPv4.
484
        """
485
        (mock_save_flow, _, _) = args
486
        dpid = "00:00:00:00:00:00:00:01"
487
        switch = get_switch_mock(dpid, 0x04)
488
        switch.id = dpid
489
        stored_flow = {
490
            "command": "add",
491
            "flow": {
492
                "priority": 10,
493
                "cookie": 84114904,
494
                "match": {
495
                    "ipv4_src": "192.168.2.1",
496
                    "ipv4_dst": "192.168.0.2",
497
                },
498
                "actions": [],
499
            },
500
        }
501
        stored_flow2 = {
502
            "command": "add",
503
            "flow": {
504
                "actions": [],
505
                "cookie": 4961162389751548787,
506
                "match": {"in_port": 2},
507
            },
508
        }
509
        flow_to_install = {"match": {"ipv4_src": '192.168.1.1/24'}}
510
        flow_list = {"flow_list": [stored_flow, stored_flow2]}
511
        command = "delete"
512
        self.napp.stored_flows = {dpid: flow_list}
513
514
        self.napp._store_changed_flows(command, flow_to_install, switch)
515
        mock_save_flow.assert_called()
516
        self.assertEqual(len(self.napp.stored_flows[dpid]['flow_list']), 3)
517
518
    @patch('napps.kytos.flow_manager.main.Main._install_flows')
519
    @patch('napps.kytos.flow_manager.main.FlowFactory.get_class')
520
    @patch("napps.kytos.flow_manager.main.StoreHouse.save_flow")
521
    def test_no_strict_delete_of10(self, *args):
522
        """Test the non-strict matching method.
523
524
        Test non-strict matching to delete a Flow using OF10.
525
        """
526
        (mock_save_flow, _, _) = args
527
        dpid = "00:00:00:00:00:00:00:01"
528
        switch = get_switch_mock(dpid, 0x01)
529
        switch.id = dpid
530
        stored_flow = {
531
            "command": "add",
532
            "flow": {
533
                "actions": [{"max_len": 65535, "port": 6}],
534
                "cookie": 4961162389751548787,
535
                "match": {
536
                    "in_port": 80,
537
                    "dl_src": "00:00:00:00:00:00",
538
                    "dl_dst": "f2:0b:a4:7d:f8:ea",
539
                    "dl_vlan": 0,
540
                    "dl_vlan_pcp": 0,
541
                    "dl_type": 0,
542
                    "nw_tos": 0,
543
                    "nw_proto": 0,
544
                    "nw_src": "192.168.0.1",
545
                    "nw_dst": "0.0.0.0",
546
                    "tp_src": 0,
547
                    "tp_dst": 0,
548
                },
549
                "out_port": 65532,
550
                "priority": 123,
551
            },
552
        }
553
        stored_flow2 = {
554
            "command": "add",
555
            "flow": {
556
                "actions": [],
557
                "cookie": 4961162389751654,
558
                "match": {
559
                    "in_port": 2,
560
                    "dl_src": "00:00:00:00:00:00",
561
                    "dl_dst": "f2:0b:a4:7d:f8:ea",
562
                    "dl_vlan": 0,
563
                    "dl_vlan_pcp": 0,
564
                    "dl_type": 0,
565
                    "nw_tos": 0,
566
                    "nw_proto": 0,
567
                    "nw_src": "192.168.0.1",
568
                    "nw_dst": "0.0.0.0",
569
                    "tp_src": 0,
570
                    "tp_dst": 0,
571
                },
572
                "out_port": 655,
573
                "priority": 1,
574
            },
575
        }
576
        flow_to_install = {"match": {"in_port": 80, "wildcards": 4194303}}
577
        flow_list = {"flow_list": [stored_flow, stored_flow2]}
578
        command = "delete"
579
        self.napp.stored_flows = {dpid: flow_list}
580
581
        self.napp._store_changed_flows(command, flow_to_install, switch)
582
        mock_save_flow.assert_called()
583
        self.assertEqual(len(self.napp.stored_flows[dpid]['flow_list']), 1)
584