Пример #1
0
        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 "+\
                    str((pkttime-starttime)*1000)+" ms", "ping-controller")
        running = False
    else:
        ofsw.receive_openflow(msg)
        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 "+\
                    str((pkttime-starttime)*1000)+" ms", "ping-controller")
        running = False
    else:
        ofsw.receive_openflow(msg)
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)
ntime=time.time()+(interval/10.0)
swindex = 0
pcount = 0
rcount = 0
while running:
    ctime = time.time()
    time.sleep(max(0,min(ntime-ctime,interval/10.0)))

    if ((ctime-starttime) <= duration):
        #Send packet if time's up
        if (ctime >= ntime):