Beispiel #1
0
def ofc2of(msg, buffer, dpid):
    print "ofc->ofconverting"
    if isinstance(msg, ofc.ofp_header):
        if isinstance(msg.payload, ofc.ofp_cflow_mod):
            #self.buffer[(pkt_in_msg.in_port, id)] = [pkt_in_msg.buffer_id, rmsg/pkt_in_msg/pkt_parsed]
            #basic structure: ofp_header()/ofp_cflow_mod()/ofp_connect_wildcards()/ofp_connect()/other_ofp_actions()
            #select info from connect (port info) and actions (just copy)
            #WDM: num_wave -> vlan id
            #OTN: supp_sw_otn_gran->different map function ; bitmap->calculate vlan id
            #ODU0 = 0, ODU1 = 1 ...
            
            # [port + id] --> [buffer_id + pkt_in_msg]
            if (msg.payload.payload.payload.in_port, msg.xid, dpid) not in buffer:
                #Do not change the match and wildcards.
                print "not in the buffer"
                flow_mod = of.ofp_flow_wildcards(OFPFW_NW_TOS=1,
                                                  OFPFW_DL_VLAN_PCP=1,
                                                  OFPFW_NW_DST_MASK=0,
                                                  OFPFW_NW_SRC_MASK=0,
                                                  OFPFW_TP_DST=1,
                                                  OFPFW_TP_SRC=1,
                                                  OFPFW_NW_PROTO=1,
                                                  OFPFW_DL_TYPE=1,
                                                  OFPFW_DL_VLAN=1,
                                                  OFPFW_IN_PORT=1,
                                                  OFPFW_DL_DST=1,
                                                  OFPFW_DL_SRC=1)\
                           /of.ofp_match(in_port=msg.payload.payload.payload.in_port)\
                           /of.ofp_flow_mod(cookie=0,
                                            command=0,
                                            idle_timeout=0,
                                            hard_timeout=0,
                                            out_port=msg.payload.payload.payload.payload.port,
                                            buffer_id=0xffff,
                                            flags=1)
                port = msg.payload.payload.payload.payload.port
                if msg.payload.payload.payload.nport_out:
                    odu = sup2odu[msg.payload.payload.payload.supp_sw_otn_gran_out]
                    vid =  ofc2of_dict_odu[odu](msg.payload.payload.payload.nport_out)
                    print "vid", vid
                    flow_mod_msg = of.ofp_header(type=14,length=104,xid=msg.xid)/flow_mod/of.ofp_action_header(type=0)/of.ofp_action_output(type=0, port=port, len=8)/of.ofp_action_header(type =1)/of.ofp_action_vlan_vid(vlan_vid = vid)
                    return flow_mod_msg 
                elif msg.payload.payload.payload.wport_out:
                    vid =  ofc2of_dict_wave(msg.payload.payload.payload.num_wave_out)
                    print "vid", vid
                    flow_mod_msg = of.ofp_header(type=14,length=104,xid=msg.xid)/flow_mod/of.ofp_action_header(type=0)/of.ofp_action_output(type=0, port=port, len=8)/of.ofp_action_header(type =1)/of.ofp_action_vlan_vid(vlan_vid = vid)
                    return flow_mod_msg 
                else:
                    flow_mod_msg = of.ofp_header(type=14,length=88,xid=msg.xid)/flow_mod/of.ofp_action_header(type=0)/of.ofp_action_output(type=0, port=port, len=8)
                    return flow_mod_msg 
###############################################use the packet_in to send the flow##############################################
            else:
                buffer_id, pkt = buffer[(msg.payload.payload.payload.in_port, msg.xid, dpid)]
                del buffer[(msg.payload.payload.payload.in_port, msg.xid, dpid)]
                pkt_parsed = pkt.payload.payload

#####################################################pkt_parsed is a Ethernet packet############################################
            
                if isinstance(pkt_parsed.payload, of.IP) or isinstance(pkt_parsed.payload.payload, of.IP):
