~ubuntu-branches/ubuntu/wily/neutron/wily

« back to all changes in this revision

Viewing changes to neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/openflow/native/test_br_tun.py

  • Committer: Package Import Robot
  • Author(s): Corey Bryant
  • Date: 2015-09-25 17:14:07 UTC
  • mfrom: (1.1.27)
  • Revision ID: package-import@ubuntu.com-20150925171407-bcttci48k7q9togi
Tags: 2:7.0.0~rc1-0ubuntu1
* d/watch: Update to cope with upstream rc versioning.
* New upstream release candidate for OpenStack Liberty.
* d/rules: Drop removal of .eggs directory in override_dh_auto_clean.
* d/control: Bump minimum pbr version to 1.8.
* d/control: Align (build-)depends with upstream.
* d/neutron-common.install: Add neutron-dev-server and neutron-rpc-server.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2014,2015 VA Linux Systems Japan K.K.
 
2
# Copyright (C) 2014,2015 YAMAMOTO Takashi <yamamoto at valinux co jp>
 
3
# All Rights Reserved.
 
4
#
 
5
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
6
#    not use this file except in compliance with the License. You may obtain
 
7
#    a copy of the License at
 
8
#
 
9
#         http://www.apache.org/licenses/LICENSE-2.0
 
10
#
 
11
#    Unless required by applicable law or agreed to in writing, software
 
12
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
13
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
14
#    License for the specific language governing permissions and limitations
 
15
#    under the License.
 
16
 
 
17
import mock
 
18
 
 
19
import neutron.plugins.ml2.drivers.openvswitch.agent.common.constants \
 
20
    as ovs_const
 
21
from neutron.tests.unit.plugins.ml2.drivers.openvswitch.agent.openflow.native \
 
22
    import ovs_bridge_test_base
 
23
 
 
24
 
 
25
call = mock.call  # short hand
 
26
 
 
27
 
 
28
class OVSTunnelBridgeTest(ovs_bridge_test_base.OVSBridgeTestBase,
 
29
                          ovs_bridge_test_base.OVSDVRProcessTestMixin):
 
30
    dvr_process_table_id = ovs_const.DVR_PROCESS
 
31
    dvr_process_next_table_id = ovs_const.PATCH_LV_TO_TUN
 
32
 
 
33
    def setUp(self):
 
34
        super(OVSTunnelBridgeTest, self).setUp()
 
35
        self.setup_bridge_mock('br-tun', self.br_tun_cls)
 
36
 
 
37
    def test_setup_default_table(self):
 
38
        patch_int_ofport = 5555
 
39
        arp_responder_enabled = False
 
40
        self.br.setup_default_table(patch_int_ofport=patch_int_ofport,
 
41
            arp_responder_enabled=arp_responder_enabled)
 
42
        (dp, ofp, ofpp) = self._get_dp()
 
