Package ru.petrsu.akolosov.flowbrook.utils

Source Code of ru.petrsu.akolosov.flowbrook.utils.FlowStats

/*
* Copyright (C) 2010 Alexander Kolosov
*
* This file is part of FlowBrook.
*
* FlowBrook is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* FlowBrook is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with FlowBrook. If not, see <http://www.gnu.org/licenses/>
*/
package ru.petrsu.akolosov.flowbrook.utils;

import ru.petrsu.akolosov.flowbrook.processing.FlowProcessingException;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import ru.petrsu.akolosov.flowbrook.FlowSourceSet;
import ru.petrsu.akolosov.flowbrook.flowtools.FlowTools;
import ru.petrsu.akolosov.flowbrook.processing.ConcurrentFlowSourceSetHandler;
import ru.petrsu.akolosov.flowbrook.processing.FlowDataProcessingRule;
import ru.petrsu.akolosov.flowbrook.processing.FlowSourceSetHandler;
import ru.petrsu.akolosov.flowbrook.processing.FlowStatsRule;
import ru.petrsu.akolosov.flowbrook.processing.IfaсeDistributionRule;
import ru.petrsu.akolosov.flowbrook.processing.IfaсeDirectionsRule;
import ru.petrsu.akolosov.flowbrook.processing.IpDirectionsRule;
import ru.petrsu.akolosov.flowbrook.processing.PortDistributionRule;
import ru.petrsu.akolosov.flowbrook.processing.filters.AndFilter;
import ru.petrsu.akolosov.flowbrook.processing.filters.FlowFilter;
import ru.petrsu.akolosov.flowbrook.processing.filters.OrFilter;
import ru.petrsu.akolosov.flowbrook.processing.filters.PortFilter;
import ru.petrsu.akolosov.flowbrook.processing.filters.ProtoFilter;

/**
*
* @author Alexander Kolosov
*/
public class FlowStats {

    public static void main(String args[]) {
       
        final Calendar cal = Calendar.getInstance();
        Logger logger = Logger.getLogger(FlowStats.class.getName());
        List<FlowDataProcessingRule> statsRules = new ArrayList<FlowDataProcessingRule>();
       
        try {
            statsRules.add(new FlowStatsRule(null, new FileOutputStream("flowsall.csv", true)));
           
            statsRules.add(new IfaсeDistributionRule(null, new FileOutputStream("flowsOutIfaces.csv", true), true));
            statsRules.add(new IfaсeDistributionRule(null, new FileOutputStream("flowsInIfaces.csv", true), false));

            statsRules.add(new IfaсeDirectionsRule(null, new FileOutputStream("flowsIfacesDirections.csv", true)));

            final FlowFilter srcWellKnownPorts = new PortFilter(1, 4096, false);
            final FlowFilter dstWellKnownPorts = new PortFilter(1, 4096, true);

            final FlowFilter udpFlows = new ProtoFilter(17);
            final FlowFilter tcpFlows = new ProtoFilter(6);
           
            /* TCP destination ports */
            final AndFilter tcpDstFlows = new AndFilter();
            tcpDstFlows.addFilter(tcpFlows);
            tcpDstFlows.addFilter(dstWellKnownPorts);
            statsRules.add(new PortDistributionRule(tcpDstFlows, new FileOutputStream("flowsTcpDstPorts.csv", true), true));

            /* TCP source ports */
            final AndFilter tcpSrcFlows = new AndFilter();
            tcpSrcFlows.addFilter(tcpFlows);
            tcpSrcFlows.addFilter(srcWellKnownPorts);
            statsRules.add(new PortDistributionRule(tcpSrcFlows, new FileOutputStream("flowsTcpSrcPorts.csv", true), false));

            /* UDP destination ports */
            final AndFilter udpDstFlows = new AndFilter();
            udpDstFlows.addFilter(udpFlows);
            udpDstFlows.addFilter(dstWellKnownPorts);
            statsRules.add(new PortDistributionRule(udpDstFlows, new FileOutputStream("flowsUdpDstPorts.csv", true), true));

            /* UDP source ports */
            final AndFilter udpSrcFlows = new AndFilter();
            udpSrcFlows.addFilter(udpFlows);
            udpSrcFlows.addFilter(srcWellKnownPorts);
            statsRules.add(new PortDistributionRule(udpSrcFlows, new FileOutputStream("flowsUdpSrcPorts.csv", true), false));

            /* UDP and TCP flows */
            final OrFilter udpTcpFlows = new OrFilter();
            udpTcpFlows.addFilter(udpFlows);
            udpTcpFlows.addFilter(tcpFlows);
            statsRules.add(new FlowStatsRule(udpTcpFlows, new FileOutputStream("flowsUdpTcp.csv", true)));

            statsRules.add(new IpDirectionsRule(udpTcpFlows, new FileOutputStream("flowsIpDirections.csv", true)));

        } catch (FileNotFoundException ex) {
            Logger.getLogger(FlowStats.class.getName()).log(Level.SEVERE, null, ex);
        }

        for (String path : args) {
            FlowSourceSet sourceSet = FlowTools.getSourceFromDir(new File(path), true);

            FlowSourceSetHandler fsHandler = new ConcurrentFlowSourceSetHandler(sourceSet, statsRules);

            cal.setTime(sourceSet.getFirstFlowTime());
            cal.set(Calendar.DAY_OF_MONTH, 1);
            cal.set(Calendar.HOUR_OF_DAY, 0);
            cal.set(Calendar.MINUTE, 0);
            cal.set(Calendar.SECOND, 0);
            cal.set(Calendar.MILLISECOND, 0);
           
            try {
                fsHandler.process(cal, Calendar.MONTH, Calendar.DAY_OF_MONTH, 1);
            } catch (FlowProcessingException ex) {
                Logger.getLogger(FlowStats.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}
TOP

Related Classes of ru.petrsu.akolosov.flowbrook.utils.FlowStats

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.