########################################################TCP OR UDP OR SCTP(L4)##################################################
                    if isinstance(pkt_parsed.payload.payload, of.TCP) or isinstance(pkt_parsed.payload.payload, of.UDP) or isinstance(pkt_parsed.payload.payload, of.SCTP) :
                        print "it is TCP or UDP or SCTP packet"
                        if  pkt_parsed.type ==0x8100:
                            print "pkt_parsed.payload.vlan",pkt_parsed.payload.vlan
                            flow_mod =of.ofp_flow_wildcards(OFPFW_NW_TOS=1,
                                                              OFPFW_DL_VLAN_PCP=1,
                                                              OFPFW_NW_DST_MASK=0,
                                                              OFPFW_NW_SRC_MASK=0,
                                                              OFPFW_TP_DST=1,
                                                              OFPFW_TP_SRC=1,
                                                              OFPFW_NW_PROTO=1,
                                                              OFPFW_DL_TYPE=1,
                                                              OFPFW_DL_VLAN=1,
                                                              OFPFW_IN_PORT=1,
                                                              OFPFW_DL_DST=1,
                                                              OFPFW_DL_SRC=1)\
                                       /of.ofp_match(in_port=msg.payload.payload.payload.in_port,
                                                     dl_src=pkt_parsed.src,
                                                     dl_dst=pkt_parsed.dst,
                                                     dl_type=pkt_parsed.type,
                                                     dl_vlan=pkt_parsed.payload.vlan,
                                                     nw_tos=pkt_parsed.payload.tos,
                                                     nw_proto=pkt_parsed.payload.proto,
                                                     nw_src=pkt_parsed.payload.src,
                                                     nw_dst=pkt_parsed.payload.dst,
                                                     tp_src = pkt_parsed.payload.payload.sport,
                                                     tp_dst = pkt_parsed.payload.payload.dport)\
                                       /of.ofp_flow_mod(cookie=0,
                                                        command=0,
                                                        idle_timeout=10,
                                                        hard_timeout=30,
                                                        out_port=msg.payload.payload.payload.payload.port,
                                                        buffer_id=buffer_id,
                                                        flags=1)
                            port = msg.payload.payload.payload.payload.port
                            if msg.payload.payload.payload.nport_out:
                                odu = sup2odu[msg.payload.payload.payload.supp_sw_otn_gran_out]
                                vid =  ofc2of_dict_odu[odu](msg.payload.payload.payload.nport_out)
                                print "vid", vid
                                flow_mod_msg = of.ofp_header(type=14,length=104,xid=pkt.xid)/flow_mod/of.ofp_action_header(type=0)/of.ofp_action_output(type=0, port=port, len=8)/of.ofp_action_header(type =1)/of.ofp_action_vlan_vid(vlan_vid = vid)
                                return flow_mod_msg
                            elif msg.payload.payload.payload.wport_out:
                                vid =  ofc2of_dict_wave(msg.payload.payload.payload.num_wave_out)
                                print "vid", vid
                                flow_mod_msg = of.ofp_header(type=14,length=104,xid=pkt.xid)/flow_mod/of.ofp_action_header(type=0)/of.ofp_action_output(type=0, port=port, len=8)/of.ofp_action_header(type =1)/of.ofp_action_vlan_vid(vlan_vid = vid)
                                return flow_mod_msg
                            else:
                                flow_mod_msg = of.ofp_header(type=14,length=88,xid=pkt.xid)/flow_mod/of.ofp_action_header(type=0)/of.ofp_action_output(type=0, port=port, len=8)
                                return flow_mod_msg
                        else:                                           
                            flow_mod = of.ofp_flow_wildcards(OFPFW_NW_TOS=1,
                                                              OFPFW_DL_VLAN_PCP=1,
                                                              OFPFW_NW_DST_MASK=0,
                                                              OFPFW_NW_SRC_MASK=0,
                                                              OFPFW_TP_DST=1,
                                                              OFPFW_TP_SRC=1,
                                                              OFPFW_NW_PROTO=1,
                                                              OFPFW_DL_TYPE=1,
                                                              OFPFW_DL_VLAN=1,
                                                              OFPFW_IN_PORT=1,
                                                              OFPFW_DL_DST=1,
                                                              OFPFW_DL_SRC=1)\
                                       /of.ofp_match(in_port=msg.payload.payload.payload.in_port,
                                                     dl_src=pkt_parsed.src,
                                                     dl_dst=pkt_parsed.dst,
                                                     dl_type=pkt_parsed.type,
                                                     nw_tos=pkt_parsed.payload.tos,
                                                     nw_proto=pkt_parsed.payload.proto,
                                                     nw_src=pkt_parsed.payload.src,
                                                     nw_dst=pkt_parsed.payload.dst,
                                                     tp_src = pkt_parsed.payload.payload.sport,
                                                     tp_dst = pkt_parsed.payload.payload.dport)\
                                       /of.ofp_flow_mod(cookie=0,
                                                        command=0,
                                                        idle_timeout=10,
                                                        hard_timeout=30,
                                                        out_port=msg.payload.payload.payload.payload.port,
                                                        buffer_id=buffer_id,
                                                        flags=1)
                            port = msg.payload.payload.payload.payload.port
                            if msg.payload.payload.payload.nport_out:
                                odu = sup2odu[msg.payload.payload.payload.supp_sw_otn_gran_out]
                                vid =  ofc2of_dict_odu[odu](msg.payload.payload.payload.nport_out)
                                print "vid", vid
                                flow_mod_msg = of.ofp_header(type=14,length=104,xid=pkt.xid)/flow_mod/of.ofp_action_header(type=0)/of.ofp_action_output(type=0, port=port, len=8)/of.ofp_action_header(type =1)/of.ofp_action_vlan_vid(vlan_vid = vid)
                                return flow_mod_msg                                
                            elif msg.payload.payload.payload.wport_out:
                                vid =  ofc2of_dict_wave(msg.payload.payload.payload.num_wave_out)
                                print "vid", vid
                                flow_mod_msg = of.ofp_header(type=14,length=104,xid=pkt.xid)/flow_mod/of.ofp_action_header(type=0)/of.ofp_action_output(type=0, port=port, len=8)/of.ofp_action_header(type =1)/of.ofp_action_vlan_vid(vlan_vid = vid)
                                return flow_mod_msg
                            else:
                                flow_mod_msg = of.ofp_header(type=14,length=88,xid=pkt.xid)/flow_mod/of.ofp_action_header(type=0)/of.ofp_action_output(type=0, port=port, len=8)
                                return flow_mod_msg
