Commit e69342ae authored by Bc. Matúš Husovský's avatar Bc. Matúš Husovský
Browse files

# Zmenene exportovane polia pre kolekciu acc_records

# -> Pridane srcMac a dstMac
# -> Zmenene octetTotalCount a packetTotalCount 
#        na deltaOctetCount a deltaPacketCount
# Pozmenena hashovacia funkcia, kvoli zmene tychto poli
parent 9d308a32
......@@ -23,8 +23,10 @@ import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.sql.Timestamp;
import java.util.Arrays;
import java.util.Calendar;
import java.util.List;
import java.util.logging.Level;
import org.apache.log4j.Logger;
import sk.tuke.cnl.bm.JXColl.IPFIX.FieldSpecifier;
import sk.tuke.cnl.bm.JXColl.IPFIX.IPFIXDataRecord;
......@@ -62,12 +64,13 @@ public class AccountingManager {
private boolean isMulticast;
//private long flowStartSeconds;
// private long octetDeltaCount;
private long octetTotalCount;
private long packetTotalCount;
private long octetDeltaCount;
private long packetDeltaCount;
private long firstFlowStartMilliseconds;
private long lastFlowStartMilliseconds;
private long lastFlowEndMiliseconds;
private InetAddress sourceIPv4AddressInet;
private InetAddress destinationIPv4AddressInet;
/** Zoznam poli v spracovavanej sablone*/
private List<FieldSpecifier> fields;
......@@ -102,8 +105,18 @@ public class AccountingManager {
// ak by nevedel, bolo by potrebne ziskat z fieldSpecifier velkost elementu
short elementID = 8;
sourceIPv4Address = data.getFieldValue(template.getFieldSpecifierPosition(elementID));
try {
sourceIPv4AddressInet = InetAddress.getByAddress(sourceIPv4Address);
} catch (UnknownHostException ex) {
java.util.logging.Logger.getLogger(AccountingManager.class.getName()).log(Level.SEVERE, null, ex);
}
elementID = 12;
destinationIPv4Address = data.getFieldValue(template.getFieldSpecifierPosition(elementID));
try {
destinationIPv4AddressInet = InetAddress.getByAddress(destinationIPv4Address);
} catch (UnknownHostException ex) {
java.util.logging.Logger.getLogger(AccountingManager.class.getName()).log(Level.SEVERE, null, ex);
}
elementID = 56;
sourceMAC = data.getFieldValue(template.getFieldSpecifierPosition(elementID));
elementID = 80;
......@@ -144,15 +157,19 @@ public class AccountingManager {
//hashKey = generateHashKey(sourceIPv4Address, destinationIPv4Address, protocolIdentifier, sourcePort, destinationPort, ipDiffServCodePoint, isMulticast);
//temporary
hashKey = generateHashKey(sourceIPv4Address, destinationIPv4Address,sourceMAC,destinationMAC, (short)0, sourcePort, destinationPort, (short)0, false);
hashKey = generateHashKey(sourceIPv4AddressInet, destinationIPv4AddressInet,sourceMAC,destinationMAC, (short)0, sourcePort, destinationPort, (short)0, false);
System.out.println(
"Hash key: " + hashKey + " for" + sourceIPv4AddressInet.toString() +
' ' + destinationIPv4AddressInet.toString() + ' ' + sourcePort + ' ' + destinationPort
);
elementID = 1;
//octetDeltaCount = ByteBuffer.wrap(data.getFieldValue(template.getFieldSpecifierPosition(elementID))).getLong();
elementID = 85;
octetTotalCount = ByteBuffer.wrap(data.getFieldValue(template.getFieldSpecifierPosition(elementID))).getLong();
elementID = 86;
packetTotalCount = ByteBuffer.wrap(data.getFieldValue(template.getFieldSpecifierPosition(elementID))).getLong();
octetDeltaCount = ByteBuffer.wrap(data.getFieldValue(template.getFieldSpecifierPosition(elementID))).getLong();
//elementID = 85;
//octetTotalCount = ByteBuffer.wrap(data.getFieldValue(template.getFieldSpecifierPosition(elementID))).getLong();
elementID = 2;
packetDeltaCount = ByteBuffer.wrap(data.getFieldValue(template.getFieldSpecifierPosition(elementID))).getLong();
//packetTotalCount = ByteBuffer.wrap(data.getFieldValue(template.getFieldSpecifierPosition(elementID))).getLong();
elementID = 152;
......@@ -184,19 +201,19 @@ public class AccountingManager {
log.debug("src IP address: " + sourceIPv4Address);
log.debug("dst IP address: " + destinationIPv4Address);
log.debug("src IP address: " + sourceIPv4AddressInet);
log.debug("dst IP address: " + destinationIPv4AddressInet);
log.debug("src MAC address: " + sourceMAC);
log.debug("dst MAC address: " + destinationMAC);
log.debug("src port:"+sourcePort);
log.debug("dst port"+destinationPort);
log.debug("octet total count: " + octetTotalCount);
log.debug("packet total count: " + packetTotalCount);
log.debug("octet delta count: " + octetDeltaCount);
log.debug("packet delta count: " + packetDeltaCount);
if(accRecordCache.containsKey(hashKey)){
//accRecordCache.aggregateFlow(hashKey, new Date(flowStartSeconds), octetTotalCount, packetTotalCount);
log.debug("Adding flow record to existing accounting record with hashkey: " + hashKey);
accRecordCache.aggregateFlow(hashKey, lastFlowEndMiliseconds, octetTotalCount, packetTotalCount);
accRecordCache.aggregateFlow(hashKey, lastFlowEndMiliseconds, octetDeltaCount, packetDeltaCount);
}
else{
//accRecord = new AccountingRecord(sourceIPv4Address, destinationIPv4Address, protocolIdentifier,
......@@ -208,7 +225,7 @@ public class AccountingManager {
// octetTotalCount, packetTotalCount);
accRecord = new AccountingRecord(sourceIPv4Address, destinationIPv4Address, sourceMAC, destinationMAC, protocolIdentifier,
sourcePort, destinationPort, ipDiffServCodePoint, firstFlowStartMilliseconds,lastFlowEndMiliseconds, isMulticast,
octetTotalCount, packetTotalCount);
octetDeltaCount, packetDeltaCount);
accRecordCache.addAccountingRecord(hashKey, accRecord);
......@@ -229,11 +246,11 @@ public class AccountingManager {
* @param multicast Atribut zaznamu
* @return Kluc zaznamu
*/
private int generateHashKey(byte[] srcIP, byte[] dstIP,byte[] srcMAC,byte[] dstMAC, short protocol, int srcPort, int dstPort, short dscp, boolean multicast){
private int generateHashKey(InetAddress srcIP, InetAddress dstIP,byte[] srcMAC,byte[] dstMAC, short protocol, int srcPort, int dstPort, short dscp, boolean multicast){
// Vhodny hash?
int hash = (srcIP.hashCode() + 1009);
hash ^= dstIP.hashCode();hash ^= srcMAC.hashCode();hash ^= dstMAC.hashCode();
hash ^= dstIP.hashCode();hash ^= Arrays.hashCode(srcMAC);hash ^= Arrays.hashCode(dstMAC);
hash ^= protocol; hash ^= srcPort; hash ^= dstPort; hash ^= dscp; hash += (multicast ? 1009 : 2003);
return hash;
}
......
......@@ -39,8 +39,8 @@ public class AccountingRecord {
private long firstFlowStart;
private long lastFlowEnd;
private boolean isMulticast;
private long octetTotalCount; // Max velkost prenesenych dat je 4,3GB pre jeden uctovaci zaznam
private long packetTotalCount; // Tato hodnota ani nie je potrebna pre uctovanie
private long octetDeltaCount; // Max velkost prenesenych dat je 4,3GB pre jeden uctovaci zaznam
private long packetDeltaCount; // Tato hodnota ani nie je potrebna pre uctovanie
private int flowCount = 0;
/** Vytvara novu instanciu triedy */
......@@ -75,8 +75,8 @@ public class AccountingRecord {
this.firstFlowStart = firstFlowStart;
this.lastFlowEnd = lastFlowEnd;
this.isMulticast = isMulticast;
this.octetTotalCount = octetCount;
this.packetTotalCount = packetCount;
this.octetDeltaCount = octetCount;
this.packetDeltaCount = packetCount;
flowCount = 1;
}
......@@ -90,8 +90,8 @@ public class AccountingRecord {
*/
public void addFlow(long lastFlowEnd, long octetCount, long packetCount){
this.lastFlowEnd = lastFlowEnd;
this.octetTotalCount += octetCount;
this.packetTotalCount += packetCount;
this.octetDeltaCount += octetCount;
this.packetDeltaCount += packetCount;
flowCount++;
}
......@@ -211,15 +211,15 @@ public class AccountingRecord {
* Get metoda
* @return Pocet bytov uctovacieho zaznamu
*/
public long getOctetTotalCount() {
return octetTotalCount;
public long getOctetDeltaCount() {
return octetDeltaCount;
}
/**
* Get metoda
* @return Pocet paketov uctovacieho zaznamu
*/
public long getPacketTotalCount() {
return packetTotalCount;
public long getPacketDeltaCount() {
return packetDeltaCount;
}
/**
* Get metoda
......
......@@ -89,7 +89,7 @@ public class AccountingRecordsExporter {
//colNames = new String[12];
String[] colNames = {"collectorID","sourceipv4address","destinationipv4address","sourcemacaddress",
"destinationmacaddress","protocolidentifier","sourceport","destinationport","ipdiffservcodepoint",
"datetime","ismulticast","octettotalcount","packettotalcount","flowcount"};
"datetime","ismulticast","octetdeltacount","packetdeltacount","flowcount"};
while(e.hasMoreElements()){
ar = (AccountingRecord)e.nextElement();
......@@ -118,8 +118,8 @@ public class AccountingRecordsExporter {
//json += "'datetime' : '" + Support.SecToTimeOfDay(averageDate / 1000) + "' , ";
values[9] = averageDate ;
values[10] = (ar.isIsMulticast() ? true : false) ;
values[11] = ar.getOctetTotalCount() ;
values[12] = ar.getPacketTotalCount() ;
values[11] = ar.getOctetDeltaCount();
values[12] = ar.getPacketDeltaCount();
values[13] = ar.getFlowCount() ;
//pgclient.insertdata("ACC_REC", json);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment