swno=int(arg) elif (opt in ("-d","--duration")): duration=int(arg) elif (opt in ("-r","--rate")): rate=float(arg) else: print "Unhandled option :"+opt sys.exit(2) #Form packet pkt = dpkt.ethernet.Ethernet() pkt.type = dpkt.ethernet.ETH_MIN pkt.dst = '\xFF\xFF\xFF\xFF\xFF\xFF' #Connect to controller ofmsg = openflow.messages() parser = of.msg.parser(ofmsg) ofnet = of.simu.network() for i in range(1,swno+1): ofsw = of.simu.switch(ofmsg, args[0], port, dpid=i, parser=parser) ofnet.add_switch(ofsw) ofsw.send_hello() output.info("Running "+str(swno)+" switches at "+str(rate)+\ " packets per seconds for "+str(duration)+" s") starttime = time.time() running = True interval = 1.0/(rate*swno)
##Print size printsize = False for opt,arg in opts: if (opt in ("-h","--help")): usage() sys.exit(0) elif (opt in ("-s","--size")): printsize = True elif (opt in ("-c","--cstruct")): printc = True elif (opt in ("-n","--names")): printname = True else: assert (False,"Unhandled option :"+opt) pyopenflow = openflow.messages() cstruct = pyopenflow.structs[args[0].strip()] pattern = pyopenflow.get_pattern(cstruct) #Print C struct if (printc): print cstruct #Print pattern print "Python pattern = "+str(pattern) #Print name if (printname): print cstruct.get_names() #Print size
##Print size printsize = False for opt, arg in opts: if (opt in ("-h", "--help")): usage() sys.exit(0) elif (opt in ("-s", "--size")): printsize = True elif (opt in ("-c", "--cstruct")): printc = True elif (opt in ("-n", "--names")): printname = True else: assert (False, "Unhandled option :" + opt) pyopenflow = openflow.messages() cstruct = pyopenflow.structs[args[0].strip()] pattern = pyopenflow.get_pattern(cstruct) #Print C struct if (printc): print cstruct #Print pattern print "Python pattern = " + str(pattern) #Print name if (printname): print cstruct.get_names() #Print size
if not (len(args) == 1): usage() sys.exit(2) # Parse options ##Input headerfile = None ##Template file templatefile = None for opt, arg in opts: if opt in ("-h", "--help"): usage() sys.exit(0) elif opt in ("-i", "--input"): headerfile = arg elif opt in ("-t", "--template"): templatefile = arg else: print "Unhandled option:" + opt sys.exit(2) # Generate Python code ofmsg = openflow.messages(headerfile) pynizer = of.pythonize.pythonizer(ofmsg) fileRef = open(args[0], "w") for x in pynizer.pycode(templatefile): fileRef.write(x + "\n") fileRef.write("\n") fileRef.close()
port = 6633 ##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