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))
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')
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))
def read_message(self, comment=''): 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 message = Message.unpack_message(msg, body, self.negotiated) self.logger.message(self.me('<< %s' % Message.ID.name(msg))) if message.TYPE == Notification.TYPE: raise message 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')
class TestData (unittest.TestCase): def test_1_open (self): check_capa = { 1: [(AFI.ipv4, SAFI.unicast), (AFI.ipv6, SAFI.unicast)], 2: RouteRefresh(), 65: 65534L, 128: RouteRefresh(), } message_id = 1 body = ''.join([chr(c) for c in [0x4, 0xff, 0xfe, 0x0, 0xb4, 0x0, 0x0, 0x0, 0x0, 0x20, 0x2, 0x6, 0x1, 0x4, 0x0, 0x1, 0x0, 0x1, 0x2, 0x6, 0x1, 0x4, 0x0, 0x2, 0x0, 0x1, 0x2, 0x2, 0x80, 0x0, 0x2, 0x2, 0x2, 0x0, 0x2, 0x6, 0x41, 0x4, 0x0, 0x0, 0xff, 0xfe]]) negotiated = {'invalid':'test'} o = Message.unpack_message(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(4,65500,'127.0.0.1',capabilities,180) 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)