Beispiel #1
0
def _timer_func ():
  global start_time, sent_time1, sent_time2, src_dpid, dst_dpid
 
  if src_dpid <>0:
    sent_time1=time.time() * 1000 - start_time
    #print "sent_time1:", sent_time1
    #send out port_stats_request packet through src_dpid
    core.openflow.getConnection(src_dpid).send(of.ofp_stats_request(body=of.ofp_port_stats_request()))
   
    f = myproto()
    f.timestamp = int(time.time()*1000 - start_time)
    #print f.timestamp
    e = pkt.ethernet()
    e.src=EthAddr("0:0:0:0:0:2")
    e.dst=EthAddr("0:1:0:0:0:1")
    e.type=0x5577
    e.payload = f
    msg = of.ofp_packet_out()
    msg.data = e.pack()
    msg.actions.append(of.ofp_action_output(port=2))
    core.openflow.getConnection(src_dpid).send(msg)
   
  if dst_dpid <>0:
     sent_time2=time.time() * 1000 - start_time
     #print "sent_time2:", sent_time2
     #send out port_stats_request packet through dst_dpid
     core.openflow.getConnection(dst_dpid).send(of.ofp_stats_request(body=of.ofp_port_stats_request()))
Beispiel #2
0
def _timer_func():
    global s1_dpid, s2_dpid, s3_dpid, s4_dpid, turn

    core.openflow.getConnection(s1_dpid).send(of.ofp_stats_request(body = of.ofp_port_stats_request()))
    core.openflow.getConnection(s2_dpid).send(of.ofp_stats_request(body = of.ofp_port_stats_request()))
    core.openflow.getConnection(s3_dpid).send(of.ofp_stats_request(body = of.ofp_port_stats_request()))


    if turn == 0:
        msg = of.ofp_flow_mod()
        msg.command = of.OFPFC_MODIFY_STRICT
        msg.priority = 100
        msg.idle_timeout = 0
        msg.hard_timeout = 0
        msg.match.in_port = 1
        msg.match.dl_type = 0x0800
        msg.match.nw_dst = "10.0.0.2"
        msg.actions.append(of.ofp_action_output(port = 3))
        core.openflow.getConnection(s1_dpid).send(msg)
        turn = 1

        msg = of.ofp_flow_mod()
        msg.command = of.OFPFC_MODIFY_STRICT
        msg.priority = 100
        msg.idle_timeout = 0
        msg.hard_timeout = 0
        msg.match.in_port = 1
        msg.match.dl_type = 0x0806
        msg.match.nw_dst = "10.0.0.2"
        msg.actions.append(of.ofp_action_output(port = 3))
        core.openflow.getConnection(s1_dpid).send(msg)
        turn = 1
        return

    if turn == 1:
        msg = of.ofp_flow_mod()
        msg.command = of.OFPFC_MODIFY_STRICT
        msg.priority = 100
        msg.idle_timeout = 0
        msg.hard_timeout = 0
        msg.match.in_port = 1
        msg.match.dl_type = 0x0800
        msg.match.nw_dst = "10.0.0.2"
        msg.actions.append(of.ofp_action_output(port = 2))
        core.openflow.getConnection(s1_dpid).send(msg)
        turn = 0

        msg = of.ofp_flow_mod()
        msg.command = of.OFPFC_MODIFY_STRICT
        msg.priority = 100
        msg.idle_timeout = 0
        msg.hard_timeout = 0
        msg.match.in_port = 1
        msg.match.dl_type = 0x0806
        msg.match.nw_dst = "10.0.0.2"
        msg.actions.append(of.ofp_action_output(port = 2))
        core.openflow.getConnection(s1_dpid).send(msg)
        turn = 0
        return
