backing up
[vsorcdistro/.git] / ryu / build / lib.linux-armv7l-2.7 / ryu / services / protocols / bgp / info_base / vrffs.py
1 # Copyright (C) 2017 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 """
17  Defines base data types and models required specifically
18  for VRF Flow Specification support.
19 """
20
21 import abc
22 import logging
23 import six
24
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
31
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
36
37 from ryu.services.protocols.bgp.utils.bgp import create_rt_extended_community
38
39 LOG = logging.getLogger('bgpspeaker.info_base.vrffs')
40
41
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
46     in represents.
47     """
48
49     def insert_vrffs_path(self, nlri, communities, is_withdraw=False):
50         assert nlri
51         assert isinstance(communities, list)
52         vrf_conf = self.vrf_conf
53
54         from ryu.services.protocols.bgp.core import EXPECTED_ORIGIN
55         pattrs = OrderedDict()
56         pattrs[BGP_ATTR_TYPE_ORIGIN] = BGPPathAttributeOrigin(
57             EXPECTED_ORIGIN)
58         pattrs[BGP_ATTR_TYPE_AS_PATH] = BGPPathAttributeAsPath([])
59
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))
64
65         pattrs[BGP_ATTR_TYPE_EXTENDED_COMMUNITIES] = (
66             BGPPathAttributeExtendedCommunities(communities=communities))
67
68         puid = self.VRF_PATH_CLASS.create_puid(
69             vrf_conf.route_dist, nlri.prefix)
70
71         path = self.VRF_PATH_CLASS(
72             puid, None, nlri, 0,
73             pattrs=pattrs, is_withdraw=is_withdraw
74         )
75
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)
81
82
83 @six.add_metaclass(abc.ABCMeta)
84 class VRFFlowSpecDest(VrfDest):
85     """Base class for VRF Flow Specification."""
86
87
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.
92     """