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


Python RoutineContainer.subroutine方法代码示例

本文整理汇总了Python中vlcp.event.runnable.RoutineContainer.subroutine方法的典型用法代码示例。如果您正苦于以下问题:Python RoutineContainer.subroutine方法的具体用法?Python RoutineContainer.subroutine怎么用?Python RoutineContainer.subroutine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在vlcp.event.runnable.RoutineContainer的用法示例。


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

示例1: ICMPResponder

# 需要导入模块: from vlcp.event.runnable import RoutineContainer [as 别名]
# 或者: from vlcp.event.runnable.RoutineContainer import subroutine [as 别名]
class ICMPResponder(FlowBase):
    _tablerequest = (
        ("l3input",("l2input",),""),
        ("l2output",("l3input",),"")
    )
    # True :  use flow auto reply icmp ping
    # False: use controller reply icmp ping

    #
    # when ovs 2.5 , icmp_type is not readonly , we can use flow auto reply icmp echo
    #
    _default_prepush = False

    # router use this mac as inner mac
    _default_inroutermac = '1a:23:67:59:63:33'

    def __init__(self,server):
        super(ICMPResponder,self).__init__(server)
        self.app_routine = RoutineContainer(self.scheduler)
        self.app_routine.main = self._main
        self.routines.append(self.app_routine)
        self._flowupdater = dict()

    def _main(self):

        flowinit = FlowInitialize.createMatcher(_ismatch=lambda x: self.vhostbind is None or
                                                x.vhost in self.vhostbind)
        conndown = OpenflowConnectionStateEvent.createMatcher(state = OpenflowConnectionStateEvent.CONNECTION_DOWN,
                                                _ismatch=lambda x:self.vhostbind is None or
                                                x.createby.vhost in self.vhostbind)
        while True:
            yield (flowinit,conndown)
            if self.app_routine.matcher is flowinit:
                c = self.app_routine.event.connection
                self.app_routine.subroutine(self._init_conn(c))
            if self.app_routine.matcher is conndown:
                c = self.app_routine.event.connection
                self.app_routine.subroutine(self._remove_conn(c))

    def _init_conn(self,conn):

        if conn in self._flowupdater:
            updater = self._flowupdater.pop(conn)
            updater.close()

        updater = ICMPResponderUpdater(conn,self)
        self._flowupdater[conn] = updater
        updater.start()

        if False:
            yield

    def _remove_conn(self,conn):

        if conn in self._flowupdater:
            updater = self._flowupdater.pop(conn)
            updater.close()

        if False:
            yield
开发者ID:hubo1016,项目名称:vlcp,代码行数:62,代码来源:icmpresponder.py

示例2: testServerClientSsl

# 需要导入模块: from vlcp.event.runnable import RoutineContainer [as 别名]
# 或者: from vlcp.event.runnable.RoutineContainer import subroutine [as 别名]
 def testServerClientSsl(self):
     c1 = Client('ssl://localhost:199', self.protocolClient, self.scheduler, 'testcerts/client.key', 'testcerts/client.crt', 'testcerts/root.crt')
     s1 = TcpServer('lssl://localhost:199', self.protocolServer, self.scheduler, 'testcerts/server.key', 'testcerts/server.crt', 'testcerts/root.crt')
     r = RoutineContainer(self.scheduler, True)
     ret = bytearray()
     def mainA():
         m = TestDataEvent.createMatcher()
         stopped = False
         while True:
             yield (m,)
             if r.event.connection is c1:
                 ret.extend(b'B')
             else:
                 ret.extend(b'A')
             if not stopped:
                 for m in s1.shutdown():
                     yield m
                 stopped = True
     r.main = mainA
     r.start()
     s1.start()
     def waitAndStart(c):
         for m in r.waitWithTimeout(0.5):
             yield m
         c.start()
     r.subroutine(waitAndStart(c1))
     self.scheduler.main()
     self.assertEqual(ret, b'ABABABABABABABABABAB')
开发者ID:dq5070410,项目名称:vlcp,代码行数:30,代码来源:testConnection.py

示例3: testBeginlock

