protocols/bgp: PEP-8 and Python3 fixes
Signed-off-by: Jason Kölker <jason@koelker.net> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
parent
7d42aecb8d
commit
db02d0f487
@ -14,10 +14,9 @@
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
import json
|
||||
from ryu.base import app_manager
|
||||
from ryu.lib import hub
|
||||
from ryu.app.wsgi import route, websocket, ControllerBase, WSGIApplication
|
||||
from ryu.app.wsgi import websocket, ControllerBase, WSGIApplication
|
||||
from ryu.app.wsgi import rpc_public, WebSocketRPCServer
|
||||
from ryu.services.protocols.bgp.api.base import call
|
||||
from ryu.services.protocols.bgp.api.base import PREFIX
|
||||
|
@ -18,7 +18,6 @@
|
||||
import imp
|
||||
import logging
|
||||
import traceback
|
||||
from os import path
|
||||
from oslo_config import cfg
|
||||
|
||||
from ryu.lib import hub
|
||||
|
@ -34,8 +34,6 @@ from ryu.services.protocols.bgp.rtconf.common \
|
||||
import DEFAULT_REFRESH_MAX_EOR_TIME
|
||||
from ryu.services.protocols.bgp.rtconf.common \
|
||||
import DEFAULT_REFRESH_STALEPATH_TIME
|
||||
from ryu.services.protocols.bgp.rtconf.common \
|
||||
import DEFAULT_BGP_CONN_RETRY_TIME
|
||||
from ryu.services.protocols.bgp.rtconf.common import DEFAULT_LABEL_RANGE
|
||||
from ryu.services.protocols.bgp.rtconf.common import REFRESH_MAX_EOR_TIME
|
||||
from ryu.services.protocols.bgp.rtconf.common import REFRESH_STALEPATH_TIME
|
||||
@ -57,8 +55,6 @@ from ryu.services.protocols.bgp.rtconf.neighbors \
|
||||
from ryu.services.protocols.bgp.rtconf.neighbors import DEFAULT_CONNECT_MODE
|
||||
from ryu.services.protocols.bgp.rtconf.neighbors import PEER_NEXT_HOP
|
||||
from ryu.services.protocols.bgp.rtconf.neighbors import PASSWORD
|
||||
from ryu.services.protocols.bgp.rtconf.neighbors import IN_FILTER
|
||||
from ryu.services.protocols.bgp.rtconf.neighbors import OUT_FILTER
|
||||
from ryu.services.protocols.bgp.rtconf.neighbors import IS_ROUTE_SERVER_CLIENT
|
||||
from ryu.services.protocols.bgp.rtconf.neighbors import IS_NEXT_HOP_SELF
|
||||
from ryu.services.protocols.bgp.rtconf.neighbors import CONNECT_MODE
|
||||
|
@ -17,15 +17,12 @@ from ryu.services.protocols.bgp.base import Activity
|
||||
from ryu.lib import hub
|
||||
from ryu.lib.packet import bmp
|
||||
from ryu.lib.packet import bgp
|
||||
from ryu.services.protocols.bgp import constants as const
|
||||
import socket
|
||||
import logging
|
||||
from calendar import timegm
|
||||
from ryu.services.protocols.bgp.signals.emit import BgpSignalBus
|
||||
from ryu.services.protocols.bgp.info_base.ipv4 import Ipv4Path
|
||||
from ryu.lib.packet.bgp import BGPUpdate
|
||||
from ryu.lib.packet.bgp import BGPPathAttributeNextHop
|
||||
from ryu.lib.packet.bgp import BGPPathAttributeMpReachNLRI
|
||||
from ryu.lib.packet.bgp import BGPPathAttributeMpUnreachNLRI
|
||||
|
||||
LOG = logging.getLogger('bgpspeaker.bmp')
|
||||
@ -82,9 +79,7 @@ class BMPClient(Activity):
|
||||
if not self._socket:
|
||||
return
|
||||
assert isinstance(msg, bmp.BMPMessage)
|
||||
serialized_msg = msg.serialize()
|
||||
|
||||
ret = self._socket.send(msg.serialize())
|
||||
self._socket.send(msg.serialize())
|
||||
|
||||
def on_adj_rib_in_changed(self, data):
|
||||
peer = data['peer']
|
||||
|
@ -7,10 +7,6 @@ from ryu.services.protocols.bgp.peer import Peer
|
||||
from ryu.lib.packet.bgp import BGPPathAttributeCommunities
|
||||
from ryu.lib.packet.bgp import BGP_ATTR_TYPE_MULTI_EXIT_DISC
|
||||
from ryu.lib.packet.bgp import BGP_ATTR_TYPE_COMMUNITIES
|
||||
from ryu.lib.packet.bgp import RF_IPv4_UC
|
||||
from ryu.lib.packet.bgp import RF_IPv6_UC
|
||||
from ryu.lib.packet.bgp import RF_IPv4_VPN
|
||||
from ryu.lib.packet.bgp import RF_IPv6_VPN
|
||||
from ryu.lib.packet.bgp import RF_RTC_UC
|
||||
from ryu.lib.packet.bgp import RouteTargetMembershipNLRI
|
||||
from ryu.services.protocols.bgp.utils.bgp \
|
||||
|
@ -445,8 +445,8 @@ class TableCoreManager(object):
|
||||
# of the given path and import this path into them.
|
||||
route_dist = vpn_path.nlri.route_dist
|
||||
for vrf_table in interested_tables:
|
||||
if not (vpn_path.source is None
|
||||
and route_dist == vrf_table.vrf_conf.route_dist):
|
||||
if (vpn_path.source is not None and
|
||||
route_dist != vrf_table.vrf_conf.route_dist):
|
||||
update_vrf_dest = vrf_table.import_vpn_path(vpn_path)
|
||||
# Queue the destination for further processing.
|
||||
if update_vrf_dest is not None:
|
||||
|
@ -23,6 +23,7 @@ from abc import ABCMeta
|
||||
from abc import abstractmethod
|
||||
from copy import copy
|
||||
import logging
|
||||
import functools
|
||||
import netaddr
|
||||
|
||||
from ryu.lib.packet.bgp import RF_IPv4_UC
|
||||
@ -249,8 +250,9 @@ class NonVrfPathProcessingMixin(object):
|
||||
LOG.debug('New best path selected for destination %s', self)
|
||||
|
||||
# If old best path was withdrawn
|
||||
if (old_best_path and old_best_path not in self._known_path_list
|
||||
and self._sent_routes):
|
||||
if (old_best_path and
|
||||
old_best_path not in self._known_path_list and
|
||||
self._sent_routes):
|
||||
# Have to clear sent_route list for this destination as
|
||||
# best path is removed.
|
||||
self._sent_routes = {}
|
||||
@ -810,7 +812,7 @@ class Path(object):
|
||||
return not interested_rts.isdisjoint(curr_rts)
|
||||
|
||||
def is_local(self):
|
||||
return self._source == None
|
||||
return self._source is None
|
||||
|
||||
def has_nexthop(self):
|
||||
return not (not self._nexthop or self._nexthop == '0.0.0.0' or
|
||||
@ -880,6 +882,7 @@ class Filter(object):
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
@functools.total_ordering
|
||||
class PrefixFilter(Filter):
|
||||
"""
|
||||
used to specify a prefix for filter.
|
||||
@ -934,8 +937,11 @@ class PrefixFilter(Filter):
|
||||
self._ge = ge
|
||||
self._le = le
|
||||
|
||||
def __cmp__(self, other):
|
||||
return cmp(self.prefix, other.prefix)
|
||||
def __lt__(self, other):
|
||||
return self._network < other._network
|
||||
|
||||
def __eq__(self, other):
|
||||
return self._network == other._network
|
||||
|
||||
def __repr__(self):
|
||||
policy = 'PERMIT' \
|
||||
@ -1009,6 +1015,7 @@ class PrefixFilter(Filter):
|
||||
le=self._le)
|
||||
|
||||
|
||||
@functools.total_ordering
|
||||
class ASPathFilter(Filter):
|
||||
"""
|
||||
used to specify a prefix for AS_PATH attribute.
|
||||
@ -1055,8 +1062,11 @@ class ASPathFilter(Filter):
|
||||
super(ASPathFilter, self).__init__(policy)
|
||||
self._as_number = as_number
|
||||
|
||||
def __cmp__(self, other):
|
||||
return cmp(self.as_number, other.as_number)
|
||||
def __lt__(self, other):
|
||||
return self.as_number < other.as_number
|
||||
|
||||
def __eq__(self, other):
|
||||
return self.as_number == other.as_number
|
||||
|
||||
def __repr__(self):
|
||||
policy = 'TOP'
|
||||
@ -1223,5 +1233,8 @@ class AttributeMap(object):
|
||||
if self.attr_type == self.ATTR_LOCAL_PREF else None
|
||||
|
||||
filter_string = ','.join(repr(f) for f in self.filters)
|
||||
return 'AttributeMap(filters=[%s],attribute_type=%s,attribute_value=%s)'\
|
||||
% (filter_string, attr_type, self.attr_value)
|
||||
return ('AttributeMap(filters=[%s],'
|
||||
'attribute_type=%s,'
|
||||
'attribute_value=%s)' % (filter_string,
|
||||
attr_type,
|
||||
self.attr_value))
|
||||
|
@ -104,8 +104,8 @@ class VrfTable(Table):
|
||||
local_route_count = 0
|
||||
for dest in self.values():
|
||||
for path in dest.known_path_list:
|
||||
if (hasattr(path.source, 'version_num')
|
||||
or path.source == VPN_TABLE):
|
||||
if (hasattr(path.source, 'version_num') or
|
||||
path.source == VPN_TABLE):
|
||||
remote_route_count += 1
|
||||
else:
|
||||
local_route_count += 1
|
||||
|
@ -22,14 +22,6 @@ import sys
|
||||
from copy import copy
|
||||
import os.path
|
||||
|
||||
CONF = {
|
||||
"ssh_port": 4990,
|
||||
"ssh_host": "localhost",
|
||||
"ssh_hostkey": None,
|
||||
"ssh_username": "ryu",
|
||||
"ssh_password": "ryu",
|
||||
}
|
||||
|
||||
from ryu.lib import hub
|
||||
from ryu import version
|
||||
from ryu.services.protocols.bgp.operator.command import Command
|
||||
@ -39,6 +31,14 @@ from ryu.services.protocols.bgp.operator.internal_api import InternalApi
|
||||
from ryu.services.protocols.bgp.operator.command import STATUS_OK
|
||||
from ryu.services.protocols.bgp.base import Activity
|
||||
|
||||
CONF = {
|
||||
"ssh_port": 4990,
|
||||
"ssh_host": "localhost",
|
||||
"ssh_hostkey": None,
|
||||
"ssh_username": "ryu",
|
||||
"ssh_password": "ryu",
|
||||
}
|
||||
|
||||
LOG = logging.getLogger('bgpspeaker.cli')
|
||||
|
||||
|
||||
@ -83,7 +83,7 @@ Hello, this is Ryu BGP speaker (version %s).
|
||||
|
||||
def _find_ssh_server_key(self):
|
||||
if CONF["ssh_hostkey"]:
|
||||
return paramiko.RSAKey.from_private_key_file(ssh_hostkey)
|
||||
return paramiko.RSAKey.from_private_key_file(CONF['ssh_hostkey'])
|
||||
elif os.path.exists("/etc/ssh_host_rsa_key"):
|
||||
# OSX
|
||||
return paramiko.RSAKey.from_private_key_file(
|
||||
|
@ -1,6 +1,8 @@
|
||||
import importlib
|
||||
import inspect
|
||||
|
||||
import six
|
||||
|
||||
|
||||
class Field(object):
|
||||
def __init__(self, field_name):
|
||||
@ -19,7 +21,7 @@ class RelatedViewField(Field):
|
||||
def _operator_view_class(self):
|
||||
if inspect.isclass(self.__operator_view_class):
|
||||
return self.__operator_view_class
|
||||
elif isinstance(self.__operator_view_class, basestring):
|
||||
elif isinstance(self.__operator_view_class, six.string_types):
|
||||
try:
|
||||
module_name, class_name =\
|
||||
self.__operator_view_class.rsplit('.', 1)
|
||||
|
@ -22,7 +22,6 @@ import time
|
||||
import traceback
|
||||
|
||||
from ryu.services.protocols.bgp.base import Activity
|
||||
from ryu.services.protocols.bgp.base import OrderedDict
|
||||
from ryu.services.protocols.bgp.base import Sink
|
||||
from ryu.services.protocols.bgp.base import Source
|
||||
from ryu.services.protocols.bgp.base import SUPPORTED_GLOBAL_RF
|
||||
@ -49,7 +48,6 @@ from ryu.lib.packet import bgp
|
||||
|
||||
from ryu.lib.packet.bgp import RouteFamily
|
||||
from ryu.lib.packet.bgp import RF_IPv4_UC
|
||||
from ryu.lib.packet.bgp import RF_IPv6_UC
|
||||
from ryu.lib.packet.bgp import RF_IPv4_VPN
|
||||
from ryu.lib.packet.bgp import RF_IPv6_VPN
|
||||
from ryu.lib.packet.bgp import RF_RTC_UC
|
||||
@ -698,7 +696,8 @@ class Peer(Source, Sink, NeighborConfListener, Activity):
|
||||
# Collect update statistics.
|
||||
self.state.incr(PeerCounterNames.SENT_UPDATES)
|
||||
else:
|
||||
LOG.debug('prefix : %s is not sent by filter : %s', path.nlri, blocked_cause)
|
||||
LOG.debug('prefix : %s is not sent by filter : %s',
|
||||
path.nlri, blocked_cause)
|
||||
|
||||
# We have to create sent_route for every OutgoingRoute which is
|
||||
# not a withdraw or was for route-refresh msg.
|
||||
@ -1035,7 +1034,7 @@ class Peer(Source, Sink, NeighborConfListener, Activity):
|
||||
if self._neigh_conf.enabled:
|
||||
self._connect_retry_event.set()
|
||||
|
||||
while 1:
|
||||
while True:
|
||||
self._connect_retry_event.wait()
|
||||
|
||||
# Reconnecting immediately after closing connection may be not very
|
||||
@ -1065,11 +1064,11 @@ class Peer(Source, Sink, NeighborConfListener, Activity):
|
||||
tcp_conn_timeout = self._common_conf.tcp_conn_timeout
|
||||
try:
|
||||
password = self._neigh_conf.password
|
||||
sock = self._connect_tcp(peer_address,
|
||||
client_factory,
|
||||
time_out=tcp_conn_timeout,
|
||||
bind_address=bind_addr,
|
||||
password=password)
|
||||
self._connect_tcp(peer_address,
|
||||
client_factory,
|
||||
time_out=tcp_conn_timeout,
|
||||
bind_address=bind_addr,
|
||||
password=password)
|
||||
except socket.error:
|
||||
self.state.bgp_state = const.BGP_FSM_ACTIVE
|
||||
if LOG.isEnabledFor(logging.DEBUG):
|
||||
@ -1405,7 +1404,8 @@ class Peer(Source, Sink, NeighborConfListener, Activity):
|
||||
tm = self._core_service.table_manager
|
||||
tm.learn_path(new_path)
|
||||
else:
|
||||
LOG.debug('prefix : %s is blocked by in-bound filter: %s', msg_nlri, blocked_cause)
|
||||
LOG.debug('prefix : %s is blocked by in-bound filter: %s',
|
||||
msg_nlri, blocked_cause)
|
||||
|
||||
# If update message had any qualifying new paths, do some book-keeping.
|
||||
if msg_nlri_list:
|
||||
@ -1467,7 +1467,8 @@ class Peer(Source, Sink, NeighborConfListener, Activity):
|
||||
tm = self._core_service.table_manager
|
||||
tm.learn_path(w_path)
|
||||
else:
|
||||
LOG.debug('prefix : %s is blocked by in-bound filter: %s', nlri_str, blocked_cause)
|
||||
LOG.debug('prefix : %s is blocked by in-bound filter: %s',
|
||||
nlri_str, blocked_cause)
|
||||
|
||||
def _extract_and_handle_mpbgp_new_paths(self, update_msg):
|
||||
"""Extracts new paths advertised in the given update message's
|
||||
@ -1562,7 +1563,8 @@ class Peer(Source, Sink, NeighborConfListener, Activity):
|
||||
tm = self._core_service.table_manager
|
||||
tm.learn_path(new_path)
|
||||
else:
|
||||
LOG.debug('prefix : %s is blocked by in-bound filter: %s', msg_nlri, blocked_cause)
|
||||
LOG.debug('prefix : %s is blocked by in-bound filter: %s',
|
||||
msg_nlri, blocked_cause)
|
||||
|
||||
# If update message had any qualifying new paths, do some book-keeping.
|
||||
if msg_nlri_list:
|
||||
@ -1623,7 +1625,8 @@ class Peer(Source, Sink, NeighborConfListener, Activity):
|
||||
tm = self._core_service.table_manager
|
||||
tm.learn_path(w_path)
|
||||
else:
|
||||
LOG.debug('prefix : %s is blocked by in-bound filter: %s', w_nlri, blocked_cause)
|
||||
LOG.debug('prefix : %s is blocked by in-bound filter: %s',
|
||||
w_nlri, blocked_cause)
|
||||
|
||||
def _handle_eor(self, route_family):
|
||||
"""Currently we only handle EOR for RTC address-family.
|
||||
|
@ -18,6 +18,7 @@
|
||||
"""
|
||||
from abc import ABCMeta
|
||||
from abc import abstractmethod
|
||||
import functools
|
||||
import numbers
|
||||
import logging
|
||||
import six
|
||||
@ -479,6 +480,7 @@ class ConfWithStatsListener(BaseConfListener):
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
@functools.total_ordering
|
||||
class ConfEvent(object):
|
||||
"""Encapsulates configuration settings change/update event."""
|
||||
|
||||
@ -517,9 +519,13 @@ class ConfEvent(object):
|
||||
return ('ConfEvent(src=%s, name=%s, value=%s)' %
|
||||
(self.src, self.name, self.value))
|
||||
|
||||
def __cmp__(self, other):
|
||||
return cmp((other.src, other.name, other.value),
|
||||
(self.src, self.name, self.value))
|
||||
def __lt__(self, other):
|
||||
return ((self.src, self.name, self.value) <
|
||||
(other.src, other.name, other.value))
|
||||
|
||||
def __eq__(self, other):
|
||||
return ((self.src, self.name, self.value) ==
|
||||
(other.src, other.name, other.value))
|
||||
|
||||
|
||||
# =============================================================================
|
||||
@ -598,10 +604,10 @@ def validate_cap_mbgp_ipv4(cmv4):
|
||||
|
||||
|
||||
@validate(name=CAP_MBGP_IPV6)
|
||||
def validate_cap_mbgp_ipv4(cmv6):
|
||||
def validate_cap_mbgp_ipv6(cmv6):
|
||||
if cmv6 not in (True, False):
|
||||
raise ConfigTypeError(desc='Invalid Enhanced Refresh capability '
|
||||
'settings: %s boolean value expected' % cmv4)
|
||||
'settings: %s boolean value expected' % cmv6)
|
||||
|
||||
return cmv6
|
||||
|
||||
|
@ -129,10 +129,11 @@ def validate_refresh_max_eor_time(rmet):
|
||||
@validate(name=LABEL_RANGE)
|
||||
def validate_label_range(label_range):
|
||||
min_label, max_label = label_range
|
||||
if (not min_label or not max_label
|
||||
or not isinstance(min_label, numbers.Integral)
|
||||
or not isinstance(max_label, numbers.Integral) or min_label < 17
|
||||
or min_label >= max_label):
|
||||
if (not min_label or
|
||||
not max_label or
|
||||
not isinstance(min_label, numbers.Integral) or
|
||||
not isinstance(max_label, numbers.Integral) or min_label < 17 or
|
||||
min_label >= max_label):
|
||||
raise ConfigValueError(desc=('Invalid label_range configuration value:'
|
||||
' (%s).' % label_range))
|
||||
|
||||
|
@ -60,7 +60,6 @@ from ryu.services.protocols.bgp.rtconf.base import SITE_OF_ORIGINS
|
||||
from ryu.services.protocols.bgp.rtconf.base import validate
|
||||
from ryu.services.protocols.bgp.rtconf.base import validate_med
|
||||
from ryu.services.protocols.bgp.rtconf.base import validate_soo_list
|
||||
from ryu.services.protocols.bgp.utils.validation import is_valid_ipv4
|
||||
from ryu.services.protocols.bgp.utils.validation import is_valid_old_asn
|
||||
from ryu.services.protocols.bgp.info_base.base import Filter
|
||||
from ryu.services.protocols.bgp.info_base.base import PrefixFilter
|
||||
|
@ -22,7 +22,6 @@ import logging
|
||||
|
||||
from ryu.lib.packet.bgp import RF_IPv4_UC
|
||||
from ryu.lib.packet.bgp import RF_IPv6_UC
|
||||
from ryu.lib.packet.bgp import BGPPathAttributeExtendedCommunities
|
||||
|
||||
from ryu.services.protocols.bgp.utils import validation
|
||||
from ryu.services.protocols.bgp.base import get_validator
|
||||
|
@ -1,5 +1,4 @@
|
||||
__author__ = 'yak'
|
||||
|
||||
from ryu.services.protocols.bgp.signals.base import SignalBus
|
||||
|
||||
__all__ = [SignalBus]
|
||||
__author__ = 'yak'
|
||||
|
@ -24,14 +24,11 @@ from socket import IPPROTO_TCP, TCP_NODELAY
|
||||
from eventlet import semaphore
|
||||
|
||||
from ryu.lib.packet import bgp
|
||||
from ryu.lib.packet.bgp import RouteFamily
|
||||
from ryu.lib.packet.bgp import RF_RTC_UC
|
||||
from ryu.lib.packet.bgp import BGPMessage
|
||||
from ryu.lib.packet.bgp import BGPOpen
|
||||
from ryu.lib.packet.bgp import BGPUpdate
|
||||
from ryu.lib.packet.bgp import BGPKeepAlive
|
||||
from ryu.lib.packet.bgp import BGPNotification
|
||||
from ryu.lib.packet.bgp import BGPRouteRefresh
|
||||
from ryu.lib.packet.bgp import BGP_MSG_OPEN
|
||||
from ryu.lib.packet.bgp import BGP_MSG_UPDATE
|
||||
from ryu.lib.packet.bgp import BGP_MSG_KEEPALIVE
|
||||
@ -39,7 +36,6 @@ from ryu.lib.packet.bgp import BGP_MSG_NOTIFICATION
|
||||
from ryu.lib.packet.bgp import BGP_MSG_ROUTE_REFRESH
|
||||
from ryu.lib.packet.bgp import BGP_CAP_ENHANCED_ROUTE_REFRESH
|
||||
from ryu.lib.packet.bgp import BGP_CAP_MULTIPROTOCOL
|
||||
from ryu.lib.packet.bgp import BGP_CAP_ROUTE_REFRESH
|
||||
from ryu.lib.packet.bgp import BGP_ERROR_HOLD_TIMER_EXPIRED
|
||||
from ryu.lib.packet.bgp import BGP_ERROR_SUB_HOLD_TIMER_EXPIRED
|
||||
from ryu.lib.packet.bgp import get_rf
|
||||
@ -143,7 +139,7 @@ class BgpProtocol(Protocol, Activity):
|
||||
'`BgpProtocol`')
|
||||
|
||||
# Compare protocol connection end point's addresses
|
||||
if (self._remotename[0] == other_protoco._remotename[0] and
|
||||
if (self._remotename[0] == other_protocol._remotename[0] and
|
||||
self._localname[0] == other_protocol._localname[0]):
|
||||
return True
|
||||
|
||||
@ -324,25 +320,23 @@ class BgpProtocol(Protocol, Activity):
|
||||
raise bgp.NotSync()
|
||||
|
||||
# Check if we have valid bgp message length.
|
||||
check = lambda: length < BGP_MIN_MSG_LEN\
|
||||
or length > BGP_MAX_MSG_LEN
|
||||
check = (length < BGP_MIN_MSG_LEN or length > BGP_MAX_MSG_LEN)
|
||||
|
||||
# RFC says: The minimum length of the OPEN message is 29
|
||||
# octets (including the message header).
|
||||
check2 = lambda: ptype == BGP_MSG_OPEN\
|
||||
and length < BGPOpen._MIN_LEN
|
||||
check2 = (ptype == BGP_MSG_OPEN and length < BGPOpen._MIN_LEN)
|
||||
|
||||
# RFC says: A KEEPALIVE message consists of only the
|
||||
# message header and has a length of 19 octets.
|
||||
check3 = lambda: ptype == BGP_MSG_KEEPALIVE\
|
||||
and length != BGPKeepAlive._MIN_LEN
|
||||
check3 = (ptype == BGP_MSG_KEEPALIVE and
|
||||
length != BGPKeepAlive._MIN_LEN)
|
||||
|
||||
# RFC says: The minimum length of the UPDATE message is 23
|
||||
# octets.
|
||||
check4 = lambda: ptype == BGP_MSG_UPDATE\
|
||||
and length < BGPUpdate._MIN_LEN
|
||||
check4 = (ptype == BGP_MSG_UPDATE and
|
||||
length < BGPUpdate._MIN_LEN)
|
||||
|
||||
if check() or check2() or check3() or check4():
|
||||
if any((check, check2, check3, check4)):
|
||||
raise bgp.BadLen(ptype, length)
|
||||
|
||||
# If we have partial message we wait for rest of the message.
|
||||
@ -380,7 +374,7 @@ class BgpProtocol(Protocol, Activity):
|
||||
self._sendlock.acquire()
|
||||
try:
|
||||
self._socket.sendall(msg.serialize())
|
||||
except socket.error as err:
|
||||
except socket.error:
|
||||
self.connection_lost('failed to write to socket')
|
||||
finally:
|
||||
self._sendlock.release()
|
||||
|
Loading…
Reference in New Issue
Block a user