当前位置: 首页>>代码示例>>Python>>正文


Python message.Message类代码示例

本文整理汇总了Python中exabgp.bgp.message.Message的典型用法代码示例。如果您正苦于以下问题:Python Message类的具体用法?Python Message怎么用?Python Message使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Message类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: read_message

	def read_message (self):
		for length,msg,header,body,notify in self.connection.reader():
			if notify:
				if self.neighbor.api['receive-packets']:
					self.peer.reactor.processes.receive(self.peer,msg,header,body)
				if self.neighbor.api[Message.ID.NOTIFICATION]:
					self.peer.reactor.processes.notification(self.peer,notify.code,notify.subcode,str(notify))
				# XXX: is notify not already Notify class ?
				raise Notify(notify.code,notify.subcode,str(notify))
			if not length:
				yield _NOP

		if self.neighbor.api['receive-packets'] and not self.neighbor.api['consolidate']:
			self.peer.reactor.processes.receive(self.peer,msg,header,body)

		if msg == Message.ID.UPDATE and not self.neighbor.api['receive-parsed'] and not self.log_routes:
			yield _UPDATE
			return

		self.logger.message(self.me('<< %s' % Message.ID.name(msg)))
		try:
			message = Message.unpack_message(msg,body,self.negotiated)
		except (KeyboardInterrupt,SystemExit,Notify):
			raise
		except Exception,e:
			self.logger.message(self.me('Could not decode message %s' % Capability.hex(msg)))
			self.logger.message(self.me('%s' % str(e)))
			raise Notify(2,0,'can not decode update message %s' % Capability.hex(msg))
开发者ID:Krychuu,项目名称:exabgp,代码行数:28,代码来源:protocol.py

示例2: read_message

	def read_message (self):
		# This will always be defined by the loop but scope leaking upset scrutinizer/pylint
		msg_id = None

		packets = self.neighbor.api['receive-packets']
		consolidate = self.neighbor.api['receive-consolidate']
		parsed = self.neighbor.api['receive-parsed']

		body,header = '',''  # just because pylint/pylama are getting more clever

		for length,msg_id,header,body,notify in self.connection.reader():
			# internal issue
			if notify:
				if self.neighbor.api.get('send-%s' % Message.CODE.NOTIFICATION.SHORT,False):
					if consolidate:
						self.peer.reactor.processes.notification(self.peer.neighbor,'send',notify.code,notify.subcode,str(notify),header,body)
					elif parsed:
						self.peer.reactor.processes.notification(self.peer.neighbor,'send',notify.code,notify.subcode,str(notify),'','')
					elif packets:
						self.peer.reactor.processes.packets(self.peer.neighbor,'send',msg_id,header,body)
				# XXX: is notify not already Notify class ?
				raise Notify(notify.code,notify.subcode,str(notify))

			if not length:
				yield _NOP
				continue

			self.logger.message(self.me('<< %s' % Message.CODE.name(msg_id)))

			for_api = self.neighbor.api.get('receive-%s' % Message.CODE.short(msg_id),False)

			if for_api and packets and not consolidate:
				self.peer.reactor.processes.packets(self.peer.neighbor,'receive',msg_id,header,body)

			if msg_id == Message.CODE.UPDATE:
				if not (for_api or self.log_routes) and not (parsed or consolidate):
					yield _UPDATE
					return

			try:
				message = Message.unpack(msg_id,body,self.negotiated)
			except (KeyboardInterrupt,SystemExit,Notify):
				raise
			except Exception,exc:
				self.logger.message(self.me('Could not decode message "%d"' % msg_id))
				self.logger.message(self.me('%s' % str(exc)))
				self.logger.message(traceback.format_exc())
				raise Notify(1,0,'can not decode update message of type "%d"' % msg_id)
				# raise Notify(5,0,'unknown message received')

			if for_api:
				if consolidate:
					self.peer.reactor.processes.message(msg_id,self.neighbor,'receive',message,header,body)
				elif parsed:
					self.peer.reactor.processes.message(msg_id,self.neighbor,'receive',message,'','')

			if message.TYPE == Notification.TYPE:
				raise message

			yield message
开发者ID:Empia,项目名称:exabgp,代码行数:60,代码来源:protocol.py

