本文整理汇总了Python中exabgp.logger.FakeLogger.debug方法的典型用法代码示例。如果您正苦于以下问题:Python FakeLogger.debug方法的具体用法?Python FakeLogger.debug怎么用?Python FakeLogger.debug使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类exabgp.logger.FakeLogger
的用法示例。
在下文中一共展示了FakeLogger.debug方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Protocol
# 需要导入模块: from exabgp.logger import FakeLogger [as 别名]
# 或者: from exabgp.logger.FakeLogger import debug [as 别名]
class Protocol (object):
decode = True
def __init__ (self, peer):
try:
self.logger = Logger()
except RuntimeError:
self.logger = FakeLogger()
self.peer = peer
self.neighbor = peer.neighbor
self.negotiated = Negotiated(self.neighbor)
self.connection = None
if self.neighbor.connect:
self.port = self.neighbor.connect
elif os.environ.get('exabgp.tcp.port','').isdigit():
self.port = int(os.environ.get('exabgp.tcp.port'))
elif os.environ.get('exabgp_tcp_port','').isdigit():
self.port = int(os.environ.get('exabgp_tcp_port'))
else:
self.port = 179
# XXX: FIXME: check the the -19 is correct (but it is harmless)
# The message size is the whole BGP message _without_ headers
self.message_size = Message.MAX_LEN-Message.HEADER_LEN
from exabgp.configuration.environment import environment
self.log_routes = peer.neighbor.adj_rib_in or environment.settings().log.routes
# XXX: we use self.peer.neighbor.peer_address when we could use self.neighbor.peer_address
def me (self, message):
return "%s/%s %s" % (self.peer.neighbor.peer_address,self.peer.neighbor.peer_as,message)
def accept (self, incoming):
self.connection = incoming
if self.peer.neighbor.api['neighbor-changes']:
self.peer.reactor.processes.connected(self.peer.neighbor)
# very important - as we use this function on __init__
return self
def connect (self):
# allows to test the protocol code using modified StringIO with a extra 'pending' function
if not self.connection:
local = self.neighbor.md5_ip.top() if not self.neighbor.auto_discovery else None
peer = self.neighbor.peer_address.top()
afi = self.neighbor.peer_address.afi
md5 = self.neighbor.md5_password
md5_base64 = self.neighbor.md5_base64
ttl_out = self.neighbor.ttl_out
self.connection = Outgoing(afi,peer,local,self.port,md5,md5_base64,ttl_out)
if not local and self.connection.init:
self.neighbor.local_address = IP.create(self.connection.local)
if self.neighbor.router_id is None and self.neighbor.local_address.afi == AFI.ipv4:
self.neighbor.router_id = self.neighbor.local_address
try:
generator = self.connection.establish()
while True:
connected = six.next(generator)
if not connected:
yield False
continue
if self.peer.neighbor.api['neighbor-changes']:
self.peer.reactor.processes.connected(self.peer.neighbor)
yield True
return
except StopIteration:
# close called by the caller
# self.close('could not connect to remote end')
yield False
return
def close (self, reason='protocol closed, reason unspecified'):
if self.connection:
self.logger.debug(reason,self.connection.session())
# must be first otherwise we could have a loop caused by the raise in the below
self.connection.close()
self.connection = None
self.peer.stats['down'] = self.peer.stats.get('down',0) + 1
try:
if self.peer.neighbor.api['neighbor-changes']:
self.peer.reactor.processes.down(self.peer.neighbor,reason)
except ProcessError:
self.logger.debug('could not send notification of neighbor close to API',self.connection.session())
def _to_api (self,direction,message,raw):
packets = self.neighbor.api['%s-packets' % direction]
parsed = self.neighbor.api['%s-parsed' % direction]
consolidate = self.neighbor.api['%s-consolidate' % direction]
negotiated = self.negotiated if self.neighbor.api['negotiated'] else None
if consolidate:
if packets:
self.peer.reactor.processes.message(self.peer.neighbor,direction,message,negotiated,raw[:19],raw[19:])
else:
#.........这里部分代码省略.........
示例2: Peer
# 需要导入模块: from exabgp.logger import FakeLogger [as 别名]
# 或者: from exabgp.logger.FakeLogger import debug [as 别名]
#.........这里部分代码省略.........
self._delay.reset()
def reestablish (self, restart_neighbor=None):
# we want to tear down the session and re-establish it
self._teardown = 3
self._restart = True
self._restarted = True
self._resend_routes = SEND.NORMAL
self._neighbor = restart_neighbor
self._delay.reset()
def reconfigure (self, restart_neighbor=None):
# we want to update the route which were in the configuration file
self._reconfigure = True
self._neighbor = restart_neighbor
self._resend_routes = SEND.NORMAL
self._neighbor = restart_neighbor
def teardown (self, code, restart=True):
self._restart = restart
self._teardown = code
self._delay.reset()
# sockets we must monitor
def sockets (self):
if self.proto:
fd = self.proto.fd()
if fd:
return [fd]
return []
def handle_connection (self, connection):
self.logger.debug("state machine for the peer is %s" % self.fsm.name(), self.id())
# if the other side fails, we go back to idle
if self.fsm == FSM.ESTABLISHED:
self.logger.debug('we already have a peer in state established for %s' % connection.name(),self.id())
return connection.notification(6,7,'could not accept the connection, already established')
# 6.8 The convention is to compare the BGP Identifiers of the peers
# involved in the collision and to retain only the connection initiated
# by the BGP speaker with the higher-valued BGP Identifier.
# FSM.IDLE , FSM.ACTIVE , FSM.CONNECT , FSM.OPENSENT , FSM.OPENCONFIRM , FSM.ESTABLISHED
if self.fsm == FSM.OPENCONFIRM:
# We cheat: we are not really reading the OPEN, we use the data we have instead
# it does not matter as the open message will be the same anyway
local_id = self.neighbor.router_id.pack()
remote_id = self.proto.negotiated.received_open.router_id.pack()
if remote_id < local_id:
self.logger.debug('closing incoming connection as we have an outgoing connection with higher router-id for %s' % connection.name(),self.id())
return connection.notification(6,7,'could not accept the connection, as another connection is already in open-confirm and will go through')
# accept the connection
if self.proto:
self.logger.debug('closing outgoing connection as we have another incoming on with higher router-id for %s' % connection.name(),self.id())
self.proto.close('closing outgoing connection as we have another incoming on with higher router-id')
self.proto = Protocol(self).accept(connection)
self.generator = None
# Let's make sure we do some work with this connection
self._delay.reset()
return None
示例3: Connection
# 需要导入模块: from exabgp.logger import FakeLogger [as 别名]
# 或者: from exabgp.logger.FakeLogger import debug [as 别名]
class Connection (object):
direction = 'undefined'
identifier = {}
def __init__ (self, afi, peer, local):
# peer and local are strings of the IP
try:
self.defensive = environment.settings().debug.defensive
self.logger = Logger()
except RuntimeError:
self.defensive = True
self.logger = FakeLogger()
self.afi = afi
self.peer = peer
self.local = local
self.io = None
self.established = False
self.id = self.identifier.get(self.direction,1)
def success (self):
identifier = self.identifier.get(self.direction,1) + 1
self.identifier[self.direction] = identifier
return identifier
# Just in case ..
def __del__ (self):
if self.io:
self.logger.warning('connection to %s closed' % self.peer,self.session())
self.close()
def name (self):
return "%s-%d %s-%s" % (self.direction,self.id,self.local,self.peer)
def session (self):
return "%s-%d" % (self.direction,self.id)
def close (self):
try:
self.logger.warning('%s, closing connection' % self.name(),source=self.session())
if self.io:
self.io.close()
self.io = None
except KeyboardInterrupt as exc:
raise exc
except Exception:
pass
def reading (self):
while True:
try:
r,_,_ = select.select([self.io,],[],[],0)
except select.error as exc:
if exc.args[0] not in error.block:
self.close()
self.logger.warning('%s %s errno %s on socket' % (self.name(),self.peer,errno.errorcode[exc.args[0]]),self.session())
raise NetworkError('errno %s on socket' % errno.errorcode[exc.args[0]])
return False
return r != []
def writing (self):
while True:
try:
_,w,_ = select.select([],[self.io,],[],0)
except select.error as exc:
if exc.args[0] not in error.block:
self.close()
self.logger.warning('%s %s errno %s on socket' % (self.name(),self.peer,errno.errorcode[exc.args[0]]),self.session())
raise NetworkError('errno %s on socket' % errno.errorcode[exc.args[0]])
return False
return w != []
def _reader (self, number):
# The function must not be called if it does not return with no data with a smaller size as parameter
if not self.io:
self.close()
raise NotConnected('Trying to read on a closed TCP connection')
if number == 0:
yield b''
return
while not self.reading():
yield b''
data = b''
reported = ''
while True:
try:
while True:
if self.defensive and random.randint(0,2):
raise socket.error(errno.EAGAIN,'raising network error on purpose')
read = self.io.recv(number)
if not read:
self.close()
self.logger.warning('%s %s lost TCP session with peer' % (self.name(),self.peer),self.session())
raise LostConnection('the TCP connection was closed by the remote end')
data += read
#.........这里部分代码省略.........