def setUp(self): #self.scheduler logging.basicConfig() self.scheduler = Scheduler(DefaultPolling()) #self.scheduler.debugging = True #self.scheduler.logger.setLevel('DEBUG') #Client.logger.setLevel('DEBUG') import tests import os.path rootpath, _ = os.path.split(tests.__path__[0]) if rootpath: os.chdir(rootpath) self.scheduler.queue.addSubQueue(3, PollEvent.createMatcher(category=PollEvent.WRITE_READY), 'write', None, None, CBQueue.AutoClassQueue.initHelper('fileno')) self.scheduler.queue.addSubQueue(1, PollEvent.createMatcher(category=PollEvent.READ_READY), 'read', None, None, CBQueue.AutoClassQueue.initHelper('fileno')) self.scheduler.queue.addSubQueue(5, PollEvent.createMatcher(category=PollEvent.ERROR), 'error') self.scheduler.queue.addSubQueue(2, ConnectionControlEvent.createMatcher(), 'control') self.scheduler.queue.addSubQueue(4, ConnectionWriteEvent.createMatcher(), 'connectionwrite', 40, 40, CBQueue.AutoClassQueue.initHelper('connection')) self.scheduler.queue.addSubQueue(10, RoutineControlEvent.createMatcher(), 'routine') self.scheduler.queue.addSubQueue(9, TimerEvent.createMatcher(), 'timer') self.scheduler.queue.addSubQueue(8, ResolveResponseEvent.createMatcher(), 'resolve') self.scheduler.queue.addSubQueue(8, ResolveRequestEvent.createMatcher(), 'resolvereq') self.scheduler.queue.addSubQueue(20, SystemControlEvent.createMatcher(), 'sysctl') self.scheduler.queue.addSubQueue(0, SystemControlLowPriorityEvent.createMatcher(), 'sysctllow') #Client.logger.setLevel('DEBUG') #TcpServer.logger.setLevel('DEBUG') self.protocolServer = TestProtocol(True) self.protocolClient = TestProtocol(False) self.resolver = Resolver(scheduler=self.scheduler) self.resolver.start()
def setUp(self): #self.scheduler logging.basicConfig() self.scheduler = Scheduler(DefaultPolling()) #self.scheduler.debugging = True #self.scheduler.logger.setLevel('DEBUG') #Client.logger.setLevel('DEBUG') import tests import os.path rootpath, _ = os.path.split(tests.__path__[0]) if rootpath: os.chdir(rootpath) self.scheduler.queue.addSubQueue(3, PollEvent.createMatcher(category=PollEvent.WRITE_READY), 'write', None, None, CBQueue.AutoClassQueue.initHelper('fileno')) self.scheduler.queue.addSubQueue(1, PollEvent.createMatcher(category=PollEvent.READ_READY), 'read', None, None, CBQueue.AutoClassQueue.initHelper('fileno')) self.scheduler.queue.addSubQueue(5, PollEvent.createMatcher(category=PollEvent.ERROR), 'error') self.scheduler.queue.addSubQueue(2, ConnectionControlEvent.createMatcher(), 'control') self.scheduler.queue.addSubQueue(4, ConnectionWriteEvent.createMatcher(), 'connectionwrite', 40, 40, CBQueue.AutoClassQueue.initHelper('connection')) self.scheduler.queue.addSubQueue(10, RoutineControlEvent.createMatcher(), 'routine') self.scheduler.queue.addSubQueue(9, TimerEvent.createMatcher(), 'timer') self.scheduler.queue.addSubQueue(8, ResolveResponseEvent.createMatcher(), 'resolve') self.scheduler.queue.addSubQueue(8, ResolveRequestEvent.createMatcher(), 'resolvereq') self.scheduler.queue.addSubQueue(20, SystemControlEvent.createMatcher(), 'sysctl') self.scheduler.queue.addSubQueue(0, SystemControlLowPriorityEvent.createMatcher(), 'sysctllow') #Client.logger.setLevel('DEBUG') #TcpServer.logger.setLevel('DEBUG') self.protocolServer = TestProtocol(True) self.protocolClient = TestProtocol(False) self.resolver = Resolver(scheduler=self.scheduler) self.resolver.start()
def formatrequest(self, request, connection, assignxid = True): if assignxid: self.assignxid(request, connection) c = ConnectionWriteEvent(connection = connection, connmark = connection.connmark, data = request._tobytes()) if self.debugging: self._logger.debug('message formatted: %r', common.dump(request)) return c
def closed(self, connection): ''' routine for connection closed ''' connection.scheduler.ignore(ConnectionWriteEvent.createMatcher(connection = connection)) for m in self._clearwritequeue(connection): yield m
def formatreply(self, reply, request, connection): reply.header.xid = request.header.xid c = ConnectionWriteEvent(connection=connection, connmark=connection.connmark, data=reply._tobytes()) if self.debugging: self._logger.debug('message formatted: %r', common.dump(request)) return c
async def error(self, connection): ''' routine for connection error ''' err = connection.socket.getsockopt(SOL_SOCKET, SO_ERROR) self._logger.warning('Connection error status: %d(%s)', err, errno.errorcode.get(err, 'Not found')) connection.scheduler.ignore(ConnectionWriteEvent.createMatcher(connection = connection)) await self._clearwritequeue(connection)
def closed(self, connection): ''' routine for connection closed ''' connection.scheduler.ignore( ConnectionWriteEvent.createMatcher(connection=connection)) for m in self._clearwritequeue(connection): yield m
def init(self, connection): ''' routine for connection initialization ''' try: connection.createdqueues = [] if self.createqueue: connection.queue = connection.scheduler.queue.addSubQueue( self.writepriority, ConnectionWriteEvent.createMatcher(connection=connection), ('write', connection), self.writequeuesize) connection.createdqueues.append(connection.queue) except IndexError: pass if False: yield
async def init(self, connection): await Protocol.init(self, connection) connection.createdqueues.append(connection.scheduler.queue.addSubQueue(\ self.messagepriority, OpenflowPresetupMessageEvent.createMatcher(connection = connection), ('presetup', connection))) connection.createdqueues.append(connection.scheduler.queue.addSubQueue(\ self.messagepriority, OpenflowConnectionStateEvent.createMatcher(connection = connection), ('connstate', connection))) connection.createdqueues.append(connection.scheduler.queue.addSubQueue(\ self.messagepriority + 1, OpenflowResponseEvent.createMatcher(connection = connection), ('response', connection), self.messagequeuesize)) connection.createdqueues.append(connection.scheduler.queue.addSubQueue(\ self.messagepriority, OpenflowAsyncMessageEvent.createMatcher(connection = connection), ('async', connection), self.messagequeuesize)) connection.createdqueues.append(connection.scheduler.queue.addSubQueue(\ self.messagepriority, OpenflowExperimenterMessageEvent.createMatcher(connection = connection), ('experimenter', connection), self.messagequeuesize)) # Add priority to echo reply, or the whole connection is down connection.createdqueues.append(connection.scheduler.queue.addSubQueue(\ self.writepriority + 10, ConnectionWriteEvent.createMatcher(connection = connection, _ismatch = lambda x: hasattr(x, 'echoreply') and x.echoreply), ('echoreply', connection))) connection._rate_limiter = RateLimiter(200, connection) await self.reconnect_init(connection)
def init(self, connection): for m in Protocol.init(self, connection): yield m connection.createdqueues.append(connection.scheduler.queue.addSubQueue(\ self.messagepriority, OpenflowPresetupMessageEvent.createMatcher(connection = connection), ('presetup', connection))) connection.createdqueues.append(connection.scheduler.queue.addSubQueue(\ self.messagepriority, OpenflowConnectionStateEvent.createMatcher(connection = connection), ('connstate', connection))) connection.createdqueues.append(connection.scheduler.queue.addSubQueue(\ self.messagepriority + 1, OpenflowResponseEvent.createMatcher(connection = connection), ('response', connection), self.messagequeuesize)) connection.createdqueues.append(connection.scheduler.queue.addSubQueue(\ self.messagepriority, OpenflowAsyncMessageEvent.createMatcher(connection = connection), ('async', connection), self.messagequeuesize)) connection.createdqueues.append(connection.scheduler.queue.addSubQueue(\ self.messagepriority, OpenflowExperimenterMessageEvent.createMatcher(connection = connection), ('experimenter', connection), self.messagequeuesize)) # Add priority to echo reply, or the whole connection is down connection.createdqueues.append(connection.scheduler.queue.addSubQueue(\ self.writepriority + 10, ConnectionWriteEvent.createMatcher(connection = connection, _ismatch = lambda x: hasattr(x, 'echoreply') and x.echoreply), ('echoreply', connection))) for m in self.reconnect_init(connection): yield m
def init(self, connection): """ routine for connection initialization """ try: connection.createdqueues = [] if self.createqueue: connection.queue = connection.scheduler.queue.addSubQueue( self.writepriority, ConnectionWriteEvent.createMatcher(connection=connection), ("write", connection), self.writequeuesize, ) connection.createdqueues.append(connection.queue) except IndexError: pass if False: yield
def parse(self, connection, data, laststart): start = 0 events = [] while True: result = common.ofp_msg.parse(data[start:]) if result is None: break msg, size = result if self.debugging: self._logger.debug('message received: %r', common.dump(msg)) start += size e = self._createevent(connection, msg) if e is not None: events.append(e) if laststart == len(data): # Remote write close events.append(ConnectionWriteEvent(connection, connection.connmark, data = b'', EOF = True)) return (events, len(data) - start)
def _extra_queues(self, connection): connection.createdqueues.append(connection.scheduler.queue.addSubQueue(\ self.writepriority + 10, ConnectionWriteEvent.createMatcher(connection = connection, _ismatch = lambda x: hasattr(x, 'echoreply') and x.echoreply), ('echoreply', connection))) if False: yield