示例3: read_message

	def read_message (self,comment=''):
		self.peer.reactor.processes.increase(self.peer)

		for length,msg,header,body,notify in self.connection.reader():
			if notify:
				if self.neighbor.api['receive-packets']:
					self.peer.reactor.processes.receive(self.peer,msg,header,body)
				if self.neighbor.api[Message.ID.NOTIFICATION]:
					self.peer.reactor.processes.notification(self.peer,notify.code,notify.subcode,str(notify))
				# XXX: is notify not already Notify class ?
				raise Notify(notify.code,notify.subcode,str(notify))
			if not length:
				yield _NOP

		if self.neighbor.api['receive_packets']:
			self.peer.reactor.processes.receive(self.peer,msg,header,body)

		if msg == Message.ID.UPDATE and not self.neighbor.api['receive-parsed'] and not self.log_routes:
			yield _UPDATE
			return

		message = Message.unpack_message(msg,body,self.negotiated)
		self.logger.message(self.me('<< %s' % Message.ID.name(msg)))
		if self.neighbor.api[msg]:
			if self.neighbor.api['receive-parsed']:
				if self.neighbor.api['consolidate'] and self.neighbor.api['receive-packets']:
					self.peer.reactor.processes.message(msg,self.peer,message,header,body)
				else:
					self.peer.reactor.processes.message(msg,self.peer,message,'','')
		yield message

		return
		# XXX: FIXME: check it is well 2,4
		raise Notify(2,4,'unknown message received')
开发者ID:asnd,项目名称:exabgp,代码行数:34,代码来源:protocol.py

示例4: read_message

	def read_message (self):
		# This will always be defined by the loop but scope leaking upset scrutinizer/pylint
		msg_id = None

		for length,msg_id,header,body,notify in self.connection.reader():
			if notify:
				if self.neighbor.api['receive-packets']:
					self.peer.reactor.processes.receive(self.peer,msg_id,header,body)
				if self.neighbor.api[Message.CODE.NOTIFICATION]:
					self.peer.reactor.processes.notification(self.peer,notify.code,notify.subcode,str(notify))
				# XXX: is notify not already Notify class ?
				raise Notify(notify.code,notify.subcode,str(notify))
			if not length:
				yield _NOP

		if self.neighbor.api['receive-packets'] and not self.neighbor.api['consolidate']:
			self.peer.reactor.processes.receive(self.peer,msg_id,header,body)

		if msg_id == Message.CODE.UPDATE and not self.neighbor.api['receive-parsed'] and not self.log_routes:
			yield _UPDATE
			return

		self.logger.message(self.me('<< %s' % Message.CODE.name(msg_id)))
		try:
			message = Message.unpack(msg_id,body,self.negotiated)
		except (KeyboardInterrupt,SystemExit,Notify):
			raise
		except Exception,exc:
			self.logger.message(self.me('Could not decode message "%d"' % msg_id))
			self.logger.message(self.me('%s' % str(exc)))
			# XXX: TODO: add backtrace here
			raise Notify(1,0,'can not decode update message of type "%d"' % msg_id)
开发者ID:fobser,项目名称:exabgp,代码行数:32,代码来源:protocol.py

示例5: packets

	def packets (self, neighbor, direction, category, header, body):
		return self._header(self._neighbor(neighbor,direction,self._kv({
			'message': '{ %s } ' % self._kv({
				'category': category,
				'header':   hexstring(header),
				'body':     hexstring(body),
			})
		})),'','',neighbor,message_type=Message.string(category))
开发者ID:SaveTheRbtz,项目名称:exabgp,代码行数:8,代码来源:json.py

示例6: send

	def send (self, peer, category, header, body):
		return self._header(self._neighbor(peer,self._kv({
			'message':'{ %s } ' % self._kv({
				'sent':   category,
				'header': hexstring(header),
				'body':   hexstring(body),
			})
		})),'','',peer.neighbor.identificator(),self.count(peer),message_type=Message.string(category))
开发者ID:rendoaw,项目名称:exabgp34-bgpls,代码行数:8,代码来源:encoding.py

示例7: command

    def command(self, scope, name, command, tokens):
        if command in ("packets", "parsed", "consolidate", "neighbor-changes"):
            scope[-1]["%s-%s" % (name, command)] = True
            return True

        message = Message.from_string(command)
        if message == Message.CODE.NOP:
            return self.error.set("unknown process message")

        scope[-1]["%s-%d" % (name, message)] = True
        return True
开发者ID:Shmuma,项目名称:exabgp,代码行数:11,代码来源:process.py

示例8: packets

	def packets (self, neighbor, direction, category, negotiated, header, body):
		message = {
			'message': '{ %s } ' % self._kv({
					'category': category,
					'header':   hexstring(header),
					'body':     hexstring(body),
			})
		}
		if negotiated:
			message.update(self._negotiated(negotiated))
		return self._header(self._neighbor(neighbor,direction,self._kv(
			message
		)),'','',neighbor,message_type=Message.string(category))
开发者ID:dhammika,项目名称:exabgp,代码行数:13,代码来源:json.py

