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 data types and models required specifically
18 for Ipv6 Flow Specification support.
23 from ryu.lib.packet.bgp import FlowSpecIPv6NLRI
24 from ryu.lib.packet.bgp import RF_IPv6_FLOWSPEC
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
31 LOG = logging.getLogger('bgpspeaker.info_base.ipv6fs')
34 class IPv6FlowSpecDest(Destination, NonVrfPathProcessingMixin):
35 """IPv6 Flow Specification Destination
37 Store Flow Specification Paths.
39 ROUTE_FAMILY = RF_IPv6_FLOWSPEC
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)
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)
51 class IPv6FlowSpecTable(Table):
52 """Global table to store IPv6 Flow Specification routing information.
54 Uses `FlowSpecIpv6Dest` to store destination information for each known
55 Flow Specification paths.
57 ROUTE_FAMILY = RF_IPv6_FLOWSPEC
58 VPN_DEST_CLASS = IPv6FlowSpecDest
60 def __init__(self, core_service, signal_bus):
61 super(IPv6FlowSpecTable, self).__init__(None, core_service, signal_bus)
63 def _table_key(self, nlri):
64 """Return a key that will uniquely identify this NLRI inside
69 def _create_dest(self, nlri):
70 return self.VPN_DEST_CLASS(self, nlri)
73 return '%s(scope_id: %s, rf: %s)' % (
74 self.__class__.__name__, self.scope_id, self.route_family
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
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 (
90 self.VRF_PATH_CLASS = Vrf6FlowSpecPath
91 # Because the IPv6 Flow Specification does not require nexthop,
92 # initialize with None.