def requestForUpdateCost():
  global middleBoxProcess
  for con in core.openflow._connections.values():
    nodeName = str(con).split("-")[-1].split(" ")[0]
    for i in range(16 - len(nodeName)):
      nodeName = "0" + nodeName

    if (nodeName in middleBoxProcess.keys()):  # just for middelBoxes
      con.send(of.ofp_stats_request(body=of.ofp_port_stats_request()))
    if (nodeName == "0000000000000002" or nodeName == "0000000000000001"):  # for sw2
      con.send(of.ofp_stats_request(body=of.ofp_port_stats_request()))
Beispiel #4
0
def _timer_func():
    global s1_dpid, s2_dpid, s3_dpid, s4_dpid, s5_dpid, turn
    core.openflow.getConnection(s1_dpid).send(
        of.ofp_stats_request(body=of.ofp_port_stats_request()))
    core.openflow.getConnection(s2_dpid).send(
        of.ofp_stats_request(body=of.ofp_port_stats_request()))
    core.openflow.getConnection(s3_dpid).send(
        of.ofp_stats_request(body=of.ofp_port_stats_request()))
    core.openflow.getConnection(s4_dpid).send(
        of.ofp_stats_request(body=of.ofp_port_stats_request()))
    #print getTheTime(), "sent the port stats request to s1_dpid"

    if turn == 0:
        msg = of.ofp_flow_mod()
        msg.command = of.OFPFC_MODIFY_STRICT
        msg.priority = 100
        msg.idle_timeout = 0
        msg.hard_timeout = 0
        msg.match.dl_type = 0x0800
        msg.match.nw_dst = "10.0.0.4"
        msg.actions.append(of.ofp_action_output(port=5))
        core.openflow.getConnection(s1_dpid).send(msg)
        turn = 1
        return

    if turn == 1:
        msg = of.ofp_flow_mod()
        msg.command = of.OFPFC_MODIFY_STRICT
        msg.priority = 100
        msg.idle_timeout = 0
        msg.hard_timeout = 0
        msg.match.dl_type = 0x0800
        msg.match.nw_dst = "10.0.0.4"
        msg.actions.append(of.ofp_action_output(port=6))
        core.openflow.getConnection(s1_dpid).send(msg)
        turn = 2
        return

    if turn == 2:
        msg = of.ofp_flow_mod()
        msg.command = of.OFPFC_MODIFY_STRICT
        msg.priority = 100
        msg.idle_timeout = 0
        msg.hard_timeout = 0
        msg.match.dl_type = 0x0800
        msg.match.nw_dst = "10.0.0.4"
        msg.actions.append(of.ofp_action_output(port=4))
        core.openflow.getConnection(s1_dpid).send(msg)
        turn = 0
        return
def _request_stats():
    log.debug('Number of connections: {}'.format(len(core.openflow.connections)))
    log.info('Sending stats requests')
    for connection in core.openflow.connections:
        log.debug("Sending stats request")
        #connection.send(of.ofp_stats_request(body=of.ofp_flow_stats_request()))
        connection.send(of.ofp_stats_request(body=of.ofp_port_stats_request()))
Beispiel #6
0
def global_stats():
    _init()
    log.info("Sending port stats req to all {0} switches".format(num_sw))
    for con in core.openflow.connections:
        handler[con.dpid] = con.addListenerByName("PortStatsReceived", _stats_listener)
        con.send(of.ofp_stats_request(body=of.ofp_port_stats_request()))
    Timer(wait_timeout, _check)
Beispiel #7
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")))
Beispiel #8
0
    def _change_port(self, dpid, port_no, down):
        con = core.openflow.getConnection(dpid)
        p = con.ports[port_no]
        log.info('%s' % con.ports)
        if down:
            s = 'down'
        else:
            s = 'up'
        log.info('change_port( dpid:%s, port_no:%s, dir:%s )' %
                 (dpid, port_no, s))

        new_state = down * of.OFPPC_PORT_DOWN
        new_state = of.OFPPC_PORT_DOWN \
            | of.OFPPC_NO_STP \
            | of.OFPPC_NO_RECV \
            | of.OFPPC_NO_RECV_STP \
            | of.OFPPC_NO_FLOOD \
            | of.OFPPC_NO_FWD \
            | of.OFPPC_NO_PACKET_IN
        log.info('change_port: new_state: %d %s ' % (new_state, con.info))

        pm = of.ofp_port_mod(port_no=p.port_no,
                             hw_addr=p.hw_addr,
                             config=new_state,
                             mask=new_state)  # of.OFPPC_PORT_DOWN )
        con.send(pm)

        body = of.ofp_port_stats_request()
        body.port_no = of.OFPP_NONE  # request all port statics
        msg = of.ofp_stats_request(body=body)
        con.send(msg.pack())
