backing up
[vsorcdistro/.git] / ryu / build / lib.linux-armv7l-2.7 / ryu / services / protocols / bgp / core_managers / import_map_manager.py
1 # Copyright (C) 2014 Nippon Telegraph and Telephone Corporation.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #    http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 # implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 from ryu.services.protocols.bgp.info_base.vrf import VrfRtImportMap
17 from ryu.services.protocols.bgp.info_base.vrf4 import Vrf4NlriImportMap
18 from ryu.services.protocols.bgp.info_base.vrf6 import Vrf6NlriImportMap
19
20
21 class ImportMapManager(object):
22
23     def __init__(self):
24         self._import_maps_by_name = {}
25
26     def create_vpnv4_nlri_import_map(self, name, value):
27         self._create_import_map_factory(name, value, Vrf4NlriImportMap)
28
29     def create_vpnv6_nlri_import_map(self, name, value):
30         self._create_import_map_factory(name, value, Vrf6NlriImportMap)
31
32     def create_rt_import_map(self, name, value):
33         self._create_import_map_factory(name, value, VrfRtImportMap)
34
35     def _create_import_map_factory(self, name, value, cls):
36         if self._import_maps_by_name.get(name) is not None:
37             raise ImportMapAlreadyExistsError()
38         self._import_maps_by_name[name] = cls(value)
39
40     def get_import_map_by_name(self, name):
41         return self._import_maps_by_name.get(name)
42
43
44 class ImportMapAlreadyExistsError(Exception):
45     pass