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

# Pridane pole applicationId v exporte do DB do kolekcie acc_records

# Zmenena hash funkcia pre ukladanie zaznamov do hash tabluky pred exportom do DB
# Upraveny ipfixFields.xml
parent e69342ae
#Tue, 20 Jan 2015 09:59:09 +0100
#Thu, 05 Mar 2015 12:58:32 +0100
/home/matus/Plocha/SLAmeterv2/novy_JXColl/jxcoll=
No preview for this file type
......@@ -3558,6 +3558,24 @@
<units>nanoseconds</units>
</field>
<field name="applicationId" dataType="octetArray"
group="application" dataTypeSemantics="identifier"
elementId="95" applicability="all" status="current">
<description>
<paragraph>
Specifies an Application ID.
</paragraph>
</description>
<reference>
<paragraph>
See Section 4 of [RFC6759]
for the applicationId Information Element
Specification.
</paragraph>
</reference>
</field>
</fieldDefinitions>
......@@ -2,6 +2,13 @@
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group/>
<group>
<file>file:/home/matus/Plocha/SLAmeterv2/novy_JXColl/jxcoll/src/sk/tuke/cnl/bm/JXColl/IpfixDecoder.java</file>
<file>file:/home/matus/Plocha/SLAmeterv2/novy_JXColl/jxcoll/src/sk/tuke/cnl/bm/JXColl/accounting/AccountingRecordsExporter.java</file>
<file>file:/home/matus/Plocha/SLAmeterv2/novy_JXColl/jxcoll/src/sk/tuke/cnl/bm/JXColl/accounting/AccountingManager.java</file>
<file>file:/home/matus/Plocha/SLAmeterv2/novy_JXColl/jxcoll/src/sk/tuke/cnl/bm/JXColl/IpfixElements.java</file>
<file>file:/home/matus/Plocha/SLAmeterv2/novy_JXColl/jxcoll/src/sk/tuke/cnl/bm/JXColl/accounting/AccountingRecordsCache.java</file>
<file>file:/home/matus/Plocha/SLAmeterv2/novy_JXColl/jxcoll/src/sk/tuke/cnl/bm/JXColl/accounting/AccountingRecord.java</file>
</group>
</open-files>
</project-private>
......@@ -22,6 +22,7 @@ package sk.tuke.cnl.bm.JXColl.accounting;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.sql.Timestamp;
import java.util.Arrays;
import java.util.Calendar;
......@@ -57,6 +58,9 @@ public class AccountingManager {
private byte[] destinationIPv4Address;
private byte[] sourceMAC;
private byte[] destinationMAC;
private byte[] applicationIdArray;
private byte[] tempIdArray;
private int applicationId;
private short protocolIdentifier;
private int sourcePort;
private int destinationPort;
......@@ -154,10 +158,19 @@ public class AccountingManager {
ipDiffServCodePoint = data.getFieldValue(template.getFieldSpecifierPosition(elementID))[0];
elementID = 206;
isMulticast = (data.getFieldValue(template.getFieldSpecifierPosition(elementID))[0] != 0);
elementID = 95;
tempIdArray = data.getFieldValue(template.getFieldSpecifierPosition(elementID));
applicationIdArray = new byte[4];
applicationIdArray[0] = tempIdArray[1];
applicationIdArray[1] = tempIdArray[2];
applicationIdArray[2] = tempIdArray[3];
applicationIdArray[3] = 0;
applicationId = byteArrayToInt(applicationIdArray);
//hashKey = generateHashKey(sourceIPv4Address, destinationIPv4Address, protocolIdentifier, sourcePort, destinationPort, ipDiffServCodePoint, isMulticast);
//temporary
hashKey = generateHashKey(sourceIPv4AddressInet, destinationIPv4AddressInet,sourceMAC,destinationMAC, (short)0, sourcePort, destinationPort, (short)0, false);
hashKey = generateHashKey(sourceIPv4AddressInet, destinationIPv4AddressInet,sourceMAC,destinationMAC, (short)0, sourcePort, destinationPort, (short)0, false, applicationId);
System.out.println(
"Hash key: " + hashKey + " for" + sourceIPv4AddressInet.toString() +
' ' + destinationIPv4AddressInet.toString() + ' ' + sourcePort + ' ' + destinationPort
......@@ -199,8 +212,6 @@ public class AccountingManager {
//log.debug("flowStartMiliseconds" + l + "Timestamp" + timestampFlowStartMiliseconds.toString());
log.debug("src IP address: " + sourceIPv4AddressInet);
log.debug("dst IP address: " + destinationIPv4AddressInet);
log.debug("src MAC address: " + sourceMAC);
......@@ -209,7 +220,8 @@ public class AccountingManager {
log.debug("dst port"+destinationPort);
log.debug("octet delta count: " + octetDeltaCount);
log.debug("packet delta count: " + packetDeltaCount);
log.debug("application id: " + applicationId);
if(accRecordCache.containsKey(hashKey)){
//accRecordCache.aggregateFlow(hashKey, new Date(flowStartSeconds), octetTotalCount, packetTotalCount);
log.debug("Adding flow record to existing accounting record with hashkey: " + hashKey);
......@@ -225,7 +237,7 @@ public class AccountingManager {
// octetTotalCount, packetTotalCount);
accRecord = new AccountingRecord(sourceIPv4Address, destinationIPv4Address, sourceMAC, destinationMAC, protocolIdentifier,
sourcePort, destinationPort, ipDiffServCodePoint, firstFlowStartMilliseconds,lastFlowEndMiliseconds, isMulticast,
octetDeltaCount, packetDeltaCount);
octetDeltaCount, packetDeltaCount, applicationId);
accRecordCache.addAccountingRecord(hashKey, accRecord);
......@@ -246,13 +258,27 @@ public class AccountingManager {
* @param multicast Atribut zaznamu
* @return Kluc zaznamu
*/
private int generateHashKey(InetAddress srcIP, InetAddress dstIP,byte[] srcMAC,byte[] dstMAC, short protocol, int srcPort, int dstPort, short dscp, boolean multicast){
// Vhodny hash?
private int generateHashKey(InetAddress srcIP, InetAddress dstIP,byte[] srcMAC,byte[] dstMAC, short protocol, int srcPort, int dstPort, short dscp, boolean multicast, int applicationId){
// Vhodny hash?
int hash = (srcIP.hashCode() + 1009);
hash ^= dstIP.hashCode();hash ^= Arrays.hashCode(srcMAC);hash ^= Arrays.hashCode(dstMAC);
hash ^= protocol; hash ^= srcPort; hash ^= dstPort; hash ^= dscp; hash += (multicast ? 1009 : 2003);
int hash = (srcIP.hashCode() + 1000009);
hash ^=applicationId;
hash ^= dstIP.hashCode() + 379;hash ^= Arrays.hashCode(srcMAC) + 12485;hash ^= Arrays.hashCode(dstMAC) + 7541699;
hash ^= protocol; hash ^= srcPort + 2015; hash ^= dstPort; hash ^= dscp; hash += (multicast ? 1009 : 2003);
return hash;
}
}
\ No newline at end of file
public static int byteArrayToInt(byte[] b) {
return ByteBuffer.wrap(b).order(ByteOrder.LITTLE_ENDIAN).getInt();
}
/*
public static int byteArrayToInt(byte[] encodedValue) {
int index = 0;
int value = 0 << Byte.SIZE * 3;
value ^= (encodedValue[index++] & 0xFF) << Byte.SIZE * 2;
value ^= (encodedValue[index++] & 0xFF) << Byte.SIZE * 1;
value ^= (encodedValue[index++] & 0xFF);
return value;
}
*/
}
......@@ -42,6 +42,7 @@ public class AccountingRecord {
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;
private int applicationId;
/** Vytvara novu instanciu triedy */
public AccountingRecord() {
......@@ -61,9 +62,10 @@ public class AccountingRecord {
* @param isMulticast Flag ci sa jedna o multivastove spojenie
* @param octetCount Pocet bytov flowu
* @param packetCount Pocet paketov flowu
* @param applicationId Id aplikacneho protokolu pre flow
*/
public AccountingRecord(byte[] srcIP, byte[] dstIP,byte[] srcMAC, byte[] dstMAC, short protocol, int srcPort, int dstPort,
short ipdscp, long firstFlowStart,long lastFlowEnd, boolean isMulticast, long octetCount, long packetCount){
short ipdscp, long firstFlowStart,long lastFlowEnd, boolean isMulticast, long octetCount, long packetCount, int applicationId){
this.sourceIPv4Address = srcIP;
this.destinationIPv4Address = dstIP;
this.sourceMAC = srcMAC;
......@@ -77,6 +79,7 @@ public class AccountingRecord {
this.isMulticast = isMulticast;
this.octetDeltaCount = octetCount;
this.packetDeltaCount = packetCount;
this.applicationId = applicationId;
flowCount = 1;
}
......@@ -114,7 +117,8 @@ public class AccountingRecord {
&& this.sourcePort == ar.getSourcePort()
&& this.destinationPort == ar.getDestinationPort()
&& this.ipDiffServCodePoint == ar.getIpDiffServCodePoint()
&& this.isMulticast == ar.isIsMulticast())
&& this.isMulticast == ar.isIsMulticast()
&& this.applicationId == ar.getApplicationId())
return true;
return false;
}
......@@ -207,6 +211,13 @@ public class AccountingRecord {
public boolean isIsMulticast() {
return isMulticast;
}
/**
* Get metoda
* @return identifikátor aplikácie účtovacieho záznamu
*/
public int getApplicationId(){
return applicationId;
}
/**
* Get metoda
* @return Pocet bytov uctovacieho zaznamu
......
......@@ -80,7 +80,7 @@ public class AccountingRecordsExporter {
public void flushCacheToDB(){
AccountingRecord ar;
String json = "{";
Object[] values = new Object[14];
Object[] values = new Object[15];
long averageDate;
Enumeration e = arCache.getArCache().elements();
log.debug("Connecting to DB for Accounting.");
......@@ -89,7 +89,7 @@ public class AccountingRecordsExporter {
//colNames = new String[12];
String[] colNames = {"collectorID","sourceipv4address","destinationipv4address","sourcemacaddress",
"destinationmacaddress","protocolidentifier","sourceport","destinationport","ipdiffservcodepoint",
"datetime","ismulticast","octetdeltacount","packetdeltacount","flowcount"};
"datetime","ismulticast","octetdeltacount","packetdeltacount","flowcount","applicationId"};
while(e.hasMoreElements()){
ar = (AccountingRecord)e.nextElement();
......@@ -121,7 +121,7 @@ public class AccountingRecordsExporter {
values[11] = ar.getOctetDeltaCount();
values[12] = ar.getPacketDeltaCount();
values[13] = ar.getFlowCount() ;
values[14] = ar.getApplicationId();
//pgclient.insertdata("ACC_REC", json);
//log.debug("Inserting values: " + 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