backing up
[vsorcdistro/.git] / ryu / build / lib.linux-armv7l-2.7 / ryu / ofproto / ofproto_protocol.py
1 # Copyright (C) 2014 Nippon Telegraph and Telephone Corporation.
2 # Copyright (C) 2014 YAMAMOTO Takashi <yamamoto at valinux co jp>
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #    http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 # implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 from ryu.ofproto import ofproto_v1_0
18 from ryu.ofproto import ofproto_v1_0_parser
19 from ryu.ofproto import ofproto_v1_2
20 from ryu.ofproto import ofproto_v1_2_parser
21 from ryu.ofproto import ofproto_v1_3
22 from ryu.ofproto import ofproto_v1_3_parser
23 from ryu.ofproto import ofproto_v1_4
24 from ryu.ofproto import ofproto_v1_4_parser
25 from ryu.ofproto import ofproto_v1_5
26 from ryu.ofproto import ofproto_v1_5_parser
27
28
29 _versions = {
30     ofproto_v1_0.OFP_VERSION: (ofproto_v1_0, ofproto_v1_0_parser),
31     ofproto_v1_2.OFP_VERSION: (ofproto_v1_2, ofproto_v1_2_parser),
32     ofproto_v1_3.OFP_VERSION: (ofproto_v1_3, ofproto_v1_3_parser),
33     ofproto_v1_4.OFP_VERSION: (ofproto_v1_4, ofproto_v1_4_parser),
34     ofproto_v1_5.OFP_VERSION: (ofproto_v1_5, ofproto_v1_5_parser),
35 }
36
37
38 # OF versions supported by every apps in this process (intersection)
39 _supported_versions = set(_versions.keys())
40
41
42 def set_app_supported_versions(vers):
43     global _supported_versions
44
45     _supported_versions &= set(vers)
46     assert _supported_versions, 'No OpenFlow version is available'
47
48
49 class ProtocolDesc(object):
50     """
51     OpenFlow protocol version flavor descriptor
52     """
53
54     def __init__(self, version=None):
55         if version is None:
56             version = max(_supported_versions)
57         self.set_version(version)
58
59     def set_version(self, version):
60         assert version in _supported_versions
61         (self.ofproto, self.ofproto_parser) = _versions[version]
62
63     @property
64     def supported_ofp_version(self):
65         return _supported_versions