1 # Copyright (C) 2014 Nippon Telegraph and Telephone Corporation.
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
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
21 class ImportMapManager(object):
24 self._import_maps_by_name = {}
26 def create_vpnv4_nlri_import_map(self, name, value):
27 self._create_import_map_factory(name, value, Vrf4NlriImportMap)
29 def create_vpnv6_nlri_import_map(self, name, value):
30 self._create_import_map_factory(name, value, Vrf6NlriImportMap)
32 def create_rt_import_map(self, name, value):
33 self._create_import_map_factory(name, value, VrfRtImportMap)
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)
40 def get_import_map_by_name(self, name):
41 return self._import_maps_by_name.get(name)
44 class ImportMapAlreadyExistsError(Exception):