# 需要导入模块: from vlcp.event.runnable import RoutineContainer [as 别名]
# 或者: from vlcp.event.runnable.RoutineContainer import subroutine [as 别名]
 def testBeginlock(self):
     rc = RoutineContainer(self.server.scheduler)
     obj = [0]
     def routineLock(key):
         l = Lock(key, rc.scheduler)
         locked = l.beginlock(rc)
         if not locked:
             for m in rc.waitWithTimeout(1.0):
                 yield m
             locked = l.trylock()
             if not locked:
                 raise ValueError('Not locked')
         t = obj[0]
         for m in rc.waitWithTimeout(0.5):
             yield m
         obj[0] = t + 1
         l.unlock()
         for m in rc.doEvents():
             yield m
         for m in l.lock(rc):
             yield m
         t = obj[0]
         for m in rc.waitWithTimeout(1.0):
             yield m
         obj[0] = t + 1
         l.unlock()
     rc.subroutine(routineLock('testobj'))
     rc.subroutine(routineLock('testobj'))
     self.server.serve()
     self.assertEqual(obj[0], 4)
开发者ID:dq5070410,项目名称:vlcp,代码行数:32,代码来源:testLock.py

示例4: testCAVerify3

# 需要导入模块: from vlcp.event.runnable import RoutineContainer [as 别名]
# 或者: from vlcp.event.runnable.RoutineContainer import subroutine [as 别名]
 def testCAVerify3(self):
     c1 = Client('ssl://localhost:199', self.protocolClient, self.scheduler, None, None, 'testcerts/root.crt')
     c2 = Client('pssl://localhost:199', self.protocolServer, self.scheduler, 'testcerts/server.key','testcerts/server.crt','testcerts/root.crt')
     r = RoutineContainer(self.scheduler, True)
     ret = bytearray()
     def mainA():
         m = TestDataEvent.createMatcher()
         while True:
             yield (m,)
             if r.event.connection is c2:
                 ret.extend(b'A')
             else:
                 ret.extend(b'B')
     self.notconnected = False
     def notConnected(connection):
         if connection is c1:
             self.notconnected = True
         if False:
             yield
     self.protocolClient.notconnected = notConnected
     r.main = mainA
     r.start()
     def waitAndStart(c):
         for m in r.waitWithTimeout(0.5):
             yield m
         c.start()
     r.subroutine(waitAndStart(c1))
     c2.start()
     self.scheduler.main()
     self.assertTrue(self.notconnected)
     self.assertEqual(ret, b'')
开发者ID:dq5070410,项目名称:vlcp,代码行数:33,代码来源:testConnection.py

示例5: testSemaphore

# 需要导入模块: from vlcp.event.runnable import RoutineContainer [as 别名]
# 或者: from vlcp.event.runnable.RoutineContainer import subroutine [as 别名]
 def testSemaphore(self):
     rc = RoutineContainer(self.server.scheduler)
     obj = [0]
     def routineLock(key):
         l = Lock(key, rc.scheduler)
         for m in l.lock(rc):
             yield m
         t = obj[0]
         for m in rc.waitWithTimeout(0.5):
             yield m
         obj[0] = t + 1
         l.unlock()
     def main_routine():
         smp = Semaphore('testobj', 2, rc.scheduler)
         smp.create()
         for m in rc.executeAll([routineLock('testobj'),
                                 routineLock('testobj'),
                                 routineLock('testobj'),
                                 routineLock('testobj')], retnames = ()):
             yield m
         for m in smp.destroy(rc):
             yield m
     rc.subroutine(main_routine())
     self.server.serve()
     self.assertEqual(obj[0], 2)
开发者ID:dq5070410,项目名称:vlcp,代码行数:27,代码来源:testLock.py

示例6: testBlock

