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), ))
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),))
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()
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()