|
@@ -268,6 +268,12 @@ public abstract class BasicPacketClassifier implements PacketSniffer {
|
|
|
* @param packets packets to be classified
|
|
|
*/
|
|
|
protected void classify(HashMap<Link, LinkedList<Packet>> packets) {
|
|
|
+ int tp = 0;
|
|
|
+ int fp = 0;
|
|
|
+ int tn = 0;
|
|
|
+ int fn = 0;
|
|
|
+ long start = Long.MAX_VALUE;
|
|
|
+ long end = Long.MIN_VALUE;
|
|
|
for (Iterator<Entry<Link, LinkedList<Packet>>> it = packets.entrySet().iterator(); it.hasNext();) {
|
|
|
|
|
|
* Link & its packets
|
|
@@ -282,15 +288,40 @@ public abstract class BasicPacketClassifier implements PacketSniffer {
|
|
|
* Packet which should be checked
|
|
|
*/
|
|
|
Packet packet = (Packet) itPacket.next();
|
|
|
+ start = Math.min(start, packet.getTimestamp());
|
|
|
+ end = Math.max(end, packet.getTimestamp());
|
|
|
|
|
|
* Instance Representation
|
|
|
*/
|
|
|
Instance packet_instance = packet2Instance(l, packet, dataset);
|
|
|
|
|
|
if(packet_instance == null)continue;
|
|
|
- classifyInstance(null, packet);
|
|
|
+ try {
|
|
|
+ classifyInstance(packet_instance, packet);
|
|
|
+ if(packet.getLabel()==0)
|
|
|
+ tn++;
|
|
|
+ else
|
|
|
+ fn++;
|
|
|
+ } catch (Exception e) {
|
|
|
+ if(packet.getLabel()==0)
|
|
|
+ fp++;
|
|
|
+ else
|
|
|
+ tp++;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ int n = tp+tn+fp+fn;
|
|
|
+ if(n!=0) {
|
|
|
+ System.out.println(getAlgoName()+" Performance: ["+start+"ms, "+end+"ms]");
|
|
|
+ System.out.println("n: ");
|
|
|
+ System.out.println("TP: "+tp);
|
|
|
+ System.out.println("FP: "+fp);
|
|
|
+ System.out.println("TN: "+tn);
|
|
|
+ System.out.println("FN: "+fn);
|
|
|
+ System.out.println("TPR: "+(tp/(tp+fn+0.0)));
|
|
|
+ System.out.println("FPR: "+(fp/(fp+tn+0.0)));
|
|
|
+ System.out.println("");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
@@ -303,8 +334,9 @@ public abstract class BasicPacketClassifier implements PacketSniffer {
|
|
|
* classifies the given instance
|
|
|
* @param instance instance which should be classified
|
|
|
* @param origin original packet, which was transformed into the instance
|
|
|
+ * @throws Exception if anomaly was detected
|
|
|
*/
|
|
|
- public abstract void classifyInstance(Instance instance, Packet origin);
|
|
|
+ public abstract void classifyInstance(Instance instance, Packet origin) throws Exception;
|
|
|
|
|
|
|
|
|
* Returns the timestep, after which the classifier should start classifying instead of training.
|
|
@@ -329,4 +361,10 @@ public abstract class BasicPacketClassifier implements PacketSniffer {
|
|
|
public boolean getMode() {
|
|
|
return !training;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ * Short String representation of the classifier
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public abstract String getAlgoName();
|
|
|
}
|