示例9: read_message

	def read_message (self):
		# This will always be defined by the loop but scope leaking upset scrutinizer/pylint
		msg_id = None

		packets = self.neighbor.api['receive-packets']
		consolidate = self.neighbor.api['receive-consolidate']
		parsed = self.neighbor.api['receive-parsed']

		body,header = '',''  # just because pylint/pylama are getting more clever

		for length,msg_id,header,body,notify in self.connection.reader():
			if notify:
				if self.neighbor.api['receive-%s' % Message.CODE.NOTIFICATION.SHORT]:
					if packets and not consolidate:
						self.peer.reactor.processes.packets(self.peer.neighbor,'receive',msg_id,header,body)

					if not packets or consolidate:
						header = ''
						body = ''

					self.peer.reactor.processes.notification(self.peer.neighbor,'receive',notify.code,notify.subcode,str(notify),header,body)
				# XXX: is notify not already Notify class ?
				raise Notify(notify.code,notify.subcode,str(notify))
			if not length:
				yield _NOP

		if packets and not consolidate:
			self.peer.reactor.processes.packets(self.peer.neighbor,'receive',msg_id,header,body)

		if msg_id == Message.CODE.UPDATE:
			if not parsed and not self.log_routes:
				yield _UPDATE
				return

		self.logger.message(self.me('<< %s' % Message.CODE.name(msg_id)))
		try:
			message = Message.unpack(msg_id,body,self.negotiated)
		except (KeyboardInterrupt,SystemExit,Notify):
			raise
		except Exception,exc:
			self.logger.message(self.me('Could not decode message "%d"' % msg_id))
			self.logger.message(self.me('%s' % str(exc)))
			self.logger.message(traceback.format_exc())
			raise Notify(1,0,'can not decode update message of type "%d"' % msg_id)
开发者ID:c0ns0le,项目名称:exabgp,代码行数:44,代码来源:protocol.py

示例10: test_1_open

	def test_1_open (self):
		check_capa = {
			1: [(AFI.ipv4, SAFI.unicast), (AFI.ipv6, SAFI.unicast)],
			2: RouteRefresh(),
			65: 65534,
			128: RouteRefresh(),
		}

		message_id = 1
		negotiated = {'invalid':'test'}

		o = Message.unpack(message_id,data_from_body(open_body),negotiated)

		self.assertEqual(o.version,4)
		self.assertEqual(o.asn,65534)
		self.assertEqual(o.router_id,RouterID('0.0.0.0'))
		self.assertEqual(o.hold_time,180)
		for k,v in o.capabilities.items():
			self.assertEqual(v,check_capa[k])
开发者ID:Exa-Networks,项目名称:exabgp,代码行数:19,代码来源:open_test.py

示例11: _from_json

	def _from_json (self, string):
		try:
			parsed = json.loads(string)
		except ValueError:
			print >> sys.stderr, 'invalid JSON message'
			sys.exit(1)

		if parsed.get('exabgp','0.0.0') != json_version:
			print >> sys.stderr, 'invalid json version', string
			sys.exit(1)

		content = parsed.get('type','')

		if not content:
			print >> sys.stderr, 'invalid json content', string
			sys.exit(1)

		neighbor = _FakeNeighbor(
			parsed['neighbor']['address']['local'],
			parsed['neighbor']['address']['peer'],
			parsed['neighbor']['asn']['local'],
			parsed['neighbor']['asn']['peer'],
		)

		if content == 'state':
			self._state()
			return string

		direction = parsed['neighbor']['direction']
		category = parsed['neighbor']['message']['category']
		header = parsed['neighbor']['message']['header']
		body = parsed['neighbor']['message']['body']
		raw = ''.join(chr(int(body[_:_+2],16)) for _ in range(0,len(body),2))

		if content == 'open':
			message = Open.unpack_message(raw)
			self._open(direction,message)
			return self.encoder.open(neighbor,direction,message,header,body)

		if content == 'keapalive':
			return self.encoder.keepalive(neighbor,direction,header,body)

		if content == 'notification':
			return self.encoder.notification(neighbor,direction,ord(message[0]),ord(message[1]),message[2:],header,body)

		if not self.negotiated:
			print >> sys.stderr, 'invalid message sequence, open not exchange not complete', string
			sys.exit(1)

		message = Message.unpack(category,raw,self.negotiated)

		if content == 'update':
			return self.encoder.update(neighbor, direction, message, header,body)

		if content == 'eor': # XXX: Should not be required
			return self.encoder.update(neighbor, direction, message, header,body)

		if content == 'refresh':
			return self.json.refresh(neighbor, direction, message, header,body)

		if content == 'operational':
			return self.json.refresh(neighbor, direction, message, header,body)

		raise RuntimeError('the programer is a monkey and forgot a JSON message type')
开发者ID:Akheon23,项目名称:exabgp,代码行数:64,代码来源:transcoder.py

示例12: _message

	def _message (self,data):
		return Message._message(self,"%s%s%s" % (
			self.what.pack(),
			pack('!H',len(data)),
			data
		))