# 需要导入模块: from vlcp.event.runnable import RoutineContainer [as 别名]
# 或者: from vlcp.event.runnable.RoutineContainer import subroutine [as 别名]
 def testBlock(self):
     scheduler = Scheduler()
     scheduler.queue.addSubQueue(10, RoutineControlEvent.createMatcher())
     scheduler.queue.addSubQueue(1, TestConsumerEvent.createMatcher(), 'consumer', 5, 5)
     rA = RoutineContainer(scheduler)
     output = bytearray()
     def mainA():
         rA.subroutine(mainB(), daemon = True)
         for i in range(0,10):
             for ms in rA.waitForSend(TestConsumerEvent(rA.mainroutine)):
                 yield ms
             output.extend(b'A')
     def mainB():
         for m in rA.doEvents():
             yield m
         matcher = TestConsumerEvent.createMatcher(producer=rA.mainroutine)
         while True:
             yield (matcher,)
             rA.event.canignore = True
             output.extend(b'B')
     def mainC():
         for m in rA.doEvents():
             yield m
         output.extend(b'C')
     rA.main = mainA
     rA.start()
     rA.subroutine(mainC())
     scheduler.main()
     self.assertEqual(output, b'AAAAACBABABABABABBBBB')
开发者ID:dq5070410,项目名称:vlcp,代码行数:31,代码来源:testScheduler.py

示例7: testSelfConnectionUnixDgram

# 需要导入模块: from vlcp.event.runnable import RoutineContainer [as 别名]
# 或者: from vlcp.event.runnable.RoutineContainer import subroutine [as 别名]
 def testSelfConnectionUnixDgram(self):
     if not hasattr(socket, 'AF_UNIX'):
         print('Skip UNIX socket test because not supported')
         return
     try:
         os.remove('/var/run/unixsocktestudp1.sock')
     except:
         pass
     try:
         os.remove('/var/run/unixsocktestudp2.sock')
     except:
         pass
     c1 = Client('dunix:/var/run/unixsocktestudp2.sock', self.protocolClient, self.scheduler, bindaddress = ((socket.AF_UNIX, '/var/run/unixsocktestudp1.sock'),))
     c2 = Client('pdunix:/var/run/unixsocktestudp2.sock', self.protocolServer, self.scheduler)
     r = RoutineContainer(self.scheduler, True)
     ret = bytearray()
     def mainA():
         m = TestDataEvent.createMatcher()
         while True:
             yield (m,)
             if r.event.connection is c2:
                 ret.extend(b'A')
             else:
                 ret.extend(b'B')
     r.main = mainA
     r.start()
     def waitAndStart(c):
         for m in r.waitWithTimeout(0.5):
             yield m
         c.start()
     r.subroutine(waitAndStart(c1))
     c2.start()
     self.scheduler.main()
     self.assertEqual(ret, b'ABABABABABABABABABAB')
开发者ID:dq5070410,项目名称:vlcp,代码行数:36,代码来源:testConnection.py

示例8: TestModule

# 需要导入模块: from vlcp.event.runnable import RoutineContainer [as 别名]
# 或者: from vlcp.event.runnable.RoutineContainer import subroutine [as 别名]
class TestModule(Module):
    _default_serverlist = ['tcp://localhost:3181/','tcp://localhost:3182/','tcp://localhost:3183/']
    def __init__(self, server):
        Module.__init__(self, server)
        self.apiroutine = RoutineContainer(self.scheduler)
        self.client = ZooKeeperClient(self.apiroutine, self.serverlist)
        self.connections.append(self.client)
        self.apiroutine.main = self.main
        self.routines.append(self.apiroutine)
    def watcher(self):
        watcher = ZooKeeperWatcherEvent.createMatcher()
        while True:
            yield (watcher,)
            print('WatcherEvent: %r' % (dump(self.apiroutine.event.message),))
    def main(self):
        def _watch(w):
            for m in w.wait(self.apiroutine):
                yield m
            print('Watcher returns:', dump(self.apiroutine.retvalue))
        def _watchall(watchers):
            for w in watchers:
                if w is not None:
                    self.apiroutine.subroutine(_watch(w))
        self.apiroutine.subroutine(self.watcher(), False, daemon = True)
        up = ZooKeeperSessionStateChanged.createMatcher(ZooKeeperSessionStateChanged.CREATED, self.client)
        yield (up,)
        print('Connection is up: %r' % (self.client.currentserver,))
        for m in self.client.requests([zk.create(b'/vlcptest', b'test'),
                                       zk.getdata(b'/vlcptest', True)], self.apiroutine):
            yield m
        print(self.apiroutine.retvalue)
        pprint(dump(self.apiroutine.retvalue[0]))
        _watchall(self.apiroutine.retvalue[3])
        for m in self.apiroutine.waitWithTimeout(0.2):
            yield m
        for m in self.client.requests([zk.delete(b'/vlcptest'),
                                        zk.getdata(b'/vlcptest', watch = True)], self.apiroutine):
            yield m
        print(self.apiroutine.retvalue)
        pprint(dump(self.apiroutine.retvalue[0]))
        _watchall(self.apiroutine.retvalue[3])
        for m in self.client.requests([zk.multi(
                                        zk.multi_create(b'/vlcptest2', b'test'),
                                        zk.multi_create(b'/vlcptest2/subtest', 'test2')
                                    ),
                                  zk.getchildren2(b'/vlcptest2', True)], self.apiroutine):
            yield m
        print(self.apiroutine.retvalue)
        pprint(dump(self.apiroutine.retvalue[0]))
        _watchall(self.apiroutine.retvalue[3])
        for m in self.client.requests([zk.multi(
                                        zk.multi_delete(b'/vlcptest2/subtest'),
                                        zk.multi_delete(b'/vlcptest2')),
                                  zk.getchildren2(b'/vlcptest2', True)], self.apiroutine):
            yield m
        print(self.apiroutine.retvalue)
        pprint(dump(self.apiroutine.retvalue[0]))
        _watchall(self.apiroutine.retvalue[3])