43
        expected = [
 
44
            call._send_msg(ofpp.OFPFlowMod(dp,
 
45
                cookie=0,
 
46
                instructions=[ofpp.OFPInstructionGotoTable(table_id=2)],
 
47
                match=ofpp.OFPMatch(in_port=patch_int_ofport),
 
48
                priority=1, table_id=0)),
 
49
            call._send_msg(ofpp.OFPFlowMod(dp,
 
50
                cookie=0,
 
51
                instructions=[],
 
52
                match=ofpp.OFPMatch(),
 
53
                priority=0, table_id=0)),
 
54
            call._send_msg(ofpp.OFPFlowMod(dp,
 
55
                cookie=0,
 
56
                instructions=[ofpp.OFPInstructionGotoTable(table_id=20)],
 
57
                match=ofpp.OFPMatch(
 
58
                    eth_dst=('00:00:00:00:00:00', '01:00:00:00:00:00')),
 
59
                priority=0,
 
60
                table_id=2)),
 
61
            call._send_msg(ofpp.OFPFlowMod(dp,
 
62
                cookie=0,
 
63
                instructions=[ofpp.OFPInstructionGotoTable(table_id=22)],
 
64
                match=ofpp.OFPMatch(
 
65
                    eth_dst=('01:00:00:00:00:00', '01:00:00:00:00:00')),
 
66
                priority=0,
 
67
                table_id=2)),
 
68
            call._send_msg(ofpp.OFPFlowMod(dp,
 
69
                cookie=0,
 
70
                instructions=[],
 
71
                match=ofpp.OFPMatch(),
 
72
                priority=0, table_id=3)),
 
73
            call._send_msg(ofpp.OFPFlowMod(dp,
 
74
                cookie=0,
 
75
                instructions=[],
 
76
                match=ofpp.OFPMatch(),
 
77
                priority=0, table_id=4)),
 
78
            call._send_msg(ofpp.OFPFlowMod(dp,
 
79
                cookie=0,
 
80
                instructions=[],
 
81
                match=ofpp.OFPMatch(),
 
82
                priority=0, table_id=6)),
 
83
            call._send_msg(ofpp.OFPFlowMod(dp,
 
84
                cookie=0,
 
85
                instructions=[
 
86
                    ofpp.OFPInstructionActions(ofp.OFPIT_APPLY_ACTIONS, [
 
87
                        ofpp.NXActionLearn(
 
88
                            cookie=0,
 
89
                            hard_timeout=300,
 
90
                            priority=1,
 
91
                            specs=[
 
92
                                ofpp.NXFlowSpecMatch(
 
93
                                    dst=('vlan_vid', 0),
 
94
                                    n_bits=12,
 
95
                                    src=('vlan_vid', 0)),
 
96
                                ofpp.NXFlowSpecMatch(
 
97
                                    dst=('eth_dst', 0),
 
98
                                    n_bits=48,
 
99
                                    src=('eth_src', 0)),
 
100
                                ofpp.NXFlowSpecLoad(
 
101
                                    dst=('vlan_vid', 0),
 
102
                                    n_bits=12,
 
103
                                    src=0),
 
104
                                ofpp.NXFlowSpecLoad(
 
105
                                    dst=('tunnel_id', 0),
 
106
                                    n_bits=64,
 
107
                                    src=('tunnel_id', 0)),
 
108
                                ofpp.NXFlowSpecOutput(
 
109
                                    dst='',
 
110
                                    n_bits=32,
 
111
                                    src=('in_port', 0)),
 
112
                            ],
 
113
                            table_id=20),
 
114
                        ofpp.OFPActionOutput(patch_int_ofport, 0),
 
115
                    ]),
 
116
                ],
 
117
                match=ofpp.OFPMatch(),
 
118
                priority=1,
 
119
                table_id=10)),
 
120
            call._send_msg(ofpp.OFPFlowMod(dp,
 
121
                cookie=0,
 
122
                instructions=[ofpp.OFPInstructionGotoTable(table_id=22)],
 
123
                match=ofpp.OFPMatch(),
 
124
                priority=0,
 
125
                table_id=20)),
 
126
            call._send_msg(ofpp.OFPFlowMod(dp,
 
127
                cookie=0,
 
128
                instructions=[],
 
129
                match=ofpp.OFPMatch(),
 
130
                priority=0,
 
131
                table_id=22))
 
132
        ]
 
133
        self.assertEqual(expected, self.mock.mock_calls)
 
134
 
 
135
    def test_setup_default_table_arp_responder_enabled(self):
 
136
        patch_int_ofport = 5555
 
137
        arp_responder_enabled = True
 
138
        self.br.setup_default_table(patch_int_ofport=patch_int_ofport,
 
139
            arp_responder_enabled=arp_responder_enabled)
 
140
        (dp, ofp, ofpp) = self._get_dp()
 
