1 # Copyright (C) 2017 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 Defines base data types and models required specifically
18 for VRF Flow Specification support.
25 from ryu.lib.packet.bgp import BGP_ATTR_TYPE_ORIGIN
26 from ryu.lib.packet.bgp import BGP_ATTR_TYPE_AS_PATH
27 from ryu.lib.packet.bgp import BGP_ATTR_TYPE_EXTENDED_COMMUNITIES
28 from ryu.lib.packet.bgp import BGPPathAttributeOrigin
29 from ryu.lib.packet.bgp import BGPPathAttributeAsPath
30 from ryu.lib.packet.bgp import BGPPathAttributeExtendedCommunities
32 from ryu.services.protocols.bgp.base import OrderedDict
33 from ryu.services.protocols.bgp.info_base.vrf import VrfTable
34 from ryu.services.protocols.bgp.info_base.vrf import VrfDest
35 from ryu.services.protocols.bgp.info_base.vrf import VrfPath
37 from ryu.services.protocols.bgp.utils.bgp import create_rt_extended_community
39 LOG = logging.getLogger('bgpspeaker.info_base.vrffs')
42 @six.add_metaclass(abc.ABCMeta)
43 class VRFFlowSpecTable(VrfTable):
44 """Virtual Routing and Forwarding information base.
45 Keeps destination imported to given VRF Flow Specification
49 def insert_vrffs_path(self, nlri, communities, is_withdraw=False):
51 assert isinstance(communities, list)
52 vrf_conf = self.vrf_conf
54 from ryu.services.protocols.bgp.core import EXPECTED_ORIGIN
55 pattrs = OrderedDict()
56 pattrs[BGP_ATTR_TYPE_ORIGIN] = BGPPathAttributeOrigin(
58 pattrs[BGP_ATTR_TYPE_AS_PATH] = BGPPathAttributeAsPath([])
60 for rt in vrf_conf.export_rts:
61 communities.append(create_rt_extended_community(rt, 2))
62 for soo in vrf_conf.soo_list:
63 communities.append(create_rt_extended_community(soo, 3))
65 pattrs[BGP_ATTR_TYPE_EXTENDED_COMMUNITIES] = (
66 BGPPathAttributeExtendedCommunities(communities=communities))
68 puid = self.VRF_PATH_CLASS.create_puid(
69 vrf_conf.route_dist, nlri.prefix)
71 path = self.VRF_PATH_CLASS(
73 pattrs=pattrs, is_withdraw=is_withdraw
76 # Insert the path into VRF table, get affected destination so that we
77 # can process it further.
78 eff_dest = self.insert(path)
79 # Enqueue the eff_dest for further processing.
80 self._signal_bus.dest_changed(eff_dest)
83 @six.add_metaclass(abc.ABCMeta)
84 class VRFFlowSpecDest(VrfDest):
85 """Base class for VRF Flow Specification."""
88 @six.add_metaclass(abc.ABCMeta)
89 class VRFFlowSpecPath(VrfPath):
90 """Represents a way of reaching an IP destination with
91 a VPN Flow Specification.