Beispiel #9
0
        def RoundRobin():
            pathRead = {}
            for p in monitored_paths:
                pathRead[p] = False

            for p in monitored_paths:  #Walk through all distinct paths, not even flows
                if pathRead[p] != True:

                    if p not in pathIterator or pathIterator[
                            p] == p.src:  # Round Robin switch selection
                        pathIterator[p] = p.dst
                    else:
                        pathIterator[p] = p.prev[pathIterator[p]]

                    curSwitch = pathIterator[p]

                    #log.debug("Sending message to switch %s", util.dpid_to_str(curSwitch))
                    msg = of.ofp_stats_request(
                        body=of.ofp_flow_stats_request())
                    switches[curSwitch].connection.send(msg)
                    msg2 = of.ofp_stats_request(
                        body=of.ofp_port_stats_request())
                    switches[curSwitch].connection.send(msg2)
                    for pPrime in monitored_pathsBySwitch[
                            curSwitch]:  #Circumvent polling multiple switches for paths from whom the stats have already been requested
                        pathRead[pPrime] = True
  def _change_port (self, dpid, port_no, down):
    con = core.openflow.getConnection(dpid)
    p = con.ports[port_no]
    log.info('%s' % con.ports)
    if down:
      s = 'down'
    else:
      s = 'up'
    log.info('change_port( dpid:%s, port_no:%s, dir:%s )' % (dpid, port_no, s))

    new_state = down * of.OFPPC_PORT_DOWN
    new_state = of.OFPPC_PORT_DOWN \
        | of.OFPPC_NO_STP \
        | of.OFPPC_NO_RECV \
        | of.OFPPC_NO_RECV_STP \
        | of.OFPPC_NO_FLOOD \
        | of.OFPPC_NO_FWD \
        | of.OFPPC_NO_PACKET_IN
    log.info('change_port: new_state: %d %s ' % (new_state, con.info))

    pm = of.ofp_port_mod( port_no=p.port_no,
                          hw_addr=p.hw_addr,
                          config = new_state,
                          mask = new_state ) # of.OFPPC_PORT_DOWN )
    con.send(pm)

    body = of.ofp_port_stats_request()
    body.port_no = of.OFPP_NONE  # request all port statics
    msg = of.ofp_stats_request(body=body)
    con.send(msg.pack())
Beispiel #11
0
    def SendStatsReq(self):
        # Send flow stat requests to every switch that has active flows.

        del self.PolSwitches[:] # empty the plist of switches to be polled in order to calculate it again.

        if core.forwarding.ActFlows:
            log.debug("Sending Port Stat Requests to all switches that have active flows")
            # Remove non-active flows in case they exist in the list
            core.forwarding.removeInactiveFlows()

            # log.debug("Before Sending Port Stats messages the ActFlow list is:")
            for fl in core.forwarding.ActFlows:
                # print fl.flow_match.s_ip, fl.flow_match.d_ip, fl.used_path, fl.active
                for r in fl.used_path:
                    if (fl.used_path[fl.used_path.index(r)][0]) not in self.PolSwitches:
                        self.PolSwitches.append(fl.used_path[fl.used_path.index(r)][0])
        else:
            log.debug("No active flows at the moment, so not sending any port stat requests")

        self.pol_counter+=1# increment polling session number

        if self.PolSwitches:
            for con in core.openflow.connections:
                if dpid_to_str(con.dpid) in self.PolSwitches:
                    log.debug("Sending Port Stats Request to %s: ", dpid_to_str(con.dpid))
                    msg = of.ofp_stats_request(body=of.ofp_port_stats_request())
                    con.send(msg)
