Files
os-ken/ryu/services/protocols/bgp/info_base/ipv4.py
ISHIDA Wataru 3fa25edeae bgp: fix bugs related to filter
previous implementation apply all filters to all paths regardless of
its route family. this implementation cause error like one shown below.

ryu.lib.hub l.60   |    ERROR | hub: uncaught exception:
Traceback (most recent call last):
  File "/home/wataru/ryu/ryu/lib/hub.py", line 52, in _launch
    func(*args, **kwargs)
  File "/home/wataru/ryu/ryu/services/protocols/bgp/peer.py", line 650,
in _process_outgoing_msg_list
    self._send_outgoing_route(outgoing_msg)
  File "/home/wataru/ryu/ryu/services/protocols/bgp/peer.py", line 599,
in _send_outgoing_route
    block, blocked_cause = self._apply_out_filter(path)
  File "/home/wataru/ryu/ryu/services/protocols/bgp/peer.py", line 505,
in _apply_out_filter
    return self._apply_filter(self._out_filters, path)
  File "/home/wataru/ryu/ryu/services/protocols/bgp/peer.py", line 490,
in _apply_filter
    policy, is_matched = filter_.evaluate(path)
  File "/home/wataru/ryu/ryu/services/protocols/bgp/info_base/base.py",
line 953, in evaluate
    net = netaddr.IPNetwork(prefix.formatted_nlri_str)
  File "/usr/local/lib/python2.7/dist-packages/netaddr/ip/__init__.py",
line 941, in __init__
    raise AddrFormatError('invalid IPNetwork %s' % addr)
AddrFormatError: invalid IPNetwork 100💯20.0.0.0/24

To fix this bug, this patch introduce the Ipv4PrefixFilter and Ipv6PrefixFilter
class which is only applied to the ipv4 path and ipv6 path.

other condition bug related to applying filter is also fixed.

Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
2014-07-30 14:01:39 +09:00

92 lines
2.9 KiB
Python

# Copyright (C) 2014 Nippon Telegraph and Telephone Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Defines data types and models required specifically for IPv4 support.
"""
import logging
from ryu.lib.packet.bgp import IPAddrPrefix
from ryu.lib.packet.bgp import RF_IPv4_UC
from ryu.services.protocols.bgp.info_base.base import Path
from ryu.services.protocols.bgp.info_base.base import Table
from ryu.services.protocols.bgp.info_base.base import Destination
from ryu.services.protocols.bgp.info_base.base import NonVrfPathProcessingMixin
from ryu.services.protocols.bgp.info_base.base import PrefixFilter
LOG = logging.getLogger('bgpspeaker.info_base.ipv4')
class IPv4Dest(Destination, NonVrfPathProcessingMixin):
"""VPNv4 Destination
Store IPv4 Paths.
"""
ROUTE_FAMILY = RF_IPv4_UC
def _best_path_lost(self):
old_best_path = self._best_path
NonVrfPathProcessingMixin._best_path_lost(self)
self._core_service._signal_bus.best_path_changed(old_best_path, True)
def _new_best_path(self, best_path):
NonVrfPathProcessingMixin._new_best_path(self, best_path)
self._core_service._signal_bus.best_path_changed(best_path, False)
class Ipv4Table(Table):
"""Global table to store IPv4 routing information.
Uses `IPv4Dest` to store destination information for each known vpnv4
paths.
"""
ROUTE_FAMILY = RF_IPv4_UC
VPN_DEST_CLASS = IPv4Dest
def __init__(self, core_service, signal_bus):
super(Ipv4Table, self).__init__(None, core_service, signal_bus)
def _table_key(self, nlri):
"""Return a key that will uniquely identify this NLRI inside
this table.
"""
return nlri.prefix
def _create_dest(self, nlri):
return self.VPN_DEST_CLASS(self, nlri)
def __str__(self):
return '%s(scope_id: %s, rf: %s)' % (
self.__class__.__name__, self.scope_id, self.route_family
)
class Ipv4Path(Path):
"""Represents a way of reaching an VPNv4 destination."""
ROUTE_FAMILY = RF_IPv4_UC
VRF_PATH_CLASS = None # defined in init - anti cyclic import hack
NLRI_CLASS = IPAddrPrefix
def __init__(self, *args, **kwargs):
super(Ipv4Path, self).__init__(*args, **kwargs)
from ryu.services.protocols.bgp.info_base.vrf4 import Vrf4Path
self.VRF_PATH_CLASS = Vrf4Path
class Ipv4PrefixFilter(PrefixFilter):
"""IPv4 Prefix Filter class"""
ROUTE_FAMILY = RF_IPv4_UC