#######################################################IP(L3)##########################################################################
                    else:
                        if  pkt_parsed.type ==0x8100:
                            print "it is just a IP packet "
                            print "pkt_parsed.payload.vlan",pkt_parsed.payload.vlan
                            flow_mod = of.ofp_flow_wildcards(OFPFW_NW_TOS=1,
                                                              OFPFW_DL_VLAN_PCP=1,
                                                              OFPFW_NW_DST_MASK=0,
                                                              OFPFW_NW_SRC_MASK=0,
                                                              OFPFW_TP_DST=1,
                                                              OFPFW_TP_SRC=1,
                                                              OFPFW_NW_PROTO=1,
                                                              OFPFW_DL_TYPE=1,
                                                              OFPFW_DL_VLAN=1,
                                                              OFPFW_IN_PORT=1,
                                                              OFPFW_DL_DST=1,
                                                              OFPFW_DL_SRC=1)\
                                       /of.ofp_match(in_port=msg.payload.payload.payload.in_port,
                                                     dl_src=pkt_parsed.src,
                                                     dl_dst=pkt_parsed.dst,
                                                     dl_type=pkt_parsed.type,
                                                     dl_vlan=pkt_parsed.payload.vlan,
                                                     nw_tos=pkt_parsed.payload.tos,
                                                     nw_proto=pkt_parsed.payload.proto,
                                                     nw_src=pkt_parsed.payload.src,
                                                     nw_dst=pkt_parsed.payload.dst,
                                                     tp_src = 0,
                                                     tp_dst = 0)\
                                       /of.ofp_flow_mod(cookie=0,
                                                        command=0,
                                                        idle_timeout=10,
                                                        hard_timeout=30,
                                                        out_port=msg.payload.payload.payload.payload.port,
                                                        buffer_id=buffer_id,
                                                        flags=1)
                            port = msg.payload.payload.payload.payload.port
                            if msg.payload.payload.payload.nport_out:
                                odu = sup2odu[msg.payload.payload.payload.supp_sw_otn_gran_out]
                                vid =  ofc2of_dict_odu[odu](msg.payload.payload.payload.nport_out)
                                print "vid", vid
                                flow_mod_msg = of.ofp_header(type=14,length=104,xid=pkt.xid)/flow_mod/of.ofp_action_header(type=0)/of.ofp_action_output(type=0, port=port, len=8)/of.ofp_action_header(type =1)/of.ofp_action_vlan_vid(vlan_vid = vid)
                                return flow_mod_msg
                            elif msg.payload.payload.payload.wport_out:
                                vid =  ofc2of_dict_wave(msg.payload.payload.payload.num_wave_out)
                                print "vid", vid
                                flow_mod_msg = of.ofp_header(type=14,length=104,xid=pkt.xid)/flow_mod/of.ofp_action_header(type=0)/of.ofp_action_output(type=0, port=port, len=8)/of.ofp_action_header(type =1)/of.ofp_action_vlan_vid(vlan_vid = vid)
                                return flow_mod_msg
                            else:
                                flow_mod_msg = of.ofp_header(type=14,length=88,xid=pkt.xid)/flow_mod/of.ofp_action_header(type=0)/of.ofp_action_output(type=0, port=port, len=8)
                                return flow_mod_msg
                        else:                                           
                            flow_mod = of.ofp_flow_wildcards(OFPFW_NW_TOS=1,
                                                              OFPFW_DL_VLAN_PCP=1,
                                                              OFPFW_NW_DST_MASK=0,
                                                              OFPFW_NW_SRC_MASK=0,
                                                              OFPFW_TP_DST=1,
                                                              OFPFW_TP_SRC=1,
                                                              OFPFW_NW_PROTO=1,
                                                              OFPFW_DL_TYPE=1,
                                                              OFPFW_DL_VLAN=1,
                                                              OFPFW_IN_PORT=0,
                                                              OFPFW_DL_DST=1,
                                                              OFPFW_DL_SRC=1)\
                                       /of.ofp_match(in_port=msg.payload.payload.payload.in_port,
                                                     dl_src=pkt_parsed.src,
                                                     dl_dst=pkt_parsed.dst,
                                                     dl_type=pkt_parsed.type,
                                                     nw_tos=pkt_parsed.payload.tos,
                                                     nw_proto=pkt_parsed.payload.proto,
                                                     nw_src=pkt_parsed.payload.src,
                                                     nw_dst=pkt_parsed.payload.dst,
                                                     tp_src = 0,
                                                     tp_dst = 0)\
                                       /of.ofp_flow_mod(cookie=0,
                                                        command=0,
                                                        idle_timeout=10,
                                                        hard_timeout=30,
                                                        out_port=msg.payload.payload.payload.payload.port,
                                                        buffer_id=buffer_id,
                                                        flags=1)
                            port = msg.payload.payload.payload.payload.port
                            if msg.payload.payload.payload.nport_out:
                                odu = sup2odu[msg.payload.payload.payload.supp_sw_otn_gran_out]
                                vid =  ofc2of_dict_odu[odu](msg.payload.payload.payload.nport_out)
                                print "vid", vid
                                flow_mod_msg = of.ofp_header(type=14,length=104,xid=pkt.xid)/flow_mod/of.ofp_action_header(type=0)/of.ofp_action_output(type=0, port=port, len=8)/of.ofp_action_header(type =1)/of.ofp_action_vlan_vid(vlan_vid = vid)
                                return flow_mod_msg
                            elif msg.payload.payload.payload.wport_out:
                                vid =  ofc2of_dict_wave(msg.payload.payload.payload.num_wave_out)
                                print "vid", vid
                                flow_mod_msg = of.ofp_header(type=14,length=104,xid=pkt.xid)/flow_mod/of.ofp_action_header(type=0)/of.ofp_action_output(type=0, port=port, len=8)/of.ofp_action_header(type =1)/of.ofp_action_vlan_vid(vlan_vid = vid)
                                return flow_mod_msg
                            else:
                                flow_mod_msg = of.ofp_header(type=14,length=88,xid=pkt.xid)/flow_mod/of.ofp_action_header(type=0)/of.ofp_action_output(type=0, port=port, len=8)
                                return flow_mod_msg
