Example #1
0
 def main(self):
     conn = Client('tcp://www.baidu.com/', http, self.scheduler)
     conn.start()
     connected = http.statematcher(
         conn, HttpConnectionStateEvent.CLIENT_CONNECTED, False)
     notconnected = http.statematcher(
         conn, HttpConnectionStateEvent.CLIENT_NOTCONNECTED, False)
     yield (connected, notconnected)
     if self.matcher is notconnected:
         print('Connect to server failed.')
     else:
         for m in http.requestwithresponse(self, conn, b'www.baidu.com',
                                           b'/', b'GET', []):
             yield m
         for r in self.http_responses:
             print('Response received:')
             print(r.status)
             print()
             print('Headers:')
             for k, v in r.headers:
                 print('%r: %r' % (k, v))
             print()
             print('Body:')
             if r.stream is None:
                 print('<Empty>')
             else:
                 try:
                     while True:
                         for m in r.stream.read(self, 1024):
                             yield m
                         print(self.data, end='')
                 except EOFError:
                     pass
                 print()
         for m in http.requestwithresponse(self,
                                           conn,
                                           b'www.baidu.com',
                                           b'/favicon.ico',
                                           b'GET', [],
                                           keepalive=False):
             yield m
         for r in self.http_responses:
             print('Response received:')
             print(r.status)
             print()
             print('Headers:')
             for k, v in r.headers:
                 print('%r: %r' % (k, v))
             print()
             print('Body:')
             if r.stream is None:
                 print('<Empty>')
             else:
                 for m in r.stream.read(self):
                     yield m
                 print('<Data: %d bytes>' % (len(self.data), ))
Example #2
0
 def main(self):
     conn = Client('tcp://www.baidu.com/', http, self.scheduler)
     conn.start()
     connected = http.statematcher(conn, HttpConnectionStateEvent.CLIENT_CONNECTED, False)
     notconnected = http.statematcher(conn, HttpConnectionStateEvent.CLIENT_NOTCONNECTED, False)
     yield (connected, notconnected)
     if self.matcher is notconnected:
         print('Connect to server failed.')
     else:
         for m in http.requestwithresponse(self, conn, b'www.baidu.com', b'/', b'GET', []):
             yield m
         for r in self.http_responses:
             print('Response received:')
             print(r.status)
             print()
             print('Headers:')
             for k,v in r.headers:
                 print('%r: %r' % (k,v))
             print()
             print('Body:')
             if r.stream is None:
                 print('<Empty>')
             else:
                 try: 
                     while True:
                         for m in r.stream.read(self, 1024):
                             yield m
                         print(self.data, end = '')
                 except EOFError:
                     pass
                 print()
         for m in http.requestwithresponse(self, conn, b'www.baidu.com', b'/favicon.ico', b'GET', [], keepalive = False):
             yield m
         for r in self.http_responses:
             print('Response received:')
             print(r.status)
             print()
             print('Headers:')
             for k,v in r.headers:
                 print('%r: %r' % (k,v))
             print()
             print('Body:')
             if r.stream is None:
                 print('<Empty>')
             else:
                 for m in r.stream.read(self):
                     yield m
                 print('<Data: %d bytes>' % (len(self.data),))
Example #3
0
 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)
Example #4
0
                table_id = currdef.OFPTT_ALL,
                out_port = currdef.OFPP_NONE,
                match = currdef.ofp_match.new(wildcards=currdef.OFPFW_ALL))
        openflow_reply = await of_proto.querymultipart(req, connection, self)
        for msg in openflow_reply:
            pprint(common.dump(msg, dumpextra = True, typeinfo = common.DUMPTYPE_FLAT, tostr=True))
        req = currdef.nx_flow_stats_request.new(table_id = currdef.OFPTT_ALL, out_port = currdef.OFPP_NONE)
        openflow_reply = await of_proto.querymultipart(req, connection, self)
        for msg in openflow_reply:
            pprint(common.dump(msg, dumpextra = True, typeinfo = common.DUMPTYPE_FLAT, tostr=True))
        req = currdef.ofp_msg.new()
        req.header.type = currdef.OFPT_GET_CONFIG_REQUEST
        openflow_reply = await of_proto.querywithreply(req, connection, self)
        pprint(common.dump(openflow_reply, tostr=True))
        await mgt_conn.shutdown(False)

if __name__ == '__main__':
    logging.basicConfig()
    s = Server()
    #s.scheduler.logger.setLevel(logging.DEBUG)
    #of_proto._logger.setLevel(logging.DEBUG)
    #of_proto.debugging = True
    #NamedStruct._logger.setLevel(logging.DEBUG)
    bridge = sys.argv[1]
    routine = MainRoutine(s.scheduler)
    routine.start()
    mgt_conn = Client('unix:/var/run/openvswitch/' + bridge + '.mgmt', of_proto, s.scheduler)
    mgt_conn.start()
    s.serve()
    
Example #5
0
            yield m
        for msg in self.openflow_reply:
            pprint(common.dump(msg, dumpextra = True, typeinfo = common.DUMPTYPE_FLAT))
        req = currdef.nx_flow_stats_request.new(table_id = currdef.OFPTT_ALL, out_port = currdef.OFPP_NONE)
        for m in of_proto.querymultipart(req, connection, self):
            yield m
        for msg in self.openflow_reply:
            pprint(common.dump(msg, dumpextra = True, typeinfo = common.DUMPTYPE_FLAT))
        req = currdef.ofp_msg.new()
        req.header.type = currdef.OFPT_GET_CONFIG_REQUEST
        for m in of_proto.querywithreply(req, connection, self):
            yield m
        pprint(common.dump(self.openflow_reply))
        for m in mgt_conn.shutdown(False):
            yield m

if __name__ == '__main__':
    logging.basicConfig()
    s = Server()
    #s.scheduler.logger.setLevel(logging.DEBUG)
    #of_proto._logger.setLevel(logging.DEBUG)
    #of_proto.debugging = True
    #NamedStruct._logger.setLevel(logging.DEBUG)
    bridge = sys.argv[1]
    routine = MainRoutine(s.scheduler)
    routine.start()
    mgt_conn = Client('unix:/var/run/openvswitch/' + bridge + '.mgmt', of_proto, s.scheduler)
    mgt_conn.start()
    s.serve()
    
Example #6
0
        ev = await connected
        connection = ev.connection
        result, error = await jsonrpc.querywithreply('list_dbs', [],
                                                     connection, self)
        if error:
            pprint(error)
        else:
            pprint(result)
        dbname = result[0]
        result, error = await jsonrpc.querywithreply('get_schema', [dbname],
                                                     connection, self)
        if error:
            pprint(error)
        else:
            pprint(result)
        await connection.shutdown()


if __name__ == '__main__':
    logging.basicConfig()
    s = Server()
    #s.scheduler.logger.setLevel(logging.DEBUG)
    #JsonRPC.debugging = True
    #JsonRPC._logger.setLevel(logging.DEBUG)
    routine = MainRoutine(s.scheduler)
    routine.start()
    mgt_conn = Client('unix:/var/run/openvswitch/db.sock', jsonrpc,
                      s.scheduler)
    mgt_conn.start()
    s.serve()
Example #7
0
                       '--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()
Example #8
0
 def __init__(self, server):
     Module.__init__(self, server)
     # Should consider to use a subclass of vlcp.service.connection.tcpserver.TcpServerBase
     self.connections.append(Client(self.url, MyProtocol(), self.scheduler))
     self.routines.append(MyClient(self.scheduler))