Search in sources :

Example 51 with PortStatistics

use of org.onosproject.net.device.PortStatistics in project ddosdn by ssulca.

the class Statistics method detectingDDoS.

/**
 * Implementa el Algoritmo3 de Fang Leu
 *
 * @return true si H0 se rechaza, false si H0 es cierta
 */
private Set<DeviceId> detectingDDoS() {
    // distribution dev count
    int nDstr;
    long nCount;
    long nBytes;
    long[] arrayNCant;
    long[] arrayNSize;
    // Set Suspicios Dev
    Set<DeviceId> suspuciosDev;
    // Distribution devs
    DeviceId[] arrayDistribtionIds;
    Set<DeviceId> DistributionIdSet;
    // Statistics per dev
    Set<PortStatistics> portStatistics;
    suspuciosDev = new HashSet<>();
    // Get all DevicesId of Distribution Devices
    DistributionIdSet = getDevIdsByAnnot(this.deviceService, STR_DISTRIBTION, this.log);
    if (DistributionIdSet.isEmpty()) {
        log.error("Dont find Distribution Devices");
        return suspuciosDev;
    }
    nDstr = DistributionIdSet.size();
    arrayNCant = new long[nDstr];
    arrayNSize = new long[nDstr];
    arrayDistribtionIds = DistributionIdSet.toArray(new DeviceId[nDstr]);
    // para arrayNCant y arrayNSize
    for (int i = 0; i < arrayDistribtionIds.length; i++) {
        portStatistics = getStatisticsEdgePorts(this.deviceService, this.linkService, arrayDistribtionIds[i], this.log);
        if (!portStatistics.isEmpty()) {
            nCount = 0;
            nBytes = 0;
            for (PortStatistics stat : portStatistics) {
                try {
                    nCount += stat.packetsReceived();
                    nBytes += stat.bytesReceived();
                } catch (NullPointerException e) {
                    log.error("Dont detected Ports Statistics");
                    return suspuciosDev;
                }
            }
            arrayNSize[i] = nBytes;
            arrayNCant[i] = nCount;
        } else {
            arrayNSize[i] = 0;
            arrayNCant[i] = 0;
        }
    }
    // Detect Resourse Cosumption
    if (isConsumption(arrayNCant, DAY_COUNT)) {
        // Check wich Edges devices issued the attack
        suspuciosDev.addAll(checkDevice(arrayDistribtionIds, arrayNCant, DAY_COUNT));
    }
    // Detect Band Width Cosumption
    if (isConsumption(arrayNSize, DAY_BYTES)) {
        // Check wich Edges devices issued the attack
        suspuciosDev.addAll(checkDevice(arrayDistribtionIds, arrayNSize, DAY_BYTES));
    }
    return suspuciosDev;
}
Also used : DeviceId(org.onosproject.net.DeviceId) PortStatistics(org.onosproject.net.device.PortStatistics)

Example 52 with PortStatistics

use of org.onosproject.net.device.PortStatistics in project ddosdn by ssulca.

the class UpgradeManager method getNewEntry.

/**
 * Get Statistics Total.
 * @return Map vales
 */
private HashMap<String, long[]> getNewEntry() {
    long[] values;
    Set<DeviceId> DistributionIdSet;
    Set<PortStatistics> portStatistics;
    HashMap<String, long[]> statisticsDevMap;
    // obtengo los Distr devices
    DistributionIdSet = getDevIdsByAnnot(this.deviceService, STR_DISTRIBTION, this.log);
    if (DistributionIdSet.isEmpty()) {
        log.error("No se encontraron Distribution for update");
        return null;
    }
    statisticsDevMap = new HashMap<>();
    // Por cada Ditribtuion obtengo las estadisticas de los puertos conectados a un EDGE
    for (DeviceId devId : DistributionIdSet) {
        portStatistics = getStatisticsEdgePortsTotal(this.deviceService, this.linkService, devId, this.log);
        if (!portStatistics.isEmpty()) {
            values = new long[2];
            // values[DAY_BYTES] = 0;
            for (PortStatistics stat : portStatistics) {
                try {
                    values[DAY_COUNT] += stat.packetsReceived();
                    values[DAY_BYTES] += stat.bytesReceived();
                } catch (NullPointerException e) {
                    log.error("Dont detected Ports Statistics");
                }
                // Agrega las entradas correspondientes en el map
                statisticsDevMap.put(devId.toString(), values);
            }
        }
    }
    return statisticsDevMap;
}
Also used : DeviceId(org.onosproject.net.DeviceId) PortStatistics(org.onosproject.net.device.PortStatistics)

Aggregations

PortStatistics (org.onosproject.net.device.PortStatistics)52 DefaultPortStatistics (org.onosproject.net.device.DefaultPortStatistics)26 DeviceId (org.onosproject.net.DeviceId)14 PortNumber (org.onosproject.net.PortNumber)14 DeviceService (org.onosproject.net.device.DeviceService)14 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)11 Device (org.onosproject.net.Device)10 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)8 ArrayList (java.util.ArrayList)8 Map (java.util.Map)8 Port (org.onosproject.net.Port)7 GET (javax.ws.rs.GET)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 PortStatisticsDiscovery (org.onosproject.net.device.PortStatisticsDiscovery)6 ConnectPoint (org.onosproject.net.ConnectPoint)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 Maps (com.google.common.collect.Maps)4 Collection (java.util.Collection)4 Set (java.util.Set)4