def _timer_func():
    '''
    handler for timer function that sends the requests to all the
    switches connected to the controller.
    '''
    for connection in core.openflow._connections.values():
        connection.send(of.ofp_stats_request(body=of.ofp_port_stats_request()))
Beispiel #13
0
	def request_stats(self):
		# Get consumption of each node in the topology
		for i in range(len(info_manager.nodes)):
			self.count_flow_stats_straight += 1
			self.count_port_stats_straight += 1


		for h in info_manager.hosts:
			border_node = info_manager.get_node(h.dpid)
			try:
				core.openflow.getConnection(border_node.id).send(of.ofp_stats_request(body=of.ofp_flow_stats_request()))
				self.count_flow_stats_adaptive += 1
			except:
				continue

		nodes_list = self.G.nodes()
		aux = 0
		for node in nodes_list:
			aux += 1
			connection = core.openflow.getConnection(node)
			if connection:
				connection.send(of.ofp_stats_request(body=of.ofp_port_stats_request()))
				self.count_port_stats_adaptive += 1

		if aux == 0:
			self.count_port_stats_adaptive = 0

		update_monitoring_stats(self.count_flow_stats_straight, self.count_flow_stats_adaptive, self.count_port_stats_straight, self.count_port_stats_adaptive)
		info_manager.update_network_consumption()
Beispiel #14
0
 def request_stats(self):
     "Request port statistics of every node in the network"
     for node in self.nodes:
         try:
             core.openflow.getConnection(node).send(
                 of.ofp_stats_request(body=of.ofp_port_stats_request()))
         except:
             pass
Beispiel #15
0
def _on_timer():

    for n in nodes:
        #Sends out requests to the network nodes
        core.openflow.getConnection(n.connection.dpid).send(of.ofp_features_request())
        n.connection.send(of.ofp_stats_request(body=of.ofp_port_stats_request()))
        n.connection.send(of.ofp_stats_request(body=of.ofp_aggregate_stats_request()))
        n.connection.send(of.ofp_stats_request(body=of.ofp_flow_stats_request()))
def request_stats():
    # Request both port and flow stats for each connection
    # Event handler will receive the results
    for conn in get_connection_list():
        conn.send( of.ofp_stats_request(body=of.ofp_port_stats_request()) )
        # conn.send( of.ofp_stats_request(body=of.ofp_flow_stats_request()) )

    log.debug("{0} connections to check".format(len(get_connection_list())))
Beispiel #17
0
    def lancer_verification_stats(self):

        if self.is_connected:
            self.connection.send(
                of.ofp_stats_request(body=of.ofp_port_stats_request()))
            self._last_port_stats_query_send_time = time.time()
            print("Envoi d'une requete de stats port au switch: " +
                  dpid_to_str(self.dpid))
Beispiel #18
0
    def sendPortStatsRequest(self, event):
        srr = of.ofp_stats_request()
        srr.type = of.OFPST_PORT
        srr.body = of.ofp_port_stats_request()
        srr.body.port_no = of.OFPP_NONE

        event.connection.send(srr)
        print "Sending port stat request message to Switch %s " % event.dpid
def request_stats():
    # Request both port and flow stats for each connection
    # Event handler will receive the results
    for conn in get_connection_list():
        conn.send(of.ofp_stats_request(body=of.ofp_port_stats_request()))
        # conn.send( of.ofp_stats_request(body=of.ofp_flow_stats_request()) )

    log.debug("{0} connections to check".format(len(get_connection_list())))
 def _timer_func():
     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()))
     log.debug("Sent %i flow/port stats request(s)",
               len(core.openflow._connections))
Beispiel #21
0
 def _ping_switches(self):
     log.info("Pinging Switches")
     nodes = self.G.nodes()
     for dpid in nodes:
         con = core.openflow.getConnection(dpid)
         msg = of.ofp_stats_request()
         msg.body = of.ofp_port_stats_request()
         if con is not None and con.connect_time is not None:
             con.send(msg)