开发者ID:dq5070410,项目名称:vlcp,代码行数:60,代码来源:testzookeeper2.py

示例9: TestModule

# 需要导入模块: from vlcp.event.runnable import RoutineContainer [as 别名]
# 或者: from vlcp.event.runnable.RoutineContainer import subroutine [as 别名]
class TestModule(Module):
    _default_url = 'tcp://localhost/'
    _default_sessiontimeout = 30
    def __init__(self, server):
        Module.__init__(self, server)
        self.protocol = ZooKeeper()
        self.client = Client(self.url, self.protocol, self.scheduler)
        self.connections.append(self.client)
        self.apiroutine = RoutineContainer(self.scheduler)
        self.apiroutine.main = self.main
        self.routines.append(self.apiroutine)
    def watcher(self):
        watcher = ZooKeeperWatcherEvent.createMatcher(connection = self.client)
        while True:
            yield (watcher,)
            print('WatcherEvent: %r' % (dump(self.apiroutine.event.message),))
    def main(self):
        self.apiroutine.subroutine(self.watcher(), False, daemon = True)
        up = ZooKeeperConnectionStateEvent.createMatcher(ZooKeeperConnectionStateEvent.UP, self.client)
        notconn = ZooKeeperConnectionStateEvent.createMatcher(ZooKeeperConnectionStateEvent.NOTCONNECTED, self.client)
        yield (up, notconn)
        if self.apiroutine.matcher is notconn:
            print('Not connected')
            return
        else:
            print('Connection is up: %r' % (self.client,))
        # Handshake
        for m in self.protocol.handshake(self.client, zk.ConnectRequest(
                                                        timeOut = int(self.sessiontimeout * 1000),
                                                        passwd = b'\x00' * 16,      # Why is it necessary...
                                                    ), self.apiroutine, []):
            yield m
        for m in self.protocol.requests(self.client, [zk.create(b'/vlcptest', b'test'),
                                                      zk.getdata(b'/vlcptest', True)], self.apiroutine):
            yield m
        pprint(dump(self.apiroutine.retvalue[0]))
        for m in self.apiroutine.waitWithTimeout(0.2):
            yield m
        for m in self.protocol.requests(self.client, [zk.delete(b'/vlcptest'),
                                                      zk.getdata(b'/vlcptest', watch = True)], self.apiroutine):
            yield m
        pprint(dump(self.apiroutine.retvalue[0]))
        for m in self.protocol.requests(self.client, [zk.multi(
                                                            zk.multi_create(b'/vlcptest2', b'test'),
                                                            zk.multi_create(b'/vlcptest2/subtest', 'test2')
                                                        ),
                                                      zk.getchildren2(b'/vlcptest2', True)], self.apiroutine):
            yield m
        pprint(dump(self.apiroutine.retvalue[0]))
        for m in self.protocol.requests(self.client, [zk.multi(
                                                            zk.multi_delete(b'/vlcptest2/subtest'),
                                                            zk.multi_delete(b'/vlcptest2')),
                                                      zk.getchildren2(b'/vlcptest2', True)], self.apiroutine):
            yield m
        pprint(dump(self.apiroutine.retvalue[0]))
