0409717470c4ac76c87b6b4942fe179d9fe4a615
[openstack-build/neutron-build.git] / neutron / plugins / ml2 / drivers / openvswitch / agent / openflow / native / ovs_ryuapp.py
1 # Copyright (C) 2015 VA Linux Systems Japan K.K.
2 # Copyright (C) 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 functools
18
19 import ryu.app.ofctl.api  # noqa
20 from ryu.base import app_manager
21 from ryu.lib import hub
22 from ryu.ofproto import ofproto_v1_3
23
24 from neutron.plugins.ml2.drivers.openvswitch.agent.openflow.native \
25     import br_int
26 from neutron.plugins.ml2.drivers.openvswitch.agent.openflow.native \
27     import br_phys
28 from neutron.plugins.ml2.drivers.openvswitch.agent.openflow.native \
29     import br_tun
30 from neutron.plugins.ml2.drivers.openvswitch.agent \
31     import ovs_neutron_agent as ovs_agent
32
33
34 class OVSNeutronAgentRyuApp(app_manager.RyuApp):
35     OFP_VERSIONS = [ofproto_v1_3.OFP_VERSION]
36
37     def start(self):
38         # Start Ryu event loop thread
39         super(OVSNeutronAgentRyuApp, self).start()
40
41         def _make_br_cls(br_cls):
42             return functools.partial(br_cls, ryu_app=self)
43
44         # Start agent main loop thread
45         bridge_classes = {
46             'br_int': _make_br_cls(br_int.OVSIntegrationBridge),
47             'br_phys': _make_br_cls(br_phys.OVSPhysicalBridge),
48             'br_tun': _make_br_cls(br_tun.OVSTunnelBridge),
49         }
50         return hub.spawn(ovs_agent.main, bridge_classes)