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