开发者ID:dq5070410,项目名称:vlcp,代码行数:57,代码来源:testzookeeper.py

示例10: testTrylock

# 需要导入模块: from vlcp.event.runnable import RoutineContainer [as 别名]
# 或者: from vlcp.event.runnable.RoutineContainer import subroutine [as 别名]
 def testTrylock(self):
     rc = RoutineContainer(self.server.scheduler)
     result = []
     def routineTrylock(key):
         l = Lock(key, rc.scheduler)
         locked = l.trylock()
         result.append(locked)
         for m in rc.waitWithTimeout(0.5):
             yield m
         l.unlock()
     rc.subroutine(routineTrylock('testobj'))
     rc.subroutine(routineTrylock('testobj'))
     self.server.serve()
     self.assertEqual(result, [True, False])
开发者ID:dq5070410,项目名称:vlcp,代码行数:16,代码来源:testLock.py

示例11: testLock2

# 需要导入模块: from vlcp.event.runnable import RoutineContainer [as 别名]
# 或者: from vlcp.event.runnable.RoutineContainer import subroutine [as 别名]
 def testLock2(self):
     rc = RoutineContainer(self.server.scheduler)
     obj = [0]
     def routineLock(key):
         l = Lock(key, rc.scheduler)
         for m in l.lock(rc):
             yield m
         t = obj[0]
         for m in rc.waitWithTimeout(0.5):
             yield m
         obj[0] = t + 1
         l.unlock()
     rc.subroutine(routineLock('testobj'))
     rc.subroutine(routineLock('testobj2'))
     self.server.serve()
     self.assertEqual(obj[0], 1)
开发者ID:dq5070410,项目名称:vlcp,代码行数:18,代码来源:testLock.py

示例12: DHCPServer

# 需要导入模块: from vlcp.event.runnable import RoutineContainer [as 别名]
# 或者: from vlcp.event.runnable.RoutineContainer import subroutine [as 别名]
class DHCPServer(FlowBase):
    "Send ARP respond"
    _tablerequest = (("l3input", ('l2input',), ''),
                     ("l2output", ("l3input",), ''))
    _default_serveraddress = '169.254.169.254'
    _default_servermac = '1a:23:67:59:63:33'
    _default_leasetime = None
    _default_t1 = None
    _default_t2 = None
    def __init__(self, server):
        FlowBase.__init__(self, server)
        self.apiroutine = RoutineContainer(self.scheduler)
        self.apiroutine.main = self._main
        self.routines.append(self.apiroutine)
        self._flowupdaters = {}
        self._extra_arps = {}
    def _main(self):
        flow_init = FlowInitialize.createMatcher(_ismatch = lambda x: self.vhostbind is None or x.vhost in self.vhostbind)
        conn_down = OpenflowConnectionStateEvent.createMatcher(state = OpenflowConnectionStateEvent.CONNECTION_DOWN,
                                                               _ismatch = lambda x: self.vhostbind is None or x.createby.vhost in self.vhostbind)
        while True:
            yield (flow_init, conn_down)
            if self.apiroutine.matcher is flow_init:
                c = self.apiroutine.event.connection
                self.apiroutine.subroutine(self._init_conn(self.apiroutine.event.connection))
            else:
                c = self.apiroutine.event.connection
                self.apiroutine.subroutine(self._remove_conn(c))
    def _init_conn(self, conn):
        # Default
        if conn in self._flowupdaters:
            updater = self._flowupdaters.pop(conn)
            updater.close()
        updater = DHCPUpdater(conn, self)
        #flowupdater = VXLANFlowUpdater(conn, self)
        self._flowupdaters[conn] = updater
        updater.start()
        if False:
            yield
    def _remove_conn(self, conn):
        # Do not need to modify flows
        if conn in self._flowupdaters:
            self._flowupdaters.pop(conn).close()
        if False:
            yield