Beispiel #2
0
    def controller_handler(self, address, fd, events):
        if events & io_loop.READ:
            data = self.sock_con.recv(1024)
            if data == '':
                print "controller disconnected"
                io_loop.remove_handler(self.fd_con)
                print "closing connection to switch"
                self.sock_sw.close()
                io_loop.remove_handler(self.fd_sw)
            else:
                rmsg = of.ofp_header(data[0:8])
                # Here, we can manipulate OpenFlow packets from CONTROLLER.
                if rmsg.type == 0xff:  #cflow_mod
                    header = ofc.ofp_header(data[0:8])

                    cflow_mod = ofc.ofp_cflow_mod(data[8:16])
                    cflow_connect_wildcards = ofc.ofp_connect_wildcards(
                        data[16:18])
                    cflow_connect = ofc.ofp_connect(data[18:92])
                    ofp_action_output = ofc.ofp_action_output(data[92:])

                    msg = header / cflow_mod / cflow_connect_wildcards / cflow_connect / ofp_action_output
                    msg.show()
                    data = convert.ofc2of(msg, self.buffer, self.dpid)

                    self.flow_cache.append([time.time(), data])

                elif rmsg.type == 14:
                    print "send flow_mod"
                    #header = of.ofp_header(data[0:8])
                    #wildcards=of.ofp_flow_wildcards(data[8:12])
                    #match=of.ofp_match(data[12:48])
                    #flow_mod =of.ofp_flow_mod(data[48:72])
                    #action_header = of.ofp_action_header(data[72:80])
                    #action_output =of.ofp_action_output(data[80:88])
                    #data1 =header/wildcards/match/flow_mod/action_header/action_output
                    #self.flow_cache.append([time.time(),data1])
                #full message for flow status request: ofp_stats_rqeuest()/ofp_flow_wildcards()/ofp_match()/ofp_flow_stats_request()
                elif rmsg.type == 16 and 0:  #do nothing and send it .
                    header = ofc.ofp_header(data[0:8])
                    ofp_stats_request = ofc.ofp_stats_request(data[8:12])
                    if ofp_stats_request.type == 1:
                        ofp_flow_wildcards = ofc.ofp_flow_wildcards(
                            data[12:16])
                        data_match = ofc.ofp_match(data[16:52])
                        ofp_flow_stats_request = ofc.ofp_flow_stats_request(
                            data[52:56])
                        for f in self.flow_cache:
                            flow = str(f[1])
                            ofp_flow_wildcards = ofc.ofp_flow_wildcards(
                                flow[8:12])
                            ofp_flow_match = ofc.ofp_match(flow[12:48])
                            ofp_flow_stats_request.out_put = of.ofp_action_output(
                                flow[80:88]).port
                            data = ofc.ofp_header(
                                type=16, length=56
                            ) / ofp_stats_request / ofp_flow_wildcards / ofp_flow_match / ofp_flow_stats_request

                            #we try to delete the flow by this code.
                            #data = of.ofp_header(type=14,length=88)/ofp_flow_wildcards/ofp_flow_match/of.ofp_flow_mod(command=3,flags=1)
                            #print 'delete matching flow'

                            io_loop.update_handler(self.fd_sw, io_loop.WRITE)
                            self.queue_sw.put(
                                str(data)
                            )  #put it into the queue of packet which need to send to Switch.
                    elif ofp_stats_request.type == 0:
                        print "send the ofp_stats_request(type = 0)"
                    elif ofp_stats_request.type == 2:
                        print "aggregate request"
                        ofp_flow_wildcards = ofc.ofp_flow_wildcards(
                            data[12:16])
                        data_match = ofc.ofp_match(data[16:52])
                        ofp_aggregate_stats_request = ofc.ofp_aggregate_stats_request(
                            data[52:56])
                        flow = str(self.flow_cache)
                        wildcards = ofc.ofp_flow_wildcards(flow[8:12])
                        match = ofc.ofp_match(flow[12:48])

                        data = header / ofp_stats_request / wildcards / match / ofp_aggregate_stats_request
                    elif ofp_stats_request.type == 3:
                        print "table request"
                    elif ofp_stats_request.type == 4:
                        print "port request"
                    elif ofp_stats_request.type == 5:
                        print "queue request"
                    elif ofp_stats_request.type == 0xffff:
                        print "vendor request"
                #There are no need to change other packets,just send them!
                io_loop.update_handler(self.fd_sw, io_loop.WRITE)
                self.queue_sw.put(str(data))

        if events & io_loop.WRITE:
            try:
                next_msg = self.queue_con.get_nowait()
            except Queue.Empty:
                io_loop.update_handler(self.fd_con, io_loop.READ)
            else:
                self.sock_con.send(next_msg)
