示例#1
0
def _timer_func():
    """ handler for timer function that sends the requests to all the
        switches connected to the controller.
    """
    log.debug("start check stat")

    for connection in core.openflow._connections.values():

        # FlowStatsReceived
        connection.send(
            of.ofp_stats_request(body=of.ofp_flow_stats_request(), type=of.ofp_stats_types_rev_map.get("OFPST_FLOW"))
        )

        # AggregateFlowStatsReceived
        connection.send(
            of.ofp_stats_request(
                body=of.ofp_aggregate_stats_request(), type=of.ofp_stats_types_rev_map.get("OFPST_AGGREGATE")
            )
        )

        # TableStatsReceived
        # I don't know which methode to call (it's not of.ofp_flow_stats())
        # connection.send(of.ofp_stats_request(body=of.ofp_table_stats()))

        # PortStatsReceived
        connection.send(
            of.ofp_stats_request(
                body=of.ofp_port_stats_request(port_no=of.OFPP_NONE), type=of.ofp_stats_types_rev_map.get("OFPST_PORT")
            )
        )

        # QueueStatsReceived
        body = of.ofp_queue_stats_request(port_no=of.OFPP_NONE, queue_id=of.OFPQ_ALL)
        connection.send(of.ofp_stats_request(body=body, type=of.ofp_stats_types_rev_map.get("OFPST_QUEUE")))
示例#2
0
  def act_like_switch (self, packet, packet_in):
    """
    Implement switch-like behavior.
    """

    srcaddr = EthAddr(packet.src)
    if not self.mac_to_port.has_key(srcaddr):
       self.mac_to_port[srcaddr] = packet_in.in_port

    for key, value in dict.items(self.mac_to_port):
       print key, value
    dstaddr = EthAddr(packet.dst)
    
    #if my_match.dl_dst in mac_t _port:
    if dstaddr in self.mac_to_port:
      # Send packet out the associated port
      out_port = self.mac_to_port[dstaddr]

      match = of.ofp_match()  
      msg = of.ofp_flow_mod() #creates a flow table entry in switc
      #msg.match.dl_src = srcaddr
      #msg.match.dl_dst = dstaddr
      msg.match.tp_dst = out_port

      for con in core.openflow.connections:
	msg2 = of.ofp_queue_stats_request()
        msg2.port_no = out_port
        msg2.queue_id = of.OFPQ_ALL
        con.send(of.ofp_stats_request(body=msg2))
	
      # Add an action to send to the specified port
      action = of.ofp_action_output(port = of.OFPP_CONTROLLER) 
      msg.actions.append(action)
	  
      queue_action = of.ofp_action_enqueue()
      queue_action.port = out_port
      queue_action.queue_id = 1
      msg.actions.append(queue_action)

      print "printing q stats in act like switch\n"
      #global stats1
      #print ("%s",s.stats)
      for f in s.stats:
		print f

      print "\n"

      # Send message to switch
      self.connection.send(msg)


      self.resend_packet(packet_in,out_port)

      
    else:
      # Flood the packet out everything but the input port
      # This part looks familiar, right?
      self.resend_packet (packet_in,of.OFPP_FLOOD)
      print "------flood-------"
示例#3
0
    def _timer_func (self):
        """
        Recurring function to request stats from switches
        for each connection (which represents a switch actually)
        request statistics
        """
        for connection in core.openflow._connections.values():
            # connection.send(of.ofp_stats_request(body=of.ofp_flow_stats_request()))

            connection.send(of.ofp_stats_request(body=of.ofp_port_stats_request()))
            connection.send(of.ofp_stats_request(body=of.ofp_queue_stats_request()))
示例#4
0
def get_switch_queues(switch_dpid):
    """
    Returns per switch a list of all queue stats. This includes:
     - Queue ID
     - Port number
     - Transmitted bytes
     - Transmitted packets
     - Transmitted packets with error
    
    :param switch_dpid: Switch DPID to request in format XX:XX:XX:XX:XX:XX:XX:XX
    :type switch_dpid: str
    :return: List of all queue stats from the requested switch
    :rtype: JSONArray
    :except BaseException: If any error occurs returns an empty list
    """
    try:
        # build openflow message
        bodyMsg = of.ofp_queue_stats_request()
        bodyMsg.port_no = of.OFPP_ALL
        bodyMsg.queue_id = of.OFPQ_ALL
        msg = of.ofp_stats_request(body=bodyMsg)
        msg.type = of.OFPST_QUEUE
        # get and verify stats
        dataArray = []
        stats = get_switch_stats(switch_dpid, msg, "queues")
        if stats == None:
            log.error("Error getting queue stats")
            return json.dumps(dataArray)
        # build and return json data
        for queueStats in stats:
            data = {
                "id": queueStats.queue_id,
                "portNumber": queueStats.port_no,
                "txBytes": queueStats.tx_bytes,
                "txPackets": queueStats.tx_packets,
                "txErrors": queueStats.tx_errors
            }
            dataArray.append(data)
        return json.dumps(dataArray)
    except BaseException, e:
        log.error(e.message)
        dataArray = []
        return json.dumps(dataArray)