Пример #1
0
	def _header (self, content, header, body, neighbor,message_type=None):
		peer     = '"host" : "%s", '   % socket.gethostname()
		pid      = '"pid" : %s, '      % os.getpid()
		ppid     = '"ppid" : %s, '     % os.getppid()
		counter  = '"counter": %s, '   % self._counter(neighbor) if neighbor is not None else ''
		header   = '"header": "%s", '  % hexstring(header) if header else ''
		body     = '"body": "%s", '    % hexstring(body) if body else ''
		mtype    = '"type": "%s", '    % message_type if message_type else 'default'

		return \
			'{ '\
			'"exabgp": "%s", '\
			'"time": %s, ' \
			'%s%s%s%s%s%s%s%s ' \
			'}' % (
				self.version,
				self.time(time.time()),
				peer,
				pid,
				ppid,
				counter,
				mtype,
				header,
				body,
				content
			)
Пример #2
0
    def _header(self, content, header, body, neighbor, message_type=None):
        peer = '"host" : "%s", ' % socket.gethostname()
        pid = '"pid" : %s, ' % os.getpid()
        ppid = '"ppid" : %s, ' % os.getppid()
        counter = '"counter": %s, ' % self._counter(
            neighbor) if neighbor is not None else ''
        header = '"header": "%s", ' % hexstring(header) if header else ''
        body = '"body": "%s", ' % hexstring(body) if body else ''
        mtype = '"type": "%s", ' % message_type if message_type else 'default'

        return \
         '{ '\
         '"exabgp": "%s", '\
         '"time": %s, ' \
         '%s%s%s%s%s%s%s%s ' \
         '}' % (
          self.version,
          self.time(time.time()),
          peer,
          pid,
          ppid,
          counter,
          mtype,
          header,
          body,
          content
         )
Пример #3
0
    def _header_body(self, header, body):
        header = " header %s" % hexstring(header) if header else ""
        body = " body %s" % hexstring(body) if body else ""

        total_string = header + body if body else header

        return total_string
Пример #4
0
	def _header_body (self, header, body):
		header = ' header %s' % hexstring(header) if header else ''
		body = ' body %s' % hexstring(body) if body else ''

		total_string = header+body if body else header

		return total_string
Пример #5
0
	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))
Пример #6
0
	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))
Пример #7
0
 def unpack_message(cls, data, negotiated):  # pylint: disable=W0613
     # This can not happen at decode time as we check the length of the KEEPALIVE message
     # But could happen when calling the function programmatically
     if data:
         raise Notify('Keepalive can not have any payload but contains %s',
                      hexstring(data))
     return cls()
Пример #8
0
	def notification (self, neighbor, direction, message, header, body):
		return self._header(self._neighbor(neighbor,direction,self._kv({
			'notification': '{ %s } ' % self._kv({
				'code':    message.code,
				'subcode': message.subcode,
				'data':    hexstring(message.data),
			})
		})),header,body,neighbor,message_type='notification')
Пример #9
0
	def notification (self, neighbor, direction, message, header, body):
		return self._header(self._neighbor(neighbor,direction,self._kv({
			'notification': '{ %s } ' % self._kv({
				'code':    message.code,
				'subcode': message.subcode,
				'data':    hexstring(message.data),
			})
		})),header,body,neighbor,message_type='notification')
Пример #10
0
 def notification(self, neighbor, direction, message, header, body):
     return "neighbor %s %s notification code %d subcode %d data %s%s\n" % (
         neighbor.peer_address,
         direction,
         message.code,
         message.subcode,
         hexstring(message.data),
         self._header_body(header, body),
     )
Пример #11
0
	def notification (self, neighbor, direction, message, header, body):
		return 'neighbor %s %s notification code %d subcode %d data %s%s\n' % (
			neighbor.peer_address,
			direction,
			message.code,
			message.subcode,
			hexstring(message.data),
			self._header_body(header,body)
		)
Пример #12
0
	def unpack_message (cls, data, negotiated):  # pylint: disable=W0613
		# This can not happen at decode time as we check the length of the KEEPALIVE message
		# But could happen when calling the function programmatically
		if data:
			raise Notify('Keepalive can not have any payload but contains %s', hexstring(data))
		return cls()