#####################delete the flow cache by hard_timeout###################
        for f in self.flow_cache:
            if fresh(f):
                self.flow_cache.remove(f)
Beispiel #3
0
    def controller_handler(self, address, fd, events):
        if events & io_loop.READ:
            data = self.sock_con.recv(1024)
            if data == '':
                print "controller disconnected"
                io_loop.remove_handler(self.fd_con)
                print "closing connection to switch"
                self.sock_sw.close()
                io_loop.remove_handler(self.fd_sw)
            else:
                rmsg = of.ofp_header(data[0:8])
                # Here, we can manipulate OpenFlow packets from CONTROLLER.
                if rmsg.type == 0xff:                           #cflow_mod   
                    header = ofc.ofp_header(data[0:8])
                    
                    cflow_mod = ofc.ofp_cflow_mod(data[8:16])
                    cflow_connect_wildcards = ofc.ofp_connect_wildcards(data[16:18])
                    cflow_connect = ofc.ofp_connect(data[18:92])
                    ofp_action_output= ofc.ofp_action_output(data[92:])

                    msg = header/cflow_mod/cflow_connect_wildcards/cflow_connect/ofp_action_output
                    msg.show()
                    data = convert.ofc2of(msg, self.buffer, self.dpid) 
                    
                    self.flow_cache.append([time.time(),data])

                elif rmsg.type == 14:
                    print "send flow_mod"
                    #header = of.ofp_header(data[0:8])
                    #wildcards=of.ofp_flow_wildcards(data[8:12])
                    #match=of.ofp_match(data[12:48])
                    #flow_mod =of.ofp_flow_mod(data[48:72])
                    #action_header = of.ofp_action_header(data[72:80])
                    #action_output =of.ofp_action_output(data[80:88])
                    #data1 =header/wildcards/match/flow_mod/action_header/action_output
                    #self.flow_cache.append([time.time(),data1])
                #full message for flow status request: ofp_stats_rqeuest()/ofp_flow_wildcards()/ofp_match()/ofp_flow_stats_request()
                elif rmsg.type == 16 and 0: #do nothing and send it .
                    header = ofc.ofp_header(data[0:8])
                    ofp_stats_request = ofc.ofp_stats_request(data[8:12])
                    if ofp_stats_request.type == 1:
                        ofp_flow_wildcards = ofc.ofp_flow_wildcards(data[12:16])
                        data_match = ofc.ofp_match(data[16:52])
                        ofp_flow_stats_request = ofc.ofp_flow_stats_request(data[52:56])
                        for f in self.flow_cache:
                            flow = str(f[1])
                            ofp_flow_wildcards = ofc.ofp_flow_wildcards(flow[8:12])
                            ofp_flow_match = ofc.ofp_match(flow[12:48])
                            ofp_flow_stats_request.out_put = of.ofp_action_output(flow[80:88]).port
                            data = ofc.ofp_header(type = 16, length = 56)/ofp_stats_request/ofp_flow_wildcards/ofp_flow_match/ofp_flow_stats_request

                            #we try to delete the flow by this code.
                            #data = of.ofp_header(type=14,length=88)/ofp_flow_wildcards/ofp_flow_match/of.ofp_flow_mod(command=3,flags=1)
                            #print 'delete matching flow'

                            io_loop.update_handler(self.fd_sw, io_loop.WRITE)
                            self.queue_sw.put(str(data))#put it into the queue of packet which need to send to Switch.  
                    elif ofp_stats_request.type == 0:
                        print "send the ofp_stats_request(type = 0)"
                    elif ofp_stats_request.type ==2:
                        print "aggregate request"
                        ofp_flow_wildcards = ofc.ofp_flow_wildcards(data[12:16])
                        data_match = ofc.ofp_match(data[16:52])
                        ofp_aggregate_stats_request = ofc.ofp_aggregate_stats_request(data[52:56])
                        flow =  str(self.flow_cache)
                        wildcards = ofc.ofp_flow_wildcards(flow[8:12])
                        match = ofc.ofp_match(flow[12:48])

                        data = header/ofp_stats_request/wildcards/match/ofp_aggregate_stats_request
                    elif ofp_stats_request.type ==3:
                        print "table request"
                    elif ofp_stats_request.type ==4:
                        print "port request"
                    elif ofp_stats_request.type ==5:
                        print "queue request" 
                    elif ofp_stats_request.type ==0xffff:
                        print "vendor request"
                #There are no need to change other packets,just send them!
                io_loop.update_handler(self.fd_sw, io_loop.WRITE)
                self.queue_sw.put(str(data))
    
        if events & io_loop.WRITE:
            try:
                next_msg = self.queue_con.get_nowait()
            except Queue.Empty:
                io_loop.update_handler(self.fd_con, io_loop.READ)
            else:
                self.sock_con.send(next_msg)
#####################delete the flow cache by hard_timeout###################
        for f in self.flow_cache:
            if fresh(f):
                self.flow_cache.remove(f)