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;
}
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;
}
Aggregations