def __init__(self, messages, controller, port, miss_send_len=128, dpid=None, n_buffers=100, n_tables=1, capability=None, parser=None, connection=None): """Initialize switch """ ofnetwork.switch.__init__(self, miss_send_len, None, dpid, n_buffers, n_tables, capability) ##Name of use for output self.name = self.__class__.__name__ + str(id(self)) ##Reference to OpenFlow messages self.__messages = messages ##Reference to connection self.connection = openflow.tcpsocket(messages, controller, port) self.sock = self.connection.sock ##Reference to Parser self.parser = None if (parser == None): self.parser = ofmsg.parser(messages) else: self.parser = parser
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)
def __init__(self, messages, controller, port, miss_send_len=128, dpid=None, n_buffers=100, n_tables=1, capability=None, parser=None, connection=None): """Initialize switch """ ofnetwork.switch.__init__(self, miss_send_len, None, dpid, n_buffers, n_tables, capability) ##Name of use for output self.name = self.__class__.__name__+str(id(self)) ##Reference to OpenFlow messages self.__messages = messages ##Reference to connection self.connection = openflow.tcpsocket(messages, controller, port) self.sock = self.connection.sock ##Reference to Parser self.parser = None if (parser == None): self.parser = ofmsg.parser(messages) else: self.parser = parser
##Set output mode output.set_mode("INFO") 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):
##Set output mode output.set_mode("INFO") 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)