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.
17 Import-map configuration.
21 from ryu.services.protocols.bgp.api.base import register
22 from ryu.services.protocols.bgp.core_manager import CORE_MANAGER
23 from ryu.services.protocols.bgp.core_managers.import_map_manager\
24 import ImportMapAlreadyExistsError
25 from ryu.services.protocols.bgp.rtconf.base import RuntimeConfigError
27 LOG = logging.getLogger('bgpspeaker.api.import_map')
30 @register(name='importmap.create')
31 def create_importmap(type, action, name, value, route_family=None):
33 raise RuntimeConfigError(
34 'Unknown action. For now we only support "drop" action.'
37 if type not in ('prefix_match', 'rt_match'):
38 raise RuntimeConfigError(
39 'Unknown type. We support only "prefix_match" and "rt_match".'
42 if type == 'prefix_match':
43 return _create_prefix_match_importmap(name, value, route_family)
44 elif type == 'rt_match':
45 return _create_rt_match_importmap(name, value)
48 def _create_prefix_match_importmap(name, value, route_family):
49 core_service = CORE_MANAGER.get_core_service()
50 importmap_manager = core_service.importmap_manager
52 if route_family == 'ipv4':
53 importmap_manager.create_vpnv4_nlri_import_map(name, value)
54 elif route_family == 'ipv6':
55 importmap_manager.create_vpnv6_nlri_import_map(name, value)
57 raise RuntimeConfigError(
58 'Unknown address family %s. it should be ipv4 or ipv6'
61 except ImportMapAlreadyExistsError:
62 raise RuntimeConfigError(
63 'Map with this name already exists'
69 def _create_rt_match_importmap(name, value):
70 core_service = CORE_MANAGER.get_core_service()
71 importmap_manager = core_service.importmap_manager
73 importmap_manager.create_rt_import_map(name, value)
74 except ImportMapAlreadyExistsError:
75 raise RuntimeConfigError(
76 'Map with this name already exists'