1 # Copyright (C) 2014,2015 VA Linux Systems Japan K.K.
2 # Copyright (C) 2014,2015 YAMAMOTO Takashi <yamamoto at valinux co jp>
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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
19 import neutron.plugins.ml2.drivers.openvswitch.agent.common.constants \
21 from neutron.tests.unit.plugins.ml2.drivers.openvswitch.agent.openflow.native \
22 import ovs_bridge_test_base
25 call = mock.call # short hand
28 class OVSPhysicalBridgeTest(ovs_bridge_test_base.OVSBridgeTestBase,
29 ovs_bridge_test_base.OVSDVRProcessTestMixin):
30 dvr_process_table_id = ovs_const.DVR_PROCESS_VLAN
31 dvr_process_next_table_id = ovs_const.LOCAL_VLAN_TRANSLATION
34 super(OVSPhysicalBridgeTest, self).setUp()
35 self.setup_bridge_mock('br-phys', self.br_phys_cls)
37 def test_setup_default_table(self):
38 self.br.setup_default_table()
39 (dp, ofp, ofpp) = self._get_dp()
42 call._send_msg(ofpp.OFPFlowMod(dp,
45 ofpp.OFPInstructionActions(ofp.OFPIT_APPLY_ACTIONS, [
46 ofpp.OFPActionOutput(ofp.OFPP_NORMAL, 0),
49 match=ofpp.OFPMatch(),
53 self.assertEqual(expected, self.mock.mock_calls)
55 def test_provision_local_vlan(self):
60 self.br.provision_local_vlan(port=port, lvid=lvid,
61 segmentation_id=segmentation_id,
62 distributed=distributed)
63 (dp, ofp, ofpp) = self._get_dp()
65 call._send_msg(ofpp.OFPFlowMod(dp,
68 ofpp.OFPInstructionActions(ofp.OFPIT_APPLY_ACTIONS, [
69 ofpp.OFPActionSetField(
70 vlan_vid=segmentation_id | ofp.OFPVID_PRESENT),
71 ofpp.OFPActionOutput(ofp.OFPP_NORMAL, 0),
76 vlan_vid=lvid | ofp.OFPVID_PRESENT),
80 self.assertEqual(expected, self.mock.mock_calls)
82 def test_provision_local_vlan_novlan(self):
85 segmentation_id = None
87 self.br.provision_local_vlan(port=port, lvid=lvid,
88 segmentation_id=segmentation_id,
89 distributed=distributed)
90 (dp, ofp, ofpp) = self._get_dp()
92 call._send_msg(ofpp.OFPFlowMod(dp,
95 ofpp.OFPInstructionActions(ofp.OFPIT_APPLY_ACTIONS, [
96 ofpp.OFPActionPopVlan(),
97 ofpp.OFPActionOutput(ofp.OFPP_NORMAL, 0),
102 vlan_vid=lvid | ofp.OFPVID_PRESENT),
106 self.assertEqual(expected, self.mock.mock_calls)
108 def test_reclaim_local_vlan(self):
111 self.br.reclaim_local_vlan(port=port, lvid=lvid)
112 (dp, ofp, ofpp) = self._get_dp()
117 vlan_vid=lvid | ofp.OFPVID_PRESENT)),
119 self.assertEqual(expected, self.mock.mock_calls)
121 def test_add_dvr_mac_vlan(self):
122 mac = '00:02:b3:13:fe:3d'
124 self.br.add_dvr_mac_vlan(mac=mac, port=port)
125 (dp, ofp, ofpp) = self._get_dp()
127 call._send_msg(ofpp.OFPFlowMod(dp,
130 ofpp.OFPInstructionActions(ofp.OFPIT_APPLY_ACTIONS, [
131 ofpp.OFPActionOutput(port, 0),
134 match=ofpp.OFPMatch(eth_src=mac),
138 self.assertEqual(expected, self.mock.mock_calls)
140 def test_remove_dvr_mac_vlan(self):
141 mac = '00:02:b3:13:fe:3d'
142 self.br.remove_dvr_mac_vlan(mac=mac)
143 (dp, ofp, ofpp) = self._get_dp()
145 call.delete_flows(eth_src=mac, table_id=3),
147 self.assertEqual(expected, self.mock.mock_calls)