backing up
[vsorcdistro/.git] / ryu / build / lib.linux-armv7l-2.7 / ryu / services / protocols / bgp / info_base / ipv6.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  Defines data types and models required specifically for IPv4 support.
17 """
18
19 import logging
20
21 from ryu.lib.packet.bgp import IPAddrPrefix
22 from ryu.lib.packet.bgp import RF_IPv6_UC
23
24 from ryu.services.protocols.bgp.info_base.base import Path
25 from ryu.services.protocols.bgp.info_base.base import Table
26 from ryu.services.protocols.bgp.info_base.base import Destination
27 from ryu.services.protocols.bgp.info_base.base import NonVrfPathProcessingMixin
28 from ryu.services.protocols.bgp.info_base.base import PrefixFilter
29
30 LOG = logging.getLogger('bgpspeaker.info_base.ipv6')
31
32
33 class IPv6Dest(Destination, NonVrfPathProcessingMixin):
34     """v6 Destination
35
36     Store IPv6 Paths.
37     """
38     ROUTE_FAMILY = RF_IPv6_UC
39
40     def _best_path_lost(self):
41         old_best_path = self._best_path
42         NonVrfPathProcessingMixin._best_path_lost(self)
43         self._core_service._signal_bus.best_path_changed(old_best_path, True)
44
45     def _new_best_path(self, best_path):
46         NonVrfPathProcessingMixin._new_best_path(self, best_path)
47         self._core_service._signal_bus.best_path_changed(best_path, False)
48
49
50 class Ipv6Table(Table):
51     """Global table to store IPv4 routing information.
52
53     Uses `IPv6Dest` to store destination information for each known vpnv6
54     paths.
55     """
56     ROUTE_FAMILY = RF_IPv6_UC
57     VPN_DEST_CLASS = IPv6Dest
58
59     def __init__(self, core_service, signal_bus):
60         super(Ipv6Table, self).__init__(None, core_service, signal_bus)
61
62     def _table_key(self, nlri):
63         """Return a key that will uniquely identify this NLRI inside
64         this table.
65         """
66         return nlri.prefix
67
68     def _create_dest(self, nlri):
69         return self.VPN_DEST_CLASS(self, nlri)
70
71     def __str__(self):
72         return '%s(scope_id: %s, rf: %s)' % (
73             self.__class__.__name__, self.scope_id, self.route_family
74         )
75
76
77 class Ipv6Path(Path):
78     """Represents a way of reaching an v6 destination."""
79     ROUTE_FAMILY = RF_IPv6_UC
80     VRF_PATH_CLASS = None  # defined in init - anti cyclic import hack
81     NLRI_CLASS = IPAddrPrefix
82
83     def __init__(self, *args, **kwargs):
84         super(Ipv6Path, self).__init__(*args, **kwargs)
85         from ryu.services.protocols.bgp.info_base.vrf6 import Vrf6Path
86         self.VRF_PATH_CLASS = Vrf6Path
87
88
89 class Ipv6PrefixFilter(PrefixFilter):
90     """IPv6 Prefix Filter class"""
91     ROUTE_FAMILY = RF_IPv6_UC