141
        expected = [
 
142
            call._send_msg(ofpp.OFPFlowMod(dp,
 
143
                cookie=0,
 
144
                instructions=[ofpp.OFPInstructionGotoTable(table_id=2)],
 
145
                match=ofpp.OFPMatch(in_port=patch_int_ofport),
 
146
                priority=1, table_id=0)),
 
147
            call._send_msg(ofpp.OFPFlowMod(dp,
 
148
                cookie=0,
 
149
                instructions=[],
 
150
                match=ofpp.OFPMatch(),
 
151
                priority=0, table_id=0)),
 
152
            call._send_msg(ofpp.OFPFlowMod(dp,
 
153
                cookie=0,
 
154
                instructions=[ofpp.OFPInstructionGotoTable(table_id=21)],
 
155
                match=ofpp.OFPMatch(
 
156
                    eth_dst='ff:ff:ff:ff:ff:ff',
 
157
                    eth_type=self.ether_types.ETH_TYPE_ARP),
 
158
                priority=1,
 
159
                table_id=2)),
 
160
            call._send_msg(ofpp.OFPFlowMod(dp,
 
161
                cookie=0,
 
162
                instructions=[ofpp.OFPInstructionGotoTable(table_id=20)],
 
163
                match=ofpp.OFPMatch(
 
164
                    eth_dst=('00:00:00:00:00:00', '01:00:00:00:00:00')),
 
165
                priority=0,
 
166
                table_id=2)),
 
167
            call._send_msg(ofpp.OFPFlowMod(dp,
 
168
                cookie=0,
 
169
                instructions=[ofpp.OFPInstructionGotoTable(table_id=22)],
 
170
                match=ofpp.OFPMatch(
 
171
                    eth_dst=('01:00:00:00:00:00', '01:00:00:00:00:00')),
 
172
                priority=0,
 
173
                table_id=2)),
 
174
            call._send_msg(ofpp.OFPFlowMod(dp,
 
175
                cookie=0,
 
176
                instructions=[],
 
177
                match=ofpp.OFPMatch(),
 
178
                priority=0, table_id=3)),
 
179
            call._send_msg(ofpp.OFPFlowMod(dp,
 
180
                cookie=0,
 
181
                instructions=[],
 
182
                match=ofpp.OFPMatch(),
 
183
                priority=0, table_id=4)),
 
184
            call._send_msg(ofpp.OFPFlowMod(dp,
 
185
                cookie=0,
 
186
                instructions=[],
 
187
                match=ofpp.OFPMatch(),
 
188
                priority=0, table_id=6)),
 
189
            call._send_msg(ofpp.OFPFlowMod(dp,
 
190
                cookie=0,
 
191
                instructions=[
 
192
                    ofpp.OFPInstructionActions(ofp.OFPIT_APPLY_ACTIONS, [
 
193
                        ofpp.NXActionLearn(
 
194
                            cookie=0,
 
195
                            hard_timeout=300,
 
196
                            priority=1,
 
197
                            specs=[
 
198
                                ofpp.NXFlowSpecMatch(
 
199
                                    dst=('vlan_vid', 0),
 
200
                                    n_bits=12,
 
201
                                    src=('vlan_vid', 0)),
 
202
                                ofpp.NXFlowSpecMatch(
 
203
                                    dst=('eth_dst', 0),
 
204
                                    n_bits=48,
 
205
                                    src=('eth_src', 0)),
 
206
                                ofpp.NXFlowSpecLoad(
 
207
                                    dst=('vlan_vid', 0),
 
208
                                    n_bits=12,
 
209
                                    src=0),
 
210
                                ofpp.NXFlowSpecLoad(
 
211
                                    dst=('tunnel_id', 0),
 
212
                                    n_bits=64,
 
213
                                    src=('tunnel_id', 0)),
 
214
                                ofpp.NXFlowSpecOutput(
 
215
                                    dst='',
 
216
                                    n_bits=32,
 
217
                                    src=('in_port', 0)),
 
218
                            ],
 
219
                            table_id=20),
 
220
                        ofpp.OFPActionOutput(patch_int_ofport, 0),
 
221
                    ]),
 
222
                ],
 
223
                match=ofpp.OFPMatch(),
 
224
                priority=1,
 
225
                table_id=10)),
 
226
            call._send_msg(ofpp.OFPFlowMod(dp,
 
227
                cookie=0,
 
228
                instructions=[ofpp.OFPInstructionGotoTable(table_id=22)],
 
229
                match=ofpp.OFPMatch(),
 
230
                priority=0,
 
231
                table_id=20)),
 
232
            call._send_msg(ofpp.OFPFlowMod(dp,
 
233
                cookie=0,
 
234
                instructions=[ofpp.OFPInstructionGotoTable(table_id=22)],
 
235
                match=ofpp.OFPMatch(),
 
236
                priority=0,
 
237
                table_id=21)),
 
238
            call._send_msg(ofpp.OFPFlowMod(dp,
 
239
                cookie=0,
 
240
                instructions=[],
 
241
                match=ofpp.OFPMatch(),
 
242
                priority=0,
 
243
                table_id=22))
 
244
        ]
 