开发者ID:asnd,项目名称:exabgp,代码行数:6,代码来源:operational.py

示例13: __init__

	def __init__ (self,what):
		Message.__init__(self)
		self.what = Type(what)
开发者ID:asnd,项目名称:exabgp,代码行数:3,代码来源:operational.py

示例14: read_message

	def read_message (self):
		# This will always be defined by the loop but scope leaking upset scrutinizer/pylint
		msg_id = None

		packets = self.neighbor.api['receive-packets']
		consolidate = self.neighbor.api['receive-consolidate']
		parsed = self.neighbor.api['receive-parsed']

		body,header = b'',b''  # just because pylint/pylama are getting more clever

		for length,msg_id,header,body,notify in self.connection.reader():
			# internal issue
			if notify:
				code = 'receive-%s' % Message.CODE.NOTIFICATION.SHORT
				if self.neighbor.api.get(code,False):
					if consolidate:
						self.peer.reactor.processes.notification(self.peer.neighbor,'receive',notify.code,notify.subcode,str(notify),None,header,body)
					elif parsed:
						self.peer.reactor.processes.notification(self.peer.neighbor,'receive',notify.code,notify.subcode,str(notify),None,b'',b'')
					elif packets:
						self.peer.reactor.processes.packets(self.peer.neighbor,'receive',msg_id,None,header,body)
				# XXX: is notify not already Notify class ?
				raise Notify(notify.code,notify.subcode,str(notify))

			if not length:
				yield _NOP
				continue

			self.logger.debug('<< message of type %s' % Message.CODE.name(msg_id),self.connection.session())

			code = 'receive-%s' % Message.CODE.short(msg_id)
			self.peer.stats[code] = self.peer.stats.get(code,0) + 1
			for_api = self.neighbor.api.get(code,False)

			if for_api and packets and not consolidate:
				negotiated = self.negotiated if self.neighbor.api.get('negotiated',False) else None
				self.peer.reactor.processes.packets(self.peer.neighbor,'receive',msg_id,negotiated,header,body)

			if msg_id == Message.CODE.UPDATE:
				if not self.neighbor.adj_rib_in and not (for_api or self.log_routes) and not (parsed or consolidate):
					yield _UPDATE
					return

			try:
				message = Message.unpack(msg_id,body,self.negotiated)
			except (KeyboardInterrupt,SystemExit,Notify):
				raise
			except Exception as exc:
				self.logger.debug('could not decode message "%d"' % msg_id,self.connection.session())
				self.logger.debug('%s' % str(exc),self.connection.session())
				self.logger.debug(traceback.format_exc(),self.connection.session())
				raise Notify(1,0,'can not decode update message of type "%d"' % msg_id)
				# raise Notify(5,0,'unknown message received')

			if message.TYPE == Update.TYPE:
				if Attribute.CODE.INTERNAL_TREAT_AS_WITHDRAW in message.attributes:
					for nlri in message.nlris:
						nlri.action = IN.WITHDRAWN

			if for_api:
				negotiated = self.negotiated if self.neighbor.api.get('negotiated',False) else None
				if consolidate:
					self.peer.reactor.processes.message(msg_id,self.neighbor,'receive',message,negotiated,header,body)
				elif parsed:
					self.peer.reactor.processes.message(msg_id,self.neighbor,'receive',message,negotiated,b'',b'')

			if message.TYPE == Notification.TYPE:
				raise message

			if message.TYPE == Update.TYPE and Attribute.CODE.INTERNAL_DISCARD in message.attributes:
				yield _NOP
			else:
				yield message
开发者ID:aabdnn,项目名称:exabgp,代码行数:73,代码来源:protocol.py

示例15: RouterID

                    0x2,
                    0x0,
                    0x2,
                    0x6,
                    0x41,
                    0x4,
                    0x0,
                    0x0,
                    0xFF,
                    0xFE,
                ]
            ]
        )
        negotiated = {"invalid": "test"}

        o = Message.unpack(message_id, body, negotiated)

        self.assertEqual(o.version, 4)
        self.assertEqual(o.asn, 65534)
        self.assertEqual(o.router_id, RouterID("0.0.0.0"))
        self.assertEqual(o.hold_time, 180)
        for k, v in o.capabilities.items():
            self.assertEqual(v, check_capa[k])

    def test_2_open(self):
        capabilities = Capabilities()
        o = Open(Version(4), ASN(65500), HoldTime(180), RouterID("127.0.0.1"), capabilities)
        self.assertEqual(o.version, 4)
        self.assertEqual(o.asn, 65500)
        self.assertEqual(o.router_id, RouterID("127.0.0.1"))
        self.assertEqual(o.hold_time, 180)
开发者ID:qz267,项目名称:exabgp,代码行数:31,代码来源:open_test.py


注:本文中的exabgp.bgp.message.Message类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。