开发者ID:hubo1016,项目名称:vlcp,代码行数:47,代码来源:dhcpserver.py

示例13: testMultipleClients

# 需要导入模块: from vlcp.event.runnable import RoutineContainer [as 别名]
# 或者: from vlcp.event.runnable.RoutineContainer import subroutine [as 别名]
 def testMultipleClients(self):
     c1 = Client('tcp://localhost:199', self.protocolClient, self.scheduler)
     c2 = Client('tcp://localhost:199', self.protocolClient, self.scheduler)
     s1 = TcpServer('ltcp://localhost:199', self.protocolServer, self.scheduler)
     r = RoutineContainer(self.scheduler, True)
     counter = {c1:0, c2:0}
     ret = bytearray()
     def mainA():
         m = TestDataEvent.createMatcher()
         c1c = False
         c2c = False
         shutdown = False
         while True:
             yield (m,)
             counter[r.event.connection] = counter.get(r.event.connection, 0) + 1
             if r.event.connection is c1:
                 ret.extend(b'A')
                 c1c = True
             elif r.event.connection is c2:
                 ret.extend(b'B')
                 c2c = True
             if c1c and c2c and not shutdown:
                 for m in s1.shutdown():
                     yield m
                 shutdown = True
     r.main = mainA
     r.start()
     s1.start()
     def waitAndStart(c):
         for m in r.waitWithTimeout(0.5):
             yield m
         c.start()
     r.subroutine(waitAndStart(c1))
     r.subroutine(waitAndStart(c2))
     self.scheduler.main()
     print(ret)
     self.assertEqual(counter[c1], 10)
     self.assertEqual(counter[c2], 10)
开发者ID:dq5070410,项目名称:vlcp,代码行数:40,代码来源:testConnection.py

示例14: testSelfConnectionUdp

# 需要导入模块: from vlcp.event.runnable import RoutineContainer [as 别名]
# 或者: from vlcp.event.runnable.RoutineContainer import subroutine [as 别名]
 def testSelfConnectionUdp(self):
     c1 = Client('udp://localhost:199', self.protocolClient, self.scheduler)
     c2 = Client('pudp://localhost:199', self.protocolServer, self.scheduler)
     r = RoutineContainer(self.scheduler, True)
     ret = bytearray()
     def mainA():
         m = TestDataEvent.createMatcher()
         while True:
             yield (m,)
             if r.event.connection is c2:
                 ret.extend(b'A')
             else:
                 ret.extend(b'B')
     r.main = mainA
     r.start()
     def waitAndStart(c):
         for m in r.waitWithTimeout(0.5):
             yield m
         c.start()
     r.subroutine(waitAndStart(c1))
     c2.start()
     self.scheduler.main()
     self.assertEqual(ret, b'ABABABABABABABABABAB')
开发者ID:dq5070410,项目名称:vlcp,代码行数:25,代码来源:testConnection.py

示例15: testTimer

# 需要导入模块: from vlcp.event.runnable import RoutineContainer [as 别名]
# 或者: from vlcp.event.runnable.RoutineContainer import subroutine [as 别名]
 def testTimer(self):
     scheduler = Scheduler()
     rA = RoutineContainer(scheduler)
     output = bytearray()
     def wait(timeout, append):
         for m in rA.waitWithTimeout(timeout):
             yield m
         output.extend(append)
     rA.subroutine(wait(0.1, b'B'))
     rA.subroutine(wait(0.5, b'D'))
     rA.subroutine(wait(0, b'A'))
     rA.subroutine(wait(0.2, b'C'))
     curr_time = time()
     scheduler.main()
     end_time = time()
     self.assertEqual(output, b'ABCD')
     self.assertTrue(0.4 < end_time - curr_time < 0.6)
开发者ID:dq5070410,项目名称:vlcp,代码行数:19,代码来源:testScheduler.py


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