コード例 #1
0
ファイル: server.py プロジェクト: sinofeng/vlcp
 def __init__(self, server):
     Module.__init__(self, server)
     # Should consider to use a subclass of vlcp.service.connection.tcpserver.TcpServerBase
     self.connections.append(
         TcpServer(self.url, MyProtocol(), self.scheduler))
     self.routines.append(MyServer(self.scheduler))
コード例 #2
0
ファイル: testhttpserver.py プロジェクト: sinofeng/vlcp
            return (tmpl % params)

    async def handlehttp(self, event):
        if event.stream is not None:
            event.stream.close(self.scheduler)
        if event.connmark == event.connection.connmark and event.connection.connected:
            #outputstream = Stream()
            document = self.formatstr(
                self.document, (escape_b(event.host), escape_b(
                    event.path), escape(repr(event.headers)).encode('utf-8')))
            outputstream = MemoryStream(document)
            http.startResponse(event.connection, event.xid, b'200 OK', [],
                               outputstream)
            #for m in outputstream.write(self.document, self, True):
            #yield m


if __name__ == '__main__':
    logging.basicConfig()
    s = Server()
    #s.scheduler.debugging = True
    #s.scheduler.logger.setLevel(logging.DEBUG)
    #Http.debugging = True
    #Http._logger.setLevel(logging.DEBUG)
    http.createmessagequeue(s.scheduler)
    routine = MainRoutine(s.scheduler)
    routine.start()
    mgt_conn = TcpServer('ltcp://0.0.0.0:8080/', http, s.scheduler)
    mgt_conn.start()
    s.serve()
コード例 #3
0
ファイル: testio.py プロジェクト: vtanrun/vlcp
                       '--parallel',
                       type=int,
                       help='When in client mode, start multiple clients',
                       metavar='NUM',
                       default=1)
    args = parse.parse_args()
    s = Server()
    if args.server and args.client:
        print('Cannot specify both --server and --client')
        sys.exit(1)
    elif not args.server and not args.client:
        print('Must specify either --server or --client')
        sys.exit(1)
    elif args.server:
        tp = TcpTestProtocol(True)
        conn = TcpServer('tcp://%s:%d/' % (args.bind, args.port), tp,
                         s.scheduler)
        sampler = Sampler(s.scheduler, args.interval, True)
        conn.start()
        sampler.start()
    else:
        tp = TcpTestProtocol(False)
        tp.totalsend = args.time
        sampler = Sampler(s.scheduler, args.interval, False)
        for _ in range(0, args.parallel):
            conn = Client('tcp://%s:%d/' % (args.client, args.port), tp,
                          s.scheduler)
            conn.start()
        sampler.start()
    s.serve()
コード例 #4
0
ファイル: testhttpserver.py プロジェクト: dq5070410/vlcp
            return (tmpl % tuple(v.decode('utf-8') for v in params)).encode('utf-8')
        else:
            return (tmpl % params)
    def handlehttp(self, event):
        if event.stream is not None:
            event.stream.close(self.scheduler)
        if event.connmark == event.connection.connmark and event.connection.connected:
            #outputstream = Stream()
            document = self.formatstr(self.document, (escape_b(event.host), escape_b(event.path), escape(repr(event.headers)).encode('utf-8')))
            outputstream = MemoryStream(document)
            http.startResponse(event.connection, event.xid, b'200 OK', [], outputstream)
            #for m in outputstream.write(self.document, self, True):
                #yield m
            if False:
                yield

if __name__ == '__main__':
    logging.basicConfig()
    s = Server()
    #s.scheduler.debugging = True
    #s.scheduler.logger.setLevel(logging.DEBUG)
    #Http.debugging = True
    #Http._logger.setLevel(logging.DEBUG)
    http.createmessagequeue(s.scheduler)
    routine = MainRoutine(s.scheduler)
    routine.start()
    mgt_conn = TcpServer('ltcp://0.0.0.0:8080/', http, s.scheduler)
    mgt_conn.start()
    s.serve()
    
コード例 #5
0
ファイル: testio.py プロジェクト: dq5070410/vlcp
    parse.add_argument('-s', '--server', action='store_true', help='Start in server mode')
    parse.add_argument('-c', '--client', help='Start in client mode and connect to IP', metavar='IP')
    parse.add_argument('-i', '--interval', type=float, help='Display bandwidth in interval', default = 10.0)
    parse.add_argument('-t', '--time', type=float, help='Run specified time', default = 10.0)
    parse.add_argument('-B', '--bind', help='When in server mode, bind to specified address', default='0.0.0.0')
    parse.add_argument('-p', '--port', type=int, help='When in server mode, bind to specified port (default 5987)', default=5987)
    parse.add_argument('-P', '--parallel', type=int, help='When in client mode, start multiple clients', metavar = 'NUM', default=1)
    args = parse.parse_args()
    s = Server()
    if args.server and args.client:
        print('Cannot specify both --server and --client')
        sys.exit(1)
    elif not args.server and not args.client:
        print('Must specify either --server or --client')
        sys.exit(1)
    elif args.server:
        tp = TcpTestProtocol(True)
        conn = TcpServer('tcp://%s:%d/' % (args.bind, args.port), tp, s.scheduler)
        sampler = Sampler(s.scheduler, args.interval, True)
        conn.start()
        sampler.start()
    else:
        tp = TcpTestProtocol(False)
        tp.totalsend = args.time
        sampler = Sampler(s.scheduler, args.interval, False)
        for _ in range(0, args.parallel):
            conn = Client('tcp://%s:%d/' % (args.client, args.port), tp, s.scheduler)
            conn.start()
        sampler.start()
    s.serve()
コード例 #6
0
    def main(self):
        while True:

            connectEventMatcher = OpenflowConnectionStateEvent.createMatcher()
            yield (connectEventMatcher,)
           
            # here event must be connect event
            self.connectStateHandler(self.event)

if __name__ == '__main__':

   
    #logging.basicConfig(format='%(asctime)s-%(name)s-%(levelname)s : %(message)s',level=logging.DEBUG)
    logging.basicConfig(format='%(asctime)s-%(name)s-%(levelname)s : %(message)s')
    log = logging.getLogger('l2switch')
    log.setLevel(logging.DEBUG)

    of_proto.debuging = True
    
    #manager['server.debugging']=True
    loopServer = Server()
    loopServer.scheduler.logger.setLevel(logging.DEBUG)

    tcpServer = TcpServer("tcp://127.0.0.1",of_proto,loopServer.scheduler)
    tcpServer.start()
    
    switch = l2switch(loopServer.scheduler)
    switch.start()

    loopServer.serve()