예제 #1
0
    def app_event_handler(self, ev):
        print ('[INFO FlowClassify.app_event_handler] %s' % ev.msg)
        t1 = time.time()
        st = datetime.datetime.fromtimestamp(t1).strftime('%Y-%m-%d %H:%M:%S')
        self.logger.info('timestamp = %s', st)
        flow_list_in_dp = flowutils.get_flow_in_dp(constant.Detect_switch_DPID)
        db_util.update_app_for_flows(data_collection.flow_list, constant.FlowClassification_IP, constant.db_method)
        evaluator.app_evaluation(flow_list_in_dp)
        evaluator.member_evaluation(flow_list_in_dp, data_collection.member_list)
        # print '[INFO FlowClassify._monitor]Flow Statistic Class\n>> member'
        # for key in statistic.database_member_record:
        #     print " >", key, statistic.database_member_record[key]
        #     for key2 in statistic.database_member_record[key].apprate:
        #         print " >", key2, statistic.database_member_record[key].apprate[key2]

        evaluator.group_evaluation(statistic.database_member_record, data_collection.group_list)
        print '[INFO FlowClassify._monitor]Flow Statistic Class\n>> group'
        self.logger.info('[INFO FlowClassify._monitor]Flow Statistic Class\n>> group')
        for key in statistic.database_group_record:
            print " >", key, statistic.database_group_record[key], statistic.database_group_record[key].member.keys()
            v = 0.0
            for key2 in statistic.database_group_record[key].apprate:
                print " >", key2, statistic.database_group_record[key].apprate[key2]
                self.logger.info('%s %f', key2, statistic.database_group_record[key].apprate[key2])
                v += statistic.database_group_record[key].apprate[key2]
            statistic.database_group_record[key].total = v
            print ' > total bandwidth: ', statistic.database_group_record[key].total
            self.logger.info(' > total bandwidth: %f', statistic.database_group_record[key].total)

        ev = Qos_UpdateEvent('Update qos for flow')
        self.send_event_to_observers(ev)
예제 #2
0
    def get_flow_data(self, req, **kwargs):
        """Get Flow data method."""
        dic = {}
        flow_list_in_dp = flowutils.get_flow_in_dp(constant.Detect_switch_DPID)
        for key in flow_list_in_dp:
            flow_c = data_collection.flow_list[key]

            # disable counter limitation for getting flows

            list_f = {
                "src_mac": flow_c.src_mac,
                "dst_mac": flow_c.dst_mac,
                "src_ip": flow_c.src_ip,
                "dst_ip": flow_c.dst_ip,
                "src_port": flow_c.src_port,
                "dst_port": flow_c.dst_port,
                "ip_proto": flow_c.ip_proto,
                "rate": flow_c.rate,
                "app": flow_c.app
            }

            dic.update({key: list_f})

        body = json.dumps(dic)
        return Response(content_type='application/json', body=body)
예제 #3
0
    def _routing_adjust(self, ev):
        datapath_list = ev.msg
        self.load = ev.load
        self.sw_stat = dict((k, v) for k, v in data_collection.switch_stat.items())
        switch_list = get_switch(self.topology_api_app, None)
        for datapath in switch_list:
            flow_list_in_dp = flowutils.get_flow_in_dp(datapath.dp.id)
            for key_tuples in flow_list_in_dp.keys():
                flow = data_collection.flow_list.get(key_tuples)
                if flow.r_limited > 3:
                    flow.r_limited = 0
                elif flow.r_limited >= 1 and flow.r_limited <= 3:
                    flow.r_limited += 1

        for datapath_id in datapath_list:
            datapath = get_switch(self.topology_api_app, dpid=datapath_id)
            flow_list_in_dp = flowutils.get_flow_in_dp(datapath[0].dp.id)
            self._adjustment_handler(flow_list_in_dp, datapath[0].dp.id)
예제 #4
0
    def get_flow_data(self, req, **kwargs):
        """Get Flow data method."""
        dic = {}
        flow_list_in_dp = flowutils.get_flow_in_dp(constant.Detect_switch_DPID)
        for key in flow_list_in_dp:
            flow_c = data_collection.flow_list[key]

            # disable counter limitation for getting flows

            list_f = {"src_mac": flow_c.src_mac, "dst_mac": flow_c.dst_mac,
                      "src_ip": flow_c.src_ip, "dst_ip": flow_c.dst_ip,
                      "src_port": flow_c.src_port, "dst_port": flow_c.dst_port,
                      "ip_proto": flow_c.ip_proto, "rate": flow_c.rate, "app": flow_c.app}

            dic.update({key: list_f})
            
        body = json.dumps(dic)
        return Response(content_type='application/json', body=body)