Exemple #1
0
 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)
Exemple #2
0
    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)
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 = ofpythonize.pythonizer(ofmsg)

fileRef = open(args[0], "w")
for x in pynizer.pycode(templatefile):
    fileRef.write(x + "\n")
fileRef.write("\n")
fileRef.close()
Exemple #4
0
ctemplatefile="include/openflow-pack.template.cc"
for opt,arg in opts:
    if (opt in ("-h","--help")):
        usage()
        sys.exit(0)
    elif (opt in ("-i","--input")):
        headerfile=arg
    elif (opt in ("-x","--codetemplate")):
        ctemplatefile=arg
    elif (opt in ("-t","--headertemplate")):
        htemplatefile=arg
    else:
        print "Unhandled option:"+opt
        sys.exit(2)

#Generate Python code
ofmsg = openflow.messages(headerfile)
cppizer = ofppize.cppizer(ofmsg)

hfileRef = open(args[0]+".hh", "w")
cfileRef = open(args[0]+".cc", "w")
for x in cppizer.hcode(args[0], htemplatefile):
    hfileRef.write(x+"\n")
for x in cppizer.ccode(ctemplatefile, None,
                       ["#include \""+args[0]+".hh\""]):
    cfileRef.write(x+"\n")
hfileRef.write("\n")
cfileRef.write("\n")
cfileRef.close()
hfileRef.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
Exemple #6
0
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()
##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