1 # Copyright (C) 2014 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.
16 Defines data types and models required specifically for IPv4 support.
21 from ryu.lib.packet.bgp import IPAddrPrefix
22 from ryu.lib.packet.bgp import RF_IPv4_UC
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
30 LOG = logging.getLogger('bgpspeaker.info_base.ipv4')
33 class IPv4Dest(Destination, NonVrfPathProcessingMixin):
38 ROUTE_FAMILY = RF_IPv4_UC
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)
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)
50 class Ipv4Table(Table):
51 """Global table to store IPv4 routing information.
53 Uses `IPv4Dest` to store destination information for each known vpnv4
56 ROUTE_FAMILY = RF_IPv4_UC
57 VPN_DEST_CLASS = IPv4Dest
59 def __init__(self, core_service, signal_bus):
60 super(Ipv4Table, self).__init__(None, core_service, signal_bus)
62 def _table_key(self, nlri):
63 """Return a key that will uniquely identify this NLRI inside
68 def _create_dest(self, nlri):
69 return self.VPN_DEST_CLASS(self, nlri)
72 return '%s(scope_id: %s, rf: %s)' % (
73 self.__class__.__name__, self.scope_id, self.route_family
78 """Represents a way of reaching an VPNv4 destination."""
79 ROUTE_FAMILY = RF_IPv4_UC
80 VRF_PATH_CLASS = None # defined in init - anti cyclic import hack
81 NLRI_CLASS = IPAddrPrefix
83 def __init__(self, *args, **kwargs):
84 super(Ipv4Path, self).__init__(*args, **kwargs)
85 from ryu.services.protocols.bgp.info_base.vrf4 import Vrf4Path
86 self.VRF_PATH_CLASS = Vrf4Path
89 class Ipv4PrefixFilter(PrefixFilter):
90 """IPv4 Prefix Filter class"""
91 ROUTE_FAMILY = RF_IPv4_UC