Beispiel #22
0
def timer_func():
    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_aggregate_stats_request())
        )  # ???????????????not supported in POX yet
        connection.send(of.ofp_stats_request(body=of.ofp_port_stats_request()))
    log.debug("Sent %i flow/port stats request(s)",
              len(core.openflow._connections))
Beispiel #23
0
def _timer_func ():
  for connection in core.openflow._connections.values():
    
    #log.debug("!!!!!!" + dpidToStr(connection.dpid))
    if(dpidToStr(connection.dpid) == "00-00-00-00-00-05"):
      connection.send(of.ofp_stats_request(body=of.ofp_flow_stats_request()))
      connection.send(of.ofp_stats_request(body=of.ofp_port_stats_request()))

    log.debug("Sent %i flow/port stats request(s)", len(core.openflow._connections))
Beispiel #24
0
def _timer_func():

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

        dpid_str = dpidToStr(connection.dpid)

        # 给每个connection的sw发送request 可以加if判断发送哪个
        connection.send(of.ofp_stats_request(body=of.ofp_flow_stats_request()))
        connection.send(of.ofp_stats_request(body=of.ofp_port_stats_request()))
Beispiel #25
0
 def _send_ofp_stats_request(self):
     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()))
     log.debug("Sent %i flow/port stats request(s)",
               len(core.openflow._connections))
     core.flow_stats._raise_StatsEvent()  #invoke event
Beispiel #26
0
 def _timer_func(self):
     """
     Recurring function to request stats from switches
     for each connection (which represents a switch actually)
     request statistics
     """
     if self.connection is not None:
         self.connection.send(
             of.ofp_stats_request(body=of.ofp_port_stats_request()))
Beispiel #27
0
def timer_func():

    con = core.openflow._connections
    # print "hey"

    # print con[2]
    connection = con[3]
    # connection.send(of.ofp_stats_request(body=of.ofp_flow_stats_request()))
    connection.send(of.ofp_stats_request(body=of.ofp_port_stats_request()))
def send_stats_requests():
  """
  Send stats request to the connecting switch
  """
  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()))

  log.debug("Sent %i flow/port stats request(s)", len(core.openflow._connections))
Beispiel #29
0
 def stats_request(self):
     for s in self.switches.keys():
         try:
             core.openflow.getConnection(s).send(
                 of.ofp_stats_request(body=of.ofp_port_stats_request()))
             #log.info('Requisitando estatisticas do switch %d a cada %d segundos' %(s,self.time))
         except:
             log.warning(
                 'Sem conexao ao Switch %s... Impossivel coletar estatisticas'
                 % s)
Beispiel #30
0
 def _handle_TopologyConverged(self, event):
     # when it catches an event that the topology has converged, it registers the listeners on how to handle the
     # openflow events. It means that it can start monitoring the network as the topology has converged
     # after bringing up the module for the first time.
     core.openflow.addListeners(self, priority = 10)
     for con in core.openflow.connections: # init prev_counter for all links
         log.debug("Sending Port Stats Request to all switches for the first time: ")
         msg = of.ofp_stats_request(body=of.ofp_port_stats_request())
         con.send(msg)
         self.PolSwitches.append(dpid_to_str(con.dpid))
Beispiel #31
0
def send_stats_requests():
    """
  Send stats request to the connecting switch
  """
    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()))

    log.debug("Sent %i flow/port stats request(s)",
              len(core.openflow._connections))
 def sendPortStatsRequest(self, connection):
     '''
     Request Port Statistics to switch
     Return time which the request taked place
     '''
     # Request port stats from the switch corresponding to this connection
     connection.send(openflowlib.ofp_stats_request(body=openflowlib.ofp_port_stats_request()))
     request_time = time.time()
     log.debug("DPID = %s - Statistics Requested to Switch", connection.dpid)
     
     return request_time