245
        self.assertEqual(expected, self.mock.mock_calls)
 
246
 
 
247
    def test_provision_local_vlan(self):
 
248
        network_type = 'vxlan'
 
249
        lvid = 888
 
250
        segmentation_id = 777
 
251
        distributed = False
 
252
        self.br.provision_local_vlan(network_type=network_type, lvid=lvid,
 
253
                                     segmentation_id=segmentation_id,
 
254
                                     distributed=distributed)
 
255
        (dp, ofp, ofpp) = self._get_dp()
 
256
        expected = [
 
257
            call._send_msg(ofpp.OFPFlowMod(dp,
 
258
                cookie=0,
 
259
                instructions=[
 
260
                    ofpp.OFPInstructionActions(ofp.OFPIT_APPLY_ACTIONS, [
 
261
                        ofpp.OFPActionPushVlan(),
 
262
                        ofpp.OFPActionSetField(
 
263
                            vlan_vid=lvid | ofp.OFPVID_PRESENT)
 
264
                    ]),
 
265
                    ofpp.OFPInstructionGotoTable(table_id=10),
 
266
                ],
 
267
                match=ofpp.OFPMatch(tunnel_id=segmentation_id),
 
268
                priority=1,
 
269
                table_id=4)),
 
270
        ]
 
271
        self.assertEqual(expected, self.mock.mock_calls)
 
272
 
 
273
    def test_reclaim_local_vlan(self):
 
274
        network_type = 'vxlan'
 
275
        segmentation_id = 777
 
276
        self.br.reclaim_local_vlan(network_type=network_type,
 
277
                                   segmentation_id=segmentation_id)
 
278
        (dp, ofp, ofpp) = self._get_dp()
 
279
        expected = [
 
280
            call.delete_flows(
 
281
                table_id=4,
 
282
                match=ofpp.OFPMatch(tunnel_id=segmentation_id)),
 
283
        ]
 
284
        self.assertEqual(expected, self.mock.mock_calls)
 
285
 
 
286
    def test_install_flood_to_tun(self):
 
287
        vlan = 3333
 
288
        tun_id = 2222
 
289
        ports = [11, 44, 22, 33]
 
290
        self.br.install_flood_to_tun(vlan=vlan,
 
291
                                     tun_id=tun_id,
 
292
                                     ports=ports)
 
293
        (dp, ofp, ofpp) = self._get_dp()
 
294
        expected = [
 
295
            call._send_msg(ofpp.OFPFlowMod(dp,
 
296
                cookie=0,
 
297
                instructions=[
 
298
                    ofpp.OFPInstructionActions(ofp.OFPIT_APPLY_ACTIONS, [
 
299
                        ofpp.OFPActionPopVlan(),
 
300
                        ofpp.OFPActionSetField(tunnel_id=tun_id),
 
301
                    ] + [ofpp.OFPActionOutput(p, 0) for p in ports]),
 
302
                ],
 
303
                match=ofpp.OFPMatch(vlan_vid=vlan | ofp.OFPVID_PRESENT),
 
304
                priority=1,
 
305
                table_id=22)),
 
306
        ]
 
307
        self.assertEqual(expected, self.mock.mock_calls)
 
308
 
 
309
    def test_delete_flood_to_tun(self):
 
310
        vlan = 3333
 
311
        self.br.delete_flood_to_tun(vlan=vlan)
 
312
        (dp, ofp, ofpp) = self._get_dp()
 
313
        expected = [
 
314
            call.delete_flows(table_id=22,
 
315
                match=ofpp.OFPMatch(vlan_vid=vlan | ofp.OFPVID_PRESENT)),
 
316
        ]
 
317
        self.assertEqual(expected, self.mock.mock_calls)
 
