本文整理汇总了Python中exabgp.reactor.network.outgoing.Outgoing.session方法的典型用法代码示例。如果您正苦于以下问题:Python Outgoing.session方法的具体用法?Python Outgoing.session怎么用?Python Outgoing.session使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类exabgp.reactor.network.outgoing.Outgoing
的用法示例。
在下文中一共展示了Outgoing.session方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Protocol
# 需要导入模块: from exabgp.reactor.network.outgoing import Outgoing [as 别名]
# 或者: from exabgp.reactor.network.outgoing.Outgoing import session [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:
#.........这里部分代码省略.........