Beispiel #33
0
 def launch_stats_query(self):
     """Sends an OpenFlow FlowStatsRequest and PortStatsRequest to the switch associated with this object."""
     if self.is_connected:
         self.connection.send(
             of.ofp_stats_request(body=of.ofp_flow_stats_request()))
         self._last_flow_stats_query_send_time = time.time()
         self.connection.send(
             of.ofp_stats_request(body=of.ofp_port_stats_request()))
         self._last_port_stats_query_send_time = time.time()
         log.debug('Sent flow and port stats requests to switch: ' +
                   dpid_to_str(self.dpid))
def get_switch_ports(switch_dpid):
    """
    Returns per switch a list of all port stats. This includes:
     - Port number
     - Received/transmitted packets
     - Received/transmitted bytes
     - Received/transmitted dropped packets
     - Received/transmitted packets with error
     - Received packets with frame error
     - Received packets with overrun error
     - Received packets with CRC error
     - Collisions
    
    :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 port stats from the requested switch
    :rtype: JSONArray
    :except BaseException: If any error occurs returns an empty list
    """
    try:
        # build openflow message
        bodyMsg = of.ofp_port_stats_request()
        bodyMsg.port_no = of.OFPP_NONE
        msg = of.ofp_stats_request(body=bodyMsg)
        msg.type = of.OFPST_PORT
        # get and verify stats
        dataArray = []
        stats = get_switch_stats(switch_dpid, msg, "ports")
        if stats == None:
            log.error("Error getting port stats")
            return json.dumps(dataArray)
        # build and return json data
        for portStats in stats:
            data = {
                "number": portStats.port_no,
                "rxPackets": portStats.rx_packets,
                "txPackets": portStats.tx_packets,
                "rxBytes": portStats.rx_bytes,
                "txBytes": portStats.tx_bytes,
                "rxDrops": portStats.rx_dropped,
                "txDrops": portStats.tx_dropped,
                "rxError": portStats.rx_errors,
                "txError": portStats.tx_errors,
                "rxFrameError": portStats.rx_frame_err,
                "rxOverrunError": portStats.rx_over_err,
                "rxCrcError": portStats.rx_crc_err,
                "collisions": portStats.collisions
            }
            dataArray.append(data)
        return json.dumps(dataArray)
    except BaseException, e:
        log.error(e.message)
        dataArray = []
        return json.dumps(dataArray)
Beispiel #35
0
 def _handle_timer(self):
     for dpid in core.topo.graph.nodes_iter():
         for _,_,(pt,_) in core.topo.graph.out_edges_iter(dpid, data='pt'):
             msg = of.ofp_stats_request()
             msg.body = of.ofp_port_stats_request()
             msg.body.port_no = pt
             core.openflow.getConnection(dpid).send(msg)
     for dpid in core.topo.graph.nodes_iter():
         msg = of.ofp_stats_request()
         msg.body = of.ofp_table_stats_request()
         core.openflow.getConnection(dpid).send(msg)
Beispiel #36
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()))
Beispiel #37
0
    def _handle_timer(self, dpid):
        sw = self.switches.get(dpid)
        if sw is None:
            return

        # send stat request
        body = of.ofp_port_stats_request()
        msg = of.ofp_stats_request(body=body)
        core.openflow.sendToDPID(dpid, msg.pack())

        core.callDelayed(self.poll_period, self._handle_timer, dpid)
Beispiel #38
0
  def _handle_timer (self, dpid):
    sw = self.switches.get(dpid)
    if sw is None:
      return

    # send stat request
    body = of.ofp_port_stats_request()
    body.port_no = of.OFPP_NONE  # request all port statics
    msg = of.ofp_stats_request(body=body)
    core.openflow.sendToDPID(dpid, msg.pack())

    core.callDelayed(self.poll_period, self._handle_timer, dpid)
Beispiel #39
0
def req_for_stats():
    tik = 30
    while True:
        time.sleep(1)
        tik = (tik - 1 + 30) % 30
        if tik == 0:
            allCon = core.openflow.connections
            for con in allCon:
                con.send(
                    of.ofp_stats_request(body=of.ofp_flow_stats_request()))
                con.send(
                    of.ofp_stats_request(body=of.ofp_port_stats_request()))