318
 
 
319
    def test_install_unicast_to_tun(self):
 
320
        vlan = 3333
 
321
        port = 55
 
322
        mac = '08:60:6e:7f:74:e7'
 
323
        tun_id = 2222
 
324
        self.br.install_unicast_to_tun(vlan=vlan,
 
325
                                       tun_id=tun_id,
 
326
                                       port=port,
 
327
                                       mac=mac)
 
328
        (dp, ofp, ofpp) = self._get_dp()
 
329
        expected = [
 
330
            call._send_msg(ofpp.OFPFlowMod(dp,
 
331
                cookie=0,
 
332
                instructions=[
 
333
                    ofpp.OFPInstructionActions(ofp.OFPIT_APPLY_ACTIONS, [
 
334
                        ofpp.OFPActionPopVlan(),
 
335
                        ofpp.OFPActionSetField(tunnel_id=tun_id),
 
336
                        ofpp.OFPActionOutput(port, 0),
 
337
                    ]),
 
338
                ],
 
339
                match=ofpp.OFPMatch(
 
340
                    eth_dst=mac, vlan_vid=vlan | ofp.OFPVID_PRESENT),
 
341
                priority=2,
 
342
                table_id=20)),
 
343
        ]
 
344
        self.assertEqual(expected, self.mock.mock_calls)
 
345
 
 
346
    def test_delete_unicast_to_tun(self):
 
347
        vlan = 3333
 
348
        mac = '08:60:6e:7f:74:e7'
 
349
        self.br.delete_unicast_to_tun(vlan=vlan, mac=mac)
 
350
        (dp, ofp, ofpp) = self._get_dp()
 
351
        expected = [
 
352
            call.delete_flows(table_id=20,
 
353
                match=ofpp.OFPMatch(
 
354
                    eth_dst=mac, vlan_vid=vlan | ofp.OFPVID_PRESENT)),
 
355
        ]
 
356
        self.assertEqual(expected, self.mock.mock_calls)
 
357
 
 
358
    def test_delete_unicast_to_tun_without_mac(self):
 
359
        vlan = 3333
 
360
        mac = None
 
361
        self.br.delete_unicast_to_tun(vlan=vlan, mac=mac)
 
362
        (dp, ofp, ofpp) = self._get_dp()
 
363
        expected = [
 
364
            call.delete_flows(table_id=20,
 
365
                match=ofpp.OFPMatch(vlan_vid=vlan | ofp.OFPVID_PRESENT)),
 
366
        ]
 
367
        self.assertEqual(expected, self.mock.mock_calls)
 
368
 
 
369
    def test_install_arp_responder(self):
 
370
        vlan = 3333
 
371
        ip = '192.0.2.1'
 
372
        mac = '08:60:6e:7f:74:e7'
 
373
        self.br.install_arp_responder(vlan=vlan, ip=ip, mac=mac)
 
374
        (dp, ofp, ofpp) = self._get_dp()
 
375
        expected = [
 
376
            call._send_msg(ofpp.OFPFlowMod(dp,
 
377
                cookie=0,
 
378
                instructions=[
 
379
                    ofpp.OFPInstructionActions(ofp.OFPIT_APPLY_ACTIONS, [
 
380
                        ofpp.OFPActionSetField(arp_op=self.arp.ARP_REPLY),
 
381
                        ofpp.NXActionRegMove(
 
382
                            dst_field='arp_tha',
 
383
                            n_bits=48,
 
384
                            src_field='arp_sha'),
 
385
                        ofpp.NXActionRegMove(
 
386
                            dst_field='arp_tpa',
 
387
                            n_bits=32,
 
388
                            src_field='arp_spa'),
 
389
                        ofpp.OFPActionSetField(arp_sha=mac),
 
390
                        ofpp.OFPActionSetField(arp_spa=ip),
 
391
                        ofpp.OFPActionOutput(ofp.OFPP_IN_PORT, 0),
 
392
                    ]),
 
393
                ],
 
394
                match=ofpp.OFPMatch(
 
395
                    eth_type=self.ether_types.ETH_TYPE_ARP,
 
396
                    arp_tpa=ip,
 
397
                    vlan_vid=vlan | ofp.OFPVID_PRESENT),
 
398
                priority=1,
 
399
                table_id=21)),
 
400
        ]
 
