def connectToController(self): #Connect to controller ofmsg = openflow.messages() ofparser = of_msg.parser(ofmsg) ofsw = of_simu.switch(ofmsg, self.controller, self.port, dpid=self.CONTROLLER_DPID, parser=ofparser) ofsw.send_hello() while self.running: msg = ofsw.connection.msgreceive(blocking=False) # OF to GUI if msg != None: ofsw.receive_openflow(msg) self.queue_OF_to_GUI.put(msg) # GUI to OF while not self.queue_GUI_to_OF.empty(): packet = self.queue_GUI_to_OF.get() ofsw.send_packet(inport=0, packet=packet) time.sleep(0.1)
for opt,arg in opts: if (opt in ("-h","--help")): usage() sys.exit(0) elif (opt in ("-v","--verbose")): output.set_mode("DBG") elif (opt in ("-p","--port")): port=int(arg) else: assert False,"Unhandled option :"+opt #Connect to controller ofmsg = openflow.messages() parser = of_msg.parser(ofmsg) ofsw = of_simu.switch(ofmsg, args[0], port, dpid=int("0xcafecafe",16), parser=parser) ofsw.send_hello() #Send echo and wait xid = 22092009 running = True ofsw.send_echo(xid) starttime = time.time() while running: msg = ofsw.connection.msgreceive(True, 0.00001) pkttime = time.time() dic = ofmsg.peek_from_front("ofp_header", msg) if (dic["type"][0] == ofmsg.get_value("OFPT_ECHO_REPLY") and dic["xid"][0] == xid): #Check reply for echo request output.info("Received echo reply after "+\
if (opt in ("-h", "--help")): usage() sys.exit(0) elif (opt in ("-v", "--verbose")): output.set_mode("DBG") elif (opt in ("-p", "--port")): port = int(arg) else: assert False, "Unhandled option :" + opt #Connect to controller ofmsg = openflow.messages() parser = of_msg.parser(ofmsg) ofsw = of_simu.switch(ofmsg, args[0], port, dpid=int("0xcafecafe", 16), parser=parser) ofsw.send_hello() #Send echo and wait xid = 22092009 running = True ofsw.send_echo(xid) starttime = time.time() while running: msg = ofsw.connection.msgreceive(True, 0.00001) pkttime = time.time() dic = ofmsg.peek_from_front("ofp_header", msg) if (dic["type"][0] == ofmsg.get_value("OFPT_ECHO_REPLY") and dic["xid"][0] == xid): #Check reply for echo request