bgp: fix bug when restart neighbor

Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
ISHIDA Wataru 2014-07-28 16:15:26 +09:00 committed by FUJITA Tomonori
parent 5bbc3c2165
commit 3a12b6b1c1
3 changed files with 15 additions and 5 deletions

View File

@ -216,7 +216,7 @@ class CoreService(Factory, Activity):
# Pro-actively try to establish bgp-session with peers.
for peer in self._peer_manager.iterpeers:
self._spawn_activity(peer, self)
self._spawn_activity(peer, self.start_protocol)
# Reactively establish bgp-session with peer by listening on
# server port for connection requests.

View File

@ -53,6 +53,11 @@ from ryu.lib.packet.bgp import BGPOpen
from ryu.lib.packet.bgp import BGPUpdate
from ryu.lib.packet.bgp import BGPRouteRefresh
from ryu.lib.packet.bgp import BGP_ERROR_CEASE
from ryu.lib.packet.bgp import BGP_ERROR_SUB_ADMINISTRATIVE_SHUTDOWN
from ryu.lib.packet.bgp import BGP_ERROR_SUB_CONNECTION_COLLISION_RESOLUTION
from ryu.lib.packet.bgp import BGP_MSG_UPDATE
from ryu.lib.packet.bgp import BGP_MSG_KEEPALIVE
from ryu.lib.packet.bgp import BGP_MSG_ROUTE_REFRESH
@ -410,9 +415,10 @@ class Peer(Source, Sink, NeighborConfListener, Activity):
LOG.debug('Peer %s configuration update event, enabled: %s.' %
(self, enabled))
if enabled:
if self._protocol:
if self._protocol and self._protocol.started:
LOG.error('Tried to enable neighbor that is already enabled')
else:
self.state.bgp_state = const.BGP_FSM_CONNECT
# Restart connect loop if not already running.
if not self._connect_retry_event.is_set():
self._connect_retry_event.set()
@ -429,6 +435,8 @@ class Peer(Source, Sink, NeighborConfListener, Activity):
BGP_ERROR_SUB_ADMINISTRATIVE_SHUTDOWN
)
self._protocol.stop()
self._protocol = None
self.state.bgp_state = const.BGP_FSM_IDLE
# If this peer is not enabled any-more we stop trying to make any
# connection.
LOG.debug('Disabling connect-retry as neighbor was disabled (%s)' %
@ -966,7 +974,8 @@ class Peer(Source, Sink, NeighborConfListener, Activity):
# If existing protocol is already established, we raise exception.
if self.state.bgp_state != const.BGP_FSM_IDLE:
LOG.debug('Currently in %s state, hence will send collision'
' Notification to close this protocol.')
' Notification to close this protocol.'
% self.state.bgp_state)
self._send_collision_err_and_stop(proto)
return
@ -1775,6 +1784,7 @@ class Peer(Source, Sink, NeighborConfListener, Activity):
)
self.state.bgp_state = const.BGP_FSM_IDLE
if self._protocol:
self._protocol.stop()
self._protocol = None
# Create new collection for initial RT NLRIs
self._init_rtc_nlri_path = []

View File

@ -371,8 +371,8 @@ class BgpProtocol(Protocol, Activity):
reason = notification.reason
self._send_with_lock(notification)
self._signal_bus.bgp_error(self._peer, code, subcode, reason)
if len(self._localname()):
LOG.error('Sent notification to %r >> %s' % (self._localname(),
if len(self._localname):
LOG.error('Sent notification to %r >> %s' % (self._localname,
notification))
self._socket.close()