Beispiel #40
0
def timer_function ():
	"""
	Request Flow and Port Stats
	"""

	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()))

	global timer_now
	timer_now = datetime.datetime.now()
	
	log.debug("Sent %i flow/port stats requests", len(core.openflow._connections))
Beispiel #41
0
def _handle_timer(message):
		print 
		print message
		connections = core.openflow._connections
		print 'connected switch:',
		for connection in connections:
			print connection,
			# print 'connection:',connection.dpid,connection.ports #to see what connection consists of
			connection.send(of.ofp_stats_request(body = of.ofp_flow_stats_request()))
			connection.send(of.ofp_stats_request(body = of.ofp_port_stats_request()))
			#delet all flows
			connection.send(of.ofp_flow_mod(match = of.ofp_match(),command = of.OFPFC_DELETE))
		print '\n'
Beispiel #42
0
def _handle_timer(message):
    print
    print message
    connections = core.openflow._connections
    print 'connected switch:',
    for connection in connections:
        print connection,
        # print 'connection:',connection.dpid,connection.ports #to see what connection consists of
        connection.send(of.ofp_stats_request(body=of.ofp_flow_stats_request()))
        connection.send(of.ofp_stats_request(body=of.ofp_port_stats_request()))
        #delet all flows
        connection.send(
            of.ofp_flow_mod(match=of.ofp_match(), command=of.OFPFC_DELETE))
    print '\n'
Beispiel #43
0
def _timer_func ():
  if len(core.openflow._connections.values())==0:
    # since no switch is connected, clean everything.
    del switches[:]
    hosts.clear()
    switch_desc.clear()
    adjacency.clear()
    link_bw.clear()
    link_bw_total.clear()
    byte.clear()
    byte_r.clear()
    clock.clear()
    flow_stats.clear()
    aggr_stats.clear()
    port_stats.clear()
  for connection in core.openflow._connections.values():
    connection.send(of.ofp_stats_request(body=of.ofp_port_stats_request()))
    connection.send(of.ofp_stats_request(body=of.ofp_aggregate_stats_request()))
    connection.send(of.ofp_stats_request(body=of.ofp_flow_stats_request()))
    connection.send(of.ofp_stats_request(body=of.ofp_desc_stats_request()))
Beispiel #44
0
def _timer_func ():
  defVal = 20
  defPort = 8080 
  ddd = core.flowDicto.getFlowDicto()
  #log.warning("-------------------- %s -------" %len(ddd))
  for f in ddd:
    v = ddd[f]
    rIp = v[0]
    rPort = v[1]
    defVal = v[2]
    if defVal != 0.0: 
      start_new_thread(sendR ,(rIp, rPort, defPort, defVal,))
    # CHERA INJA BREAK BOOOOOOOD??????? :((((((((
  core.flowDicto.resetFlowDicto()
  '''
  if core.cong == True:
    core.congRounds += 1.0
  else:
    core.congRounds = 1.0
  '''
  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()))
 def _handle_ConnectionUp (self, event):
   log.debug("Switch %s has come up.", dpid_to_str(event.dpid))
   #print event.ofp
   event.connection.send(of.ofp_stats_request(body=of.ofp_port_stats_request()))
   event.connection.send(of.ofp_stats_request(body=of.ofp_flow_stats_request()))
   event.connection.send(of.ofp_stats_request(body=of.ofp_desc_stats_request()))
Beispiel #46
0
def _timer_func ():
  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()))
  log.debug("Sent %i flow/port stats request(s)", len(core.openflow._connections))
Beispiel #47
0
 def _init (self, port_no=2):
   sr = of.ofp_stats_request(body=of.ofp_port_stats_request())
   self._con.send(sr)
   self.xid = sr.xid