401
        self.assertEqual(expected, self.mock.mock_calls)
 
402
 
 
403
    def test_delete_arp_responder(self):
 
404
        vlan = 3333
 
405
        ip = '192.0.2.1'
 
406
        self.br.delete_arp_responder(vlan=vlan, ip=ip)
 
407
        (dp, ofp, ofpp) = self._get_dp()
 
408
        expected = [
 
409
            call.delete_flows(
 
410
                match=ofpp.OFPMatch(
 
411
                    eth_type=self.ether_types.ETH_TYPE_ARP,
 
412
                    arp_tpa=ip,
 
413
                    vlan_vid=vlan | ofp.OFPVID_PRESENT),
 
414
                table_id=21),
 
415
        ]
 
416
        self.assertEqual(expected, self.mock.mock_calls)
 
417
 
 
418
    def test_delete_arp_responder_without_ip(self):
 
419
        vlan = 3333
 
420
        ip = None
 
421
        self.br.delete_arp_responder(vlan=vlan, ip=ip)
 
422
        (dp, ofp, ofpp) = self._get_dp()
 
423
        expected = [
 
424
            call.delete_flows(
 
425
                match=ofpp.OFPMatch(
 
426
                    eth_type=self.ether_types.ETH_TYPE_ARP,
 
427
                    vlan_vid=vlan | ofp.OFPVID_PRESENT),
 
428
                table_id=21),
 
429
        ]
 
430
        self.assertEqual(expected, self.mock.mock_calls)
 
431
 
 
432
    def test_setup_tunnel_port(self):
 
433
        network_type = 'vxlan'
 
434
        port = 11111
 
435
        self.br.setup_tunnel_port(network_type=network_type, port=port)
 
436
        (dp, ofp, ofpp) = self._get_dp()
 
437
        expected = [
 
438
            call._send_msg(ofpp.OFPFlowMod(dp,
 
439
                cookie=0,
 
440
                instructions=[
 
441
                    ofpp.OFPInstructionGotoTable(table_id=4),
 
442
                ],
 
443
                match=ofpp.OFPMatch(in_port=port),
 
444
                priority=1,
 
445
                table_id=0)),
 
446
        ]
 
447
        self.assertEqual(expected, self.mock.mock_calls)
 
448
 
 
449
    def test_cleanup_tunnel_port(self):
 
450
        port = 11111
 
451
        self.br.cleanup_tunnel_port(port=port)
 
452
        (dp, ofp, ofpp) = self._get_dp()
 
453
        expected = [
 
454
            call.delete_flows(in_port=port),
 
455
        ]
 
456
        self.assertEqual(expected, self.mock.mock_calls)
 
457
 
 
458
    def test_add_dvr_mac_tun(self):
 
459
        mac = '00:02:b3:13:fe:3d'
 
460
        port = 8888
 
461
        self.br.add_dvr_mac_tun(mac=mac, port=port)
 
462
        (dp, ofp, ofpp) = self._get_dp()
 
463
        expected = [
 
464
            call._send_msg(ofpp.OFPFlowMod(dp,
 
465
                cookie=0,
 
466
                instructions=[
 
467
                    ofpp.OFPInstructionActions(ofp.OFPIT_APPLY_ACTIONS, [
 
468
                        ofpp.OFPActionOutput(port, 0),
 
469
                    ]),
 
470
                ],
 
471
                match=ofpp.OFPMatch(eth_src=mac),
 
472
                priority=1,
 
473
                table_id=9)),
 
474
        ]
 
475
        self.assertEqual(expected, self.mock.mock_calls)
 
476
 
 
477
    def test_remove_dvr_mac_tun(self):
 
478
        mac = '00:02:b3:13:fe:3d'
 
479
        self.br.remove_dvr_mac_tun(mac=mac)
 
480
        (dp, ofp, ofpp) = self._get_dp()
 
481
        expected = [
 
482
            call.delete_flows(eth_src=mac, table_id=9),
 
483
        ]
 
484
        self.assertEqual(expected, self.mock.mock_calls)