Beispiel #48
0
 def port_stat (self, dpid):
   core.openflow.sendToDPID(
     dpid,
     of.ofp_stats_request(body=of.ofp_port_stats_request())
   )
Beispiel #49
0
def flowUpdate():
  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()))
Beispiel #50
0
def request_PLR():
    for connection in core.openflow._connections.values():
        connection.send(of.ofp_stats_request(body=of.ofp_port_stats_request()))
Beispiel #51
0
def timer_func ():
    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_aggregate_stats_request())) # ???????????????not supported in POX yet
        connection.send(of.ofp_stats_request(body=of.ofp_port_stats_request()))
    log.debug("Sent %i flow/port stats request(s)", len(core.openflow._connections))
Beispiel #52
0
 def _send_ofp_stats_request (self):
   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()))
   log.debug("Sent %i flow/port stats request(s)", len(core.openflow._connections))
   core.flow_stats._raise_StatsEvent()  #invoke event 
Beispiel #53
0
def _handle_ConnectionUp (event):
  msg = of.ofp_stats_request(body=of.ofp_port_stats_request())
  #event.connection.send(msg)
  #log.info("Port stats request sent")
  __addFlowmod2(event)
Beispiel #54
0
def send_requests():
    print "Sending request:"
    for con in core.openflow._connections.values():
        con.send(of.ofp_stats_request(body=of.ofp_port_stats_request()))
        print "Sent stat requests to", con
 def run (self):
     """
     Gets and aggregates switch port stats to record them in a flat file as
     plain text with a defined sample time.
     """
     # build and check flat file path
     dir_path = get_dir_path()
     if not os.path.exists(dir_path):
         os.makedirs(dir_path)
     path = get_file_path(self.dpid)
     # create and/or write file (a = append)
     f = open(path, "a")
     while self.infinite:
         # initialize stats
         rx_packets = 0
         tx_packets = 0
         rx_bytes = 0
         tx_bytes = 0
         rx_drops = 0
         tx_drops = 0
         rx_error = 0
         tx_error = 0
         rx_frame_error = 0
         rx_overrun_error = 0
         rx_crc_error = 0
         collisions = 0
         # build openflow message
         bodyMsg = of.ofp_port_stats_request()
         bodyMsg.port_no = of.OFPP_NONE
         msg = of.ofp_stats_request(body = bodyMsg)
         msg.type = of.OFPST_PORT
         # get and verify stats
         stats = get_switch_stats(self.dpid, msg, "ports")
         if stats == None:
             log.error("Error getting port stats")
             stats = []
         # aggregate ports stats
         for portStats in stats:
             rx_packets += portStats.rx_packets
             tx_packets += portStats.tx_packets
             rx_bytes += portStats.rx_bytes
             tx_bytes += portStats.tx_bytes
             rx_drops += portStats.rx_dropped
             tx_drops += portStats.tx_dropped
             rx_error += portStats.rx_errors
             tx_error += portStats.tx_errors
             rx_frame_error += portStats.rx_frame_err
             rx_overrun_error += portStats.rx_over_err
             rx_crc_error += portStats.rx_crc_err
             collisions += portStats.collisions
         # write in file
         time_ms = int(round(time.time() * 1000))
         f.write("time=" + str(time_ms) + "|rxPackets=" + str(rx_packets)
                 + "|txPackets=" + str(tx_packets) + "|rxBytes="
                 + str(rx_bytes) + "|txBytes=" + str(tx_bytes) + "|rxDrops="
                 + str(rx_drops) + "|txDrops=" + str(tx_drops) + "|rxError="
                 + str(rx_error) + "|txError=" + str(tx_error)
                 + "|rxFrameError=" + str(rx_frame_error)
                 + "|rxOverrunError=" + str(rx_overrun_error)
                 + "|rxCrcError=" + str(rx_crc_error) + "|collisions="
                 + str(collisions) + "|\n")
         f.flush()
         log.debug("Thread is recording aggregate port stats from switch %s" % dpidToStr(self.dpid))
         # sleep sample time seconds
         time.sleep(self.sampletime)
     f.close()